r290 - in trunk/software/py-ophoned: . pygsm

smartphones-commits at linuxtogo.org smartphones-commits at linuxtogo.org
Thu May 1 20:00:49 CEST 2008


Author: mickeylauer
Date: 2008-05-01 20:00:48 +0200 (Thu, 01 May 2008)
New Revision: 290

Modified:
   trunk/software/py-ophoned/config.py
   trunk/software/py-ophoned/frontend.py
   trunk/software/py-ophoned/ophoned
   trunk/software/py-ophoned/pygsm/__init__.py
   trunk/software/py-ophoned/pygsm/attention.py
   trunk/software/py-ophoned/pygsm/genericmodem.py
Log:
py-ophoned: add option to use preferred modem


Modified: trunk/software/py-ophoned/config.py
===================================================================
--- trunk/software/py-ophoned/config.py	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/config.py	2008-05-01 18:00:48 UTC (rev 290)
@@ -1,4 +1,23 @@
 DBUS_INTERFACE_PREFIX = "org.freesmartphone.GSM"
 DBUS_PATH_PREFIX = "/org/freesmartphone/GSM"
+DBUS_BUS_NAME = "/org/freesmartphone/ophoned"
 
 VERSION = "0.0.0"
+
+log_debug = True
+log_info = True
+
+from syslog import syslog, LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG
+from traceback import format_exc
+
+def LOG(level, *values):
+    if level <= LOG_ERR and log_debug:
+            syslog(level, '%s %s'% (values[0], format_exc(), ))
+    if level <= LOG_ERR \
+    or level <= LOG_INFO and log_info \
+    or level <= LOG_DEBUG and log_debug:
+            try: syslog(level, ' '.join([str(i) for i in values]).__repr__())
+            except Exception, e:
+                    print 'error on syslog', values.__repr__()
+                    print 'error on syslog', format_exc()
+                    print 'error on syslog', e

Modified: trunk/software/py-ophoned/frontend.py
===================================================================
--- trunk/software/py-ophoned/frontend.py	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/frontend.py	2008-05-01 18:00:48 UTC (rev 290)
@@ -13,9 +13,10 @@
         self.mainloop = gobject.MainLoop()
         gobject.idle_add( self.idle )
         gobject.timeout_add_seconds( 10, self.timeout )
-        self.bus = dbus.SessionBus()
+        self.bus = dbus.SystemBus()
         self.busname = dbus.service.BusName( config.DBUS_INTERFACE_PREFIX, self.bus )
 
+
         self.backend = backend
         self.objects = {}
 

Modified: trunk/software/py-ophoned/ophoned
===================================================================
--- trunk/software/py-ophoned/ophoned	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/ophoned	2008-05-01 18:00:48 UTC (rev 290)
@@ -2,24 +2,31 @@
 # -*- coding: latin1 -*-
 #
 # Authored by Michael 'Mickey' Lauer <mickey at vanille-media.de>
-# (C) 2008 OpenMoko Inc.
+# (C) 2008 Openmoko, Inc.
 # GPLv2 or later
 #############################################################################
 
+import pygsm
 from optparse import OptionParser
+from config import LOG, LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG
+from syslog import LOG_PERROR, LOG_DAEMON
+import os
 
 parser = OptionParser()
-parser.add_option( "-b", "--backend", dest = "backend",
-    help = "select backend. Available options = 'testing'" )
+parser.add_option( "-m", "--modem", dest = "modem",
+    help = "select modem. Available options = %s " % pygsm.allModems() )
 
 options, args = parser.parse_args()
 
-if options.backend not in "testing ".split():
-    parser.error( "Need to give a valid backend" )
+if options.modem is None:
+    options.modem = "ti_calypso"
 
+if options.modem not in pygsm.allModems():
+    parser.error( "Sorry, need to give a valid modem such as %s" % pygsm.allModems() )
+else:
+    if "OPHONED_DEBUG" in os.environ:
+        openlog( "py-ophoned", LOG_PERROR, LOG_DAEMON )
+        LOG( LOG_INFO, "Using modem '%s' % options.modem" )
+
 from frontend import Controller
-import backend
-
-if options.backend == "testing":
-    Controller( backend.TestingBackend() ).run()
-
+Controller( options.modem ).run()

