mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Refactor CAN logging
This commit is contained in:
parent
7c6b18f0d1
commit
ec00b9be8f
3 changed files with 26 additions and 46 deletions
|
@ -614,31 +614,32 @@ void init_equipment_stop_button() {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CAN_FD
|
enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1
|
||||||
// Functions
|
void print_can_frame(CAN_frame frame, frameDirection msgDir);
|
||||||
#ifdef DEBUG_CANFD_DATA
|
void print_can_frame(CAN_frame frame, frameDirection msgDir) {
|
||||||
enum frameDirection { MSG_RX, MSG_TX };
|
uint8_t i = 0;
|
||||||
void print_canfd_frame(CANFDMessage rx_frame, frameDirection msgDir); // Needs to be declared before it is defined
|
Serial.print(millis());
|
||||||
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);
|
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
for (i = 0; i < rx_frame.len; i++) {
|
(msgDir == 0) ? Serial.print("RX ") : Serial.print("TX ");
|
||||||
Serial.print(rx_frame.data[i] < 16 ? "0" : "");
|
Serial.print(frame.ID, HEX);
|
||||||
Serial.print(rx_frame.data[i], 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.print(" ");
|
||||||
}
|
}
|
||||||
Serial.println(" ");
|
Serial.println(" ");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#ifdef CAN_FD
|
||||||
|
// Functions
|
||||||
void receive_canfd() { // This section checks if we have a complete CAN-FD message incoming
|
void receive_canfd() { // This section checks if we have a complete CAN-FD message incoming
|
||||||
CANFDMessage frame;
|
CANFDMessage frame;
|
||||||
if (canfd.available()) {
|
if (canfd.available()) {
|
||||||
canfd.receive(frame);
|
canfd.receive(frame);
|
||||||
#ifdef DEBUG_CANFD_DATA
|
|
||||||
print_canfd_frame(frame, frameDirection(MSG_RX));
|
|
||||||
#endif
|
|
||||||
CAN_frame rx_frame;
|
CAN_frame rx_frame;
|
||||||
rx_frame.ID = frame.id;
|
rx_frame.ID = frame.id;
|
||||||
rx_frame.ext_ID = frame.ext;
|
rx_frame.ext_ID = frame.ext;
|
||||||
|
@ -1078,6 +1079,9 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
||||||
if (!allowed_to_send_CAN) {
|
if (!allowed_to_send_CAN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_CAN_DATA
|
||||||
|
print_can_frame(*tx_frame, frameDirection(MSG_TX));
|
||||||
|
#endif //DEBUG_CAN_DATA
|
||||||
|
|
||||||
switch (interface) {
|
switch (interface) {
|
||||||
case CAN_NATIVE:
|
case CAN_NATIVE:
|
||||||
|
@ -1120,10 +1124,6 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
||||||
send_ok = canfd.tryToSend(MCP2518Frame);
|
send_ok = canfd.tryToSend(MCP2518Frame);
|
||||||
if (!send_ok) {
|
if (!send_ok) {
|
||||||
set_event(EVENT_CANFD_BUFFER_FULL, interface);
|
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
|
#else // Interface not compiled, and settings try to use it
|
||||||
set_event(EVENT_INTERFACE_MISSING, interface);
|
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) {
|
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) {
|
if (interface == can_config.battery) {
|
||||||
receive_can_battery(*rx_frame);
|
receive_can_battery(*rx_frame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
//#define KIA_E_GMP_BATTERY
|
//#define KIA_E_GMP_BATTERY
|
||||||
//#define KIA_HYUNDAI_HYBRID_BATTERY
|
//#define KIA_HYUNDAI_HYBRID_BATTERY
|
||||||
//#define MG_5_BATTERY
|
//#define MG_5_BATTERY
|
||||||
//#define NISSAN_LEAF_BATTERY
|
#define NISSAN_LEAF_BATTERY
|
||||||
//#define PYLON_BATTERY
|
//#define PYLON_BATTERY
|
||||||
//#define RJXZS_BMS
|
//#define RJXZS_BMS
|
||||||
//#define RENAULT_KANGOO_BATTERY
|
//#define RENAULT_KANGOO_BATTERY
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
|
|
||||||
/* Other options */
|
/* 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_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 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 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.
|
//#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.
|
||||||
|
|
|
@ -130,35 +130,11 @@ void update_values_battery2() { // Handle the values coming in from battery #2
|
||||||
|
|
||||||
void receive_can_battery2(CAN_frame rx_frame) {
|
void receive_can_battery2(CAN_frame rx_frame) {
|
||||||
datalayer.battery2.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
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
|
#endif // DOUBLE_BATTERY
|
||||||
|
|
||||||
void receive_can_battery(CAN_frame rx_frame) {
|
void receive_can_battery(CAN_frame rx_frame) {
|
||||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
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() {
|
void send_can_battery() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue