LAPI:705: Generate GPS and voice are two separate process; Added exit function

This commit is contained in:
2023-05-15 20:44:50 +03:00
parent 0c62a937ec
commit 2a22d7a209
5 changed files with 66 additions and 44 deletions

View File

@ -344,8 +344,17 @@ class Asset {
}
_start() {
this.generate_voice && this._makePtt();
this.generate_gps && this._sendGPS();
this.generate_voice && this._makePtt(); // Generate voce
this.generate_gps && this._sendGPS(); // Generate GPS
this._measuringTestTime(); // Process exit base on this.endTime and current date
}
_measuringTestTime() {
setInterval(() => {
if(Date.now() > this.endTime + 18000) {
process.exit(0)
}
}, 1000);
}
_verifyRecorder(callback) {
@ -458,19 +467,12 @@ class Asset {
this.pttEndSuccessfully = true;
setTimeout(() => {
this._sendPttRelease();
const now = +new Date();
if(this.endTime > now) {
if(this.endTime > +new Date()) {
this._makePtt(callback);
} else {
setTimeout(() => {
utils.writeLog(`Asset: ${this.id} - STOP`)
.then(() => {
process.exit(0);
});
}, 10000);
utils.writeLog(`Asset ${this.id} Voice sleeping...`);
}
}, 1800); // Hangtime
}, 1500); // Hangtime
});
// @TODO: Ugly hack for the voice to work with mp3 (The fix is to remove float32ToInt16 conversion). It is the _transform function from OpusEncoderStream class (mumble-client-codecs-node project).
@ -532,7 +534,7 @@ class Asset {
})
}
_sendGPS(callback) {
_sendGPS() {
let hub = this.hub;
if (hub && hub.connected) {
let lat = this.configs.settings.gps_lat_start_point;
@ -547,36 +549,30 @@ class Asset {
interval = this.configs.settings.gps_report_interval;
}
setInterval(() => {
const now = +new Date();
if(this.endTime > now) {
var new_lat = this._randomCoordinates(lat);
var new_lng = this._randomCoordinates(lng);
const now = +new Date();
if(this.endTime > now) {
var new_lat = this._randomCoordinates(lat);
var new_lng = this._randomCoordinates(lng);
hub.emit('gps', JSON.stringify(
{
unix_time: 1467126677000,
asset_id: this.assetProps.id,
asset_sip_id: this.assetProps.sip_id,
speed_kmh: 16,
lat: new_lat,
lng: new_lng,
accuracy: 20.3,
activity_type: "driving",
activity_confidence: 90
}
));
lat = new_lat;
lng = new_lng;
} else {
setTimeout(() => {
utils.writeLog(`Asset: ${this.id} - STOP`)
.then(() => {
process.exit(0);
});
}, 11000);
}
}, interval);
hub.emit('gps', JSON.stringify(
{
unix_time: 1467126677000,
asset_id: this.assetProps.id,
asset_sip_id: this.assetProps.sip_id,
speed_kmh: 16,
lat: new_lat,
lng: new_lng,
accuracy: 20.3,
activity_type: "driving",
activity_confidence: 90
}
));
lat = new_lat;
lng = new_lng;
setTimeout(() => { this._sendGPS(); }, interval);
} else {
utils.writeLog(`Asset ${this.id} GPS sleeping...`);
}
}
}