Commit e07d18058ff73f7ad9e6a6fb53a2975727a99f01
1 parent
9de643e330
Exists in
master
Code cleanup
Showing 4 changed files with 5 additions and 31 deletions Side-by-side Diff
config.sample.json
lib/modem.js
1 | 1 | 'use strict'; |
2 | 2 | |
3 | +const DEFAULT_SLEEP_AFTER_SEND_SMS_MS = 2000; | |
3 | 4 | const INTERVAL_BEETWEN_SIGNAL_STRENGTH_MS = 60000; |
4 | 5 | const MAX_LAST_DATA_AGE_MS = 3 * 60 * 1000; |
5 | 6 | const REGEX_WAIT_FOR_OK_OR_ERROR = /\n(?:OK|ERROR)\r/; |
... | ... | @@ -20,9 +21,7 @@ const common = require('./common'); |
20 | 21 | const sms = require('./sms'); |
21 | 22 | const dbCops = require('./db-cops'); |
22 | 23 | const reportSender = require('./report-sender'); |
23 | -// const msisdn = require('./msisdn'); | |
24 | 24 | const registerModem = require('./register-modem'); |
25 | -// const counters = require('./counters'); | |
26 | 25 | |
27 | 26 | const modemInfo = { |
28 | 27 | device: config.modem.device, |
... | ... | @@ -37,8 +36,6 @@ const modemInfo = { |
37 | 36 | signalStrength: null, |
38 | 37 | signalStrengthTs: null, |
39 | 38 | signalStrengthTsReadable: null, |
40 | - // messageSentCounter: null, | |
41 | - // messageReceivedCounter: null, | |
42 | 39 | }; |
43 | 40 | |
44 | 41 | let lastTs = new Date(); |
... | ... | @@ -138,7 +135,6 @@ parserReadLine.on('data', (data) => { |
138 | 135 | registerModem(modemInfo); |
139 | 136 | } |
140 | 137 | } else if (data.indexOf('+CMTI: ') === 0) { |
141 | - // counters.increment('MESSAGE_RECEIVED', modemInfo); | |
142 | 138 | onIncomingSMS(data); |
143 | 139 | } else if (data.indexOf('+COPS: ') === 0) { |
144 | 140 | onCOPS(data); |
... | ... | @@ -282,12 +278,11 @@ async function sendSMS(destination, msg) { |
282 | 278 | logger.verbose('Waiting for command lock to send message'); |
283 | 279 | await mutex.setLockWaitForCommand(); |
284 | 280 | |
285 | - logger.info('Sending message', { destination, msg }); | |
286 | - // counters.increment('MESSAGE_SENT', modemInfo); | |
281 | + logger.info('Preparing to send message', { destination, msg }); | |
287 | 282 | |
288 | 283 | const correctedDestination = `+${destination}`.replace(/^0/, '62').replace(/^\++/, '+'); |
289 | 284 | |
290 | - logger.verbose('Waiting for lock before set to text mode'); | |
285 | + logger.verbose('Waiting for lock before set SMS to text mode'); | |
291 | 286 | await mutex.setLockWaitForSubCommand(); |
292 | 287 | port.pipe(parser); |
293 | 288 | await writeToPort('AT+CMGF=1\r'); |
... | ... | @@ -307,7 +302,7 @@ async function sendSMS(destination, msg) { |
307 | 302 | setTimeout(() => { |
308 | 303 | logger.verbose('Releasing command lock'); |
309 | 304 | mutex.releaseLockWaitForCommand(); |
310 | - }, config.wait_for_release_lock_wait_for_command_ms || 2000); | |
305 | + }, config.sleep_after_send_sms_ms || DEFAULT_SLEEP_AFTER_SEND_SMS_MS); | |
311 | 306 | } |
312 | 307 | |
313 | 308 | /** |
lib/msisdn.js
... | ... | @@ -1,10 +0,0 @@ |
1 | -'use strict'; | |
2 | - | |
3 | -const fs = require('fs'); | |
4 | -const logger = require('komodo-sdk/logger'); | |
5 | - | |
6 | -const db = fs.existsSync('db-msisdn.json') || fs.existsSync('db-msisdn.js') ? require('../db-msisdn') : {}; | |
7 | - | |
8 | -logger.info(`MSISDN database loaded with ${Object.keys(db).length}.`); | |
9 | - | |
10 | -module.exports = db; |
lib/register-modem.js
... | ... | @@ -8,8 +8,6 @@ const locks = require('locks'); |
8 | 8 | const config = require('komodo-sdk/config'); |
9 | 9 | const logger = require('komodo-sdk/logger'); |
10 | 10 | |
11 | -// const counters = require('./counters'); | |
12 | - | |
13 | 11 | const mutex = locks.createMutex(); |
14 | 12 | |
15 | 13 | function reportUrl() { |
... | ... | @@ -23,13 +21,6 @@ function reportUrl() { |
23 | 21 | |
24 | 22 | function sender(modemInfo) { |
25 | 23 | if (mutex.tryLock()) { |
26 | - // logger.info('Getting message counters before registering modem'); | |
27 | - | |
28 | - // eslint-disable-next-line no-param-reassign | |
29 | - // modemInfo.messageSentCounter = await counters.get('MESSAGE_SENT', modemInfo); | |
30 | - // eslint-disable-next-line no-param-reassign | |
31 | - // modemInfo.messageReceivedCounter = await counters.get('MESSAGE_RECEIVED', modemInfo); | |
32 | - | |
33 | 24 | const requestOptions = { |
34 | 25 | url: reportUrl(), |
35 | 26 | qs: { |
... | ... | @@ -44,8 +35,6 @@ function sender(modemInfo) { |
44 | 35 | report_port: config.http_command_server.listen_port, |
45 | 36 | report_apikey: config.http_command_server.apikey, |
46 | 37 | report_path_sms: '/sms', |
47 | - // counter_sent: modemInfo.messageSentCounter, | |
48 | - // counter_received: modemInfo.messageReceivedCounter, | |
49 | 38 | }, |
50 | 39 | }; |
51 | 40 |