Merge pull request #264 from dalathegreat/bugfix/kia64-startup

Bugfix: Remake logic how Kia64 startup is handled
This commit is contained in:
Daniel Öster 2024-04-23 21:35:05 +03:00 committed by GitHub
commit 201e6be2bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,31 +19,31 @@ static uint16_t soc_calculated = 0;
static uint16_t SOC_BMS = 0;
static uint16_t SOC_Display = 0;
static uint16_t batterySOH = 1000;
static uint8_t waterleakageSensor = 164;
static int16_t leadAcidBatteryVoltage = 0;
static uint16_t CellVoltMax_mV = 3700;
static uint8_t CellVmaxNo = 0;
static uint16_t CellVoltMin_mV = 3700;
static uint8_t CellVminNo = 0;
static uint16_t cell_deviation_mV = 0;
static uint16_t allowedDischargePower = 0;
static uint16_t allowedChargePower = 0;
static uint16_t batteryVoltage = 0;
static uint16_t inverterVoltageFrameHigh = 0;
static uint16_t inverterVoltage = 0;
static uint16_t cellvoltages_mv[98];
static int16_t leadAcidBatteryVoltage = 0;
static int16_t batteryAmps = 0;
static int16_t temperatureMax = 0;
static int16_t temperatureMin = 0;
static int8_t temperature_water_inlet = 0;
static int16_t poll_data_pid = 0;
static uint8_t CellVmaxNo = 0;
static uint8_t CellVminNo = 0;
static uint8_t batteryManagementMode = 0;
static uint8_t BMS_ign = 0;
static int16_t poll_data_pid = 0;
static int8_t heatertemp = 0;
static uint8_t batteryRelay = 0;
static int8_t powerRelayTemperature = 0;
static uint16_t inverterVoltageFrameHigh = 0;
static uint16_t inverterVoltage = 0;
static uint8_t startedUp = false;
static uint8_t waterleakageSensor = 164;
static uint8_t counter_200 = 0;
static uint16_t cellvoltages_mv[98];
static int8_t temperature_water_inlet = 0;
static int8_t heatertemp = 0;
static int8_t powerRelayTemperature = 0;
static bool startedUp = false;
CAN_frame_t KIA_HYUNDAI_200 = {.FIR = {.B =
{
@ -301,17 +301,21 @@ void update_values_battery() { //This function maps all the values fetched via
void receive_can_battery(CAN_frame_t rx_frame) {
switch (rx_frame.MsgID) {
case 0x4DE:
startedUp = true;
break;
case 0x542: //BMS SOC
case 0x542: //BMS SOC
startedUp = true;
CANstillAlive = 12; //We use this message to verify that BMS is still alive
SOC_Display = rx_frame.data.u8[0] * 5; //100% = 200 ( 200 * 5 = 1000 )
break;
case 0x594:
startedUp = true;
allowedChargePower = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]);
allowedDischargePower = ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]);
SOC_BMS = rx_frame.data.u8[5] * 5; //100% = 200 ( 200 * 5 = 1000 )
break;
case 0x595:
startedUp = true;
batteryVoltage = (rx_frame.data.u8[7] << 8) + rx_frame.data.u8[6];
batteryAmps = (rx_frame.data.u8[5] << 8) + rx_frame.data.u8[4];
if (counter_200 > 3) {
@ -320,18 +324,21 @@ void receive_can_battery(CAN_frame_t rx_frame) {
} //VCU measured voltage sent back to bms
break;
case 0x596:
startedUp = true;
leadAcidBatteryVoltage = rx_frame.data.u8[1]; //12v Battery Volts
temperatureMin = rx_frame.data.u8[6]; //Lowest temp in battery
temperatureMax = rx_frame.data.u8[7]; //Highest temp in battery
break;
case 0x598:
startedUp = true;
break;
case 0x5D5:
startedUp = true;
waterleakageSensor = rx_frame.data.u8[3]; //Water sensor inside pack, value 164 is no water --> 0 is short
powerRelayTemperature = rx_frame.data.u8[7];
break;
case 0x5D8:
startedUp = 1;
startedUp = true;
//PID data is polled after last message sent from battery:
if (poll_data_pid >= 10) { //polling one of ten PIDs at 100ms, resolution = 1s
@ -529,6 +536,11 @@ void receive_can_battery(CAN_frame_t rx_frame) {
void send_can_battery() {
unsigned long currentMillis = millis();
if (!startedUp) {
return; // Don't send any CAN messages towards battery until it has started up
}
//Send 100ms message
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
previousMillis100 = currentMillis;
@ -560,11 +572,7 @@ void send_can_battery() {
break;
case 3:
KIA_HYUNDAI_200.data.u8[5] = 0xD7;
if (startedUp) {
++counter_200;
} else {
counter_200 = 0;
}
++counter_200;
break;
case 4:
KIA_HYUNDAI_200.data.u8[3] = 0x10;