From f59ea3e3ed8bb97fe1ae347e1d7b2119aa4f4f2d Mon Sep 17 00:00:00 2001 From: krakenrf <> Date: Thu, 27 Oct 2022 11:28:39 +0100 Subject: add middleware folder --- middleware | 1 - middleware/simulation_from_log.js | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) delete mode 160000 middleware create mode 100644 middleware/simulation_from_log.js (limited to 'middleware/simulation_from_log.js') diff --git a/middleware b/middleware deleted file mode 160000 index fd52f67..0000000 --- a/middleware +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fd52f677a62a9a0728b4ab87d687e709f3e681de diff --git a/middleware/simulation_from_log.js b/middleware/simulation_from_log.js new file mode 100644 index 0000000..ef86304 --- /dev/null +++ b/middleware/simulation_from_log.js @@ -0,0 +1,63 @@ +const axios = require('axios'); + +const fs = require('fs'); +const { syncBuiltinESMExports } = require('module'); + +var logArray = []; +var logIndex = 0; +try { + const data = fs.readFileSync('redoubt360.csv', 'UTF-8'); + const lines = data.split(/\r?\n/); + + lines.forEach(line => { + var logData = line.split(','); + + var logEntry = { + tStamp: parseInt(logData[0]), + latitude: parseFloat(logData[1]), + longitude: parseFloat(logData[2]), + gpsBearing: parseFloat(logData[3]), + radioBearing: parseFloat(logData[5]), + conf: parseInt(logData[6]), + power: parseFloat(logData[7]), + freq: parseInt(logData[8]), + antType: logData[9], + latency: parseInt(logData[10]), + doaArray: logData.slice(12, logData.length-1).map(x => parseFloat(x))+",", + }; +/* + // new Format + var logEntry = { + tStamp: parseInt(logData[0]), + latitude: parseFloat(logData[8]), + longitude: parseFloat(logData[9]), + gpsBearing: parseFloat(logData[10]), + radioBearing: parseFloat(logData[1]), + conf: parseFloat(logData[2]), + power: parseFloat(logData[3]), + freq: parseInt(logData[4]), + antType: logData[5], + latency: parseInt(logData[6]), + doaArray: logData.slice(17, logData.length).map(x => parseFloat(x))+",", + };*/ + //console.log(logEntry.doaArray); + logArray.push(logEntry); + }); + +} catch (err) { + console.error(err); +} + +setInterval(() => { +if (logIndex <= logArray.length) { + console.log("Sending Data as kraken: "+logArray[logIndex]) + axios.post('http://localhost:8042/doapost', logArray[logIndex]) + .then(function (response) { + //console.log(response); + }) + .catch(function (error) { + console.log(error); + }); + logIndex++; +} +}, 1000); \ No newline at end of file -- cgit v1.2.3