diff --git a/Software/build_dtcs.py b/Software/build_dtcs.py new file mode 100644 index 0000000..662765e --- /dev/null +++ b/Software/build_dtcs.py @@ -0,0 +1,142 @@ +import os +import time +import json + +# Pfad zur Eingabedatei und Ausgabedatei +input_file = "src/dtc_defs.txt" +output_file = "include/dtc_defs.h" +json_output_file = "data_src/static/dtc_table.json" + +# Ãœberprüfen, ob das Verzeichnis existiert, andernfalls erstellen +json_output_dir = os.path.dirname(json_output_file) +if not os.path.exists(json_output_dir): + os.makedirs(json_output_dir) + +# Mehrdimensionales Array zum Speichern der Zeilen aus der Eingabedatei +dtc_lines = [] + +# Lesen und analysieren der Eingabedatei +with open(input_file, "r", encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#"): + continue + + parts = line.split(";") + if len(parts) == 5: + num, dtc_name, dtc_severity, title, description = [part.strip() for part in parts] + dtc_lines.append([int(num), dtc_name, dtc_severity, title, description]) + +# Ãœberprüfen auf Duplikate in den DTC-Nummern und DTC-Namen +num_set = set() +dtc_name_set = set() +duplicates = [] + +for line in dtc_lines: + num, dtc_name, _, _, _ = line + if num in num_set: + duplicates.append(f"DTC-Nummer {num} ist ein Duplikat.") + else: + num_set.add(num) + + if dtc_name in dtc_name_set: + duplicates.append(f"DTC-Name '{dtc_name}' ist ein Duplikat.") + else: + dtc_name_set.add(dtc_name) + +if duplicates: + for duplicate in duplicates: + print(f"Fehler: {duplicate}") + raise ValueError("Duplicate DTC Data detected") + +# Suchen nach DTC_NO_DTC und DTC_LAST_DTC +dtc_no_dtc_added = False +dtc_last_dtc_line = None + +for line in dtc_lines: + _, dtc_name, _, _, _ = line + if dtc_name == "DTC_NO_DTC": + dtc_no_dtc_added = True + elif dtc_name == "DTC_LAST_DTC": + dtc_last_dtc_line = line + +# Einen DTC für DTC_NO_DTC hinzufügen (wenn nicht vorhanden) +if not dtc_no_dtc_added: + dtc_lines.insert(0, [0, "DTC_NO_DTC", "DTC_NONE", "No Error", "No Error"]) + +# Falls DTC_LAST_DTC existiert, lösche es +if dtc_last_dtc_line: + dtc_lines.remove(dtc_last_dtc_line) + +# Einen DTC für DTC_LAST_DTC hinzufügen (mit der höchsten Nummer) +if dtc_lines: + highest_num = max([line[0] for line in dtc_lines]) +else: + highest_num = 0 + +dtc_lines.append([highest_num + 1, "DTC_LAST_DTC", "DTC_NONE", "Last Error", "Last Error"]) + +# Sortieren der Zeilen nach der Nummer aufsteigend +dtc_lines.sort(key=lambda x: x[0]) + +# DTC_NAME_CONSTANT-Makros initialisieren +dtc_macros = [] +dtc_structs = [] +dtc_table_data = [] + +# Verarbeiten der sortierten Zeilen +for i, line in enumerate(dtc_lines): + num, dtc_name, dtc_severity, title, description = line + dtc_macros.append(f"#define {dtc_name:<30} {num}") + comma = "," if i < len(dtc_lines) - 1 else " " + dtc_structs.append(f" {{ {dtc_name:<30}, {dtc_severity:<12} }}{comma} // {description}") + dtc_table_data.append({"num": num, "title": title, "description": description}) + +# Unix-Zeitstempel hinzufügen +timestamp = int(time.time()) + +# Headerdatei schreiben +with open(output_file, "w") as f: + f.write(f"// Auto-generated by script on {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))}\n") + f.write(f"#ifndef DTC_DEFS_H\n") + f.write(f"#define DTC_DEFS_H\n\n") + f.write("#include \n\n") + + f.write("typedef uint32_t DTCNum_t;\n\n") + + f.write("typedef enum\n") + f.write("{\n") + f.write(" DTC_INACTIVE,\n") + f.write(" DTC_ACTIVE,\n") + f.write(" DTC_PREVIOUS\n") + f.write("} DTCActive_t;\n\n") + + f.write("typedef enum\n") + f.write("{\n") + f.write(" DTC_NONE,\n") + f.write(" DTC_INFO,\n") + f.write(" DTC_WARN,\n") + f.write(" DTC_CRITICAL\n") + f.write("} DTCSeverity_t;\n\n") + + f.write("typedef struct {\n") + f.write(" DTCNum_t code;\n") + f.write(" DTCSeverity_t severity;\n") + f.write("} DTC_t;\n\n") + + # Füge die DTC_NAME_CONSTANT #define hinzu + f.write("\n".join(dtc_macros) + "\n\n") + + f.write(f"const DTC_t dtc_definitions[] = {{\n") + f.write(",\n".join(dtc_structs) + "\n") + f.write("};\n\n") + f.write(f"const uint32_t dtc_generation_timestamp = {timestamp};\n\n") + f.write("#endif // DTC_DEFS_H\n") + +print(f"Header-Datei wurde erstellt: {output_file}") + +# JSON-Datei mit UTF-8-Zeichencodierung erstellen +with open(json_output_file, 'w', encoding='utf-8') as json_f: + json.dump(dtc_table_data, json_f, ensure_ascii=False, indent=4, separators=(',', ': ')) + +print(f"JSON-Datei wurde erstellt: {json_output_file}") diff --git a/Software/data_src/index.htm b/Software/data_src/index.htm index fdf6421..afe8c22 100644 --- a/Software/data_src/index.htm +++ b/Software/data_src/index.htm @@ -11,6 +11,7 @@ + @@ -814,19 +815,27 @@ var dtc = dtctr.data('dtc') var debugval = dtctr.data('debugval') var modal = $(this) - $.getJSON('static/tt_dtc/dtc_' + dtc + '.json', function (data) { - modal.find('.modal-title').text(data.title) - modal.find('.dtc-desc').text(data.description) - if (debugval > 0) { - modal.find('.dtc-debugval').text("Debugvalue: " + debugval) + + getDescriptionForDTCNumber(dtc, function (error, title, description) { + if (error) + { + console.error("Fehler beim Abrufen der Beschreibung:", error); + modal.find('.modal-title').text("Fehler") + modal.find('.dtc-desc').text("DTC-Beschreibung konnte nicht geladen werden") } - else { - modal.find('.dtc-debugval').remove() + else + { + modal.find('.modal-title').text(title) + modal.find('.dtc-desc').text(description) + if (debugval > 0) + { + modal.find('.dtc-debugval').text("Debugvalue: " + debugval) + } + else + { + modal.find('.dtc-debugval').remove() + } } - }).fail(function () { - console.log("An error has occurred."); - modal.find('.modal-title').text("Fehler") - modal.find('.dtc-desc').text("DTC-Beschreibung konnte nicht geladen werden") }); }); diff --git a/Software/data_src/static/dtc_table.json b/Software/data_src/static/dtc_table.json new file mode 100644 index 0000000..76fc5dc --- /dev/null +++ b/Software/data_src/static/dtc_table.json @@ -0,0 +1,77 @@ +[ + { + "num": 0, + "title": "No Error", + "description": "No Error" + }, + { + "num": 1, + "title": "Ölvorrat leer", + "description": "Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen" + }, + { + "num": 2, + "title": "Ölvorrat niedrig", + "description": "Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen" + }, + { + "num": 3, + "title": "kein EEPROM erkannt", + "description": "Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten." + }, + { + "num": 4, + "title": "EEPROM CFG Checksumme", + "description": "Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück" + }, + { + "num": 5, + "title": "EEPROM PDS Checksumme", + "description": "Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück" + }, + { + "num": 6, + "title": "EEPROM PDS Adresse", + "description": "Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück" + }, + { + "num": 7, + "title": "EEPROM Version falsch", + "description": "Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück" + }, + { + "num": 8, + "title": "Flashspeicher Fehler", + "description": "Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware" + }, + { + "num": 9, + "title": "Flashversion falsch", + "description": "Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei" + }, + { + "num": 10, + "title": "Keine GPS-Verbindung", + "description": "Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul" + }, + { + "num": 11, + "title": "CAN-Transceiver Error", + "description": "Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte" + }, + { + "num": 12, + "title": "Keine CAN-Verbindung", + "description": "Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen" + }, + { + "num": 13, + "title": "Config-Validierung", + "description": "Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen" + }, + { + "num": 14, + "title": "Last Error", + "description": "Last Error" + } +] \ No newline at end of file diff --git a/Software/data_src/static/js/dtc_table.js b/Software/data_src/static/js/dtc_table.js new file mode 100644 index 0000000..c7e9255 --- /dev/null +++ b/Software/data_src/static/js/dtc_table.js @@ -0,0 +1,23 @@ +const jsonFilePath = "static/dtc_table.json"; + +function getDescriptionForDTCNumber(number, callback) { + fetch(jsonFilePath) + .then((response) => response.json()) + .then((data) => { + const foundEntry = data.find((entry) => entry.num === number); + + if (foundEntry) { + const description = foundEntry.description; + const title = foundEntry.title; + 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); + } + }) + .catch((error) => { + // Im Fehlerfall geben Sie den Fehler zurück + callback(error, null, null); + }); +} + diff --git a/Software/data_src/static/tt_dtc/dtc_1.json b/Software/data_src/static/tt_dtc/dtc_1.json deleted file mode 100644 index ceb525f..0000000 --- a/Software/data_src/static/tt_dtc/dtc_1.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Ölvorrat leer", - "description": "Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_10.json b/Software/data_src/static/tt_dtc/dtc_10.json deleted file mode 100644 index ee3f567..0000000 --- a/Software/data_src/static/tt_dtc/dtc_10.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Keine GPS-Verbindung", - "description": "Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_11.json b/Software/data_src/static/tt_dtc/dtc_11.json deleted file mode 100644 index bdd7a7f..0000000 --- a/Software/data_src/static/tt_dtc/dtc_11.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "CAN-Transceiver Error", - "description": "Es konnte keine Verbindung zum CAN-Transceiver hergestellt werden. Prüfen Sie die Hardware auf Defekte" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_12.json b/Software/data_src/static/tt_dtc/dtc_12.json deleted file mode 100644 index 76389cf..0000000 --- a/Software/data_src/static/tt_dtc/dtc_12.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Keine CAN-Verbindung", - "description": "Es konnte kein CAN-Signal empfangen werden. Prüfen sie die Verbindung und die Einstellungen" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_13.json b/Software/data_src/static/tt_dtc/dtc_13.json deleted file mode 100644 index d16920a..0000000 --- a/Software/data_src/static/tt_dtc/dtc_13.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Config-Validierung", - "description": "Ein oder mehrer Einstellungswerte sind ausserhalb plausibler Werte. Prüfen Sie Ihre Einstellungen" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_2.json b/Software/data_src/static/tt_dtc/dtc_2.json deleted file mode 100644 index 9b05de2..0000000 --- a/Software/data_src/static/tt_dtc/dtc_2.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Ölvorrat niedrig", - "description": "Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_3.json b/Software/data_src/static/tt_dtc/dtc_3.json deleted file mode 100644 index a0156b2..0000000 --- a/Software/data_src/static/tt_dtc/dtc_3.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "kein EEPROM gefunden", - "description": "Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten." -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_4.json b/Software/data_src/static/tt_dtc/dtc_4.json deleted file mode 100644 index 8237023..0000000 --- a/Software/data_src/static/tt_dtc/dtc_4.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "EEPROM CFG Checksumme", - "description": "Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_5.json b/Software/data_src/static/tt_dtc/dtc_5.json deleted file mode 100644 index c4e528e..0000000 --- a/Software/data_src/static/tt_dtc/dtc_5.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "EEPROM PDS Checksumme", - "description": "Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_6.json b/Software/data_src/static/tt_dtc/dtc_6.json deleted file mode 100644 index 85990a0..0000000 --- a/Software/data_src/static/tt_dtc/dtc_6.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "EEPROM PDS Adresse", - "description": "Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_7.json b/Software/data_src/static/tt_dtc/dtc_7.json deleted file mode 100644 index cb17b4c..0000000 --- a/Software/data_src/static/tt_dtc/dtc_7.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "EEPROM Version falsch", - "description": "Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_8.json b/Software/data_src/static/tt_dtc/dtc_8.json deleted file mode 100644 index 62a3e98..0000000 --- a/Software/data_src/static/tt_dtc/dtc_8.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Flashstorage Fehler", - "description": "Der Flashstorage konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware" -} \ No newline at end of file diff --git a/Software/data_src/static/tt_dtc/dtc_9.json b/Software/data_src/static/tt_dtc/dtc_9.json deleted file mode 100644 index 438b8c1..0000000 --- a/Software/data_src/static/tt_dtc/dtc_9.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Flashstorage Version falsch", - "description": "Die Version des Flashstorage stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei" -} \ No newline at end of file diff --git a/Software/include/dtc.h b/Software/include/dtc.h index 46a1ee2..5090e19 100644 --- a/Software/include/dtc.h +++ b/Software/include/dtc.h @@ -2,56 +2,25 @@ #define _DTC_H_ #include +#include "dtc_defs.h" #define MAX_DTC_STORAGE 6 -typedef enum DTCNums_e +typedef struct { - DTC_TANK_EMPTY = 1, - DTC_TANK_LOW, - DTC_NO_EEPROM_FOUND, - DTC_EEPROM_CFG_BAD, - DTC_EEPROM_PDS_BAD, - DTC_EEPROM_PDSADRESS_BAD, - DTC_EEPROM_VERSION_BAD, - DTC_FLASHFS_ERROR, - DTC_FLASHFS_VERSION_ERROR, - DTC_NO_GPS_SERIAL, - DTC_CAN_TRANSCEIVER_FAILED, - DTC_NO_CAN_SIGNAL, - DTC_EEPROM_CFG_SANITY, - DTC_LAST_DTC -} DTCNums_t; - -typedef enum DTCActive_e -{ - DTC_NONE, - DTC_ACTIVE, - DTC_PREVIOUS -} DTCActive_t; - -typedef enum DTCSeverity_e -{ - DTC_INFO, - DTC_WARN, - DTC_CRITICAL -} DTCSeverity_t; - -typedef struct DTCEntry_s -{ - DTCNums_t Number; + DTCNum_t Number; uint32_t timestamp; DTCActive_t active; - DTCSeverity_t severity; uint32_t debugVal; } DTCEntry_t; -void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue = 0); -void ClearDTC(DTCNums_t DTC_no); +void MaintainDTC(DTCNum_t DTC_no, boolean active, uint32_t DebugValue = 0); +void ClearDTC(DTCNum_t DTC_no); void ClearAllDTC(); -DTCNums_t getlastDTC(boolean only_active); -DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity); +DTCNum_t getlastDTC(boolean only_active); +DTCNum_t ActiveDTCseverity(DTCSeverity_t severity); +DTCSeverity_t getSeverityForDTC(DTCNum_t targetCode); void DTC_Process(); -extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE]; +extern DTCEntry_t DTCStorage[MAX_DTC_STORAGE]; #endif \ No newline at end of file diff --git a/Software/include/dtc_defs.h b/Software/include/dtc_defs.h new file mode 100644 index 0000000..d2c248d --- /dev/null +++ b/Software/include/dtc_defs.h @@ -0,0 +1,65 @@ +// Auto-generated by script on 2023-09-27 19:05:49 +#ifndef DTC_DEFS_H +#define DTC_DEFS_H + +#include + +typedef uint32_t DTCNum_t; + +typedef enum +{ + DTC_INACTIVE, + DTC_ACTIVE, + DTC_PREVIOUS +} DTCActive_t; + +typedef enum +{ + DTC_NONE, + DTC_INFO, + DTC_WARN, + DTC_CRITICAL +} DTCSeverity_t; + +typedef struct { + DTCNum_t code; + DTCSeverity_t severity; +} DTC_t; + +#define DTC_NO_DTC 0 +#define DTC_TANK_EMPTY 1 +#define DTC_TANK_LOW 2 +#define DTC_NO_EEPROM_FOUND 3 +#define DTC_EEPROM_CFG_BAD 4 +#define DTC_EEPROM_PDS_BAD 5 +#define DTC_EEPROM_PDSADRESS_BAD 6 +#define DTC_EEPROM_VERSION_BAD 7 +#define DTC_FLASHFS_ERROR 8 +#define DTC_FLASHFS_VERSION_ERROR 9 +#define DTC_NO_GPS_SERIAL 10 +#define DTC_CAN_TRANSCEIVER_FAILED 11 +#define DTC_NO_CAN_SIGNAL 12 +#define DTC_EEPROM_CFG_SANITY 13 +#define DTC_LAST_DTC 14 + +const DTC_t dtc_definitions[] = { + { DTC_NO_DTC , DTC_NONE }, // No Error, + { DTC_TANK_EMPTY , DTC_CRITICAL }, // Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen, + { DTC_TANK_LOW , DTC_WARN }, // Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen, + { DTC_NO_EEPROM_FOUND , DTC_CRITICAL }, // Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten., + { DTC_EEPROM_CFG_BAD , DTC_CRITICAL }, // Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück, + { DTC_EEPROM_PDS_BAD , DTC_CRITICAL }, // Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück, + { DTC_EEPROM_PDSADRESS_BAD , DTC_CRITICAL }, // Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück, + { DTC_EEPROM_VERSION_BAD , DTC_CRITICAL }, // Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück, + { DTC_FLASHFS_ERROR , DTC_CRITICAL }, // Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware, + { DTC_FLASHFS_VERSION_ERROR , DTC_CRITICAL }, // Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei, + { DTC_NO_GPS_SERIAL , DTC_CRITICAL }, // Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul, + { 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_LAST_DTC , DTC_NONE } // Last Error +}; + +const uint32_t dtc_generation_timestamp = 1695834349; + +#endif // DTC_DEFS_H diff --git a/Software/platformio.ini b/Software/platformio.ini index ddf4dae..4bf372d 100644 --- a/Software/platformio.ini +++ b/Software/platformio.ini @@ -30,6 +30,7 @@ build_flags = board_build.filesystem = littlefs extra_scripts = post:prepare_littlefs.py + pre:build_dtcs.py pre:prepare_fwfiles.py monitor_filters = esp8266_exception_decoder diff --git a/Software/src/can.cpp b/Software/src/can.cpp index ad0b440..39fa3d3 100644 --- a/Software/src/can.cpp +++ b/Software/src/can.cpp @@ -10,7 +10,7 @@ void Init_CAN() { if (CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) != CAN_OK) - MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, DTC_CRITICAL, true); + MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, true); CAN0.init_Mask(0, 0, 0x07FF0000); // Init first mask... CAN0.init_Mask(1, 0, 0x07FF0000); // Init second mask... @@ -55,7 +55,7 @@ uint32_t Process_CAN_WheelSpeed() if (lastRecTimestamp > 1000) { - MaintainDTC(DTC_NO_CAN_SIGNAL, DTC_CRITICAL, (millis() > lastRecTimestamp + 10000 ? true : false)); + MaintainDTC(DTC_NO_CAN_SIGNAL, (millis() > lastRecTimestamp + 10000 ? true : false)); } return milimeters_to_add; diff --git a/Software/src/config.cpp b/Software/src/config.cpp index fa99e1d..4facf96 100644 --- a/Software/src/config.cpp +++ b/Software/src/config.cpp @@ -83,6 +83,12 @@ void StoreConfig_EEPROM() return; ee.updateBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig)); + + uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); + if (ConfigSanityCheckResult > 0) + { + MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult); + } } void GetConfig_EEPROM() @@ -97,16 +103,14 @@ void GetConfig_EEPROM() if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) != checksum) { - MaintainDTC(DTC_EEPROM_CFG_BAD, DTC_CRITICAL, true); + MaintainDTC(DTC_EEPROM_CFG_BAD, true); } LubeConfig.checksum = checksum; uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); - if (ConfigSanityCheckResult > 0) { - MaintainDTC(DTC_EEPROM_CFG_SANITY, DTC_WARN, true, ConfigSanityCheckResult); - globals.requestEEAction = EE_CFG_SAVE; + MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult); } } @@ -138,7 +142,7 @@ void GetPersistence_EEPROM() { MovePersistencePage_EEPROM(true); FormatPersistence_EEPROM(); - MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, DTC_CRITICAL, true); + MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, true); } else { @@ -149,7 +153,7 @@ void GetPersistence_EEPROM() if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum) { - MaintainDTC(DTC_EEPROM_PDS_BAD, DTC_CRITICAL, true); + MaintainDTC(DTC_EEPROM_PDS_BAD, true); } PersistenceData.checksum = checksum; } @@ -245,10 +249,10 @@ boolean checkEEPROMavailable() { if (!ee.isConnected()) { - MaintainDTC(DTC_NO_EEPROM_FOUND, DTC_CRITICAL, true); + MaintainDTC(DTC_NO_EEPROM_FOUND, true); return false; } - MaintainDTC(DTC_NO_EEPROM_FOUND, DTC_CRITICAL, false); + MaintainDTC(DTC_NO_EEPROM_FOUND, false); return true; } diff --git a/Software/src/debugger.cpp b/Software/src/debugger.cpp index 1960da9..9a5f4b6 100644 --- a/Software/src/debugger.cpp +++ b/Software/src/debugger.cpp @@ -325,7 +325,7 @@ void Debug_ShowDTCs() else strcpy(buff_active, "none"); - Debug_pushMessage("%s %7d %8s %8d\n", buff_timestamp, DTCStorage[i].Number, buff_active, DTCStorage[i].severity); + Debug_pushMessage("%s %7d %8s %8d\n", buff_timestamp, DTCStorage[i].Number, buff_active); } } } diff --git a/Software/src/dtc.cpp b/Software/src/dtc.cpp index 4641b0b..7e0b327 100644 --- a/Software/src/dtc.cpp +++ b/Software/src/dtc.cpp @@ -1,9 +1,9 @@ #include "dtc.h" #include "debugger.h" -DTCEntry_s DTCStorage[MAX_DTC_STORAGE]; +DTCEntry_t DTCStorage[MAX_DTC_STORAGE]; -void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue) +void MaintainDTC(DTCNum_t DTC_no, boolean active, uint32_t DebugValue) { for (int i = 0; i < MAX_DTC_STORAGE; i++) { @@ -14,7 +14,6 @@ void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, u Debug_pushMessage("DTC gone active: %d, DebugVal: %d\n", DTC_no, DebugValue); DTCStorage[i].timestamp = millis(); DTCStorage[i].active = DTC_ACTIVE; - DTCStorage[i].severity = DTC_severity; DTCStorage[i].debugVal = DebugValue; } if (!active && DTCStorage[i].active == DTC_ACTIVE) @@ -39,21 +38,20 @@ void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, u DTCStorage[i].timestamp = millis(); DTCStorage[i].active = DTC_ACTIVE; DTCStorage[i].debugVal = DebugValue; - DTCStorage[i].severity = DTC_severity; return; } } } } -void ClearDTC(DTCNums_t DTC_no) +void ClearDTC(DTCNum_t DTC_no) { for (int i = 0; i < MAX_DTC_STORAGE; i++) { if (DTCStorage[i].Number == DTC_no) { DTCStorage[i].Number = DTC_LAST_DTC; - DTCStorage[i].active = DTC_NONE; + DTCStorage[i].active = DTC_INACTIVE; DTCStorage[i].timestamp = 0; } } @@ -64,12 +62,12 @@ void ClearAllDTC() for (int i = 0; i < MAX_DTC_STORAGE; i++) { DTCStorage[i].Number = DTC_LAST_DTC; - DTCStorage[i].active = DTC_NONE; + DTCStorage[i].active = DTC_INACTIVE; DTCStorage[i].timestamp = 0; } } -DTCNums_t getlastDTC(boolean only_active) +DTCNum_t getlastDTC(boolean only_active) { int8_t pointer = -1; uint32_t lasttimestamp = 0; @@ -89,34 +87,28 @@ DTCNums_t getlastDTC(boolean only_active) return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC; } -DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity) +DTCSeverity_t getSeverityForDTC(DTCNum_t targetCode) { - int8_t pointer = -1; - uint32_t lasttimestamp = 0; - - for (int i = 0; i < MAX_DTC_STORAGE; i++) + for (int i = 0; i < DTC_LAST_DTC; i++) { - if (DTCStorage[i].Number > 0 && DTCStorage[i].timestamp > lasttimestamp) + if (dtc_definitions[i].code == targetCode) { - if ((only_active == false || DTCStorage[i].active == DTC_ACTIVE) && DTCStorage[i].severity == severity) - { - pointer = i; - lasttimestamp = DTCStorage[i].timestamp; - } + return dtc_definitions[i].severity; } } - - return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC; + return DTC_NONE; } void DTC_Process() { static tSystem_Status preserverSysStatusError; + DTCNum_t lastDTC = getlastDTC(true); - if (getlastDTC(false) < DTC_LAST_DTC) + if (lastDTC < DTC_LAST_DTC) { globals.hasDTC = true; - if (getlastDTC_Severity(true, DTC_CRITICAL) < DTC_LAST_DTC && globals.systemStatus != sysStat_Shutdown) + + if (getSeverityForDTC(lastDTC) == DTC_CRITICAL && globals.systemStatus != sysStat_Shutdown) { if (globals.systemStatus != sysStat_Error) { @@ -124,16 +116,14 @@ void DTC_Process() } globals.systemStatus = sysStat_Error; } - else - { - if (globals.systemStatus == sysStat_Error) - { - globals.systemStatus = preserverSysStatusError; - } - } } else { globals.hasDTC = false; + + if (globals.systemStatus == sysStat_Error) + { + globals.systemStatus = preserverSysStatusError; + } } } \ No newline at end of file diff --git a/Software/src/dtc_defs.txt b/Software/src/dtc_defs.txt new file mode 100644 index 0000000..c2ce06b --- /dev/null +++ b/Software/src/dtc_defs.txt @@ -0,0 +1,16 @@ +# No. | DTC-Constant | Severity | Title | Description +#-----|------------------------------|---------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------- + 1; DTC_TANK_EMPTY; DTC_CRITICAL; Ölvorrat leer; Ölvorrat ist komplett leer. Den Ölvorrat auffüllen und im Menu 'Wartung' zurück setzen + 2; DTC_TANK_LOW; DTC_WARN; Ölvorrat niedrig; Ölvorrat ist unter der Warnschwelle. Den Ölvorrat demnächst auffüllen und im Menu 'Wartung' zurück setzen + 3; DTC_NO_EEPROM_FOUND; DTC_CRITICAL; kein EEPROM erkannt; Es wurde kein EEPROM gefunden. Dies lässt einen Hardware-Defekt vermuten. + 4; DTC_EEPROM_CFG_BAD; DTC_CRITICAL; EEPROM CFG Checksumme; Die Checksumme der Config-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück + 5; DTC_EEPROM_PDS_BAD; DTC_CRITICAL; EEPROM PDS Checksumme; Die Checksumme der Betriebsdaten-Partition des EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück + 6; DTC_EEPROM_PDSADRESS_BAD; DTC_CRITICAL; EEPROM PDS Adresse; Die Adresse der Betriebsdaten-Partition im EEPROM ist ungültig. Setzen sie den EEPROM-Bereich 'PDS' im Menu 'Wartung' zurück + 7; DTC_EEPROM_VERSION_BAD; DTC_CRITICAL; EEPROM Version falsch; Die Layout-Version des EEPROM stimmt nicht mit der Firmware-Version überein. Setzen sie den EEPROM-Bereich 'CFG' im Menu 'Wartung' zurück + 8; DTC_FLASHFS_ERROR; DTC_CRITICAL; Flashspeicher Fehler; Der Flashspeicher konnte nicht initialisiert werden. Aktualisieren sie Flash & Firmware + 9; DTC_FLASHFS_VERSION_ERROR; DTC_CRITICAL; Flashversion falsch; Die Version des Flashspeicher stimmt nicht mit der Firmware-Version überein. Aktualisieren sie den Flash mit der passenden Update-Datei + 10; DTC_NO_GPS_SERIAL; DTC_CRITICAL; Keine GPS-Verbindung; Es wurde kein GPS-Signal über die serielle Schnittstelle empfangen, Prüfen sie die Verbindung und das GPS-Modul + 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 + diff --git a/Software/src/lubeapp.cpp b/Software/src/lubeapp.cpp index df7bf1d..028b5be 100644 --- a/Software/src/lubeapp.cpp +++ b/Software/src/lubeapp.cpp @@ -7,8 +7,8 @@ void RunLubeApp(uint32_t add_milimeters) globals.TankPercentage = PersistenceData.tankRemain_microL / (LubeConfig.tankCapacity_ml * 10); - MaintainDTC(DTC_TANK_EMPTY, DTC_CRITICAL, (PersistenceData.tankRemain_microL < LubeConfig.amountPerDose_microL)); - MaintainDTC(DTC_TANK_LOW, DTC_WARN, (globals.TankPercentage < LubeConfig.TankRemindAtPercentage)); + MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_microL < LubeConfig.amountPerDose_microL)); + MaintainDTC(DTC_TANK_LOW, (globals.TankPercentage < LubeConfig.TankRemindAtPercentage)); // Add traveled Distance in mm PersistenceData.TravelDistance_highRes_mm += add_milimeters; diff --git a/Software/src/webui.cpp b/Software/src/webui.cpp index 5e32e18..322d51d 100644 --- a/Software/src/webui.cpp +++ b/Software/src/webui.cpp @@ -19,6 +19,7 @@ AsyncWebSocket webSocket("/ws"); void WebsocketEvent_Callback(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len); void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len); +void Websocket_RefreshClientData_DTCs(); #endif @@ -27,7 +28,7 @@ void initWebUI() if (!LittleFS.begin()) { Debug_pushMessage("An Error has occurred while mounting LittleFS\n"); - MaintainDTC(DTC_FLASHFS_ERROR, DTC_CRITICAL, true); + MaintainDTC(DTC_FLASHFS_ERROR, true); return; } @@ -37,7 +38,7 @@ void initWebUI() snprintf(buffer, sizeof(buffer), "%d.%02d", constants.Required_Flash_Version_major, constants.Required_Flash_Version_minor); if (strcmp(globals.FlashVersion, buffer)) { - MaintainDTC(DTC_FLASHFS_VERSION_ERROR, DTC_WARN, true); + MaintainDTC(DTC_FLASHFS_VERSION_ERROR, true); } MDNS.begin(globals.DeviceName); @@ -183,7 +184,7 @@ String processor(const String &var) temp = temp + " data-debugval=" + String(DTCStorage[i].debugVal) + ">" + String(buff_timestamp); temp = temp + "" + String(DTCStorage[i].Number) + ""; temp = temp + "";