mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Make CAN-FD work with refactor
This commit is contained in:
parent
e92f35e50b
commit
28c4bf1c7f
4 changed files with 23 additions and 34 deletions
|
@ -43,8 +43,21 @@ static int8_t temperature_water_inlet = 0;
|
|||
static int8_t powerRelayTemperature = 0;
|
||||
static int8_t heatertemp = 0;
|
||||
|
||||
CANFDMessage EGMP_7E4;
|
||||
CANFDMessage EGMP_7E4_ack;
|
||||
CAN_frame_t EGMP_7E4 = {.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std, // Converted to CAN-FD when sent
|
||||
}},
|
||||
.MsgID = 0x7E4,
|
||||
.data = {0x03, 0x22, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}}; //Poll PID 03 22 01 01
|
||||
CAN_frame_t EGMP_7E4_ack = {
|
||||
.FIR = {.B =
|
||||
{
|
||||
.DLC = 8,
|
||||
.FF = CAN_frame_std, // Converted to CAN-FD when sent
|
||||
}},
|
||||
.MsgID = 0x7E4,
|
||||
.data = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; //Ack frame, correct PID is returned
|
||||
|
||||
void set_cell_voltages(CANFDMessage frame, int start, int length, int startCell) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
|
@ -173,18 +186,6 @@ void update_values_battery() { //This function maps all the values fetched via
|
|||
#endif
|
||||
}
|
||||
|
||||
void send_canfd_frame(CANFDMessage frame) {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
const bool ok = canfd.tryToSend(frame);
|
||||
if (ok) {
|
||||
} else {
|
||||
Serial.println("Send canfd failure.");
|
||||
}
|
||||
#else
|
||||
canfd.tryToSend(frame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void receive_canfd_battery(CANFDMessage frame) {
|
||||
datalayer.battery.status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
switch (frame.id) {
|
||||
|
@ -195,7 +196,7 @@ void receive_canfd_battery(CANFDMessage frame) {
|
|||
// Serial.println ("Send ack");
|
||||
poll_data_pid = frame.data[4];
|
||||
// if (frame.data[4] == poll_data_pid) {
|
||||
send_canfd_frame(EGMP_7E4_ack); //Send ack to BMS if the same frame is sent as polled
|
||||
transmit_can(&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
|
||||
|
@ -388,8 +389,8 @@ void send_can_battery() {
|
|||
datalayer.system.status.battery_allows_contactor_closing = false;
|
||||
}
|
||||
// Section end
|
||||
EGMP_7E4.data[3] = KIA_7E4_COUNTER;
|
||||
send_canfd_frame(EGMP_7E4);
|
||||
EGMP_7E4.data.u8[3] = KIA_7E4_COUNTER;
|
||||
transmit_can(&EGMP_7E4, can_config.battery);
|
||||
|
||||
KIA_7E4_COUNTER++;
|
||||
if (KIA_7E4_COUNTER > 0x0D) { // gets up to 0x010C before repeating
|
||||
|
@ -409,18 +410,6 @@ void setup_battery(void) { // Performs one time setup at startup
|
|||
8064; // TODO: define when battery is known, charging is not possible (goes into forced discharge)
|
||||
datalayer.battery.info.min_design_voltage_dV =
|
||||
4320; // TODO: define when battery is known. discharging further is disabled
|
||||
|
||||
EGMP_7E4.id = 0x7E4;
|
||||
EGMP_7E4.ext = false;
|
||||
EGMP_7E4.len = 8;
|
||||
uint8_t dataEGMP_7E4[8] = {0x03, 0x22, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}; //Poll PID 03 22 01 01
|
||||
memcpy(EGMP_7E4.data, dataEGMP_7E4, sizeof(dataEGMP_7E4));
|
||||
|
||||
EGMP_7E4_ack.id = 0x7E4;
|
||||
EGMP_7E4_ack.ext = false;
|
||||
EGMP_7E4_ack.len = 8;
|
||||
uint8_t dataEGMP_7E4_ack[8] = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Ack frame, correct PID is returned
|
||||
memcpy(EGMP_7E4_ack.data, dataEGMP_7E4_ack, sizeof(dataEGMP_7E4_ack));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue