fix: formatting of DPEC errors

This commit is contained in:
Kilian Bracher 2025-03-31 21:54:57 +02:00
parent 11a2121fd8
commit 44c012082b
2 changed files with 12 additions and 7 deletions

View File

@ -104,7 +104,7 @@ static inline void debug_clear_console() {
} }
[[gnu::format(printf, 2, 3)]] [[gnu::format(printf, 2, 3)]]
static inline void debug_log(unsigned int level, const char *msg, ...) { static inline void debug_log(enum log_level_t level, const char *msg, ...) {
if (!DEBUG_CHANNEL_ENABLED(level)) { if (!DEBUG_CHANNEL_ENABLED(level)) {
return; return;
} }
@ -139,7 +139,7 @@ static inline void debug_log(unsigned int level, const char *msg, ...) {
} }
[[gnu::format(printf, 2, 3)]] [[gnu::format(printf, 2, 3)]]
static inline void debug_log_cont(unsigned int level, const char *msg, ...) { static inline void debug_log_cont(enum log_level_t level, const char *msg, ...) {
if (!DEBUG_CHANNEL_ENABLED(level)) { if (!DEBUG_CHANNEL_ENABLED(level)) {
return; return;
} }

View File

@ -248,6 +248,10 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen)
} }
} }
if (arglen == 0) {
return HAL_OK; //no data to check
}
//check data PEC //check data PEC
for (size_t i = 0; i < N_BMS; i++) { for (size_t i = 0; i < N_BMS; i++) {
size_t offset = BUFFER_BMS_OFFSET(i, arglen); size_t offset = BUFFER_BMS_OFFSET(i, arglen);
@ -258,12 +262,13 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen)
debug_log_cont(LOG_LEVEL_ERROR, "%02X ", buffer[offset + j]); debug_log_cont(LOG_LEVEL_ERROR, "%02X ", buffer[offset + j]);
} }
debug_log_cont(LOG_LEVEL_ERROR, "| %02X %02X ", buffer[offset + arglen], buffer[offset + arglen + 1]); //print out the DPEC debug_log_cont(LOG_LEVEL_ERROR, "| %02X %02X ", buffer[offset + arglen], buffer[offset + arglen + 1]); //print out the DPEC
debug_log(LOG_LEVEL_ERROR, "^ DATA"); debug_log(LOG_LEVEL_ERROR, " DATA ^");
//print out spaces until start of DPEC //print out spaces until start of DPEC
for (size_t j = 0; j < arglen; j++) { for (size_t j = 0; j < arglen - 1; j++) {
debug_log_cont(LOG_LEVEL_ERROR, (arglen < 2) ? "" : " "); debug_log_cont(LOG_LEVEL_ERROR, (arglen < 2) ? "" : "^^^");
} }
debug_log(LOG_LEVEL_ERROR, " ^ DPEC"); debug_log_cont(LOG_LEVEL_ERROR, "^^ ");
debug_log_cont(LOG_LEVEL_ERROR, " PEC ^");
return HAL_ERROR; return HAL_ERROR;
} }
} }