modem-info.js
1.42 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
45
46
const DEFAULT_MAX_LAST_DATA_AGE_MS = 2 * 60 * 1000;
const DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS = 30 * 1000;
const config = require('komodo-sdk/config');
const logger = require('komodo-sdk/logger');
const modemInfo = {
device: config.modem.device,
manufacturer: null,
model: null,
imei: null,
imsi: null,
cops: null,
networkId: null,
networkName: null,
signalStrength: null,
signalStrengthTs: null,
signalStrengthTsReadable: null,
startTime: new Date(),
lastWriteTs: null,
lastReadTs: null,
};
if (!config.disable_idle_check) {
const intervalBeetwenCheckMs = config.interval_beetwen_signal_strength_ms
|| DEFAULT_INTERVAL_BETWEEN_IDLE_CHECK_MS;
logger.info('Registering idle / stuck modem background check', { intervalBeetwenCheckMs });
setInterval(() => {
const deltaMs = new Date() - Math.max(
modemInfo.startTime,
Math.min(modemInfo.lastWriteTs, modemInfo.lastReadTs),
);
const maxLastDataAgeMs = config.max_last_data_age_ms || DEFAULT_MAX_LAST_DATA_AGE_MS;
if (deltaMs >= maxLastDataAgeMs) {
logger.warn(`Modem idle for more than ${maxLastDataAgeMs} ms. Stucked modem? Terminating!`, { deltaMs });
process.exit(1);
}
}, intervalBeetwenCheckMs);
} else {
logger.info('Skip idle / stuck modem background check by config.disable_idle_check');
}
module.exports = modemInfo;