added JSDoc to refull.js and websocket.js

This commit is contained in:
unknown 2021-01-15 19:08:08 +01:00
parent 35f1b3f45f
commit a40a8c5ffd
2 changed files with 30 additions and 3 deletions

View File

@ -4,14 +4,27 @@
* @authors Timo Volkmann, Frank Herkommer.
*/
// indexes of a list of all collected Serial data where Timestamps matched with the smallest time
//difference so they can be fitted on a chart with a smaller amount of tcp data
let indexes
function composeTimestamp(servertime){
/**
* function to parse a timestamp to a number
* @param time Timestamp
* @returns composed a number
*/
function composeTimestamp(time){
let composed;
composed = servertime.slice(11,25).split(':').join("").split('.').join("");
composed = time.slice(11,25).split(':').join("").split('.').join("");
return composed;
}
/**
* function to compare a Timestamp from tcp to all timestamps from serial to find a best match.
* @param num tcp timestamp
* @param arr list of serial timestamps
* @returns {(*|number)[]} array with the index of the closest Serial timestamp match
*/
function findBestTimeMatch(num, arr) {
let mid;
let lo = 0;
@ -30,6 +43,11 @@ function findBestTimeMatch(num, arr) {
return [arr[hi], hi];
}
/**
* function that calls find best match function and saves the indexes from a match into a list.
* @param tcpdataList
* @param serialdataList
*/
function findSerialDataIndex(tcpdataList, serialdataList) {
let allSerialTimes = []
@ -108,7 +126,6 @@ window.addEventListener("load", function(evt) {
updateMapSERIALbulk(r.data.Data.SOURCE_SERIAL)
addSerialSpeedData(r.data.Data.SOURCE_SERIAL)
}
addDistances(prepareForDistanceCalc(r.data.Data))
})
}

View File

@ -1,3 +1,4 @@
// Temporary TCP and Serial data used to calculate vincenty distance between two coordinates in realtime.
let tempTCPCoords = null;
let tempSERIALCoords = null;
@ -27,8 +28,10 @@ window.addEventListener("load", function(evt) {
ws.onerror = wsOnErrorF
}, 1000)
}
// function called every time a message is received by the server.
const wsOnMessageF = function (evt) {
let dat = JSON.parse(evt.data)
// If message comes from TCP source call functions to add TCP data != 0 to the charts
if ('SOURCE_TCP' in dat) {
setIndicatorsTcp(dat.SOURCE_TCP)
if(dat.SOURCE_TCP.Orientation[0] !== 0 && dat.SOURCE_TCP.Orientation[1] !== 0 && dat.SOURCE_TCP.Orientation[2] !== 0){
@ -58,6 +61,7 @@ window.addEventListener("load", function(evt) {
}
}
// If message comes from Serial source call functions to add serial data != 0 to the charts
if ('SOURCE_SERIAL' in dat) {
setIndicatorsSer(dat.SOURCE_SERIAL)
if(dat.SOURCE_SERIAL.Orientation[0] !== 0 && dat.SOURCE_SERIAL.Orientation[2] !== 0){
@ -137,6 +141,8 @@ window.addEventListener("load", function(evt) {
oldNode = output.firstChild
output.replaceChild(d, oldNode)
};
// On open send HTTP request corresponding to the chosen Source/s
document.getElementById("open").onclick = function(evt) {
if(checkBoxSmartphone.checked && checkBoxUblox.checked){
fetch('http://localhost:3011/trackings?serial=true&tcp=true', { method: 'POST', body: 'some test data'})
@ -176,6 +182,10 @@ window.addEventListener("load", function(evt) {
//------------------------Buttons------------------------------
/*
Provides every Button with the corresponding HTTP request if the websocket is open.
*/
document.getElementById("messungstarten").onclick = function(evt) {
if (ws) {
fetch('http://localhost:3011/trackings/', { method: 'PATCH', body: 'some data'})