diff --git a/Software/Software.ino b/Software/Software.ino index ce84181b..30afdb1c 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -15,6 +15,7 @@ #include "src/communication/rs485/comm_rs485.h" #include "src/communication/seriallink/comm_seriallink.h" #include "src/datalayer/datalayer.h" +#include "src/devboard/sdcard/sdcard.h" #include "src/devboard/utils/events.h" #include "src/devboard/utils/led_handler.h" #include "src/devboard/utils/logging.h" @@ -79,12 +80,16 @@ MyTimer core_task_timer_10s(INTERVAL_10_S); int64_t connectivity_task_time_us; MyTimer connectivity_task_timer_10s(INTERVAL_10_S); +int64_t logging_task_time_us; +MyTimer logging_task_timer_10s(INTERVAL_10_S); + MyTimer loop_task_timer_10s(INTERVAL_10_S); MyTimer check_pause_2s(INTERVAL_2_S); TaskHandle_t main_loop_task; TaskHandle_t connectivity_loop_task; +TaskHandle_t logging_loop_task; Logging logging; @@ -99,6 +104,11 @@ void setup() { TASK_CONNECTIVITY_PRIO, &connectivity_loop_task, WIFI_CORE); #endif +#ifdef LOG_CAN_TO_SD + xTaskCreatePinnedToCore((TaskFunction_t)&logging_loop, "logging_loop", 4096, &logging_task_time_us, + TASK_CONNECTIVITY_PRIO, &logging_loop_task, WIFI_CORE); +#endif + init_events(); init_CAN(); @@ -138,6 +148,18 @@ void loop() { #endif } +#ifdef LOG_CAN_TO_SD +void logging_loop(void* task_time_us) { + + init_logging_buffer(); + init_sdcard(); + + while (true) { + write_can_frame_to_sdcard(); + } +} +#endif + #ifdef WIFI void connectivity_loop(void* task_time_us) { @@ -192,13 +214,7 @@ void core_loop(void* task_time_us) { #endif // Input, Runs as fast as possible - receive_can_native(); // Receive CAN messages from native CAN port -#ifdef CANFD_ADDON - receive_canfd_addon(); // Receive CAN-FD messages. -#endif // CANFD_ADDON -#ifdef CAN_ADDON - receive_can_addon(); // Receive CAN messages on add-on MCP2515 chip -#endif // CAN_ADDON + receive_can(); // Receive CAN messages #ifdef RS485_INVERTER_SELECTED receive_RS485(); // Process serial2 RS485 interface #endif // RS485_INVERTER_SELECTED @@ -239,7 +255,7 @@ void core_loop(void* task_time_us) { START_TIME_MEASUREMENT(cantx); // Output - send_can(); // Send CAN messages to all components + transmit_can(); // Send CAN messages to all components END_TIME_MEASUREMENT_MAX(cantx, datalayer.system.status.time_cantx_us); END_TIME_MEASUREMENT_MAX(all, datalayer.system.status.core_task_10s_max_us); @@ -267,7 +283,7 @@ void core_loop(void* task_time_us) { } #endif // FUNCTION_TIME_MEASUREMENT if (check_pause_2s.elapsed()) { - emulator_pause_state_send_CAN_battery(); + emulator_pause_state_transmit_can_battery(); } vTaskDelayUntil(&xLastWakeTime, xFrequency); diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 2496c2ce..62eb7b7f 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -74,6 +74,7 @@ #endif //#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 LOG_CAN_TO_SD //Enable this line to log incoming/outgoing CAN & CAN-FD messages to SD card //#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting //#define CAN_ADDON //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 chip (Needed for some inverters / double battery) #define CRYSTAL_FREQUENCY_MHZ 8 //CAN_ADDON option, what is your MCP2515 add-on boards crystal frequency? diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index 7be73f22..43ccb23a 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -112,14 +112,14 @@ #include "SERIAL-LINK-RECEIVER-FROM-BATTERY.h" #endif -void receive_can_battery(CAN_frame rx_frame); +void handle_incoming_can_frame_battery(CAN_frame rx_frame); void update_values_battery(); -void send_can_battery(); +void transmit_can_battery(); void setup_battery(void); #ifdef DOUBLE_BATTERY void update_values_battery2(); -void receive_can_battery2(CAN_frame rx_frame); +void map_can_frame_to_variable_battery2(CAN_frame rx_frame); #endif #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index cf535f5f..77a2d1bd 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -502,7 +502,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer_extended.bmwi3.ST_cold_shutoff_valve = battery_status_cold_shutoff_valve; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x112: //BMS [10ms] Status Of High-Voltage Battery - 2 battery_awake = true; @@ -632,7 +632,7 @@ void receive_can_battery(CAN_frame rx_frame) { case 0x607: //BMS - responses to message requests on 0x615 if ((cmdState == CELL_VOLTAGE_CELLNO || cmdState == CELL_VOLTAGE_CELLNO_LAST) && (rx_frame.data.u8[0] == 0xF4)) { if (rx_frame.DLC == 6) { - transmit_can(&BMW_6F4_CELL_CONTINUE, can_config.battery); // tell battery to send the cellvoltage + transmit_can_frame(&BMW_6F4_CELL_CONTINUE, can_config.battery); // tell battery to send the cellvoltage } if (rx_frame.DLC == 8) { // We have the full value, map it datalayer.battery.status.cell_voltages_mV[current_cell_polled - 1] = @@ -645,7 +645,7 @@ void receive_can_battery(CAN_frame rx_frame) { while (count < rx_frame.DLC && next_data < 49) { message_data[next_data++] = rx_frame.data.u8[count++]; } - transmit_can(&BMW_6F1_CONTINUE, can_config.battery); // tell battery to send additional messages + transmit_can_frame(&BMW_6F1_CONTINUE, can_config.battery); // tell battery to send additional messages } else if (rx_frame.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 && ((rx_frame.data.u8[1] & 0xF0) == 0x20)) { @@ -681,7 +681,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x112: //BMS [10ms] Status Of High-Voltage Battery - 2 battery2_awake = true; @@ -820,7 +820,7 @@ void receive_can_battery2(CAN_frame rx_frame) { while (count2 < rx_frame.DLC && next_data < 49) { message_data[next_data++] = rx_frame.data.u8[count2++]; } - transmit_can(&BMW_6F1_CONTINUE, can_config.battery_double); + transmit_can_frame(&BMW_6F1_CONTINUE, can_config.battery_double); } else if (rx_frame.DLC > 3 && next_data > 0 && rx_frame.data.u8[0] == 0xf1 && ((rx_frame.data.u8[1] & 0xF0) == 0x20)) { @@ -856,7 +856,7 @@ void receive_can_battery2(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); if (battery_awake) { @@ -887,12 +887,12 @@ void send_can_battery() { if (datalayer.battery.status.bms_status == FAULT) { } //If battery is not in Fault mode, allow contactor to close by sending 10B else { - transmit_can(&BMW_10B, can_config.battery); + transmit_can_frame(&BMW_10B, can_config.battery); } #ifdef DOUBLE_BATTERY //If second battery is allowed to join in, also send 10B if (datalayer.system.status.battery2_allows_contactor_closing == true) { - transmit_can(&BMW_10B, can_config.battery_double); + transmit_can_frame(&BMW_10B, can_config.battery_double); } #endif } @@ -905,9 +905,9 @@ void send_can_battery() { alive_counter_100ms = increment_alive_counter(alive_counter_100ms); - transmit_can(&BMW_12F, can_config.battery); + transmit_can_frame(&BMW_12F, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_12F, can_config.battery_double); + transmit_can_frame(&BMW_12F, can_config.battery_double); #endif } // Send 200ms CAN Message @@ -919,9 +919,9 @@ void send_can_battery() { alive_counter_200ms = increment_alive_counter(alive_counter_200ms); - transmit_can(&BMW_19B, can_config.battery); + transmit_can_frame(&BMW_19B, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_19B, can_config.battery_double); + transmit_can_frame(&BMW_19B, can_config.battery_double); #endif } // Send 500ms CAN Message @@ -933,20 +933,20 @@ void send_can_battery() { alive_counter_500ms = increment_alive_counter(alive_counter_500ms); - transmit_can(&BMW_30B, can_config.battery); + transmit_can_frame(&BMW_30B, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_30B, can_config.battery_double); + transmit_can_frame(&BMW_30B, can_config.battery_double); #endif } // Send 640ms CAN Message if (currentMillis - previousMillis640 >= INTERVAL_640_MS) { previousMillis640 = currentMillis; - transmit_can(&BMW_512, can_config.battery); // Keep BMS alive - transmit_can(&BMW_5F8, can_config.battery); + transmit_can_frame(&BMW_512, can_config.battery); // Keep BMS alive + transmit_can_frame(&BMW_5F8, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_512, can_config.battery_double); - transmit_can(&BMW_5F8, can_config.battery_double); + transmit_can_frame(&BMW_512, can_config.battery_double); + transmit_can_frame(&BMW_5F8, can_config.battery_double); #endif } // Send 1000ms CAN Message @@ -973,39 +973,39 @@ void send_can_battery() { alive_counter_1000ms = increment_alive_counter(alive_counter_1000ms); - transmit_can(&BMW_3E8, can_config.battery); //Order comes from CAN logs - transmit_can(&BMW_328, can_config.battery); - transmit_can(&BMW_3F9, can_config.battery); - transmit_can(&BMW_2E2, can_config.battery); - transmit_can(&BMW_41D, can_config.battery); - transmit_can(&BMW_3D0, can_config.battery); - transmit_can(&BMW_3CA, can_config.battery); - transmit_can(&BMW_3A7, can_config.battery); - transmit_can(&BMW_2CA, can_config.battery); - transmit_can(&BMW_3FB, can_config.battery); - transmit_can(&BMW_418, can_config.battery); - transmit_can(&BMW_1D0, can_config.battery); - transmit_can(&BMW_3EC, can_config.battery); - transmit_can(&BMW_192, can_config.battery); - transmit_can(&BMW_13E, can_config.battery); - transmit_can(&BMW_433, can_config.battery); + transmit_can_frame(&BMW_3E8, can_config.battery); //Order comes from CAN logs + transmit_can_frame(&BMW_328, can_config.battery); + transmit_can_frame(&BMW_3F9, can_config.battery); + transmit_can_frame(&BMW_2E2, can_config.battery); + transmit_can_frame(&BMW_41D, can_config.battery); + transmit_can_frame(&BMW_3D0, can_config.battery); + transmit_can_frame(&BMW_3CA, can_config.battery); + transmit_can_frame(&BMW_3A7, can_config.battery); + transmit_can_frame(&BMW_2CA, can_config.battery); + transmit_can_frame(&BMW_3FB, can_config.battery); + transmit_can_frame(&BMW_418, can_config.battery); + transmit_can_frame(&BMW_1D0, can_config.battery); + transmit_can_frame(&BMW_3EC, can_config.battery); + transmit_can_frame(&BMW_192, can_config.battery); + transmit_can_frame(&BMW_13E, can_config.battery); + transmit_can_frame(&BMW_433, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_3E8, can_config.battery_double); - transmit_can(&BMW_328, can_config.battery_double); - transmit_can(&BMW_3F9, can_config.battery_double); - transmit_can(&BMW_2E2, can_config.battery_double); - transmit_can(&BMW_41D, can_config.battery_double); - transmit_can(&BMW_3D0, can_config.battery_double); - transmit_can(&BMW_3CA, can_config.battery_double); - transmit_can(&BMW_3A7, can_config.battery_double); - transmit_can(&BMW_2CA, can_config.battery_double); - transmit_can(&BMW_3FB, can_config.battery_double); - transmit_can(&BMW_418, can_config.battery_double); - transmit_can(&BMW_1D0, can_config.battery_double); - transmit_can(&BMW_3EC, can_config.battery_double); - transmit_can(&BMW_192, can_config.battery_double); - transmit_can(&BMW_13E, can_config.battery_double); - transmit_can(&BMW_433, can_config.battery_double); + transmit_can_frame(&BMW_3E8, can_config.battery_double); + transmit_can_frame(&BMW_328, can_config.battery_double); + transmit_can_frame(&BMW_3F9, can_config.battery_double); + transmit_can_frame(&BMW_2E2, can_config.battery_double); + transmit_can_frame(&BMW_41D, can_config.battery_double); + transmit_can_frame(&BMW_3D0, can_config.battery_double); + transmit_can_frame(&BMW_3CA, can_config.battery_double); + transmit_can_frame(&BMW_3A7, can_config.battery_double); + transmit_can_frame(&BMW_2CA, can_config.battery_double); + transmit_can_frame(&BMW_3FB, can_config.battery_double); + transmit_can_frame(&BMW_418, can_config.battery_double); + transmit_can_frame(&BMW_1D0, can_config.battery_double); + transmit_can_frame(&BMW_3EC, can_config.battery_double); + transmit_can_frame(&BMW_192, can_config.battery_double); + transmit_can_frame(&BMW_13E, can_config.battery_double); + transmit_can_frame(&BMW_433, can_config.battery_double); #endif BMW_433.data.u8[1] = 0x01; // First 433 message byte1 we send is unique, once we sent initial value send this @@ -1014,23 +1014,23 @@ void send_can_battery() { next_data = 0; switch (cmdState) { case SOC: - transmit_can(&BMW_6F1_CELL, can_config.battery); + transmit_can_frame(&BMW_6F1_CELL, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_6F1_CELL, can_config.battery_double); + transmit_can_frame(&BMW_6F1_CELL, can_config.battery_double); #endif cmdState = CELL_VOLTAGE_MINMAX; break; case CELL_VOLTAGE_MINMAX: - transmit_can(&BMW_6F1_SOH, can_config.battery); + transmit_can_frame(&BMW_6F1_SOH, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_6F1_SOH, can_config.battery_double); + transmit_can_frame(&BMW_6F1_SOH, can_config.battery_double); #endif cmdState = SOH; break; case SOH: - transmit_can(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery); + transmit_can_frame(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery_double); + transmit_can_frame(&BMW_6F1_CELL_VOLTAGE_AVG, can_config.battery_double); #endif cmdState = CELL_VOLTAGE_CELLNO; current_cell_polled = 0; @@ -1045,16 +1045,16 @@ void send_can_battery() { cmdState = CELL_VOLTAGE_CELLNO; BMW_6F4_CELL_VOLTAGE_CELLNO.data.u8[6] = current_cell_polled; - transmit_can(&BMW_6F4_CELL_VOLTAGE_CELLNO, can_config.battery); + transmit_can_frame(&BMW_6F4_CELL_VOLTAGE_CELLNO, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_6F4_CELL_VOLTAGE_CELLNO, can_config.battery_double); + transmit_can_frame(&BMW_6F4_CELL_VOLTAGE_CELLNO, can_config.battery_double); #endif } break; case CELL_VOLTAGE_CELLNO_LAST: - transmit_can(&BMW_6F1_SOC, can_config.battery); + transmit_can_frame(&BMW_6F1_SOC, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_6F1_SOC, can_config.battery_double); + transmit_can_frame(&BMW_6F1_SOC, can_config.battery_double); #endif cmdState = SOC; break; @@ -1067,25 +1067,25 @@ void send_can_battery() { BMW_3FC.data.u8[1] = ((BMW_3FC.data.u8[1] & 0xF0) + alive_counter_5000ms); BMW_3C5.data.u8[0] = ((BMW_3C5.data.u8[0] & 0xF0) + alive_counter_5000ms); - transmit_can(&BMW_3FC, can_config.battery); //Order comes from CAN logs - transmit_can(&BMW_3C5, can_config.battery); - transmit_can(&BMW_3A0, can_config.battery); - transmit_can(&BMW_592_0, can_config.battery); - transmit_can(&BMW_592_1, can_config.battery); + transmit_can_frame(&BMW_3FC, can_config.battery); //Order comes from CAN logs + transmit_can_frame(&BMW_3C5, can_config.battery); + transmit_can_frame(&BMW_3A0, can_config.battery); + transmit_can_frame(&BMW_592_0, can_config.battery); + transmit_can_frame(&BMW_592_1, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_3FC, can_config.battery_double); - transmit_can(&BMW_3C5, can_config.battery_double); - transmit_can(&BMW_3A0, can_config.battery_double); - transmit_can(&BMW_592_0, can_config.battery_double); - transmit_can(&BMW_592_1, can_config.battery_double); + transmit_can_frame(&BMW_3FC, can_config.battery_double); + transmit_can_frame(&BMW_3C5, can_config.battery_double); + transmit_can_frame(&BMW_3A0, can_config.battery_double); + transmit_can_frame(&BMW_592_0, can_config.battery_double); + transmit_can_frame(&BMW_592_1, can_config.battery_double); #endif alive_counter_5000ms = increment_alive_counter(alive_counter_5000ms); if (BMW_380_counter < 3) { - transmit_can(&BMW_380, can_config.battery); // This message stops after 3 times on startup + transmit_can_frame(&BMW_380, can_config.battery); // This message stops after 3 times on startup #ifdef DOUBLE_BATTERY - transmit_can(&BMW_380, can_config.battery_double); + transmit_can_frame(&BMW_380, can_config.battery_double); #endif BMW_380_counter++; } @@ -1094,13 +1094,13 @@ void send_can_battery() { if (currentMillis - previousMillis10000 >= INTERVAL_10_S) { previousMillis10000 = currentMillis; - transmit_can(&BMW_3E5, can_config.battery); //Order comes from CAN logs - transmit_can(&BMW_3E4, can_config.battery); - transmit_can(&BMW_37B, can_config.battery); + transmit_can_frame(&BMW_3E5, can_config.battery); //Order comes from CAN logs + transmit_can_frame(&BMW_3E4, can_config.battery); + transmit_can_frame(&BMW_37B, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&BMW_3E5, can_config.battery_double); - transmit_can(&BMW_3E4, can_config.battery_double); - transmit_can(&BMW_37B, can_config.battery_double); + transmit_can_frame(&BMW_3E5, can_config.battery_double); + transmit_can_frame(&BMW_3E4, can_config.battery_double); + transmit_can_frame(&BMW_37B, can_config.battery_double); #endif BMW_3E5.data.u8[0] = 0xFD; // First 3E5 message byte0 we send is unique, once we sent initial value send this diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 63228ea8..3aea2786 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -20,6 +20,6 @@ #define MAX_PACK_VOLTAGE_120AH 4030 // Charge stops if pack voltage exceeds this value #define MIN_PACK_VOLTAGE_120AH 2680 // Discharge stops if pack voltage exceeds this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/BMW-IX-BATTERY.cpp b/Software/src/battery/BMW-IX-BATTERY.cpp index ebecb6da..4296793f 100644 --- a/Software/src/battery/BMW-IX-BATTERY.cpp +++ b/Software/src/battery/BMW-IX-BATTERY.cpp @@ -516,7 +516,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV; } } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { battery_awake = true; switch (rx_frame.ID) { case 0x112: @@ -540,7 +540,7 @@ void receive_can_battery(CAN_frame rx_frame) { } //Frame has continued data - so request it - transmit_can(&BMWiX_6F4_CONTINUE_DATA, can_config.battery); + transmit_can_frame(&BMWiX_6F4_CONTINUE_DATA, can_config.battery); } if (rx_frame.DLC = 64 && rx_frame.data.u8[0] == 0xF4 && @@ -674,7 +674,7 @@ void receive_can_battery(CAN_frame rx_frame) { logging.println("Cell MinMax Qualifier Invalid - Requesting BMS Reset"); #endif //set_event(EVENT_BATTERY_VALUE_UNAVAILABLE, (millis())); //Eventually need new Info level event type - transmit_can(&BMWiX_6F4_REQUEST_HARD_RESET, can_config.battery); + transmit_can_frame(&BMWiX_6F4_REQUEST_HARD_RESET, can_config.battery); } else { //Only ingest values if they are not the 10V Error state min_cell_voltage = (rx_frame.data.u8[6] << 8 | rx_frame.data.u8[7]); max_cell_voltage = (rx_frame.data.u8[8] << 8 | rx_frame.data.u8[9]); @@ -724,7 +724,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); //if (battery_awake) { //We can always send CAN as the iX BMS will wake up on vehicle comms @@ -734,10 +734,10 @@ void send_can_battery() { //Loop through and send a different UDS request each cycle uds_req_id_counter = increment_uds_req_id_counter(uds_req_id_counter); - transmit_can(UDS_REQUESTS100MS[uds_req_id_counter], can_config.battery); + transmit_can_frame(UDS_REQUESTS100MS[uds_req_id_counter], can_config.battery); //Send SME Keep alive values 100ms - transmit_can(&BMWiX_510, can_config.battery); + transmit_can_frame(&BMWiX_510, can_config.battery); } // Send 200ms CAN Message if (currentMillis - previousMillis200 >= INTERVAL_200_MS) { @@ -745,16 +745,16 @@ void send_can_battery() { //Send SME Keep alive values 200ms BMWiX_0C0.data.u8[0] = increment_0C0_counter(BMWiX_0C0.data.u8[0]); //Keep Alive 1 - transmit_can(&BMWiX_0C0, can_config.battery); + transmit_can_frame(&BMWiX_0C0, can_config.battery); } // Send 1000ms CAN Message if (currentMillis - previousMillis1000 >= INTERVAL_1_S) { previousMillis1000 = currentMillis; //Send SME Keep alive values 1000ms - //Don't believe this is needed: transmit_can(&BMWiX_06D, can_config.battery); - //Don't believe this is needed: transmit_can(&BMWiX_2F1, can_config.battery); - //Don't believe this is needed: transmit_can(&BMWiX_439, can_config.battery); + //Don't believe this is needed: transmit_can_frame(&BMWiX_06D, can_config.battery); + //Don't believe this is needed: transmit_can_frame(&BMWiX_2F1, can_config.battery); + //Don't believe this is needed: transmit_can_frame(&BMWiX_439, can_config.battery); } // Send 5000ms CAN Message if (currentMillis - previousMillis5000 >= INTERVAL_5_S) { diff --git a/Software/src/battery/BMW-IX-BATTERY.h b/Software/src/battery/BMW-IX-BATTERY.h index a5336778..4c40b6ec 100644 --- a/Software/src/battery/BMW-IX-BATTERY.h +++ b/Software/src/battery/BMW-IX-BATTERY.h @@ -18,6 +18,6 @@ #define STALE_PERIOD_CONFIG \ 300000; //Number of milliseconds before critical values are classed as stale/stuck 300000 = 300 seconds void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/BOLT-AMPERA-BATTERY.cpp b/Software/src/battery/BOLT-AMPERA-BATTERY.cpp index 90d85eb5..e7c2e0f6 100644 --- a/Software/src/battery/BOLT-AMPERA-BATTERY.cpp +++ b/Software/src/battery/BOLT-AMPERA-BATTERY.cpp @@ -254,7 +254,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer_extended.boltampera.battery_current_7E4 = battery_current_7E4; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x200: datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; @@ -319,7 +319,7 @@ void receive_can_battery(CAN_frame rx_frame) { case 0x7EC: //When polling 7E4 BMS replies with 7EC ?? if (rx_frame.data.u8[0] == 0x10) { //"PID Header" - transmit_can(&BOLT_ACK_7E4, can_config.battery); + transmit_can_frame(&BOLT_ACK_7E4, can_config.battery); } //Frame 2 & 3 contains reply @@ -391,7 +391,7 @@ void receive_can_battery(CAN_frame rx_frame) { case 0x7EF: //When polling 7E7 BMS replies with 7EF if (rx_frame.data.u8[0] == 0x10) { //"PID Header" - transmit_can(&BOLT_ACK_7E7, can_config.battery); + transmit_can_frame(&BOLT_ACK_7E7, can_config.battery); } //Frame 2 & 3 contains reply @@ -730,7 +730,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); //Send 20ms message @@ -742,7 +742,7 @@ void send_can_battery() { clear_event(EVENT_CAN_OVERRUN); } previousMillis20ms = currentMillis; - transmit_can(&BOLT_778, can_config.battery); + transmit_can_frame(&BOLT_778, can_config.battery); } //Send 100ms message @@ -756,7 +756,7 @@ void send_can_battery() { BOLT_POLL_7E7.data.u8[2] = (uint8_t)((currentpoll_7E7 & 0xFF00) >> 8); BOLT_POLL_7E7.data.u8[3] = (uint8_t)(currentpoll_7E7 & 0x00FF); - transmit_can(&BOLT_POLL_7E7, can_config.battery); + transmit_can_frame(&BOLT_POLL_7E7, can_config.battery); } //Send 120ms message @@ -770,7 +770,7 @@ void send_can_battery() { BOLT_POLL_7E4.data.u8[2] = (uint8_t)((currentpoll_7E4 & 0xFF00) >> 8); BOLT_POLL_7E4.data.u8[3] = (uint8_t)(currentpoll_7E4 & 0x00FF); - transmit_can(&BOLT_POLL_7E4, can_config.battery); + transmit_can_frame(&BOLT_POLL_7E4, can_config.battery); } } diff --git a/Software/src/battery/BOLT-AMPERA-BATTERY.h b/Software/src/battery/BOLT-AMPERA-BATTERY.h index 7d877220..56a515fd 100644 --- a/Software/src/battery/BOLT-AMPERA-BATTERY.h +++ b/Software/src/battery/BOLT-AMPERA-BATTERY.h @@ -141,6 +141,6 @@ #define POLL_7E7_CELL_96 0x4240 void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/BYD-ATTO-3-BATTERY.cpp b/Software/src/battery/BYD-ATTO-3-BATTERY.cpp index f0f74da4..d1fb293f 100644 --- a/Software/src/battery/BYD-ATTO-3-BATTERY.cpp +++ b/Software/src/battery/BYD-ATTO-3-BATTERY.cpp @@ -162,7 +162,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer_extended.bydAtto3.voltage_polled = BMS_voltage; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { //Log values taken with 422V from battery case 0x244: //00,00,00,04,41,0F,20,8B - Static, values never changes between logs break; @@ -292,7 +292,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); //Send 50ms message if (currentMillis - previousMillis50 >= INTERVAL_50_MS) { @@ -334,9 +334,9 @@ void send_can_battery() { ATTO_3_12D.data.u8[6] = (0x0F | (frame6_counter << 4)); ATTO_3_12D.data.u8[7] = (0x09 | (frame7_counter << 4)); - transmit_can(&ATTO_3_12D, can_config.battery); + transmit_can_frame(&ATTO_3_12D, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&ATTO_3_12D, can_config.battery_double); + transmit_can_frame(&ATTO_3_12D, can_config.battery_double); #endif //DOUBLE_BATTERY } // Send 100ms CAN Message @@ -355,9 +355,9 @@ void send_can_battery() { ATTO_3_441.data.u8[7] = 0xF5; } - transmit_can(&ATTO_3_441, can_config.battery); + transmit_can_frame(&ATTO_3_441, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&ATTO_3_441, can_config.battery_double); + transmit_can_frame(&ATTO_3_441, can_config.battery_double); #endif //DOUBLE_BATTERY } // Send 500ms CAN Message @@ -402,9 +402,9 @@ void send_can_battery() { break; } - transmit_can(&ATTO_3_7E7_POLL, can_config.battery); + transmit_can_frame(&ATTO_3_7E7_POLL, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&ATTO_3_7E7_POLL, can_config.battery_double); + transmit_can_frame(&ATTO_3_7E7_POLL, can_config.battery_double); #endif //DOUBLE_BATTERY } } @@ -477,7 +477,7 @@ void update_values_battery2() { //This function maps all the values fetched via datalayer.battery2.status.temperature_max_dC = battery2_calc_max_temperature * 10; } -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { switch (rx_frame.ID) { //Log values taken with 422V from battery2 case 0x244: //00,00,00,04,41,0F,20,8B - Static, values never changes between logs break; diff --git a/Software/src/battery/BYD-ATTO-3-BATTERY.h b/Software/src/battery/BYD-ATTO-3-BATTERY.h index 1829ec6b..57f943ff 100644 --- a/Software/src/battery/BYD-ATTO-3-BATTERY.h +++ b/Software/src/battery/BYD-ATTO-3-BATTERY.h @@ -17,6 +17,6 @@ #define MIN_CELL_VOLTAGE_MV 2800 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/CELLPOWER-BMS.cpp b/Software/src/battery/CELLPOWER-BMS.cpp index 80c981c6..9a73ed40 100644 --- a/Software/src/battery/CELLPOWER-BMS.cpp +++ b/Software/src/battery/CELLPOWER-BMS.cpp @@ -213,7 +213,7 @@ void update_values_battery() { //TODO, shall we react on this? } } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x1A4: //PDO1_TX - 200ms @@ -316,7 +316,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 1s CAN Message if (currentMillis - previousMillis1s >= INTERVAL_1_S) { @@ -324,10 +324,10 @@ void send_can_battery() { previousMillis1s = currentMillis; /* - transmit_can(&CELLPOWER_18FF50E9, can_config.battery); - transmit_can(&CELLPOWER_18FF50E8, can_config.battery); - transmit_can(&CELLPOWER_18FF50E7, can_config.battery); - transmit_can(&CELLPOWER_18FF50E5, can_config.battery); + transmit_can_frame(&CELLPOWER_18FF50E9, can_config.battery); + transmit_can_frame(&CELLPOWER_18FF50E8, can_config.battery); + transmit_can_frame(&CELLPOWER_18FF50E7, can_config.battery); + transmit_can_frame(&CELLPOWER_18FF50E5, can_config.battery); */ } } diff --git a/Software/src/battery/CELLPOWER-BMS.h b/Software/src/battery/CELLPOWER-BMS.h index e1956b74..c5da0ece 100644 --- a/Software/src/battery/CELLPOWER-BMS.h +++ b/Software/src/battery/CELLPOWER-BMS.h @@ -14,6 +14,6 @@ #define NATIVECAN_250KBPS void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index a8faddfc..f99d61ed 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -367,7 +367,7 @@ inline void process_vehicle_vendor_ID(CAN_frame rx_frame) { ((rx_frame.data.u8[2] << 8) | rx_frame.data.u8[1]); //Actually more bytes, but not needed for our purpose } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { #ifdef CH_CAN_DEBUG logging.print(millis()); // Example printout, time, ID, length, data: 7553 1DB 8 FF C0 B9 EA 0 0 2 5D logging.print(" "); @@ -657,7 +657,7 @@ void update_evse_discharge_capabilities(CAN_frame& f) { CHADEMO_208.data.u8[7] = highByte(x208_evse_dischg_cap.lower_threshold_voltage); } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); @@ -693,8 +693,8 @@ void send_can_battery() { * that is the limiting factor. Therefore, we * can generally send as is without tweaks here. */ - transmit_can(&CHADEMO_108, can_config.battery); - transmit_can(&CHADEMO_109, can_config.battery); + transmit_can_frame(&CHADEMO_108, can_config.battery); + transmit_can_frame(&CHADEMO_109, can_config.battery); /* TODO for dynamic control: can send x118 with byte 6 bit 0 set to 0 for 1s (before flipping back to 1) as a way of giving vehicle a chance to update 101.1 and 101.2 * within 6 seconds of x118 toggle. @@ -703,9 +703,9 @@ void send_can_battery() { */ if (EVSE_mode == CHADEMO_DISCHARGE || EVSE_mode == CHADEMO_BIDIRECTIONAL) { - transmit_can(&CHADEMO_208, can_config.battery); + transmit_can_frame(&CHADEMO_208, can_config.battery); if (x201_received) { - transmit_can(&CHADEMO_209, can_config.battery); + transmit_can_frame(&CHADEMO_209, can_config.battery); x209_sent = true; } } @@ -717,7 +717,7 @@ void send_can_battery() { //FIXME REMOVE logging.println("REMOVE: proto 2.0"); #endif - transmit_can(&CHADEMO_118, can_config.battery); + transmit_can_frame(&CHADEMO_118, can_config.battery); } } } @@ -819,7 +819,7 @@ void handle_chademo_sequence() { case CHADEMO_INIT: /* Transient state while awaiting CAN from Vehicle. * Used for triggers/error handling elsewhere; - * State change to CHADEMO_NEGOTIATE occurs in receive_can_battery(..) + * State change to CHADEMO_NEGOTIATE occurs in handle_incoming_can_frame_battery(..) */ #ifdef DEBUG_LOG // logging.println("Awaiting initial vehicle CAN to trigger negotiation"); diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index fa6545a9..eacc2fd1 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -13,6 +13,6 @@ #define ISA_SHUNT void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/CHADEMO-SHUNTS.cpp b/Software/src/battery/CHADEMO-SHUNTS.cpp index 92c0da68..61ca170b 100644 --- a/Software/src/battery/CHADEMO-SHUNTS.cpp +++ b/Software/src/battery/CHADEMO-SHUNTS.cpp @@ -257,7 +257,7 @@ void ISA_initialize() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); delay(500); } @@ -282,7 +282,7 @@ void ISA_STOP() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_sendSTORE() { @@ -297,7 +297,7 @@ void ISA_sendSTORE() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_START() { @@ -312,7 +312,7 @@ void ISA_START() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_RESTART() { @@ -328,7 +328,7 @@ void ISA_RESTART() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_deFAULT() { @@ -347,7 +347,7 @@ void ISA_deFAULT() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); delay(500); ISA_START(); @@ -369,7 +369,7 @@ void ISA_initCurrent() { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); delay(500); ISA_sendSTORE(); @@ -394,7 +394,7 @@ void ISA_getCONFIG(uint8_t i) { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_getCAN_ID(uint8_t i) { @@ -414,7 +414,7 @@ void ISA_getCAN_ID(uint8_t i) { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } void ISA_getINFO(uint8_t i) { @@ -430,6 +430,6 @@ void ISA_getINFO(uint8_t i) { outframe.data.u8[6] = 0x00; outframe.data.u8[7] = 0x00; - transmit_can(&outframe, can_config.battery); + transmit_can_frame(&outframe, can_config.battery); } #endif diff --git a/Software/src/battery/CHADEMO-SHUNTS.h b/Software/src/battery/CHADEMO-SHUNTS.h index b4ebe3cb..9a40e53c 100644 --- a/Software/src/battery/CHADEMO-SHUNTS.h +++ b/Software/src/battery/CHADEMO-SHUNTS.h @@ -25,6 +25,6 @@ void ISA_getCONFIG(uint8_t i); void ISA_getCAN_ID(uint8_t i); void ISA_getINFO(uint8_t i); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/ECMP-BATTERY.cpp b/Software/src/battery/ECMP-BATTERY.cpp index afcfd98b..9bea886a 100644 --- a/Software/src/battery/ECMP-BATTERY.cpp +++ b/Software/src/battery/ECMP-BATTERY.cpp @@ -72,7 +72,7 @@ void update_values_battery() { datalayer.battery.status.cell_max_voltage_mV = max_cell_mv_value; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x125: @@ -288,7 +288,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 1s CAN Message if (currentMillis - previousMillis1000 >= INTERVAL_1_S) { diff --git a/Software/src/battery/ECMP-BATTERY.h b/Software/src/battery/ECMP-BATTERY.h index 14955bd6..a637ad8c 100644 --- a/Software/src/battery/ECMP-BATTERY.h +++ b/Software/src/battery/ECMP-BATTERY.h @@ -7,6 +7,6 @@ #define MAX_CELL_DEVIATION_MV 250 void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 64a75e6c..ddc63814 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -129,7 +129,7 @@ void update_values_battery() { //This function maps all the values fetched via #endif } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x374: //BMU message, 10ms - SOC datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; @@ -207,7 +207,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index 70bbf9fb..4191ab67 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -11,6 +11,6 @@ #define MIN_CELL_VOLTAGE_MV 2750 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp b/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp index 1292f0cc..618b32c8 100644 --- a/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp +++ b/Software/src/battery/JAGUAR-IPACE-BATTERY.cpp @@ -119,7 +119,7 @@ void update_values_battery() { #endif } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { // Do not log noisy startup messages - there are many ! if (rx_frame.ID == 0 && rx_frame.DLC == 8 && rx_frame.data.u8[0] == 0 && rx_frame.data.u8[1] == 0 && @@ -242,13 +242,13 @@ void receive_can_battery(CAN_frame rx_frame) { logging.println(""); } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); /* Send keep-alive every 200ms */ if (currentMillis - previousMillisKeepAlive >= INTERVAL_200_MS) { previousMillisKeepAlive = currentMillis; - transmit_can(&ipace_keep_alive, can_config.battery); + transmit_can_frame(&ipace_keep_alive, can_config.battery); return; } } diff --git a/Software/src/battery/JAGUAR-IPACE-BATTERY.h b/Software/src/battery/JAGUAR-IPACE-BATTERY.h index 6ff7827f..adf120a1 100644 --- a/Software/src/battery/JAGUAR-IPACE-BATTERY.h +++ b/Software/src/battery/JAGUAR-IPACE-BATTERY.h @@ -10,6 +10,6 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index 476459aa..70f9fd45 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -750,7 +750,7 @@ void update_values_battery() { //This function maps all the values fetched via #endif } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { startedUp = true; switch (rx_frame.ID) { case 0x055: @@ -811,7 +811,7 @@ void receive_can_battery(CAN_frame rx_frame) { // logging.println ("Send ack"); poll_data_pid = rx_frame.data.u8[4]; // if (rx_frame.data.u8[4] == poll_data_pid) { - transmit_can(&EGMP_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled + transmit_can_frame(&EGMP_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled // } break; case 0x21: //First frame in PID group @@ -982,7 +982,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); if (startedUp) { //Send Contactor closing message loop @@ -993,7 +993,7 @@ void send_can_battery() { if (currentMillis - startMillis >= messageDelays[messageIndex]) { // Transmit the current message - transmit_can(messages[messageIndex], can_config.battery); + transmit_can_frame(messages[messageIndex], can_config.battery); // Move to the next message messageIndex++; @@ -1019,7 +1019,7 @@ void send_can_battery() { EGMP_7E4.data.u8[3] = KIA_7E4_COUNTER; if (ok_start_polling_battery) { - transmit_can(&EGMP_7E4, can_config.battery); + transmit_can_frame(&EGMP_7E4, can_config.battery); } KIA_7E4_COUNTER++; diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.h b/Software/src/battery/KIA-E-GMP-BATTERY.h index 8c9f0db7..b0f3dccc 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.h +++ b/Software/src/battery/KIA-E-GMP-BATTERY.h @@ -18,6 +18,6 @@ extern ACAN2517FD canfd; #define RAMPDOWNPOWERALLOWED 10000 // What power we ramp down from towards top balancing void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index ea55a988..d14e78cd 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -220,7 +220,7 @@ void update_number_of_cells() { } } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x4DE: startedUp = true; @@ -268,17 +268,17 @@ void receive_can_battery(CAN_frame rx_frame) { } poll_data_pid++; if (poll_data_pid == 1) { - transmit_can(&KIA64_7E4_id1, can_config.battery); + transmit_can_frame(&KIA64_7E4_id1, can_config.battery); } else if (poll_data_pid == 2) { - transmit_can(&KIA64_7E4_id2, can_config.battery); + transmit_can_frame(&KIA64_7E4_id2, can_config.battery); } else if (poll_data_pid == 3) { - transmit_can(&KIA64_7E4_id3, can_config.battery); + transmit_can_frame(&KIA64_7E4_id3, can_config.battery); } else if (poll_data_pid == 4) { - transmit_can(&KIA64_7E4_id4, can_config.battery); + transmit_can_frame(&KIA64_7E4_id4, can_config.battery); } else if (poll_data_pid == 5) { - transmit_can(&KIA64_7E4_id5, can_config.battery); + transmit_can_frame(&KIA64_7E4_id5, can_config.battery); } else if (poll_data_pid == 6) { - transmit_can(&KIA64_7E4_id6, can_config.battery); + transmit_can_frame(&KIA64_7E4_id6, can_config.battery); } else if (poll_data_pid == 7) { } else if (poll_data_pid == 8) { } else if (poll_data_pid == 9) { @@ -289,7 +289,8 @@ void receive_can_battery(CAN_frame rx_frame) { switch (rx_frame.data.u8[0]) { case 0x10: //"PID Header" if (rx_frame.data.u8[4] == poll_data_pid) { - transmit_can(&KIA64_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled + transmit_can_frame(&KIA64_7E4_ack, + can_config.battery); //Send ack to BMS if the same frame is sent as polled } break; case 0x21: //First frame in PID group @@ -460,7 +461,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); if (!startedUp) { @@ -471,9 +472,9 @@ void send_can_battery() { if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { previousMillis100 = currentMillis; - transmit_can(&KIA64_553, can_config.battery); - transmit_can(&KIA64_57F, can_config.battery); - transmit_can(&KIA64_2A1, can_config.battery); + transmit_can_frame(&KIA64_553, can_config.battery); + transmit_can_frame(&KIA64_57F, can_config.battery); + transmit_can_frame(&KIA64_2A1, can_config.battery); } // Send 10ms CAN Message if (currentMillis - previousMillis10 >= INTERVAL_10_MS) { @@ -525,11 +526,11 @@ void send_can_battery() { break; } - transmit_can(&KIA_HYUNDAI_200, can_config.battery); + transmit_can_frame(&KIA_HYUNDAI_200, can_config.battery); - transmit_can(&KIA_HYUNDAI_523, can_config.battery); + transmit_can_frame(&KIA_HYUNDAI_523, can_config.battery); - transmit_can(&KIA_HYUNDAI_524, can_config.battery); + transmit_can_frame(&KIA_HYUNDAI_524, can_config.battery); } } diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index 8b1b3935..ff972508 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -14,6 +14,6 @@ void setup_battery(void); void update_number_of_cells(); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp index c37fcb15..71c4c88f 100644 --- a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp @@ -86,7 +86,7 @@ void update_values_battery() { //This function maps all the values fetched via } } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x5F1: @@ -108,7 +108,7 @@ void receive_can_battery(CAN_frame rx_frame) { switch (rx_frame.data.u8[0]) { case 0x10: //"PID Header" if (rx_frame.data.u8[3] == poll_data_pid) { - transmit_can(&KIA_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled + transmit_can_frame(&KIA_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled } break; case 0x21: //First frame in PID group @@ -230,7 +230,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 1000ms CAN Message @@ -243,15 +243,15 @@ void send_can_battery() { } poll_data_pid++; if (poll_data_pid == 1) { - transmit_can(&KIA_7E4_id1, can_config.battery); + transmit_can_frame(&KIA_7E4_id1, can_config.battery); } else if (poll_data_pid == 2) { - transmit_can(&KIA_7E4_id2, can_config.battery); + transmit_can_frame(&KIA_7E4_id2, can_config.battery); } else if (poll_data_pid == 3) { - transmit_can(&KIA_7E4_id3, can_config.battery); + transmit_can_frame(&KIA_7E4_id3, can_config.battery); } else if (poll_data_pid == 4) { } else if (poll_data_pid == 5) { - transmit_can(&KIA_7E4_id5, can_config.battery); + transmit_can_frame(&KIA_7E4_id5, can_config.battery); } } } diff --git a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h index 26b06d6f..5808723e 100644 --- a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h @@ -11,6 +11,6 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/MEB-BATTERY.cpp b/Software/src/battery/MEB-BATTERY.cpp index 643824ee..c73a6f51 100644 --- a/Software/src/battery/MEB-BATTERY.cpp +++ b/Software/src/battery/MEB-BATTERY.cpp @@ -618,7 +618,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer_extended.meb.rt_battery_unathorized = realtime_warning_battery_unathorized; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { last_can_msg_timestamp = millis(); if (first_can_msg == 0) first_can_msg = last_can_msg_timestamp; @@ -994,7 +994,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; case 0x1C42007B: // Reply from battery if (rx_frame.data.u8[0] == 0x10) { //PID header - transmit_can(&MEB_ACK_FRAME, can_config.battery); + transmit_can_frame(&MEB_ACK_FRAME, can_config.battery); } if (rx_frame.DLC == 8) { pid_reply = (rx_frame.data.u8[2] << 8) + rx_frame.data.u8[3]; @@ -1453,7 +1453,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 10ms CAN Message if (currentMillis > last_can_msg_timestamp + 500) { @@ -1474,7 +1474,7 @@ void send_can_battery() { counter_10ms = (counter_10ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. - transmit_can(&MEB_0FC, can_config.battery); // Required for contactor closing + transmit_can_frame(&MEB_0FC, can_config.battery); // Required for contactor closing } // Send 20ms CAN Message if (currentMillis - previousMillis20ms >= INTERVAL_20_MS) { @@ -1485,7 +1485,7 @@ void send_can_battery() { counter_20ms = (counter_20ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. - transmit_can(&MEB_0FD, can_config.battery); // Required for contactor closing + transmit_can_frame(&MEB_0FD, can_config.battery); // Required for contactor closing } // Send 40ms CAN Message if (currentMillis - previousMillis40ms >= INTERVAL_40_MS) { @@ -1502,7 +1502,7 @@ void send_can_battery() { } toggle = !toggle; // Flip the toggle each time the code block is executed - transmit_can(&MEB_040, can_config.battery); // Airbag message - Needed for contactor closing + transmit_can_frame(&MEB_040, can_config.battery); // Airbag message - Needed for contactor closing } // Send 50ms CAN Message if (currentMillis - previousMillis50ms >= INTERVAL_50_MS) { @@ -1518,7 +1518,7 @@ void send_can_battery() { MEB_0C0.data.u8[0] = vw_crc_calc(MEB_0C0.data.u8, MEB_0C0.DLC, MEB_0C0.ID); counter_50ms = (counter_50ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. - transmit_can(&MEB_0C0, can_config.battery); // Needed for contactor closing + transmit_can_frame(&MEB_0C0, can_config.battery); // Needed for contactor closing } // Send 100ms CAN Message if (currentMillis - previousMillis100ms >= INTERVAL_100_MS) { @@ -1560,11 +1560,11 @@ void send_can_battery() { MEB_14C.data.u8[0] = vw_crc_calc(MEB_14C.data.u8, MEB_14C.DLC, MEB_14C.ID); counter_100ms = (counter_100ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. - transmit_can(&MEB_503, can_config.battery); - transmit_can(&MEB_272, can_config.battery); - transmit_can(&MEB_3C0, can_config.battery); - transmit_can(&MEB_3BE, can_config.battery); - transmit_can(&MEB_14C, can_config.battery); + transmit_can_frame(&MEB_503, can_config.battery); + transmit_can_frame(&MEB_272, can_config.battery); + transmit_can_frame(&MEB_3C0, can_config.battery); + transmit_can_frame(&MEB_3BE, can_config.battery); + transmit_can_frame(&MEB_14C, can_config.battery); } //Send 200ms message if (currentMillis - previousMillis200ms >= INTERVAL_200_MS) { @@ -1574,11 +1574,11 @@ void send_can_battery() { //TODO: MEB_1B0000B9 & MEB_1B000010 & MEB_1B000046 has CAN sleep commands, static OK? - transmit_can(&MEB_5E1, can_config.battery); - transmit_can(&MEB_153, can_config.battery); - transmit_can(&MEB_1B0000B9, can_config.battery); - transmit_can(&MEB_1B000010, can_config.battery); - transmit_can(&MEB_1B000046, can_config.battery); + transmit_can_frame(&MEB_5E1, can_config.battery); + transmit_can_frame(&MEB_153, can_config.battery); + transmit_can_frame(&MEB_1B0000B9, can_config.battery); + transmit_can_frame(&MEB_1B000010, can_config.battery); + transmit_can_frame(&MEB_1B000046, can_config.battery); switch (poll_pid) { case PID_SOC: @@ -2076,7 +2076,7 @@ void send_can_battery() { break; } if (first_can_msg > 0 && currentMillis > first_can_msg + 2000) { - transmit_can(&MEB_POLLING_FRAME, can_config.battery); + transmit_can_frame(&MEB_POLLING_FRAME, can_config.battery); } } @@ -2084,11 +2084,11 @@ void send_can_battery() { if (currentMillis - previousMillis500ms >= INTERVAL_500_MS) { previousMillis500ms = currentMillis; - transmit_can(&MEB_16A954B4, can_config.battery); //eTM, Cooling valves and pumps for BMS - transmit_can(&MEB_569, can_config.battery); // Battery heating requests - transmit_can(&MEB_1A55552B, can_config.battery); //Climate, heatpump and priorities - transmit_can(&MEB_1A555548, can_config.battery); //ORU, OTA update message for reserving battery - transmit_can(&MEB_16A954FB, can_config.battery); //Climate, request to BMS for starting preconditioning + transmit_can_frame(&MEB_16A954B4, can_config.battery); //eTM, Cooling valves and pumps for BMS + transmit_can_frame(&MEB_569, can_config.battery); // Battery heating requests + transmit_can_frame(&MEB_1A55552B, can_config.battery); //Climate, heatpump and priorities + transmit_can_frame(&MEB_1A555548, can_config.battery); //ORU, OTA update message for reserving battery + transmit_can_frame(&MEB_16A954FB, can_config.battery); //Climate, request to BMS for starting preconditioning } //Send 1s CANFD message @@ -2109,12 +2109,12 @@ void send_can_battery() { MEB_6B2.data.u8[7] = (uint8_t)((seconds & 0x3E) >> 1); seconds = (seconds + 1) % 60; - counter_1000ms = (counter_1000ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. - transmit_can(&MEB_6B2, can_config.battery); // Diagnostics - Needed for contactor closing - transmit_can(&MEB_641, can_config.battery); // Motor - OBD - transmit_can(&MEB_5F5, can_config.battery); // Loading profile - transmit_can(&MEB_585, can_config.battery); // Systeminfo - transmit_can(&MEB_1A5555A6, can_config.battery); // Temperature QBit + counter_1000ms = (counter_1000ms + 1) % 16; //Goes from 0-1-2-3...15-0-1-2-3.. + transmit_can_frame(&MEB_6B2, can_config.battery); // Diagnostics - Needed for contactor closing + transmit_can_frame(&MEB_641, can_config.battery); // Motor - OBD + transmit_can_frame(&MEB_5F5, can_config.battery); // Loading profile + transmit_can_frame(&MEB_585, can_config.battery); // Systeminfo + transmit_can_frame(&MEB_1A5555A6, can_config.battery); // Temperature QBit } } diff --git a/Software/src/battery/MEB-BATTERY.h b/Software/src/battery/MEB-BATTERY.h index 3648dec4..00be49b5 100644 --- a/Software/src/battery/MEB-BATTERY.h +++ b/Software/src/battery/MEB-BATTERY.h @@ -133,6 +133,6 @@ #define PID_CELLVOLTAGE_CELL_108 0x1EAB void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/MG-5-BATTERY.cpp b/Software/src/battery/MG-5-BATTERY.cpp index 006634ab..07c54a7d 100644 --- a/Software/src/battery/MG-5-BATTERY.cpp +++ b/Software/src/battery/MG-5-BATTERY.cpp @@ -44,7 +44,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer.battery.status.temperature_max_dC; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x171: //Following messages were detected on a MG5 battery BMS @@ -108,7 +108,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); //Send 10ms message if (currentMillis - previousMillis10 >= INTERVAL_10_MS) { @@ -120,13 +120,13 @@ void send_can_battery() { } previousMillis10 = currentMillis; - transmit_can(&MG_5_100, can_config.battery); + transmit_can_frame(&MG_5_100, can_config.battery); } // Send 100ms CAN Message if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { previousMillis100 = currentMillis; - //transmit_can(&MG_5_100, can_config.battery); + //transmit_can_frame(&MG_5_100, can_config.battery); } } diff --git a/Software/src/battery/MG-5-BATTERY.h b/Software/src/battery/MG-5-BATTERY.h index 4efd3735..415ed0dc 100644 --- a/Software/src/battery/MG-5-BATTERY.h +++ b/Software/src/battery/MG-5-BATTERY.h @@ -11,6 +11,6 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index b4b94b65..6e693774 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -502,7 +502,7 @@ void update_values_battery2() { // Handle the values coming in from battery #2 } } } -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x1DB: if (is_message_corrupt(rx_frame)) { @@ -612,7 +612,7 @@ void receive_can_battery2(CAN_frame rx_frame) { //First check which group data we are getting if (rx_frame.data.u8[0] == 0x10) { //First message of a group battery2_group_7bb = rx_frame.data.u8[3]; - transmit_can(&LEAF_NEXT_LINE_REQUEST, can_config.battery_double); + transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery_double); } if (battery2_group_7bb == 1) //High precision SOC, Current, voltages etc. @@ -740,7 +740,7 @@ void receive_can_battery2(CAN_frame rx_frame) { } #endif // DOUBLE_BATTERY -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x1DB: if (is_message_corrupt(rx_frame)) { @@ -870,7 +870,7 @@ void receive_can_battery(CAN_frame rx_frame) { if (rx_frame.data.u8[0] == 0x10) { //First message of a group group_7bb = rx_frame.data.u8[3]; - transmit_can(&LEAF_NEXT_LINE_REQUEST, can_config.battery); //Request the next frame for the group + transmit_can_frame(&LEAF_NEXT_LINE_REQUEST, can_config.battery); //Request the next frame for the group } if (group_7bb == 1) //High precision SOC, Current, voltages etc. @@ -1056,7 +1056,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { if (battery_can_alive) { unsigned long currentMillis = millis(); @@ -1089,9 +1089,9 @@ void send_can_battery() { LEAF_1D4.data.u8[7] = 0xDE; break; } - transmit_can(&LEAF_1D4, can_config.battery); + transmit_can_frame(&LEAF_1D4, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&LEAF_1D4, can_config.battery_double); + transmit_can_frame(&LEAF_1D4, can_config.battery_double); #endif // DOUBLE_BATTERY switch (mprun10r) { @@ -1185,9 +1185,9 @@ void send_can_battery() { //Only send this message when NISSANLEAF_CHARGER is not defined (otherwise it will collide!) #ifndef NISSANLEAF_CHARGER - transmit_can(&LEAF_1F2, can_config.battery); + transmit_can_frame(&LEAF_1F2, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&LEAF_1F2, can_config.battery_double); + transmit_can_frame(&LEAF_1F2, can_config.battery_double); #endif // DOUBLE_BATTERY #endif @@ -1212,9 +1212,9 @@ void send_can_battery() { } // VCM message, containing info if battery should sleep or stay awake - transmit_can(&LEAF_50B, can_config.battery); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1 + transmit_can_frame(&LEAF_50B, can_config.battery); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1 #ifdef DOUBLE_BATTERY - transmit_can(&LEAF_50B, can_config.battery_double); + transmit_can_frame(&LEAF_50B, can_config.battery_double); #endif // DOUBLE_BATTERY LEAF_50C.data.u8[3] = mprun100; @@ -1236,9 +1236,9 @@ void send_can_battery() { LEAF_50C.data.u8[5] = 0x9A; break; } - transmit_can(&LEAF_50C, can_config.battery); + transmit_can_frame(&LEAF_50C, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&LEAF_50C, can_config.battery_double); + transmit_can_frame(&LEAF_50C, can_config.battery_double); #endif // DOUBLE_BATTERY mprun100 = (mprun100 + 1) % 4; // mprun100 cycles between 0-1-2-3-0-1... @@ -1255,9 +1255,9 @@ void send_can_battery() { PIDindex = (PIDindex + 1) % 6; // 6 = amount of elements in the PIDgroups[] LEAF_GROUP_REQUEST.data.u8[2] = PIDgroups[PIDindex]; - transmit_can(&LEAF_GROUP_REQUEST, can_config.battery); + transmit_can_frame(&LEAF_GROUP_REQUEST, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&LEAF_GROUP_REQUEST, can_config.battery_double); + transmit_can_frame(&LEAF_GROUP_REQUEST, can_config.battery_double); #endif // DOUBLE_BATTERY } @@ -1320,19 +1320,19 @@ void clearSOH(void) { break; case 1: // Set CAN_PROCESS_FLAG to 0xC0 LEAF_CLEAR_SOH.data = {0x02, 0x10, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // BMS should reply 02 50 C0 FF FF FF FF FF stateMachineClearSOH = 2; break; case 2: // Set something ? LEAF_CLEAR_SOH.data = {0x02, 0x3E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // BMS should reply 7E FF FF FF FF FF FF stateMachineClearSOH = 3; break; case 3: // Request challenge to solve LEAF_CLEAR_SOH.data = {0x02, 0x27, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // BMS should reply with (challenge) 06 67 65 (02 DD 86 43) FF stateMachineClearSOH = 4; break; @@ -1340,34 +1340,34 @@ void clearSOH(void) { decodeChallengeData(incomingChallenge, solvedChallenge); LEAF_CLEAR_SOH.data = { 0x10, 0x0A, 0x27, 0x66, solvedChallenge[0], solvedChallenge[1], solvedChallenge[2], solvedChallenge[3]}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // BMS should reply 7BB 8 30 01 00 FF FF FF FF FF // Proceed with more data (PID ACK) stateMachineClearSOH = 5; break; case 5: // Reply with even more decoded challenge data LEAF_CLEAR_SOH.data = { 0x21, solvedChallenge[4], solvedChallenge[5], solvedChallenge[6], solvedChallenge[7], 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // BMS should reply 02 67 66 FF FF FF FF FF // Thank you for the data stateMachineClearSOH = 6; break; case 6: // Check if solved data was OK LEAF_CLEAR_SOH.data = {0x03, 0x31, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); //7BB 8 03 71 03 01 FF FF FF FF // If all is well, BMS replies with 03 71 03 01. //Incase you sent wrong challenge, you get 03 7f 31 12 stateMachineClearSOH = 7; break; case 7: // Reset SOH% request LEAF_CLEAR_SOH.data = {0x03, 0x31, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); //7BB 8 03 71 03 02 FF FF FF FF // 03 71 03 02 means that BMS accepted command. //7BB 03 7f 31 12 means your challenge was wrong, so command ignored stateMachineClearSOH = 8; break; case 8: // Please proceed with resetting SOH LEAF_CLEAR_SOH.data = {0x02, 0x10, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00}; - transmit_can(&LEAF_CLEAR_SOH, can_config.battery); + transmit_can_frame(&LEAF_CLEAR_SOH, can_config.battery); // 7BB 8 02 50 81 FF FF FF FF FF // SOH reset OK stateMachineClearSOH = 255; break; diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index 245f0f39..f5e7adcd 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -13,7 +13,7 @@ uint16_t Temp_fromRAW_to_F(uint16_t temperature); bool is_message_corrupt(CAN_frame rx_frame); void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); void clearSOH(void); //Cryptographic functions void decodeChallengeData(unsigned int SeedInput, unsigned char* Crypt_Output_Buffer); diff --git a/Software/src/battery/PYLON-BATTERY.cpp b/Software/src/battery/PYLON-BATTERY.cpp index ec61901d..86ea9c0f 100644 --- a/Software/src/battery/PYLON-BATTERY.cpp +++ b/Software/src/battery/PYLON-BATTERY.cpp @@ -80,7 +80,7 @@ void update_values_battery() { datalayer.battery.info.min_design_voltage_dV = discharge_cutoff_voltage; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x7310: @@ -156,17 +156,17 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 1s CAN Message if (currentMillis - previousMillis1000 >= INTERVAL_1_S) { previousMillis1000 = currentMillis; - transmit_can(&PYLON_3010, can_config.battery); // Heartbeat - transmit_can(&PYLON_4200, can_config.battery); // Ensemble OR System equipment info, depends on frame0 - transmit_can(&PYLON_8200, can_config.battery); // Control device quit sleep status - transmit_can(&PYLON_8210, can_config.battery); // Charge command + transmit_can_frame(&PYLON_3010, can_config.battery); // Heartbeat + transmit_can_frame(&PYLON_4200, can_config.battery); // Ensemble OR System equipment info, depends on frame0 + transmit_can_frame(&PYLON_8200, can_config.battery); // Control device quit sleep status + transmit_can_frame(&PYLON_8210, can_config.battery); // Charge command if (ensemble_info_ack) { PYLON_4200.data.u8[0] = 0x00; //Request system equipment info diff --git a/Software/src/battery/PYLON-BATTERY.h b/Software/src/battery/PYLON-BATTERY.h index 98588c69..8d17c047 100644 --- a/Software/src/battery/PYLON-BATTERY.h +++ b/Software/src/battery/PYLON-BATTERY.h @@ -13,6 +13,6 @@ #define MAX_CELL_DEVIATION_MV 500 void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.cpp b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.cpp index 4ca3a330..3ff1325e 100644 --- a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.cpp +++ b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.cpp @@ -180,7 +180,7 @@ void update_values_battery() { datalayer.battery.info.min_design_voltage_dV = DischargeVoltageLimit * 10; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x080: // 15ms @@ -301,14 +301,14 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 50ms CAN Message if (currentMillis - previousMillis50ms >= INTERVAL_50_MS) { previousMillis50ms = currentMillis; - transmit_can(&RANGE_ROVER_18B, can_config.battery); + transmit_can_frame(&RANGE_ROVER_18B, can_config.battery); } } diff --git a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h index c4cdcf07..9dfcaf06 100644 --- a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h +++ b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h @@ -13,6 +13,6 @@ #define MAX_CELL_DEVIATION_MV 500 //TODO: Configure void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 6b3e35c3..4fa4a6e4 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -137,7 +137,7 @@ void update_values_battery() { //This function maps all the values fetched via #endif } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x155: //BMS1 @@ -210,12 +210,12 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message (for 2.4s, then pause 10s) if ((currentMillis - previousMillis100) >= (INTERVAL_100_MS + GVL_pause)) { previousMillis100 = currentMillis; - transmit_can(&KANGOO_423, can_config.battery); + transmit_can_frame(&KANGOO_423, can_config.battery); GVI_Pollcounter++; GVL_pause = 0; if (GVI_Pollcounter >= 24) { @@ -227,9 +227,9 @@ void send_can_battery() { if (currentMillis - previousMillis1000 >= INTERVAL_1_S) { previousMillis1000 = currentMillis; if (GVB_79B_Continue) - transmit_can(&KANGOO_79B_Continue, can_config.battery); + transmit_can_frame(&KANGOO_79B_Continue, can_config.battery); } else { - transmit_can(&KANGOO_79B, can_config.battery); + transmit_can_frame(&KANGOO_79B, can_config.battery); } } diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index 6afb2335..25f739c6 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -12,6 +12,6 @@ #define MAX_CHARGE_POWER_W 5000 // Battery can be charged with this amount of power void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/RENAULT-TWIZY.cpp b/Software/src/battery/RENAULT-TWIZY.cpp index b0140eff..b6c746f2 100644 --- a/Software/src/battery/RENAULT-TWIZY.cpp +++ b/Software/src/battery/RENAULT-TWIZY.cpp @@ -65,7 +65,7 @@ void update_values_battery() { max_value(cell_temperatures_dC, sizeof(cell_temperatures_dC) / sizeof(*cell_temperatures_dC)); } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x155: @@ -127,7 +127,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { // we do not need to send anything to the battery for now } diff --git a/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.cpp index 22035cc5..28a69df6 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.cpp @@ -135,7 +135,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer.battery.status.voltage_dV = static_cast((calculated_total_pack_voltage_mV / 100)); // mV to dV } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x155: //10ms - Charging power, current and SOC datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; @@ -195,7 +195,7 @@ void receive_can_battery(CAN_frame rx_frame) { switch (frame0) { case 0x10: //PID HEADER, datarow 0 requested_poll = rx_frame.data.u8[3]; - transmit_can(&ZOE_ACK_79B, can_config.battery); + transmit_can_frame(&ZOE_ACK_79B, can_config.battery); if (requested_poll == GROUP1_CELLVOLTAGES_1_POLL) { cellvoltages[0] = (rx_frame.data.u8[4] << 8) | rx_frame.data.u8[5]; @@ -486,7 +486,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { @@ -495,7 +495,7 @@ void send_can_battery() { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100)); } previousMillis100 = currentMillis; - transmit_can(&ZOE_423, can_config.battery); + transmit_can_frame(&ZOE_423, can_config.battery); if ((counter_423 / 5) % 2 == 0) { // Alternate every 5 messages between these two ZOE_423.data.u8[4] = 0xB2; @@ -534,7 +534,7 @@ void send_can_battery() { ZOE_POLL_79B.data.u8[2] = current_poll; - transmit_can(&ZOE_POLL_79B, can_config.battery); + transmit_can_frame(&ZOE_POLL_79B, can_config.battery); } } diff --git a/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.h b/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.h index 81c7c2cc..1a3968bf 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.h @@ -11,6 +11,6 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp index 9c35d7da..ec0e8e8d 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp @@ -218,7 +218,7 @@ void update_values_battery() { //This function maps all the values fetched via datalayer_extended.zoePH2.battery_soc_max = battery_soc_max; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x18DAF1DB: // LBC Reply from active polling @@ -358,7 +358,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 200ms CAN Message if (currentMillis - previousMillis200 >= INTERVAL_200_MS) { @@ -375,8 +375,8 @@ void send_can_battery() { ZOE_POLL_18DADBF1.data.u8[2] = (uint8_t)((currentpoll & 0xFF00) >> 8); ZOE_POLL_18DADBF1.data.u8[3] = (uint8_t)(currentpoll & 0x00FF); - transmit_can(&ZOE_POLL_18DADBF1, can_config.battery); - transmit_can(&ZOE_373, can_config.battery); + transmit_can_frame(&ZOE_POLL_18DADBF1, can_config.battery); + transmit_can_frame(&ZOE_373, can_config.battery); } } diff --git a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.h b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.h index c75bb774..cfcc65d7 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.h @@ -10,7 +10,7 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #define POLL_SOC 0x9001 #define POLL_USABLE_SOC 0x9002 diff --git a/Software/src/battery/RJXZS-BMS.cpp b/Software/src/battery/RJXZS-BMS.cpp index c59a99f1..345e8eae 100644 --- a/Software/src/battery/RJXZS-BMS.cpp +++ b/Software/src/battery/RJXZS-BMS.cpp @@ -158,7 +158,7 @@ void update_values_battery() { datalayer.battery.status.cell_min_voltage_mV = minimum_cell_voltage; } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { /* // All CAN messages recieved will be logged via serial @@ -550,7 +550,7 @@ void receive_can_battery(CAN_frame rx_frame) { } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 10s CAN Message if (currentMillis - previousMillis10s >= INTERVAL_10_S) { @@ -563,8 +563,8 @@ void send_can_battery() { } if (!setup_completed) { - transmit_can(&RJXZS_10, can_config.battery); // Communication connected flag - transmit_can(&RJXZS_1C, can_config.battery); // CAN OK + transmit_can_frame(&RJXZS_10, can_config.battery); // Communication connected flag + transmit_can_frame(&RJXZS_1C, can_config.battery); // CAN OK } } } diff --git a/Software/src/battery/RJXZS-BMS.h b/Software/src/battery/RJXZS-BMS.h index f42af734..a6067039 100644 --- a/Software/src/battery/RJXZS-BMS.h +++ b/Software/src/battery/RJXZS-BMS.h @@ -19,6 +19,6 @@ #define NATIVECAN_250KBPS void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index 766a9094..21f61816 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -116,7 +116,7 @@ void update_values_battery() { //This function maps all the values fetched via } } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x1FF: datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; @@ -171,7 +171,8 @@ void receive_can_battery(CAN_frame rx_frame) { switch (rx_frame.data.u8[0]) { case 0x10: //"PID Header" if (rx_frame.data.u8[4] == poll_data_pid) { - transmit_can(&SANTAFE_7E4_ack, can_config.battery); //Send ack to BMS if the same frame is sent as polled + transmit_can_frame(&SANTAFE_7E4_ack, + can_config.battery); //Send ack to BMS if the same frame is sent as polled } break; case 0x21: //First frame in PID group @@ -332,7 +333,7 @@ void receive_can_battery(CAN_frame rx_frame) { break; } } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); //Send 10ms message @@ -351,13 +352,13 @@ void send_can_battery() { SANTAFE_200.data.u8[7] = checksum_200; - transmit_can(&SANTAFE_200, can_config.battery); - transmit_can(&SANTAFE_2A1, can_config.battery); - transmit_can(&SANTAFE_2F0, can_config.battery); + transmit_can_frame(&SANTAFE_200, can_config.battery); + transmit_can_frame(&SANTAFE_2A1, can_config.battery); + transmit_can_frame(&SANTAFE_2F0, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&SANTAFE_200, can_config.battery_double); - transmit_can(&SANTAFE_2A1, can_config.battery_double); - transmit_can(&SANTAFE_2F0, can_config.battery_double); + transmit_can_frame(&SANTAFE_200, can_config.battery_double); + transmit_can_frame(&SANTAFE_2A1, can_config.battery_double); + transmit_can_frame(&SANTAFE_2F0, can_config.battery_double); #endif //DOUBLE_BATTERY counter_200++; @@ -370,9 +371,9 @@ void send_can_battery() { if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { previousMillis100 = currentMillis; - transmit_can(&SANTAFE_523, can_config.battery); + transmit_can_frame(&SANTAFE_523, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&SANTAFE_523, can_config.battery_double); + transmit_can_frame(&SANTAFE_523, can_config.battery_double); #endif //DOUBLE_BATTERY } @@ -383,9 +384,9 @@ void send_can_battery() { // PID data is polled after last message sent from battery: poll_data_pid = (poll_data_pid % 5) + 1; SANTAFE_7E4_poll.data.u8[3] = (uint8_t)poll_data_pid; - transmit_can(&SANTAFE_7E4_poll, can_config.battery); + transmit_can_frame(&SANTAFE_7E4_poll, can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&SANTAFE_7E4_poll, can_config.battery_double); + transmit_can_frame(&SANTAFE_7E4_poll, can_config.battery_double); #endif //DOUBLE_BATTERY } } @@ -425,7 +426,7 @@ void update_values_battery2() { //This function maps all the values fetched via } } -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x1FF: datalayer.battery2.status.CAN_battery_still_alive = CAN_STILL_ALIVE; @@ -480,8 +481,8 @@ void receive_can_battery2(CAN_frame rx_frame) { switch (rx_frame.data.u8[0]) { case 0x10: //"PID Header" if (rx_frame.data.u8[4] == poll_data_pid) { - transmit_can(&SANTAFE_7E4_ack, - can_config.battery_double); //Send ack to BMS if the same frame is sent as polled + transmit_can_frame(&SANTAFE_7E4_ack, + can_config.battery_double); //Send ack to BMS if the same frame is sent as polled } break; case 0x21: //First frame in PID group diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h index fb4774a5..092a200e 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h @@ -12,6 +12,6 @@ uint8_t CalculateCRC8(CAN_frame rx_frame); void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp index 349f4d82..35a7104c 100644 --- a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp +++ b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp @@ -224,7 +224,7 @@ void setup_battery(void) { } // Needed to make the compiler happy void update_values_battery() {} -void send_can_battery() {} -void receive_can_battery(CAN_frame rx_frame) {} +void transmit_can_battery() {} +void handle_incoming_can_frame_battery(CAN_frame rx_frame) {} #endif diff --git a/Software/src/battery/TESLA-BATTERY.cpp b/Software/src/battery/TESLA-BATTERY.cpp index 4e17068e..c69fc8d4 100644 --- a/Software/src/battery/TESLA-BATTERY.cpp +++ b/Software/src/battery/TESLA-BATTERY.cpp @@ -1202,7 +1202,7 @@ void update_values_battery() { //This function maps all the values fetched via #endif //DEBUG_LOG } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { static uint8_t mux = 0; static uint16_t temp = 0; @@ -1862,7 +1862,7 @@ void receive_can_battery(CAN_frame rx_frame) { #ifdef DOUBLE_BATTERY //Need to update battery2 -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { static uint8_t mux = 0; static uint16_t temp = 0; @@ -2676,7 +2676,7 @@ int index_1CF = 0; int index_118 = 0; #endif //defined(TESLA_MODEL_SX_BATTERY) || defined(EXP_TESLA_BMS_DIGITAL_HVIL) -void send_can_battery() { +void transmit_can_battery() { /*From bielec: My fist 221 message, to close the contactors is 0x41, 0x11, 0x01, 0x00, 0x00, 0x00, 0x20, 0x96 and then, to cause "hv_up_for_drive" I send an additional 221 message 0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA so two 221 messages are being continuously transmitted. When I want to shut down, I stop the second message and only send @@ -2691,10 +2691,10 @@ the first, for a few cycles, then stop all messages which causes the contactor #if defined(TESLA_MODEL_SX_BATTERY) || defined(EXP_TESLA_BMS_DIGITAL_HVIL) if ((datalayer.system.status.inverter_allows_contactor_closing) && (datalayer.battery.status.bms_status != FAULT)) { if (currentMillis - lastSend1CF >= 10) { - transmit_can(&can_msg_1CF[index_1CF], can_config.battery); + transmit_can_frame(&can_msg_1CF[index_1CF], can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&can_msg_1CF[index_1CF], can_config.battery_double); + transmit_can_frame(&can_msg_1CF[index_1CF], can_config.battery_double); #endif // DOUBLE_BATTERY index_1CF = (index_1CF + 1) % 8; @@ -2702,9 +2702,9 @@ the first, for a few cycles, then stop all messages which causes the contactor } if (currentMillis - lastSend118 >= 10) { - transmit_can(&can_msg_118[index_118], can_config.battery); + transmit_can_frame(&can_msg_118[index_118], can_config.battery); #ifdef DOUBLE_BATTERY - transmit_can(&can_msg_1CF[index_1CF], can_config.battery_double); + transmit_can_frame(&can_msg_1CF[index_1CF], can_config.battery_double); #endif //DOUBLE_BATTERY index_118 = (index_118 + 1) % 16; @@ -2729,21 +2729,21 @@ the first, for a few cycles, then stop all messages which causes the contactor if ((datalayer.system.status.inverter_allows_contactor_closing == true) && (datalayer.battery.status.bms_status != FAULT)) { sendContactorClosingMessagesStill = 300; - transmit_can(&TESLA_221_1, can_config.battery); - transmit_can(&TESLA_221_2, can_config.battery); + transmit_can_frame(&TESLA_221_1, can_config.battery); + transmit_can_frame(&TESLA_221_2, can_config.battery); #ifdef DOUBLE_BATTERY if (datalayer.system.status.battery2_allows_contactor_closing) { - transmit_can(&TESLA_221_1, can_config.battery_double); - transmit_can(&TESLA_221_2, can_config.battery_double); + transmit_can_frame(&TESLA_221_1, can_config.battery_double); + transmit_can_frame(&TESLA_221_2, can_config.battery_double); } #endif //DOUBLE_BATTERY } else { // Faulted state, or inverter blocks contactor closing if (sendContactorClosingMessagesStill > 0) { - transmit_can(&TESLA_221_1, can_config.battery); + transmit_can_frame(&TESLA_221_1, can_config.battery); sendContactorClosingMessagesStill--; #ifdef DOUBLE_BATTERY - transmit_can(&TESLA_221_1, can_config.battery_double); + transmit_can_frame(&TESLA_221_1, can_config.battery_double); #endif //DOUBLE_BATTERY } } diff --git a/Software/src/battery/TESLA-BATTERY.h b/Software/src/battery/TESLA-BATTERY.h index 4f6c1689..817ca1f6 100644 --- a/Software/src/battery/TESLA-BATTERY.h +++ b/Software/src/battery/TESLA-BATTERY.h @@ -35,7 +35,7 @@ void printDebugIfActive(uint8_t symbol, const char* message); void print_int_with_units(char* header, int value, char* units); void print_SOC(char* header, int SOC); void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #ifdef DOUBLE_BATTERY void printFaultCodesIfActive_battery2(); #endif //DOUBLE_BATTERY diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index 52b19b32..634d0179 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -122,21 +122,21 @@ void update_values_battery2() { // Handle the values coming in from battery #2 #endif } -void receive_can_battery2(CAN_frame rx_frame) { +void map_can_frame_to_variable_battery2(CAN_frame rx_frame) { datalayer.battery2.status.CAN_battery_still_alive = CAN_STILL_ALIVE; } #endif // DOUBLE_BATTERY -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { previousMillis100 = currentMillis; // Put fake messages here incase you want to test sending CAN - //transmit_can(&TEST, can_config.battery); + //transmit_can_frame(&TEST, can_config.battery); } } diff --git a/Software/src/battery/TEST-FAKE-BATTERY.h b/Software/src/battery/TEST-FAKE-BATTERY.h index 27b56fe2..c54f1577 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.h +++ b/Software/src/battery/TEST-FAKE-BATTERY.h @@ -6,6 +6,6 @@ #define MAX_CELL_DEVIATION_MV 9999 void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.cpp b/Software/src/battery/VOLVO-SPA-BATTERY.cpp index 0c8b4e85..2d27b02f 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.cpp +++ b/Software/src/battery/VOLVO-SPA-BATTERY.cpp @@ -140,7 +140,7 @@ void update_values_battery() { //This function maps all the values fetched via #endif } -void receive_can_battery(CAN_frame rx_frame) { +void handle_incoming_can_frame_battery(CAN_frame rx_frame) { datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE; switch (rx_frame.ID) { case 0x3A: @@ -263,7 +263,7 @@ void receive_can_battery(CAN_frame rx_frame) { { cell_voltages[battery_request_idx++] = ((rx_frame.data.u8[5] << 8) | rx_frame.data.u8[6]); cell_voltages[battery_request_idx] = (rx_frame.data.u8[7] << 8); - transmit_can(&VOLVO_FlowControl, can_config.battery); // Send flow control + transmit_can_frame(&VOLVO_FlowControl, can_config.battery); // Send flow control rxConsecutiveFrames = 1; } else if ((rx_frame.data.u8[0] == 0x21) && (rxConsecutiveFrames == 1)) { cell_voltages[battery_request_idx++] = cell_voltages[battery_request_idx] | rx_frame.data.u8[1]; @@ -273,7 +273,7 @@ void receive_can_battery(CAN_frame rx_frame) { if (batteryModuleNumber <= 0x2A) // Run until last pack is read { VOLVO_CELL_U_Req.data.u8[3] = batteryModuleNumber++; - transmit_can(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for next module + transmit_can_frame(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for next module } else { min_max_voltage[0] = 9999; min_max_voltage[1] = 0; @@ -284,7 +284,7 @@ void receive_can_battery(CAN_frame rx_frame) { min_max_voltage[1] = cell_voltages[cellcounter]; } - transmit_can(&VOLVO_SOH_Req, can_config.battery); //Send SOH read request + transmit_can_frame(&VOLVO_SOH_Req, can_config.battery); //Send SOH read request } rxConsecutiveFrames = 0; } @@ -299,10 +299,10 @@ void readCellVoltages() { batteryModuleNumber = 0x10; rxConsecutiveFrames = 0; VOLVO_CELL_U_Req.data.u8[3] = batteryModuleNumber++; - transmit_can(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for first module + transmit_can_frame(&VOLVO_CELL_U_Req, can_config.battery); //Send cell voltage read request for first module } -void send_can_battery() { +void transmit_can_battery() { unsigned long currentMillis = millis(); // Send 100ms CAN Message if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { @@ -314,8 +314,8 @@ void send_can_battery() { } previousMillis100 = currentMillis; - transmit_can(&VOLVO_536, can_config.battery); //Send 0x536 Network managing frame to keep BMS alive - transmit_can(&VOLVO_372, can_config.battery); //Send 0x372 ECMAmbientTempCalculated + transmit_can_frame(&VOLVO_536, can_config.battery); //Send 0x536 Network managing frame to keep BMS alive + transmit_can_frame(&VOLVO_372, can_config.battery); //Send 0x372 ECMAmbientTempCalculated if (datalayer.battery.status.bms_status == ACTIVE) { datalayer.system.status.battery_allows_contactor_closing = true; diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.h b/Software/src/battery/VOLVO-SPA-BATTERY.h index 76c28074..6dcda0e7 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.h +++ b/Software/src/battery/VOLVO-SPA-BATTERY.h @@ -11,6 +11,6 @@ #define MIN_CELL_VOLTAGE_MV 2700 //Battery is put into emergency stop if one cell goes below this value void setup_battery(void); -void transmit_can(CAN_frame* tx_frame, int interface); +void transmit_can_frame(CAN_frame* tx_frame, int interface); #endif diff --git a/Software/src/charger/CHARGERS.h b/Software/src/charger/CHARGERS.h index 7aa68c77..a41b5bc9 100644 --- a/Software/src/charger/CHARGERS.h +++ b/Software/src/charger/CHARGERS.h @@ -10,7 +10,7 @@ #include "NISSAN-LEAF-CHARGER.h" #endif -void receive_can_charger(CAN_frame rx_frame); -void send_can_charger(); +void map_can_frame_to_variable_charger(CAN_frame rx_frame); +void transmit_can_charger(); #endif diff --git a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp index 3b947d2d..618c7d2a 100644 --- a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp +++ b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp @@ -56,7 +56,7 @@ static CAN_frame charger_set_targets = { .data = {0x40, 0x00, 0x00, 0x00}}; // data[0] is a static value, meaning unknown /* We are mostly sending out not receiving */ -void receive_can_charger(CAN_frame rx_frame) { +void map_can_frame_to_variable_charger(CAN_frame rx_frame) { uint16_t charger_stat_HVcur_temp = 0; uint16_t charger_stat_HVvol_temp = 0; uint16_t charger_stat_LVcur_temp = 0; @@ -108,7 +108,7 @@ void receive_can_charger(CAN_frame rx_frame) { } } -void send_can_charger() { +void transmit_can_charger() { unsigned long currentMillis = millis(); uint16_t Vol_temp = 0; @@ -137,7 +137,7 @@ void send_can_charger() { charger_keepalive_frame.data.u8[0] = charger_mode; - transmit_can(&charger_keepalive_frame, can_config.charger); + transmit_can_frame(&charger_keepalive_frame, can_config.charger); } /* Send current targets every 200ms */ @@ -174,7 +174,7 @@ void send_can_charger() { /* LSB of the voltage command. Then MSB LSB is divided by 2 */ charger_set_targets.data.u8[3] = lowByte(Vol_temp); - transmit_can(&charger_set_targets, can_config.charger); + transmit_can_frame(&charger_set_targets, can_config.charger); } #ifdef DEBUG_LOG diff --git a/Software/src/charger/NISSAN-LEAF-CHARGER.cpp b/Software/src/charger/NISSAN-LEAF-CHARGER.cpp index 0c756cf9..104e6a9b 100644 --- a/Software/src/charger/NISSAN-LEAF-CHARGER.cpp +++ b/Software/src/charger/NISSAN-LEAF-CHARGER.cpp @@ -129,7 +129,7 @@ static uint8_t calculate_checksum_nibble(CAN_frame* frame) { return sum; } -void receive_can_charger(CAN_frame rx_frame) { +void map_can_frame_to_variable_charger(CAN_frame rx_frame) { switch (rx_frame.ID) { case 0x679: // This message fires once when charging cable is plugged in @@ -166,7 +166,7 @@ void receive_can_charger(CAN_frame rx_frame) { } } -void send_can_charger() { +void transmit_can_charger() { unsigned long currentMillis = millis(); /* Send keepalive with mode every 10ms */ @@ -182,13 +182,13 @@ void send_can_charger() { #ifndef NISSAN_LEAF_BATTERY // VCM message, containing info if battery should sleep or stay awake - transmit_can(&LEAF_50B, can_config.charger); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1 + transmit_can_frame(&LEAF_50B, can_config.charger); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1 LEAF_1DB.data.u8[7] = calculate_CRC_Nissan(&LEAF_1DB); - transmit_can(&LEAF_1DB, can_config.charger); + transmit_can_frame(&LEAF_1DB, can_config.charger); LEAF_1DC.data.u8[7] = calculate_CRC_Nissan(&LEAF_1DC); - transmit_can(&LEAF_1DC, can_config.charger); + transmit_can_frame(&LEAF_1DC, can_config.charger); #endif OBCpowerSetpoint = ((charger_setpoint_HV_IDC * 4) + 0x64); @@ -233,8 +233,9 @@ void send_can_charger() { LEAF_1F2.data.u8[6] = mprun10; LEAF_1F2.data.u8[7] = calculate_checksum_nibble(&LEAF_1F2); - transmit_can(&LEAF_1F2, - can_config.charger); // Sending of 1F2 message is halted in LEAF-BATTERY function incase used here + transmit_can_frame( + &LEAF_1F2, + can_config.charger); // Sending of 1F2 message is halted in LEAF-BATTERY function incase used here } /* Send messages every 100ms here */ @@ -252,11 +253,11 @@ void send_can_charger() { LEAF_55B.data.u8[6] = ((0x1 << 4) | (mprun100)); LEAF_55B.data.u8[7] = calculate_CRC_Nissan(&LEAF_55B); - transmit_can(&LEAF_55B, can_config.charger); + transmit_can_frame(&LEAF_55B, can_config.charger); - transmit_can(&LEAF_59E, can_config.charger); + transmit_can_frame(&LEAF_59E, can_config.charger); - transmit_can(&LEAF_5BC, can_config.charger); + transmit_can_frame(&LEAF_5BC, can_config.charger); #endif } } diff --git a/Software/src/communication/can/comm_can.cpp b/Software/src/communication/can/comm_can.cpp index b9aa2259..24063c35 100644 --- a/Software/src/communication/can/comm_can.cpp +++ b/Software/src/communication/can/comm_can.cpp @@ -1,5 +1,6 @@ #include "comm_can.h" #include "../../include.h" +#include "src/devboard/sdcard/sdcard.h" // Parameters @@ -102,13 +103,31 @@ void init_CAN() { } // Transmit functions +void transmit_can() { + if (!allowed_to_send_CAN) { + return; + } + transmit_can_battery(); -void transmit_can(CAN_frame* tx_frame, int interface) { +#ifdef CAN_INVERTER_SELECTED + transmit_can_inverter(); +#endif // CAN_INVERTER_SELECTED + +#ifdef CHARGER_SELECTED + transmit_can_charger(); +#endif // CHARGER_SELECTED +} + +void transmit_can_frame(CAN_frame* tx_frame, int interface) { if (!allowed_to_send_CAN) { return; } print_can_frame(*tx_frame, frameDirection(MSG_TX)); +#ifdef LOG_CAN_TO_SD + add_can_frame_to_buffer(*tx_frame, frameDirection(MSG_TX)); +#endif + switch (interface) { case CAN_NATIVE: CAN_frame_t frame; @@ -168,50 +187,18 @@ void transmit_can(CAN_frame* tx_frame, int interface) { } } -void send_can() { - if (!allowed_to_send_CAN) { - return; - } - send_can_battery(); - -#ifdef CAN_INVERTER_SELECTED - send_can_inverter(); -#endif // CAN_INVERTER_SELECTED - -#ifdef CHARGER_SELECTED - send_can_charger(); -#endif // CHARGER_SELECTED -} - // Receive functions - -void receive_can(CAN_frame* rx_frame, int interface) { - print_can_frame(*rx_frame, frameDirection(MSG_RX)); - - if (interface == can_config.battery) { - receive_can_battery(*rx_frame); -#ifdef CHADEMO_BATTERY - ISA_handleFrame(rx_frame); -#endif - } - if (interface == can_config.inverter) { -#ifdef CAN_INVERTER_SELECTED - receive_can_inverter(*rx_frame); -#endif - } - if (interface == can_config.battery_double) { -#ifdef DOUBLE_BATTERY - receive_can_battery2(*rx_frame); -#endif - } - if (interface == can_config.charger) { -#ifdef CHARGER_SELECTED - receive_can_charger(*rx_frame); -#endif - } +void receive_can() { + receive_frame_can_native(); // Receive CAN messages from native CAN port +#ifdef CAN_ADDON + receive_frame_can_addon(); // Receive CAN messages on add-on MCP2515 chip +#endif // CAN_ADDON +#ifdef CANFD_ADDON + receive_frame_canfd_addon(); // Receive CAN-FD messages. +#endif // CANFD_ADDON } -void receive_can_native() { // This section checks if we have a complete CAN message incoming on native CAN port +void receive_frame_can_native() { // This section checks if we have a complete CAN message incoming on native CAN port CAN_frame_t rx_frame_native; if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame_native, 0) == pdTRUE) { CAN_frame rx_frame; @@ -226,47 +213,46 @@ void receive_can_native() { // This section checks if we have a complete CAN me rx_frame.data.u8[i] = rx_frame_native.data.u8[i]; } //message incoming, pass it on to the handler - receive_can(&rx_frame, CAN_NATIVE); + map_can_frame_to_variable(&rx_frame, CAN_NATIVE); } } #ifdef CAN_ADDON -void receive_can_addon() { // This section checks if we have a complete CAN message incoming on add-on CAN port - CAN_frame rx_frame; // Struct with our CAN format - CANMessage MCP2515Frame; // Struct with ACAN2515 library format, needed to use the MCP2515 library +void receive_frame_can_addon() { // This section checks if we have a complete CAN message incoming on add-on CAN port + CAN_frame rx_frame; // Struct with our CAN format + CANMessage MCP2515frame; // Struct with ACAN2515 library format, needed to use the MCP2515 library if (can.available()) { - can.receive(MCP2515Frame); + can.receive(MCP2515frame); - rx_frame.ID = MCP2515Frame.id; - rx_frame.ext_ID = MCP2515Frame.ext ? CAN_frame_ext : CAN_frame_std; - rx_frame.DLC = MCP2515Frame.len; - for (uint8_t i = 0; i < MCP2515Frame.len && i < 8; i++) { - rx_frame.data.u8[i] = MCP2515Frame.data[i]; + rx_frame.ID = MCP2515frame.id; + rx_frame.ext_ID = MCP2515frame.ext ? CAN_frame_ext : CAN_frame_std; + rx_frame.DLC = MCP2515frame.len; + for (uint8_t i = 0; i < MCP2515frame.len && i < 8; i++) { + rx_frame.data.u8[i] = MCP2515frame.data[i]; } //message incoming, pass it on to the handler - receive_can(&rx_frame, CAN_ADDON_MCP2515); + map_can_frame_to_variable(&rx_frame, CAN_ADDON_MCP2515); } } #endif // CAN_ADDON #ifdef CANFD_ADDON -// Functions -void receive_canfd_addon() { // This section checks if we have a complete CAN-FD message incoming - CANFDMessage frame; +void receive_frame_canfd_addon() { // This section checks if we have a complete CAN-FD message incoming + CANFDMessage MCP2518frame; int count = 0; while (canfd.available() && count++ < 16) { - canfd.receive(frame); + canfd.receive(MCP2518frame); CAN_frame rx_frame; - rx_frame.ID = frame.id; - rx_frame.ext_ID = frame.ext; - rx_frame.DLC = frame.len; - memcpy(rx_frame.data.u8, frame.data, MIN(rx_frame.DLC, 64)); + rx_frame.ID = MCP2518frame.id; + rx_frame.ext_ID = MCP2518frame.ext; + rx_frame.DLC = MCP2518frame.len; + memcpy(rx_frame.data.u8, MCP2518frame.data, MIN(rx_frame.DLC, 64)); //message incoming, pass it on to the handler - receive_can(&rx_frame, CANFD_ADDON_MCP2518); - receive_can(&rx_frame, CANFD_NATIVE); + map_can_frame_to_variable(&rx_frame, CANFD_ADDON_MCP2518); + map_can_frame_to_variable(&rx_frame, CANFD_NATIVE); } } #endif // CANFD_ADDON @@ -326,3 +312,33 @@ void print_can_frame(CAN_frame frame, frameDirection msgDir) { datalayer.system.info.logged_can_messages_offset = offset; // Update offset in buffer } } + +void map_can_frame_to_variable(CAN_frame* rx_frame, int interface) { + print_can_frame(*rx_frame, frameDirection(MSG_RX)); + +#ifdef LOG_CAN_TO_SD + add_can_frame_to_buffer(*rx_frame, frameDirection(MSG_RX)); +#endif + + if (interface == can_config.battery) { + handle_incoming_can_frame_battery(*rx_frame); +#ifdef CHADEMO_BATTERY + ISA_handleFrame(rx_frame); +#endif + } + if (interface == can_config.inverter) { +#ifdef CAN_INVERTER_SELECTED + map_can_frame_to_variable_inverter(*rx_frame); +#endif + } + if (interface == can_config.battery_double) { +#ifdef DOUBLE_BATTERY + map_can_frame_to_variable_battery2(*rx_frame); +#endif + } + if (interface == can_config.charger) { +#ifdef CHARGER_SELECTED + map_can_frame_to_variable_charger(*rx_frame); +#endif + } +} diff --git a/Software/src/communication/can/comm_can.h b/Software/src/communication/can/comm_can.h index 48e3c9c3..a5117f16 100644 --- a/Software/src/communication/can/comm_can.h +++ b/Software/src/communication/can/comm_can.h @@ -15,8 +15,6 @@ #include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h" #endif //CANFD_ADDON -enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1 - /** * @brief Initialization function for CAN. * @@ -34,7 +32,7 @@ void init_CAN(); * * @return void */ -void transmit_can(); +void transmit_can_frame(); /** * @brief Send CAN messages to all components @@ -43,7 +41,7 @@ void transmit_can(); * * @return void */ -void send_can(); +void transmit_can(); /** * @brief Receive CAN messages from all interfaces @@ -61,7 +59,7 @@ void receive_can(); * * @return void */ -void receive_can_native(); +void receive_frame_can_native(); /** * @brief Receive CAN messages from CAN addon chip @@ -70,7 +68,7 @@ void receive_can_native(); * * @return void */ -void receive_can_addon(); +void receive_frame_can_addon(); /** * @brief Receive CAN messages from CANFD addon chip @@ -79,7 +77,7 @@ void receive_can_addon(); * * @return void */ -void receive_canfd_addon(); +void receive_frame_canfd_addon(); /** * @brief print CAN frames via USB @@ -90,4 +88,14 @@ void receive_canfd_addon(); */ void print_can_frame(CAN_frame frame, frameDirection msgDir); +/** + * @brief Map CAN frame from specified interface to variable + * + * @param[in] CAN_frame* rx_frame + * @param[in] int interface + * + * @return void + */ +void map_can_frame_to_variable(CAN_frame* rx_frame, int interface); + #endif diff --git a/Software/src/devboard/safety/safety.cpp b/Software/src/devboard/safety/safety.cpp index 39f4b133..f662adfe 100644 --- a/Software/src/devboard/safety/safety.cpp +++ b/Software/src/devboard/safety/safety.cpp @@ -283,12 +283,12 @@ void setBatteryPause(bool pause_battery, bool pause_CAN, bool equipment_stop, bo } //immediate check if we can send CAN messages - emulator_pause_state_send_CAN_battery(); + emulator_pause_state_transmit_can_battery(); } /// @brief handle emulator pause status /// @return true if CAN messages should be sent to battery, false if not -void emulator_pause_state_send_CAN_battery() { +void emulator_pause_state_transmit_can_battery() { bool previous_allowed_to_send_CAN = allowed_to_send_CAN; if (emulator_pause_status == NORMAL) { diff --git a/Software/src/devboard/safety/safety.h b/Software/src/devboard/safety/safety.h index 32ae0ab8..8fa98a3d 100644 --- a/Software/src/devboard/safety/safety.h +++ b/Software/src/devboard/safety/safety.h @@ -22,7 +22,7 @@ void update_machineryprotection(); //battery pause status begin void setBatteryPause(bool pause_battery, bool pause_CAN, bool equipment_stop = false, bool store_settings = true); -void emulator_pause_state_send_CAN_battery(); +void emulator_pause_state_transmit_can_battery(); std::string get_emulator_pause_status(); //battery pause status end diff --git a/Software/src/devboard/sdcard/sdcard.cpp b/Software/src/devboard/sdcard/sdcard.cpp new file mode 100644 index 00000000..9cb2ff61 --- /dev/null +++ b/Software/src/devboard/sdcard/sdcard.cpp @@ -0,0 +1,151 @@ +#include "sdcard.h" +#include "freertos/ringbuf.h" + +File can_log_file; +RingbufHandle_t can_bufferHandle; + +bool can_logging_paused = false; +bool can_file_open = false; +bool delete_can_file = false; +bool sd_card_active = false; + +void delete_can_log() { + can_logging_paused = true; + delete_can_file = true; +} + +void resume_can_writing() { + can_logging_paused = false; + can_log_file = SD.open(CAN_LOG_FILE, FILE_APPEND); + can_file_open = true; +} + +void pause_can_writing() { + can_logging_paused = true; +} + +void add_can_frame_to_buffer(CAN_frame frame, frameDirection msgDir) { + + if (!sd_card_active) + return; + + CAN_log_frame log_frame = {frame, msgDir}; + if (xRingbufferSend(can_bufferHandle, &log_frame, sizeof(log_frame), 0) != pdTRUE) { + Serial.println("Failed to send CAN frame to ring buffer!"); + return; + } +} + +void write_can_frame_to_sdcard() { + + if (!sd_card_active) + return; + + size_t receivedMessageSize; + CAN_log_frame* log_frame = + (CAN_log_frame*)xRingbufferReceive(can_bufferHandle, &receivedMessageSize, pdMS_TO_TICKS(10)); + + if (log_frame != NULL) { + + if (can_logging_paused) { + if (can_file_open) { + can_log_file.close(); + can_file_open = false; + } + if (delete_can_file) { + SD.remove(CAN_LOG_FILE); + delete_can_file = false; + can_logging_paused = false; + } + vRingbufferReturnItem(can_bufferHandle, (void*)log_frame); + return; + } + + if (can_file_open == false) { + can_log_file = SD.open(CAN_LOG_FILE, FILE_APPEND); + can_file_open = true; + } + + uint8_t i = 0; + can_log_file.print("("); + can_log_file.print(millis() / 1000.0); + (log_frame->direction == MSG_RX) ? can_log_file.print(") RX0 ") : can_log_file.print(") TX1 "); + can_log_file.print(log_frame->frame.ID, HEX); + can_log_file.print(" ["); + can_log_file.print(log_frame->frame.DLC); + can_log_file.print("] "); + for (i = 0; i < log_frame->frame.DLC; i++) { + can_log_file.print(log_frame->frame.data.u8[i] < 16 ? "0" : ""); + can_log_file.print(log_frame->frame.data.u8[i], HEX); + if (i < log_frame->frame.DLC - 1) + can_log_file.print(" "); + } + can_log_file.println(""); + + vRingbufferReturnItem(can_bufferHandle, (void*)log_frame); + } +} + +void init_logging_buffer() { + can_bufferHandle = xRingbufferCreate(64 * 1024, RINGBUF_TYPE_BYTEBUF); + if (can_bufferHandle == NULL) { + Serial.println("Failed to create CAN ring buffer!"); + return; + } +} + +void init_sdcard() { + + pinMode(SD_CS_PIN, OUTPUT); + digitalWrite(SD_CS_PIN, HIGH); + pinMode(SD_SCLK_PIN, OUTPUT); + pinMode(SD_MOSI_PIN, OUTPUT); + pinMode(SD_MISO_PIN, INPUT); + + SPI.begin(SD_SCLK_PIN, SD_MISO_PIN, SD_MOSI_PIN, SD_CS_PIN); + if (!SD.begin(SD_CS_PIN)) { + Serial.println("SD Card initialization failed!"); + return; + } + + Serial.println("SD Card initialization successful."); + sd_card_active = true; + + print_sdcard_details(); +} + +void print_sdcard_details() { + + Serial.print("SD Card Type: "); + switch (SD.cardType()) { + case CARD_MMC: + Serial.println("MMC"); + break; + case CARD_SD: + Serial.println("SD"); + break; + case CARD_SDHC: + Serial.println("SDHC"); + break; + case CARD_UNKNOWN: + Serial.println("UNKNOWN"); + break; + case CARD_NONE: + Serial.println("No SD Card found"); + break; + } + + if (SD.cardType() != CARD_NONE) { + Serial.print("SD Card Size: "); + Serial.print(SD.cardSize() / 1024 / 1024); + Serial.println(" MB"); + + Serial.print("Total space: "); + Serial.print(SD.totalBytes() / 1024 / 1024); + Serial.println(" MB"); + + Serial.print("Used space: "); + Serial.print(SD.usedBytes() / 1024 / 1024); + Serial.println(" MB"); + } +} diff --git a/Software/src/devboard/sdcard/sdcard.h b/Software/src/devboard/sdcard/sdcard.h new file mode 100644 index 00000000..0f792358 --- /dev/null +++ b/Software/src/devboard/sdcard/sdcard.h @@ -0,0 +1,23 @@ +#ifndef SDCARD_H +#define SDCARD_H + +#include +#include +#include "../../communication/can/comm_can.h" +#include "../hal/hal.h" + +#define CAN_LOG_FILE "/canlog.txt" + +void init_logging_buffer(); + +void init_sdcard(); +void print_sdcard_details(); + +void add_can_frame_to_buffer(CAN_frame frame, frameDirection msgDir); +void write_can_frame_to_sdcard(); + +void pause_can_writing(); +void resume_can_writing(); +void delete_can_log(); + +#endif diff --git a/Software/src/devboard/utils/types.h b/Software/src/devboard/utils/types.h index 126aff26..d5cbf2c7 100644 --- a/Software/src/devboard/utils/types.h +++ b/Software/src/devboard/utils/types.h @@ -51,6 +51,13 @@ typedef struct { } data; } CAN_frame; +enum frameDirection { MSG_RX, MSG_TX }; //RX = 0, TX = 1 + +typedef struct { + CAN_frame frame; + frameDirection direction; +} CAN_log_frame; + std::string getBMSStatus(bms_status_enum status); #endif diff --git a/Software/src/devboard/webserver/can_logging_html.cpp b/Software/src/devboard/webserver/can_logging_html.cpp index 77f1975e..e64de232 100644 --- a/Software/src/devboard/webserver/can_logging_html.cpp +++ b/Software/src/devboard/webserver/can_logging_html.cpp @@ -24,6 +24,9 @@ String can_logger_processor(const String& var) { content += ""; content += " "; content += " "; +#ifdef LOG_CAN_TO_SD + content += " "; +#endif content += ""; // Start a new block for the CAN messages @@ -52,6 +55,9 @@ String can_logger_processor(const String& var) { content += "