[pkg-fso-commits] [SCM] framworkd debian packageing branch, nomeata-fixes, updated. milestone2-155-gfa115b8

Joachim Breitner mail at joachim-breitner.de
Sun Sep 7 21:30:56 UTC 2008


The following commit has been merged in the nomeata-fixes branch:
commit 5096ee73279cd13b2f27305cf85319bc55b533b9
Merge: 723b74a5db0a0ea6393c7a7b26f7dffa673f1121 02c8fbe7588cf7ef62764b37f58925eaf007dc8d
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Sun Sep 7 23:23:51 2008 +0200

    Merge master

diff --combined framework/subsystems/ogsmd/gsm/channel.py
index 1802692,9274e5d..909e6e1
--- a/framework/subsystems/ogsmd/gsm/channel.py
+++ b/framework/subsystems/ogsmd/gsm/channel.py
@@@ -20,7 -20,7 +20,7 @@@ import parse
  import gobject # pygobject
  
  import serial # pyserial
- import Queue, fcntl, os, time # stdlib
+ import Queue, fcntl, os, time, types # stdlib
  
  import logging
  logger = logging.getLogger( "ogsmd" )
@@@ -45,8 -45,6 +45,6 @@@ class VirtualChannel( object )
      This class represents a sequential serial transport channel.
      """
  
-     DEBUGLOG = 0
- 
      #
      # public API
      #
@@@ -60,8 -58,8 +58,8 @@@
          self.watchReadyToRead = None
          self.serial = None
  
-         if VirtualChannel.DEBUGLOG:
-             self.debugFile = open( "/tmp/%s.log" % self.name, "w" )
+     def __repr__( self ):
+         return "<%s via %s>" % ( self.__class__.__name__, self.serial.port if self.serial is not None else "unknown" )
  
      @logged
      def open( self, path=None ):
@@@ -77,7 -75,7 +75,7 @@@
              return False
  
          # set up serial port object and open it
-         logger.info( "(%s: using modem path '%s')", self, path )
+         logger.info( "%s: initializing" % self )
          self.serial = serial.Serial()
          self.serial.port = str( path )
          self.serial.baudrate = 115200
@@@ -211,10 -209,9 +209,9 @@@
              inWaiting = self.serial.inWaiting()
          except IOError:
              inWaiting = 0
+             # should we really continue here?
          data = self.serial.read( inWaiting )
-         logger.debug( "(%s: got %d bytes from %s: %s)", self, len(data), self.serial.port, repr(data) )
-         if VirtualChannel.DEBUGLOG:
-             self.debugFile.write( data )
+         logger.debug( "%s: got %d bytes from: %s", self, len(data), repr(data) )
          self.readyToRead( data )
  
          self._hookPostReading()
@@@ -225,7 -222,6 +222,6 @@@
          assert source == self.serial.fd, "ready to write on bogus source"
          assert condition == gobject.IO_OUT, "ready to write on bogus condition"
  
- 
          self._hookPreSending()
          self.readyToSend()
          self.watchReadyToSend = None
@@@ -286,7 -282,7 +282,7 @@@ class QueuedVirtualChannel( VirtualChan
          else:
              self.timeout = 5 # default timeout in seconds
  
-         logger.info( "(%s: Creating channel with timeout = %d seconds)", self, self.timeout )
+         logger.info( "%s: Creating channel with timeout = %d seconds", self, self.timeout )
  
      def installParser( self ):
          """
@@@ -300,6 -296,9 +296,9 @@@
          """
          Enqueue data block for sending over the channel.
          """
+         if type( data ) == types.UnicodeType:
+             logger.warning( "%s: Got unicode input. Trying to convert to plain string..." % self )
+             data = str( data )
          self.q.put( ( data, response_cb, error_cb, timeout or self.timeout ) )
          if not self.connected:
              return
@@@ -327,22 -326,19 +326,19 @@@
              return
          self._handleCommandCancellation()
  
-     @logged
+     #@logged
      def readyToSend( self ):
          """
          Reimplemented for internal purposes.
          """
-         if __debug__: print "(%s queue is: %s)" % ( repr(self), repr(self.q.queue) )
+         if __debug__: logger.debug( "%s queue is: %s" % ( repr(self), repr(self.q.queue) ) )
          if self.q.empty():
