Skip to content

Commit 787f1df

Browse files
committed
Properly handle when parsing other types of SMS PDUs (#16)
1 parent 6cae05b commit 787f1df

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Hologram/Network/Modem/Modem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,10 @@ def _parsePDU(self, header, pdu):
550550

551551
# EFFECTS: Parses the rest of the sms pdu (sender).
552552
def _parse_sender(self, pdu, offset):
553-
554553
sms_deliver = int(pdu[offset],16)
555-
if sms_deliver & 0x03 != 0: return None
554+
# options are SMS-SUBMIT, SMS-DELIVER or SMS-STATUS-REPORT
555+
# we are looking for a deliver, return none for other types
556+
if sms_deliver & 0x03 != 0: return None, offset
556557
offset += 1
557558
sender_len = int(pdu[offset:offset+2],16)
558559
offset += 2
@@ -889,4 +890,3 @@ def version(self):
889890
@property
890891
def imei(self):
891892
return self._basic_command('+GSN')
892-

tests/Modem/test_Modem.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010
import sys
11+
from datetime import datetime
1112

1213
sys.path.append(".")
1314
sys.path.append("..")
@@ -33,6 +34,12 @@ def mock_close_serial_port(modem):
3334

3435
def mock_detect_usable_serial_port(modem, stop_on_first=True):
3536
return '/dev/ttyUSB0'
37+
38+
def mock_command_sms(modem, at_command):
39+
return (ModemResult.OK, ['+CMGL: 2,1,,26', '0791447779071413040C9144977304250500007160421062944008D4F29C0E8AC966'])
40+
41+
def mock_set_sms(modem, at_command, val):
42+
return None
3643

3744
@pytest.fixture
3845
def no_serial_port(monkeypatch):
@@ -43,6 +50,10 @@ def no_serial_port(monkeypatch):
4350
monkeypatch.setattr(Modem, 'closeSerialPort', mock_close_serial_port)
4451
monkeypatch.setattr(Modem, 'detect_usable_serial_port', mock_detect_usable_serial_port)
4552

53+
@pytest.fixture
54+
def get_sms(monkeypatch):
55+
monkeypatch.setattr(Modem, 'command', mock_command_sms)
56+
monkeypatch.setattr(Modem, 'set', mock_set_sms)
4657

4758
# CONSTRUCTOR
4859

@@ -79,6 +90,14 @@ def test_get_location(no_serial_port):
7990
assert(modem.location == 'test location')
8091
assert('This modem does not support this property' in str(e))
8192

93+
# SMS
94+
95+
def test_get_sms(no_serial_port, get_sms):
96+
modem = Modem()
97+
res = modem.popReceivedSMS()
98+
assert(res.sender == '447937405250')
99+
assert(res.timestamp == datetime.utcfromtimestamp(1498264009))
100+
assert(res.message == 'Test 123')
82101

83102
# DEBUGWRITE
84103

0 commit comments

Comments
 (0)