]> git.neil.brown.name Git - plato.git/commitdiff
gsmd: improve CFUN handling, and split 'init' state.
authorNeilBrown <neilb@suse.de>
Thu, 24 Jan 2013 23:39:52 +0000 (10:39 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 24 Jan 2013 23:39:52 +0000 (10:39 +1100)
Sometimes it can take a little while for CFUN to be effective.
So if it tells us the state is stil '0', we don't want to immediately
try the rest of the init process.

So split the init state into two - one which sets CFUN, and one
which is entered once CFUN says it is OK.

Also, if CFUN says it isn't OK in some way, trigger a reset, but
not too often.

Signed-off-by: NeilBrown <neilb@suse.de>
gsm/gsmd.py
gsm/notes

index 70c1ab9e086c9666ea07454da70f820380db186d..e1980d93e07ec0e41e31231cfa34f130b38d59dd 100644 (file)
@@ -431,6 +431,22 @@ def call_status(channel, line, m):
         #    channel.set_state('on-call')
         pass
 
+def check_cfun(channel, line, m):
+    # response to +CFUN?
+    # If '1', then advance from init1 to init2
+    # else if not 0, possibly do a reset
+    if not m:
+        return
+    if m.groups()[0] == '1':
+        if channel.gstate == 'init1':
+            channel.set_state('init2')
+        return
+    if m.groups()[0] != '0':
+        if channel.last_reset + 100 < time.time():
+            channel.last_reset = time.time()
+            channel.set_state('reset')
+        return
+
 def data_handle(channel, line, m):
     # Response to _OWANDATA - should contain IP address etc
     if not m:
@@ -558,12 +574,11 @@ control['reset'] = [
     PowerAction('reopen'),
     #PowerAction('off'),
     AtAction(at='E0', timeout=30000),
-    ChangeStateAction('init'),
+    ChangeStateAction('init1'),
     ]
 
 # For suspend, we want power on, but no wakups for status or cellid
 control['suspend'] = [
-    AtAction(check='+CFUN?', ok='\+CFUN: [14]', at='+CFUN=1', timeout=10000),
     AtAction(check='+CPAS', ok='\+CPAS: (\d)', handle = call_status),
     CheckSMS(),
     ChangeStateAction(None), # allow async state change
@@ -576,7 +591,6 @@ control['suspend'] = [
     ]
 control['resume'] = [
     BlockSuspendAction(True),
-    AtAction(check='+CFUN?', ok='\+CFUN: [14]', at='+CFUN=1', timeout=10000),
     AtAction(check='+CPAS', ok='\+CPAS: (\d)', handle = call_status),
     AtAction(at='+CNMI=1,1,2,0,0', critical=False),
     AtAction(at='_OSQI=1', critical=False),
@@ -591,7 +605,10 @@ control['listenerr'] = [
     AtAction(at='V1E0'),
     AtAction(at='+CMEE=2;+CRC=1')
     ]
-control['init'] = [
+
+# init1 checks phone status and once we are online
+# we switch to init2, then idle
+control['init1'] = [
     BlockSuspendAction(True),
     PowerAction('on'),
     AtAction(at='V1E0'),
@@ -605,6 +622,10 @@ control['init'] = [
     #         record=('carrier', '\\1'), timeout=10000),
     AtAction(check='+COPS?', ok='\+COPS: \d+,\d+,"([^"]*)"', at='+COPS=0',
              record=('carrier', '\\1'), timeout=10000),
+    AtAction(check='+CFUN?', ok='\+CFUN: (\d)', at='+CFUN=1', timeout=10000, handle=check_cfun, repeat=5000),
+]
+
+control['init2'] = [
     # text format for various messages such SMS
     AtAction(check='+CMGF?', ok='\+CMGF: 0', at='+CMGF=0'),
     # get location status updates
@@ -655,6 +676,7 @@ control['idle'] = [
     RouteVoice(False),
     CheckSMS(),
     BlockSuspendAction(False),
+    AtAction(check='+CFUN?', ok='\+CFUN: (\d)', timeout=10000, handle=check_cfun, repeat=30000),
     AtAction(check='+COPS?', ok='\+COPS: \d+,\d+,"([^"]*)"', at='+COPS',
              record=('carrier', '\\1'), timeout=10000),
     #AtAction(check='+COPS?', ok='\+COPS: \d+,\d+,"([^"]*)"', at='+COPS=0',
@@ -795,6 +817,7 @@ class GsmD(AtChannel):
         self.next_data_call = 0
         self.gstate = None
         self.nextstate = []
+        self.last_reset = time.time()
 
         record('carrier','')
         record('cell','')
@@ -893,7 +916,7 @@ class GsmD(AtChannel):
                 if self.suspend_handle.suspended:
                     self.set_state('suspend')
                 else:
-                    self.set_state('init')
+                    self.set_state('init1')
         else:
             if not self.flightmode:
                 self.flightmode = True
index 47b4b0e2ab46aa63ba5784f616afe394b8e19e96..c3abe7203fc53d47a54e41791d0089a0544b955b 100644 (file)
--- a/gsm/notes
+++ b/gsm/notes
@@ -295,3 +295,12 @@ Data sequencing:
 
 
 ADD CLCC monitoring to get out of 'idle' into 'on-call' ?
+
+
+How to record data usage?
+Need a log file with:
+  data/time SIM bytes-received bytes-transmitted
+
+that updates every 10 minutes.
+Also have state file with counts at last log so increments can
+be monitored.