Modified: trunk/software/py-ophoned/pygsm/__init__.py
===================================================================
--- trunk/software/py-ophoned/pygsm/__init__.py	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/pygsm/__init__.py	2008-05-01 18:00:48 UTC (rev 290)
@@ -1,9 +1,31 @@
-#!/usr/bin/env python2.5
-# -*- coding: utf-8 -*-
+modems = {}
+try:
+    import testingmodem
+except ImportError:
+    pass
+else:
+    modems["testing"] = testingmodem.Modem
 
-# copyright: m. dietrich
-# license: gpl
-__revision = '$Rev: 227 $'
+try:
+    import ficmodem
+except ImportError:
+    pass
+else:
+    modems["ti_calypso"] = ficmodem.FicModem
 
+try:
+    import genericmodem
+except ImportError:
+    pass
+else:
+    modems["generic"] = genericmodem.GenericModem
 
-# vim:tw=0:nowrap
+
+def allModems():
+    return modems.keys()
+
+def hasModem( m ):
+    return m in modems
+
+def modem( m ):
+    return modems.get( m, None )

Modified: trunk/software/py-ophoned/pygsm/attention.py
===================================================================
--- trunk/software/py-ophoned/pygsm/attention.py	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/pygsm/attention.py	2008-05-01 18:00:48 UTC (rev 290)
@@ -181,10 +181,11 @@
 
 	finals = ('+CME ERROR', '+CMS ERROR', 'BUSY', 'CONNECT', 'ERROR', 'NO ANSWER', 'NO CARRIER', 'NO DIALTONE', 'OK', )
 	def __read_rr(self, source, condition):
+		#print "__READ_RR: ENTER"
 		assert self.rr is source
 		line = source.readline().strip()
 		if self.debuglog: print >> self.debuglog, time(), source.port, 'read', line
-		try:
+		if True: #try:
 			LOG(LOG_DEBUG, __name__, '__read_rr', 'read line', line)
 			if line.startswith('+CRING'): return True # hm, can't switch that unsol. spam off here...
 			if line: # ignore empty lines
@@ -199,8 +200,9 @@
 						self.__next_rr()
 				else:
 					LOG(LOG_WARNING, __name__, '__read_rr', 'no parser for line', line)
-		except Exception, e:
-			LOG(LOG_ERR, __name__, '__read_rr', e, line)
+		#except Exception, e:
+		#	LOG(LOG_ERR, __name__, '__read_rr', e, line)
+		#print "__READ_RR: LEAVE"
 		return True
 
 	def __read_um(self, source, condition):
@@ -231,11 +233,13 @@
 		return True
 
 	def __next_rr(self):
+		#print "next_rr:ENTER"
 		if self.rr.request_stack:
 			command, self.rr.request_parser, self.rr.request_timeout = self.rr.request_stack.pop(0)
 			self.__attention_write(self.rr, command)
 			if self.rr.request_timeout:
 				self.rr.tow = timeout_add(self.rr.request_timeout, self.__timeout_rr)
+		#print "next_rr:LEAVE"
 		return False
 
 	def __timeout_rr(self):
@@ -274,6 +278,7 @@
 
 	@staticmethod
 	def parse_types(values):
+		#print "parse_types: ENTER"
 		values = values.split(',')
 		for idx, val in enumerate(values):
 			try:
@@ -285,6 +290,7 @@
 					val = int(val)
 			except: pass
 			values[idx] = val
+		#print "parse_types: LEAVE"
 		return values
 
 # vim:tw=0:nowrap

Modified: trunk/software/py-ophoned/pygsm/genericmodem.py
===================================================================
--- trunk/software/py-ophoned/pygsm/genericmodem.py	2008-05-01 14:19:01 UTC (rev 289)
+++ trunk/software/py-ophoned/pygsm/genericmodem.py	2008-05-01 18:00:48 UTC (rev 290)
@@ -168,7 +168,7 @@
 	def responseCGSN(self, _name, imei):
 		LOG(LOG_DEBUG, __name__, 'imei', imei)
 		_device_info = dict(self._device_info,
-			imei=imei,
+			imei=str(imei),
 			)
 		#if _device_info != self._device_info:
 		self.DeviceInfo(_device_info)




More information about the Smartphones-commits mailing list