diff --git a/Software/src/battery/MEB-BATTERY.cpp b/Software/src/battery/MEB-BATTERY.cpp index a20ccb2e..bda14b14 100644 --- a/Software/src/battery/MEB-BATTERY.cpp +++ b/Software/src/battery/MEB-BATTERY.cpp @@ -1271,7 +1271,7 @@ void MebBattery::handle_incoming_can_frame(CAN_frame rx_frame) { } break; case 0x18DAF105: - handle_obd_frame(rx_frame); + handle_obd_frame(rx_frame, can_interface); break; default: break; diff --git a/Software/src/communication/can/comm_can.cpp b/Software/src/communication/can/comm_can.cpp index 4696d8df..a9e3e615 100644 --- a/Software/src/communication/can/comm_can.cpp +++ b/Software/src/communication/can/comm_can.cpp @@ -228,11 +228,11 @@ bool init_CAN() { return true; } -void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface) { +void transmit_can_frame_to_interface(const CAN_frame* tx_frame, CAN_Interface interface) { if (!allowed_to_send_CAN) { return; } - print_can_frame(*tx_frame, frameDirection(MSG_TX)); + print_can_frame(*tx_frame, interface, frameDirection(MSG_TX)); if (datalayer.system.info.CAN_SD_logging_active) { add_can_frame_to_buffer(*tx_frame, frameDirection(MSG_TX)); @@ -367,13 +367,20 @@ void receive_frame_canfd_addon() { // This section checks if we have a complete } // Support functions -void print_can_frame(CAN_frame frame, frameDirection msgDir) { +void print_can_frame(CAN_frame frame, CAN_Interface interface, frameDirection msgDir) { if (datalayer.system.info.CAN_usb_logging_active) { uint8_t i = 0; Serial.print("("); Serial.print(millis() / 1000.0); - (msgDir == MSG_RX) ? Serial.print(") RX0 ") : Serial.print(") TX1 "); + if (msgDir == MSG_RX) { + Serial.print(") RX"); + Serial.print((int)(interface * 2)); + } else { + Serial.print(") TX"); + Serial.print((int)(interface * 2) + 1); + } + Serial.print(" "); Serial.print(frame.ID, HEX); Serial.print(" ["); Serial.print(frame.DLC); @@ -388,7 +395,7 @@ void print_can_frame(CAN_frame frame, frameDirection msgDir) { } if (datalayer.system.info.can_logging_active) { // If user clicked on CAN Logging page in webserver, start recording - dump_can_frame(frame, msgDir); + dump_can_frame(frame, interface, msgDir); } } @@ -396,7 +403,7 @@ void map_can_frame_to_variable(CAN_frame* rx_frame, CAN_Interface interface) { if (interface != CANFD_NATIVE) { //Avoid printing twice due to receive_frame_canfd_addon sending to both FD interfaces //TODO: This check can be removed later when refactored to use inline functions for logging - print_can_frame(*rx_frame, frameDirection(MSG_RX)); + print_can_frame(*rx_frame, interface, frameDirection(MSG_RX)); } if (datalayer.system.info.CAN_SD_logging_active) { @@ -416,7 +423,7 @@ void map_can_frame_to_variable(CAN_frame* rx_frame, CAN_Interface interface) { } } -void dump_can_frame(CAN_frame& frame, frameDirection msgDir) { +void dump_can_frame(CAN_frame& frame, CAN_Interface interface, frameDirection msgDir) { char* message_string = datalayer.system.info.logged_can_messages; int offset = datalayer.system.info.logged_can_messages_offset; // Keeps track of the current position in the buffer size_t message_string_size = sizeof(datalayer.system.info.logged_can_messages); @@ -430,8 +437,9 @@ void dump_can_frame(CAN_frame& frame, frameDirection msgDir) { offset += snprintf(message_string + offset, message_string_size - offset, "(%lu.%03lu) ", currentTime / 1000, currentTime % 1000); - // Add direction. The 0 and 1 after RX and TX ensures that SavvyCAN puts TX and RX in a different bus. - offset += snprintf(message_string + offset, message_string_size - offset, "%s ", (msgDir == MSG_RX) ? "RX0" : "TX1"); + // Add direction. Multiplying the interface by two ensures that SavvyCAN puts TX and RX in a different bus. + offset += snprintf(message_string + offset, message_string_size - offset, "%s%d ", (msgDir == MSG_RX) ? "RX" : "TX", + (int)(interface * 2) + (msgDir == MSG_RX ? 0 : 1)); // Add ID and DLC offset += snprintf(message_string + offset, message_string_size - offset, "%X [%u] ", frame.ID, frame.DLC); diff --git a/Software/src/communication/can/comm_can.h b/Software/src/communication/can/comm_can.h index 2efad224..e77e86c2 100644 --- a/Software/src/communication/can/comm_can.h +++ b/Software/src/communication/can/comm_can.h @@ -7,8 +7,8 @@ extern bool use_canfd_as_can; extern uint8_t user_selected_can_addon_crystal_frequency_mhz; extern uint8_t user_selected_canfd_addon_crystal_frequency_mhz; -void dump_can_frame(CAN_frame& frame, frameDirection msgDir); -void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface); +void dump_can_frame(CAN_frame& frame, CAN_Interface interface, frameDirection msgDir); +void transmit_can_frame_to_interface(const CAN_frame* tx_frame, CAN_Interface interface); //These defines are not used if user updates values via Settings page #define CRYSTAL_FREQUENCY_MHZ 8 @@ -94,7 +94,7 @@ void receive_frame_canfd_addon(); * * @return void */ -void print_can_frame(CAN_frame frame, frameDirection msgDir); +void print_can_frame(CAN_frame frame, CAN_Interface interface, frameDirection msgDir); // Stop/pause CAN communication for all interfaces void stop_can(); diff --git a/Software/src/communication/can/obd.cpp b/Software/src/communication/can/obd.cpp index ec2bc49b..26aab251 100644 --- a/Software/src/communication/can/obd.cpp +++ b/Software/src/communication/can/obd.cpp @@ -23,7 +23,7 @@ void show_dtc(uint8_t byte0, uint8_t byte1) { logging.printf("%c%d\n", letter, ((byte0 & 0x3F) << 8) | byte1); } -void handle_obd_frame(CAN_frame& rx_frame) { +void handle_obd_frame(CAN_frame& rx_frame, CAN_Interface interface) { if (rx_frame.data.u8[1] == 0x7F) { const char* error_str = "?"; switch (rx_frame.data.u8[3]) { // See https://automotive.wiki/index.php/ISO_14229 @@ -105,10 +105,10 @@ void handle_obd_frame(CAN_frame& rx_frame) { logging.printf("ODBx reply frame received:\n"); } } - dump_can_frame(rx_frame, MSG_RX); + dump_can_frame(rx_frame, interface, MSG_RX); } -void transmit_obd_can_frame(unsigned int address, int interface, bool canFD) { +void transmit_obd_can_frame(unsigned int address, CAN_Interface interface, bool canFD) { static CAN_frame OBD_frame; OBD_frame.FD = canFD; OBD_frame.ID = address; diff --git a/Software/src/communication/can/obd.h b/Software/src/communication/can/obd.h index 2a495820..38671d4a 100644 --- a/Software/src/communication/can/obd.h +++ b/Software/src/communication/can/obd.h @@ -3,8 +3,8 @@ #include "comm_can.h" -void handle_obd_frame(CAN_frame& rx_frame); +void handle_obd_frame(CAN_frame& rx_frame, CAN_Interface interface); -void transmit_obd_can_frame(unsigned int address, int interface, bool canFD); +void transmit_obd_can_frame(unsigned int address, CAN_Interface interface, bool canFD); #endif // _OBD_H_ diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 74599e62..5a58b66a 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -157,7 +157,7 @@ void canReplayTask(void* param) { (datalayer.system.info.can_replay_interface == CANFD_ADDON_MCP2518); currentFrame.ext_ID = (currentFrame.ID > 0x7F0); - transmit_can_frame_to_interface(¤tFrame, datalayer.system.info.can_replay_interface); + transmit_can_frame_to_interface(¤tFrame, (CAN_Interface)datalayer.system.info.can_replay_interface); } } while (datalayer.system.info.loop_playback); diff --git a/test/emul/can.cpp b/test/emul/can.cpp index 8beb1574..2903a1c6 100644 --- a/test/emul/can.cpp +++ b/test/emul/can.cpp @@ -1,7 +1,7 @@ #include "../../Software/src/communication/Transmitter.h" #include "../../Software/src/communication/can/comm_can.h" -void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface) {} +void transmit_can_frame_to_interface(const CAN_frame* tx_frame, CAN_Interface interface) {} void register_can_receiver(CanReceiver* receiver, CAN_Interface interface, CAN_Speed speed) {} @@ -19,4 +19,4 @@ char const* getCANInterfaceName(CAN_Interface) { void register_transmitter(Transmitter* transmitter) {} -void dump_can_frame(CAN_frame& frame, frameDirection msgDir) {} +void dump_can_frame(CAN_frame& frame, CAN_Interface interface, frameDirection msgDir) {}