DTC in WebUI now handled via Websocket

This commit is contained in:
Marcel Peterkau 2023-12-04 02:18:16 +01:00
parent aa3a2106aa
commit a576c7b70c
8 changed files with 220 additions and 83 deletions

View File

@ -75,11 +75,11 @@
</p>
<!-- Div Group current Mode -->
<!-- Div Group DTC Table -->
<div %SHOW_DTC_TABLE%>
<div id="dtc_container" hidden>
<hr />
<p>
<h4>Fehlercodes</h4>
<table class="table">
<table class="table" id="dtc_table">
<tbody>
<tr>
<th class="col-6" scope="col">Zeitstempel</th>
@ -87,7 +87,6 @@
<th class="col-2" scope="col">Schwere</th>
<th class="col-2" scope="col">Aktiv</th>
</tr>
%DTC_TABLE%
</tbody>
</table>
</p>
@ -803,18 +802,10 @@
nextSibling.innerText = fileName
});
$(document).ready(function () {
$("tr[data-dtc]").each(function (i) {
$(this).attr('data-toggle', "modal");
$(this).attr('data-target', "#dtcModal");
});
});
$('#dtcModal').on('show.bs.modal', function (event) {
var dtctr = $(event.relatedTarget)
var dtc = dtctr.data('dtc')
var debugval = dtctr.data('debugval')
var modal = $(this)
$('table').on('click', 'tr[data-dtc]', function () {
var dtc = $(this).data('dtc');
var debugval = $(this).data('debugval');
var modal = $('#dtcModal');
getDescriptionForDTCNumber(dtc, function (error, title, description) {
if (error)
@ -837,6 +828,8 @@
}
}
});
// Modal anzeigen
modal.modal('show');
});
</script>

View File

@ -71,6 +71,21 @@
},
{
"num": 14,
"title": "Dummy-DTC Info",
"description": "Ein Dummy-DTC der Schwere \"Info\" für Debugging-Zwecke"
},
{
"num": 15,
"title": "Dummy-DTC Warnung",
"description": "Ein Dummy-DTC der Schwere \"Warnung\" für Debugging-Zwecke"
},
{
"num": 16,
"title": "Dummy-DTC Kritisch",
"description": "Ein Dummy-DTC der Schwere \"Kritisch\" für Debugging-Zwecke"
},
{
"num": 17,
"title": "Last Error",
"description": "Last Error"
}

View File

@ -12,7 +12,11 @@ function getDescriptionForDTCNumber(number, callback) {
callback(null, title, description);
} else {
// Wenn die Nummer nicht gefunden wurde, geben Sie einen Fehler zurück
callback(`Beschreibung für Nummer ${number} nicht gefunden.`,null, null);
callback(
`Beschreibung für Nummer ${number} nicht gefunden.`,
null,
null
);
}
})
.catch((error) => {
@ -21,3 +25,98 @@ function getDescriptionForDTCNumber(number, callback) {
});
}
function fillDTCTable(dtcArray) {
// Referenz auf das Tabellen-Element
var table = document.getElementById("dtc_table");
var tablediv = document.getElementById("dtc_container");
// Prüfen, ob DTC vorhanden sind
if (dtcArray.length === 0) {
// Verstecke das Tabellen-Div, wenn keine DTC vorhanden sind
tablediv.hidden = true;
return;
} else {
// Zeige das Tabellen-Div, wenn DTC vorhanden sind
tablediv.hidden = false;
}
// Tabelle leeren, bevor sie neu gefüllt wird
table.innerHTML = "";
// Überschriften für die Tabelle erstellen
var headerRow = table.insertRow(0);
// Definition der Klassen und Scopes für die Spalten
var columnDefinitions = [
{ class: "col-6", scope: "Zeitstempel" },
{ class: "col-2", scope: "Fehlercode" },
{ class: "col-2", scope: "Schwere" },
{ class: "col-2", scope: "Aktiv" },
];
for (var i = 0; i < columnDefinitions.length; i++) {
var headerCell = headerRow.insertCell(i);
headerCell.className = `th ${columnDefinitions[i].class}`;
headerCell.scope = columnDefinitions[i].scope;
headerCell.innerHTML = columnDefinitions[i].scope;
}
// DTC-Daten in die Tabelle einfügen
for (var i = 0; i < dtcArray.length; i++) {
var dtcInfo = dtcArray[i].split(",");
var row = table.insertRow(i + 1); // +1 wegen der Überschriftenzeile
// Zeitstempel
var timestampCell = row.insertCell(0);
timestampCell.innerHTML = formatTimestamp(parseInt(dtcInfo[0]));
// Fehlercode
var errorCodeCell = row.insertCell(1);
errorCodeCell.innerHTML = dtcInfo[1];
// Schwere
var severityCell = row.insertCell(2);
var severity = parseInt(dtcInfo[2]);
// Schwere
switch (severity) {
case 1:
severityCell.innerHTML = '<img src="static/img/info.png" alt="Info" />';
break;
case 2:
severityCell.innerHTML =
'<img src="static/img/warn.png" alt="Warnung" />';
break;
case 3:
severityCell.innerHTML =
'<img src="static/img/critical.png" alt="Kritisch" />';
break;
default:
severityCell.innerHTML =
'<img src="static/img/none.png" alt="Unbekannt" />';
}
row.setAttribute("data-dtc", dtcInfo[1]);
row.setAttribute("data-debugval", dtcInfo[4]);
// Aktivität
var activityCell = row.insertCell(3);
activityCell.innerHTML = parseInt(dtcInfo[3]) === 1 ? "active" : "previous";
}
}
function formatTimestamp(milliseconds) {
const date = new Date(milliseconds);
const days = String(date.getUTCDate() - 1).padStart(2, "0");
const hours = String(date.getUTCHours()).padStart(2, "0");
const minutes = String(date.getUTCMinutes()).padStart(2, "0");
const seconds = String(date.getUTCSeconds()).padStart(2, "0");
const millisecondsFormatted = String(date.getUTCMilliseconds()).padStart(
3,
"0"
);
return `${days}-${hours}:${minutes}:${seconds}:${millisecondsFormatted}`;
}

