def __init__(self, device, modem_path, com_path): self.modem_path = modem_path self.com_path = com_path self.device = device self.task_pool = TaskPool(device) self.modem = ModemPort(modem_path, self.task_pool) self.com = CommunicationPort(com_path, self.task_pool) self.modem_is_open = False
class DeviceIO : RETURN_SUCCESS = 0 RETURN_FAILURE = 1 def __init__(self, device, modem_path, com_path): self.modem_path = modem_path self.com_path = com_path self.device = device self.task_pool = TaskPool(device) self.modem = ModemPort(modem_path, self.task_pool) self.com = CommunicationPort(com_path, self.task_pool) self.modem_is_open = False def start(self): try: self.task_pool.start() self.com.open() self.actions_pre_start() return self.RETURN_SUCCESS except: return self.RETURN_FAILURE def stop(self): try: self.actions_pre_stop() self.task_pool.stop() self.com.close() if self.modem_is_open == True : self.modem.close() return True except: return False def pause(self): try: self.actions_pre_pause() self.task_pool.stop() self.com.close() if self.modem_is_open == True : self.modem.close() return True except: return False def resume(self): try: self.task_pool.start() self.com.open() self.actions_pre_resume() return True except: return False def actions_pre_start(self): def function(task): cmd = 'AT+CFUN?' regex = '\+CFUN:\ +(?P<is_on>\d*)' r_values = ["is_on"] res = self.com.send_query({"type" : "regex", "cmd" : cmd, "task" : task, "regex" : regex, "r_values" : r_values}) if res != None and bool(int(res["is_on"])) == False : self.com.send_query({"cmd" : "AT+CFUN=1" , "task" : task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at start") def actions_pre_stop(self): pass def actions_pre_pause(self): def function(task): self.com.send_query({"cmd" : "AT+CFUN=0" , "task" : task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at pause") def actions_pre_resume(self): def function(task): self.com.send_query({"cmd" : "AT+CFUN=1" , "task" : task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at resume") def enable_modem_port(self, enable): if enable == True and self.modem_is_open == False : self.modem.open() self.modem_is_open = True elif enable == False and self.modem_is_open == True : self.modem.close() self.modem_is_open = False def is_modem_port_enabled(self): return self.modem_is_open
class DeviceIO: RETURN_SUCCESS = 0 RETURN_FAILURE = 1 def __init__(self, device, modem_path, com_path): self.modem_path = modem_path self.com_path = com_path self.device = device self.task_pool = TaskPool(device) self.modem = ModemPort(modem_path, self.task_pool) self.com = CommunicationPort(com_path, self.task_pool) self.modem_is_open = False def start(self): try: self.task_pool.start() self.com.open() self.actions_pre_start() return self.RETURN_SUCCESS except: return self.RETURN_FAILURE def stop(self): try: self.actions_pre_stop() self.task_pool.stop() self.com.close() if self.modem_is_open == True: self.modem.close() return True except: return False def pause(self): try: self.actions_pre_pause() self.task_pool.stop() self.com.close() if self.modem_is_open == True: self.modem.close() return True except: return False def resume(self): try: self.task_pool.start() self.com.open() self.actions_pre_resume() return True except: return False def actions_pre_start(self): def function(task): cmd = "AT+CFUN?" regex = "\+CFUN:\ +(?P<is_on>\d*)" r_values = ["is_on"] res = self.com.send_query({"type": "regex", "cmd": cmd, "task": task, "regex": regex, "r_values": r_values}) if res != None and bool(int(res["is_on"])) == False: self.com.send_query({"cmd": "AT+CFUN=1", "task": task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at start") def actions_pre_stop(self): pass def actions_pre_pause(self): def function(task): self.com.send_query({"cmd": "AT+CFUN=0", "task": task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at pause") def actions_pre_resume(self): def function(task): self.com.send_query({"cmd": "AT+CFUN=1", "task": task}) self.task_pool.exec_task(function, task_msg="[Generic] actions at resume") def enable_modem_port(self, enable): if enable == True and self.modem_is_open == False: self.modem.open() self.modem_is_open = True elif enable == False and self.modem_is_open == True: self.modem.close() self.modem_is_open = False def is_modem_port_enabled(self): return self.modem_is_open