/usr/lib/python2.7/dist-packages/framework/subsystems/ogsmd/modems/abstract/channel.py is in fso-frameworkd 0.10.1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #!/usr/bin/env python
"""
The Open GSM Daemon - Python Implementation
(C) 2007-2008 M. Dietrich
(C) 2008 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
(C) 2008 Openmoko, Inc.
GPLv2 or later
Package: ogsmd.modems.abstract
Module: channel
"""
__version__ = "0.9.1"
MODULE_NAME = "ogsmd.modems.abstract.channel"
from ogsmd.gsm.decor import logged
from ogsmd.gsm.channel import AtCommandChannel
import gobject
import logging
logger = logging.getLogger( MODULE_NAME )
#=========================================================================#
class AbstractModemChannel( AtCommandChannel ):
#=========================================================================#
def __init__( self, *args, **kwargs ):
AtCommandChannel.__init__( self, *args, **kwargs )
self.callback = None
# NOTE: might make it a weak-reference, so that garbage collection
# does not get disturbed by the cirular modem/channel reference
self._modem = kwargs["modem"]
self._commands = {}
self._populateCommands()
self._sendCommands( "init" )
# FIXME add warm start handling (querying CFUN and CPIN status) here:
# 1. Query CFUN to check whether we are powered
# 2. Query CPIN to check whether we are READY
# 3. Try to read a message or a phonebook entry
# 4. If that works, send the SIM ready signal
def modemStateAntennaOn( self ):
"""
Called, when the modem signalizes the antenna being powered on.
"""
self._sendCommands( "antenna" )
def modemStateSimUnlocked( self ):
"""
Called, when the modem signalizes the SIM being unlocked.
Override this in your concrete class to issue sending
org.freesmartphone.GSM.SIM.ReadyStatus( true ) eventually.
"""
# FIXME we might want to make this a 'pure virtual' method
# don't hammer modem too early with the additional commands
# FIXME it's actually modem specific whether we can send the command directly
# after +CPIN: READY or not, so we should not have this here
gobject.timeout_add_seconds( 10, self._sendCommands, "sim" )
def modemStateSimReady( self ):
"""
Called, when the modem signalizes the SIM data can be read.
"""
gobject.timeout_add_seconds( 1, self._sendCommands, "sim" )
def suspend( self, ok_callback, error_callback ):
"""
Called, when the channel needs to configure the modem for suspending.
"""
def done( request, response, self=self, ok_callback=ok_callback ):
ok_callback( self )
self._sendCommandsNotifyDone( "suspend", done )
def resume( self, ok_callback, error_callback ):
def done( request, response, self=self, ok_callback=ok_callback ):
ok_callback( self )
self._sendCommandsNotifyDone( "resume", done )
#
# internal API
#
def _sendCommands( self, state ):
commands = self._commands[state]
if commands:
for command in commands:
try:
commandstring = command()
except TypeError: # not a callable
commandstring = command
self.enqueue( commandstring )
def _sendCommandsNotifyDone( self, state, done_callback ):
# FIXME no error handling, just checking when the results are through
commands = self._commands[state]
if commands:
for command in commands[:-1]:
try:
commandstring = command()
except TypeError: # not a callable
commandstring = command
self.enqueue( commandstring )
command = commands[-1]
try:
commandstring = command()
except TypeError:
commandstring = command
self.enqueue( commandstring, done_callback, done_callback )
else:
done_callback( "", "" )
def _populateCommands( self ):
"""
Populate the command queues to be sent on modem state changes.
"""
c = []
# reset
c.append( '' ) # wakeup
c.append( 'Z' ) # soft reset
c.append( 'E0V1' ) # echo off, verbose result on
# error and result reporting reporting
c.append( '+CMEE=1' ) # report mobile equipment errors: in numerical format
c.append( '+CRC=1' ) # cellular result codes: enable extended format
c.append( '+CSCS="UCS2"' ) # character set conversion: use UCS2
c.append( '+CSDH=1' ) # show text mode parameters: show values
c.append( '+CSNS=0' ) # single numbering scheme: voice
# sms
c.append( '+CMGF=0' ) # message format: enable pdu mode, disable text mode
# unsolicited
c.append( '+CLIP=0' ) # calling line identification presentation: disable
c.append( '+COLP=0' ) # connected line identification presentation: disable
c.append( '+CCWA=0' ) # call waiting: disable
self._commands["init"] = c
c = []
c.append( '+CSMS=1' ) # GSM Phase 2+ commands: enable
def sms_and_cb( self=self ):
if self._modem.data( "sim-buffers-sms" ):
return "+CNMI=%s" % self._modem.data( "sms-buffered-cb" )
else:
return "+CNMI=%s" % self._modem.data( "sms-direct-cb" )
c.append( sms_and_cb )
self._commands["sim"] = c
c = []
self._commands["antenna"] = c
c = []
self._commands["suspend"] = c
c = []
self._commands["resume"] = c
def setIntermediateResponseCallback( self, callback ):
assert self.callback is None, "callback already set"
self.callback = callback
def handleUnsolicitedResponse( self, response ):
if self.callback is not None:
self.callback( response )
else:
logger.warning( "UNHANDLED INTERMEDIATE: %s", response )
|