Fix startup crash

This commit is contained in:
Daniel Öster 2025-08-03 20:52:50 +03:00
parent 2d56ab8916
commit 6ab63497f4
3 changed files with 46 additions and 63 deletions

View file

@ -302,10 +302,6 @@ void setup_battery() {
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer_extended.KiaHyundai64_2, battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer_extended.KiaHyundai64_2,
&datalayer.system.status.battery2_allowed_contactor_closing, &datalayer.system.status.battery2_allowed_contactor_closing,
can_config.battery_double); can_config.battery_double);
#elif defined(HYUNDAI_IONIQ_28_BATTERY)
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, &datalayer_extended.ioniq28,
&datalayer.system.status.battery2_allowed_contactor_closing,
can_config.battery_double);
#elif defined(SANTA_FE_PHEV_BATTERY) || defined(TEST_FAKE_BATTERY) #elif defined(SANTA_FE_PHEV_BATTERY) || defined(TEST_FAKE_BATTERY)
battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, can_config.battery_double); battery2 = new SELECTED_BATTERY_CLASS(&datalayer.battery2, can_config.battery_double);
#else #else

View file

@ -298,63 +298,58 @@ void HyundaiIoniq28Battery::transmit_can(unsigned long currentMillis) {
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) { if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
previousMillis100 = currentMillis; previousMillis100 = currentMillis;
if (contactor_closing_allowed == nullptr || *contactor_closing_allowed) { transmit_can_frame(&IONIQ_553);
transmit_can_frame(&IONIQ_553); transmit_can_frame(&IONIQ_57F);
transmit_can_frame(&IONIQ_57F); transmit_can_frame(&IONIQ_2A1);
transmit_can_frame(&IONIQ_2A1);
}
} }
// Send 10ms CAN Message // Send 10ms CAN Message
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) { if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
previousMillis10 = currentMillis; previousMillis10 = currentMillis;
if (contactor_closing_allowed == nullptr || *contactor_closing_allowed) { switch (counter_200) {
case 0:
switch (counter_200) { IONIQ_200.data.u8[5] = 0x17;
case 0: ++counter_200;
IONIQ_200.data.u8[5] = 0x17; break;
++counter_200; case 1:
break; IONIQ_200.data.u8[5] = 0x57;
case 1: ++counter_200;
IONIQ_200.data.u8[5] = 0x57; break;
++counter_200; case 2:
break; IONIQ_200.data.u8[5] = 0x97;
case 2: ++counter_200;
IONIQ_200.data.u8[5] = 0x97; break;
++counter_200; case 3:
break; IONIQ_200.data.u8[5] = 0xD7;
case 3: ++counter_200;
IONIQ_200.data.u8[5] = 0xD7; break;
++counter_200; case 4:
break; IONIQ_200.data.u8[3] = 0x10;
case 4: IONIQ_200.data.u8[5] = 0xFF;
IONIQ_200.data.u8[3] = 0x10; ++counter_200;
IONIQ_200.data.u8[5] = 0xFF; break;
++counter_200; case 5:
break; IONIQ_200.data.u8[5] = 0x3B;
case 5: ++counter_200;
IONIQ_200.data.u8[5] = 0x3B; break;
++counter_200; case 6:
break; IONIQ_200.data.u8[5] = 0x7B;
case 6: ++counter_200;
IONIQ_200.data.u8[5] = 0x7B; break;
++counter_200; case 7:
break; IONIQ_200.data.u8[5] = 0xBB;
case 7: ++counter_200;
IONIQ_200.data.u8[5] = 0xBB; break;
++counter_200; case 8:
break; IONIQ_200.data.u8[5] = 0xFB;
case 8: counter_200 = 5;
IONIQ_200.data.u8[5] = 0xFB; break;
counter_200 = 5;
break;
}
transmit_can_frame(&IONIQ_200);
transmit_can_frame(&IONIQ_523);
transmit_can_frame(&IONIQ_524);
} }
transmit_can_frame(&IONIQ_200);
transmit_can_frame(&IONIQ_523);
transmit_can_frame(&IONIQ_524);
} }
} }
@ -368,9 +363,7 @@ void HyundaiIoniq28Battery::setup(void) { // Performs one time setup at startup
datalayer_battery->info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV; datalayer_battery->info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_MV;
datalayer_battery->info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV; datalayer_battery->info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_MV;
datalayer_battery->info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_MV; datalayer_battery->info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_MV;
if (allows_contactor_closing) { datalayer.system.status.battery_allows_contactor_closing = true;
*allows_contactor_closing = true;
}
} }
uint16_t HyundaiIoniq28Battery::get_lead_acid_voltage() const { uint16_t HyundaiIoniq28Battery::get_lead_acid_voltage() const {

View file

@ -35,12 +35,6 @@ class HyundaiIoniq28Battery : public CanBattery {
DATALAYER_BATTERY_TYPE* datalayer_battery; DATALAYER_BATTERY_TYPE* datalayer_battery;
// If not null, this battery decides when the contactor can be closed and writes the value here.
bool* allows_contactor_closing;
// If not null, this battery listens to this boolean to determine whether contactor closing is allowed
bool* contactor_closing_allowed;
static const int MAX_PACK_VOLTAGE_DV = 4050; //5000 = 500.0V static const int MAX_PACK_VOLTAGE_DV = 4050; //5000 = 500.0V
static const int MIN_PACK_VOLTAGE_DV = 2880; static const int MIN_PACK_VOLTAGE_DV = 2880;
static const int MAX_CELL_DEVIATION_MV = 150; static const int MAX_CELL_DEVIATION_MV = 150;