View File

@ -30,12 +30,27 @@ function onClose(event) {
}
function onMessage(event) {
var data = event.data;
if (data.startsWith("DEBUG:")) {
var addtext = data.slice(6);
var livedebug_out = document.getElementById("livedebug-out");
var textarea_heigth = livedebug_out.scrollHeight;
livedebug_out.value += event.data;
livedebug_out.value += addtext;
livedebug_out.scrollTop = livedebug_out.scrollHeight;
do_resize(livedebug_out);
}
if (data.startsWith("DTC:")) {
const dtcs = data.slice(4);
const dtcArray = dtcs.trim() !== "" ? dtcs.split(";").filter(Boolean) : [];
if(dtcArray[0] != "0")
{
notifyMe();
fillDTCTable(dtcArray);
}
console.log(dtcArray + "\n");
}
console.log("ws_msg:" + event.data + "\n");
}
function onLoad(event) {
initWebSocket();
@ -66,3 +81,19 @@ function do_resize(textbox) {
else if (rows < minrows) textbox.rows = minrows;
else textbox.rows = rows;
}
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
const notification = new Notification("Hi there!");
// …
} else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
const notification = new Notification("Hi there!");
// …
}
});
}
}

View File

@ -1,4 +1,4 @@
// Auto-generated by script on 2023-10-20 12:04:36
// Auto-generated by script on 2023-12-04 02:10:49
#ifndef DTC_DEFS_H
#define DTC_DEFS_H
@ -40,7 +40,10 @@ typedef struct {
#define DTC_CAN_TRANSCEIVER_FAILED 11
#define DTC_NO_CAN_SIGNAL 12
#define DTC_EEPROM_CFG_SANITY 13
#define DTC_LAST_DTC 14
#define DTC_FAKE_DTC_INFO 14
#define DTC_FAKE_DTC_WARN 15
#define DTC_FAKE_DTC_CRIT 16
#define DTC_LAST_DTC 17
const DTC_t dtc_definitions[] = {
{ DTC_NO_DTC , DTC_NONE }, // No Error
@ -57,9 +60,12 @@ const DTC_t dtc_definitions[] = {
{ DTC_CAN_TRANSCEIVER_FAILED , DTC_CRITICAL }, // Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte
{ DTC_NO_CAN_SIGNAL , DTC_WARN }, // Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen
{ DTC_EEPROM_CFG_SANITY , DTC_WARN }, // Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen
{ DTC_FAKE_DTC_INFO , DTC_INFO }, // Ein Dummy-DTC der Schwere "Info" für Debugging-Zwecke
{ DTC_FAKE_DTC_WARN , DTC_WARN }, // Ein Dummy-DTC der Schwere "Warnung" für Debugging-Zwecke
{ DTC_FAKE_DTC_CRIT , DTC_CRITICAL }, // Ein Dummy-DTC der Schwere "Kritisch" für Debugging-Zwecke
{ DTC_LAST_DTC , DTC_NONE } // Last Error
};
const uint32_t dtc_generation_timestamp = 1697796276;
const uint32_t dtc_generation_timestamp = 1701652249;
#endif // DTC_DEFS_H

View File

@ -175,12 +175,20 @@ void processCmdDebug(String command)
Debug_dumpPersistance();
else if (command == "saveEE")
globals.requestEEAction = EE_ALL_SAVE;
else if (command == "showdtc")
Debug_ShowDTCs();
else if (command == "dumpGlobals")
Debug_dumpGlobals();
else if (command == "sdbg")
SetDebugportStatus(dbg_Serial, enabled);
else if (command == "dtc_show")
Debug_ShowDTCs();
else if (command == "dtc_clear")
ClearAllDTC();
else if (command == "dtc_crit")
MaintainDTC(DTC_FAKE_DTC_CRIT, true, millis());
else if (command == "dtc_warn")
MaintainDTC(DTC_FAKE_DTC_WARN, true, millis());
else if (command == "dtc_info")
MaintainDTC(DTC_FAKE_DTC_INFO, true, millis());
else
Debug_pushMessage("unknown Command\n");
}

View File

@ -13,4 +13,6 @@
11; DTC_CAN_TRANSCEIVER_FAILED; DTC_CRITICAL; CAN-Transceiver Error; Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte
12; DTC_NO_CAN_SIGNAL; DTC_WARN; Keine CAN-Verbindung; Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen
13; DTC_EEPROM_CFG_SANITY; DTC_WARN; Config-Validierung; Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen
14; DTC_FAKE_DTC_INFO; DTC_INFO; Dummy-DTC Info; Ein Dummy-DTC der Schwere "Info" für Debugging-Zwecke
15; DTC_FAKE_DTC_WARN; DTC_WARN; Dummy-DTC Warnung; Ein Dummy-DTC der Schwere "Warnung" für Debugging-Zwecke
16; DTC_FAKE_DTC_CRIT; DTC_CRITICAL; Dummy-DTC Kritisch; Ein Dummy-DTC der Schwere "Kritisch" für Debugging-Zwecke

View File

@ -67,7 +67,15 @@ void initWebUI()
void Webserver_Process()
{
#ifdef FEATURE_ENABLE_WEBSOCKETS
static uint32_t previousMillis = 0;
webSocket.cleanupClients();
if ((webSocket.count() > 0) && (millis() - previousMillis >= 10000))
{
Websocket_RefreshClientData_DTCs();
previousMillis = millis();
}
#endif
}
@ -161,58 +169,6 @@ String processor(const String &var)
#else
return "hidden";
#endif
if (var == "SHOW_DTC_TABLE")
return globals.hasDTC ? "" : "hidden";
if (var == "DTC_TABLE")
{
String temp = "";
char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number < DTC_LAST_DTC)
{
sprintf(buff_timestamp, "%02d-%02d:%02d:%02d:%03d",
DTCStorage[i].timestamp / 86400000, // Days
DTCStorage[i].timestamp / 360000 % 24, // Hours
DTCStorage[i].timestamp / 60000 % 60, // Minutes
DTCStorage[i].timestamp / 1000 % 60, // Seconds
DTCStorage[i].timestamp % 1000); // milliseconds
temp = temp + "<tr data-dtc=" + String(DTCStorage[i].Number);
temp = temp + " data-debugval=" + String(DTCStorage[i].debugVal) + "><td>" + String(buff_timestamp);
temp = temp + "</td><td>" + String(DTCStorage[i].Number) + "</td><td>";
temp = temp + "<img src=static/img/";
switch (getSeverityForDTC(DTCStorage[i].Number))
{
case DTC_CRITICAL:
temp = temp + "critical";
break;
case DTC_WARN:
temp = temp + "warn";
break;
case DTC_INFO:
temp = temp + "info";
break;
case DTC_NONE:
temp = temp + "none";
break;
}
temp = temp + ".png></td><td>";
if (DTCStorage[i].active == DTC_ACTIVE)
temp = temp + "active";
else if (DTCStorage[i].active == DTC_PREVIOUS)
temp = temp + "previous";
else
temp = temp + "none";
temp = temp + "</td></tr>";
}
}
return temp;
}
if (var == "SOURCE_SELECT_OPTIONS")
{
@ -685,6 +641,33 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len)
void Websocket_PushLiveDebug(String Message)
{
webSocket.textAll(Message + "\n");
webSocket.textAll("DEBUG:" + Message);
}
void Websocket_RefreshClientData_DTCs()
{
String temp = "";
// Build DTC-String
if (globals.hasDTC != true)
{
temp = "DTC:" + String(DTC_NO_DTC) + ";";
}
else
{
temp = "DTC:";
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number < DTC_LAST_DTC)
{
temp = temp + String(DTCStorage[i].timestamp) + ",";
temp = temp + String(DTCStorage[i].Number) + ",";
temp = temp + String(getSeverityForDTC(DTCStorage[i].Number)) + ",";
temp = temp + String(DTCStorage[i].active) + ",";
temp = temp + String(DTCStorage[i].debugVal) + ";";
}
}
}
webSocket.textAll(temp);
}
#endif