Added DTC-Table in WebUI and improved DTC-System

This commit is contained in:
Marcel Peterkau 2022-03-09 20:25:02 +01:00
parent 6e0b7581eb
commit dab826b862
9 changed files with 101 additions and 64 deletions

View File

@ -70,6 +70,19 @@
</div>
<h4>aktueller Modus</h4>
<input class="form-control" type="text" placeholder="%SYSTEM_STATUS%" readonly>
<div %SHOW_DTC_TABLE%>
<h4>Fehlercodes</h4>
<table class="table">
<tbody>
<tr>
<th class="col-md-4" scope="col">Timestamp</td>
<th class="col-md-4" scope="col">DTC</td>
<th class="col-md-4" scope="col">active</td>
</tr>
%DTC_TABLE%
</tbody>
</table>
</div>
</p>
</div>
<!-- Div Tab Home-->

View File

@ -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;
}

View File

@ -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;
}

View File

@ -3,29 +3,34 @@
#include <Arduino.h>
#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

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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 = "<tr><td>" + String(buff_timestamp);
temp = temp + "</td><td>" + String(DTCStorage[i].Number) + "</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")
{
@ -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")

View File

@ -8,6 +8,7 @@
#include <ESPAsyncWebServer.h>
#include "config.h"
#include "globals.h"
#include "dtc.h"
void initWebUI();