Skip to content

Commit 7db811d

Browse files
committed
move ublox specific URCs to nova base class
1 parent 71c4bde commit 7db811d

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
@@ -400,46 +400,16 @@ def checkURC(self, hide=False):
400400

401401
# EFFECTS: Handles URC related AT command responses.
402402
def handleURC(self, urc):
403-
self.logger.debug("URC! %s", urc)
403+
self.logger.debug("URC! %s", urc)
404404
self.logger.debug("handleURC state: %d", self.urc_state)
405405

406-
next_urc_state = self.urc_state
407-
408406
if urc.startswith("+CMTI: "):
409407
self._handle_sms_receive_urc(urc)
410-
elif urc.startswith('+UULOC: '):
411-
self._handle_location_urc(urc)
412-
elif urc.startswith('+UUSORD: '):
413-
414-
# Strip UUSORD socket identifier + payload length from the URC event.
415-
# Example: {+UUSORD: 0,2} -> 0 and 2
416-
response_list = urc.lstrip('+UUSORD: ').split(',')
417-
socket_identifier = int(response_list[0])
418-
payload_length = int(response_list[-1])
419-
420-
if self.urc_state == Modem.SOCKET_RECEIVE_READ:
421-
self._read_and_append_message_receive_buffer(socket_identifier, payload_length)
422-
else:
423-
self.socket_identifier = socket_identifier
424-
self.last_read_payload_length = payload_length
425-
next_urc_state = Modem.SOCKET_SEND_READ
426-
elif urc.startswith('+UUSOLI: '):
427-
self._handle_listen_urc(urc)
428-
self.last_read_payload_length = 0
429-
next_urc_state = Modem.SOCKET_RECEIVE_READ
430-
elif urc.startswith('+UUPSDD: '):
431-
self.event.broadcast('cellular.forced_disconnect')
432-
elif urc.startswith('+UUSOCL: '):
433-
next_urc_state = Modem.SOCKET_CLOSED
434408
else:
435409
self.logger.debug("URC was not handled. \'%s\'", urc)
436410

437-
self.urc_state = next_urc_state
438-
439411

440412
# URC handlers
441-
442-
443413
def _handle_sms_receive_urc(self, urc):
444414
self.event.broadcast('sms.received')
445415

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
@@ -89,14 +89,6 @@ def get_sim_otp_response(self, command):
8989

9090
return self.last_sim_otp_command_response
9191

92-
# EFFECTS: Handles URC related AT command responses.
93-
def handleURC(self, urc):
94-
if urc.startswith('+CSIM: '):
95-
self.parse_and_populate_last_sim_otp_response(urc.lstrip('+CSIM: '))
96-
return
97-
98-
super().handleURC(urc)
99-
10092
def populate_location_obj(self, response):
10193
response_list = response.split(',')
10294
self.last_location = Location(*response_list)

0 commit comments

Comments
 (0)