add: better error message when DPEC fails to validate

This commit is contained in:
Kilian Bracher 2025-03-31 19:46:47 +02:00
parent c9c9ac06d3
commit 6145508e8b
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
2 changed files with 13 additions and 2 deletions

View File

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

View File

@ -252,6 +252,18 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen)
for (size_t i = 0; i < N_BMS; i++) {
size_t offset = BUFFER_BMS_OFFSET(i, arglen);
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;
}
}