zabsalahid / serialport-gsm

SerialPort-GSM is a simplified plugin for communicating with gsm modems. (Primarily for sms) (Focused in PDU mode)
MIT License
90 stars 47 forks source link

message.getScts is not a function #84

Closed adrian-amaglio closed 3 years ago

adrian-amaglio commented 3 years ago

Hi, thanks for your work.

I got a little issue with the example provided in example/example.js. When the script is listing my INBOX messages I got the following error:

TypeError: message.getScts is not a function
    at module.exports.self.processMessage (/home/ilya/git/test-gsm-adrian/node_modules/serialport-gsm/lib/functions/modem.js:1476:29)
    at EventEmitter.item.logic (/home/ilya/git/test-gsm-adrian/node_modules/serialport-gsm/lib/functions/modem.js:1284:28)
    at /home/ilya/git/test-gsm-adrian/node_modules/serialport-gsm/lib/functions/modem.js:1032:50
    at Array.forEach (<anonymous>)
    at /home/ilya/git/test-gsm-adrian/node_modules/serialport-gsm/lib/functions/modem.js:960:16
    at Array.forEach (<anonymous>)
    at SerialPort.modem.dataReceived (/home/ilya/git/test-gsm-adrian/node_modules/serialport-gsm/lib/functions/modem.js:958:11)
    at SerialPort.emit (node:events:379:20)
    at addChunk (node:internal/streams/readable:313:12)
    at readableAddChunk (node:internal/streams/readable:288:9)

I tried to debug by adding a log at line 1471 of node_modules/serialport-gsm/lib/functions/modem.js:

self.processMessage = (message, messageIndex) => {
    console.log(message) //my new line

And the buggy message is logged as following:

<ref *1> Submit {
  _sca: SCA {
    _type: Type { _type: 1, _plan: 1 },
    _size: 0,
    _phone: null,
    _encoded: null,
    _isAddress: false
  },
  _type: Submit { _rp: 0, _udhi: 0, _srr: 0, _vpf: 2, _rd: 0, _mti: 1 },
  _pid: PID { _pid: 0, _indicates: 0, _type: 0 },
  _dcs: DCS {
    _encodeGroup: 0,
    _dataEncoding: 0,
    _compressedText: false,
    _alphabet: 0,
    _useMessageClass: false,
    _classMessage: 0,
    _discardMessage: false,
    _storeMessage: false,
    _storeMessageUCS2: false,
    _dataCodingAndMessageClass: false,
    _messageIndication: false,
    _messageIndicationType: false
  },
  _mr: 0,
  _vp: VP { _pdu: [Circular *1], _interval: 172800 },
  _address: SCA {
    _type: Type { _type: 0, _plan: 1 },
    _size: 10,
    _phone: '0612345678',
    _encoded: '0612345678',
    _isAddress: true
  },
  _udl: 109,
  _ud: Data {
    _parts: [ [Part] ],
    _isUnicode: false,
    _pdu: [Circular *1],
    _data: "a private text message",
    _size: 109
  }
}

I used a workaround by changing the line 1475 to:

dateTimeSent: 'getScts' in message && message.getScts() ? new Date(message.getScts().getIsoString()) : null || null,

It is not a smart fix but it seems to work. I hope this report can help you in any way. I can provide more information if needed.

Apollon77 commented 3 years ago

I fix it with my next PR

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.