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]
max_fails = 3
send_voice = false
send_gps = 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_lng_start_point = 24.776126
delay_between_clients = 300
testing_duration = 600 # seconds
testing_duration = 20 # seconds
[assets]
#ids = [
# 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501, 5502
#]
[[assets]]
asset_id = 63
group_id = 1
generate_voice = true
generate_gps = true
ids = [
1868
]
[[assets]]
asset_id = 64
group_id = 1
generate_voice = false
generate_gps = true
[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']

View File

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

View File

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

View File

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

View File

@ -12,12 +12,12 @@ class Simulator {
this.configs = configs;
this.token;
// Read assets ids from configs
this.assetIds = configs.assets.ids;
this.assets = configs.assets;
this.assetIds = this.assets.map(asset => asset.asset_id);
this.apiEndpoint = this.configs.api.use_secure ? 'https' : 'http';
this.apiEndpoint += '://' + this.configs.api.host + (this.configs.api.port ? (':' + this.configs.api.port) : '');
async.waterfall([
this._manageLogs.bind(this),
this._unregisterAsstes.bind(this),
@ -36,16 +36,17 @@ class Simulator {
_start() {
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;
if(settings.hasOwnProperty('delay_between_clients')) {
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);
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)
}, i * delay_between_clients);
})
@ -74,6 +75,7 @@ class Simulator {
}
_unregisterAsstes(callback) {
let url = this.apiEndpoint + '/audio/un-register/[' + this.assetIds + ']/';
Request.post(
url,