Beispiel #1
0
    def parse_stored_messages(self, lines):
        # loop through all the lines attempting to match CMGL lines (the header)
        # and then match NOT CMGL lines (the content)
        # need to seed the loop first 'cause Python no like 'until' loops
        pdu_lines = []
        messages = []
        m = None
        if len(lines) > 0:
            m = self.CMGL_MATCHER.match(lines[0])

        while len(lines) > 0:
            if m is None:
                # couldn't match OR no text data following match
                raise (errors.GsmReadError())

            # if here, we have a match AND text
            # start by popping the header (which we have stored in the 'm'
            # matcher object already)
            lines.pop(0)

            # now loop through, popping content until we get
            # the next CMGL or out of lines
            while len(lines) > 0:
                m = self.CMGL_MATCHER.match(lines[0])
                if m is not None:
                    # got another header, get out
                    break
                else:
                    # HACK: For some reason on the multitechs the first
                    # PDU line has the second '+CMGL' response tacked on
                    # this may be a multitech bug or our bug in
                    # reading the responses. For now, split the response
                    # on +CMGL
                    line = lines.pop(0)
                    line, cmgl, rest = line.partition('+CMGL')
                    if len(cmgl) > 0:
                        lines.insert(0, '%s%s' % (cmgl, rest))
                    pdu_lines.append(line)

            # now create and process PDUs
            for pl in pdu_lines:
                try:
                    pdu = gsmpdu.ReceivedGsmPdu(pl)
                    msg = self._process_incoming_pdu(pdu)
                    if msg is not None:
                        messages.append(msg)

                except Exception, ex:
                    traceback.print_exc(ex)
                    self.modem._log('Error parsing PDU: %s' % pl)  # TODO log
Beispiel #2
0
    def _fetch_stored_messages(self):
        """
        Fetch stored unread messages, and add them to incoming queue.
        Return number fetched.
        """

        lines = self._strip_ok(self.command('AT+CMGL="%s"' % CMGL_STATUS))
        # loop through all the lines attempting to match CMGL lines (the header)
        # and then match NOT CMGL lines (the content)
        # need to seed the loop first
        num_found=0
        if len(lines)>0:
            m=CMGL_MATCHER.match(lines[0])

        while len(lines)>0:
            if m is None:
                # couldn't match OR no text data following match
                raise(errors.GsmReadError())

            # if here, we have a match AND text
            # start by popping the header (which we have stored in the 'm'
            # matcher object already)
            lines.pop(0)

            # now put the captures into independent vars
            index, status, sender, timestamp = m.groups()

            # now loop through, popping content until we get
            # the next CMGL or out of lines
            msg_buf=StringIO.StringIO()
            while len(lines)>0:
                m=CMGL_MATCHER.match(lines[0])
                if m is not None:
                    # got another header, get out
                    break
                else:
                    msg_buf.write(lines.pop(0))

            # get msg text
            msg_text=msg_buf.getvalue().strip()

            # now create message
            self._add_incoming(timestamp,sender,msg_text)
            num_found+=1

        return num_found
Beispiel #3
0
    def parse_stored_messages(self, lines):
        # loop through all the lines attempting to match CMGL lines (the header)
        # and then match NOT CMGL lines (the content)
        # need to seed the loop first
        messages = []
        if len(lines) > 0:
            m = self.CMGL_MATCHER.match(lines[0])

        while len(lines) > 0:
            if m is None:
                # couldn't match OR no text data following match
                raise (errors.GsmReadError())

            # if here, we have a match AND text
            # start by popping the header (which we have stored in the 'm'
            # matcher object already)
            lines.pop(0)

            # now put the captures into independent vars
            index, status, sender, timestamp = m.groups()

            # now loop through, popping content until we get
            # the next CMGL or out of lines
            msg_buf = StringIO.StringIO()
            while len(lines) > 0:
                m = self.CMGL_MATCHER.match(lines[0])
                if m is not None:
                    # got another header, get out
                    break
                else:
                    msg_buf.write(lines.pop(0))

            # get msg text
            msg_text = msg_buf.getvalue().strip()

            # now create message
            messages.append(
                self._incoming_to_msg(timestamp, sender, msg_text, index))
        return messages