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