예제 #1
0
    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)
예제 #2
0
    def _check_registered_helper(cmd, result):
        r = ''
        if isinstance(result, list):
            # If more than one response is provided, assume that only
            # the last response is of interest and that the
            # rest are uncaught URCs that we should disregard.
            if len(result) > 0:
                r = result[-1]
            else:
                raise SerialError('Internal error: input cannot be an empty list')
        else:
            r = result

        response_list = r.lstrip(cmd).lstrip(': ').split(',')

        if len(response_list) < 2:
            raise SerialError('Unable to parse registration URC response')

        regstatus = int(response_list[1])
        # 1: registered home network
        # 5: registered roaming
        return regstatus == 1 or regstatus == 5
예제 #3
0
    def connect(self, timeout=DEFAULT_NOVA_TIMEOUT):

        success = super(Nova, self).connect(timeout)

        # put serial mode on other port
        if success is True:
            # detect another open serial port to use for PPP
            devices = self.detect_usable_serial_port()
            if not devices:
                raise SerialError('Not enough serial ports detected for Nova')
            self.device_name = devices[0]
            super(Nova, self).initialize_serial_interface()

        return success
예제 #4
0
    def send_message(self, data, timeout=DEFAULT_SEND_TIMEOUT):

        self.urc_state = Modem.SOCKET_INIT

        self.write_socket(data)

        loop_timeout = Timeout(timeout)
        while self.urc_state != Modem.SOCKET_SEND_READ:
            self.checkURC()
            if self.urc_state != Modem.SOCKET_SEND_READ:
                if loop_timeout.expired():
                    raise SerialError('Timeout occurred waiting for message status')
                time.sleep(self._RETRY_DELAY)
            elif self.urc_state == Modem.SOCKET_CLOSED:
                return '[1,0]' #this is connection closed for hologram cloud response

        return self.read_socket()
예제 #5
0
 def _initialize_device_name(self, device_name):
     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]