sanity checks

This commit is contained in:
Josh Deprez 2024-10-08 16:18:56 +11:00
parent 399a371e7b
commit 98f2a24f8a

View file

@ -164,6 +164,18 @@ func mainImpl() error {
if err != nil {
return fmt.Errorf("sensor reading error: %v", err)
}
// sanity check sensor outputs:
// current = shunt / resistor, but resistor is fixed,
// so if current == 0 if and only if shunt == 0
if (p.Current == 0) != (p.Shunt == 0) {
return fmt.Errorf("current = %v but shunt = %v", p.Current, p.Shunt)
}
// power = current * voltage, similar logic
if (p.Power == 0) != (p.Current == 0 || p.Voltage == 0) {
return fmt.Errorf("power = %v but current = %v and voltage = %v", p.Power, p.Current, p.Voltage)
}
busVolts := float64(p.Voltage) / float64(physic.Volt)
busVoltageHist.Observe(busVolts)
busVoltageSumm.Observe(busVolts)