From 44c012082bb026eee20e966daf381c523d1777c1 Mon Sep 17 00:00:00 2001 From: kbracher Date: Mon, 31 Mar 2025 21:54:57 +0200 Subject: [PATCH] fix: formatting of DPEC errors --- AMS_Master_Code/Core/Inc/swo_log.h | 4 ++-- .../ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/AMS_Master_Code/Core/Inc/swo_log.h b/AMS_Master_Code/Core/Inc/swo_log.h index 1a1a3c6..ed95e66 100644 --- a/AMS_Master_Code/Core/Inc/swo_log.h +++ b/AMS_Master_Code/Core/Inc/swo_log.h @@ -104,7 +104,7 @@ static inline void debug_clear_console() { } [[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)) { return; } @@ -139,7 +139,7 @@ static inline void debug_log(unsigned int level, const char *msg, ...) { } [[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)) { return; } diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c index a35f37b..f951a04 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c @@ -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 for (size_t i = 0; i < N_BMS; i++) { size_t offset = BUFFER_BMS_OFFSET(i, arglen); @@ -257,13 +261,14 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen) for (size_t j = 0; j < arglen + 2; 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(LOG_LEVEL_ERROR, "^ DATA"); + 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 ^"); //print out spaces until start of DPEC - for (size_t j = 0; j < arglen; j++) { - debug_log_cont(LOG_LEVEL_ERROR, (arglen < 2) ? "" : " "); + for (size_t j = 0; j < arglen - 1; j++) { + 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; } }