first Values updated by websockets!
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
var gateway = `ws://${window.location.hostname}/ws`;
|
||||
var websocket;
|
||||
|
||||
var statusMapping;
|
||||
var staticMapping;
|
||||
|
||||
window.addEventListener("load", onLoad);
|
||||
|
||||
function initWebSocket() {
|
||||
@@ -31,25 +34,79 @@ function onClose(event) {
|
||||
|
||||
function onMessage(event) {
|
||||
var data = event.data;
|
||||
console.log("ws_msg:" + event.data + "\n");
|
||||
|
||||
if (data.startsWith("DEBUG:")) {
|
||||
var addtext = data.slice(6);
|
||||
var livedebug_out = document.getElementById("livedebug-out");
|
||||
livedebug_out.value += addtext;
|
||||
livedebug_out.scrollTop = livedebug_out.scrollHeight;
|
||||
do_resize(livedebug_out);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.startsWith("DTC:")) {
|
||||
const dtcs = data.slice(4);
|
||||
const dtcArray = dtcs.trim() !== "" ? dtcs.split(";").filter(Boolean) : [];
|
||||
|
||||
if(dtcArray[0] != "0")
|
||||
{
|
||||
if (dtcArray[0] != "0") {
|
||||
processDTCNotifications(dtcArray);
|
||||
fillDTCTable(dtcArray);
|
||||
}
|
||||
console.log(dtcArray + "\n");
|
||||
return;
|
||||
}
|
||||
console.log("ws_msg:" + event.data + "\n");
|
||||
|
||||
if (data.startsWith("MAPPING_STATUS:")) {
|
||||
const data_sliced = data.slice(15);
|
||||
statusMapping = createMapping(data_sliced);
|
||||
}
|
||||
|
||||
if (data.startsWith("MAPPING_STATIC:")) {
|
||||
const data_sliced = data.slice(15);
|
||||
staticMapping = createMapping(data_sliced);
|
||||
}
|
||||
|
||||
if (data.startsWith("STATUS:")) {
|
||||
const data_sliced = data.slice(7);
|
||||
const result = processDataString(data_sliced, statusMapping);
|
||||
console.log("STATUS:");
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
fillValuestoHTML(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.startsWith("STATIC:")) {
|
||||
const data_sliced = data.slice(7);
|
||||
const result = processDataString(data_sliced, staticMapping);
|
||||
console.log("STATIC:");
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
fillValuestoHTML(result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function createMapping(mappingString) {
|
||||
const mappingArray = mappingString.split(";");
|
||||
const mapping = [];
|
||||
|
||||
mappingArray.forEach((variable) => {
|
||||
if (variable !== null) mapping.push(variable.trim());
|
||||
});
|
||||
return mapping;
|
||||
}
|
||||
|
||||
function processDataString(dataString, mapping) {
|
||||
const valuesArray = dataString.split(";");
|
||||
const dataObject = {};
|
||||
|
||||
valuesArray.forEach((value, index) => {
|
||||
const variable = mapping[index];
|
||||
if (variable) {
|
||||
dataObject[variable] = value.trim();
|
||||
}
|
||||
});
|
||||
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
function onLoad(event) {
|
||||
@@ -82,4 +139,11 @@ function do_resize(textbox) {
|
||||
else textbox.rows = rows;
|
||||
}
|
||||
|
||||
|
||||
function fillValuestoHTML(dataset) {
|
||||
for (var key in dataset) {
|
||||
var inputElement = document.getElementById(key);
|
||||
if (inputElement) {
|
||||
inputElement.value = dataset[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user