mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-06 03:50:13 +02:00
Add even more CAN message sending
This commit is contained in:
parent
197539b95f
commit
cc012c5a71
1 changed files with 172 additions and 5 deletions
|
@ -4,20 +4,24 @@
|
|||
|
||||
//TODO: before using
|
||||
// Map the final values in update_values_i3_battery, set some to static values if not available (current, discharge max , charge max)
|
||||
// 0x2A0 / 0x397 / 0x540 / 0x560 / 0x510 / 0x2FC / 0x2F1 skipped since not in logs
|
||||
// 0x100 next to be added
|
||||
|
||||
/* Do not change code below unless you are sure what you are doing */
|
||||
static unsigned long previousMillis10 = 0; // will store last time a 20ms CAN Message was send
|
||||
static unsigned long previousMillis10 = 0; // will store last time a 10ms 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 previousMillis30 = 0; // will store last time a 30ms CAN Message was send
|
||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
static unsigned long previousMillis200 = 0; // will store last time a 200ms CAN Message was send
|
||||
static unsigned long previousMillis500 = 0; // will store last time a 500ms 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 interval30 = 30; // 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 interval500 = 500; // 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
|
||||
|
@ -32,7 +36,14 @@ CAN_frame_t BMW_BB = {.FIR = {.B =
|
|||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0xBB,
|
||||
.data = {0x7D, 0xFF, 0xFF}};
|
||||
.data = {0x00, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_AD = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0xAD,
|
||||
.data = {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF}};
|
||||
CAN_frame_t BMW_10B = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 3,
|
||||
|
@ -40,6 +51,13 @@ CAN_frame_t BMW_10B = {.FIR = {.B =
|
|||
}},
|
||||
.MsgID = 0x10B,
|
||||
.data = {0xCD, 0x01, 0xFC}};
|
||||
CAN_frame_t BMW_197 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 4,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x197,
|
||||
.data = {0x64, 0xE0, 0x0E, 0xC0}};
|
||||
CAN_frame_t BMW_512 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
|
@ -68,6 +86,27 @@ CAN_frame_t BMW_1A1 = {.FIR = {.B =
|
|||
}},
|
||||
.MsgID = 0x1A1,
|
||||
.data = {0x08, 0xC1, 0x00, 0x00, 0x81}}; //0x1A1 Vehicle speed
|
||||
CAN_frame_t BMW_1D0 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x1D0,
|
||||
.data = {0x4D, 0xF0, 0xAE, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_19E = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x19E,
|
||||
.data = {0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_105 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x105,
|
||||
.data = {0x03, 0xF0, 0x7F, 0xE0, 0x2E, 0x00, 0xFC, 0x0F}};
|
||||
CAN_frame_t BMW_2FA = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 6,
|
||||
|
@ -75,6 +114,20 @@ CAN_frame_t BMW_2FA = {.FIR = {.B =
|
|||
}},
|
||||
.MsgID = 0x2FA,
|
||||
.data = {0x0F, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_2FC = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x2FC,
|
||||
.data = {0x81, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_2A0 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x2A0,
|
||||
.data = {0x88, 0x88, 0xF8, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF}};
|
||||
CAN_frame_t BMW_3F9 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
|
@ -117,6 +170,20 @@ CAN_frame_t BMW_330 = {.FIR = {.B =
|
|||
}},
|
||||
.MsgID = 0x330,
|
||||
.data = {0x27, 0x33, 0x01, 0x00, 0x00, 0x00, 0x4D, 0x02}};
|
||||
CAN_frame_t BMW_397 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 7,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x397,
|
||||
.data = {0x00, 0x2A, 0x00, 0x6C, 0x0F, 0x55, 0x00}};
|
||||
CAN_frame_t BMW_433 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 4,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x433,
|
||||
.data = {0xFF, 0x00, 0x0F, 0xFF}};
|
||||
CAN_frame_t BMW_51A = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
|
@ -124,6 +191,27 @@ CAN_frame_t BMW_51A = {.FIR = {.B =
|
|||
}},
|
||||
.MsgID = 0x51A,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x1A}};
|
||||
CAN_frame_t BMW_510 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x510,
|
||||
.data = {0x40, 0x10, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
CAN_frame_t BMW_540 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x540,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0xFD, 0x3C, 0xFF, 0x40}};
|
||||
CAN_frame_t BMW_560 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std,
|
||||
}},
|
||||
.MsgID = 0x560,
|
||||
.data = {0x0, 0x0, 0x0, 0x0, 0xFE, 0x00, 0x00, 0x60}};
|
||||
|
||||
//These CAN messages need to be sent towards the battery to keep it alive
|
||||
|
||||
|
@ -131,7 +219,21 @@ static const uint8_t BMW_10B_0[15] = {0xCD, 0x19, 0x94, 0x6D, 0xE0, 0x34, 0x78,
|
|||
0x97, 0x43, 0x0F, 0xF6, 0xBA, 0x6E, 0x81};
|
||||
static const uint8_t BMW_10B_1[15] = {0x01, 0x02, 0x33, 0x34, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x00};
|
||||
static const uint8_t BMW_197_0[15] = {0x89, 0x06, 0x8A, 0x05, 0x8F, 0x00, 0x8C, 0x03,
|
||||
0x85, 0x0A, 0x86, 0x09, 0x83, 0x0C, 0x80};
|
||||
static const uint8_t BMW_105_0[15] = {0x03, 0x5E, 0xB9, 0xE4, 0x6A, 0x37, 0xD0, 0x8D,
|
||||
0xD1, 0x8C, 0x6B, 0x36, 0xB8, 0xE5, 0x02};
|
||||
static const uint8_t BMW_1D0_0[15] = {0x4D, 0x10, 0xF7, 0xAA, 0x24, 0x79, 0x9E, 0xC3,
|
||||
0x9F, 0xC2, 0x25, 0x78, 0xF6, 0xAB, 0x4C};
|
||||
static const uint8_t BMW_F0_FE[15] = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE};
|
||||
static const uint8_t BMW_19E_0[6] = {0x05, 0x00, 0x05, 0x07, 0x0A, 0x0A};
|
||||
static uint8_t BMW_10B_counter = 0;
|
||||
static uint8_t BMW_105_counter = 0;
|
||||
static uint8_t BMW_1D0_counter = 0;
|
||||
static uint8_t BMW_197_counter = 0;
|
||||
static uint8_t BMW_19E_counter = 0;
|
||||
static uint8_t BMW_10_counter = 0;
|
||||
static uint32_t BMW_328_counter = 0;
|
||||
|
||||
static int16_t Battery_Current = 0;
|
||||
|
@ -269,7 +371,29 @@ void send_can_i3_battery() {
|
|||
if (currentMillis - previousMillis10 >= interval10) {
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
BMW_105.data.u8[0] = BMW_105_0[BMW_105_counter];
|
||||
BMW_105.data.u8[1] = BMW_F0_FE[BMW_105_counter];
|
||||
|
||||
BMW_105_counter++;
|
||||
if (BMW_105_counter > 14) {
|
||||
BMW_105_counter = 0;
|
||||
}
|
||||
|
||||
BMW_10_counter++;
|
||||
if (BMW_10_counter > 3) {
|
||||
BMW_10_counter = 3;
|
||||
|
||||
BMW_BB.data.u8[0] = 0x7D;
|
||||
|
||||
BMW_AD.data.u8[2] = 0xFE;
|
||||
BMW_AD.data.u8[3] = 0xE7;
|
||||
BMW_AD.data.u8[4] = 0x7F;
|
||||
BMW_AD.data.u8[5] = 0xFE;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_BB);
|
||||
ESP32Can.CANWriteFrame(&BMW_105);
|
||||
ESP32Can.CANWriteFrame(&BMW_AD);
|
||||
}
|
||||
//Send 20ms message
|
||||
if (currentMillis - previousMillis20 >= interval20) {
|
||||
|
@ -285,11 +409,25 @@ void send_can_i3_battery() {
|
|||
ESP32Can.CANWriteFrame(&BMW_10B);
|
||||
ESP32Can.CANWriteFrame(&BMW_1A1);
|
||||
}
|
||||
//Send 30ms message
|
||||
if (currentMillis - previousMillis30 >= interval30) {
|
||||
previousMillis30 = currentMillis;
|
||||
|
||||
BMW_197.data.u8[0] = BMW_197_0[BMW_197_counter];
|
||||
BMW_197.data.u8[1] = BMW_197_counter;
|
||||
BMW_197_counter++;
|
||||
if (BMW_197_counter > 14) {
|
||||
BMW_197_counter = 0;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_197);
|
||||
}
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= interval100) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_12F);
|
||||
ESP32Can.CANWriteFrame(&BMW_2FC);
|
||||
}
|
||||
// Send 200ms CAN Message
|
||||
if (currentMillis - previousMillis200 >= interval200) {
|
||||
|
@ -297,6 +435,26 @@ void send_can_i3_battery() {
|
|||
|
||||
ESP32Can.CANWriteFrame(&BMW_03C);
|
||||
ESP32Can.CANWriteFrame(&BMW_3E9);
|
||||
ESP32Can.CANWriteFrame(&BMW_2A0);
|
||||
ESP32Can.CANWriteFrame(&BMW_397);
|
||||
ESP32Can.CANWriteFrame(&BMW_510);
|
||||
ESP32Can.CANWriteFrame(&BMW_540);
|
||||
ESP32Can.CANWriteFrame(&BMW_560);
|
||||
}
|
||||
// Send 500ms CAN Message
|
||||
if (currentMillis - previousMillis500 >= interval500) {
|
||||
previousMillis500 = currentMillis;
|
||||
|
||||
BMW_19E.data.u8[0] = BMW_19E_0[BMW_19E_counter];
|
||||
BMW_19E.data.u8[3] = 0x04;
|
||||
if (BMW_19E_counter == 1) {
|
||||
BMW_19E.data.u8[3] = 0x00;
|
||||
}
|
||||
if (BMW_19E_counter < 5) {
|
||||
BMW_19E_counter++;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_19E);
|
||||
}
|
||||
// Send 600ms CAN Message
|
||||
if (currentMillis - previousMillis600 >= interval600) {
|
||||
|
@ -315,10 +473,19 @@ void send_can_i3_battery() {
|
|||
BMW_328.data.u8[2] = BMW_328_counter << 16;
|
||||
BMW_328.data.u8[3] = BMW_328_counter << 24;
|
||||
|
||||
BMW_1D0.data.u8[0] = BMW_1D0_0[BMW_1D0_counter];
|
||||
BMW_1D0.data.u8[1] = BMW_F0_FE[BMW_1D0_counter];
|
||||
|
||||
if (BMW_328_counter > 1) {
|
||||
BMW_433.data.u8[1] = 0x01;
|
||||
}
|
||||
|
||||
ESP32Can.CANWriteFrame(&BMW_328);
|
||||
ESP32Can.CANWriteFrame(&BMW_3F9);
|
||||
ESP32Can.CANWriteFrame(&BMW_3E8);
|
||||
ESP32Can.CANWriteFrame(&BMW_2FA);
|
||||
ESP32Can.CANWriteFrame(&BMW_1D0);
|
||||
ESP32Can.CANWriteFrame(&BMW_433);
|
||||
}
|
||||
// Send 5000ms CAN Message
|
||||
if (currentMillis - previousMillis5000 >= interval5000) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue