Prevent CAN ID collision with DieBieMS / FlexiBMS

This commit is contained in:
rpasichnyk 2021-04-21 08:55:52 +02:00
parent 36d32ed96d
commit 0d2610c9bc
1 changed files with 10 additions and 1 deletions

View File

@ -23,7 +23,16 @@
#include HW_SOURCE #include HW_SOURCE
uint8_t hw_id_from_uuid(void) { uint8_t hw_id_from_uuid(void) {
return utils_crc32c(STM32_UUID_8, 12) & 0x7F; uint8_t id = utils_crc32c(STM32_UUID_8, 12) & 0x7F;
// CAN ID 10 and 11 are often used by DieBieMS / FlexiBMS
uint8_t reserved[] = {10, 11};
for (size_t i = 0; i < sizeof(reserved); ++i) {
if (id == reserved[i]) {
id = (id + 1) & 0x7F;
i = 0;
}
}
return id;
} }
#if defined(HW_ID_PIN_GPIOS) && defined(HW_ID_PIN_PINS) #if defined(HW_ID_PIN_GPIOS) && defined(HW_ID_PIN_PINS)