else:
channel.advance()
+def gpio_set(line, val):
+ file = "/sys/class/gpio/gpio%d/value" % line
+ try:
+ fd = open(file, "w")
+ fd.write("%d\n" % val)
+ fd.close()
+ except IOError:
+ pass
+def hs_on():
+ try:
+ os.stat("/dev/ttyHS_Application")
+ return
+ except OSError:
+ pass
+ gpio_set(186,0)
+ time.sleep(0.1)
+ gpio_set(186,1)
+ time.sleep(6)
+def hs_off():
+ log("hs_off")
+ gpio_set(186,0)
+ time.sleep(0.1)
+
class PowerAction(Task):
# A PowerAction ensure that we have a connection to the modem
# and sets the power on or off, or resets the modem
def start(self, channel):
if self.cmd == "on":
+ hs_on()
if not channel.connected:
channel.connect()
if not channel.altchan.connected:
channel.altchan.connect()
channel.check_flightmode()
+ elif self.cmd == 'down':
+ hs_off()
elif self.cmd == "off":
record('carrier', '')
record('cell', '')
record('signal_strength','-/32')
channel.disconnect()
channel.altchan.disconnect()
+ #hs_off()
elif self.cmd == 'reopen':
record('status','')
record('incoming','')
calllog_end('outgoing')
channel.disconnect()
channel.altchan.disconnect()
+ #hs_off()
+ #hs_on()
channel.connect()
channel.altchan.connect()
+ elif self.cmd == 'wait':
+ time.sleep(5)
return channel.advance()
class ChangeStateAction(Task):
if channel.gstate == 'init1':
channel.set_state('init2')
return
- if m.groups()[0] != '0':
+ if m.groups()[0] != '0' or channel.gstate == 'idle':
global recording
if 'signal_strength' in recording:
s = recording['signal_strength'].split('/')
- if s[0] != '0':
+ if s[0] not in '0-':
return
if channel.last_reset + 100 < time.time():
# For flight mode, we turn the power off.
control['to-flight'] = [
AtAction(at='+CFUN=0'),
+ PowerAction('down'),
+ AtAction(at='$QCPWRDN'),
PowerAction('off'),
ChangeStateAction('flight')
]
BlockSuspendAction(False),
PowerAction('reopen'),
BlockSuspendAction(True),
- AtAction(at='E0', timeout=30000),
+ AtAction(at='V1E0', timeout=30000),
ChangeStateAction('init1'),
]
control['reset'] = [
# Harder reset - use _ORESET and re-open devices.
# Don't block suspend if we cannot re-open.
- AtAction(at='_ORESET', critical = False),
+ #AtAction(at='_ORESET', critical = False),
#AtAction(at='$QCPWRDN', critical = False, retries = 0),
BlockSuspendAction(False),
+ PowerAction('wait'),
PowerAction('reopen'),
BlockSuspendAction(True),
- AtAction(at='E0', timeout=30000),
+ AtAction(at='V1E0', timeout=30000),
ChangeStateAction('init1'),
]
record=('sid','\\2', 'carrier','\\1'), critical=False),
# Make sure to use both 2G and 3G
- AtAction(at='_OPSYS=3,2', critical=False),
+ # 0=only2g 1=only3g 2=prefer2g 3=prefer3g 4=staywhereyouare 5=auto
+ AtAction(at='_OPSYS=%s,2', arg='mode', critical=False),
# Enable reporting of Caller number id.
AtAction(check='+CLIP?', ok='\+CLIP: 1,[012]', at='+CLIP=1', timeout=10000,
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='_OSIMOP', ok='_OSIMOP: "(.*)",".*","(.*)"',
+ record=('sid','\\2', 'carrier','\\1'), critical=False, repeat=37000),
#AtAction(check='+COPS?', ok='\+COPS: \d+,\d+,"([^"]*)"', at='+COPS=0',
# record=('carrier', '\\1'), timeout=10000, repeat=37000),
# get signal string
record=('signal_strength','\\1/32'), repeat=29000),
AtAction(check='_OWANDATA?',
ok='_OWANDATA: 1, ([0-9.]+), [0-9.]+, ([0-9.]+), ([0-9.]+), [0-9.]+, [0-9.]+,\d+$',
- handle=data_handle, repeat=if_data),
+ handle=data_handle, repeat=if_data, critical=False),
]
control['data-call'] = [
self.flightmode = True
self.state = None
self.args = {}
+ self.args['mode'] = 3 # prefer 3g
self.suspend_pending = False
self.pending_sms = False
self.sound_on = True
# Monitor other external events which affect us
d = dnotify.dir('/var/lib/misc/flightmode')
self.flightmode_watcher = d.watch('active', self.check_flightmode)
+ d = dnotify.dir('/var/lib/misc/gsm')
+ self.gsmmode_watcher = d.watch('mode', self.check_gsmmode)
d = dnotify.dir('/run/gsm-state')
self.call_watcher = d.watch('call', self.check_call)
self.dtmf_watcher = d.watch('dtmf', self.check_dtmf)
# Check the externally imposed state
self.check_flightmode(self.flightmode_watcher)
+ self.check_gsmmode(self.gsmmode_watcher)
# and GO!
self.advance()
self.flightmode = True
self.set_state('to-flight')
+ def check_gsmmode(self, f = None):
+ try:
+ fd = open("/var/lib/misc/gsm/mode")
+ l = fd.readline()
+ fd.close()
+ except IOError:
+ l = "3"
+ log("check gsmmode got", l)
+ if len(l) and l[0] in "012345":
+ self.args['mode'] = l[0]
+ if self.gstate == 'idle':
+ self.set_state('refresh')
+
def do_suspend(self):
self.suspend_pending = True
if self.gstate not in ['flight', 'resume']: