some debugging regarding EEPROM
This commit is contained in:
		| @@ -23,6 +23,8 @@ const char PROGMEM helpCmd[] = "sysinfo     - System Info\n" | |||||||
|                                "checkEE     - Check EEPROM with checksum\n" |                                "checkEE     - Check EEPROM with checksum\n" | ||||||
|                                "dumpEE1k    - dump the first 1kb of EEPROM to Serial\n" |                                "dumpEE1k    - dump the first 1kb of EEPROM to Serial\n" | ||||||
|                                "dumpEE      - dump the whole EPPROM to Serial\n" |                                "dumpEE      - dump the whole EPPROM to Serial\n" | ||||||
|  |                                "killEE      - kill the first 1024 byte of EEPROM\n" | ||||||
|  |                                "zeroEE      - zero the first 1024 byte of EEPROM\n" | ||||||
|                                "resetPageEE - Reset the PersistenceData Page\n" |                                "resetPageEE - Reset the PersistenceData Page\n" | ||||||
|                                "dumpCFG     - print Config struct\n" |                                "dumpCFG     - print Config struct\n" | ||||||
|                                "dumpPDS     - print PersistanceStruct\n" |                                "dumpPDS     - print PersistanceStruct\n" | ||||||
|   | |||||||
| @@ -117,6 +117,8 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length); | |||||||
| void MovePersistencePage_EEPROM(boolean reset); | void MovePersistencePage_EEPROM(boolean reset); | ||||||
| uint32_t ConfigSanityCheck(bool autocorrect = false); | uint32_t ConfigSanityCheck(bool autocorrect = false); | ||||||
| bool validateWiFiString(char *string, size_t size); | bool validateWiFiString(char *string, size_t size); | ||||||
|  | void writeSequentialToEEPROM(uint16_t memoryAddress, uint16_t length); | ||||||
|  | void writeZeroToEEPROM(uint16_t memoryAddress, uint16_t length); | ||||||
|  |  | ||||||
| extern configData_t ConfigData; | extern configData_t ConfigData; | ||||||
| extern persistenceData_t PersistenceData; | extern persistenceData_t PersistenceData; | ||||||
|   | |||||||
| @@ -19,10 +19,10 @@ | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifdef FEATURE_ENABLE_WIFI_CLIENT | #ifdef FEATURE_ENABLE_WIFI_CLIENT | ||||||
|     #ifndef WIFI_CLIENT_PASSWORD |     #ifndef WIFI_PASSWORD_CLIENT | ||||||
|         #error "You must define an WIFI_PASSWORD for OTA-Update" |         #error "You must define an WIFI_PASSWORD for OTA-Update" | ||||||
|     #endif |     #endif | ||||||
|     #ifndef WIFI_CLIENT_SSID |     #ifndef WIFI_SSID_CLIENT | ||||||
|         #error "You must define an WIFI_SSID for OTA-Update" |         #error "You must define an WIFI_SSID for OTA-Update" | ||||||
|     #endif |     #endif | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -20,9 +20,9 @@ board = d1_mini | |||||||
| upload_protocol = esptool | upload_protocol = esptool | ||||||
| upload_speed = 921600 | upload_speed = 921600 | ||||||
| ;upload_port = 10.0.1.48 | ;upload_port = 10.0.1.48 | ||||||
| ;upload_protocol = espota | ;upload_flags = | ||||||
| ;upload_flags =   | ;  --port=8266 | ||||||
| ;   --auth=${wifi_cred.ota_password} | ;  --auth=${wifi_cred.admin_password} | ||||||
|  |  | ||||||
| build_flags= | build_flags= | ||||||
|   !python codegen/git_rev_macro.py |   !python codegen/git_rev_macro.py | ||||||
| @@ -31,10 +31,10 @@ build_flags= | |||||||
|   ;-DFEATURE_ENABLE_LORA |   ;-DFEATURE_ENABLE_LORA | ||||||
|   -DFEATURE_ENABLE_UARTLORA |   -DFEATURE_ENABLE_UARTLORA | ||||||
|   -DWIFI_AP_IP_GW=10,0,0,1 |   -DWIFI_AP_IP_GW=10,0,0,1 | ||||||
|   -DADMIN_PASSWORD=${wifi_cred.ota_password} |   -DADMIN_PASSWORD=${wifi_cred.admin_password} | ||||||
|   -DWIFI_CLIENT_SSID=${wifi_cred.wifi_client_ssid} |   -DWIFI_SSID_CLIENT=${wifi_cred.wifi_ssid_client} | ||||||
|   -DWIFI_CLIENT_PASSWORD=${wifi_cred.wifi_client_password} |   -DWIFI_PASSWORD_CLIENT=${wifi_cred.wifi_password_client} | ||||||
|   -DWIFI_AP_SSID=${wifi_cred.wifi_ap_ssid} |   -DADMIN_PASSWORD=${wifi_cred.admin_password} | ||||||
|   -DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password} |   -DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password} | ||||||
|   -DDEVICE_NAME='"Dark Emergency Timer"' |   -DDEVICE_NAME='"Dark Emergency Timer"' | ||||||
|  |  | ||||||
|   | |||||||
| @@ -179,7 +179,6 @@ void Debug_pushMessage(const char *format, ...) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @brief Processes a debug command and performs corresponding actions. |  * @brief Processes a debug command and performs corresponding actions. | ||||||
|  * |  * | ||||||
| @@ -206,6 +205,10 @@ void processCmdDebug(String command) | |||||||
|         dumpEEPROM(0, 1024); |         dumpEEPROM(0, 1024); | ||||||
|     else if (command == "dumpEE") |     else if (command == "dumpEE") | ||||||
|         dumpEEPROM(0, EEPROM_SIZE_BYTES); |         dumpEEPROM(0, EEPROM_SIZE_BYTES); | ||||||
|  |     else if (command == "killEE") | ||||||
|  |         writeSequentialToEEPROM(0, 1024); | ||||||
|  |     else if (command == "zeroEE") | ||||||
|  |         writeZeroToEEPROM(0, 1024); | ||||||
|     else if (command == "resetPageEE") |     else if (command == "resetPageEE") | ||||||
|         MovePersistencePage_EEPROM(true); |         MovePersistencePage_EEPROM(true); | ||||||
|     else if (command == "dumpCFG") |     else if (command == "dumpCFG") | ||||||
| @@ -291,6 +294,15 @@ void Debug_printSystemInfo() | |||||||
| void Debug_dumpConfig() | void Debug_dumpConfig() | ||||||
| { | { | ||||||
|     Debug_pushMessage("batteryType: %d\n", ConfigData.batteryType); |     Debug_pushMessage("batteryType: %d\n", ConfigData.batteryType); | ||||||
|  |     Debug_pushMessage("Faction_1_Name: %s\n", ConfigData.Faction_1_Name); | ||||||
|  |     Debug_pushMessage("Faction_1_Name: %s\n", ConfigData.Faction_2_Name); | ||||||
|  |     Debug_pushMessage("Faction_1_Name: %s\n", ConfigData.Faction_3_Name); | ||||||
|  |     Debug_pushMessage("active_faction_on_reboot: %d\n", ConfigData.active_faction_on_reboot); | ||||||
|  |     Debug_pushMessage("wifi_autoconnect: %d\n", ConfigData.wifi_autoconnect); | ||||||
|  |     Debug_pushMessage("wifi_ap_password: %s\n", ConfigData.wifi_ap_password); | ||||||
|  |     Debug_pushMessage("wifi_ap_ssid: %s\n", ConfigData.wifi_ap_ssid); | ||||||
|  |     Debug_pushMessage("wifi_client_ssid: %s\n", ConfigData.wifi_client_ssid); | ||||||
|  |     Debug_pushMessage("wifi_client_password: %s\n", ConfigData.wifi_client_password); | ||||||
|     Debug_pushMessage("EEPROM_Version: %d\n", ConfigData.EEPROM_Version); |     Debug_pushMessage("EEPROM_Version: %d\n", ConfigData.EEPROM_Version); | ||||||
|     Debug_pushMessage("checksum: 0x%08X\n", ConfigData.checksum); |     Debug_pushMessage("checksum: 0x%08X\n", ConfigData.checksum); | ||||||
| } | } | ||||||
| @@ -451,12 +463,15 @@ void Debug_printHelp() | |||||||
|  * @return A pointer to a const char string containing the binary representation |  * @return A pointer to a const char string containing the binary representation | ||||||
|  * of the input number with nibbles separated by a space. |  * of the input number with nibbles separated by a space. | ||||||
|  */ |  */ | ||||||
| const char* uint32_to_binary_string(uint32_t num) { | const char *uint32_to_binary_string(uint32_t num) | ||||||
|  | { | ||||||
|     static char binary_str[65]; // 32 bits + 31 spaces + null terminator |     static char binary_str[65]; // 32 bits + 31 spaces + null terminator | ||||||
|     int i, j; |     int i, j; | ||||||
|     for (i = 31, j = 0; i >= 0; i--, j++) { |     for (i = 31, j = 0; i >= 0; i--, j++) | ||||||
|  |     { | ||||||
|         binary_str[j] = ((num >> i) & 1) ? '1' : '0'; |         binary_str[j] = ((num >> i) & 1) ? '1' : '0'; | ||||||
|         if (i % 4 == 0 && i != 0) { |         if (i % 4 == 0 && i != 0) | ||||||
|  |         { | ||||||
|             binary_str[++j] = ' '; // Insert space after every nibble |             binary_str[++j] = ' '; // Insert space after every nibble | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ configData_t ConfigData; | |||||||
| persistenceData_t PersistenceData; | persistenceData_t PersistenceData; | ||||||
|  |  | ||||||
| // EEPROM version identifier | // EEPROM version identifier | ||||||
| const uint16_t eeVersion = EEPROM_STRUCTURE_REVISION;  | const uint16_t eeVersion = EEPROM_STRUCTURE_REVISION; | ||||||
|  |  | ||||||
| // Flag indicating whether EEPROM is available | // Flag indicating whether EEPROM is available | ||||||
| boolean eeAvailable = false; | boolean eeAvailable = false; | ||||||
| @@ -113,16 +113,23 @@ void EEPROM_Process() | |||||||
|  */ |  */ | ||||||
| void StoreConfig_EEPROM() | void StoreConfig_EEPROM() | ||||||
| { | { | ||||||
|  |   // Berechnung der Prüfsumme | ||||||
|   ConfigData.checksum = 0; |   ConfigData.checksum = 0; | ||||||
|   ConfigData.checksum = Checksum_EEPROM((uint8_t *)&ConfigData, sizeof(ConfigData)); |   ConfigData.checksum = Checksum_EEPROM((uint8_t *)&ConfigData, sizeof(ConfigData)); | ||||||
|  |  | ||||||
|  |   // Überprüfung, ob der EEPROM verfügbar ist | ||||||
|   if (!checkEEPROMavailable()) |   if (!checkEEPROMavailable()) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|   ee.updateBlock(startofConfigData, (uint8_t *)&ConfigData, sizeof(ConfigData)); |   // Byteweise in den EEPROM schreiben | ||||||
|  |   uint8_t *dataPtr = (uint8_t *)&ConfigData; | ||||||
|  |   for (uint16_t i = 0; i < sizeof(ConfigData); i++) | ||||||
|  |   { | ||||||
|  |     ee.writeByte(startofConfigData + i, dataPtr[i]); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Sanity Check der Konfiguration | ||||||
|   uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); |   uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); | ||||||
|  |  | ||||||
|   if (ConfigSanityCheckResult > 0) |   if (ConfigSanityCheckResult > 0) | ||||||
|   { |   { | ||||||
|     MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult); |     MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult); | ||||||
| @@ -152,7 +159,6 @@ void GetConfig_EEPROM() | |||||||
|   uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); |   uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false); | ||||||
|  |  | ||||||
|   MaintainDTC(DTC_EEPROM_CFG_SANITY, (ConfigSanityCheckResult > 0), ConfigSanityCheckResult); |   MaintainDTC(DTC_EEPROM_CFG_SANITY, (ConfigSanityCheckResult > 0), ConfigSanityCheckResult); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -174,7 +180,12 @@ void StorePersistence_EEPROM() | |||||||
|   if (!checkEEPROMavailable()) |   if (!checkEEPROMavailable()) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|   ee.updateBlock(globals.eePersistanceAdress, (uint8_t *)&PersistenceData, sizeof(PersistenceData)); |   // Byteweise in den EEPROM schreiben | ||||||
|  |   uint8_t *dataPtr = (uint8_t *)&PersistenceData; | ||||||
|  |   for (uint16_t i = 0; i < sizeof(PersistenceData); i++) | ||||||
|  |   { | ||||||
|  |     ee.writeByte(globals.eePersistanceAdress + i, dataPtr[i]); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -306,7 +317,7 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length) | |||||||
|   if (!checkEEPROMavailable()) |   if (!checkEEPROMavailable()) | ||||||
|     return; |     return; | ||||||
|  |  | ||||||
|   char ascii_buf[BLOCK_TO_LENGTH + 1]; |   char ascii_buf[BLOCK_TO_LENGTH + 1] = {0}; | ||||||
|   sprintf(ascii_buf, "%*s", BLOCK_TO_LENGTH, "ASCII"); |   sprintf(ascii_buf, "%*s", BLOCK_TO_LENGTH, "ASCII"); | ||||||
|  |  | ||||||
|   // Print column headers |   // Print column headers | ||||||
| @@ -326,24 +337,26 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length) | |||||||
|     // Print ASCII representation header for each block |     // Print ASCII representation header for each block | ||||||
|     if (blockpoint == 0) |     if (blockpoint == 0) | ||||||
|     { |     { | ||||||
|       ascii_buf[BLOCK_TO_LENGTH] = 0; |       if (i > 0) // Ensure we don't print an empty ASCII buffer on the first iteration | ||||||
|       Debug_pushMessage("  %s", ascii_buf); |       { | ||||||
|  |         ascii_buf[BLOCK_TO_LENGTH] = 0; | ||||||
|  |         Debug_pushMessage("  %s", ascii_buf); | ||||||
|  |       } | ||||||
|       Debug_pushMessage("\n0x%05X:", memoryAddress); |       Debug_pushMessage("\n0x%05X:", memoryAddress); | ||||||
|  |       memset(ascii_buf, ' ', BLOCK_TO_LENGTH); // Clear the ASCII buffer with spaces | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Read and print each byte |     // Read and print each byte | ||||||
|     ascii_buf[blockpoint] = ee.readByte(memoryAddress); |     uint8_t byte = ee.readByte(memoryAddress); | ||||||
|     Debug_pushMessage(" %02X", ascii_buf[blockpoint]); |     ascii_buf[blockpoint] = (byte >= 0x20 && byte <= 0x7E) ? byte : '.'; | ||||||
|  |     Debug_pushMessage(" %02X", byte); | ||||||
|     // Replace non-printable characters with dots in ASCII representation |  | ||||||
|     if (ascii_buf[blockpoint] < 0x20 || ascii_buf[blockpoint] > 0x7E) |  | ||||||
|       ascii_buf[blockpoint] = '.'; |  | ||||||
|  |  | ||||||
|     memoryAddress++; |     memoryAddress++; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Print a new line at the end of the dump |   // Print remaining ASCII buffer | ||||||
|   Debug_pushMessage("\n"); |   ascii_buf[BLOCK_TO_LENGTH] = 0; | ||||||
|  |   Debug_pushMessage("  %s\n", ascii_buf); // Final ASCII line | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -459,3 +472,43 @@ bool validateWiFiString(char *string, size_t size) | |||||||
|   return false; |   return false; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @brief Write sequential numbers to a portion of EEPROM. | ||||||
|  |  * | ||||||
|  |  * This function writes sequential numbers starting from 0 to a specified portion of EEPROM. | ||||||
|  |  * If the number reaches 255, it wraps around and starts again from 1. | ||||||
|  |  * | ||||||
|  |  * @param memoryAddress Starting address in EEPROM. | ||||||
|  |  * @param length Number of bytes to write. | ||||||
|  |  */ | ||||||
|  | void writeSequentialToEEPROM(uint16_t memoryAddress, uint16_t length) | ||||||
|  | { | ||||||
|  |   if (!checkEEPROMavailable()) | ||||||
|  |     return; | ||||||
|  |  | ||||||
|  |   uint8_t value = 0; | ||||||
|  |   for (uint16_t i = 0; i < length; i++) | ||||||
|  |   { | ||||||
|  |     ee.writeByte(memoryAddress + i, value); | ||||||
|  |     value = (value == 255) ? 1 : value + 1; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @brief Write 0 to a portion of EEPROM. | ||||||
|  |  * | ||||||
|  |  * This function writes 0 to a specified portion of EEPROM. | ||||||
|  |  * | ||||||
|  |  * @param memoryAddress Starting address in EEPROM. | ||||||
|  |  * @param length Number of bytes to write. | ||||||
|  |  */ | ||||||
|  | void writeZeroToEEPROM(uint16_t memoryAddress, uint16_t length) | ||||||
|  | { | ||||||
|  |   if (!checkEEPROMavailable()) | ||||||
|  |     return; | ||||||
|  |  | ||||||
|  |   for (uint16_t i = 0; i < length; i++) | ||||||
|  |   { | ||||||
|  |     ee.writeByte(memoryAddress + i, 0); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -568,6 +568,7 @@ void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping) | |||||||
|   if (send_mapping) |   if (send_mapping) | ||||||
|   { |   { | ||||||
|     const char mapping[] = "MAPPING_STATUS:" |     const char mapping[] = "MAPPING_STATUS:" | ||||||
|  |                            "batterylevel;" | ||||||
|                            "systemstatus;" |                            "systemstatus;" | ||||||
|                            "activefaction;" |                            "activefaction;" | ||||||
|                            "time_faction1;" |                            "time_faction1;" | ||||||
| @@ -582,6 +583,7 @@ void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping) | |||||||
|  |  | ||||||
|   String temp = "STATUS:"; |   String temp = "STATUS:"; | ||||||
|  |  | ||||||
|  |   temp.concat(String(globals.battery_level) + ";"); | ||||||
|   temp.concat(String(globals.systemStatustxt) + ";"); |   temp.concat(String(globals.systemStatustxt) + ";"); | ||||||
|   temp.concat(String(PersistenceData.activeFaction) + ";"); |   temp.concat(String(PersistenceData.activeFaction) + ";"); | ||||||
|   temp.concat(String(PersistenceData.faction_1_timer) + ";"); |   temp.concat(String(PersistenceData.faction_1_timer) + ";"); | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| [wifi_cred] | [wifi_cred] | ||||||
| wifi_ap_ssid = wifi-ap-ssid | admin_password = chainlube | ||||||
| wifi_ap_password = wifiappass | wifi_ap_password = wifiappass | ||||||
| wifi_client_ssid = wifi-ssid | wifi_ssid_client = wifi-ssid | ||||||
| wifi_client_password = wifi-pass | wifi_password_client = ota-password | ||||||
| ota_password = ota-password |  | ||||||
		Reference in New Issue
	
	Block a user