コード例 #1
0
ファイル: pdusmshandler.py プロジェクト: dkdndes/pygsm
 def parse_incoming_message(self, header_line, line):
     pdu = None
     try:
         pdu = gsmpdu.ReceivedGsmPdu(line)
     except Exception, ex:
         traceback.print_exc(ex)
         self.modem._log('Error parsing PDU: %s' % line)
コード例 #2
0
ファイル: pdusmshandler.py プロジェクト: dkdndes/pygsm
    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