Commit e49a560323ca9f0a041c78634e324019cc164f0c
1 parent
beba81d886
Exists in
master
Prototype of bootstrap module
Showing 3 changed files with 50 additions and 1 deletions Side-by-side Diff
lib/bootstrap.js
... | ... | @@ -0,0 +1,44 @@ |
1 | +/** | |
2 | + * Modul modem bootstrap | |
3 | + * @module bootstrap | |
4 | + * @since 2019-09-25 | |
5 | + */ | |
6 | + | |
7 | +const SerialPort = require('serialport'); | |
8 | + | |
9 | +const config = require('komodo-sdk/config'); | |
10 | +const logger = require('komodo-sdk/logger'); | |
11 | + | |
12 | +const parsers = require('./serialport-parsers'); | |
13 | +const modemCommands = require('./modem-commands'); | |
14 | +const modemInfo = require('./modem-info'); | |
15 | + | |
16 | +const port = new SerialPort(config.modem.device, { baudRate: 115200 }, async (err) => { | |
17 | + if (err) { | |
18 | + logger.warn(`Error opening modem. ${err}. Terminating modem ${config.modem.device}.`); | |
19 | + process.exit(1); | |
20 | + } | |
21 | + | |
22 | + await modemCommands.writeToPortAndWaitForOkOrError(`${modemCommands.CTRLZ}AT&FE0\r`); | |
23 | + await modemCommands.initATCommands(); | |
24 | + await modemCommands.queryManufacturer(); | |
25 | + await modemCommands.queryModel(); | |
26 | + await modemCommands.queryIMEIAndIMSI(); | |
27 | + await modemCommands.queryCOPSAndSignalQuality(); | |
28 | + | |
29 | + logger.info('Modem state', modemInfo); | |
30 | + | |
31 | + setInterval(async () => { | |
32 | + await modemCommands.initATCommands(); | |
33 | + await modemCommands.queryManufacturer(); | |
34 | + await modemCommands.queryModel(); | |
35 | + await modemCommands.queryIMEIAndIMSI(); | |
36 | + await modemCommands.queryCOPSAndSignalQuality(); | |
37 | + logger.info('Modem state', modemInfo); | |
38 | + }, config.interval_beetwen_signal_strength_ms || 30000); | |
39 | +}); | |
40 | + | |
41 | +global.MODEM_PORT = port; | |
42 | +parsers.setPort(port); | |
43 | +modemCommands.setPort(port); | |
44 | +port.pipe(parsers.parserReadline); |
lib/modem-commands/index.js