update from server
47
.env
@ -1,43 +1,21 @@
|
|||||||
# APP CONFIG
|
|
||||||
PORT=6014
|
PORT=6014
|
||||||
PORT_EXPRESS=3400
|
PORT_EXPRESS=3400
|
||||||
PORT_UDP=20203
|
PORT_UDP=20203
|
||||||
# NODE_ENV=development
|
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
API_VERSION=1
|
API_VERSION=1
|
||||||
PATH_URL=/tracking
|
PATH_URL=/tracking
|
||||||
TZ=Asia/Jakarta
|
TZ=Asia/Jakarta
|
||||||
|
|
||||||
# DATABASE CONFIG
|
|
||||||
# CONNECTIONLIMIT=10
|
|
||||||
# # DBHOST=149.129.214.64
|
|
||||||
# DBHOST=8.215.31.239
|
|
||||||
# DBUSER=root
|
|
||||||
# DBPASSWORD=vYR/+QHD4lJ8y/v2
|
|
||||||
# DATABASE=db_trucking
|
|
||||||
# ACQRTIMEOUT=10000
|
|
||||||
|
|
||||||
# DATABASE CONFIG BONCENG(mariadb)
|
|
||||||
# CONNECTIONLIMIT=10
|
|
||||||
# DBHOST=147.139.133.230
|
|
||||||
# DBUSER=boncengdball
|
|
||||||
# DBPASSWORD=rtzL8NI4TchNNwu7
|
|
||||||
# DATABASE=db_trucking
|
|
||||||
# ACQRTIMEOUT=10000
|
|
||||||
|
|
||||||
# DATABASE CONFIG BONCENG(mariadb 10.7)
|
|
||||||
CONNECTIONLIMIT=10
|
CONNECTIONLIMIT=10
|
||||||
DBHOST=127.0.0.1
|
DBHOST=172.16.140.45
|
||||||
DBUSER=root
|
DBPORT=3306
|
||||||
DBPASSWORD=root
|
DBUSER=remote
|
||||||
DATABASE=db_fleet
|
DBPASSWORD=L8q@Rz!1Yk#mWu3B
|
||||||
|
DATABASE=gps_tracker_db
|
||||||
ACQRTIMEOUT=10000
|
ACQRTIMEOUT=10000
|
||||||
|
|
||||||
# REDIS CONFIG
|
#REDIS_HOST=redis
|
||||||
# if using local system
|
REDIS_HOST=localhost
|
||||||
# REDIS_HOST=localhost
|
|
||||||
# if using docker
|
|
||||||
REDIS_HOST=redis
|
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode
|
REDIS_SCHEDULER_REVERSE_GEO=scheduleReverseGeocode
|
||||||
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder
|
REDIS_QUEUE_BLAST_ORDER=queueBlastOrder
|
||||||
@ -47,22 +25,15 @@ REDIS_SCHEDULER_DRV_UP_LOC_IDLE=scheduleDrvUpLocIdle
|
|||||||
REDIS_SCHEDULER_DRV_BLAST_NOTIF=schedulerDrvBlastNotif
|
REDIS_SCHEDULER_DRV_BLAST_NOTIF=schedulerDrvBlastNotif
|
||||||
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp
|
REDIS_SCHEDULER_GPS_TRACKER_WAKEUP=schedulerGpsTrackerWakeUp
|
||||||
|
|
||||||
# SMTP MAILTRAP RAFIF
|
|
||||||
SMTP_HOST=smtp.mailtrap.io
|
SMTP_HOST=smtp.mailtrap.io
|
||||||
SMTP_PORT=2525
|
SMTP_PORT=2525
|
||||||
SMTP_USER=e9aace0ebb3398
|
SMTP_USER=e9aace0ebb3398
|
||||||
SMTP_PASW=c8f9ccee5122d6
|
SMTP_PASW=c8f9ccee5122d6
|
||||||
SMTP_FROM=rafifrest@gmail.com
|
SMTP_FROM=rafifrest@gmail.com
|
||||||
|
|
||||||
# SMTP BONCENG NO REPLY
|
PROXY_URL=172.16.128.214
|
||||||
# SMTP_HOST=bagaspati.iixcp.rumahweb.com
|
PROXY_PORT=8080
|
||||||
# SMTP_PORT=465
|
|
||||||
# SMTP_USER=non-reply@bonceng-indonesia.com
|
|
||||||
# SMTP_PASW=eGgKSpJAuv1p
|
|
||||||
# SMTP_FROM=non-reply@bonceng-indonesia.com
|
|
||||||
|
|
||||||
# SCHEDULER BULLMQ CONFIG (CUSTOM)
|
|
||||||
# sekali jalan maximal looping
|
|
||||||
SCHEDULE_REVERSE_GEO_MAX_LOOP=10
|
SCHEDULE_REVERSE_GEO_MAX_LOOP=10
|
||||||
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
SCHEDULE_REVERSE_GEO_TIME=*/2 * * * *
|
||||||
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
SCHEDULE_DRV_UP_LOC_MAX_LOOP=1
|
||||||
|
|||||||
0
.env.example
Normal file → Executable file
2
.gitignore
vendored
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
logs/
|
logs/
|
||||||
# .env
|
.env
|
||||||
# .env.*
|
# .env.*
|
||||||
.vscode
|
.vscode
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
0
Dockerfile
Normal file → Executable file
0
Message Notifikasi Apps Driver Tracker.xlsx
Normal file → Executable file
6
app.js
Normal file → Executable file
@ -1,5 +1,6 @@
|
|||||||
require('dotenv').config({ path: '.env' });
|
require('dotenv').config({ path: '.env' });
|
||||||
require('events').EventEmitter.prototype._maxListeners = 30;
|
require('events').EventEmitter.prototype._maxListeners = 30;
|
||||||
|
const morgan = require('morgan');
|
||||||
// start for gps-tracking
|
// start for gps-tracking
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
@ -16,7 +17,7 @@ const nanoid = require('nanoid').nanoid;
|
|||||||
|
|
||||||
// start for normal http request
|
// start for normal http request
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const LibBullAdapter = require('./library/LibBullAdapter');
|
// const LibBullAdapter = require('./library/LibBullAdapter');
|
||||||
const routes = require('./routes/routes');
|
const routes = require('./routes/routes');
|
||||||
// const routes = require('./routes/routes_without_scheduler');
|
// const routes = require('./routes/routes_without_scheduler');
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -465,6 +466,7 @@ net.createServer({
|
|||||||
// end for gps-tracking TCP ONLY
|
// end for gps-tracking TCP ONLY
|
||||||
|
|
||||||
// start for normal http request
|
// start for normal http request
|
||||||
|
app.use(morgan('combined'));
|
||||||
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
app.use(express.json({ limit: '10mb' })); // parsing application/json
|
||||||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // parsing application/x-www-form-urlencoded
|
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // parsing application/x-www-form-urlencoded
|
||||||
app.use(async function (req, res, next) {
|
app.use(async function (req, res, next) {
|
||||||
@ -474,7 +476,7 @@ app.use(async function (req, res, next) {
|
|||||||
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-api-key, x-forwarded-for');
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
// app.use(process.env.PATH_URL + '/bull/monitor', LibBullAdapter.getRouter());
|
||||||
routes.use(app);
|
routes.use(app);
|
||||||
app.listen(process.env.PORT_EXPRESS, () => {
|
app.listen(process.env.PORT_EXPRESS, () => {
|
||||||
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
console.log('Express server running at port ' + process.env.PORT_EXPRESS);
|
||||||
|
|||||||
0
app.js.express
Normal file → Executable file
0
app.js.gps
Normal file → Executable file
0
app_dev_restapi.js
Normal file → Executable file
0
app_scheduler.js
Normal file → Executable file
0
backup/.gitignore
vendored
Normal file → Executable file
1
config/dbMysqlConn.js
Normal file → Executable file
@ -3,6 +3,7 @@ const mysql = require('mysql');
|
|||||||
const pool = mysql.createPool({
|
const pool = mysql.createPool({
|
||||||
connectionLimit: process.env.CONNECTIONLIMIT,
|
connectionLimit: process.env.CONNECTIONLIMIT,
|
||||||
host: process.env.DBHOST,
|
host: process.env.DBHOST,
|
||||||
|
port: process.env.DBPORT,
|
||||||
user: process.env.DBUSER,
|
user: process.env.DBUSER,
|
||||||
password: process.env.DBPASSWORD,
|
password: process.env.DBPASSWORD,
|
||||||
database: process.env.DATABASE,
|
database: process.env.DATABASE,
|
||||||
|
|||||||
0
config/netConn.js
Normal file → Executable file
0
config/request.js
Normal file → Executable file
0
config/response.js
Normal file → Executable file
0
controllers/AuthController.js
Normal file → Executable file
0
controllers/DummyController.js
Normal file → Executable file
421
controllers/ListenController.js
Normal file
@ -0,0 +1,421 @@
|
|||||||
|
const moment = require("moment");
|
||||||
|
const Validator = require("validatorjs");
|
||||||
|
const Helper = require("../library/LibHelper");
|
||||||
|
const response = require("../config/response");
|
||||||
|
const LibMail = require("../library/LibMail");
|
||||||
|
const LibDevice = require("../library/LibDevice");
|
||||||
|
const DanaModels = require("../models/DanaModels");
|
||||||
|
const GpsTracksModels = require("../models/GpsTracksModels");
|
||||||
|
const { nanoid } = require("nanoid");
|
||||||
|
const VhcModels = require("../models/VhcModels");
|
||||||
|
const ZoneModels = require("../models/ZoneModels");
|
||||||
|
const LibHelper = require("../library/LibHelper");
|
||||||
|
|
||||||
|
// const LibQueueBlastOrder = require('../library/LibQueueBlastOrder');
|
||||||
|
Validator.useLang("en");
|
||||||
|
|
||||||
|
const devices = [];
|
||||||
|
|
||||||
|
async function commitMessage(now, logDevice) {
|
||||||
|
try {
|
||||||
|
// don't log
|
||||||
|
if (!logDevice.original_hex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// in the future don't log to db if device_id not found in vhc
|
||||||
|
const vhc = await VhcModels.getVhcByDeviceId(logDevice.device_id);
|
||||||
|
const lastTrack = await GpsTracksModels.get2LastLocByDeviceId(logDevice.device_id);
|
||||||
|
if (["heartbeat", "alarm"].includes(logDevice.action)) {
|
||||||
|
// set engine stts moving,idling,stopped
|
||||||
|
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
||||||
|
if (logDevice.speed) {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_MOVING;
|
||||||
|
} else {
|
||||||
|
if (lastTrack.length > 0) {
|
||||||
|
const checkLastHeartbeat = await GpsTracksModels.getLastHeartbeatToDeterminIdling(logDevice.device_id, lastTrack[0].crt, now);
|
||||||
|
if (checkLastHeartbeat.length >= 3) {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_IDLING;
|
||||||
|
} else {
|
||||||
|
logDevice.stts_engine = lastTrack[0].stts_engine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_STOPING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// get last ignition, stts_engine, stts_alarm, stts_charge, stts_acc, stts_volt, stts_switch
|
||||||
|
if (["location"].includes(logDevice.action)) {
|
||||||
|
console.log("logDevice:", logDevice);
|
||||||
|
// get last ignition
|
||||||
|
const lastHeartbeatOrAlarm = await GpsTracksModels.get2LastHeartbeatOrAlarm(logDevice.device_id);
|
||||||
|
if (lastHeartbeatOrAlarm.length > 0) {
|
||||||
|
logDevice.ignition = lastHeartbeatOrAlarm[0].ignition;
|
||||||
|
logDevice.stts_gps = lastHeartbeatOrAlarm[0].stts_gps;
|
||||||
|
logDevice.stts_gsm = lastHeartbeatOrAlarm[0].stts_gsm;
|
||||||
|
} else {
|
||||||
|
logDevice.ignition = lastHeartbeatOrAlarm[0].ignition;
|
||||||
|
logDevice.stts_gps = lastHeartbeatOrAlarm[0].stts_gps;
|
||||||
|
logDevice.stts_gsm = lastHeartbeatOrAlarm[0].stts_gsm;
|
||||||
|
}
|
||||||
|
// set engine stts moving,idling,stopped
|
||||||
|
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
||||||
|
if (logDevice.speed) {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_MOVING;
|
||||||
|
} else {
|
||||||
|
if (lastTrack.length > 0) {
|
||||||
|
const checkLastHeartbeat = await GpsTracksModels.getLastHeartbeatToDeterminIdling(logDevice.device_id, lastTrack[0].crt, now);
|
||||||
|
if (checkLastHeartbeat.length >= 3) {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_IDLING;
|
||||||
|
} else {
|
||||||
|
logDevice.stts_engine = lastTrack[0].stts_engine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// get stts_alarm, stts_charge, stts_acc, stts_volt, stts_switch
|
||||||
|
} else {
|
||||||
|
logDevice.stts_engine = GpsTracksModels.STTS_EN_STOPING;
|
||||||
|
}
|
||||||
|
logDevice.stts_oil_electricity = lastHeartbeatOrAlarm[0].stts_oil_electricity;
|
||||||
|
logDevice.stts_alarm = lastHeartbeatOrAlarm[0].stts_alarm;
|
||||||
|
logDevice.stts_charge = lastHeartbeatOrAlarm[0].stts_charge;
|
||||||
|
logDevice.stts_acc = lastHeartbeatOrAlarm[0].stts_acc;
|
||||||
|
logDevice.stts_volt = lastHeartbeatOrAlarm[0].stts_volt;
|
||||||
|
logDevice.stts_switch = lastHeartbeatOrAlarm[0].stts_switch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sekarang heartbeat diinject data lokasi juga dari lokasi terakhir
|
||||||
|
if (["heartbeat"].includes(logDevice.action)) {
|
||||||
|
if (lastTrack.length > 0) {
|
||||||
|
logDevice.latitude = lastTrack[0].latitude;
|
||||||
|
logDevice.longitude = lastTrack[0].longitude;
|
||||||
|
logDevice.speed = lastTrack[0].speed;
|
||||||
|
logDevice.orientation = lastTrack[0].orientation;
|
||||||
|
if (logDevice.latitude) {
|
||||||
|
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
logDevice.length_gps = lastTrack[0].length_gps;
|
||||||
|
logDevice.pos_stlt_gps = lastTrack[0].pos_stlt_gps;
|
||||||
|
logDevice.pos_type_gps = lastTrack[0].pos_type_gps;
|
||||||
|
logDevice.is_pos_gps = lastTrack[0].is_pos_gps;
|
||||||
|
|
||||||
|
// jika gapengen dimunculin di last movement
|
||||||
|
// logDevice.crt = lastTrack[0].crt;
|
||||||
|
// logDevice.crt_format = lastTrack[0].crt_format;
|
||||||
|
// logDevice.crt_d = lastTrack[0].crt_d;
|
||||||
|
// logDevice.crt_d_format = lastTrack[0].crt_d_format;
|
||||||
|
// jika pengen di munculin di last movement
|
||||||
|
logDevice.crt = now;
|
||||||
|
logDevice.crt_format = moment.unix(now).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
logDevice.crt_d = now;
|
||||||
|
logDevice.crt_d_format = moment.unix(now).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// count milleage
|
||||||
|
if (logDevice.latitude != null && logDevice.longitude != null && lastTrack.length > 0) {
|
||||||
|
const distance = LibHelper.haversineGreatCircleDistance(lastTrack[0].latitude, lastTrack[0].longitude, logDevice.latitude, logDevice.longitude, LibHelper.EARTH_RADIUS_KM);
|
||||||
|
const distance_km = LibHelper.kmToKm(distance, 100000000);
|
||||||
|
// console.log(`GPS TRACKER UP LOCATION => device_id:${logDevice.device_id} vhc_id:${(vhc[0]) ? vhc[0].vid : 0}, distance_km:${distance_km}`);
|
||||||
|
// validasi jika lebih dari 3km, ga disimpan
|
||||||
|
if (distance_km >= 3) {
|
||||||
|
GpsTracksModels.bundleCreate2(logDevice, logDevice); // jika tidak disimpan malah jadi bug, jadi akan update lokasi terus dengan kalkulasi jarak sebelumnya jadi makan lama makin lebar, mending disimpen terus milleagenya jadi 0 aja
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
logDevice.pre_milleage = distance_km;
|
||||||
|
logDevice.sum_milleage = (lastTrack[0].sum_milleage + logDevice.pre_milleage).toFixed(8);
|
||||||
|
if (vhc.length > 0) {
|
||||||
|
logDevice.vhc_id = vhc[0] ? vhc[0].vid : 0;
|
||||||
|
if (lastTrack[0].vhc_id == logDevice.vhc_id) {
|
||||||
|
logDevice.vhc_milleage = (lastTrack[0].vhc_milleage + logDevice.pre_milleage).toFixed(8);
|
||||||
|
} else {
|
||||||
|
logDevice.vhc_milleage = (vhc[0] ? vhc[0].sum_milleage : 0 + logDevice.pre_milleage).toFixed(8);
|
||||||
|
}
|
||||||
|
VhcModels.update(vhc[0] ? vhc[0].vid : 0, { sum_milleage: logDevice.vhc_milleage });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// truck zoning spawn
|
||||||
|
if (logDevice.latitude != null && logDevice.longitude != null) {
|
||||||
|
// && vhc.length > 0
|
||||||
|
// log tracking
|
||||||
|
const currTrack = await GpsTracksModels.bundleCreate2(logDevice, logDevice);
|
||||||
|
// console.log('GT06 HAS LOCATION AND CHECK ZONE');
|
||||||
|
const inCircle = await ZoneModels.getInCircle(logDevice.latitude, logDevice.longitude);
|
||||||
|
const inShape = await ZoneModels.getInShape(logDevice.latitude, logDevice.longitude);
|
||||||
|
const insideSpawnZone = [];
|
||||||
|
for (let zone of inCircle) {
|
||||||
|
insideSpawnZone.push(zone);
|
||||||
|
}
|
||||||
|
for (let zone of inShape) {
|
||||||
|
insideSpawnZone.push(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get lastSpawn desc index 0, where leave_at = 0
|
||||||
|
* kalo gaada create, dengan isi field enter_at aja, kalo ada didalam zona
|
||||||
|
* kalo ada update, dengan isi field leave_at aja, kalo udah diluar zona
|
||||||
|
*/
|
||||||
|
const lastSpawn = await GpsTracksModels.listSpawnZone({
|
||||||
|
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||||
|
device_id: logDevice.device_id,
|
||||||
|
vhc_id: vhc[0] ? vhc[0].vid : 0,
|
||||||
|
leave_at_d: 0,
|
||||||
|
order_by: "ORDER BY id DESC",
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (lastSpawn.length > 0) {
|
||||||
|
let is_leave_zone = 1;
|
||||||
|
for (const insideZone of insideSpawnZone) {
|
||||||
|
if (insideZone.zid === lastSpawn[0].zone_id) is_leave_zone = 0;
|
||||||
|
}
|
||||||
|
if (is_leave_zone === 1 && lastSpawn[0].device_id == logDevice.device_id) {
|
||||||
|
GpsTracksModels.updt2SpawnZone(
|
||||||
|
{
|
||||||
|
leave_lat: logDevice.latitude,
|
||||||
|
leave_lng: logDevice.longitude,
|
||||||
|
leave_at_d: logDevice.crt_d || now,
|
||||||
|
leave_at_d_format: moment.unix(logDevice.crt_d || now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
leave_at_s: now,
|
||||||
|
leave_at_s_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
updt: now,
|
||||||
|
updt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
},
|
||||||
|
lastSpawn[0].id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let zone of insideSpawnZone) {
|
||||||
|
let mailData = {
|
||||||
|
pic_name: zone.pic_name,
|
||||||
|
pic_mail: zone.pic_mail,
|
||||||
|
z_name: zone.name,
|
||||||
|
z_type_name: zone.type_name,
|
||||||
|
z_workflow_name: zone.workflow_type_name,
|
||||||
|
shiptocode: zone.shiptocode,
|
||||||
|
z_fulladdress: zone.fulladdress,
|
||||||
|
v_nopol: (vhc[0] ? vhc[0].nopol1 : 0 || "") + (vhc[0] ? vhc[0].nopol2 : 0 || "") + (vhc[0] ? vhc[0].nopol3 : 0 || ""),
|
||||||
|
da_name: vhc[0] ? vhc[0].da_name : 0 || "",
|
||||||
|
da_phone: "+" + (vhc[0] ? vhc[0].da_phone_code : 0 || "") + (vhc[0] ? vhc[0].da_phone : 0 || ""),
|
||||||
|
};
|
||||||
|
// LibMail.sendVhcSpawnZoneMail(`${(vhc[0]) ? vhc[0].nopol1 : 0 || ''}${(vhc[0]) ? vhc[0].nopol2 : 0 || ''}${(vhc[0]) ? vhc[0].nopol3 : 0 || ''} entering zone ${mailData.z_name}`, mailData.pic_mail, mailData);
|
||||||
|
|
||||||
|
if (logDevice.device_id === "0865784052395871") console.log(1234567890);
|
||||||
|
GpsTracksModels.create2SpawnZone({
|
||||||
|
device_id: logDevice.device_id,
|
||||||
|
master_id: Number(currTrack.result.insertId),
|
||||||
|
enter_lat: logDevice.latitude,
|
||||||
|
enter_lng: logDevice.longitude,
|
||||||
|
enter_at_d: logDevice.crt_d || now,
|
||||||
|
enter_at_d_format: moment.unix(logDevice.crt_d || now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
enter_at_s: now,
|
||||||
|
enter_at_s_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
zone_id: zone.zid,
|
||||||
|
zone_name: zone.name,
|
||||||
|
vhc_id: vhc[0] ? vhc[0].vid : 0,
|
||||||
|
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
});
|
||||||
|
if (logDevice.device_id === "0865784052395871") console.log("DISINI");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// log tracking
|
||||||
|
GpsTracksModels.bundleCreate2(logDevice, logDevice);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListenController {
|
||||||
|
async gps(req, res) {
|
||||||
|
let apiRes = {};
|
||||||
|
try {
|
||||||
|
const c = { id: req.body._id };
|
||||||
|
let buffer_req = Buffer.from(req.body.data, "base64");
|
||||||
|
console.log("buffer_req", buffer_req);
|
||||||
|
const now = moment().unix();
|
||||||
|
const me = LibDevice.identifyProtocolFromBuffer(buffer_req);
|
||||||
|
// console.log('app ', buffer_req);
|
||||||
|
|
||||||
|
const logDevice = {
|
||||||
|
original_hex: me.ori_string,
|
||||||
|
protocol: me.protocol_name == "unknown" ? null : me.protocol_name,
|
||||||
|
action: null,
|
||||||
|
device_id: null,
|
||||||
|
latitude: null,
|
||||||
|
longitude: null,
|
||||||
|
speed: null,
|
||||||
|
orientation: 0,
|
||||||
|
ignition: 0,
|
||||||
|
stts_engine: 0,
|
||||||
|
stts_gps: 0,
|
||||||
|
length_gps: 0,
|
||||||
|
pos_stlt_gps: 0,
|
||||||
|
pos_type_gps: 0,
|
||||||
|
is_pos_gps: 0,
|
||||||
|
stts_gsm: 0,
|
||||||
|
stts_oil_electricity: 0,
|
||||||
|
stts_alarm: 0,
|
||||||
|
stts_charge: 0,
|
||||||
|
stts_acc: 0,
|
||||||
|
stts_volt: 0,
|
||||||
|
stts_switch: 0,
|
||||||
|
stts_reverse_geo: 0,
|
||||||
|
pre_milleage: 0,
|
||||||
|
source: GpsTracksModels.SOURCE_GPS_TRACKER,
|
||||||
|
vhc_id: 0,
|
||||||
|
drv_id: 0,
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
crt_d: 0,
|
||||||
|
crt_d_format: null,
|
||||||
|
crt_s: now,
|
||||||
|
crt_s_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (me.protocol_name == "gt06") {
|
||||||
|
// const act = LibDevice.gt06Action(me, device.device_id || null);
|
||||||
|
let dvc_id = devices[c.id];
|
||||||
|
const act = LibDevice.gt06Action(me, dvc_id || null);
|
||||||
|
|
||||||
|
if (act.action_type == "login") {
|
||||||
|
logDevice.action = act.action_type;
|
||||||
|
logDevice.device_id = act.device_id;
|
||||||
|
|
||||||
|
devices[c.id] = act.device_id;
|
||||||
|
// netConn[act.device_id] = c;
|
||||||
|
if (typeof act.buffer_resp != "undefined") {
|
||||||
|
// c.write(act.buffer_resp);
|
||||||
|
}
|
||||||
|
} else if (act.action_type == "location") {
|
||||||
|
logDevice.action = act.action_type;
|
||||||
|
logDevice.device_id = act.device_id;
|
||||||
|
|
||||||
|
logDevice.latitude = act.gps_data.latitude || null;
|
||||||
|
logDevice.longitude = act.gps_data.longitude || null;
|
||||||
|
logDevice.speed = act.gps_data.speed;
|
||||||
|
logDevice.orientation = act.gps_data.orientation;
|
||||||
|
if (logDevice.latitude) {
|
||||||
|
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
logDevice.length_gps = act.gps_data.quantity_pos_satellites_c;
|
||||||
|
logDevice.pos_stlt_gps = act.gps_data.quantity_pos_satellites_b;
|
||||||
|
logDevice.pos_type_gps = Number(act.gps_data.realtime_dif_gps) === 0 ? GpsTracksModels.STTS_POS_TYPE_GPS_RLTM : GpsTracksModels.STTS_POS_TYPE_GPS_DIFF;
|
||||||
|
logDevice.is_pos_gps = Number(act.gps_data.positioning_gps) ? GpsTracksModels.STTS_IS_POS_GPS_HAS : GpsTracksModels.STTS_IS_POS_GPS_NOT;
|
||||||
|
|
||||||
|
logDevice.crt = moment(act.gps_data.date).unix();
|
||||||
|
logDevice.crt_format = moment(act.gps_data.date).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
logDevice.crt_d = moment(act.gps_data.date).unix();
|
||||||
|
logDevice.crt_d_format = moment(act.gps_data.date).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
} else if (act.action_type == "heartbeat") {
|
||||||
|
logDevice.action = act.action_type;
|
||||||
|
logDevice.device_id = act.device_id;
|
||||||
|
|
||||||
|
logDevice.ignition = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_IGNITION_HIGH : GpsTracksModels.STTS_IGNITION_LOW;
|
||||||
|
logDevice.stts_gps = act.stts_data.terminal_info.gps_tracking ? GpsTracksModels.STTS_GPS_ON : GpsTracksModels.STTS_GPS_OFF; // 1=>on, 2=>off
|
||||||
|
logDevice.stts_gsm = Number(act.stts_data.gsm_signal_strength) + 1; // 1=>no signal, n>1=>get signal
|
||||||
|
|
||||||
|
logDevice.stts_oil_electricity = Number(act.stts_data.terminal_info.oil_electricity) === 0 ? GpsTracksModels.STTS_OIL_ELECTRIC_ON : GpsTracksModels.STTS_OIL_ELECTRIC_OFF; // 1=>on, 2=>off
|
||||||
|
|
||||||
|
let stts_alarm = Number(act.stts_data.terminal_info.stts);
|
||||||
|
if (stts_alarm == 0) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_NORMAL;
|
||||||
|
} else if (stts_alarm == 1) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SHOCK;
|
||||||
|
} else if (stts_alarm == 2) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_POWER_CUT;
|
||||||
|
} else if (stts_alarm == 3) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_LOW_BATTERY;
|
||||||
|
} else if (stts_alarm == 4) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
logDevice.stts_charge = Number(act.stts_data.terminal_info.charge) ? GpsTracksModels.STTS_CHARGE_ON : GpsTracksModels.STTS_CHARGE_OFF;
|
||||||
|
logDevice.stts_acc = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_ACC_HIGH : GpsTracksModels.STTS_ACC_LOW;
|
||||||
|
logDevice.stts_switch = Number(act.stts_data.terminal_info.is_active) ? GpsTracksModels.STTS_SWITCH_ON : GpsTracksModels.STTS_SWITCH_OFF;
|
||||||
|
logDevice.stts_volt = Number(act.stts_data.voltage_level) + 1;
|
||||||
|
|
||||||
|
if (typeof act.buffer_resp != "undefined") {
|
||||||
|
// c.write(act.buffer_resp);
|
||||||
|
}
|
||||||
|
} else if (act.action_type == "alarm") {
|
||||||
|
logDevice.action = act.action_type;
|
||||||
|
logDevice.device_id = act.device_id;
|
||||||
|
|
||||||
|
logDevice.latitude = act.gps_data.latitude || null;
|
||||||
|
logDevice.longitude = act.gps_data.longitude || null;
|
||||||
|
logDevice.speed = act.gps_data.speed;
|
||||||
|
logDevice.orientation = act.gps_data.orientation;
|
||||||
|
if (logDevice.latitude) {
|
||||||
|
logDevice.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
logDevice.length_gps = act.gps_data.quantity_pos_satellites_c;
|
||||||
|
logDevice.pos_stlt_gps = act.gps_data.quantity_pos_satellites_b;
|
||||||
|
logDevice.pos_type_gps = Number(act.gps_data.realtime_dif_gps) === 0 ? GpsTracksModels.STTS_POS_TYPE_GPS_RLTM : GpsTracksModels.STTS_POS_TYPE_GPS_DIFF;
|
||||||
|
logDevice.is_pos_gps = Number(act.gps_data.positioning_gps) ? GpsTracksModels.STTS_IS_POS_GPS_HAS : GpsTracksModels.STTS_IS_POS_GPS_NOT;
|
||||||
|
|
||||||
|
logDevice.ignition = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_IGNITION_HIGH : GpsTracksModels.STTS_IGNITION_LOW;
|
||||||
|
logDevice.stts_gps = act.stts_data.terminal_info.gps_tracking ? GpsTracksModels.STTS_GPS_ON : GpsTracksModels.STTS_GPS_OFF; // 1=>on, 2=>off
|
||||||
|
logDevice.stts_gsm = Number(act.stts_data.gsm_signal_strength) + 1; // 1=>no signal, n>1=>get signal
|
||||||
|
|
||||||
|
logDevice.stts_oil_electricity = Number(act.stts_data.terminal_info.oil_electricity) === 0 ? GpsTracksModels.STTS_OIL_ELECTRIC_ON : GpsTracksModels.STTS_OIL_ELECTRIC_OFF; // 1=>on, 2=>off
|
||||||
|
|
||||||
|
let stts_alarm = Number(act.stts_data.terminal_info.stts);
|
||||||
|
if (stts_alarm == 0) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_NORMAL;
|
||||||
|
} else if (stts_alarm == 1) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SHOCK;
|
||||||
|
} else if (stts_alarm == 2) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_POWER_CUT;
|
||||||
|
} else if (stts_alarm == 3) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_LOW_BATTERY;
|
||||||
|
} else if (stts_alarm == 4) {
|
||||||
|
logDevice.stts_alarm = GpsTracksModels.STTS_ALARM_SOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
logDevice.stts_charge = Number(act.stts_data.terminal_info.charge) ? GpsTracksModels.STTS_CHARGE_ON : GpsTracksModels.STTS_CHARGE_OFF;
|
||||||
|
logDevice.stts_acc = Number(act.stts_data.terminal_info.acc) ? GpsTracksModels.STTS_ACC_HIGH : GpsTracksModels.STTS_ACC_LOW;
|
||||||
|
logDevice.stts_switch = Number(act.stts_data.terminal_info.is_active) ? GpsTracksModels.STTS_SWITCH_ON : GpsTracksModels.STTS_SWITCH_OFF;
|
||||||
|
logDevice.stts_volt = Number(act.stts_data.voltage_level) + 1;
|
||||||
|
|
||||||
|
logDevice.crt = moment(act.gps_data.date).unix();
|
||||||
|
logDevice.crt_format = moment(act.gps_data.date).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
logDevice.crt_d = moment(act.gps_data.date).unix();
|
||||||
|
logDevice.crt_d_format = moment(act.gps_data.date).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
|
||||||
|
if (typeof act.buffer_resp != "undefined") {
|
||||||
|
// c.write(act.buffer_resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// act.action_type == 'other'
|
||||||
|
else {
|
||||||
|
logDevice.action = act.action_type;
|
||||||
|
logDevice.device_id = act.device_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await commitMessage(now, logDevice);
|
||||||
|
|
||||||
|
apiRes = JSON.parse(JSON.stringify(response[200]));
|
||||||
|
apiRes.meta.message = "success";
|
||||||
|
apiRes.data = logDevice;
|
||||||
|
return res.status(200).json(apiRes);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("error", e);
|
||||||
|
apiRes = JSON.parse(JSON.stringify(response[500]));
|
||||||
|
apiRes.meta.message += Helper.setErrMsg(": " + e.message);
|
||||||
|
return res.status(500).json(apiRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const object = new ListenController();
|
||||||
|
|
||||||
|
module.exports = object;
|
||||||
0
controllers/OrderController.js
Normal file → Executable file
0
controllers/ServiceDriverController.js
Normal file → Executable file
0
controllers/WorkerController.js
Normal file → Executable file
0
controllers/ZoneController.js
Normal file → Executable file
274
cron/ReverseGeocodeWorker.js
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
require("dotenv").config({ path: "../.env" })
|
||||||
|
const LibWinston = require("../library/LibWinston")
|
||||||
|
const moment = require("moment")
|
||||||
|
const axios = require("axios").default
|
||||||
|
const url = require("url")
|
||||||
|
const request = require("../config/request")
|
||||||
|
const GpsTracksModels = require("../models/GpsTracksModels")
|
||||||
|
const RegionModels = require("../models/RegionModels")
|
||||||
|
|
||||||
|
const schedulerName = process.env.REDIS_SCHEDULER_REVERSE_GEO
|
||||||
|
const Logger = LibWinston.initialize(schedulerName)
|
||||||
|
|
||||||
|
const go = async () => {
|
||||||
|
try {
|
||||||
|
Logger.log("info", `${schedulerName} running: ${moment().format("YYYY-MM-DD HH:mm:ss")}`)
|
||||||
|
// (async function() {
|
||||||
|
try {
|
||||||
|
let loop = process.env.SCHEDULE_REVERSE_GEO_MAX_LOOP
|
||||||
|
for (let x = 0; x < loop; x++) {
|
||||||
|
// let tracks = [];
|
||||||
|
let tracks = await GpsTracksModels.get2ForReverseGeo(1)
|
||||||
|
for (let i = 0; i < tracks.length; i++) {
|
||||||
|
console.log("tracks[i] :", tracks[i].id, tracks[i].device_id, tracks[i].latitude, tracks[i].longitude)
|
||||||
|
let now = moment().unix()
|
||||||
|
let updtData = {}
|
||||||
|
let respReverseGeo = null
|
||||||
|
try {
|
||||||
|
const sameAddr = await GpsTracksModels.select2Address(tracks[i].latitude, tracks[i].longitude)
|
||||||
|
|
||||||
|
if (sameAddr.length > 0) {
|
||||||
|
let addrData = {
|
||||||
|
device_id: tracks[i].device_id,
|
||||||
|
master_id: tracks[i].id,
|
||||||
|
type: sameAddr[0].type,
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lng: tracks[i].longitude,
|
||||||
|
country_id: sameAddr[0].country_id,
|
||||||
|
country_code: sameAddr[0].country_code,
|
||||||
|
country_text: sameAddr[0].country_text,
|
||||||
|
state_id: sameAddr[0].state_id,
|
||||||
|
state_text: sameAddr[0].state_text,
|
||||||
|
city_id: sameAddr[0].city_id,
|
||||||
|
city_text: sameAddr[0].city_text,
|
||||||
|
district_id: sameAddr[0].district_id,
|
||||||
|
district_text: sameAddr[0].district_text,
|
||||||
|
village_id: sameAddr[0].village_id,
|
||||||
|
village_text: sameAddr[0].village_text,
|
||||||
|
postcode: sameAddr[0].postcode,
|
||||||
|
streets: sameAddr[0].streets,
|
||||||
|
fulladdress: encodeURIComponent(decodeURIComponent(sameAddr[0].fulladdress)),
|
||||||
|
type_reverse_geo: sameAddr[0].type_reverse_geo,
|
||||||
|
stts_reverse_geo: GpsTracksModels.STTS_REVERSE_GEO_SC,
|
||||||
|
log_reverse_geo: sameAddr[0].log_reverse_geo,
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
}
|
||||||
|
GpsTracksModels.create2Address(addrData)
|
||||||
|
updtData.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_SC
|
||||||
|
await GpsTracksModels.update2(tracks[i].id, updtData)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
let params = new url.URLSearchParams({
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lon: tracks[i].longitude,
|
||||||
|
format: "geojson",
|
||||||
|
})
|
||||||
|
//const axInstance = axios.create()
|
||||||
|
const axInstance = axios.create({
|
||||||
|
proxy: {
|
||||||
|
host: process.env.PROXY_URL,
|
||||||
|
port: process.env.PROXY_PORT, },
|
||||||
|
});
|
||||||
|
axios.defaults.timeout = 10000
|
||||||
|
axios.defaults.crossDomain = true
|
||||||
|
// respReverseGeo = await axios({
|
||||||
|
// url: request.osm_reverse_geo.urlFull,
|
||||||
|
// method: request.osm_reverse_geo.method,
|
||||||
|
// params: params,
|
||||||
|
// responseType: 'json',
|
||||||
|
// });
|
||||||
|
respReverseGeo = await axInstance.get(request.osm_reverse_geo.urlFull + "?" + params.toString(), {
|
||||||
|
timeout: 10000,
|
||||||
|
})
|
||||||
|
console.log("respReverseGeo: ",respReverseGeo.data || null )
|
||||||
|
let respData = respReverseGeo.data || {}
|
||||||
|
if (respReverseGeo.status == 200) {
|
||||||
|
if (respData.features.length < 1) {
|
||||||
|
GpsTracksModels.create2Address({
|
||||||
|
device_id: tracks[i].device_id,
|
||||||
|
master_id: tracks[i].id,
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lng: tracks[i].longitude,
|
||||||
|
stts_reverse_geo: GpsTracksModels.STTS_REVERSE_GEO_LOST,
|
||||||
|
log_reverse_geo: JSON.stringify(respData),
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
})
|
||||||
|
updtData.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_LOST
|
||||||
|
await GpsTracksModels.update2(tracks[i].id, updtData)
|
||||||
|
} else {
|
||||||
|
let respAddr = respData.features[0].properties.address
|
||||||
|
let addrData = {
|
||||||
|
device_id: tracks[i].device_id,
|
||||||
|
master_id: tracks[i].id,
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lng: tracks[i].longitude,
|
||||||
|
country_id: GpsTracksModels.DEFAULT_COUNTRY_ID,
|
||||||
|
country_code: respAddr.country_code,
|
||||||
|
country_text: respAddr.country ? respAddr.country.toUpperCase() : respAddr.country || null,
|
||||||
|
state_id: null,
|
||||||
|
city_id: null,
|
||||||
|
district_id: null,
|
||||||
|
village_id: null,
|
||||||
|
postcode: respAddr.postcode,
|
||||||
|
fulladdress: encodeURIComponent(respData.features[0].properties.display_name),
|
||||||
|
stts_reverse_geo: GpsTracksModels.STTS_REVERSE_GEO_SC,
|
||||||
|
log_reverse_geo: respData.features[0].properties ? JSON.stringify(respData.features[0].properties) : null,
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
}
|
||||||
|
if (respAddr.state || respAddr.city) {
|
||||||
|
addrData.state_text = respAddr.region || respAddr.state || respAddr.state_district || respAddr.county || respAddr.city || ""
|
||||||
|
addrData.state_text = addrData.state_text ? addrData.state_text.toUpperCase() : addrData.state_text || null
|
||||||
|
addrData.state_text = addrData.state_text || null
|
||||||
|
}
|
||||||
|
if (respAddr.city_district || respAddr.city) {
|
||||||
|
addrData.city_text = respAddr.city_district || respAddr.city || ""
|
||||||
|
addrData.city_text = addrData.city_text ? addrData.city_text.toUpperCase() : addrData.city_text || null
|
||||||
|
addrData.city_text = addrData.city_text || null
|
||||||
|
}
|
||||||
|
if (respAddr.suburb || respAddr.subdistrict) {
|
||||||
|
addrData.district_text = respAddr.suburb || respAddr.subdistrict || respAddr.subdivision || ""
|
||||||
|
addrData.district_text = addrData.district_text ? addrData.district_text.toUpperCase() : addrData.district_text || null
|
||||||
|
addrData.district_text = addrData.district_text || null
|
||||||
|
}
|
||||||
|
if (respAddr.village) {
|
||||||
|
addrData.village_text = respAddr.village || respAddr.neighbourhood || ""
|
||||||
|
addrData.village_text = addrData.village_text ? addrData.village_text.toUpperCase() : addrData.village_text || null
|
||||||
|
addrData.village_text = addrData.village_text || null
|
||||||
|
}
|
||||||
|
if (respAddr.amenity || respAddr.road || respAddr.city_block) {
|
||||||
|
addrData.streets = ""
|
||||||
|
addrData.streets += respAddr.amenity ? respAddr.amenity + ", " : ""
|
||||||
|
addrData.streets += respAddr.road ? respAddr.road + ", " : ""
|
||||||
|
addrData.streets += respAddr.house_number ? respAddr.house_number + ", " : ""
|
||||||
|
addrData.streets += respAddr.house_name ? respAddr.house_name + ", " : ""
|
||||||
|
addrData.streets += respAddr.city_block ? respAddr.city_block + ", " : ""
|
||||||
|
addrData.streets += addrData.streets || null
|
||||||
|
if (addrData.streets) {
|
||||||
|
addrData.streets = encodeURIComponent(addrData.streets.slice(0, -2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let byAll = await RegionModels.whereLike({
|
||||||
|
nmProvinsiKel: addrData.state_text,
|
||||||
|
nmKotamadyaKel: addrData.city_text,
|
||||||
|
nmKecamatanKel: addrData.district_text,
|
||||||
|
nmKelurahan: addrData.village_text,
|
||||||
|
})
|
||||||
|
if (byAll.length > 1) {
|
||||||
|
addrData.state_id = byAll[0].kodeProv
|
||||||
|
addrData.city_id = byAll[0].kodeKab
|
||||||
|
addrData.district_id = byAll[0].kodeKec
|
||||||
|
addrData.village_id = byAll[0].kodeKel
|
||||||
|
}
|
||||||
|
|
||||||
|
let byKel = await RegionModels.whereLike({
|
||||||
|
nmKelurahan: addrData.village_text,
|
||||||
|
})
|
||||||
|
if (byAll.length < 1 && byKel.length > 0) {
|
||||||
|
addrData.state_id = byKel[0].kodeProv
|
||||||
|
addrData.city_id = byKel[0].kodeKab
|
||||||
|
addrData.district_id = byKel[0].kodeKec
|
||||||
|
addrData.village_id = byKel[0].kodeKel
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addrData.state_id === null) {
|
||||||
|
let byPr = await RegionModels.whereLike({ nmProvinsiKel: addrData.state_text })
|
||||||
|
if (byPr.length > 0) {
|
||||||
|
addrData.state_id = byPr[0].kodeProv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addrData.state_id !== null && addrData.city_id === null) {
|
||||||
|
let byKt = await RegionModels.whereLike({ nmKotamadyaKel: addrData.city_text })
|
||||||
|
if (byKt.length > 0) {
|
||||||
|
addrData.city_id = byKt[0].kodeKab
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id === null) {
|
||||||
|
let byKc = await RegionModels.whereLike({ nmKecamatanKel: addrData.district_text })
|
||||||
|
if (byKc.length > 0) {
|
||||||
|
addrData.district_id = byKc[0].kodeKec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addrData.state_id !== null && addrData.city_id !== null && addrData.district_id !== null && addrData.village_id === null) {
|
||||||
|
let byKl = await RegionModels.whereLike({ nmKelurahan: addrData.village_text })
|
||||||
|
if (byKl.length > 0) {
|
||||||
|
addrData.village_id = byKl[0].kodeKel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GpsTracksModels.create2Address(addrData).catch((e) => {
|
||||||
|
Logger.log("error", `${schedulerName} running_error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`)
|
||||||
|
})
|
||||||
|
updtData.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_SC
|
||||||
|
await GpsTracksModels.update2(tracks[i].id, updtData)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GpsTracksModels.create2Address({
|
||||||
|
device_id: tracks[i].device_id,
|
||||||
|
master_id: tracks[i].id,
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lng: tracks[i].longitude,
|
||||||
|
stts_reverse_geo: GpsTracksModels.STTS_REVERSE_GEO_ER,
|
||||||
|
log_reverse_geo: JSON.stringify(respData),
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
})
|
||||||
|
updtData.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_ER
|
||||||
|
await GpsTracksModels.update2(tracks[i].id, updtData)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
let respData = {}
|
||||||
|
if (respReverseGeo) {
|
||||||
|
if (respReverseGeo.status != 200) {
|
||||||
|
respData.data = respReverseGeo.data
|
||||||
|
} else {
|
||||||
|
respData.msg = e.message
|
||||||
|
}
|
||||||
|
} else if (typeof e.response != "undefined") {
|
||||||
|
respData.data = e.response
|
||||||
|
} else {
|
||||||
|
respData.msg = e.message
|
||||||
|
}
|
||||||
|
GpsTracksModels.create2Address({
|
||||||
|
device_id: tracks[i].device_id,
|
||||||
|
master_id: tracks[i].id,
|
||||||
|
lat: tracks[i].latitude,
|
||||||
|
lng: tracks[i].longitude,
|
||||||
|
stts_reverse_geo: GpsTracksModels.STTS_REVERSE_GEO_ER,
|
||||||
|
log_reverse_geo: JSON.stringify(respData),
|
||||||
|
crt: now,
|
||||||
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
})
|
||||||
|
updtData.stts_reverse_geo = GpsTracksModels.STTS_REVERSE_GEO_ER
|
||||||
|
await GpsTracksModels.update2(tracks[i].id, updtData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
Logger.log("error", `${schedulerName} error: ${JSON.stringify(e)}`)
|
||||||
|
}
|
||||||
|
// })();
|
||||||
|
|
||||||
|
Logger.log("info", `${schedulerName} success do reverse geocoding ${moment().format("YYYY-MM-DD HH:mm:ss")}`)
|
||||||
|
} catch (e) {
|
||||||
|
Logger.log("error", `${schedulerName} error: ${JSON.stringify(e)}`)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = async () => {
|
||||||
|
while (1 == 1) {
|
||||||
|
await go()
|
||||||
|
await new Promise((r) => setTimeout(r, 300))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index()
|
||||||
0
docker-compose.yml
Normal file → Executable file
0
files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-7399bbf4fc.json
Normal file → Executable file
0
files/keys/bingcorp-tracker-firebase-adminsdk-7tcet-c817089752.json
Normal file → Executable file
0
files/keys/google-services.json
Normal file → Executable file
0
files/mails/admInfoOrder.ejs
Normal file → Executable file
0
files/mails/adminInfoNoVdrAccOrd.ejs
Normal file → Executable file
0
files/mails/bidOrderMail.ejs
Normal file → Executable file
0
files/mails/clientCreateOrd.ejs
Normal file → Executable file
0
files/mails/clientOrdHaveBeenAccMail.ejs
Normal file → Executable file
0
files/mails/driverGetOrderMail.ejs
Normal file → Executable file
0
files/mails/financeInfoDanaAmount.ejs
Normal file → Executable file
0
files/mails/financeInfoTfPocket.ejs
Normal file → Executable file
0
files/mails/template/end.ejs
Normal file → Executable file
0
files/mails/template/start.ejs
Normal file → Executable file
0
files/mails/vdrAccOrderMail.ejs
Normal file → Executable file
0
files/mails/zoningMail.ejs
Normal file → Executable file
0
files/public/OpenSans-B9K8.ttf
Normal file → Executable file
0
files/public/OpenSans-B9K8.ttf_neon_100/NVCrVnY_km5eldKtXvghZGtF.ttf_0.png
Normal file → Executable file
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
0
files/public/OpenSans-B9K8.ttf_neon_100/neon_100.fnt
Normal file → Executable file
0
files/public/OpenSans-B9K8.ttf_neon_16/FWd0hhbQQsviQcgc8vksJ1t0.ttf_0.png
Normal file → Executable file
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
0
files/public/OpenSans-B9K8.ttf_neon_16/neon_16.fnt
Normal file → Executable file
0
files/public/OpenSans-B9K8.ttf_neon_32/MlLA3aDGaXpxSgao3dSOGIYD.ttf_0.png
Normal file → Executable file
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
0
files/public/OpenSans-B9K8.ttf_neon_32/neon_32.fnt
Normal file → Executable file
0
files/public/OpenSans-B9K8.ttf_neon_64/0cqXNM8gYrt7OJ5mzJ_o3PUe.ttf_0.png
Normal file → Executable file
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
0
files/public/OpenSans-B9K8.ttf_neon_64/neon_64.fnt
Normal file → Executable file
0
files/public/img_white_bg.png
Normal file → Executable file
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
0
library/LibBullAdapter.js
Normal file → Executable file
0
library/LibCurl.js
Normal file → Executable file
@ -1,7 +1,6 @@
|
|||||||
const LibHelper = require('./LibHelper');
|
const LibHelper = require("./LibHelper");
|
||||||
|
|
||||||
class LibDevice {
|
class LibDevice {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Buffer} buffer
|
* @param {Buffer} buffer
|
||||||
@ -10,11 +9,11 @@ class LibDevice {
|
|||||||
* must return at least => obj.protocol_name
|
* must return at least => obj.protocol_name
|
||||||
*/
|
*/
|
||||||
static identifyProtocolFromBuffer(buffer, opts = {}) {
|
static identifyProtocolFromBuffer(buffer, opts = {}) {
|
||||||
let ori_hex_str = '';
|
let ori_hex_str = "";
|
||||||
if (typeof opts.skip_buffer != 'undefined' && opts.skip_buffer === true) {
|
if (typeof opts.skip_buffer != "undefined" && opts.skip_buffer === true) {
|
||||||
ori_hex_str = buffer;
|
ori_hex_str = buffer;
|
||||||
} else {
|
} else {
|
||||||
ori_hex_str = buffer.toString('hex'); // 16
|
ori_hex_str = buffer.toString("hex"); // 16
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = ori_hex_str;
|
const data = ori_hex_str;
|
||||||
@ -24,7 +23,7 @@ class LibDevice {
|
|||||||
|
|
||||||
// eelinkCustom
|
// eelinkCustom
|
||||||
if (opts.isEelinkCustom) {
|
if (opts.isEelinkCustom) {
|
||||||
me.protocol_name = 'eelinkCustom';
|
me.protocol_name = "eelinkCustom";
|
||||||
|
|
||||||
me.field0 = data.slice(0, 2); // system status flag
|
me.field0 = data.slice(0, 2); // system status flag
|
||||||
me.field1 = data.slice(2, 18); // IMEI
|
me.field1 = data.slice(2, 18); // IMEI
|
||||||
@ -46,33 +45,33 @@ class LibDevice {
|
|||||||
me.ori_string = data;
|
me.ori_string = data;
|
||||||
}
|
}
|
||||||
// gt06
|
// gt06
|
||||||
else if (data.slice(0, 4) == '7878') {
|
else if (data.slice(0, 4) == "7878" || data.slice(0, 4) == "7979") {
|
||||||
me.protocol_name = 'gt06';
|
me.protocol_name = "gt06";
|
||||||
|
|
||||||
me.start = data.slice(0, 4);
|
me.start = data.slice(0, 4);
|
||||||
me.length = parseInt(data.slice(4, 6), 16);
|
me.length = parseInt(data.slice(4, 6), 16);
|
||||||
me.protocol_id = data.slice(6, 8);
|
me.protocol_id = data.slice(6, 8);
|
||||||
me.serial_number = data.slice(-12, -8)
|
me.serial_number = data.slice(-12, -8);
|
||||||
me.error_check = data.slice(-8, -4)
|
me.error_check = data.slice(-8, -4);
|
||||||
me.finish = data.slice(-4); // data.substr(6 + me.length * 2, 4);
|
me.finish = data.slice(-4); // data.substr(6 + me.length * 2, 4);
|
||||||
|
|
||||||
if (me.finish != '0d0a') {
|
if (me.finish != "0d0a") {
|
||||||
throw 'finish code incorrect!';
|
throw "finish code incorrect!";
|
||||||
}
|
}
|
||||||
|
|
||||||
me.ori_string = data;
|
me.ori_string = data;
|
||||||
}
|
}
|
||||||
// gt02a
|
// gt02a
|
||||||
else if (data.slice(0, 4) == '6868') {
|
else if (data.slice(0, 4) == "6868") {
|
||||||
me.protocol_name = 'gt02a';
|
me.protocol_name = "gt02a";
|
||||||
}
|
}
|
||||||
// tk103
|
// tk103
|
||||||
// else if (data.indexOf("B")) {
|
// else if (data.indexOf("B")) {
|
||||||
// me.protocol_name = 'tk103';
|
// me.protocol_name = 'tk103';
|
||||||
// }
|
// }
|
||||||
// eelink
|
// eelink
|
||||||
else if (data.slice(0, 4) == '6767') {
|
else if (data.slice(0, 4) == "6767") {
|
||||||
me.protocol_name = 'eelink';
|
me.protocol_name = "eelink";
|
||||||
|
|
||||||
me.start = data.slice(0, 4);
|
me.start = data.slice(0, 4);
|
||||||
me.pid = data.slice(4, 6);
|
me.pid = data.slice(4, 6);
|
||||||
@ -83,7 +82,7 @@ class LibDevice {
|
|||||||
}
|
}
|
||||||
// unknown
|
// unknown
|
||||||
else {
|
else {
|
||||||
me.protocol_name = 'unknown';
|
me.protocol_name = "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
return me;
|
return me;
|
||||||
@ -97,24 +96,24 @@ class LibDevice {
|
|||||||
* must return at least => act.cmd,act.action_type,act.device_id
|
* must return at least => act.cmd,act.action_type,act.device_id
|
||||||
*/
|
*/
|
||||||
static gt06Action(me, device_id = null) {
|
static gt06Action(me, device_id = null) {
|
||||||
const act = {}
|
const act = {};
|
||||||
|
|
||||||
// Login message
|
// Login message
|
||||||
if (me.protocol_id == '01') {
|
if (me.protocol_id == "01") {
|
||||||
act.action_type = 'login';
|
act.action_type = "login";
|
||||||
|
|
||||||
act.cmd = 'login_request';
|
act.cmd = "login_request";
|
||||||
act.action = 'login_request';
|
act.action = "login_request";
|
||||||
act.device_id = me.ori_string.slice(8).slice(0, 16).padStart(16, '0');
|
act.device_id = me.ori_string.slice(8).slice(0, 16).padStart(16, "0");
|
||||||
|
|
||||||
act.buffer_resp = LibDevice.gt06AuthorizeResp(me);
|
act.buffer_resp = LibDevice.gt06AuthorizeResp(me);
|
||||||
}
|
}
|
||||||
// Location data
|
// Location data
|
||||||
else if (me.protocol_id == '12') {
|
else if (me.protocol_id == "12" || me.protocol_id == "a0") {
|
||||||
act.action_type = 'location';
|
act.action_type = "location";
|
||||||
|
|
||||||
act.cmd = 'ping';
|
act.cmd = "ping";
|
||||||
act.action = 'ping';
|
act.action = "ping";
|
||||||
act.device_id = device_id; // because device_id only sent when login
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
// content data
|
// content data
|
||||||
@ -134,11 +133,11 @@ class LibDevice {
|
|||||||
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
||||||
}
|
}
|
||||||
// Status information
|
// Status information
|
||||||
else if (me.protocol_id == '13') {
|
else if (me.protocol_id == "13") {
|
||||||
act.action_type = 'heartbeat';
|
act.action_type = "heartbeat";
|
||||||
|
|
||||||
act.cmd = 'heartbeat';
|
act.cmd = "heartbeat";
|
||||||
act.action = 'heartbeat';
|
act.action = "heartbeat";
|
||||||
act.device_id = device_id; // because device_id only sent when login
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
// status information
|
// status information
|
||||||
@ -148,16 +147,16 @@ class LibDevice {
|
|||||||
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||||
}
|
}
|
||||||
// String information
|
// String information
|
||||||
else if (me.protocol_id == '15') {
|
else if (me.protocol_id == "15") {
|
||||||
// act.action_type = 'other'; // 'heartbeat';
|
// act.action_type = 'other'; // 'heartbeat';
|
||||||
// act.cmd = 'other'; // 'heartbeat';
|
// act.cmd = 'other'; // 'heartbeat';
|
||||||
// act.action = 'other'; // 'heartbeat';
|
// act.action = 'other'; // 'heartbeat';
|
||||||
// act.device_id = ''; // device_id; // because device_id only sent when login
|
// act.device_id = ''; // device_id; // because device_id only sent when login
|
||||||
|
|
||||||
act.action_type = 'heartbeat';
|
act.action_type = "heartbeat";
|
||||||
|
|
||||||
act.cmd = 'heartbeat';
|
act.cmd = "heartbeat";
|
||||||
act.action = 'heartbeat';
|
act.action = "heartbeat";
|
||||||
act.device_id = device_id; // because device_id only sent when login
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
// status information
|
// status information
|
||||||
@ -167,11 +166,11 @@ class LibDevice {
|
|||||||
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||||
}
|
}
|
||||||
// Alarm data
|
// Alarm data
|
||||||
else if (me.protocol_id == '16' || me.protocol_id == '18') {
|
else if (me.protocol_id == "16" || me.protocol_id == "18") {
|
||||||
act.action_type = 'alarm';
|
act.action_type = "alarm";
|
||||||
|
|
||||||
act.cmd = 'alarm';
|
act.cmd = "alarm";
|
||||||
act.action = 'alarm';
|
act.action = "alarm";
|
||||||
act.device_id = device_id; // because device_id only sent when login
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
// content data
|
// content data
|
||||||
@ -192,26 +191,26 @@ class LibDevice {
|
|||||||
act.buffer_resp = LibDevice.gt06AlarmResp(me);
|
act.buffer_resp = LibDevice.gt06AlarmResp(me);
|
||||||
}
|
}
|
||||||
// GPS, query address information by phone number
|
// GPS, query address information by phone number
|
||||||
else if (me.protocol_id == '1A') {
|
else if (me.protocol_id == "1A") {
|
||||||
act.action_type = 'other';
|
act.action_type = "other";
|
||||||
|
|
||||||
act.cmd = 'other';
|
act.cmd = "other";
|
||||||
act.action = 'other';
|
act.action = "other";
|
||||||
act.device_id = '';
|
act.device_id = "";
|
||||||
}
|
}
|
||||||
// Command information sent by the server to the terminal
|
// Command information sent by the server to the terminal
|
||||||
else if (me.protocol_id == '80') {
|
else if (me.protocol_id == "80") {
|
||||||
act.action_type = 'other';
|
act.action_type = "other";
|
||||||
|
|
||||||
act.cmd = 'other';
|
act.cmd = "other";
|
||||||
act.action = 'other';
|
act.action = "other";
|
||||||
act.device_id = '';
|
act.device_id = "";
|
||||||
} else {
|
} else {
|
||||||
act.action_type = 'other';
|
act.action_type = "other";
|
||||||
|
|
||||||
act.cmd = 'other';
|
act.cmd = "other";
|
||||||
act.action = 'other';
|
act.action = "other";
|
||||||
act.device_id = '';
|
act.device_id = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return act;
|
return act;
|
||||||
@ -226,13 +225,13 @@ class LibDevice {
|
|||||||
gps_string = me.ori_string.slice(8).slice(0, 36);
|
gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
let year = (parseInt(gps_string.slice(0, 2), 16) + '').padStart(2, 0);
|
let year = (parseInt(gps_string.slice(0, 2), 16) + "").padStart(2, 0);
|
||||||
year = '20' + year;
|
year = "20" + year;
|
||||||
let month = (parseInt(gps_string.slice(2, 4), 16) + '').padStart(2, 0);
|
let month = (parseInt(gps_string.slice(2, 4), 16) + "").padStart(2, 0);
|
||||||
let day = (parseInt(gps_string.slice(4, 6), 16) + '').padStart(2, 0);
|
let day = (parseInt(gps_string.slice(4, 6), 16) + "").padStart(2, 0);
|
||||||
let hour = (parseInt(gps_string.slice(6, 8), 16) + '').padStart(2, 0);
|
let hour = (parseInt(gps_string.slice(6, 8), 16) + "").padStart(2, 0);
|
||||||
let minute = (parseInt(gps_string.slice(8, 10), 16) + '').padStart(2, 0);
|
let minute = (parseInt(gps_string.slice(8, 10), 16) + "").padStart(2, 0);
|
||||||
let second = (parseInt(gps_string.slice(10, 12), 16) + '').padStart(2, 0);
|
let second = (parseInt(gps_string.slice(10, 12), 16) + "").padStart(2, 0);
|
||||||
|
|
||||||
let ob1 = LibHelper.hex2bin(gps_string.slice(32, 34)); // orientation_byte1
|
let ob1 = LibHelper.hex2bin(gps_string.slice(32, 34)); // orientation_byte1
|
||||||
let ob1_bit7 = ob1.slice(0, 1);
|
let ob1_bit7 = ob1.slice(0, 1);
|
||||||
@ -253,38 +252,38 @@ class LibDevice {
|
|||||||
// let ob2_bit1 = ob2.slice(6, 7);
|
// let ob2_bit1 = ob2.slice(6, 7);
|
||||||
// let ob2_bit0 = ob2.slice(7, 8);
|
// let ob2_bit0 = ob2.slice(7, 8);
|
||||||
|
|
||||||
let lat_wind = ''; // wind direction N,S
|
let lat_wind = ""; // wind direction N,S
|
||||||
let lng_wind = ''; // wind direction W,E
|
let lng_wind = ""; // wind direction W,E
|
||||||
if (ob1_bit3 == 1) {
|
if (ob1_bit3 == 1) {
|
||||||
lng_wind = 'W';
|
lng_wind = "W";
|
||||||
}
|
}
|
||||||
if (ob1_bit3 == 0) {
|
if (ob1_bit3 == 0) {
|
||||||
lng_wind = 'E';
|
lng_wind = "E";
|
||||||
}
|
}
|
||||||
if (ob1_bit2 == 1) {
|
if (ob1_bit2 == 1) {
|
||||||
lat_wind = 'N';
|
lat_wind = "N";
|
||||||
}
|
}
|
||||||
if (ob1_bit2 == 0) {
|
if (ob1_bit2 == 0) {
|
||||||
lat_wind = 'S';
|
lat_wind = "S";
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
'date_raw': gps_string.slice(0, 12),
|
date_raw: gps_string.slice(0, 12),
|
||||||
'date': `${year}-${month}-${day} ${hour}:${minute}:${second}`,
|
date: `${year}-${month}-${day} ${hour}:${minute}:${second}`,
|
||||||
'quantity_pos_satellites_raw': gps_string.slice(12, 14),
|
quantity_pos_satellites_raw: gps_string.slice(12, 14),
|
||||||
'quantity_pos_satellites_c': parseInt(gps_string.slice(12, 13), 16), // length of gps information
|
quantity_pos_satellites_c: parseInt(gps_string.slice(12, 13), 16), // length of gps information
|
||||||
'quantity_pos_satellites_b': parseInt(gps_string.slice(13, 14), 16), // number of positioning satellites
|
quantity_pos_satellites_b: parseInt(gps_string.slice(13, 14), 16), // number of positioning satellites
|
||||||
realtime_dif_gps: ob1_bit5, // 0 (realtime GPS) or differential positioning
|
realtime_dif_gps: ob1_bit5, // 0 (realtime GPS) or differential positioning
|
||||||
positioning_gps: ob1_bit6, // 1 (GPS has been positioned)
|
positioning_gps: ob1_bit6, // 1 (GPS has been positioned)
|
||||||
'latitude_raw': gps_string.slice(14, 22),
|
latitude_raw: gps_string.slice(14, 22),
|
||||||
'longitude_raw': gps_string.slice(22, 30),
|
longitude_raw: gps_string.slice(22, 30),
|
||||||
lat_wind_direction: lat_wind,
|
lat_wind_direction: lat_wind,
|
||||||
lng_wind_direction: lng_wind,
|
lng_wind_direction: lng_wind,
|
||||||
'latitude': LibDevice.gt06Hex2DMM(gps_string.slice(14, 22), lat_wind),
|
latitude: LibDevice.gt06Hex2DMM(gps_string.slice(14, 22), lat_wind),
|
||||||
'longitude': LibDevice.gt06Hex2DMM(gps_string.slice(22, 30), lng_wind),
|
longitude: LibDevice.gt06Hex2DMM(gps_string.slice(22, 30), lng_wind),
|
||||||
'speed': parseInt(gps_string.slice(30, 32), 16), // km/h
|
speed: parseInt(gps_string.slice(30, 32), 16), // km/h
|
||||||
'orientation_raw': gps_string.slice(32, 36),
|
orientation_raw: gps_string.slice(32, 36),
|
||||||
'orientation': parseInt(`${ob1_bit1}${ob1_bit0}${ob2}`, 2), // -360 ~ 360 derajat
|
orientation: parseInt(`${ob1_bit1}${ob1_bit0}${ob2}`, 2), // -360 ~ 360 derajat
|
||||||
};
|
};
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -294,10 +293,10 @@ class LibDevice {
|
|||||||
static gt06Hex2DMM(hex, direction) {
|
static gt06Hex2DMM(hex, direction) {
|
||||||
hex = parseInt(hex, 16);
|
hex = parseInt(hex, 16);
|
||||||
// convert hexadecimal to Degrees Minutes.m (DMM)
|
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||||
let a = parseInt(hex, 10) // to decimal values
|
let a = parseInt(hex, 10); // to decimal values
|
||||||
let b = a / 30000.0
|
let b = a / 30000.0;
|
||||||
let degrees = b / 60
|
let degrees = b / 60;
|
||||||
let minutes = b % 60
|
let minutes = b % 60;
|
||||||
// convert DMM to Decimal Degrees (DD)
|
// convert DMM to Decimal Degrees (DD)
|
||||||
// let d = minutes / 60
|
// let d = minutes / 60
|
||||||
// let dd = degrees + d
|
// let dd = degrees + d
|
||||||
@ -311,13 +310,13 @@ class LibDevice {
|
|||||||
static gt06Hex2DMM1(hex, direction) {
|
static gt06Hex2DMM1(hex, direction) {
|
||||||
hex = parseInt(hex, 16);
|
hex = parseInt(hex, 16);
|
||||||
// convert hexadecimal to Degrees Minutes.m (DMM)
|
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||||
let a = parseInt(hex, 10) // to decimal values
|
let a = parseInt(hex, 10); // to decimal values
|
||||||
let b = a / 30000.0
|
let b = a / 30000.0;
|
||||||
let degrees = b / 60
|
let degrees = b / 60;
|
||||||
let minutes = b % 60
|
let minutes = b % 60;
|
||||||
// convert DMM to Decimal Degrees (DD)
|
// convert DMM to Decimal Degrees (DD)
|
||||||
let d = minutes / 60
|
let d = minutes / 60;
|
||||||
let dd = degrees + d
|
let dd = degrees + d;
|
||||||
// add - follow wind direction
|
// add - follow wind direction
|
||||||
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
||||||
dd = dd * -1;
|
dd = dd * -1;
|
||||||
@ -494,13 +493,13 @@ class LibDevice {
|
|||||||
static eelinkCustomAction(me, device_id = null) {
|
static eelinkCustomAction(me, device_id = null) {
|
||||||
const act = {
|
const act = {
|
||||||
device_id: me.field1,
|
device_id: me.field1,
|
||||||
action_type: 'exist_data',
|
action_type: "exist_data",
|
||||||
cmd: 'exist_data',
|
cmd: "exist_data",
|
||||||
}
|
};
|
||||||
|
|
||||||
if (me.field3 == '60000000' || me.field3 == '00000000') {
|
if (me.field3 == "60000000" || me.field3 == "00000000") {
|
||||||
act.action_type = 'no_data_since_hardware_reset';
|
act.action_type = "no_data_since_hardware_reset";
|
||||||
act.cmd = 'no_data_since_hardware_reset';
|
act.cmd = "no_data_since_hardware_reset";
|
||||||
|
|
||||||
// act.buffer_resp = Buffer.from('LOAD');
|
// act.buffer_resp = Buffer.from('LOAD');
|
||||||
// act.buffer_resp = 'LOAD';
|
// act.buffer_resp = 'LOAD';
|
||||||
@ -508,22 +507,30 @@ class LibDevice {
|
|||||||
// act.buffer_resp = `6767${me.field0}000A0001${me.field1}01`;
|
// act.buffer_resp = `6767${me.field0}000A0001${me.field1}01`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (act.action_type !== 'exist_data') return act;
|
if (act.action_type !== "exist_data") return act;
|
||||||
|
|
||||||
act.flag = me.field0;
|
act.flag = me.field0;
|
||||||
act.imsi = me.field2; // International Mobile Subscriber Identifier
|
act.imsi = me.field2; // International Mobile Subscriber Identifier
|
||||||
|
|
||||||
act.time_string = me.field3;
|
act.time_string = me.field3;
|
||||||
const time_data = {};
|
const time_data = {};
|
||||||
time_data.year = '20' + (parseInt(me.field3.slice(0, 1), 16) + 10);
|
time_data.year = "20" + (parseInt(me.field3.slice(0, 1), 16) + 10);
|
||||||
time_data.month = '' + parseInt(me.field3.slice(1, 2), 16);
|
time_data.month = "" + parseInt(me.field3.slice(1, 2), 16);
|
||||||
if (time_data.month.length === 1) { time_data.month = '0' + time_data.month; }
|
if (time_data.month.length === 1) {
|
||||||
time_data.day = '' + parseInt(me.field3.slice(2, 4), 16);
|
time_data.month = "0" + time_data.month;
|
||||||
if (time_data.day.length === 1) { time_data.day = '0' + time_data.day; }
|
}
|
||||||
time_data.hour = '' + parseInt(me.field3.slice(4, 6), 16);
|
time_data.day = "" + parseInt(me.field3.slice(2, 4), 16);
|
||||||
if (time_data.hour.length === 1) { time_data.hour = '0' + time_data.hour; }
|
if (time_data.day.length === 1) {
|
||||||
time_data.minute = '' + parseInt(me.field3.slice(6, 8), 16);
|
time_data.day = "0" + time_data.day;
|
||||||
if (time_data.minute.length === 1) { time_data.minute = '0' + time_data.minute; }
|
}
|
||||||
|
time_data.hour = "" + parseInt(me.field3.slice(4, 6), 16);
|
||||||
|
if (time_data.hour.length === 1) {
|
||||||
|
time_data.hour = "0" + time_data.hour;
|
||||||
|
}
|
||||||
|
time_data.minute = "" + parseInt(me.field3.slice(6, 8), 16);
|
||||||
|
if (time_data.minute.length === 1) {
|
||||||
|
time_data.minute = "0" + time_data.minute;
|
||||||
|
}
|
||||||
act.time_data = time_data;
|
act.time_data = time_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -539,18 +546,18 @@ class LibDevice {
|
|||||||
north = north * -1 + 1;
|
north = north * -1 + 1;
|
||||||
west = west * -1 + 1;
|
west = west * -1 + 1;
|
||||||
// convert to string
|
// convert to string
|
||||||
north += '';
|
north += "";
|
||||||
west += '';
|
west += "";
|
||||||
// remove - from string at first and save to temporary variable
|
// remove - from string at first and save to temporary variable
|
||||||
let signedNorth = '';
|
let signedNorth = "";
|
||||||
if (north.indexOf('-') === 0) {
|
if (north.indexOf("-") === 0) {
|
||||||
north = north.slice(1);
|
north = north.slice(1);
|
||||||
signedNorth = '-';
|
signedNorth = "-";
|
||||||
}
|
}
|
||||||
let signedWest = '';
|
let signedWest = "";
|
||||||
if (west.indexOf('-') === 0) {
|
if (west.indexOf("-") === 0) {
|
||||||
west = west.slice(1);
|
west = west.slice(1);
|
||||||
signedWest = '-';
|
signedWest = "-";
|
||||||
}
|
}
|
||||||
// separate DDM => Degree Decimal Minutes
|
// separate DDM => Degree Decimal Minutes
|
||||||
let northDegree = north.slice(0, 1);
|
let northDegree = north.slice(0, 1);
|
||||||
@ -562,12 +569,11 @@ class LibDevice {
|
|||||||
let westDegree = west.slice(0, 3);
|
let westDegree = west.slice(0, 3);
|
||||||
let westDecimalMinute = west.slice(3, 7);
|
let westDecimalMinute = west.slice(3, 7);
|
||||||
// convert DDM to DD (Decimal Degrees)
|
// convert DDM to DD (Decimal Degrees)
|
||||||
act.latitude = '' + signedNorth + northDegree + '.' + ('' + (northDecimalMinute/60)).replace('.', '');
|
act.latitude = "" + signedNorth + northDegree + "." + ("" + northDecimalMinute / 60).replace(".", "");
|
||||||
act.longitude = '' + signedWest + westDegree + '.' + ('' + (westDecimalMinute/60)).replace('.', '');
|
act.longitude = "" + signedWest + westDegree + "." + ("" + westDecimalMinute / 60).replace(".", "");
|
||||||
|
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = LibDevice;
|
module.exports = LibDevice;
|
||||||
573
library/LibDevice.js_bak
Executable file
@ -0,0 +1,573 @@
|
|||||||
|
const LibHelper = require('./LibHelper');
|
||||||
|
|
||||||
|
class LibDevice {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Buffer} buffer
|
||||||
|
* @param {Object} opts
|
||||||
|
* @returns {Object} me
|
||||||
|
* must return at least => obj.protocol_name
|
||||||
|
*/
|
||||||
|
static identifyProtocolFromBuffer(buffer, opts = {}) {
|
||||||
|
let ori_hex_str = '';
|
||||||
|
if (typeof opts.skip_buffer != 'undefined' && opts.skip_buffer === true) {
|
||||||
|
ori_hex_str = buffer;
|
||||||
|
} else {
|
||||||
|
ori_hex_str = buffer.toString('hex'); // 16
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = ori_hex_str;
|
||||||
|
const me = {
|
||||||
|
ori_string: data,
|
||||||
|
};
|
||||||
|
|
||||||
|
// eelinkCustom
|
||||||
|
if (opts.isEelinkCustom) {
|
||||||
|
me.protocol_name = 'eelinkCustom';
|
||||||
|
|
||||||
|
me.field0 = data.slice(0, 2); // system status flag
|
||||||
|
me.field1 = data.slice(2, 18); // IMEI
|
||||||
|
me.field2 = data.slice(18, 34); // IMSI
|
||||||
|
me.field3 = data.slice(34, 42); // Time
|
||||||
|
me.field4 = data.slice(42, 58); // Location
|
||||||
|
me.field5 = data.slice(58, 62); // Altitude
|
||||||
|
me.field6 = data.slice(62, 66); // Heading
|
||||||
|
me.field7 = data.slice(66, 68); // Velocity
|
||||||
|
me.field8 = data.slice(68, 70); // Power Input Voltage
|
||||||
|
me.field9 = data.slice(70, 72); // GPIO Status
|
||||||
|
me.field10 = data.slice(72, 74); // Time Seconds
|
||||||
|
me.field11 = data.slice(74, 76); // RSSI
|
||||||
|
me.field12 = data.slice(76, 78); // Sequence Counter
|
||||||
|
me.field13 = data.slice(78, 80); // Vendor ID
|
||||||
|
me.field14 = data.slice(80, 82); // GPS Satellites
|
||||||
|
me.field15 = data.slice(82, 90); // Accumulators
|
||||||
|
|
||||||
|
me.ori_string = data;
|
||||||
|
}
|
||||||
|
// gt06
|
||||||
|
else if (data.slice(0, 4) == '7878') {
|
||||||
|
me.protocol_name = 'gt06';
|
||||||
|
|
||||||
|
me.start = data.slice(0, 4);
|
||||||
|
me.length = parseInt(data.slice(4, 6), 16);
|
||||||
|
me.protocol_id = data.slice(6, 8);
|
||||||
|
me.serial_number = data.slice(-12, -8)
|
||||||
|
me.error_check = data.slice(-8, -4)
|
||||||
|
me.finish = data.slice(-4); // data.substr(6 + me.length * 2, 4);
|
||||||
|
|
||||||
|
if (me.finish != '0d0a') {
|
||||||
|
throw 'finish code incorrect!';
|
||||||
|
}
|
||||||
|
|
||||||
|
me.ori_string = data;
|
||||||
|
}
|
||||||
|
// gt02a
|
||||||
|
else if (data.slice(0, 4) == '6868') {
|
||||||
|
me.protocol_name = 'gt02a';
|
||||||
|
}
|
||||||
|
// tk103
|
||||||
|
// else if (data.indexOf("B")) {
|
||||||
|
// me.protocol_name = 'tk103';
|
||||||
|
// }
|
||||||
|
// eelink
|
||||||
|
else if (data.slice(0, 4) == '6767') {
|
||||||
|
me.protocol_name = 'eelink';
|
||||||
|
|
||||||
|
me.start = data.slice(0, 4);
|
||||||
|
me.pid = data.slice(4, 6);
|
||||||
|
me.size = parseInt(data.slice(6, 10), 16);
|
||||||
|
me.sequence = parseInt(data.slice(10, 4), 16);
|
||||||
|
|
||||||
|
me.ori_string = data;
|
||||||
|
}
|
||||||
|
// unknown
|
||||||
|
else {
|
||||||
|
me.protocol_name = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Object} me
|
||||||
|
* @param {String} device_id
|
||||||
|
* @returns
|
||||||
|
* must return at least => act.cmd,act.action_type,act.device_id
|
||||||
|
*/
|
||||||
|
static gt06Action(me, device_id = null) {
|
||||||
|
const act = {}
|
||||||
|
|
||||||
|
// Login message
|
||||||
|
if (me.protocol_id == '01') {
|
||||||
|
act.action_type = 'login';
|
||||||
|
|
||||||
|
act.cmd = 'login_request';
|
||||||
|
act.action = 'login_request';
|
||||||
|
act.device_id = me.ori_string.slice(8).slice(0, 16).padStart(16, '0');
|
||||||
|
|
||||||
|
act.buffer_resp = LibDevice.gt06AuthorizeResp(me);
|
||||||
|
}
|
||||||
|
// Location data
|
||||||
|
else if (me.protocol_id == '12') {
|
||||||
|
act.action_type = 'location';
|
||||||
|
|
||||||
|
act.cmd = 'ping';
|
||||||
|
act.action = 'ping';
|
||||||
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
|
// content data
|
||||||
|
// me.ori_string.slice(8).slice(0, 52); // me.ori_string.substr(8, me.length * 2);
|
||||||
|
|
||||||
|
// gps information
|
||||||
|
act.gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||||
|
act.gps_data = LibDevice.gt06ParseLocation(me, act.gps_string);
|
||||||
|
// if (!act.gps_data) {
|
||||||
|
// //Something bad happened
|
||||||
|
// _this.do_log('GPS Data can\'t be parsed. Discarding packet...');
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lbs information
|
||||||
|
act.lbs_string = me.ori_string.slice(8).slice(36, 52);
|
||||||
|
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
||||||
|
}
|
||||||
|
// Status information
|
||||||
|
else if (me.protocol_id == '13') {
|
||||||
|
act.action_type = 'heartbeat';
|
||||||
|
|
||||||
|
act.cmd = 'heartbeat';
|
||||||
|
act.action = 'heartbeat';
|
||||||
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
|
// status information
|
||||||
|
act.stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||||
|
act.stts_data = LibDevice.gt06ParseHeartbeat(me, act.stts_string);
|
||||||
|
|
||||||
|
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||||
|
}
|
||||||
|
// String information
|
||||||
|
else if (me.protocol_id == '15') {
|
||||||
|
// act.action_type = 'other'; // 'heartbeat';
|
||||||
|
// act.cmd = 'other'; // 'heartbeat';
|
||||||
|
// act.action = 'other'; // 'heartbeat';
|
||||||
|
// act.device_id = ''; // device_id; // because device_id only sent when login
|
||||||
|
|
||||||
|
act.action_type = 'heartbeat';
|
||||||
|
|
||||||
|
act.cmd = 'heartbeat';
|
||||||
|
act.action = 'heartbeat';
|
||||||
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
|
// status information
|
||||||
|
act.stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||||
|
act.stts_data = LibDevice.gt06ParseHeartbeat(me, act.stts_string);
|
||||||
|
|
||||||
|
act.buffer_resp = LibDevice.gt06HeartbeatResp(me);
|
||||||
|
}
|
||||||
|
// Alarm data
|
||||||
|
else if (me.protocol_id == '16' || me.protocol_id == '18') {
|
||||||
|
act.action_type = 'alarm';
|
||||||
|
|
||||||
|
act.cmd = 'alarm';
|
||||||
|
act.action = 'alarm';
|
||||||
|
act.device_id = device_id; // because device_id only sent when login
|
||||||
|
|
||||||
|
// content data
|
||||||
|
// me.ori_string.slice(8).slice(0, 64); // me.ori_string.substr(8, me.length * 2);
|
||||||
|
|
||||||
|
// gps information
|
||||||
|
act.gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||||
|
act.gps_data = LibDevice.gt06ParseLocation(me, act.gps_string);
|
||||||
|
|
||||||
|
// lbs information
|
||||||
|
act.lbs_string = me.ori_string.slice(8).slice(36, 54);
|
||||||
|
act.lbs_data = LibDevice.gt06ParseLbs(me, act.lbs_string);
|
||||||
|
|
||||||
|
// status information
|
||||||
|
act.stts_string = me.ori_string.slice(8).slice(54, 64);
|
||||||
|
act.stts_data = LibDevice.gt06ParseStatusAlarm(me, act.stts_string);
|
||||||
|
|
||||||
|
act.buffer_resp = LibDevice.gt06AlarmResp(me);
|
||||||
|
}
|
||||||
|
// GPS, query address information by phone number
|
||||||
|
else if (me.protocol_id == '1A') {
|
||||||
|
act.action_type = 'other';
|
||||||
|
|
||||||
|
act.cmd = 'other';
|
||||||
|
act.action = 'other';
|
||||||
|
act.device_id = '';
|
||||||
|
}
|
||||||
|
// Command information sent by the server to the terminal
|
||||||
|
else if (me.protocol_id == '80') {
|
||||||
|
act.action_type = 'other';
|
||||||
|
|
||||||
|
act.cmd = 'other';
|
||||||
|
act.action = 'other';
|
||||||
|
act.device_id = '';
|
||||||
|
} else {
|
||||||
|
act.action_type = 'other';
|
||||||
|
|
||||||
|
act.cmd = 'other';
|
||||||
|
act.action = 'other';
|
||||||
|
act.device_id = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return act;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06AuthorizeResp(me) {
|
||||||
|
return Buffer.from("787805010001d9dc0d0a", "hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06ParseLocation(me, gps_string = null) {
|
||||||
|
if (!gps_string) {
|
||||||
|
gps_string = me.ori_string.slice(8).slice(0, 36);
|
||||||
|
}
|
||||||
|
|
||||||
|
let year = (parseInt(gps_string.slice(0, 2), 16) + '').padStart(2, 0);
|
||||||
|
year = '20' + year;
|
||||||
|
let month = (parseInt(gps_string.slice(2, 4), 16) + '').padStart(2, 0);
|
||||||
|
let day = (parseInt(gps_string.slice(4, 6), 16) + '').padStart(2, 0);
|
||||||
|
let hour = (parseInt(gps_string.slice(6, 8), 16) + '').padStart(2, 0);
|
||||||
|
let minute = (parseInt(gps_string.slice(8, 10), 16) + '').padStart(2, 0);
|
||||||
|
let second = (parseInt(gps_string.slice(10, 12), 16) + '').padStart(2, 0);
|
||||||
|
|
||||||
|
let ob1 = LibHelper.hex2bin(gps_string.slice(32, 34)); // orientation_byte1
|
||||||
|
let ob1_bit7 = ob1.slice(0, 1);
|
||||||
|
let ob1_bit6 = ob1.slice(1, 2);
|
||||||
|
let ob1_bit5 = ob1.slice(2, 3); // 0 (realtime GPS) or differential positioning
|
||||||
|
let ob1_bit4 = ob1.slice(3, 4); // 1 (GPS has been positioned)
|
||||||
|
let ob1_bit3 = ob1.slice(4, 5); // 0 (east longitude) || 1 (west longitude)
|
||||||
|
let ob1_bit2 = ob1.slice(5, 6); // 1 (north latitude) || 0 (south latitude)
|
||||||
|
let ob1_bit1 = ob1.slice(6, 7);
|
||||||
|
let ob1_bit0 = ob1.slice(7, 8);
|
||||||
|
let ob2 = LibHelper.hex2bin(gps_string.slice(34, 36)); // orientation_byte2
|
||||||
|
// let ob2_bit7 = ob2.slice(0, 1);
|
||||||
|
// let ob2_bit6 = ob2.slice(1, 2);
|
||||||
|
// let ob2_bit5 = ob2.slice(2, 3);
|
||||||
|
// let ob2_bit4 = ob2.slice(3, 4);
|
||||||
|
// let ob2_bit3 = ob2.slice(4, 5);
|
||||||
|
// let ob2_bit2 = ob2.slice(5, 6);
|
||||||
|
// let ob2_bit1 = ob2.slice(6, 7);
|
||||||
|
// let ob2_bit0 = ob2.slice(7, 8);
|
||||||
|
|
||||||
|
let lat_wind = ''; // wind direction N,S
|
||||||
|
let lng_wind = ''; // wind direction W,E
|
||||||
|
if (ob1_bit3 == 1) {
|
||||||
|
lng_wind = 'W';
|
||||||
|
}
|
||||||
|
if (ob1_bit3 == 0) {
|
||||||
|
lng_wind = 'E';
|
||||||
|
}
|
||||||
|
if (ob1_bit2 == 1) {
|
||||||
|
lat_wind = 'N';
|
||||||
|
}
|
||||||
|
if (ob1_bit2 == 0) {
|
||||||
|
lat_wind = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
'date_raw': gps_string.slice(0, 12),
|
||||||
|
'date': `${year}-${month}-${day} ${hour}:${minute}:${second}`,
|
||||||
|
'quantity_pos_satellites_raw': gps_string.slice(12, 14),
|
||||||
|
'quantity_pos_satellites_c': parseInt(gps_string.slice(12, 13), 16), // length of gps information
|
||||||
|
'quantity_pos_satellites_b': parseInt(gps_string.slice(13, 14), 16), // number of positioning satellites
|
||||||
|
realtime_dif_gps: ob1_bit5, // 0 (realtime GPS) or differential positioning
|
||||||
|
positioning_gps: ob1_bit6, // 1 (GPS has been positioned)
|
||||||
|
'latitude_raw': gps_string.slice(14, 22),
|
||||||
|
'longitude_raw': gps_string.slice(22, 30),
|
||||||
|
lat_wind_direction: lat_wind,
|
||||||
|
lng_wind_direction: lng_wind,
|
||||||
|
'latitude': LibDevice.gt06Hex2DMM(gps_string.slice(14, 22), lat_wind),
|
||||||
|
'longitude': LibDevice.gt06Hex2DMM(gps_string.slice(22, 30), lng_wind),
|
||||||
|
'speed': parseInt(gps_string.slice(30, 32), 16), // km/h
|
||||||
|
'orientation_raw': gps_string.slice(32, 36),
|
||||||
|
'orientation': parseInt(`${ob1_bit1}${ob1_bit0}${ob2}`, 2), // -360 ~ 360 derajat
|
||||||
|
};
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// more accurate
|
||||||
|
static gt06Hex2DMM(hex, direction) {
|
||||||
|
hex = parseInt(hex, 16);
|
||||||
|
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||||
|
let a = parseInt(hex, 10) // to decimal values
|
||||||
|
let b = a / 30000.0
|
||||||
|
let degrees = b / 60
|
||||||
|
let minutes = b % 60
|
||||||
|
// convert DMM to Decimal Degrees (DD)
|
||||||
|
// let d = minutes / 60
|
||||||
|
// let dd = degrees + d
|
||||||
|
// add - follow wind direction
|
||||||
|
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
||||||
|
degrees = degrees * -1;
|
||||||
|
}
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
// ga akurat
|
||||||
|
static gt06Hex2DMM1(hex, direction) {
|
||||||
|
hex = parseInt(hex, 16);
|
||||||
|
// convert hexadecimal to Degrees Minutes.m (DMM)
|
||||||
|
let a = parseInt(hex, 10) // to decimal values
|
||||||
|
let b = a / 30000.0
|
||||||
|
let degrees = b / 60
|
||||||
|
let minutes = b % 60
|
||||||
|
// convert DMM to Decimal Degrees (DD)
|
||||||
|
let d = minutes / 60
|
||||||
|
let dd = degrees + d
|
||||||
|
// add - follow wind direction
|
||||||
|
if (direction == "S" || direction == "W" || direction == "s" || direction == "w") {
|
||||||
|
dd = dd * -1;
|
||||||
|
}
|
||||||
|
return dd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06HeartbeatResp(me) {
|
||||||
|
return Buffer.from("787805130001d9dc0d0a", "hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06ParseHeartbeat(me, stts_string) {
|
||||||
|
if (!stts_string) {
|
||||||
|
stts_string = me.ori_string.slice(8).slice(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
let terminal_info_raw = stts_string.slice(0, 2);
|
||||||
|
let tib1 = LibHelper.hex2bin(terminal_info_raw); // terminal_info_byte1
|
||||||
|
let tib1_bit7 = tib1.slice(0, 1);
|
||||||
|
let tib1_bit6 = tib1.slice(1, 2);
|
||||||
|
let tib1_bit5 = tib1.slice(2, 3);
|
||||||
|
let tib1_bit4 = tib1.slice(3, 4);
|
||||||
|
let tib1_bit3 = tib1.slice(4, 5);
|
||||||
|
let tib1_bit2 = tib1.slice(5, 6);
|
||||||
|
let tib1_bit1 = tib1.slice(6, 7);
|
||||||
|
let tib1_bit0 = tib1.slice(7, 8);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: No Power (shutdown)
|
||||||
|
* 1: Extremely Low Battery (not enough for calling or sending text messages, etc.)
|
||||||
|
* 2: Very Low Battery (Low Battery Alarm)
|
||||||
|
* 3: Low Battery (can be used normally)
|
||||||
|
* 4: Medium
|
||||||
|
* 5: High
|
||||||
|
* 6: Very High
|
||||||
|
*/
|
||||||
|
let voltage_level = stts_string.slice(2, 4);
|
||||||
|
|
||||||
|
let gsm_signal_strength = stts_string.slice(4, 6);
|
||||||
|
|
||||||
|
let alarm_stts = stts_string.slice(6, 8); // former bit: terminal alarm status (suitable for alarm packet and electronic fence project)
|
||||||
|
let language = stts_string.slice(8, 10); // latter bit: the current language used in the terminal
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
terminal_info_raw: terminal_info_raw,
|
||||||
|
terminal_info_byte: tib1,
|
||||||
|
terminal_info: {
|
||||||
|
oil_electricity: tib1_bit7, // 1: oil and electricity disconnected, 0: gas oil and electricity connected
|
||||||
|
gps_tracking: tib1_bit6, // 1: GPS tracking is on, 0: GPS tracking is off
|
||||||
|
stts: `${tib1_bit5}${tib1_bit4}${tib1_bit3}`, // 100: SOS, 011: Low Battery Alarm, 010: Power Cut Alarm, 001: Shock Alarm, 000: Normal
|
||||||
|
charge: tib1_bit2, // 1: Charge On, 0: Charge Off
|
||||||
|
acc: tib1_bit1, // 1: ACC high, 0: ACC Low
|
||||||
|
is_active: tib1_bit0, // 1: Activated, 0: Deactivated
|
||||||
|
},
|
||||||
|
voltage_level,
|
||||||
|
gsm_signal_strength, // 0x00: no signal; 0x01: extremely weak signal; 0x02: very weak signal; 0x03: good signal; 0x04: strong signal.
|
||||||
|
alarm_stts, // 0x00: normal, 0x01: SOS, 0x02: Power Cut Alarm, 0x03: Shock Alarm, 0x04: Fence In Alarm, 0x05: Fence Out Alarm
|
||||||
|
language, // 0x01: Chinese, 0x02: English
|
||||||
|
};
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06ParseLbs(me, lbs_string) {
|
||||||
|
let mcc_raw = null,
|
||||||
|
mcc = null, // mobile country code
|
||||||
|
mnc_raw = null,
|
||||||
|
mnc = null, // mobile network code
|
||||||
|
lac_raw = null,
|
||||||
|
lac = null, // location area code
|
||||||
|
cellID_raw = null,
|
||||||
|
cellID = null, // cell tower id
|
||||||
|
lbs_length_raw = null,
|
||||||
|
lbs_length = null;
|
||||||
|
|
||||||
|
// from location
|
||||||
|
if (lbs_string.length == 16) {
|
||||||
|
mcc_raw = lbs_string.slice(0, 4);
|
||||||
|
mnc_raw = lbs_string.slice(4, 6);
|
||||||
|
lac_raw = lbs_string.slice(6, 10);
|
||||||
|
cellID_raw = lbs_string.slice(10, 16);
|
||||||
|
}
|
||||||
|
// from alarm
|
||||||
|
else if (lbs_string.length == 18) {
|
||||||
|
lbs_length_raw = lbs_string.slice(0, 2);
|
||||||
|
mcc_raw = lbs_string.slice(2, 6);
|
||||||
|
mnc_raw = lbs_string.slice(6, 8);
|
||||||
|
lac_raw = lbs_string.slice(8, 12);
|
||||||
|
cellID_raw = lbs_string.slice(12, 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lbs_length_raw) {
|
||||||
|
lbs_length = parseInt(lbs_length_raw, 16);
|
||||||
|
}
|
||||||
|
if (mnc_raw && mcc_raw && lac_raw && cellID_raw) {
|
||||||
|
mnc = parseInt(mnc_raw, 16);
|
||||||
|
mcc = parseInt(mcc_raw, 16);
|
||||||
|
lac = parseInt(lac_raw, 16);
|
||||||
|
cellID = parseInt(cellID_raw, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
lbs_length_raw,
|
||||||
|
lbs_length,
|
||||||
|
mcc_raw,
|
||||||
|
mcc,
|
||||||
|
mnc_raw,
|
||||||
|
mnc,
|
||||||
|
lac_raw,
|
||||||
|
lac,
|
||||||
|
cellID_raw,
|
||||||
|
cellID,
|
||||||
|
};
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06ParseStatusAlarm(me, stts_string) {
|
||||||
|
if (!stts_string) {
|
||||||
|
stts_string = me.ori_string.slice(8).slice(54, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
let terminal_info_raw = stts_string.slice(0, 2);
|
||||||
|
let tib1 = LibHelper.hex2bin(terminal_info_raw); // terminal_info_byte1
|
||||||
|
let tib1_bit7 = tib1.slice(0, 1);
|
||||||
|
let tib1_bit6 = tib1.slice(1, 2);
|
||||||
|
let tib1_bit5 = tib1.slice(2, 3);
|
||||||
|
let tib1_bit4 = tib1.slice(3, 4);
|
||||||
|
let tib1_bit3 = tib1.slice(4, 5);
|
||||||
|
let tib1_bit2 = tib1.slice(5, 6);
|
||||||
|
let tib1_bit1 = tib1.slice(6, 7);
|
||||||
|
let tib1_bit0 = tib1.slice(7, 8);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: No Power (shutdown)
|
||||||
|
* 1: Extremely Low Battery (not enough for calling or sending text messages, etc.)
|
||||||
|
* 2: Very Low Battery (Low Battery Alarm)
|
||||||
|
* 3: Low Battery (can be used normally)
|
||||||
|
* 4: Medium
|
||||||
|
* 5: High
|
||||||
|
* 6: Very High
|
||||||
|
*/
|
||||||
|
let voltage_level = stts_string.slice(2, 4);
|
||||||
|
|
||||||
|
let gsm_signal_strength = stts_string.slice(4, 6);
|
||||||
|
|
||||||
|
let alarm_stts = stts_string.slice(6, 8); // former bit: terminal alarm status (suitable for alarm packet and electronic fence project)
|
||||||
|
let language = stts_string.slice(8, 10); // latter bit: the current language used in the terminal
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
terminal_info_raw: terminal_info_raw,
|
||||||
|
terminal_info_byte: tib1,
|
||||||
|
terminal_info: {
|
||||||
|
oil_electricity: tib1_bit7, // 1: oil and electricity disconnected, 0: gas oil and electricity connected
|
||||||
|
gps_tracking: tib1_bit6, // 1: GPS tracking is on, 0: GPS tracking is off
|
||||||
|
stts: `${tib1_bit5}${tib1_bit4}${tib1_bit3}`, // 100: SOS, 011: Low Battery Alarm, 010: Power Cut Alarm, 001: Shock Alarm, 000: Normal
|
||||||
|
charge: tib1_bit2, // 1: Charge On, 0: Charge Off
|
||||||
|
acc: tib1_bit1, // 1: ACC high, 0: ACC Low
|
||||||
|
is_active: tib1_bit0, // 1: Activated, 0: Deactivated
|
||||||
|
},
|
||||||
|
voltage_level,
|
||||||
|
gsm_signal_strength, // 0x00: no signal; 0x01: extremely weak signal; 0x02: very weak signal; 0x03: good signal; 0x04: strong signal.
|
||||||
|
alarm_stts, // 0x00: normal, 0x01: SOS, 0x02: Power Cut Alarm, 0x03: Shock Alarm, 0x04: Fence In Alarm, 0x05: Fence Out Alarm
|
||||||
|
language, // 0x01: Chinese, 0x02: English
|
||||||
|
};
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gt06AlarmResp(me) {
|
||||||
|
return Buffer.from("787805160001d9dc0d0a", "hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
static eelinkCustomAction(me, device_id = null) {
|
||||||
|
const act = {
|
||||||
|
device_id: me.field1,
|
||||||
|
action_type: 'exist_data',
|
||||||
|
cmd: 'exist_data',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (me.field3 == '60000000' || me.field3 == '00000000') {
|
||||||
|
act.action_type = 'no_data_since_hardware_reset';
|
||||||
|
act.cmd = 'no_data_since_hardware_reset';
|
||||||
|
|
||||||
|
// act.buffer_resp = Buffer.from('LOAD');
|
||||||
|
// act.buffer_resp = 'LOAD';
|
||||||
|
// act.buffer_resp = Buffer.from(`6767${me.field0}000A0001${me.field1}01`, 'hex');
|
||||||
|
// act.buffer_resp = `6767${me.field0}000A0001${me.field1}01`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (act.action_type !== 'exist_data') return act;
|
||||||
|
|
||||||
|
act.flag = me.field0;
|
||||||
|
act.imsi = me.field2; // International Mobile Subscriber Identifier
|
||||||
|
|
||||||
|
act.time_string = me.field3;
|
||||||
|
const time_data = {};
|
||||||
|
time_data.year = '20' + (parseInt(me.field3.slice(0, 1), 16) + 10);
|
||||||
|
time_data.month = '' + parseInt(me.field3.slice(1, 2), 16);
|
||||||
|
if (time_data.month.length === 1) { time_data.month = '0' + time_data.month; }
|
||||||
|
time_data.day = '' + parseInt(me.field3.slice(2, 4), 16);
|
||||||
|
if (time_data.day.length === 1) { time_data.day = '0' + time_data.day; }
|
||||||
|
time_data.hour = '' + parseInt(me.field3.slice(4, 6), 16);
|
||||||
|
if (time_data.hour.length === 1) { time_data.hour = '0' + time_data.hour; }
|
||||||
|
time_data.minute = '' + parseInt(me.field3.slice(6, 8), 16);
|
||||||
|
if (time_data.minute.length === 1) { time_data.minute = '0' + time_data.minute; }
|
||||||
|
act.time_data = time_data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* north => -9000000 to +9000000, can 1 or 2 digits of degree
|
||||||
|
* west => -18000000 to +18000000, usually 3 digits degree
|
||||||
|
*/
|
||||||
|
act.location_string = me.field4;
|
||||||
|
// original value is expressed as signed hex value, so we must to conversion to decimal
|
||||||
|
// using two complement
|
||||||
|
let north = ~parseInt(me.field4.slice(0, 8), 16);
|
||||||
|
let west = ~parseInt(me.field4.slice(8, 16), 16);
|
||||||
|
// add magnitude
|
||||||
|
north = north * -1 + 1;
|
||||||
|
west = west * -1 + 1;
|
||||||
|
// convert to string
|
||||||
|
north += '';
|
||||||
|
west += '';
|
||||||
|
// remove - from string at first and save to temporary variable
|
||||||
|
let signedNorth = '';
|
||||||
|
if (north.indexOf('-') === 0) {
|
||||||
|
north = north.slice(1);
|
||||||
|
signedNorth = '-';
|
||||||
|
}
|
||||||
|
let signedWest = '';
|
||||||
|
if (west.indexOf('-') === 0) {
|
||||||
|
west = west.slice(1);
|
||||||
|
signedWest = '-';
|
||||||
|
}
|
||||||
|
// separate DDM => Degree Decimal Minutes
|
||||||
|
let northDegree = north.slice(0, 1);
|
||||||
|
let northDecimalMinute = north.slice(1, 7);
|
||||||
|
if (north.length === 8) {
|
||||||
|
northDegree = north.slice(0, 2);
|
||||||
|
northDecimalMinute = north.slice(2, 7);
|
||||||
|
}
|
||||||
|
let westDegree = west.slice(0, 3);
|
||||||
|
let westDecimalMinute = west.slice(3, 7);
|
||||||
|
// convert DDM to DD (Decimal Degrees)
|
||||||
|
act.latitude = '' + signedNorth + northDegree + '.' + ('' + (northDecimalMinute/60)).replace('.', '');
|
||||||
|
act.longitude = '' + signedWest + westDegree + '.' + ('' + (westDecimalMinute/60)).replace('.', '');
|
||||||
|
|
||||||
|
return act;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = LibDevice;
|
||||||