-
Notifications
You must be signed in to change notification settings - Fork 1
/
box.old.js
162 lines (139 loc) · 4.93 KB
/
box.old.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var log = require("noogger");
let serialportgsm = require('serialport-gsm');
let modem = serialportgsm.Modem();
const ussd = require('serialport-gsm/lib/functions/ussd');
ussd(modem);
let serialport = serialportgsm.serialport;
let options = {
baudRate: 115200,
dataBits: 8,
stopBits: 1,
parity: 'none',
rtscts: false,
xon: false,
xoff: false,
xany: false,
autoDeleteOnReceive: true,
enableConcatenation: true,
incomingCallIndication: true,
incomingSMSIndication: true,
pin: '',
customInitCommand: ''
};
modem.open('COM15', options);
modem.on('open', data => {
modem.initializeModem(function (initResult) {
if (initResult.status != 'success') {
console.log(initResult);
} else {
// modem.sendUSSD('*101#').then(
// (success) => {
// console.log(success)
// },
// (fail) => {
// console.log(fail)
// }
// );
sendUSSD("*444#","COM15");
sendUSSD("*160#","COM15");
modem.on('onNewMessage', function (data) {
log.warning("NEW MESSAGE");
log.debug(data);
{
id: "NA",
port: data.GsmSpan,
sender: data.sender,
time: data.dateTimeSent,
index: data.index,
total: data.Total,
content: data.message
smsc: data.smsc
}
});
modem.on('onMemoryFull', (result) => {
log.warning("MEM FULLL");
log.debug(result);
});
// modem.getSimInbox((result) => {
// log.warning("SIM INBOX");
// log.debug(result);
// });
modem.on('onSendingMessage', result => {
log.warning("SENDING MSG");
log.debug(result);
});
modem.sendSMS('+22652004896', 'Hello there Zab!', false, null, function(data) {
log.debug(data);
});
}
});
});
function sendUSSD(USSD,port) {
log.warning("sending USSD");
// let modem= getModem(port);
let commandParser = modem.executeCommand('AT+CUSD=1,"'+USSD+'"', (result, err) => {
if (err) {
console.log(`Error`, err);
} else {
console.log(result);
if(result.status == 'success') {
log.warning(commandParser.result);
}
else log.error(commandParser.result);
}
});
commandParser.result = {};
commandParser.logic = dataLine => {
log.critical(dataLine);
if (dataLine) {
if (dataLine.startsWith("AT+CUSD=1")) {
commandParser.result.command = dataLine.trim();
} else if (dataLine.startsWith("+CUSD: 0,") ) {
let startIdx= dataLine.indexOf('"')+1;
let length= dataLine.indexOf('"', dataLine.length-5) - startIdx;
log.notice("startIdx= "+startIdx +" length= "+ length);
commandParser.result.content = dataLine.substr(startIdx, length);
commandParser.result.response = dataLine.trim();
}
if( dataLine.endsWith('+CUSD: 0, "MSISDN:') ) {
commandParser.result.content = "--MSISDN:"
commandParser.result.response = '+CUSD: 0, "MSISDN:';
}
if( dataLine.endsWith('", 15') && commandParser.result.content == "--MSISDN:") {
commandParser.result.content = "MSISDN: " + dataLine.replace('", 15','');
commandParser.result.response = '+CUSD: 0, "MSISDN:'+ dataLine;
}
}
if (dataLine.endsWith('15')) {
return {
resultData: {
status: 'success',
request: 'executeCommand',
data: commandParser.result
},
returnResult: true,
};
} else if (dataLine.includes('+CUSD: 2') || dataLine.includes('COMMAND NOT SUPPORT')) {
return {
resultData: {
status: 'failed',
request: 'executeCommand',
data: `Execute Command returned Error: ${dataLine}`,
},
returnResult: true,
};
}
};
}
// modem.on('onNewMessage', function (data) {
// log.debug(data);
// });
// modem.on('onNewMessageIndicator', (data) => {
// log.debug(data);
// });
modem.on('close', data => {
log.warning(" Modem closed\nReason: "+data);
});
modem.on('error', data => {
log.error(" ERROR: "+ data);
});