def initializeNetwork(self, network): self.event = Event() self.__message_buffer = [] # Network Configuration self._networkManager = NetworkManager.NetworkManager( self.event, network) # This registers the message buffering feature based on network availability. self.event.subscribe('network.connected', self.__clear_payload_buffer) self.event.subscribe('network.disconnected', self._networkManager.networkDisconnected)
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super(Modem, self).__init__(device_name=device_name, baud_rate=baud_rate, event=event) self.serial_port = None self.timeout = Modem.DEFAULT_SERIAL_TIMEOUT self.response = [] self._at_sockets_available = False self.urc_state = Modem.SOCKET_INIT self._socket_receive_buffer = deque() self.socket_identifier = 0 self.last_read_payload_length = 0 self.result = ModemResult.OK self.debug_out = '' self.in_ext = False self._initialize_device_name(device_name) self._initialize_chatscript_file(chatscript_file) # This serial mode device name/port will always be equivalent to whatever the # default port is for the specific modem. self._mode = None self.initialize_serial_interface() self.logger.info('Instantiated a %s interface with device name of %s', self.__repr__(), self.device_name)
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super(Modem, self).__init__(device_name=device_name, baud_rate=baud_rate, event=event) self.carrier = None self.serial_port = None self.timeout = Modem.DEFAULT_SERIAL_TIMEOUT self.response = [] self._at_sockets_available = False self.urc_state = Modem.SOCKET_INIT self.last_location = None self.last_send_response = None self._socket_receive_buffer = deque() self.socket_identifier = 0 self.last_read_payload_length = 0 self.last_sim_otp_command_response = None self.result = ModemResult.OK self.debug_out = '' self.gsm = u"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà" self.in_ext = False self.ext = { 0x40: u'|', 0x14: u'^', 0x65: u'€', 0x28: u'{', 0x29: u'}', 0x3C: u'[', 0x3D: u'~', 0x3E: u']', 0x2F: u'\\', } if device_name is None: devices = self.detect_usable_serial_port() if not devices: raise SerialError('Unable to detect a usable serial port') self.device_name = devices[0] if chatscript_file is None: # Get the absolute path of the chatscript file. self.chatscript_file = os.path.dirname( __file__) + DEFAULT_CHATSCRIPT_PATH else: self.chatscript_file = chatscript_file self.logger.info('chatscript file: %s', self.chatscript_file) # This serial mode device name/port will always be equivalent to whatever the # default port is for the specific modem. self._mode = None self.initialize_serial_interface() self.logger.info('Instantiated a %s interface with device name of %s', self.__repr__(), self.device_name)
def __init__(self, device_name='/dev/ttyUSB0', baud_rate='9600', event=Event()): # Logging setup. self.logger = logging.getLogger(__name__) self.logger.addHandler(NullHandler()) self.event = event self.device_name = device_name self.baud_rate = baud_rate
class BLE(Network): def __init__(self): self.event = Event() super().__init__() def connect(self): self.event.broadcast('ble.connected') return True def disconnect(self): self.event.broadcast('ble.disconnected') return True def getConnectionStatus(self): raise Exception('BLE mode doesn\'t support this call yet') def reconnect(self): return True
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super(Nova, self).__init__(device_name=device_name, baud_rate=baud_rate, chatscript_file=chatscript_file, event=event)
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super().__init__(device_name=device_name, baud_rate=baud_rate, chatscript_file=chatscript_file, event=event) self._at_sockets_available = True modem_id = self.modem_id self.baud_rate = '115200' if("R404" in modem_id): self.is_r410 = False else: self.is_r410 = True
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super(Nova_U201, self).__init__(device_name=device_name, baud_rate=baud_rate, chatscript_file=chatscript_file, event=event) # We need to enforce multi serial port support. We then reinstantiate # the serial interface with the correct device name. self.enforce_nova_modem_mode() self._at_sockets_available = True self.last_sim_otp_command_response = None self.last_location = None
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super(NovaM_R404, self).__init__(device_name=device_name, baud_rate=baud_rate, chatscript_file=chatscript_file, event=event) self._at_sockets_available = True
def __init__(self, device_name=None, baud_rate='9600', chatscript_file=None, event=Event()): super().__init__(device_name=device_name, baud_rate=baud_rate, chatscript_file=chatscript_file, event=event) self._at_sockets_available = True self.urc_response = ''
def __init__(self): self.event = Event() super().__init__()
class Cloud: def __repr__(self): return type(self).__name__ def __init__(self, credentials, send_host='', send_port=0, receive_host='', receive_port=0, network=''): # Logging setup. self.logger = logging.getLogger(__name__) self.logger.addHandler(NullHandler()) self.authentication = None # Host and port configuration self.__initialize_host_and_port(send_host, send_port, receive_host, receive_port) self.initializeNetwork(network) def __initialize_host_and_port(self, send_host, send_port, receive_host, receive_port): self.send_host = send_host self.send_port = send_port self.receive_host = receive_host self.receive_port = receive_port def initializeNetwork(self, network): self.event = Event() self.__message_buffer = [] # Network Configuration self._networkManager = NetworkManager.NetworkManager( self.event, network) # This registers the message buffering feature based on network availability. self.event.subscribe('network.connected', self.__clear_payload_buffer) self.event.subscribe('network.disconnected', self._networkManager.networkDisconnected) # EFFECTS: Adds the given payload to the buffer def addPayloadToBuffer(self, payload): self.__message_buffer.append(payload) # EFFECTS: Tells the network manager that it is connected and clears all buffered # messages by sending them to the cloud. def __clear_payload_buffer(self): self._networkManager.networkConnected() for payload in self.__message_buffer: recv = self.sendMessage(payload) self.logger.info( "A buffered message has been sent since an active connection is established" ) self.logger.debug("The buffered message sent is: %s", str(payload)) self.logger.info("The buffered response is: %s", str(recv)) def sendMessage(self, messages, topics=None): raise NotImplementedError('Must instantiate a Cloud type') # EFFECTS: Sends the SMS to the destination number specified. def sendSMS(self, destination_number, message): raise NotImplementedError('Must instantiate a Cloud type') @property def authentication(self): return self._authentication @authentication.setter def authentication(self, authentication): self._authentication = authentication @property def credentials(self): return self.authentication.credentials @credentials.setter def credentials(self, credentials): self.authentication.credentials = credentials @property def version(self): return __version__ @property def send_host(self): return self._send_host @send_host.setter def send_host(self, send_host): self._send_host = send_host @property def send_port(self): return self._send_port @send_port.setter def send_port(self, send_port): try: self._send_port = int(send_port) except ValueError as e: raise ValueError( 'Invalid port parameter. Unable to convert port to a valid integer' ) @property def receive_host(self): return self._receive_host @receive_host.setter def receive_host(self, receive_host): self._receive_host = receive_host @property def receive_port(self): return self._receive_port @receive_port.setter def receive_port(self, receive_port): self._receive_port = int(receive_port) @property def event(self): return self._event @event.setter def event(self, event): self._event = event @property def network_type(self): return repr(self._networkManager) # Returns the network instance itself. @property def network(self): return self._networkManager.network
def __init__(self, event=Event()): super().__init__(event=event) self._connection_status = CLOUD_DISCONNECTED self._modem = None self._route = Route() self.__receive_port = None
def __init__(self, event=Event()): self.event = event # Logging setup. self.logger = logging.getLogger(__name__) self.logger.addHandler(NullHandler())
def __init__(self, event=Event()): self.event = event # Logging setup. self.logger = logging.getLogger(__name__) self.logger.addHandler(NullHandler()) self.scope = NetworkScope.SYSTEM
def test_create(self): event = Event()