Skip to content

Commit 3028323

Browse files
committed
move ublox specific URCs to nova base class
1 parent 0566314 commit 3028323

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

Hologram/Network/Modem/Modem.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -393,46 +393,16 @@ def checkURC(self, hide=False):
393393

394394
# EFFECTS: Handles URC related AT command responses.
395395
def handleURC(self, urc):
396-
self.logger.debug("URC! %s", urc)
396+
self.logger.debug("URC! %s", urc)
397397
self.logger.debug("handleURC state: %d", self.urc_state)
398398

399-
next_urc_state = self.urc_state
400-
401399
if urc.startswith("+CMTI: "):
402400
self._handle_sms_receive_urc(urc)
403-
elif urc.startswith('+UULOC: '):
404-
self._handle_location_urc(urc)
405-
elif urc.startswith('+UUSORD: '):
406-
407-
# Strip UUSORD socket identifier + payload length from the URC event.
408-
# Example: {+UUSORD: 0,2} -> 0 and 2
409-
response_list = urc.lstrip('+UUSORD: ').split(',')
410-
socket_identifier = int(response_list[0])
411-
payload_length = int(response_list[-1])
412-
413-
if self.urc_state == Modem.SOCKET_RECEIVE_READ:
414-
self._read_and_append_message_receive_buffer(socket_identifier, payload_length)
415-
else:
416-
self.socket_identifier = socket_identifier
417-
self.last_read_payload_length = payload_length
418-
next_urc_state = Modem.SOCKET_SEND_READ
419-
elif urc.startswith('+UUSOLI: '):
420-
self._handle_listen_urc(urc)
421-
self.last_read_payload_length = 0
422-
next_urc_state = Modem.SOCKET_RECEIVE_READ
423-
elif urc.startswith('+UUPSDD: '):
424-
self.event.broadcast('cellular.forced_disconnect')
425-
elif urc.startswith('+UUSOCL: '):
426-
next_urc_state = Modem.SOCKET_CLOSED
427401
else:
428402
self.logger.debug("URC was not handled. \'%s\'", urc)
429403

430-
self.urc_state = next_urc_state
431-
432404

433405
# URC handlers
434-
435-
436406
def _handle_sms_receive_urc(self, urc):
437407
self.event.broadcast('sms.received')
438408

Hologram/Network/Modem/Nova.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,48 @@ def disable_at_sockets_mode(self):
2727
def enable_at_sockets_mode(self):
2828
self._at_sockets_available = True
2929

30+
def handleURC(self, urc):
31+
"""
32+
Handles UBlox URC related AT command responses.
33+
34+
:param urc: the URC string
35+
:type urc: string
36+
"""
37+
self.logger.debug("URC! %s", urc)
38+
39+
if urc.startswith('+CSIM: '):
40+
self.parse_and_populate_last_sim_otp_response(urc.lstrip('+CSIM: '))
41+
return
42+
elif urc.startswith('+UULOC: '):
43+
self._handle_location_urc(urc)
44+
elif urc.startswith('+UUSORD: '):
45+
46+
# Strip UUSORD socket identifier + payload length from the URC event.
47+
# Example: {+UUSORD: 0,2} -> 0 and 2
48+
response_list = urc.lstrip('+UUSORD: ').split(',')
49+
socket_identifier = int(response_list[0])
50+
payload_length = int(response_list[-1])
51+
52+
if self.urc_state == Modem.SOCKET_RECEIVE_READ:
53+
self._read_and_append_message_receive_buffer(socket_identifier, payload_length)
54+
else:
55+
self.socket_identifier = socket_identifier
56+
self.last_read_payload_length = payload_length
57+
self.urc_state = Modem.SOCKET_SEND_READ
58+
elif urc.startswith('+UUSOLI: '):
59+
self._handle_listen_urc(urc)
60+
self.last_read_payload_length = 0
61+
self.urc_state = Modem.SOCKET_RECEIVE_READ
62+
elif urc.startswith('+UUPSDD: '):
63+
self.event.broadcast('cellular.forced_disconnect')
64+
elif urc.startswith('+UUSOCL: '):
65+
self.urc_state = Modem.SOCKET_CLOSED
66+
67+
super().handleURC(urc)
68+
69+
def parse_and_populate_last_sim_otp_response(self, response):
70+
raise NotImplementedError('Must instantiate the right modem type')
71+
3072
@property
3173
def version(self):
3274
return self._basic_command('I9')

Hologram/Network/Modem/Nova_U201.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ def get_sim_otp_response(self, command):
9595

9696
return self.last_sim_otp_command_response
9797

98-
# EFFECTS: Handles URC related AT command responses.
99-
def handleURC(self, urc):
100-
if urc.startswith('+CSIM: '):
101-
self.parse_and_populate_last_sim_otp_response(urc.lstrip('+CSIM: '))
102-
return
103-
104-
super().handleURC(urc)
105-
10698
def populate_location_obj(self, response):
10799
response_list = response.split(',')
108100
self.last_location = Location(*response_list)

0 commit comments

Comments
 (0)