Implemented DebugVal for DTCs and SanityCheck
This commit is contained in:
		| @@ -89,9 +89,11 @@ void GetConfig_EEPROM() | ||||
|   } | ||||
|   LubeConfig.checksum = checksum; | ||||
|  | ||||
|   if (!ConfigSanityCheck(true)) | ||||
|   uint32_t ConfigSanityCheckResult = ConfigSanityCheck(true); | ||||
|  | ||||
|   if (ConfigSanityCheckResult > 0) | ||||
|   { | ||||
|     MaintainDTC(DTC_EEPROM_CFG_SANITY, DTC_WARN, true); | ||||
|     MaintainDTC(DTC_EEPROM_CFG_SANITY, DTC_WARN, true, ConfigSanityCheckResult); | ||||
|     globals.requestEEAction = EE_CFG_SAVE; | ||||
|   } | ||||
| } | ||||
| @@ -238,90 +240,90 @@ boolean checkEEPROMavailable() | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| bool ConfigSanityCheck(bool autocorrect) | ||||
| uint32_t ConfigSanityCheck(bool autocorrect) | ||||
| { | ||||
|   bool allvalid = true; | ||||
|   uint32_t setting_reset_bits = 0; | ||||
|  | ||||
|   if (!(LubeConfig.DistancePerLube_Default > 0) || !(LubeConfig.DistancePerLube_Default < 50000)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 0); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.DistancePerLube_Default = LubeConfig_defaults.DistancePerLube_Default; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.DistancePerLube_Rain > 0) || !(LubeConfig.DistancePerLube_Rain < 50000)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 1); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.DistancePerLube_Rain = LubeConfig_defaults.DistancePerLube_Rain; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.tankCapacity_ml > 0) || !(LubeConfig.tankCapacity_ml < 5000)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 2); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.tankCapacity_ml = LubeConfig_defaults.tankCapacity_ml; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.amountPerDose_µl > 0) || !(LubeConfig.amountPerDose_µl < 100)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 3); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.amountPerDose_µl = LubeConfig_defaults.amountPerDose_µl; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.TankRemindAtPercentage >= 0) || !(LubeConfig.TankRemindAtPercentage <= 100)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 4); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.TankRemindAtPercentage = LubeConfig_defaults.TankRemindAtPercentage; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.PulsePerRevolution > 0) || !(LubeConfig.PulsePerRevolution < 1000)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 5); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.PulsePerRevolution = LubeConfig_defaults.PulsePerRevolution; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.TireWidth_mm > 0) || !(LubeConfig.TireWidth_mm < 500)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 6); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.TireWidth_mm = LubeConfig_defaults.TireWidth_mm; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.TireWidthHeight_Ratio > 0) || !(LubeConfig.TireWidthHeight_Ratio < 150)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 7); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.TireWidthHeight_Ratio = LubeConfig_defaults.TireWidthHeight_Ratio; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.RimDiameter_Inch > 0) || !(LubeConfig.RimDiameter_Inch < 30)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 8); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.RimDiameter_Inch = LubeConfig_defaults.RimDiameter_Inch; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.DistancePerRevolution_mm > 0) || !(LubeConfig.DistancePerRevolution_mm < 10000)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 9); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.DistancePerRevolution_mm = LubeConfig_defaults.DistancePerRevolution_mm; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.BleedingPulses > 0) || !(LubeConfig.BleedingPulses < 1001)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 10); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.BleedingPulses = LubeConfig_defaults.BleedingPulses; | ||||
|   } | ||||
|  | ||||
|   if (!(LubeConfig.SpeedSource >= 0) || !(LubeConfig.SpeedSource < SpeedSourceString_Elements)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 11); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.SpeedSource = LubeConfig_defaults.SpeedSource; | ||||
|   } | ||||
| @@ -329,7 +331,7 @@ bool ConfigSanityCheck(bool autocorrect) | ||||
| #ifdef FEATURE_ENABLE_GPS | ||||
|   if (!(LubeConfig.GPSBaudRate >= 0) || !(LubeConfig.GPSBaudRate < GPSBaudRateString_Elements)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 12); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.GPSBaudRate = LubeConfig_defaults.GPSBaudRate; | ||||
|   } | ||||
| @@ -338,10 +340,10 @@ bool ConfigSanityCheck(bool autocorrect) | ||||
| #ifdef FEATURE_ENABLE_CAN | ||||
|   if (!(LubeConfig.CANSource >= 0) || !(LubeConfig.CANSource < CANSourceString_Elements)) | ||||
|   { | ||||
|     allvalid = false; | ||||
|     setting_reset_bits = setting_reset_bits | (1 << 13); | ||||
|     if (autocorrect) | ||||
|       LubeConfig.CANSource = LubeConfig_defaults.CANSource; | ||||
|   } | ||||
| #endif | ||||
|   return allvalid; | ||||
|   return setting_reset_bits; | ||||
| } | ||||
| @@ -116,7 +116,7 @@ void FormatPersistence_EEPROM(); | ||||
| uint32_t Checksum_EEPROM(uint8_t const *data, size_t len); | ||||
| void dumpEEPROM(uint16_t memoryAddress, uint16_t length); | ||||
| void MovePersistencePage_EEPROM(boolean reset); | ||||
| bool ConfigSanityCheck(bool autocorrect = false); | ||||
| uint32_t ConfigSanityCheck(bool autocorrect = false); | ||||
|  | ||||
| extern LubeConfig_t LubeConfig; | ||||
| extern persistenceData_t PersistenceData; | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| DTCEntry_s DTCStorage[MAX_DTC_STORAGE]; | ||||
|  | ||||
| void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active) | ||||
| void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue) | ||||
| { | ||||
|     for (int i = 0; i < MAX_DTC_STORAGE; i++) | ||||
|     { | ||||
| @@ -10,10 +10,11 @@ void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active) | ||||
|         { | ||||
|             if (active && DTCStorage[i].active != DTC_ACTIVE) | ||||
|             { | ||||
|                 Serial.printf("DTC gone active: %d\n", DTC_no); | ||||
|                 Serial.printf("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) | ||||
|             { | ||||
| @@ -32,10 +33,11 @@ void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active) | ||||
|         { | ||||
|             if (DTCStorage[i].Number == DTC_LAST_DTC) | ||||
|             { | ||||
|                 Serial.printf("new DTC registered: %d\n", DTC_no); | ||||
|                 Serial.printf("new DTC registered: %d, DebugVal: %d\n", DTC_no, DebugValue); | ||||
|                 DTCStorage[i].Number = DTC_no; | ||||
|                 DTCStorage[i].timestamp = millis(); | ||||
|                 DTCStorage[i].active = DTC_ACTIVE; | ||||
|                 DTCStorage[i].debugVal = DebugValue; | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -47,9 +47,10 @@ typedef struct DTCEntry_s | ||||
|   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); | ||||
| void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active, uint32_t DebugValue = 0); | ||||
| void ClearDTC(DTCNums_t DTC_no); | ||||
| void ClearAllDTC(); | ||||
| DTCNums_t getlastDTC(boolean only_active); | ||||
|   | ||||
| @@ -140,7 +140,8 @@ String processor(const String &var) | ||||
|                 DTCStorage[i].timestamp / 1000 % 60,   // Seconds | ||||
|                 DTCStorage[i].timestamp % 1000);       // milliseconds | ||||
|  | ||||
|         temp = temp + "<tr data-dtc=" + String(DTCStorage[i].Number) + "><td>" + String(buff_timestamp); | ||||
|         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 (DTCStorage[i].severity) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user