-             if __debug__: print "(%s: nothing in request queue)" % repr(self)
+             if __debug__: logger.debug( "%s: nothing in request queue" % repr(self) )
              self.watchReadyToSend = None
              return False
  
-         logger.debug( "(%s: sending %d bytes to %s: %s)" % ( repr(self), len(self.q.peek()[0]), self.serial.port, repr(self.q.peek()[0]) ) )
-         if VirtualChannel.DEBUGLOG:
-             self.debugFile.write( self.q.peek()[0] ) # channel data
- 
+         logger.debug( "%s: sending %d bytes: %s" % ( repr(self), len(self.q.peek()[0]), repr(self.q.peek()[0]) ) )
 -        self.serial.write( self.q.peek()[0] ) # channel data
 +        self.serial.write( self.q.peek()[0].encode('ascii') ) # channel data
          if self.q.peek()[3]: # channel timeout
              self.watchTimeout = gobject.timeout_add_seconds( self.q.peek()[3], self._handleCommandTimeout )
          return False
@@@ -359,7 -355,7 +355,7 @@@
  
          The default implementation does nothing.
          """
-         logger.info( "(%s: unsolicited data incoming: %s)", self, repr(response) )
+         logger.info( "%s: unhandled unsolicited data incoming: %s", self, repr(response) )
  
      def handleResponseToRequest( self, request, response ):
          """
@@@ -369,17 -365,20 +365,20 @@@
          """
          reqstring, ok_cb, error_cb, timeout = request
          if not ok_cb and not error_cb:
-             logger.debug( "(%s: COMPLETED '%s' => %s)" % ( repr(self), reqstring.strip(), response ) )
+             logger.debug( "%s: COMPLETED '%s' => %s" % ( repr(self), reqstring.strip(), response ) )
          else:
-             logger.debug( "(%s: COMPLETED '%s' => %s)" % ( repr(self), reqstring.strip(), response ) )
- 
-             # check whether given callback is a generator
-             # if so, advance and give result, if not
-             # call it as usual
-             if hasattr( ok_cb, "send" ):
-                 ok_cb.send( response )
-             else:
-                 ok_cb( reqstring.strip(), response )
+             logger.debug( "%s: COMPLETED '%s' => %s" % ( repr(self), reqstring.strip(), response ) )
+ 
+             try:
+                 # check whether given callback is a generator
+                 # if so, advance and give result, if not
+                 # call it as usual
+                 if hasattr( ok_cb, "send" ):
+                     ok_cb.send( response )
+                 else:
+                     ok_cb( reqstring.strip(), response )
+             except Exception, e:
+                 logger.exception( "unhandled exception in response callback: %s" % e )
  
      def handleCommandTimeout( self, request ):
          """
@@@ -389,16 -388,16 +388,16 @@@
          """
          reqstring, ok_cb, error_cb, timeout = request
          if not ok_cb and not error_cb:
-             logger.debug( "(%s: TIMEOUT '%s' => ???)" % ( repr(self), reqstring.strip() ) )
+             logger.debug( "%s: TIMEOUT '%s' => ???" % ( repr(self), reqstring.strip() ) )
          else:
-             logger.debug( "(%s: TIMEOUT '%s' => ???)" % ( repr(self), reqstring.strip() ) )
+             logger.debug( "%s: TIMEOUT '%s' => ???" % ( repr(self), reqstring.strip() ) )
              error_cb( reqstring.strip(), ( "timeout", timeout ) )
  
      #
      # private API
      #
  
-     @logged
+     #@logged
      def _handleCommandCancellation( self ):
          """
          Called, when the current command should be cancelled.
@@@ -411,12 -410,12 +410,12 @@@
          gobject.source_remove( self.watchTimeout )
          self.watchTimeout = None
          # send EOF to cancel current command
-         logger.debug( "(%s: sending EOF)" % repr(self) )
+         logger.debug( "%s: sending EOF" % repr(self) )
          self.serial.write( "\x1A" )
