faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
385 stars 303 forks source link

PDU creates invalid messages when > allowed length #81

Open vai-brma opened 7 years ago

vai-brma commented 7 years ago

The pdu.py splits long messages up depending on the type of string (GSM-7, UCS2,8-bit) But the calculated lengths are wrong and cause modem errors.

attached is a fixed version that works with Multitech MTD-H5 pdu.py.txt

tomchy commented 7 years ago

Hi! could you test if this issue occurs inside following updated fork ? It has several updates and fixes, including long PDUs :slightly_smiling_face:.

vai-brma commented 7 years ago

chunks calculation in divideTextUcs2 should be:

fullChunksCount = int((len(plainText) -1) / MAX_MULTIPART_MESSAGE_LENGTH[0x08])

From: tomchy [mailto:notifications@github.com] Sent: March-07-17 2:04 PM To: faucamp/python-gsmmodem python-gsmmodem@noreply.github.com Cc: Matthews Brian BRMA Brian.Matthews@vaisala.com; Author author@noreply.github.com Subject: Re: [faucamp/python-gsmmodem] PDU creates invalid messages when > allowed length (#81)

Hi! could you test if this issue occurs inside following updated forkhttps://github.com/babca/python-gsmmodem ? It has several updates and fixes, including long PDUs 🙂.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/faucamp/python-gsmmodem/issues/81#issuecomment-284874610, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYTpQ9ngp03HlSJfa0b7LWwRT2pvkHkcks5rjdQ_gaJpZM4MWDqh.

tomchy commented 7 years ago

Could you explain that/provide an example?

Current implementation passes following unit tests (last test inside test_pdu.py):

    def test_encode_Ucs2_divideSMS(self):
        """ Tests whether text will be devided into a correct number of chunks while using UCS-2 alphabet"""
        text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060"
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)
        text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 1234567"
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)
        text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 12345678"
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)
        text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 123456["
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)
        text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 1234567["
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)
        text = "12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,123456 12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,1234567"
        self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)
vai-brma commented 7 years ago

Hi,

 I think it is OK as is.

 if a ucs-2 buffer is exactly 134 bytes long, your calc results in 2 fullChunks and no remainder, whereas my pedantically correct way results in 1 fullChunk and 67 remainder.

Either way it works.

I will try your code tomorrow. It looks OK to me, as it handles the shortened buffer size it needs to  once it is chunked.

Brian

From: tomchy [mailto:notifications@github.com] Sent: March-07-17 4:23 PM To: faucamp/python-gsmmodem python-gsmmodem@noreply.github.com Cc: Matthews Brian BRMA Brian.Matthews@vaisala.com; Author author@noreply.github.com Subject: Re: [faucamp/python-gsmmodem] PDU creates invalid messages when > allowed length (#81)

Could you explain that/provide an example?

Current implementation passes following unit tests (last test inside test_pdu.py):

def test_encode_Ucs2_divideSMS(self):

    """ Tests whether text will be devided into a correct number of chunks while using UCS-2 alphabet"""

    text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060"

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)

    text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 1234567"

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)

    text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 12345678"

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)

    text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 123456["

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 1)

    text = "12345-010 12345-020 12345-030 12345-040 12345-050 12345-060 1234567["

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)

    text = "12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,123456 12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,1234567"

    self.assertEqual(len(gsmmodem.pdu.divideTextUcs2(text)), 2)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/faucamp/python-gsmmodem/issues/81#issuecomment-284905256, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYTpQ900A5D322NO7lsEdNZWI7Pnr-utks5rjfTXgaJpZM4MWDqh.