CM69 - Bugfix graph cartest, CMXX - Healthindex update

This commit is contained in:
“VeLiTi”
2024-10-02 16:57:01 +02:00
parent 17df4c7bc1
commit bf567ec426
14 changed files with 776 additions and 125 deletions

View File

@@ -2,15 +2,6 @@ var port, textEncoder, writableStreamClosed, writer, historyIndex = -1;
const lineHistory = [];
maintenanceRun = 0;
// To read and clean device data
const VCP = []; //for VCP values
const VPP1 = []; //for VPP1 values
const VPP2 = []; //for VPP2 values
const VBAT = []; //for VBAT values
const PWM = []; //for PWM values
const STATE = []; //for STATE values
const xChart = []; //x-axis chart values
function progressBar(percentage, message, color){
var readbar = document.getElementById("readBar");
readBar.style.background = color;
@@ -239,26 +230,92 @@ const plug_data = document.getElementById("plug_data");
async function appendToTerminal(newStuff) {
serialResultsDiv.innerHTML += newStuff;
const keyword = '$STATUS;STATE';
const keyword2 = 'PWM';
// To read and clean device data
VCP = []; //for VCP values
VPP1 = []; //for VPP1 values
VPP2 = []; //for VPP2 values
VBAT = []; //for VBAT values
PWM = []; //for PWM values
STATE = []; //for STATE values
xChart = []; //x-axis chart values
// Input string with multiple status reports
const statusString = serialResultsDiv.innerHTML;
let lineCounter = 0;
// Split the input by newline to get each status report
let statusLines = statusString.split(/\r?\n/);
// Process each status line and populate the parameter arrays and counters
statusLines.forEach((line) => {
if (line.includes(keyword) && line.includes(keyword2) && /\d$/.test(line.trim())) {
const pairs = line.split(';'); // Split by ';'
// Loop through each pair and split by '='
pairs.forEach(pair => {
const [key, value] = pair.split('=');
if (key && value !== undefined && key !== "$STATUS") { // Skip '$STATUS'
// Push the value and counter to the corresponding parameter object
if (key === "STATE") {
let state
switch (value) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
default:
state = 0;
break;
}
STATE.push(state);
} else if (key === "VCP") {
VCP.push(value / 1000000);
} else if (key === "VPP1") {
VPP1.push(value / 1000000);
} else if (key === "VPP2") {
VPP2.push(value / 1000000);
} else if (key === "VBAT") {
VBAT.push(value / 1000000);
} else if (key === "PWM") {
PWM.push(value /10);
}
}
});
xChart.push(lineCounter);
lineCounter = lineCounter + 1;
}
});
//vcp_data.value +=newStuff
if (typeof plug_data !== "undefined"){
if (typeof plug_data !== "undefined"){
var plugdata = {"VCP":{VCP}, "VPP1":{VPP1},"VPP2":{VPP2},"VBAT":{VBAT}, "PWM":{PWM},"STATE":{STATE}, "xChart":{xChart}}
plug_data.value = JSON.stringify(plugdata);
}
serialOutput +=newStuff;
//serialOutput +=newStuff;
}
function renderChart(){
var test = serialResultsDiv.innerHTML.split(";");
test.forEach(getData);
const xValues = xChart;
new Chart("chart_VCP", {
type: "line",
data: {
labels: xValues,
labels: xChart,
datasets: [{
label: "VCP",
data: VCP,
@@ -300,54 +357,76 @@ function renderChart(){
}
//Get the RAW data and turn into object
function getData(item) {
function getData() {
const keyword = '$STATUS;STATE';
const keyword2 = 'PWM';
let item_array = item.split("=");
let xaxis = xChart.length + 1;
// To read and clean device data
const VCP = []; //for VCP values
const VPP1 = []; //for VPP1 values
const VPP2 = []; //for VPP2 values
const VBAT = []; //for VBAT values
const PWM = []; //for PWM values
const STATE = []; //for STATE values
const xChart = []; //x-axis chart values
// Input string with multiple status reports
const statusString = serialResultsDiv.innerHTML;
let lineCounter = 0;
// Split the input by newline to get each status report
let statusLines = statusString.split(/\r?\n/);
// Process each status line and populate the parameter arrays and counters
statusLines.forEach((line) => {
if (line.includes(keyword) && line.includes(keyword2) && /\d$/.test(line.trim())) {
const pairs = line.split(';'); // Split by ';'
if (item_array[0] == "VCP"){
let vcp = item_array[1] / 1000000;
VCP.push(vcp)
xChart.push(xaxis);
}
if (item_array[0] == "VPP1"){
let vpp1 = item_array[1] / 1000000;
VPP1.push(vpp1)
}
if (item_array[0] == "VPP2"){
let vpp2 = item_array[1] / 1000000;
VPP2.push(vpp2)
}
if (item_array[0] == "VBAT"){
let vbat = item_array[1] / 1000000;
VBAT.push(vbat)
}
if (item_array[0] == "STATE"){
let state
switch (item_array[1]) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
}
STATE.push(state)
}
if (item_array[0] == "PWM")
{
var check_return = item_array[1].match(/[^\r\n]+/g);
if (check_return.length == 2){
let pwm = check_return[0] / 10;
PWM.push(pwm)
}
// Loop through each pair and split by '='
pairs.forEach(pair => {
const [key, value] = pair.split('=');
if (key && value !== undefined && key !== "$STATUS") { // Skip '$STATUS'
// Push the value and counter to the corresponding parameter object
if (key === "STATE") {
let state
switch (value) {
case 'FULL_CONNECT':
state = 5;
break;
case 'REACTIVATE':
state = 3;
break;
case 'WAIT_CONNECT':
state = -5;
break;
case 'DISCONNECTED':
state = 0;
break;
default:
state = 0;
break;
}
STATE.push(state);
} else if (key === "VCP") {
VCP.push(value / 1000000);
} else if (key === "VPP1") {
VPP1.push(value / 1000000);
} else if (key === "VPP2") {
VPP2.push(value / 1000000);
} else if (key === "VBAT") {
VBAT.push(value / 1000000);
} else if (key === "PWM") {
PWM.push(value /10);
}
}
});
xChart.push(lineCounter);
lineCounter = lineCounter + 1;
}
});
}
async function closePort(){