Added new configuration to allow custom group join and individual asset ptt/gps

This commit is contained in:
Sergiu Toma 2023-03-27 22:35:18 +03:00
parent 636e3cce1a
commit 702cd0efe4
5 changed files with 90 additions and 86 deletions

View File

@ -16,24 +16,25 @@ accept_untrusted_certs = true
[settings] [settings]
max_fails = 3 max_fails = 3
send_voice = false
send_gps = true
send_group_monitoring_before_each_call = 'true' send_group_monitoring_before_each_call = 'true'
gps_report_interval = 300 # The interval in which the GPS is sent gps_report_interval = 1000 # The interval in which the GPS is sent
gps_lat_start_point = 46.217802 gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126 gps_lng_start_point = 24.776126
delay_between_clients = 300 delay_between_clients = 300
testing_duration = 600 # seconds testing_duration = 20 # seconds
[assets]
#ids = [ [[assets]]
# 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501, 5502 asset_id = 63
#] group_id = 1
generate_voice = true
generate_gps = true
ids = [ [[assets]]
1868 asset_id = 64
] group_id = 1
generate_voice = false
generate_gps = true
[sounds] [sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3'] tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -15,6 +15,9 @@ let configs = {
elogs: config.get('elogs'), elogs: config.get('elogs'),
} }
console.log('configs', configs)
// Start simulation. // Start simulation.
console.log('Starting simulation...'); console.log('Starting simulation...');
var simulator = new Simulator(configs); var simulator = new Simulator(configs);

View File

