# 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:
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
]
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),
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'),
# 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
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',
self.next_data_call = 0
self.gstate = None
self.nextstate = []
+ self.last_reset = time.time()
record('carrier','')
record('cell','')
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