Compare commits

..

No commits in common. "eafd97b3bdfc150ce62d0b02be9d0506231c7262" and "c9c9ac06d31b7cb6ce6bb94813b0dd54faa9c677" have entirely different histories.

3 changed files with 40 additions and 65 deletions

View File

@ -104,58 +104,44 @@ static void debug_clear_console() {
} }
} }
[[maybe_unused, gnu::format(printf, 2, 3)]] #define debug_log(level, msg, ...) \
static inline void debug_log(unsigned int level, const char *msg, ...) { do { \
if (!DEBUG_CHANNEL_ENABLED(level)) { if (DEBUG_CHANNEL_ENABLED(level)) { \
return; char __swo_buffer[MAX_MESSAGE_LENGTH]; \
} size_t len = \
snprintf(__swo_buffer, sizeof(__swo_buffer), msg, ##__VA_ARGS__); \
char __swo_buffer[MAX_MESSAGE_LENGTH]; __swo_putc('\n', level); \
va_list args; /* Print timestamp if enabled */ \
va_start(args, msg); if (PRINT_TIMESTAMP) { \
size_t len = vsnprintf(__swo_buffer, sizeof(__swo_buffer), msg, args); char __time_buffer[16]; \
va_end(args); if (USE_ANSI_ESCAPE_CODES) { \
snprintf(__time_buffer, sizeof(__time_buffer), \
__swo_putc('\n', level); "\033[90m[%lu]\033[0m ", HAL_GetTick()); \
} else { \
/* Print timestamp if enabled */ snprintf(__time_buffer, sizeof(__time_buffer), "[%lu] ", \
if (PRINT_TIMESTAMP) { HAL_GetTick()); \
char __time_buffer[16]; } \
if (USE_ANSI_ESCAPE_CODES) { __swo_print(level, __time_buffer); \
snprintf(__time_buffer, sizeof(__time_buffer), } \
"\033[90m[%lu]\033[0m ", HAL_GetTick()); __swo_print(level, log_level_names[level]); \
} else { __swo_print(level, __swo_buffer); \
snprintf(__time_buffer, sizeof(__time_buffer), "[%lu] ", if (len >= sizeof(__swo_buffer)) { \
HAL_GetTick()); __swo_print(level, " [message length exceeded] "); \
} } \
__swo_print(level, __time_buffer); } \
} } while (0)
__swo_print(level, log_level_names[level]);
__swo_print(level, __swo_buffer);
if (len >= sizeof(__swo_buffer)) {
__swo_print(level, " [message length exceeded] ");
}
}
[[maybe_unused, gnu::format(printf, 2, 3)]] #define debug_log_cont(level, msg, ...) \
static inline void debug_log_cont(unsigned int level, const char *msg, ...) { do { \
if (!DEBUG_CHANNEL_ENABLED(level)) { if (DEBUG_CHANNEL_ENABLED(level)) { \
return; char __swo_buffer[MAX_MESSAGE_LENGTH]; \
} size_t len = \
snprintf(__swo_buffer, sizeof(__swo_buffer), msg, ##__VA_ARGS__); \
char __swo_buffer[MAX_MESSAGE_LENGTH]; __swo_print(level, __swo_buffer); \
va_list args; if (len >= sizeof(__swo_buffer)) { \
va_start(args, msg); __swo_print(level, " [message length exceeded] "); \
size_t len = vsnprintf(__swo_buffer, sizeof(__swo_buffer), msg, args); } \
va_end(args); } \
} while (0)
__swo_print(level, __swo_buffer);
if (len >= sizeof(__swo_buffer)) {
__swo_print(level, " [message length exceeded] ");
}
}
#endif /* __SWO_LOG_H */ #endif /* __SWO_LOG_H */

View File

@ -85,7 +85,8 @@ HAL_StatusTypeDef initAMS(SPI_HandleTypeDef* hspi) {
} }
HAL_StatusTypeDef amsWakeUp() { HAL_StatusTypeDef amsWakeUp() {
return __pollCMD(PLADC, 100); //wake up ADBMS6830, wait for T_wake = 200 us (100 cycles at 500 kHz) uint8_t buffer[CMD_BUFFER_SIZE(CFG_GROUP_A_SIZE)] = {0};
return readCMD(RDCFGA, buffer, CFG_GROUP_A_SIZE);
} }
HAL_StatusTypeDef amsCellMeasurement(Cell_Module (*module)[N_BMS]) { HAL_StatusTypeDef amsCellMeasurement(Cell_Module (*module)[N_BMS]) {

View File

@ -252,18 +252,6 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen)
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);
if (checkDataPEC(&buffer[offset], arglen + 2) != 0) { if (checkDataPEC(&buffer[offset], arglen + 2) != 0) {
debug_log(LOG_LEVEL_ERROR, "Invalid data PEC when reading BMS %d", i);
debug_log(LOG_LEVEL_ERROR, "Received: ");
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");
//print out spaces until start of DPEC
for (size_t j = 0; j < arglen; j++) {
debug_log_cont(LOG_LEVEL_ERROR, (arglen < 2) ? "" : " ");
}
debug_log(LOG_LEVEL_ERROR, " ^ DPEC");
return HAL_ERROR; return HAL_ERROR;
} }
} }