r256 - in trunk/software/pyneod: . pygsm

smartphones-commits at lists.linuxtogo.org smartphones-commits at lists.linuxtogo.org
Sun Apr 27 13:18:25 CEST 2008


Author: emdete
Date: 2008-04-27 13:18:25 +0200 (Sun, 27 Apr 2008)
New Revision: 256

Modified:
   trunk/software/pyneod/base.py
   trunk/software/pyneod/pygsm/attention.py
   trunk/software/pyneod/pygsm/genericmodem.py
   trunk/software/pyneod/pyneod.ini
Log:
sms send fixed


Modified: trunk/software/pyneod/base.py
===================================================================
--- trunk/software/pyneod/base.py	2008-04-25 17:32:13 UTC (rev 255)
+++ trunk/software/pyneod/base.py	2008-04-27 11:18:25 UTC (rev 256)
@@ -27,7 +27,7 @@
 			#e = format_exc()
 			#if e:
 				for l in extract_stack(): #e.split('\n'):
-					syslog(level, ('%s %s:%d'% (values[0], l[0], l[1], )).__repr__())
+					syslog(level, ('+++ %s %s:%d'% (values[0], l[0], l[1], )).__repr__())
 		if level <= LOG_ERR \
 		or level <= LOG_INFO and log_info \
 		or level <= LOG_DEBUG and log_debug:

Modified: trunk/software/pyneod/pygsm/attention.py
===================================================================
--- trunk/software/pyneod/pygsm/attention.py	2008-04-25 17:32:13 UTC (rev 255)
+++ trunk/software/pyneod/pygsm/attention.py	2008-04-27 11:18:25 UTC (rev 256)
@@ -67,6 +67,12 @@
 			self._callback = None
 			self._error = None
 
+class GsmCommand(object):
+	def __init__(self, s):
+		self.s = s
+	def __str__(self):
+		return self.s
+
 class MuxedLines(object):
 
 	__slots__ = ( 'rr', 'um', 'bus', )
@@ -75,7 +81,10 @@
 		LOG(LOG_DEBUG, __name__, '__init__')
 		self.bus = bus
 		self.rr, self.um, = None, None,
-		self.debuglog = open('/media/card/gsm.log', 'w')
+		if config.get('logging', 'debug') == 'True':
+			self.debuglog = open('/media/card/gsm.log', 'w')
+		else:
+			self.debuglog = None
 
 	def open(self):
 		LOG(LOG_DEBUG, __name__, 'open')
@@ -142,10 +151,12 @@
 	def __attention_write(self, source, command, ):
 		LOG(LOG_DEBUG, __name__, '__attention_write', command)
 		try:
-			source.request = command
-			if self.debuglog: print >> self.debuglog, time(), source.port, 'write', 'AT%s'%command
-			command = 'AT%s\r\n'% command
-			source.write(command)
+			if isinstance(command, GsmCommand):
+				source.request = str(command)
+			else:
+				source.request = 'AT%s\r\n'% command
+			if self.debuglog: print >> self.debuglog, time(), source.port, 'write', source.request.__repr__()
+			source.write(source.request)
 		except Exception, e:
 			LOG(LOG_ERR, __name__, 'error', e)
 
@@ -161,7 +172,7 @@
 			if self.rr.request_timeout:
 				self.rr.tow = timeout_add(self.rr.request_timeout, self.__timeout_rr)
 
-	def activate(self, command, timeout=500): # TODO timeout not implemented now
+	def activate(self, command, timeout=500): # TODO differnt timeouts not implemented now
 		if self.um.request:
 			self.um.request_stack.append(command)
 		else:

Modified: trunk/software/pyneod/pygsm/genericmodem.py
===================================================================
--- trunk/software/pyneod/pygsm/genericmodem.py	2008-04-25 17:32:13 UTC (rev 255)
+++ trunk/software/pyneod/pygsm/genericmodem.py	2008-04-27 11:18:25 UTC (rev 256)
@@ -58,6 +58,20 @@
 			res[str(n[1])] = n[2]
 		self._callback(res)
 
+class CMGSParser(StandardParser):
+	def __init__(self, callback, error):
+		StandardParser.__init__(self, callback, error)
+		self.state = 0 # 0: command, 1: line, 2: ^Z
+	def feed(self, line):
+		self.state += 1
+		if self.state >= 2:
+			return StandardParser.feed(self, line)
+		return line == '>'
+	def callback(self, *values):
+		LOG(LOG_DEBUG, __name__, 'callback', values)
+	def done(self, name):
+		self._callback()
+
 class GenericModem(MuxedLines):
 
 	def __init__(self, bus):
@@ -359,10 +373,14 @@
 		self.request('+CMGD=0,4', timeout=5000, parser=StandardParser(response, error))
 
 	def messages_store(self, number, text, response, error):
-		self.request('+CMGW="%s"\n\r%s\n\r\x1a'% (number, text, ), timeout=5000, parser=StandardParser(response, error))
+		parser = CMGSParser(response, error)
+		self.request('+CMGW="%s"'% (number, ), parser=parser)
+		self.request(GsmCommand('%s\r\n\x1a'% text), timeout=20000, parser=parser)
 
 	def messages_send(self, number, text, response, error):
-		self.request('+CMGS="%s"\n\r%s\n\r\x1a'% (number, text, ), timeout=20000, parser=StandardParser(response, error))
+		parser = CMGSParser(response, error)
+		self.request('+CMGS="%s"'% (number, ), parser=parser)
+		self.request(GsmCommand('%s\r\n\x1a'% text), timeout=20000, parser=parser)
 
 	def phonebook_list_all(self, response, error):
 		self.request('+CPBF', timeout=5000, parser=StandardParser(response, error)) # Find phonebook entries 

Modified: trunk/software/pyneod/pyneod.ini
===================================================================
--- trunk/software/pyneod/pyneod.ini	2008-04-25 17:32:13 UTC (rev 255)
+++ trunk/software/pyneod/pyneod.ini	2008-04-27 11:18:25 UTC (rev 256)
@@ -1,7 +1,7 @@
 [logging]
 use_syslog = True
 info = True
-debug = True
+debug = False
 
 [gsm]
 bus = org.pyneo




More information about the Smartphones-commits mailing list