some debugging regarding EEPROM
This commit is contained in:
@@ -179,7 +179,6 @@ void Debug_pushMessage(const char *format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Processes a debug command and performs corresponding actions.
|
||||
*
|
||||
@@ -206,6 +205,10 @@ void processCmdDebug(String command)
|
||||
dumpEEPROM(0, 1024);
|
||||
else if (command == "dumpEE")
|
||||
dumpEEPROM(0, EEPROM_SIZE_BYTES);
|
||||
else if (command == "killEE")
|
||||
writeSequentialToEEPROM(0, 1024);
|
||||
else if (command == "zeroEE")
|
||||
writeZeroToEEPROM(0, 1024);
|
||||
else if (command == "resetPageEE")
|
||||
MovePersistencePage_EEPROM(true);
|
||||
else if (command == "dumpCFG")
|
||||
@@ -291,6 +294,15 @@ void Debug_printSystemInfo()
|
||||
void Debug_dumpConfig()
|
||||
{
|
||||
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("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
|
||||
* 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
|
||||
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';
|
||||
if (i % 4 == 0 && i != 0) {
|
||||
if (i % 4 == 0 && i != 0)
|
||||
{
|
||||
binary_str[++j] = ' '; // Insert space after every nibble
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ configData_t ConfigData;
|
||||
persistenceData_t PersistenceData;
|
||||
|
||||
// EEPROM version identifier
|
||||
const uint16_t eeVersion = EEPROM_STRUCTURE_REVISION;
|
||||
const uint16_t eeVersion = EEPROM_STRUCTURE_REVISION;
|
||||
|
||||
// Flag indicating whether EEPROM is available
|
||||
boolean eeAvailable = false;
|
||||
@@ -113,16 +113,23 @@ void EEPROM_Process()
|
||||
*/
|
||||
void StoreConfig_EEPROM()
|
||||
{
|
||||
// Berechnung der Prüfsumme
|
||||
ConfigData.checksum = 0;
|
||||
ConfigData.checksum = Checksum_EEPROM((uint8_t *)&ConfigData, sizeof(ConfigData));
|
||||
|
||||
// Überprüfung, ob der EEPROM verfügbar ist
|
||||
if (!checkEEPROMavailable())
|
||||
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);
|
||||
|
||||
if (ConfigSanityCheckResult > 0)
|
||||
{
|
||||
MaintainDTC(DTC_EEPROM_CFG_SANITY, true, ConfigSanityCheckResult);
|
||||
@@ -152,7 +159,6 @@ void GetConfig_EEPROM()
|
||||
uint32_t ConfigSanityCheckResult = ConfigSanityCheck(false);
|
||||
|
||||
MaintainDTC(DTC_EEPROM_CFG_SANITY, (ConfigSanityCheckResult > 0), ConfigSanityCheckResult);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +180,12 @@ void StorePersistence_EEPROM()
|
||||
if (!checkEEPROMavailable())
|
||||
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())
|
||||
return;
|
||||
|
||||
char ascii_buf[BLOCK_TO_LENGTH + 1];
|
||||
char ascii_buf[BLOCK_TO_LENGTH + 1] = {0};
|
||||
sprintf(ascii_buf, "%*s", BLOCK_TO_LENGTH, "ASCII");
|
||||
|
||||
// Print column headers
|
||||
@@ -326,24 +337,26 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
||||
// Print ASCII representation header for each block
|
||||
if (blockpoint == 0)
|
||||
{
|
||||
ascii_buf[BLOCK_TO_LENGTH] = 0;
|
||||
Debug_pushMessage(" %s", ascii_buf);
|
||||
if (i > 0) // Ensure we don't print an empty ASCII buffer on the first iteration
|
||||
{
|
||||
ascii_buf[BLOCK_TO_LENGTH] = 0;
|
||||
Debug_pushMessage(" %s", ascii_buf);
|
||||
}
|
||||
Debug_pushMessage("\n0x%05X:", memoryAddress);
|
||||
memset(ascii_buf, ' ', BLOCK_TO_LENGTH); // Clear the ASCII buffer with spaces
|
||||
}
|
||||
|
||||
// Read and print each byte
|
||||
ascii_buf[blockpoint] = ee.readByte(memoryAddress);
|
||||
Debug_pushMessage(" %02X", ascii_buf[blockpoint]);
|
||||
|
||||
// Replace non-printable characters with dots in ASCII representation
|
||||
if (ascii_buf[blockpoint] < 0x20 || ascii_buf[blockpoint] > 0x7E)
|
||||
ascii_buf[blockpoint] = '.';
|
||||
uint8_t byte = ee.readByte(memoryAddress);
|
||||
ascii_buf[blockpoint] = (byte >= 0x20 && byte <= 0x7E) ? byte : '.';
|
||||
Debug_pushMessage(" %02X", byte);
|
||||
|
||||
memoryAddress++;
|
||||
}
|
||||
|
||||
// Print a new line at the end of the dump
|
||||
Debug_pushMessage("\n");
|
||||
// Print remaining ASCII buffer
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
const char mapping[] = "MAPPING_STATUS:"
|
||||
"batterylevel;"
|
||||
"systemstatus;"
|
||||
"activefaction;"
|
||||
"time_faction1;"
|
||||
@@ -582,6 +583,7 @@ void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping)
|
||||
|
||||
String temp = "STATUS:";
|
||||
|
||||
temp.concat(String(globals.battery_level) + ";");
|
||||
temp.concat(String(globals.systemStatustxt) + ";");
|
||||
temp.concat(String(PersistenceData.activeFaction) + ";");
|
||||
temp.concat(String(PersistenceData.faction_1_timer) + ";");
|
||||
|
Reference in New Issue
Block a user