Device Status

Device-level data storage and functions (like max/min values, error flags, etc.)

Enums

enum ErrorFlag

Error Flags

When adding new flags, please make sure to use only up to 32 errors Each enum must represent a unique power of 2 number

Values:

enumerator ERR_BAT_UNDERVOLTAGE

Battery voltage too low

Set and cleared in Charger::discharge_control() if the battery voltage dropped to lower than absolute minimum. Load outputs should have switched off earlier.

enumerator ERR_BAT_OVERVOLTAGE

Battery voltage too high

Set directly in ISR after ADC conversion finished, cleared in Charger::charge_control() when voltage reached lower level again.

enumerator ERR_BAT_DIS_OVERCURRENT

Battery discharge overcurrent

Not used yet, reserved for future.

enumerator ERR_BAT_CHG_OVERCURRENT

Battery charge overcurrent

Not used yet, reserved for future.

enumerator ERR_BAT_DIS_UNDERTEMP

Temperature below discharge minimum limit

Set and cleared in Charger::discharge_control (with 2°C hysteresis)

enumerator ERR_BAT_DIS_OVERTEMP

Temperature above discharge maximum limit

Set and cleared in Charger::discharge_control (with 2°C hysteresis)

enumerator ERR_BAT_CHG_UNDERTEMP

Temperature below charge minimum limit

Set and cleared in Charger::charge_control (with 2°C hysteresis)

enumerator ERR_BAT_CHG_OVERTEMP

Temperature above charge maximum limit

Set and cleared in Charger::charge_control (with 2°C hysteresis)

enumerator ERR_INT_OVERTEMP

Charge controller internal temperature too high

Set and cleared by daq_update()

enumerator ERR_DCDC_HS_MOSFET_SHORT

Short-circuit in HS MOSFET

Set in Dcdc::control() and never cleared

enumerator ERR_DCDC_HS_OVERVOLTAGE

Overvoltage in HS MOSFET

Set in DAQ alert and never cleared

enumerator ERR_PWM_SWITCH_OVERVOLTAGE

Overvoltage caused by PWM switch

Set and cleared in PwmSwitch::control()

enumerator ERR_ANY_ERROR

Mask to catch all error flags (up to 32 errors)

class DeviceStatus
#include <device_status.h>

Device Status data

Stores error counters and some maximum ever measured values to EEPROM

Public Functions

void update_energy()

Updates the total energy counters for solar, battery and load bus

void update_min_max_values()

Updates the logged min/max values for voltages, power, temperatures etc.

inline void set_error(uint32_t e)

sets one or more error flags in device state

Parameters:

e – a single ErrorFlag or “bitwise ORed” ERR_XXX | ERR_YYY

inline void clear_error(uint32_t e)

clears one or more error flags in device state

Parameters:

e – a single ErrorFlag or “bitwise ORed” ERR_XXX | ERR_YYY

inline bool has_error(uint32_t e)

queries one or more error flags in device state

Parameters:

e – a single ErrorFlag or “bitwise ORed” ERR_XXX | ERR_YYY

Returns:

true if any of the error flags given in e are set in device state

Public Members

uint32_t bat_chg_total_Wh
uint32_t bat_dis_total_Wh
uint32_t solar_in_total_Wh
uint32_t load_out_total_Wh
uint32_t grid_import_total_Wh
uint32_t grid_export_total_Wh
uint16_t solar_power_max_day
uint16_t load_power_max_day
uint16_t solar_power_max_total
uint16_t load_power_max_total
float battery_voltage_max
float solar_voltage_max
float dcdc_current_max
float load_current_max
int16_t bat_temp_max
int16_t int_temp_max
int16_t mosfet_temp_max
uint32_t day_counter
uint32_t error_flags

Currently detected errors.

float internal_temp

Internal temperature (measured in MCU)