reworked DTC-Data handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user