Commit c428dcf05aeaf8daf22f268390c601c0d9fc8814

Authored by Adhidarma Hadiwinoto
1 parent bc541e414d
Exists in master

More information about modem

Showing 1 changed file with 62 additions and 0 deletions Side-by-side Diff

... ... @@ -15,6 +15,8 @@ const common = require('./common');
15 15 const sms = require('./sms');
16 16  
17 17 const modemInfo = {
  18 + manufacturer: null,
  19 + model: null,
18 20 imsi: null,
19 21 signalStrength: null,
20 22 };
... ... @@ -96,6 +98,22 @@ parserWaitForOK.on('data', () => {
96 98 mutex.releaseLockWaitForOK();
97 99 });
98 100  
  101 +function simpleCommand(cmd, callback) {
  102 + const parser = new ParserDelimiter({ delimiter: DELIMITER_WAIT_FOR_OK });
  103 + parser.on('data', (data) => {
  104 + port.unpipe(parser);
  105 + mutex.releaseLockWaitForOK();
  106 +
  107 + if (data) {
  108 + callback(null, data.toString().trim());
  109 + }
  110 + });
  111 +
  112 + port.pipe(parser);
  113 + writeToPortAndWaitForOK(cmd);
  114 +}
  115 +
  116 +/*
99 117 async function readIMSI() {
100 118 logger.info('Querying IMSI');
101 119 const parserReadIMSI = new ParserDelimiter({ delimiter: DELIMITER_WAIT_FOR_OK });
... ... @@ -116,6 +134,47 @@ async function readIMSI() {
116 134 port.unpipe(parserReadIMSI);
117 135 mutex.releaseLockWaitForCommand();
118 136 }
  137 +*/
  138 +
  139 +function readManufacturer() {
  140 + return new Promise((resolve) => {
  141 + simpleCommand('AT+CGMI\r', (err, result) => {
  142 + modemInfo.manufacturer = result;
  143 + logger.info(`Manufacturer: ${result}`);
  144 + resolve(result);
  145 + });
  146 + });
  147 +}
  148 +
  149 +function readModel() {
  150 + return new Promise((resolve) => {
  151 + simpleCommand('AT+CGMM\r', (err, result) => {
  152 + modemInfo.model = result;
  153 + logger.info(`Model: ${result}`);
  154 + resolve(result);
  155 + });
  156 + });
  157 +}
  158 +
  159 +function readIMEI() {
  160 + return new Promise((resolve) => {
  161 + simpleCommand('AT+CGSN\r', (err, result) => {
  162 + modemInfo.imei = result;
  163 + logger.info(`IMEI: ${result}`);
  164 + resolve(result);
  165 + });
  166 + });
  167 +}
  168 +
  169 +function readIMSI() {
  170 + return new Promise((resolve) => {
  171 + simpleCommand('AT+CIMI\r', (err, result) => {
  172 + modemInfo.imsi = result;
  173 + logger.info(`IMSI: ${result}`);
  174 + resolve(result);
  175 + });
  176 + });
  177 +}
119 178  
120 179 async function querySignalStrength() {
121 180 port.pipe(parserWaitForOK);
... ... @@ -166,6 +225,9 @@ function init() {
166 225 logger.info('Deleting existing messages');
167 226 // await writeToPortAndWaitForOK('AT+CMGD=0,4\r');
168 227  
  228 + await readManufacturer();
  229 + await readModel();
  230 + await readIMEI();
169 231 await readIMSI();
170 232  
171 233 port.unpipe(parserWaitForOK);