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