-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·41 lines (35 loc) · 1.58 KB
/
index.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
const net = require('net');
const parser_content = require('./parser_content');
net.createServer((connection) => {
connection.on('data', (data) => {
console.log(connection.remoteAddress)
console.log(data);
if (data.length == 17){
let response = Buffer.from('01', 'hex');
let IMEI = data;
IMEI = IMEI.toString().slice(2);
console.log(data.toString());
connection.write(response);
}
else{
let payload = data.slice(0, 8);
let contentlength = payload.slice(4,8);
console.log("payload " + contentlength.readUInt32BE() + "----------------");
console.log(payload);
let content = data.slice(8, contentlength.readUInt32BE());
console.log("content----------------------");
console.log(content);
let information = parser_content(content);
console.log("--------------------------------")
console.log(information);
let latitude = Buffer.allocUnsafe(4);
let longitude = Buffer.allocUnsafe(4);
latitude.writeUInt32BE(information.pop().latitude);
longitude.writeUInt32BE(information.pop().longitude);
latitude = latitude.readInt32BE()/Math.pow(10,7);
longitude = longitude.readInt32BE()/Math.pow(10,7);
console.log(`latitude: ${latitude} | longitude: ${longitude}`);
connection.write(Buffer.from("00000002", 'hex'));
}
});
}).listen(12000, '0.0.0.0');