make ram use custom datatypes

This commit is contained in:
Alex Janka 2022-12-18 13:42:25 +11:00
parent 87ee197f01
commit 345650b044
2 changed files with 186 additions and 186 deletions

View file

@ -212,72 +212,68 @@ fn get_data(modbus: &Modbus) -> (Info, MpptRam, MpptEeprom) {
drop(a);
let ram_data = MpptRam {
v_pu: info.scale_voltage_f(
data_in[OffsetsRam::V_PU_HI] as f32
+ (data_in[OffsetsRam::V_PU_LO] as f32 / f32::powf(2., 16.)),
),
i_pu: info.scale_current_f(
data_in[OffsetsRam::I_PU_HI] as f32
+ (data_in[OffsetsRam::I_PU_LO] as f32 / f32::powf(2., 16.)),
),
ver_sw: data_in[OffsetsRam::VER_SW],
adc_vb_f_med: info.scale_voltage(&data_in[OffsetsRam::ADC_VB_F_MED]),
adc_vbterm_f: info.scale_voltage(&data_in[OffsetsRam::ADC_VBTERM_F]),
adc_vbs_f: info.scale_voltage(&data_in[OffsetsRam::ADC_VBS_F]),
adc_va_f: info.scale_voltage(&data_in[OffsetsRam::ADC_VA_F]),
adc_ib_f_shadow: info.scale_current(&data_in[OffsetsRam::ADC_IB_F_SHADOW]),
adc_ia_f_shadow: info.scale_current(&data_in[OffsetsRam::ADC_IA_F_SHADOW]),
adc_p12_f: data_in[OffsetsRam::ADC_P12_F] as f32 * 18.618 * f32::powf(2., -15.),
adc_p3_f: data_in[OffsetsRam::ADC_P3_F] as f32 * 6.6 * f32::powf(2., -15.),
adc_pmeter_f: data_in[OffsetsRam::ADC_PMETER_F] as f32 * 18.618 * f32::powf(2., -15.),
adc_p18_f: data_in[OffsetsRam::ADC_P18_F] as f32 * 3. * f32::powf(2., -15.),
adc_v_ref: data_in[OffsetsRam::ADC_V_REF] as f32 * 3. * f32::powf(2., -15.),
t_hs: data_in[OffsetsRam::T_HS],
t_rts: data_in[OffsetsRam::T_RTS],
t_batt: data_in[OffsetsRam::T_BATT],
adc_vb_f_1m: info.scale_voltage(&data_in[OffsetsRam::ADC_VB_F_1M]),
adc_ib_f_1m: info.scale_current(&data_in[OffsetsRam::ADC_IB_F_1M]),
vb_min: info.scale_voltage(&data_in[OffsetsRam::VB_MIN]),
vb_max: info.scale_voltage(&data_in[OffsetsRam::VB_MAX]),
hourmeter_hi: data_in[OffsetsRam::HOURMETER_HI],
hourmeter_lo: data_in[OffsetsRam::HOURMETER_LO],
fault_all: data_in[OffsetsRam::FAULT_ALL],
alarm_hi: data_in[OffsetsRam::ALARM_HI],
alarm_lo: data_in[OffsetsRam::ALARM_LO],
dip_all: data_in[OffsetsRam::DIP_ALL],
led_state: data_in[OffsetsRam::LED_STATE],
charge_state: data_in[OffsetsRam::CHARGE_STATE],
vb_ref: info.scale_voltage(&data_in[OffsetsRam::VB_REF]),
ahc_r_hi: data_in[OffsetsRam::AHC_R_HI],
ahc_r_lo: data_in[OffsetsRam::AHC_R_LO],
ahc_t_hi: data_in[OffsetsRam::AHC_T_HI],
ahc_t_lo: data_in[OffsetsRam::AHC_T_LO],
kwhc_r: data_in[OffsetsRam::KWHC_R],
kwhc_t: data_in[OffsetsRam::KWHC_T],
power_out_shadow: info.scale_power(&data_in[OffsetsRam::POWER_OUT_SHADOW]),
power_in_shadow: info.scale_power(&data_in[OffsetsRam::POWER_IN_SHADOW]),
sweep_pin_max: info.scale_power(&data_in[OffsetsRam::SWEEP_PIN_MAX]),
sweep_vmp: info.scale_voltage(&data_in[OffsetsRam::SWEEP_VMP]),
sweep_voc: info.scale_voltage(&data_in[OffsetsRam::SWEEP_VOC]),
vb_min_daily: info.scale_voltage(&data_in[OffsetsRam::VB_MIN_DAILY]),
vb_max_daily: info.scale_voltage(&data_in[OffsetsRam::VB_MAX_DAILY]),
va_max_daily: info.scale_voltage(&data_in[OffsetsRam::VA_MAX_DAILY]),
ahc_daily: data_in[OffsetsRam::AHC_DAILY] as f32 * 0.1,
whc_daily: data_in[OffsetsRam::WHC_DAILY],
flags_daily: data_in[OffsetsRam::FLAGS_DAILY],
pout_max_daily: info.scale_power(&data_in[OffsetsRam::POUT_MAX_DAILY]),
tb_min_daily: data_in[OffsetsRam::TB_MIN_DAILY],
tb_max_daily: data_in[OffsetsRam::TB_MAX_DAILY],
fault_daily: data_in[OffsetsRam::FAULT_DAILY],
alarm_daily_hi: data_in[OffsetsRam::ALARM_DAILY_HI],
alarm_daily_lo: data_in[OffsetsRam::ALARM_DAILY_LO],
time_ab_daily: data_in[OffsetsRam::TIME_AB_DAILY],
time_eq_daily: data_in[OffsetsRam::TIME_EQ_DAILY],
time_fl_daily: data_in[OffsetsRam::TIME_FL_DAILY],
ib_ref_slave: data_in[OffsetsRam::IB_REF_SLAVE] as f32 * 80. * f32::powf(2., -15.),
vb_ref_slave: info.scale_voltage(&data_in[OffsetsRam::VB_REF_SLAVE]),
va_ref_fixed: info.scale_voltage(&data_in[OffsetsRam::VA_REF_FIXED]),
va_ref_fixed_pct: data_in[OffsetsRam::VA_REF_FIXED_PCT] as f32 * 100. * f32::powf(2., -16.),
v_pu_hi: Raw::from_u16(data_in[OffsetsRam::V_PU_HI]),
v_pu_lo: Raw::from_u16(data_in[OffsetsRam::V_PU_LO]),
i_pu_hi: Raw::from_u16(data_in[OffsetsRam::I_PU_HI]),
i_pu_lo: Raw::from_u16(data_in[OffsetsRam::I_PU_LO]),
ver_sw: Raw::from_u16(data_in[OffsetsRam::VER_SW]),
adc_vb_f_med: Raw::from_u16(data_in[OffsetsRam::ADC_VB_F_MED]),
adc_vbterm_f: Raw::from_u16(data_in[OffsetsRam::ADC_VBTERM_F]),
adc_vbs_f: Raw::from_u16(data_in[OffsetsRam::ADC_VBS_F]),
adc_va_f: Raw::from_u16(data_in[OffsetsRam::ADC_VA_F]),
adc_ib_f_shadow: Raw::from_u16(data_in[OffsetsRam::ADC_IB_F_SHADOW]),
adc_ia_f_shadow: Raw::from_u16(data_in[OffsetsRam::ADC_IA_F_SHADOW]),
adc_p12_f: Raw::from_u16(data_in[OffsetsRam::ADC_P12_F]),
adc_p3_f: Raw::from_u16(data_in[OffsetsRam::ADC_P3_F]),
adc_pmeter_f: Raw::from_u16(data_in[OffsetsRam::ADC_PMETER_F]),
adc_p18_f: Raw::from_u16(data_in[OffsetsRam::ADC_P18_F]),
adc_v_ref: Raw::from_u16(data_in[OffsetsRam::ADC_V_REF]),
t_hs: Raw::from_u16(data_in[OffsetsRam::T_HS]),
t_rts: Raw::from_u16(data_in[OffsetsRam::T_RTS]),
t_batt: Raw::from_u16(data_in[OffsetsRam::T_BATT]),
adc_vb_f_1m: Raw::from_u16(data_in[OffsetsRam::ADC_VB_F_1M]),
adc_ib_f_1m: Raw::from_u16(data_in[OffsetsRam::ADC_IB_F_1M]),
vb_min: Raw::from_u16(data_in[OffsetsRam::VB_MIN]),
vb_max: Raw::from_u16(data_in[OffsetsRam::VB_MAX]),
hourmeter_hi: Raw::from_u16(data_in[OffsetsRam::HOURMETER_HI]),
hourmeter_lo: Raw::from_u16(data_in[OffsetsRam::HOURMETER_LO]),
fault_all: Raw::from_u16(data_in[OffsetsRam::FAULT_ALL]),
alarm_hi: Raw::from_u16(data_in[OffsetsRam::ALARM_HI]),
alarm_lo: Raw::from_u16(data_in[OffsetsRam::ALARM_LO]),
dip_all: Raw::from_u16(data_in[OffsetsRam::DIP_ALL]),
led_state: Raw::from_u16(data_in[OffsetsRam::LED_STATE]),
charge_state: Raw::from_u16(data_in[OffsetsRam::CHARGE_STATE]),
vb_ref: Raw::from_u16(data_in[OffsetsRam::VB_REF]),
ahc_r_hi: Raw::from_u16(data_in[OffsetsRam::AHC_R_HI]),
ahc_r_lo: Raw::from_u16(data_in[OffsetsRam::AHC_R_LO]),
ahc_t_hi: Raw::from_u16(data_in[OffsetsRam::AHC_T_HI]),
ahc_t_lo: Raw::from_u16(data_in[OffsetsRam::AHC_T_LO]),
kwhc_r: Raw::from_u16(data_in[OffsetsRam::KWHC_R]),
kwhc_t: Raw::from_u16(data_in[OffsetsRam::KWHC_T]),
power_out_shadow: Raw::from_u16(data_in[OffsetsRam::POWER_OUT_SHADOW]),
power_in_shadow: Raw::from_u16(data_in[OffsetsRam::POWER_IN_SHADOW]),
sweep_pin_max: Raw::from_u16(data_in[OffsetsRam::SWEEP_PIN_MAX]),
sweep_vmp: Raw::from_u16(data_in[OffsetsRam::SWEEP_VMP]),
sweep_voc: Raw::from_u16(data_in[OffsetsRam::SWEEP_VOC]),
vb_min_daily: Raw::from_u16(data_in[OffsetsRam::VB_MIN_DAILY]),
vb_max_daily: Raw::from_u16(data_in[OffsetsRam::VB_MAX_DAILY]),
va_max_daily: Raw::from_u16(data_in[OffsetsRam::VA_MAX_DAILY]),
ahc_daily: Raw::from_u16(data_in[OffsetsRam::AHC_DAILY]),
whc_daily: Raw::from_u16(data_in[OffsetsRam::WHC_DAILY]),
flags_daily: Raw::from_u16(data_in[OffsetsRam::FLAGS_DAILY]),
pout_max_daily: Raw::from_u16(data_in[OffsetsRam::POUT_MAX_DAILY]),
tb_min_daily: Raw::from_u16(data_in[OffsetsRam::TB_MIN_DAILY]),
tb_max_daily: Raw::from_u16(data_in[OffsetsRam::TB_MAX_DAILY]),
fault_daily: Raw::from_u16(data_in[OffsetsRam::FAULT_DAILY]),
alarm_daily_hi: Raw::from_u16(data_in[OffsetsRam::ALARM_DAILY_HI]),
alarm_daily_lo: Raw::from_u16(data_in[OffsetsRam::ALARM_DAILY_LO]),
time_ab_daily: Raw::from_u16(data_in[OffsetsRam::TIME_AB_DAILY]),
time_eq_daily: Raw::from_u16(data_in[OffsetsRam::TIME_EQ_DAILY]),
time_fl_daily: Raw::from_u16(data_in[OffsetsRam::TIME_FL_DAILY]),
ib_ref_slave: Raw::from_u16(data_in[OffsetsRam::IB_REF_SLAVE]),
vb_ref_slave: Raw::from_u16(data_in[OffsetsRam::VB_REF_SLAVE]),
va_ref_fixed: Raw::from_u16(data_in[OffsetsRam::VA_REF_FIXED]),
va_ref_fixed_pct: Raw::from_u16(data_in[OffsetsRam::VA_REF_FIXED_PCT]),
};
let mut data_in: [u16; EEPROM_DATA_SIZE as usize + 1] = [0; EEPROM_DATA_SIZE as usize + 1];

View file

@ -5,138 +5,142 @@ use std::fmt::{self, Debug, Display};
#[derive(Serialize, Deserialize, Debug)]
pub struct MpptRam {
// scaling values
pub v_pu: f32,
pub i_pu: f32,
pub ver_sw: u16,
pub v_pu_hi: Raw,
pub v_pu_lo: Raw,
pub i_pu_hi: Raw,
pub i_pu_lo: Raw,
pub ver_sw: Raw,
// filtered ADC
pub adc_vb_f_med: f32,
pub adc_vbterm_f: f32,
pub adc_vbs_f: f32,
pub adc_va_f: f32,
pub adc_ib_f_shadow: f32,
pub adc_ia_f_shadow: f32,
pub adc_p12_f: f32,
pub adc_p3_f: f32,
pub adc_pmeter_f: f32,
pub adc_p18_f: f32,
pub adc_v_ref: f32,
pub adc_vb_f_med: Raw,
pub adc_vbterm_f: Raw,
pub adc_vbs_f: Raw,
pub adc_va_f: Raw,
pub adc_ib_f_shadow: Raw,
pub adc_ia_f_shadow: Raw,
pub adc_p12_f: Raw,
pub adc_p3_f: Raw,
pub adc_pmeter_f: Raw,
pub adc_p18_f: Raw,
pub adc_v_ref: Raw,
// temperatures
pub t_hs: u16,
pub t_rts: u16,
pub t_batt: u16,
pub t_hs: Raw,
pub t_rts: Raw,
pub t_batt: Raw,
// status
pub adc_vb_f_1m: f32,
pub adc_ib_f_1m: f32,
pub vb_min: f32,
pub vb_max: f32,
pub hourmeter_hi: u16,
pub hourmeter_lo: u16,
pub fault_all: u16,
pub alarm_hi: u16,
pub alarm_lo: u16,
pub dip_all: u16,
pub led_state: u16,
pub adc_vb_f_1m: Raw,
pub adc_ib_f_1m: Raw,
pub vb_min: Raw,
pub vb_max: Raw,
pub hourmeter_hi: Raw,
pub hourmeter_lo: Raw,
pub fault_all: Raw,
pub alarm_hi: Raw,
pub alarm_lo: Raw,
pub dip_all: Raw,
pub led_state: Raw,
// charger
pub charge_state: u16,
pub vb_ref: f32,
pub ahc_r_hi: u16,
pub ahc_r_lo: u16,
pub ahc_t_hi: u16,
pub ahc_t_lo: u16,
pub kwhc_r: u16,
pub kwhc_t: u16,
pub charge_state: Raw,
pub vb_ref: Raw,
pub ahc_r_hi: Raw,
pub ahc_r_lo: Raw,
pub ahc_t_hi: Raw,
pub ahc_t_lo: Raw,
pub kwhc_r: Raw,
pub kwhc_t: Raw,
// MpptRam
pub power_out_shadow: f32,
pub power_in_shadow: f32,
pub sweep_pin_max: f32,
pub sweep_vmp: f32,
pub sweep_voc: f32,
pub power_out_shadow: Raw,
pub power_in_shadow: Raw,
pub sweep_pin_max: Raw,
pub sweep_vmp: Raw,
pub sweep_voc: Raw,
// logger - today's values
pub vb_min_daily: f32,
pub vb_max_daily: f32,
pub va_max_daily: f32,
pub ahc_daily: f32,
pub whc_daily: u16,
pub flags_daily: u16,
pub pout_max_daily: f32,
pub tb_min_daily: u16,
pub tb_max_daily: u16,
pub fault_daily: u16,
pub alarm_daily_hi: u16,
pub alarm_daily_lo: u16,
pub time_ab_daily: u16,
pub time_eq_daily: u16,
pub time_fl_daily: u16,
pub vb_min_daily: Raw,
pub vb_max_daily: Raw,
pub va_max_daily: Raw,
pub ahc_daily: Raw,
pub whc_daily: Raw,
pub flags_daily: Raw,
pub pout_max_daily: Raw,
pub tb_min_daily: Raw,
pub tb_max_daily: Raw,
pub fault_daily: Raw,
pub alarm_daily_hi: Raw,
pub alarm_daily_lo: Raw,
pub time_ab_daily: Raw,
pub time_eq_daily: Raw,
pub time_fl_daily: Raw,
// manual control
pub ib_ref_slave: f32,
pub vb_ref_slave: f32,
pub va_ref_fixed: f32,
pub va_ref_fixed_pct: f32,
pub ib_ref_slave: Raw,
pub vb_ref_slave: Raw,
pub va_ref_fixed: Raw,
pub va_ref_fixed_pct: Raw,
}
impl MpptRam {
pub fn get_fake() -> Self {
Self {
v_pu: 0.,
i_pu: 0.,
ver_sw: 0,
adc_vb_f_med: 0.,
adc_vbterm_f: 0.,
adc_vbs_f: 0.,
adc_va_f: 0.,
adc_ib_f_shadow: 0.,
adc_ia_f_shadow: 0.,
adc_p12_f: 0.,
adc_p3_f: 0.,
adc_pmeter_f: 0.,
adc_p18_f: 0.,
adc_v_ref: 0.,
t_hs: 0,
t_rts: 0,
t_batt: 0,
adc_vb_f_1m: 0.,
adc_ib_f_1m: 0.,
vb_min: 0.,
vb_max: 0.,
hourmeter_hi: 0,
hourmeter_lo: 0,
fault_all: 0,
alarm_hi: 0,
alarm_lo: 0,
dip_all: 0,
led_state: 0,
charge_state: 0,
vb_ref: 0.,
ahc_r_hi: 0,
ahc_r_lo: 0,
ahc_t_hi: 0,
ahc_t_lo: 0,
kwhc_r: 0,
kwhc_t: 0,
power_out_shadow: 0.,
power_in_shadow: 0.,
sweep_pin_max: 0.,
sweep_vmp: 0.,
sweep_voc: 0.,
vb_min_daily: 0.,
vb_max_daily: 0.,
va_max_daily: 0.,
ahc_daily: 0.,
whc_daily: 0,
flags_daily: 0,
pout_max_daily: 0.,
tb_min_daily: 0,
tb_max_daily: 0,
fault_daily: 0,
alarm_daily_hi: 0,
alarm_daily_lo: 0,
time_ab_daily: 0,
time_eq_daily: 0,
time_fl_daily: 0,
ib_ref_slave: 0.,
vb_ref_slave: 0.,
va_ref_fixed: 0.,
va_ref_fixed_pct: 0.,
v_pu_hi: Raw::from_u16(0x0000),
v_pu_lo: Raw::from_u16(0x0000),
i_pu_hi: Raw::from_u16(0x0000),
i_pu_lo: Raw::from_u16(0x0000),
ver_sw: Raw::from_u16(0x0000),
adc_vb_f_med: Raw::from_u16(0x0000),
adc_vbterm_f: Raw::from_u16(0x0000),
adc_vbs_f: Raw::from_u16(0x0000),
adc_va_f: Raw::from_u16(0x0000),
adc_ib_f_shadow: Raw::from_u16(0x0000),
adc_ia_f_shadow: Raw::from_u16(0x0000),
adc_p12_f: Raw::from_u16(0x0000),
adc_p3_f: Raw::from_u16(0x0000),
adc_pmeter_f: Raw::from_u16(0x0000),
adc_p18_f: Raw::from_u16(0x0000),
adc_v_ref: Raw::from_u16(0x0000),
t_hs: Raw::from_u16(0x0000),
t_rts: Raw::from_u16(0x0000),
t_batt: Raw::from_u16(0x0000),
adc_vb_f_1m: Raw::from_u16(0x0000),
adc_ib_f_1m: Raw::from_u16(0x0000),
vb_min: Raw::from_u16(0x0000),
vb_max: Raw::from_u16(0x0000),
hourmeter_hi: Raw::from_u16(0x0000),
hourmeter_lo: Raw::from_u16(0x0000),
fault_all: Raw::from_u16(0x0000),
alarm_hi: Raw::from_u16(0x0000),
alarm_lo: Raw::from_u16(0x0000),
dip_all: Raw::from_u16(0x0000),
led_state: Raw::from_u16(0x0000),
charge_state: Raw::from_u16(0x0000),
vb_ref: Raw::from_u16(0x0000),
ahc_r_hi: Raw::from_u16(0x0000),
ahc_r_lo: Raw::from_u16(0x0000),
ahc_t_hi: Raw::from_u16(0x0000),
ahc_t_lo: Raw::from_u16(0x0000),
kwhc_r: Raw::from_u16(0x0000),
kwhc_t: Raw::from_u16(0x0000),
power_out_shadow: Raw::from_u16(0x0000),
power_in_shadow: Raw::from_u16(0x0000),
sweep_pin_max: Raw::from_u16(0x0000),
sweep_vmp: Raw::from_u16(0x0000),
sweep_voc: Raw::from_u16(0x0000),
vb_min_daily: Raw::from_u16(0x0000),
vb_max_daily: Raw::from_u16(0x0000),
va_max_daily: Raw::from_u16(0x0000),
ahc_daily: Raw::from_u16(0x0000),
whc_daily: Raw::from_u16(0x0000),
flags_daily: Raw::from_u16(0x0000),
pout_max_daily: Raw::from_u16(0x0000),
tb_min_daily: Raw::from_u16(0x0000),
tb_max_daily: Raw::from_u16(0x0000),
fault_daily: Raw::from_u16(0x0000),
alarm_daily_hi: Raw::from_u16(0x0000),
alarm_daily_lo: Raw::from_u16(0x0000),
time_ab_daily: Raw::from_u16(0x0000),
time_eq_daily: Raw::from_u16(0x0000),
time_fl_daily: Raw::from_u16(0x0000),
ib_ref_slave: Raw::from_u16(0x0000),
vb_ref_slave: Raw::from_u16(0x0000),
va_ref_fixed: Raw::from_u16(0x0000),
va_ref_fixed_pct: Raw::from_u16(0x0000),
}
}
}