def __init__(self, bus_addr=1, com_port=None, baud=115200):
super(PjonPiperClient, self).__init__()
self._pipe = None
self._bus_addr = bus_addr
self._serial_baud = baud
self._piper_client_stdin_queue = Queue()
self._piper_client_stdout_queue = Queue()
self._receiver_function = self.dummy_receiver
self._error_function = self.dummy_error
self._last_watchdog_poll_ts = 0
self._piper_stdout_watchdog_timeout = 0
self._piper_stdout_last_received_ts = 0
if sys.platform == 'win32':
self._startupinfo = subprocess.STARTUPINFO()
self._startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self._startupinfo.wShowWindow = subprocess.SW_HIDE
self._pjon_piper_path = os.path.join(self.get_self_path(), 'pjon_piper_bin', 'win', 'PJON-piper.exe')
elif sys.platform == 'linux2':
#os.setpgrp()
if(self.is_arm_platform()):
if self.is_raspberry():
self._pjon_piper_path = os.path.join(self.get_self_path(), 'pjon_piper_bin', 'rpi',
'pjon_piper')
#print(self._pjon_piper_path)
else:
NotImplementedError("Only Linux on Raspberry is supported")
else:
raise NotImplementedError("this version of Linux is not supported yet")
else:
raise NotImplementedError("platform not supported; currently provided support only for: win32")
if sys.platform == 'win32':
self._pipier_client_subproc_cmd = "%s %s %s %s\n" % (self._pjon_piper_path, com_port.strip(), baud, bus_addr)
elif sys.platform == 'linux2':
self._pipier_client_subproc_cmd = [self._pjon_piper_path, com_port.strip(), str(baud), str(bus_addr)]
if com_port is None:
raise ComPortUndefinedExc("missing com_port kwarg: serial port name is required")
available_coms = self.get_coms()
if com_port not in available_coms:
raise ComPortNotAvailableExc("com port %s is not available in this system; available ports are: %s" % (com_port, str(available_coms)))
else:
log.info("COM OK: %s" % com_port)
self._pipier_client_watchdog = WatchDog(suproc_command=self._pipier_client_subproc_cmd,
stdin_queue=self._piper_client_stdin_queue,
stdout_queue=self._piper_client_stdout_queue,
parent = self)
self._packets_processor = ReceivedPacketsProcessor(self)
atexit.register(self.stop_client)
# TODO:
# 3. implement periodic checks if com is available
# if not: restart watchdog (can be a permanent restart; no state machine required)
评论列表
文章目录