-         logger.debug( "(%s: EOF sent)" % repr(self) )
+         logger.debug( "%s: EOF sent" % repr(self) )
          # We do _not_ erase the current command and send cancellation ACK,
          # otherwise we would get an "unsolicited" OK as response. If for
-         # whatever reason we want to change the semantics, we could do
+         # whatever reason we would like to change the semantics, we could do
          # with something like:
          #   request = self.q.get()
          #   reqstring, ok_cb, error_cb, timeout = request
@@@ -489,7 -488,7 +488,7 @@@ class DelegateChannel( QueuedVirtualCha
          assert self.delegate is None, "delegate already set"
          self.delegate = object
  
-     @logged
+     #@logged
      def _handleUnsolicitedResponse( self, response ):
          """
          Reimplemented for internal purposes.
@@@ -519,11 -518,15 +518,15 @@@
              # no appropriate handler found, hand over to generic handler
              return self.handleUnsolicitedResponse( data )
          else:
-             if len( response ) == 2:
-                 # unsolicited data contains a PDU
-                 method( values.strip(), response[1] )
-             else:
-                 method( values.strip() )
+             try:
+                 if len( response ) == 2:
+                     # unsolicited data contains a PDU
+                     method( values.strip(), response[1] )
+                 else:
+                     method( values.strip() )
+             except Exception, e:
+                 logger.exception( "unhandled exception in unsolicited response handler: %s" % e )
+                 return False
  
          return True # unsolicited response handled OK
  
diff --combined framework/subsystems/ogsmd/gsm/const.py
index 911d62c,069c96e..9a6e2dc
--- a/framework/subsystems/ogsmd/gsm/const.py
+++ b/framework/subsystems/ogsmd/gsm/const.py
@@@ -1,5 -1,5 +1,5 @@@
  #!/usr/bin/env python
- # -*- coding: iso-8859-15 -*-
+ #coding=utf8
  """
  The Open Device Daemon - Python Implementation
  
@@@ -16,6 -16,9 +16,9 @@@ GSM constants, strings, formats, parse 
  import re
  from ogsmd.helpers import BiDict
  
+ import logging
+ logger = logging.getLogger( "ogsmd" )
+ 
  #=========================================================================#
  # format patterns
  #=========================================================================#
@@@ -41,9 -44,14 +44,14 @@@ PAT_PHONEBOOK_INFO = re.compile( '\((?P
  # +CMGL: 20,"STO UNSENT","",,,128,10
  PAT_SMS_TEXT_HEADER = re.compile( '(?P<index>\d+),"(?P<status>[^"]+)","(?P<number>[^"]*)",(?:"(?P<name>[^"]+)")?,(?:"(?P<timestamp>[^"]+)")?,(?P<ntype>\d+),(?P<textlen>\d+)' )
  
+ # +CMGL: 1,1,"",125
+ PAT_SMS_PDU_HEADER = re.compile( '(?P<index>\d+),(?P<status>\d+),(?:"(?P<name>[^"]+)")?,(?P<pdulen>\d+)' )
+ 
  # +CMGR: "REC READ","Alice-Team",,"08/05/13,09:12:15+08",208,133
  PAT_SMS_TEXT_HEADER_SINGLE = re.compile( '"(?P<status>[^"]+)","(?P<number>[^"]+)",(?:"(?P<name>[^"]+)")?,(?:"(?P<timestamp>[^"]+)")?,(?P<ntype>\d+),(?P<textlen>\d+)' )
  
+ PAT_SMS_PDU_HEADER_SINGLE = re.compile( '(?P<status>\d+),(?:"(?P<name>[^"]+)"),(?P<pdulen>\d+)' )
+ 
  PAT_STRING = re.compile( r'''"([^"]+?)"''' )
  
  # call forwarding
@@@ -66,8 -74,6 +74,6 @@@ def groupDictIfMatch( pattern, string )
      return match.groupdict() if match is not None else None
  
  #=========================================================================#
- # timeouts
- #=========================================================================#
  TIMEOUT = { \
    "CPIN": 6+1,
    "CFUN": 8+1,
@@@ -79,6 -85,17 +85,17 @@@
  }
  
  #=========================================================================#
+ #        "112"      // GSM 02.30, Europe
+ #        "911"      // GSM 02.30, US and Canada
+ #        "08"       // GSM 02.30, Mexico
+ #        "000"      // GSM 22.101, Australia
+ #        "999"      // GSM 22.101, United Kingdom
+ #        "110"      // GSM 22.101
+ #        "118"      // GSM 22.101
+ #        "119"      // GSM 22.101
+ EMERGENCY_NUMBERS = "112 911 08 000 999 110 118 119".split()
+ 
+ #=========================================================================#
  CME = { \
      0:    "Phone failure",
      1:    "No connection to phone",
@@@ -662,6 -679,23 +679,23 @@@ SMS_STATUS_IN = { 
  }
  
  #=========================================================================#
+ SMS_PDU_STATUS_OUT = { \
+     0 : "unread",
+     1 : "read",
+     2 : "unsent",
+     3 : "sent",
+ }
+ 
+ #=========================================================================#
+ SMS_PDU_STATUS_IN = { \
+     "unread": 0,
+     "read": 1,
+     "unsent": 2,
+     "sent": 3,
+     "all": 4,
+ }
+ 
+ #=========================================================================#
  CALL_DIRECTION = { \
      0: "outgoing",
      1: "incoming",
@@@ -726,6 -760,165 +760,165 @@@ CALL_IDENTIFICATION_RESTRICTION = BiDic
  CALL_VALID_DTMF = "0123456789*#ABCD"
  
  #=========================================================================#
+ NETWORK_USSD_MODE = { \
+     0: "completed",
+     1: "useraction",
+     2: "terminated",
+     3: "localclient",
+     4: "unsupported",
+     5: "timeout",
+ }
+ 
+ #=========================================================================#
+ # PDU TP definitions follow here according to the appearance in GSM 03.40
+ # chapter 9.2.3
+ TP_MTI_INCOMING = { \
+     "sms-deliver" : 0,
+     "sms-submit-report" : 1,
+     "sms-status-report" : 2,
+     "reserved" : 3,
+ }
+ 
+ TP_MTI_OUTGOING = { \
+     "sms-deliver-report" : 0,
+     "sms-submit" : 1,
+     "sms-command" : 2,
+     "reserved" : 3,
+ }
+ 
+ #=========================================================================#
+ TP_VPF = { \
+     "n/a" : 0,
+     "enhanced" : 1,
+     "relative" : 2,
+     "absolute" : 3,
+ }
+ 
+ #=========================================================================#
+ TP_PID = { \
+     "implicit" : 0,
+     "telex" : 1,
+     "g3-telefax" : 2,
+     "g4-telefax" : 3,
+     "voice-telphone" : 4,
+     "ermes" : 5,
+     "paging" : 6,
+     "videotex" : 7,
+     "teletex" : 8,
+     "teletex-pspdn" : 9,
+     "teletex-cspdn" : 10,
+     "teletex-pstn" : 11,
+     "teletex-isdn" : 12,
+     "uci" : 13,
+     # reserved
+     "message-handling" : 16,
+     "public-x400" : 17,
+     "e-mail" : 18,
+     # reserved
+     "gsm-ms" : 31,
+ }
+ # FIXME incomplete
+ # Missing TP_VPEXT
+ #=========================================================================#
+ TP_ST = { \
+     # Transaction completed
+     "received" : 0,
+     "forwarded" : 1,
+     "replaced" : 2,
+     # Temporary error, trying again
+     "congestion" : 32,
+     "sme-busy" : 33,
+     "sme-no-response" : 34,
+     "service-rejected" : 35,
+     "qos-na" : 36,
+     "sme-error" : 37,
+     # Permanent error
+     "remote-procedure-error" : 64,
+     "incompatible-destination" : 65,
+     "sme-connection-rejected" : 66,
+     "not-obtainable" : 67,
+     "qos-na" : 68,
+     "internetworking-na" : 69,
+     "vp-expired" : 70,
+     "deleted-by-origin" : 71,
+     "deleted-by-sc" : 72,
+     "nonexistant" : 73,
+     # Temporary error, giving up
+     "congestion" : 96,
+     "sme-busy" : 97,
+     "sme-no-response" : 98,
+     "service-rejected" : 99,
+     "qos-na" : 100,
+     "sme-error" : 101,
+ }
+ 
+ #=========================================================================#
+ TP_CT = { \
+     "request-status-report" : 0,
+     "cancel-status-report" : 1,
+     "delete-sm" : 2,
+     "enable-status-report" : 3,
+ }
+ 
+ #=========================================================================#
+ TP_FCS = { \
+     "telematic-unsupported" : 0x80,
+     "sm-type0-unsupported" : 0x81,
+     "replace-sm-failed" : 0x82,
+     "tp-pid-error" : 0x8f,
+ 
+     "dcs-unsupported" : 0x90,
+     "message-class-unsupported" : 0x91,
+     "tp-dcs-error" : 0x9f,
+ 
+     "cmd-no-action" : 0xa0,
+     "cmd-unsupported" : 0xa1,
+     "tp-cmd-error" : 0xaf,
+ 
+     "sc-busy" : 0xc0,
+     "sc-no-subscription" : 0xc1,
+     "sc-failure" : 0xc2,
+     "invalid-address" : 0xc3,
+     "destination-barred" : 0xc4,
+     "rejected-duplicaet" : 0xc5,
+     "tp-vfp-unsupported" : 0xc6,
+     "tp-vf-unsupported" : 0xc7,
+ 
+     "sim-storage-full" : 0xd0,
+     "no-sim-storage" : 0xd1,
+     "ms-error" : 0xd2,
+     "memory-exceeded" : 0xd3,
+     "stk-busy" : 0xd4,
+     "data-download-error" : 0xd5,
+ 
+     "error" : 0xff,
+ }
+ 
+ #=========================================================================#
+ TP_UDH_IEI = { \
+     "csm8" : 0,
+     "special-sms" : 1,
+     "port8" : 4,
+     "port16" : 5,
+     "smsc-control" : 6,
+     "udh-source" : 7,
+     "csm16" : 8,
+     "wcmp" : 9,
+     #stk-security
+     #various specific foo
+ }
+ 
+ #=========================================================================#
+ GSMALPHABET =    u'@£$¥èéùìòÇ\nØø\nÅåΔ_ΦΓΛΩΠΨΣΘΞ�ÆæßÉ !"#¤%&\'()*+,-./'+\
+                  u'0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿'+\
+                  u'abcdefghijklmnopqrstuvwxyzäöñà'
+ GSMEXTBYTE = 27
+ GSMEXTALPHABET = u'          \n         ^                   {}    '+\
+                  u' \\            [~] |                              '+\
+                  u'    €                          '
+ 
+ 
+ #=========================================================================#
  import types, math
  
  #=========================================================================#
@@@ -802,10 -995,7 +995,10 @@@ def phonebookTupleToNumber( nstring, nt
      """
  
      # FIXME figure out how to decode ntype 208
 -    assert ntype in ( 129, 145, 185, 208 ), "unknown type %i" % ntype
 +    if not ntype in ( 129, 145, 185, 208 ):
 +	# No logger available in this module, so I’m being lazy, this
 +	# is just a workaround anyways.
 +	print >>sys.stderr, "Unknown number type %i when reading number \"%s\"" % (ntype, nstring)
      if ntype == 145: # should not include '+', but sometimes it does
          if nstring[0] == '+':
              return nstring
@@@ -849,13 -1039,17 +1042,17 @@@ def unicodeToString( uni )
  def textToUnicode( text ):
  #=========================================================================#
      """
-     Returns a unicode text for a text given from the modem.
+     Strip " from a modem text and convert it to unicode. Do nothing, if already unicode.
      """
+     stripped = text.strip( '"' )
+     if type( stripped ) == types.UnicodeType:
+         logger.warning( "textToUnicode called with unicode string, ignoring." )
+         return stripped
      try:
-         result = unicode( text.strip( '"' ), "iso-8859-1" ) # as set via +CSCS
+         result = unicode( stripped, "iso-8859-1" ) # as set via +CSCS
      except UnicodeDecodeError:
          result = "<??? undecodable ???>"
-         # log warning
+         logger.error( "textToUnicode called with unconvertable string" )
      return result
  
  #=========================================================================#

-- 
framworkd debian packageing



More information about the pkg-fso-commits mailing list