# '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:
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)
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):