Skip to content

Commit df20a9a

Browse files
committed
Fix alphanumeric address decoding (issue #36)
1 parent 28f7c90 commit df20a9a

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

gsmmodem/pdu.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
from __future__ import unicode_literals
66

7-
import sys, codecs
7+
import sys, codecs, math
88
from datetime import datetime, timedelta, tzinfo
99
from copy import copy
10-
import codecs
1110
from .exceptions import EncodingError
1211

1312
# For Python 3 support
@@ -549,7 +548,7 @@ def _decodeAddressField(byteIter, smscField=False, log=False):
549548
ton = (toa & 0x70) # bits 6,5,4 of type-of-address == type-of-number
550549
if ton == 0x50:
551550
# Alphanumberic number
552-
addressLen /= 2
551+
addressLen = int(math.ceil(addressLen / 2.0))
553552
septets = unpackSeptets(byteIter, addressLen)
554553
addressValue = decodeGsm7(septets)
555554
return (addressValue, (addressLen + 2))

test/test_pdu.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,13 @@ def test_decode(self):
422422
'number': '+b08427829207025', # <- broken number (invalid PDU data; the reference number is more than a single byte (or they added something))
423423
'reference': 28,
424424
'time': datetime(2013, 7, 26, 14, 29, 27, tzinfo=SimpleOffsetTzInfo(2)),
425-
'discharge': datetime(2013, 7, 26, 14, 29, 31, tzinfo=SimpleOffsetTzInfo(2))})
425+
'discharge': datetime(2013, 7, 26, 14, 29, 31, tzinfo=SimpleOffsetTzInfo(2))}),
426+
(b'07919762020033F1400DD0CDF2396C7EBB010008415072411084618C0500035602010053004D005300200063006F00640065003A00200034003800350036002C00200063006F006E006600690072006D006100740069006F006E0020006F00660020006100730073006F00630069006100740069006F006E0020006200650074007700650065006E0020006100630063006F0075006E007400200061006E00640020004D00650067',
427+
{'type': 'SMS-DELIVER',
428+
'smsc': '+79262000331',
429+
'number': 'Megafon',
430+
'text': 'SMS code: 4856, confirmation of association between account and Meg',
431+
'time': datetime(2014, 5, 27, 14, 1, 48, tzinfo=SimpleOffsetTzInfo(4))})
426432
)
427433

428434
for pdu, expected in tests:

0 commit comments

Comments
 (0)