diff --git a/Software/Software.ino b/Software/Software.ino index 2b45dc5a..c85c376d 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -614,31 +614,32 @@ void init_equipment_stop_button() { #endif -#ifdef CAN_FD -// Functions -#ifdef DEBUG_CANFD_DATA -enum frameDirection { MSG_RX, MSG_TX }; -void print_canfd_frame(CANFDMessage rx_frame, frameDirection msgDir); // Needs to be declared before it is defined -void print_canfd_frame(CANFDMessage rx_frame, frameDirection msgDir) { - int i = 0; - (msgDir == 0) ? Serial.print("RX ") : Serial.print("TX "); - Serial.print(rx_frame.id, HEX); +enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1 +void print_can_frame(CAN_frame frame, frameDirection msgDir); +void print_can_frame(CAN_frame frame, frameDirection msgDir) { + uint8_t i = 0; + Serial.print(millis()); Serial.print(" "); - for (i = 0; i < rx_frame.len; i++) { - Serial.print(rx_frame.data[i] < 16 ? "0" : ""); - Serial.print(rx_frame.data[i], HEX); + (msgDir == 0) ? Serial.print("RX ") : Serial.print("TX "); + Serial.print(frame.ID, HEX); + Serial.print(" "); + Serial.print(frame.DLC); + Serial.print(" "); + for (i = 0; i < frame.DLC; i++) { + Serial.print(frame.data.u8[i] < 16 ? "0" : ""); + Serial.print(frame.data.u8[i], HEX); Serial.print(" "); } Serial.println(" "); } -#endif + +#ifdef CAN_FD +// Functions void receive_canfd() { // This section checks if we have a complete CAN-FD message incoming CANFDMessage frame; if (canfd.available()) { canfd.receive(frame); -#ifdef DEBUG_CANFD_DATA - print_canfd_frame(frame, frameDirection(MSG_RX)); -#endif + CAN_frame rx_frame; rx_frame.ID = frame.id; rx_frame.ext_ID = frame.ext; @@ -1078,6 +1079,9 @@ void transmit_can(CAN_frame* tx_frame, int interface) { if (!allowed_to_send_CAN) { return; } +#ifdef DEBUG_CAN_DATA + print_can_frame(*tx_frame, frameDirection(MSG_TX)); +#endif //DEBUG_CAN_DATA switch (interface) { case CAN_NATIVE: @@ -1120,10 +1124,6 @@ void transmit_can(CAN_frame* tx_frame, int interface) { send_ok = canfd.tryToSend(MCP2518Frame); if (!send_ok) { set_event(EVENT_CANFD_BUFFER_FULL, interface); - } else { -#ifdef DEBUG_CANFD_DATA - print_canfd_frame(MCP2518Frame, frameDirection(MSG_TX)); -#endif } #else // Interface not compiled, and settings try to use it set_event(EVENT_INTERFACE_MISSING, interface); @@ -1136,6 +1136,10 @@ void transmit_can(CAN_frame* tx_frame, int interface) { } void receive_can(CAN_frame* rx_frame, int interface) { +#ifdef DEBUG_CAN_DATA + print_can_frame(*rx_frame, frameDirection(MSG_RX)); +#endif //DEBUG_CAN_DATA + if (interface == can_config.battery) { receive_can_battery(*rx_frame); } diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 26272ca7..2f30bf26 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -20,7 +20,7 @@ //#define KIA_E_GMP_BATTERY //#define KIA_HYUNDAI_HYBRID_BATTERY //#define MG_5_BATTERY -//#define NISSAN_LEAF_BATTERY +#define NISSAN_LEAF_BATTERY //#define PYLON_BATTERY //#define RJXZS_BMS //#define RENAULT_KANGOO_BATTERY @@ -54,7 +54,7 @@ /* Other options */ //#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production) -//#define DEBUG_CANFD_DATA //Enable this line to have the USB port output CAN-FD data while program runs (WARNING, raises CPU load, do not use for production) +//#define DEBUG_CAN_DATA //Enable this line to print incoming/outgoing CAN & CAN-FD messages to USB serial (WARNING, raises CPU load, do not use for production) //#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting //#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle automatic precharge/contactor+/contactor- closing sequence //#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM for CONTACTOR_CONTROL, which lowers power consumption and heat generation. CONTACTOR_CONTROL must be enabled. diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index 630fa536..423654aa 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -130,35 +130,11 @@ void update_values_battery2() { // Handle the values coming in from battery #2 void receive_can_battery2(CAN_frame rx_frame) { datalayer.battery2.status.CAN_battery_still_alive = CAN_STILL_ALIVE; - // All CAN messages recieved will be logged via serial - Serial.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D - Serial.print(" "); - Serial.print(rx_frame.ID, HEX); - Serial.print(" "); - Serial.print(rx_frame.DLC); - Serial.print(" "); - for (int i = 0; i < rx_frame.DLC; ++i) { - Serial.print(rx_frame.data.u8[i], HEX); - Serial.print(" "); - } - Serial.println(""); } #endif // DOUBLE_BATTERY void receive_can_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; - // All CAN messages recieved will be logged via serial - Serial.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D - Serial.print(" "); - Serial.print(rx_frame.ID, HEX); - Serial.print(" "); - Serial.print(rx_frame.DLC); - Serial.print(" "); - for (int i = 0; i < rx_frame.DLC; ++i) { - Serial.print(rx_frame.data.u8[i], HEX); - Serial.print(" "); - } - Serial.println(""); } void send_can_battery() { unsigned long currentMillis = millis();