app: convert device status to C struct
DeviceStatus becomes struct device_status with prefixed functions. The error flag helpers are static inline functions in the header. The implementation stays in C++ for now, as it reads data from objects which are not converted yet. The header doesn't include the headers of these objects anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3cc24411b5
commit
a428892916
+10
-10
@@ -43,7 +43,7 @@ void check_temperature_readings()
|
||||
|
||||
ZTEST(daq, test_adc_alert_lv_undervoltage_triggering)
|
||||
{
|
||||
dev_stat.clear_error(ERR_ANY_ERROR);
|
||||
device_status_clear_error(&dev_stat, ERR_ANY_ERROR);
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100);
|
||||
daq_set_lv_limits(bat_conf.absolute_max_voltage, bat_conf.absolute_min_voltage);
|
||||
prepare_adc_filtered();
|
||||
@@ -53,7 +53,7 @@ ZTEST(daq, test_adc_alert_lv_undervoltage_triggering)
|
||||
adcval.battery_voltage = bat_conf.absolute_min_voltage - 0.1f;
|
||||
prepare_adc_readings(adcval);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_low));
|
||||
zassert_equal(dev_stat.has_error(ERR_LOAD_VOLTAGE_DIP), false);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_LOAD_VOLTAGE_DIP), false);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_low));
|
||||
load.control();
|
||||
zassert_equal(flags_check(&load.error_flags, ERR_LOAD_VOLTAGE_DIP), true);
|
||||
@@ -66,12 +66,12 @@ ZTEST(daq, test_adc_alert_lv_undervoltage_triggering)
|
||||
daq_update();
|
||||
|
||||
charger.discharge_control(&bat_conf);
|
||||
zassert_equal(dev_stat.has_error(ERR_BAT_UNDERVOLTAGE), false); // ToDo
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_BAT_UNDERVOLTAGE), false); // ToDo
|
||||
}
|
||||
|
||||
ZTEST(daq, test_adc_alert_lv_overvoltage_triggering)
|
||||
{
|
||||
dev_stat.clear_error(ERR_ANY_ERROR);
|
||||
device_status_clear_error(&dev_stat, ERR_ANY_ERROR);
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100);
|
||||
daq_set_lv_limits(bat_conf.absolute_max_voltage, bat_conf.absolute_min_voltage);
|
||||
prepare_adc_filtered();
|
||||
@@ -83,9 +83,9 @@ ZTEST(daq, test_adc_alert_lv_overvoltage_triggering)
|
||||
adcval.battery_voltage = bat_conf.absolute_max_voltage + 0.1f;
|
||||
prepare_adc_readings(adcval);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_low));
|
||||
zassert_equal(dev_stat.has_error(ERR_BAT_OVERVOLTAGE), false);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_BAT_OVERVOLTAGE), false);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_low));
|
||||
zassert_equal(dev_stat.has_error(ERR_BAT_OVERVOLTAGE), true);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_BAT_OVERVOLTAGE), true);
|
||||
// zassert_equal(pwm_switch.active(), false);
|
||||
zassert_equal(dcdc.state, DCDC_CONTROL_OFF);
|
||||
|
||||
@@ -97,12 +97,12 @@ ZTEST(daq, test_adc_alert_lv_overvoltage_triggering)
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
|
||||
charger.charge_control(&bat_conf);
|
||||
zassert_equal(dev_stat.has_error(ERR_BAT_OVERVOLTAGE), false);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_BAT_OVERVOLTAGE), false);
|
||||
}
|
||||
|
||||
ZTEST(daq, test_adc_alert_hv_overvoltage_triggering)
|
||||
{
|
||||
dev_stat.clear_error(ERR_ANY_ERROR);
|
||||
device_status_clear_error(&dev_stat, ERR_ANY_ERROR);
|
||||
daq_set_hv_limit(DT_PROP(DT_PATH(pcb), hs_voltage_max));
|
||||
prepare_adc_filtered();
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_high));
|
||||
@@ -111,9 +111,9 @@ ZTEST(daq, test_adc_alert_hv_overvoltage_triggering)
|
||||
adcval.solar_voltage = 85.0F;
|
||||
prepare_adc_readings(adcval);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_high));
|
||||
zassert_equal(dev_stat.has_error(ERR_DCDC_HS_OVERVOLTAGE), false);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_DCDC_HS_OVERVOLTAGE), false);
|
||||
daq_emul_process(DAQ_DEV, DAQ_CH(v_high));
|
||||
zassert_equal(dev_stat.has_error(ERR_DCDC_HS_OVERVOLTAGE), true);
|
||||
zassert_equal(device_status_has_error(&dev_stat, ERR_DCDC_HS_OVERVOLTAGE), true);
|
||||
zassert_equal(dcdc.state, DCDC_CONTROL_OFF);
|
||||
}
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ ZTEST(dcdc, test_boost_correct_mppt_operation)
|
||||
ZTEST(dcdc, test_fuse_destruction_forces_low_side_on)
|
||||
{
|
||||
start_buck();
|
||||
dev_stat.set_error(ERR_DCDC_HS_MOSFET_SHORT);
|
||||
device_status_set_error(&dev_stat, ERR_DCDC_HS_MOSFET_SHORT);
|
||||
|
||||
// fuse destruction is delayed by 21 calls (seconds) to be able to send out data
|
||||
for (int i = 0; i < 21; i++) {
|
||||
@@ -444,7 +444,7 @@ ZTEST(dcdc, test_fuse_destruction_forces_low_side_on)
|
||||
zassert_equal(half_bridge_get_compare(dcdc.half_bridge), 0);
|
||||
|
||||
dcdc.stop();
|
||||
dev_stat.clear_error(ERR_DCDC_HS_MOSFET_SHORT);
|
||||
device_status_clear_error(&dev_stat, ERR_DCDC_HS_MOSFET_SHORT);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(dcdc, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
@@ -25,7 +25,7 @@ ZTEST(device_status, test_reset_counters_at_start_of_day)
|
||||
|
||||
// 5 hours without sun
|
||||
for (int i = 0; i <= 5 * 60 * 60; i++) {
|
||||
dev_stat.update_energy();
|
||||
device_status_update_energy(&dev_stat);
|
||||
}
|
||||
|
||||
zassert_equal(dev_stat.solar_in_total_Wh, 10);
|
||||
@@ -43,7 +43,7 @@ ZTEST(device_status, test_reset_counters_at_start_of_day)
|
||||
|
||||
// now solar power comes back
|
||||
solar_terminal.bus->voltage = bat_terminal.bus->voltage + 1;
|
||||
dev_stat.update_energy();
|
||||
device_status_update_energy(&dev_stat);
|
||||
|
||||
// day counter should be increased and daily energy counters reset
|
||||
zassert_equal(dev_stat.day_counter, 1);
|
||||
@@ -56,35 +56,35 @@ ZTEST(device_status, test_reset_counters_at_start_of_day)
|
||||
ZTEST(device_status, test_dev_stat_new_solar_voltage_max)
|
||||
{
|
||||
solar_terminal.bus->voltage = 40;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.solar_voltage_max, 40);
|
||||
}
|
||||
|
||||
ZTEST(device_status, test_dev_stat_new_bat_voltage_max)
|
||||
{
|
||||
bat_terminal.bus->voltage = 31;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.battery_voltage_max, 31);
|
||||
}
|
||||
|
||||
ZTEST(device_status, test_dev_stat_new_dcdc_current_max)
|
||||
{
|
||||
dcdc.inductor_current = 21;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.dcdc_current_max, 21);
|
||||
}
|
||||
|
||||
ZTEST(device_status, test_dev_stat_new_load_current_max)
|
||||
{
|
||||
load.current = 21;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.load_current_max, 21);
|
||||
}
|
||||
|
||||
ZTEST(device_status, test_dev_stat_solar_power_max)
|
||||
{
|
||||
solar_terminal.power = -50;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.solar_power_max_day, 50);
|
||||
zassert_equal(dev_stat.solar_power_max_total, 50);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ ZTEST(device_status, test_dev_stat_solar_power_max)
|
||||
ZTEST(device_status, test_dev_stat_load_power_max)
|
||||
{
|
||||
load.power = 50;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.load_power_max_day, 50);
|
||||
zassert_equal(dev_stat.load_power_max_total, 50);
|
||||
}
|
||||
@@ -100,14 +100,14 @@ ZTEST(device_status, test_dev_stat_load_power_max)
|
||||
ZTEST(device_status, test_dev_stat_new_mosfet_temp_max)
|
||||
{
|
||||
dcdc.temp_mosfets = 80;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.mosfet_temp_max, 80);
|
||||
}
|
||||
|
||||
ZTEST(device_status, test_dev_stat_new_bat_temp_max)
|
||||
{
|
||||
charger.bat_temperature = 45;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.bat_temp_max, 45);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ ZTEST(device_status, test_dev_stat_new_int_temp_max)
|
||||
{
|
||||
dev_stat.int_temp_max = 20;
|
||||
dev_stat.internal_temp = 22;
|
||||
dev_stat.update_min_max_values();
|
||||
device_status_update_min_max_values(&dev_stat);
|
||||
zassert_equal(dev_stat.int_temp_max, 22);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user