mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-02 17:29:22 +02:00
Include CAN interface number in logs (with distinct TX/RX)
This commit is contained in:
parent
b33f42c9c5
commit
9554cbf808
7 changed files with 29 additions and 21 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue