-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marvin Villegas
committed
Jul 30, 2020
1 parent
4fbdfb7
commit 84a33b8
Showing
8 changed files
with
1,061 additions
and
32,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import axios from 'axios' | ||
import md5 from 'md5' | ||
import moment from 'moment' | ||
|
||
const date = new Date() | ||
const today = moment(date).add(8, 'hours').format('YYYY-MM-DD HH:mm:ss') | ||
|
||
export default class Olrms { | ||
constructor() { | ||
this.authorization = md5('olrmsgps') | ||
this.url = 'http://gps.olrms.com/gps/getdeviceinfo' | ||
} | ||
parseGprs({ data }) { | ||
if (data) { | ||
const gps = data.split(',') | ||
const imei = gps[1] || '' | ||
if (imei) { | ||
const lat = gps[4] || '' | ||
const lng = gps[5] || '' | ||
const network = gps[16] || '' | ||
|
||
const networkData = network.split('|') | ||
const mcc = networkData[0] || '' | ||
const mnc = networkData[1] || '' | ||
|
||
return { | ||
imei: imei, | ||
lat: lat, | ||
lng: lng, | ||
mcc: mcc, | ||
mnc: mnc, | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
createGpsData({ data }) { | ||
const gprs = this.parseGprs({ data }) | ||
if (gprs) { | ||
return { | ||
device_info: { | ||
batt_level: '', | ||
dt: [ | ||
{ | ||
date_time: today, | ||
}, | ||
], | ||
imei: gprs.imei, | ||
laccid: [ | ||
{ | ||
lac: 0, | ||
cid: 0, | ||
}, | ||
], | ||
latlng: [ | ||
{ | ||
lat: gprs.lat, | ||
lng: gprs.lng, | ||
}, | ||
], | ||
mac_address: gprs.imei, | ||
mcc: gprs.mcc, | ||
mnc: gprs.mnc, | ||
}, | ||
} | ||
} | ||
|
||
return false | ||
} | ||
async sendToApi({ data }) { | ||
const payLoad = this.createGpsData({ data }) | ||
try { | ||
if (payLoad) { | ||
const response = await axios({ | ||
method: 'POST', | ||
headers: { | ||
Auth: this.authorization, | ||
'Content-Type': 'application/json', | ||
}, | ||
data: payLoad, | ||
url: this.url, | ||
}) | ||
if (response.status !== 200) { | ||
console.error(`Status: ${response.status}`) | ||
return false | ||
} | ||
console.log(response.data) | ||
return true | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
'use strict' | ||
|
||
const net = require('net') | ||
import net from 'net' | ||
import Olrms from './api/Olrms.js' | ||
|
||
const hostname = '127.0.0.1' | ||
const port = 43552 | ||
const olrms = new Olrms() | ||
const port = 43556 | ||
|
||
const app = net.createServer(function(socket) { | ||
let remoteAddress = socket.remoteAddress | ||
let remotePort = socket.remotePort | ||
const app = net.createServer((socket) => { | ||
const remoteAddress = socket.remoteAddress | ||
const remotePort = socket.remotePort | ||
|
||
console.log(`CONNECTED: ${remoteAddress}:${remotePort}`) | ||
socket.setEncoding('utf8') | ||
|
||
socket.on('data', function(data) { | ||
console.log(`${data}`) | ||
socket.on('data', (data) => { | ||
olrms.sendToApi({ data }) | ||
}) | ||
|
||
socket.write(`Server Reply`) | ||
socket.pipe(socket) | ||
}) | ||
|
||
app.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`) | ||
app.listen(port, () => { | ||
console.log(`Server running at ${port}`) | ||
}) | ||
|
||
module.exports = app | ||
export default app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Set options as a parameter, environment variable, or rc file. | ||
require = require('esm')(module /*, options*/) | ||
module.exports = require('./app.js') |
Oops, something went wrong.