@ -18,19 +18,21 @@ const log = require('./utils').log
class Asset { class Asset {
constructor(id, configs, token) { constructor(asset, configs, token) {
this.id = id; this.id = asset.asset_id;
this.group_id = asset.group_id;
this.generate_voice = asset.generate_voice;
this.generate_gps = asset.generate_gps;
this.token = token; this.token = token;
this.configs = configs this.configs = configs
this._processConfigs(); this._processConfigs();
this.pttEndSuccessfully = false; this.pttEndSuccessfully = false;
this.assetProps = {}; this.assetProps = {};
this.murmurPassword = ''; this.murmurPassword = '';
this.startTime = null; // Will be set at the initialization of ptt(_start -> on_tt)
this.endTime = +new Date() + (this.configs.settings.testing_duration * 1000) this.endTime = +new Date() + (this.configs.settings.testing_duration * 1000)
utils.writeLog(`Creating asset ${id}`) utils.writeLog(`Creating asset ${this.id}`)
// Do async work: Init asset. // Do async work: Init asset.
async.waterfall([ async.waterfall([
@ -129,17 +131,16 @@ class Asset {
// Find what group this asset is monitoring. // Find what group this asset is monitoring.
this.groups.forEach((g) => { this.groups.forEach((g) => {
if (g.is_talk_group && g.monitoring.indexOf(this.id) != -1) { if (g.id === this.group_id) {
this.groupId = g.id;
this.groupSipId = g.sip_id; this.groupSipId = g.sip_id;
this.groupName = g.name; this.groupName = g.name;
} }
}); });
if (!this.groupId) { // if (!this.groupId) {
return callback('No talk group assigned to ' + this.id); // return callback('No talk group assigned to ' + this.id);
} // }
utils.writeLog(`Informations about asset ${this.id} received`) utils.writeLog(`Informations about asset ${this.id} received | groupId: ${this.group_id} | groupName: ${this.groupName}`);
return callback(); return callback();
} else { } else {
utils.writeLog(`Error getting informations about asset ${this.id}`, error); utils.writeLog(`Error getting informations about asset ${this.id}`, error);
@ -209,6 +210,7 @@ class Asset {
} }
_connectToMurmur(callback) { _connectToMurmur(callback) {
console.log(`Asset ${this.id} connecting to Murmur`);
this.configs.murmurPassword = this.murmurPassword; this.configs.murmurPassword = this.murmurPassword;
this.mumble = new Mumble(this.id, this.configs, (err) => { this.mumble = new Mumble(this.id, this.configs, (err) => {
@ -226,6 +228,7 @@ class Asset {
} }
_register(callback) { _register(callback) {
console.log(`Asset ${this.id} connecting to Register`);
Request.post( Request.post(
this.apiEndpoint + '/audio/register/' + this.id, this.apiEndpoint + '/audio/register/' + this.id,
{ {
@ -240,7 +243,7 @@ class Asset {
} else { } else {
console.log('_register--------------------') console.log('_register--------------------')
console.log('error---', error) console.log('error---', error)
console.log('response---', response) // console.log('response---', response)
console.log('body---', body) console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio registered error`, error); // utils.writeLog(`Asset ${this.id} audio registered error`, error);
// utils.writeErrorLog(`ERROR_API`); // utils.writeErrorLog(`ERROR_API`);
@ -251,8 +254,10 @@ class Asset {
} }
_moveToChannel(callback) { _moveToChannel(callback) {
console.log(`Asset ${this.id} move to Channel ${this.group_id}`);
// console.log('_moveToChannel', this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.group_id)
Request.post( Request.post(
this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.groupId, this.apiEndpoint + '/audio/enter-group/' + this.id + '/' + this.group_id,
{ {
headers: { headers: {
Authorization: `Bearer ${this.token}` Authorization: `Bearer ${this.token}`
@ -270,12 +275,12 @@ class Asset {
asset_alias : this.assetProps.name, asset_alias : this.assetProps.name,
request_ptt_groups_status: false, request_ptt_groups_status: false,
group_sip_id: this.groupSipId, group_sip_id: this.groupSipId,
group_id: this.groupId, group_id: this.group_id,
group_name: this.groupName, group_name: this.groupName,
scan_group_ids: null scan_group_ids: null
} }
)); ));
utils.writeLog(`Asset ${this.id} mmonitoring group ${this.groupId}`) utils.writeLog(`Asset ${this.id} monitoring group ${this.group_id}`)
if (callback) return callback(); if (callback) return callback();
} else { } else {
if (callback) return callback('Cannot send group-monitoring: Hub not connected'); if (callback) return callback('Cannot send group-monitoring: Hub not connected');
@ -283,7 +288,7 @@ class Asset {
} else { } else {
console.log('_moveToChannel--------------------') console.log('_moveToChannel--------------------')
console.log('error---', error) console.log('error---', error)
console.log('response---', response) // console.log('response---', response)
console.log('body---', body) console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio enter group error`, error); // utils.writeLog(`Asset ${this.id} audio enter group error`, error);
// utils.writeErrorLog(`ERROR_API`); // utils.writeErrorLog(`ERROR_API`);
@ -294,31 +299,8 @@ class Asset {
} }
_start() { _start() {
this.startTime = +new Date(); this.generate_voice && this._makePtt();
if(this.endTime > this.startTime) { this.generate_gps && this._sendGPS();
if(this.configs.settings.send_voice) {
this._makePtt(() => {
if(this.pttEndSuccessfully) {
this._verifyRecorder();
}
});
}
if(this.configs.settings.send_gps) {
this._sendGPS();
}
} else {
const assetIds = this.configs.assets.ids;
if(Math.max(...assetIds) == this.id) {
setTimeout(() => {
utils.writeLog('STOP')
.then(() => {
process.exit(0);
});
}, 10000);
}
}
} }
_verifyRecorder(callback) { _verifyRecorder(callback) {
@ -387,7 +369,6 @@ class Asset {
// Send ptt-press and wait for it to be accepted. // Send ptt-press and wait for it to be accepted.
this._sendPttPress((isAccepted) => { this._sendPttPress((isAccepted) => {
if (!isAccepted) { if (!isAccepted) {
return callback(); return callback();
} }
@ -432,8 +413,19 @@ class Asset {
this.pttEndSuccessfully = true; this.pttEndSuccessfully = true;
setTimeout(() => { setTimeout(() => {
this._sendPttRelease(); this._sendPttRelease();
callback(); const now = +new Date();
}, 1500); // Hangtime if(this.endTime > now) {
this._makePtt();
} else {
setTimeout(() => {
utils.writeLog(`Asset: ${this.id} - STOP`)
.then(() => {
process.exit(0);
});
}, 10000);
}
}, 1800); // 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). // @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).
@ -501,7 +493,9 @@ class Asset {
let lat = this.configs.settings.gps_lat_start_point; let lat = this.configs.settings.gps_lat_start_point;
let lng = this.configs.settings.gps_lng_start_point; let lng = this.configs.settings.gps_lng_start_point;
setTimeout(() => { setInterval(() => {
const now = +new Date();
if(this.endTime > now) {
var new_lat = this._randomCoordinates(lat); var new_lat = this._randomCoordinates(lat);
var new_lng = this._randomCoordinates(lng); var new_lng = this._randomCoordinates(lng);
@ -520,8 +514,13 @@ class Asset {
)); ));
lat = new_lat; lat = new_lat;
lng = new_lng; lng = new_lng;
if (!this.configs.settings.send_voice) { } else {
this._start(); setTimeout(() => {
utils.writeLog(`Asset: ${this.id} - STOP`)
.then(() => {
process.exit(0);
});
}, 11000);
} }
}, this.configs.settings.gps_report_interval); }, this.configs.settings.gps_report_interval);
} }
@ -544,7 +543,7 @@ class Asset {
if (data.asset_id != this.id) { if (data.asset_id != this.id) {
return; return;
} }
utils.writeLog(`Asset ${this.id} sending PTT-PRESS to group ${this.groupId}`) utils.writeLog(`Asset ${this.id} sending PTT-PRESS to group ${this.group_id}`)
hub.removeListener('ptt-deny', pttDenyHandler); hub.removeListener('ptt-deny', pttDenyHandler);
callback(true); callback(true);
}; };
@ -563,7 +562,7 @@ class Asset {
hub.emit('ptt-press', JSON.stringify( hub.emit('ptt-press', JSON.stringify(
{ {
destination_group_id: this.groupId, destination_group_id: this.group_id,
destination_group_sip_id: this.groupSipId, destination_group_sip_id: this.groupSipId,
destination_asset_id: 0, destination_asset_id: 0,
destination_asset_sip_id: 0, destination_asset_sip_id: 0,
@ -582,10 +581,10 @@ class Asset {
let hub = this.hub; let hub = this.hub;
if (hub && hub.connected) { if (hub && hub.connected) {
utils.writeLog(`Asset ${this.id} sending PTT-RELEASE to group ${this.groupId}`); utils.writeLog(`Asset ${this.id} sending PTT-RELEASE to group ${this.group_id}`);
hub.emit('ptt-release', JSON.stringify( hub.emit('ptt-release', JSON.stringify(
{ {
destination_group_id: this.groupId, destination_group_id: this.group_id,
destination_group_sip_id: this.groupSipId, destination_group_sip_id: this.groupSipId,
destination_asset_id: 0, destination_asset_id: 0,
destination_asset_sip_id: 0, destination_asset_sip_id: 0,

View File

@ -12,7 +12,6 @@ const OpusEncoder = require('node-opus').OpusEncoder;
class Mumble { class Mumble {
constructor(id, configs, connectedCallback) { constructor(id, configs, connectedCallback) {
console.log('------', configs)
this.id = id; this.id = id;
this.configs = configs; this.configs = configs;
let mumble = configs.mumble; let mumble = configs.mumble;
@ -104,7 +103,7 @@ class Mumble {
.on('reconnect', function (n, delay) { .on('reconnect', function (n, delay) {
// n = current number of reconnect // n = current number of reconnect
// delay = delay used before reconnect // delay = delay used before reconnect
console.log('------ Server reconnect...'); // console.log('------ Server reconnect...');
// utils.writeErrorLog(`ERROR_MUMBLE_RECONNECT`); // utils.writeErrorLog(`ERROR_MUMBLE_RECONNECT`);
// utils.exitWriteErrorLog(`ERROR_MUMBLE_RECONNECT`); // utils.exitWriteErrorLog(`ERROR_MUMBLE_RECONNECT`);
}) })

View File

@ -12,8 +12,8 @@ class Simulator {
this.configs = configs; this.configs = configs;
this.token; this.token;
// Read assets ids from configs this.assets = configs.assets;
this.assetIds = configs.assets.ids; this.assetIds = this.assets.map(asset => asset.asset_id);
this.apiEndpoint = this.configs.api.use_secure ? 'https' : 'http'; this.apiEndpoint = this.configs.api.use_secure ? 'https' : 'http';
this.apiEndpoint += '://' + this.configs.api.host + (this.configs.api.port ? (':' + this.configs.api.port) : ''); this.apiEndpoint += '://' + this.configs.api.host + (this.configs.api.port ? (':' + this.configs.api.port) : '');
@ -36,16 +36,17 @@ class Simulator {
_start() { _start() {
const settings = this.configs.settings; const settings = this.configs.settings;
this.assetIds.forEach((id, i) => { // this.assetIds.forEach((id, i) => {
this.assets.forEach((asset, i) => {
let delay_between_clients = 500; let delay_between_clients = 500;
if(settings.hasOwnProperty('delay_between_clients')) { if(settings.hasOwnProperty('delay_between_clients')) {
delay_between_clients = parseInt(settings.delay_between_clients, 10); delay_between_clients = parseInt(settings.delay_between_clients, 10);
} }
console.log('id', id, i * delay_between_clients+'ms') console.log('asset_id', asset.asset_id, i * delay_between_clients+'ms')
delay_between_clients = this._getRandomInt(delay_between_clients); delay_between_clients = this._getRandomInt(delay_between_clients);
setTimeout(() => { setTimeout(() => {
new Asset(id, this.configs, this.token); new Asset(asset, this.configs, this.token);
// console.log('id, this.configs, this.token', id, this.configs, this.token) // console.log('id, this.configs, this.token', id, this.configs, this.token)
}, i * delay_between_clients); }, i * delay_between_clients);
}) })
@ -74,6 +75,7 @@ class Simulator {
} }
_unregisterAsstes(callback) { _unregisterAsstes(callback) {
let url = this.apiEndpoint + '/audio/un-register/[' + this.assetIds + ']/'; let url = this.apiEndpoint + '/audio/un-register/[' + this.assetIds + ']/';
Request.post( Request.post(
url, url,