From dab826b8622b20429830a9b1d01a4bf6b45fdf24 Mon Sep 17 00:00:00 2001
From: Marcel Peterkau
Date: Wed, 9 Mar 2022 20:25:02 +0100
Subject: [PATCH] Added DTC-Table in WebUI and improved DTC-System
---
Software/ChainLube/data/index.htm | 13 ++++++++++
Software/ChainLube/src/can.cpp | 15 ++----------
Software/ChainLube/src/dtc.cpp | 37 ++++++++++++++++++-----------
Software/ChainLube/src/dtc.h | 31 ++++++++++++++----------
Software/ChainLube/src/gps.cpp | 13 +---------
Software/ChainLube/src/lubeapp.cpp | 15 ++++--------
Software/ChainLube/src/main.cpp | 2 ++
Software/ChainLube/src/webui.cpp | 38 ++++++++++++++++++++++++++++--
Software/ChainLube/src/webui.h | 1 +
9 files changed, 101 insertions(+), 64 deletions(-)
diff --git a/Software/ChainLube/data/index.htm b/Software/ChainLube/data/index.htm
index 4344ca8..a93ddf9 100644
--- a/Software/ChainLube/data/index.htm
+++ b/Software/ChainLube/data/index.htm
@@ -70,6 +70,19 @@
aktueller Modus
+
+
Fehlercodes
+
+
+
+ Timestamp
+ | DTC
+ | active
+ |
+ %DTC_TABLE%
+
+
+
diff --git a/Software/ChainLube/src/can.cpp b/Software/ChainLube/src/can.cpp
index ef0d54c..7405f46 100644
--- a/Software/ChainLube/src/can.cpp
+++ b/Software/ChainLube/src/can.cpp
@@ -22,7 +22,7 @@ uint32_t Process_CAN_WheelSpeed()
#define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h
can_frame canMsg;
- static uint32_t lastRecTimestamp;
+ static uint32_t lastRecTimestamp = 0;
uint16_t RearWheelSpeed_raw;
if (CAN0.readMsgBuf(&canMsg.can_id, &canMsg.can_dlc, canMsg.data) == CAN_OK)
@@ -40,18 +40,7 @@ uint32_t Process_CAN_WheelSpeed()
return milimeters_to_add;
}
- if (millis() > lastRecTimestamp + 10000)
- {
- if (globals.systemStatus != sysStat_Shutdown)
- globals.systemStatus = sysStat_Error;
- MaintainDTC(DTC_NO_CAN_SIGNAL, true);
- }
- else
- {
- if (globals.systemStatus != sysStat_Shutdown)
- globals.systemStatus = globals.resumeStatus;
- MaintainDTC(DTC_NO_CAN_SIGNAL, false);
- }
+ MaintainDTC(DTC_NO_CAN_SIGNAL, (millis() > lastRecTimestamp + 10000));
return 0;
}
diff --git a/Software/ChainLube/src/dtc.cpp b/Software/ChainLube/src/dtc.cpp
index 190fedb..f5213ee 100644
--- a/Software/ChainLube/src/dtc.cpp
+++ b/Software/ChainLube/src/dtc.cpp
@@ -2,23 +2,24 @@
DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
-void MaintainDTC(uint32_t DTC_no, boolean active)
+void MaintainDTC(DTCNums_t DTC_no, boolean active)
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number == DTC_no)
{
- if (active == true)
+ if (active && DTCStorage[i].active != DTC_ACTIVE)
{
+ Serial.printf("DTC gone active: %d", DTC_no);
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;
- return;
}
- else
+ if (!active && DTCStorage[i].active == DTC_ACTIVE)
{
- DTCStorage[i].active = DTCStorage[i].active == DTC_ACTIVE ? DTC_PREVIOUS : DTC_NONE;
- return;
+ Serial.printf("DTC gone previous: %d", DTC_no);
+ DTCStorage[i].active = DTC_PREVIOUS;
}
+ return;
}
}
@@ -28,8 +29,10 @@ void MaintainDTC(uint32_t DTC_no, boolean active)
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
- if (DTCStorage[i].Number == 0)
+ if (DTCStorage[i].Number == DTC_LAST_DTC)
{
+ Serial.printf("new DTC registered: %d", DTC_no);
+ DTCStorage[i].Number = DTC_no;
DTCStorage[i].timestamp = millis();
DTCStorage[i].active = DTC_ACTIVE;
return;
@@ -38,13 +41,15 @@ void MaintainDTC(uint32_t DTC_no, boolean active)
}
}
-void ClearDTC(uint32_t DTC_no)
+void ClearDTC(DTCNums_t DTC_no)
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
{
if (DTCStorage[i].Number == DTC_no)
{
- DTCStorage[i].Number = 0;
+ DTCStorage[i].Number = DTC_LAST_DTC;
+ DTCStorage[i].active = DTC_NONE;
+ DTCStorage[i].timestamp = 0;
}
}
}
@@ -52,12 +57,16 @@ void ClearDTC(uint32_t DTC_no)
void ClearAllDTC()
{
for (int i = 0; i < MAX_DTC_STORAGE; i++)
- DTCStorage[i].Number = 0;
+ {
+ DTCStorage[i].Number = DTC_LAST_DTC;
+ DTCStorage[i].active = DTC_NONE;
+ DTCStorage[i].timestamp = 0;
+ }
}
-uint32_t getlastDTC(boolean only_active)
+DTCNums_t getlastDTC(boolean only_active)
{
- uint8_t pointer = 0;
+ int8_t pointer = -1;
uint32_t lasttimestamp = 0;
for (int i = 0; i < MAX_DTC_STORAGE; i++)
@@ -72,5 +81,5 @@ uint32_t getlastDTC(boolean only_active)
}
}
- return pointer > 0 ? DTCStorage[pointer].Number : 0;
-}
+ return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC;
+}
\ No newline at end of file
diff --git a/Software/ChainLube/src/dtc.h b/Software/ChainLube/src/dtc.h
index 21ee505..38b3016 100644
--- a/Software/ChainLube/src/dtc.h
+++ b/Software/ChainLube/src/dtc.h
@@ -3,29 +3,34 @@
#include
-#define MAX_DTC_STORAGE 16
+#define MAX_DTC_STORAGE 3
-#define DTC_NO_GPS_SERIAL 100
-#define DTC_NO_CAN_SIGNAL 101
-#define DTC_TANK_EMPTY 102
+typedef enum DTCNums_e
+{
+ DTC_NO_GPS_SERIAL,
+ DTC_NO_CAN_SIGNAL,
+ DTC_TANK_EMPTY,
+ DTC_LAST_DTC
+} DTCNums_t;
typedef enum DTCActive_e
{
-DTC_ACTIVE,
-DTC_PREVIOUS,
-DTC_NONE
-} DTCActive_s;
+ DTC_ACTIVE,
+ DTC_PREVIOUS,
+ DTC_NONE
+} DTCActive_t;
typedef struct DTCEntry_s
{
- uint32_t Number;
+ DTCNums_t Number;
uint32_t timestamp;
- DTCActive_s active;
+ DTCActive_t active;
} DTCEntry_t;
-void MaintainDTC(uint32_t DTC_no, boolean active);
-void ClearDTC(uint32_t DTC_no);
+void MaintainDTC(DTCNums_t DTC_no, boolean active);
+void ClearDTC(DTCNums_t DTC_no);
void ClearAllDTC();
-uint32_t getlastDTC(boolean only_active);
+DTCNums_t getlastDTC(boolean only_active);
+extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE];
#endif
\ No newline at end of file
diff --git a/Software/ChainLube/src/gps.cpp b/Software/ChainLube/src/gps.cpp
index 2b79c23..ea355e7 100644
--- a/Software/ChainLube/src/gps.cpp
+++ b/Software/ChainLube/src/gps.cpp
@@ -50,18 +50,7 @@ uint32_t Process_GPS_WheelSpeed()
}
}
- if (millis() > lastRecTimestamp + 10000)
- {
- if (globals.systemStatus != sysStat_Shutdown)
- globals.systemStatus = sysStat_Error;
- MaintainDTC(DTC_NO_GPS_SERIAL, true);
- }
- else
- {
- if (globals.systemStatus != sysStat_Shutdown)
- globals.systemStatus = globals.resumeStatus;
- MaintainDTC(DTC_NO_GPS_SERIAL, false);
- }
+ MaintainDTC(DTC_NO_GPS_SERIAL, (millis() > lastRecTimestamp + 10000));
return 0;
}
diff --git a/Software/ChainLube/src/lubeapp.cpp b/Software/ChainLube/src/lubeapp.cpp
index 2657095..f824c8f 100644
--- a/Software/ChainLube/src/lubeapp.cpp
+++ b/Software/ChainLube/src/lubeapp.cpp
@@ -4,16 +4,11 @@ uint32_t lubePulseTimestamp = 0;
void RunLubeApp(uint32_t add_milimeters)
{
- if (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl)
- {
- MaintainDTC(DTC_TANK_EMPTY, true);
- }
- else
- {
- if (globals.systemStatus != sysStat_Shutdown)
- globals.systemStatus = globals.resumeStatus;
- MaintainDTC(DTC_TANK_EMPTY, false);
- }
+
+ MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl));
+
+ if (getlastDTC(true) < DTC_LAST_DTC)
+ globals.systemStatus = sysStat_Error;
// Add traveled Distance in mm
PersistenceData.TravelDistance_highRes += add_milimeters;
diff --git a/Software/ChainLube/src/main.cpp b/Software/ChainLube/src/main.cpp
index e555809..4c9b532 100644
--- a/Software/ChainLube/src/main.cpp
+++ b/Software/ChainLube/src/main.cpp
@@ -81,6 +81,8 @@ void setup()
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
WiFi.persistent(false);
+ ClearAllDTC(); // Init DTC-Storage
+
#ifdef WIFI_CLIENT
WiFi.mode(WIFI_STA);
WiFi.setHostname(DeviceName);
diff --git a/Software/ChainLube/src/webui.cpp b/Software/ChainLube/src/webui.cpp
index a088c82..50373c5 100644
--- a/Software/ChainLube/src/webui.cpp
+++ b/Software/ChainLube/src/webui.cpp
@@ -17,7 +17,7 @@ void initWebUI()
return;
}
- webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");;
+ webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");
webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->redirect("/index.htm"); });
webServer.onNotFound(WebserverNotFound_Callback);
@@ -85,6 +85,40 @@ String processor(const String &var)
return LubeConfig.SpeedSource == SOURCE_CAN ? "" : "hidden";
if (var == "SHOW_GPS_SETTINGS")
return LubeConfig.SpeedSource == SOURCE_GPS ? "" : "hidden";
+ if (var == "SHOW_DTC_TABLE")
+ return globals.systemStatus == sysStat_Error ? "" : "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 > 0)
+ {
+ 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 = "" + String(buff_timestamp);
+ temp = temp + " | " + String(DTCStorage[i].Number) + " | ";
+
+ 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 + " |
";
+ }
+ }
+ return temp;
+ }
if (var == "SOURCE_SELECT_OPTIONS")
{
@@ -180,7 +214,7 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request)
if (p->name() == "cansave")
globals.requestEEAction = EE_CFG_SAVE;
// end: POST Form Source CAN Settings
- // begin: POST Form Lubrication
+ // begin: POST Form Lubrication
if (p->name() == "lubedistancenormal")
LubeConfig.DistancePerLube_Default = p->value().toInt();
if (p->name() == "lubedistancerain")
diff --git a/Software/ChainLube/src/webui.h b/Software/ChainLube/src/webui.h
index f48918d..af82387 100644
--- a/Software/ChainLube/src/webui.h
+++ b/Software/ChainLube/src/webui.h
@@ -8,6 +8,7 @@
#include
#include "config.h"
#include "globals.h"
+#include "dtc.h"
void initWebUI();