mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
iPace: Send proper keep alive message
Rework the existing transmit code to instead send proper keep-alive messages. Signed-off-by: Christopher Obbard <obbardc@gmail.com>
This commit is contained in:
parent
21b94b3552
commit
5b1036e577
1 changed files with 19 additions and 60 deletions
|
@ -5,9 +5,7 @@
|
||||||
#include "JAGUAR-IPACE-BATTERY.h"
|
#include "JAGUAR-IPACE-BATTERY.h"
|
||||||
|
|
||||||
/* Do not change code below unless you are sure what you are doing */
|
/* Do not change code below unless you are sure what you are doing */
|
||||||
static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was send
|
static unsigned long previousMillisKeepAlive = 0;
|
||||||
static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
|
||||||
static unsigned long previousMillis500 = 0; // will store last time a 500ms CAN Message was send
|
|
||||||
|
|
||||||
static uint8_t HVBattAvgSOC = 0;
|
static uint8_t HVBattAvgSOC = 0;
|
||||||
static uint8_t HVBattFastChgCounter = 0;
|
static uint8_t HVBattFastChgCounter = 0;
|
||||||
|
@ -41,17 +39,22 @@ static bool HVBattHVILError = false;
|
||||||
static bool HVILBattIsolationError = false;
|
static bool HVILBattIsolationError = false;
|
||||||
static bool HVIsolationTestStatus = false;
|
static bool HVIsolationTestStatus = false;
|
||||||
|
|
||||||
/* TODO: Actually use a proper keepalive message */
|
/* KeepAlive: PMZ_CAN_GWM_OSEK_NM_Pdu every 200ms.
|
||||||
|
*/
|
||||||
CAN_frame ipace_keep_alive = {.FD = false,
|
CAN_frame ipace_keep_alive = {.FD = false,
|
||||||
.ext_ID = false,
|
.ext_ID = false,
|
||||||
.DLC = 8,
|
.DLC = 8,
|
||||||
.ID = 0x063,
|
.ID = 0x51e,
|
||||||
.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
.data = {0x22, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||||
CAN_frame ipace_7e4 = {.FD = false,
|
|
||||||
.ext_ID = false,
|
/* KeepAlive: PMZ_CAN_NodeGWM_NM every 1s.
|
||||||
.DLC = 8,
|
* TODO: This may be needed for >2021 models.
|
||||||
.ID = 0x7e4,
|
*/
|
||||||
.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
/*CAN_frame ipace_keep_alive = {.FD = false,
|
||||||
|
.ext_ID = false,
|
||||||
|
.DLC = 8,
|
||||||
|
.ID = 0x59e,
|
||||||
|
.data = {0x9E, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};*/
|
||||||
|
|
||||||
void print_units(char* header, int value, char* units) {
|
void print_units(char* header, int value, char* units) {
|
||||||
Serial.print(header);
|
Serial.print(header);
|
||||||
|
@ -243,58 +246,14 @@ void receive_can_battery(CAN_frame rx_frame) {
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
int state = 0;
|
|
||||||
|
|
||||||
void send_can_battery() {
|
void send_can_battery() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
// Send 100ms CAN Message
|
|
||||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
|
||||||
previousMillis100 = currentMillis;
|
|
||||||
|
|
||||||
//transmit_can(&ipace_keep_alive);
|
/* Send keep-alive every 200ms */
|
||||||
}
|
if (currentMillis - previousMillisKeepAlive >= INTERVAL_200_MS) {
|
||||||
|
previousMillisKeepAlive = currentMillis;
|
||||||
// Send 500ms CAN Message
|
transmit_can(&ipace_keep_alive, can_config.battery);
|
||||||
if (currentMillis - previousMillis500 >= INTERVAL_500_MS) {
|
return;
|
||||||
previousMillis500 = currentMillis;
|
|
||||||
|
|
||||||
CAN_frame msg;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case 0:
|
|
||||||
|
|
||||||
// car response: 7ec 07 59 02 8f c0 64 88 28
|
|
||||||
// response: 7EC 07 59 02 8F F0 01 00 28
|
|
||||||
// response: 7EC 03 59 02 8F 00 00 00 00
|
|
||||||
// 7EC 8 3 7F 19 11 0 0 0 0
|
|
||||||
msg = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7e4,
|
|
||||||
.data = {0x03, 0x19, 0x02, 0x8f, 0x00, 0x00, 0x00, 0x00}};
|
|
||||||
transmit_can(&msg, can_config.battery);
|
|
||||||
state++;
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
// car response: 7EC 11 fa 59 04 c0 64 88 28
|
|
||||||
// response:
|
|
||||||
msg = {.FD = false,
|
|
||||||
.ext_ID = false,
|
|
||||||
.DLC = 8,
|
|
||||||
.ID = 0x7e4,
|
|
||||||
.data = {0x06, 0x19, 0x04, 0xc0, 0x64, 0x88, 0xff, 0x00}};
|
|
||||||
transmit_can(&msg, can_config.battery);
|
|
||||||
state++;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
/* reset */
|
|
||||||
state = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue