From bc2f596c9395e247c9dad997e6d44af0707e3063 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 16 Dec 2013 16:41:55 +1100 Subject: [PATCH] gsmd2: use +CLCC in place of +CPAS We poll the status while a call is incoming so we can know when the called hangs up. CPAS isn't reliable as it reports any connection including data. So use +CLCC. --- gsm/gsmd2.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/gsm/gsmd2.py b/gsm/gsmd2.py index dd27063..a30156a 100644 --- a/gsm/gsmd2.py +++ b/gsm/gsmd2.py @@ -1124,10 +1124,7 @@ add_engine(config()) # 'incoming' is "-" for private, or "number" of incoming (or empty) # 'status' is "INCOMING" or 'BUSY' or 'on-call' (or empty) # -# While 'on-call' we poll with +CPAS -# 0=ready 1=unavailable 2=unknown 3=ringing 4=call-in-progress 5=asleep -# need 4 '0' in a row before assume hang-up -# Could use AT+CLCC ?? +# While 'on-call' we poll with +CLCC # ringing: # +CLCC: 1,1,4,0,0,"0403463349",128 # answered: @@ -1158,6 +1155,7 @@ class voice(Engine): request_async('+CLIP:', self.incoming_number) request_async('NO CARRIER', self.hangup) request_async('BUSY', self.busy) + request_async('_OLCC', self.async_activity) watch('/run/gsm-state', 'call', self.check_call) watch('/run/gsm-state', 'dtmf', self.check_dtmf) self.f = EvDev('/dev/input/incoming', self.incoming_wake) @@ -1179,23 +1177,35 @@ class voice(Engine): self.zero_cnt = 0 self.retry(0) def do_retry(self): - at_queue('+CPAS', self.get_activity) + at_queue('+CLCC', self.get_activity) def get_activity(self, line): - if line == None: - return False - m = re.match('\+CPAS: (\d)', line) + m = re.match('\+CLCC: \d+,(\d+),(\d+),\d+,\d+,"([^"]*)".*', line) if m: - n = m.group(1) - if n == '0' or (n == '4' and self.state == 'idle'): - self.zero_cnt += 1 - if self.zero_cnt >= 4 or self.state == 'idle': + n1 = m.group(1) + n2 = m.group(2) + num = m.group(3) + if n1 == '1': + if n2 == '30': self.to_idle() - else: - self.zero_cnt = 0 - if n == '3': - if self.state != 'incoming': - self.to_incoming() + else: + self.to_incoming(num) self.retry() + else: + self.to_idle() + return False + + def async_activity(self, line): + m = re.match('_OLCC: \d+,(\d+),(\d+),\d+,\d+,"([^"]*)".*', line) + if m: + n1 = m.group(1) + n2 = m.group(2) + num = m.group(3) + if n1 == '1': + if n2 == '30': + self.to_idle() + else: + self.to_incoming(num) + return True return False def incoming(self, line): -- 2.39.5