update 21.06.2020

This commit is contained in:
Robert Richter 2020-06-21 22:53:03 +02:00
parent 211634bd7c
commit c8bd4f3974
2 changed files with 15 additions and 17 deletions

View File

@ -96,10 +96,20 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) {
// Typ ist String
if (data.constructor == String) {
// teste ob der String JSON-Konform ist
// String versuchen in JSON umzuwandeln
try {
var tmp = JSON.parse(data);
callback && callback(tmp);
} catch (error) {
callback && callback(false);
};
};
// Typ ist Object
if (data.constructor === Object) {
// teste ob der String des Objects JSON-Konform ist
var text = JSON.stringify(data);
if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// falls ja, dann versuche String in JSON zu parsen
//falls ja, dann versuche String in JSON zu parsen
try {
var tmp = JSON.parse(text);
callback && callback(tmp);
@ -110,22 +120,10 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) {
callback && callback(false);
};
};
// Typ ist Object
if (data.constructor === Object) {
console.log(data);
try {
var tmp = JSON.parse(text);
console.log(tmp);
callback && callback(tmp);
} catch (error) {
callback && callback(false);
};
};
// Log
if (app_cfg.global.development) {
//console.log('Validierung WAIP: ' + JSON.stringify(data));
console.log('Validierung WAIP: ' + JSON.stringify(data));
};
};

View File

@ -13,14 +13,14 @@ module.exports = function (app_cfg, sql, saver) {
// Warten auf Einsatzdaten
udp_server.on('message', function (message, remote) {
saver.save_new_waip(message, remote.address + ':' + remote.port, 'udp')
saver.save_new_waip(message.toString('utf8'), remote.address + ':' + remote.port, 'udp')
});
// UDP-Daten senden
function send_message(message) {
udp_server.send(message, 0, message.length, app_cfg.global.udpport, 'localhost', function (err, bytes) {
if (err) throw err;
sql.db_log('WAIP', 'UDP-Testalarm an localhost:' + app_cfg.global.udpport + ') gesendet.');
sql.db_log('WAIP', 'UDP-Testalarm an localhost:' + app_cfg.global.udpport + ' gesendet.');
});
};