mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Add error message incase MCP2515 fails to start
This commit is contained in:
parent
2a359d95ac
commit
966a6c5517
3 changed files with 17 additions and 2 deletions
|
@ -407,7 +407,18 @@ void init_CAN() {
|
|||
SPI.begin(MCP2515_SCK, MCP2515_MISO, MCP2515_MOSI);
|
||||
ACAN2515Settings settings(QUARTZ_FREQUENCY, 500UL * 1000UL); // CAN bit rate 500 kb/s
|
||||
settings.mRequestedMode = ACAN2515Settings::NormalMode;
|
||||
can.begin(settings, [] { can.isr(); });
|
||||
const uint16_t errorCodeMCP = can.begin(settings, [] { can.isr(); });
|
||||
if (errorCodeMCP == 0) {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("Can ok");
|
||||
#endif
|
||||
} else {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.print("Error Can: 0x");
|
||||
Serial.println(errorCodeMCP, HEX);
|
||||
#endif
|
||||
set_event(EVENT_CANMCP_INIT_FAILURE, (uint8_t)errorCodeMCP);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CAN_FD
|
||||
|
|
|
@ -141,6 +141,7 @@ void init_events(void) {
|
|||
}
|
||||
|
||||
events.entries[EVENT_CANFD_INIT_FAILURE].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_CANMCP_INIT_FAILURE].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_CANFD_BUFFER_FULL].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_CAN_OVERRUN].level = EVENT_LEVEL_INFO;
|
||||
events.entries[EVENT_CAN_RX_FAILURE].level = EVENT_LEVEL_ERROR;
|
||||
|
@ -244,6 +245,8 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) {
|
|||
switch (event) {
|
||||
case EVENT_CANFD_INIT_FAILURE:
|
||||
return "CAN-FD initialization failed. Check hardware or bitrate settings";
|
||||
case EVENT_CANMCP_INIT_FAILURE:
|
||||
return "CAN-MCP addon initialization failed. Check hardware";
|
||||
case EVENT_CANFD_BUFFER_FULL:
|
||||
return "CAN-FD buffer overflowed. Some CAN messages were not sent. Contact developers.";
|
||||
case EVENT_CAN_OVERRUN:
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
// #define INCLUDE_EVENTS_TEST // Enable to run an event test loop, see events_test_on_target.cpp
|
||||
|
||||
#define EE_MAGIC_HEADER_VALUE 0x0013 // 0x0000 to 0xFFFF
|
||||
#define EE_MAGIC_HEADER_VALUE 0x0014 // 0x0000 to 0xFFFF
|
||||
|
||||
#define GENERATE_ENUM(ENUM) ENUM,
|
||||
#define GENERATE_STRING(STRING) #STRING,
|
||||
|
@ -27,6 +27,7 @@
|
|||
|
||||
#define EVENTS_ENUM_TYPE(XX) \
|
||||
XX(EVENT_CANFD_INIT_FAILURE) \
|
||||
XX(EVENT_CANMCP_INIT_FAILURE) \
|
||||
XX(EVENT_CANFD_BUFFER_FULL) \
|
||||
XX(EVENT_CAN_OVERRUN) \
|
||||
XX(EVENT_CAN_RX_FAILURE) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue