Commit 2e49a3d2029d7fabcc902fad15b2d9d9abf48a62

Authored by Adhidarma Hadiwinoto
1 parent 58d87d4cd9
Exists in master

pduParsed

Showing 1 changed file with 17 additions and 2 deletions Side-by-side Diff

lib/serialport-parsers.js
1 1 const PARSER_READLINE_DELIMITER = '\r\n';
2 2 const PARSER_WAIT_FOR_OK_OR_ERROR_REGEX = /\r\n(?:OK|ERROR)\r\n/;
3 3  
4   -
  4 +const pdu = require('node-pdu');
5 5 const ParserReadline = require('@serialport/parser-readline');
6 6 const ParserRegex = require('@serialport/parser-regex');
7 7  
... ... @@ -20,6 +20,17 @@ exports.getPort = function getPort() {
20 20 return port;
21 21 };
22 22  
  23 +function parsePdu(data) {
  24 + if (!data) return null;
  25 +
  26 + try {
  27 + const result = pdu.parse(data.toString().trim() || '');
  28 + return result;
  29 + } catch (e) {
  30 + return null;
  31 + }
  32 +}
  33 +
23 34 function onCSQ(data) {
24 35 const val = data.toString().trim().match(/\+CSQ:\s*(.*)/);
25 36 if (!val || !val[1]) return null;
... ... @@ -71,7 +82,11 @@ parserReadline.on('data', (data) => {
71 82 logger.verbose('INCOMING', { parser: 'parserReadLine', data: `${data.toString()}${PARSER_READLINE_DELIMITER}` });
72 83  
73 84 if (!data) return;
74   - if (isResultCodeIs(data, 'CSQ')) {
  85 +
  86 + const pduParsed = parsePdu(data);
  87 + if (pduParsed) {
  88 + logger.verbose('Got a PDU data', { pduParsed });
  89 + } else if (isResultCodeIs(data, 'CSQ')) {
75 90 logger.verbose('Got a signal quality report', { data: data.toString() });
76 91 onCSQ(data);
77 92 } else if (isResultCodeIs(data, 'COPS:')) {