From: NeilBrown Date: Fri, 13 Dec 2013 09:29:53 +0000 (+1100) Subject: Assorted gsmd fixes X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=7952e0b5d0cf625b72767045802980e3d957ad03;p=plato.git Assorted gsmd fixes particularly support for selecting 2G or 3G or some combination. --- diff --git a/gsm/gsmd.py b/gsm/gsmd.py index 04ec2ca..2071459 100644 --- a/gsm/gsmd.py +++ b/gsm/gsmd.py @@ -188,6 +188,29 @@ class AtAction(Task): 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 @@ -197,17 +220,21 @@ class PowerAction(Task): 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','') @@ -218,8 +245,12 @@ class PowerAction(Task): 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): @@ -455,11 +486,11 @@ def check_cfun(channel, line, m): 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(): @@ -580,6 +611,8 @@ control = {} # For flight mode, we turn the power off. control['to-flight'] = [ AtAction(at='+CFUN=0'), + PowerAction('down'), + AtAction(at='$QCPWRDN'), PowerAction('off'), ChangeStateAction('flight') ] @@ -594,19 +627,20 @@ control['refresh'] = [ 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'), ] @@ -681,7 +715,8 @@ control['init2'] = [ 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, @@ -712,6 +747,8 @@ control['idle'] = [ 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 @@ -719,7 +756,7 @@ control['idle'] = [ 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'] = [ @@ -836,6 +873,7 @@ class GsmD(AtChannel): 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 @@ -869,6 +907,8 @@ class GsmD(AtChannel): # 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) @@ -879,6 +919,7 @@ class GsmD(AtChannel): # Check the externally imposed state self.check_flightmode(self.flightmode_watcher) + self.check_gsmmode(self.gsmmode_watcher) # and GO! self.advance() @@ -955,6 +996,19 @@ class GsmD(AtChannel): 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']: