From 3bb0cacf04e0af377955ff7176b90ae1a9b99f5f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 30 Nov 2023 19:08:28 +0200 Subject: [PATCH] Add various CAN messages --- Software/src/battery/BMW-I3-BATTERY.cpp | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 76976ec1..1ccdcc77 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -10,13 +10,17 @@ static unsigned long previousMillis10 = 0; // will store last time a 20ms CAN Message was send static unsigned long previousMillis20 = 0; // will store last time a 20ms CAN Message was send static unsigned long previousMillis100 = 0; // will store last time a 20ms CAN Message was send +static unsigned long previousMillis200 = 0; // will store last time a 20ms CAN Message was send static unsigned long previousMillis600 = 0; // will store last time a 600ms CAN Message was send static unsigned long previousMillis1000 = 0; // will store last time a 1000ms CAN Message was send +static unsigned long previousMillis5000 = 0; // will store last time a 5000ms CAN Message was send static const int interval10 = 10; // interval (ms) at which send CAN Messages static const int interval20 = 20; // interval (ms) at which send CAN Messages static const int interval100 = 100; // interval (ms) at which send CAN Messages +static const int interval200 = 200; // interval (ms) at which send CAN Messages static const int interval600 = 600; // interval (ms) at which send CAN Messages static const int interval1000 = 1000; // interval (ms) at which send CAN Messages +static const int interval5000 = 5000; // interval (ms) at which send CAN Messages static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive #define LB_MAX_SOC 1000 //BMS never goes over this value. We use this info to rescale SOC% sent to Inverter @@ -43,6 +47,13 @@ CAN_frame_t BMW_512 = {.FIR = {.B = }}, .MsgID = 0x512, .data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12}}; //0x512 Network management edme VCU +CAN_frame_t BMW_03C = {.FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x03C, + .data = {0xFF, 0x5F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}}; CAN_frame_t BMW_12F = {.FIR = {.B = { .DLC = 8, @@ -64,6 +75,34 @@ CAN_frame_t BMW_3F9 = {.FIR = {.B = }}, .MsgID = 0x3F9, .data = {0x1F, 0x34, 0x00, 0xE2, 0xA6, 0x30, 0xC3, 0xFF}}; +CAN_frame_t BMW_3A0 = {.FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x3A0, + .data = {0xFF, 0xFF, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC}}; +CAN_frame_t BMW_3E8 = {.FIR = {.B = + { + .DLC = 2, + .FF = CAN_frame_std, + }}, + .MsgID = 0x3E8, + .data = {0xF1, 0xFF}}; //1000ms OBD reset +CAN_frame_t BMW_328 = {.FIR = {.B = + { + .DLC = 6, + .FF = CAN_frame_std, + }}, + .MsgID = 0x328, + .data = {0xB0, 0x33, 0xBF, 0x0C, 0xD3, 0x20}}; +CAN_frame_t BMW_51A = {.FIR = {.B = + { + .DLC = 8, + .FF = CAN_frame_std, + }}, + .MsgID = 0x51A, + .data = {0x0, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x1A}}; //These CAN messages need to be sent towards the battery to keep it alive @@ -72,6 +111,7 @@ static const uint8_t BMW_10B_0[15] = {0xCD, 0x19, 0x94, 0x6D, 0xE0, 0x34, 0x78, static const uint8_t BMW_10B_1[15] = {0x01, 0x02, 0x33, 0x34, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x00}; static uint8_t BMW_10B_counter = 0; +static uint32_t BMW_328_counter = 0; static int16_t Battery_Current = 0; static uint16_t Battery_Capacity_kWh = 0; @@ -230,6 +270,12 @@ void send_can_i3_battery() { ESP32Can.CANWriteFrame(&BMW_12F); } + // Send 200ms CAN Message + if (currentMillis - previousMillis200 >= interval200) { + previousMillis200 = currentMillis; + + ESP32Can.CANWriteFrame(&BMW_03C); + } // Send 600ms CAN Message if (currentMillis - previousMillis600 >= interval600) { previousMillis600 = currentMillis; @@ -240,6 +286,21 @@ void send_can_i3_battery() { if (currentMillis - previousMillis1000 >= interval1000) { previousMillis1000 = currentMillis; + BMW_328_counter++; + BMW_328.data.u8[0] = BMW_328_counter; //rtc msg. needs to be every 1 sec. first 32 bits are 1 second wrap counter + BMW_328.data.u8[1] = BMW_328_counter << 8; + BMW_328.data.u8[2] = BMW_328_counter << 16; + BMW_328.data.u8[3] = BMW_328_counter << 24; + + ESP32Can.CANWriteFrame(&BMW_328); + ESP32Can.CANWriteFrame(&BMW_51A); ESP32Can.CANWriteFrame(&BMW_3F9); + ESP32Can.CANWriteFrame(&BMW_3E8); + } + // Send 5000ms CAN Message + if (currentMillis - previousMillis5000 >= interval5000) { + previousMillis5000 = currentMillis; + + ESP32Can.CANWriteFrame(&BMW_3A0); } }