Commit 956d2003e4a2fcaf82e6c3fe431361af77d52349
1 parent
ed3ac5f425
Exists in
master
MODEM-TESTER: parserRegex
Showing 1 changed file with 15 additions and 3 deletions Side-by-side Diff
modem-tester.js
1 | +const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r/; | |
2 | + | |
1 | 3 | const SerialPort = require('serialport'); |
2 | -const ParserReadline = require('@serialport/parser-readline'); | |
3 | 4 | |
4 | 5 | const config = require('komodo-sdk/config'); |
5 | 6 | const logger = require('komodo-sdk/logger'); |
6 | 7 | |
7 | -let port; | |
8 | +/* | |
9 | +const ParserReadline = require('@serialport/parser-readline'); | |
8 | 10 | |
9 | 11 | const parserCRLF = new ParserReadline({ delimiter: '\r\n' }); |
10 | 12 | parserCRLF.on('data', (data) => { |
11 | 13 | logger.verbose('INCOMING', { parser: 'parserReadLine', data: data.toString() }); |
12 | 14 | }); |
15 | +*/ | |
16 | + | |
17 | +const ParserRegex = require('@serialport/parser-regex'); | |
18 | + | |
19 | +const parserWaitForOkOrError = new ParserRegex({ regex: REGEX_WAIT_FOR_OK_OR_ERROR }); | |
20 | +parserWaitForOkOrError.on('data', (data) => { | |
21 | + logger.verbose('INCOMING', { parser: 'parserWaitForOkOrError', data: data.toString() }); | |
22 | +}); | |
23 | + | |
24 | +let port; | |
13 | 25 | |
14 | 26 | function sleep(ms) { |
15 | 27 | return new Promise((resolve) => { |
... | ... | @@ -59,4 +71,4 @@ port = new SerialPort(config.modem.device, { baudRate: 115200 }, async (err) => |
59 | 71 | if (isNotBlacklistedCommand('CMGD')) await writeToPortDelayed('AT+CMGD=0,4\r', 1000); |
60 | 72 | }); |
61 | 73 | |
62 | -port.pipe(parserCRLF); | |
74 | +port.pipe(parserWaitForOkOrError); |