succd: log pressures in error messages

This commit is contained in:
Serge Bazanski 2024-09-28 09:46:18 +02:00
parent 451b44e31b
commit 590e93e43e
3 changed files with 31 additions and 25 deletions

View file

@ -36,24 +36,6 @@ func formatVolts(v float32) string {
return fmt.Sprintf("%.4f V", v) return fmt.Sprintf("%.4f V", v)
} }
// formatMbar formats a millibar value using scientific notation and returns a
// HTML fragment (for superscript support).
func formatMbar(v float32) template.HTML {
exp := 0
for v < 1 {
v *= 10
exp -= 1
}
for v >= 10 {
v /= 10
exp += 1
}
res := fmt.Sprintf("%.3f", v)
res += fmt.Sprintf(" x 10<sup>%d</sup>", exp)
res += " mbar"
return template.HTML(res)
}
// apiData is the data model served to the user via HTTP/WebSockets // apiData is the data model served to the user via HTTP/WebSockets
type apiData struct { type apiData struct {
// Safety interlocks. // Safety interlocks.
@ -125,7 +107,7 @@ func (s *webServer) apiData(skipSystem bool) *apiData {
ad.Safety.Failsafe = state.safety.failsafe ad.Safety.Failsafe = state.safety.failsafe
ad.Safety.HighPressure = state.safety.highPressure ad.Safety.HighPressure = state.safety.highPressure
ad.Pirani.Volts = formatVolts(volts) ad.Pirani.Volts = formatVolts(volts)
ad.Pirani.Mbar = formatMbar(mbar) ad.Pirani.Mbar = formatMbarHTML(mbar)
ad.Pirani.MbarFloat = mbar ad.Pirani.MbarFloat = mbar
ad.Pumps.RPOn = state.rpOn ad.Pumps.RPOn = state.rpOn
ad.Pumps.DPOn = state.dpOn ad.Pumps.DPOn = state.dpOn

View file

@ -78,11 +78,11 @@ func (d *daemon) processOnce(_ context.Context) error {
d.safety.failsafe = true d.safety.failsafe = true
klog.Errorf("Pirani probe seems disconnected; enabling failsafe mode") klog.Errorf("Pirani probe seems disconnected; enabling failsafe mode")
} }
} else { } else if d.piraniDetection() == piraniDetectionConnected {
if d.safety.failsafe { if d.safety.failsafe {
if mbar >= 1e2 { if mbar >= 1e2 {
d.safety.failsafe = false d.safety.failsafe = false
klog.Infof("Values are plausible again; quitting failsafe mode") klog.Infof("Pirani probe value (%s) is plausible again; quitting failsafe mode", formatMbar(mbar))
} }
} }
} }
@ -90,12 +90,12 @@ func (d *daemon) processOnce(_ context.Context) error {
if mbar >= 1e-1 { if mbar >= 1e-1 {
if !d.safety.highPressure { if !d.safety.highPressure {
d.safety.highPressure = true d.safety.highPressure = true
klog.Errorf("Pressure is too high; enabling diffusion pump lockout") klog.Errorf("Pressure is too high (%s mbar); enabling diffusion pump lockout", formatMbar(mbar))
} }
} else if mbar < (1e-1)-(1e-2) { } else if mbar < (1e-1)-(1e-2) {
if d.safety.highPressure { if d.safety.highPressure {
d.safety.highPressure = false d.safety.highPressure = false
klog.Infof("Pressure is low enough for diffusion pump operation; quitting diffusion pump lockout") klog.Infof("Pressure is low enough (%s mbar) for diffusion pump operation; quitting diffusion pump lockout", formatMbar(mbar))
} }
} }

View file

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"html/template"
"strconv" "strconv"
) )
@ -16,8 +17,25 @@ func (s *ScientificNotationValue) UnmarshalText(text []byte) error {
return nil return nil
} }
func (s *ScientificNotationValue) MarshalText() ([]byte, error) { // formatMbarHTML formats a millibar value using scientific notation and returns
v := float64(*s) // a HTML fragment (for superscript support).
func formatMbarHTML(v float32) template.HTML {
exp := 0
for v < 1 {
v *= 10
exp -= 1
}
for v >= 10 {
v /= 10
exp += 1
}
res := fmt.Sprintf("%.3f", v)
res += fmt.Sprintf(" x 10<sup>%d</sup>", exp)
res += " mbar"
return template.HTML(res)
}
func formatMbar(v float32) string {
exp := 0 exp := 0
for v < 1 { for v < 1 {
v *= 10 v *= 10
@ -29,5 +47,11 @@ func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
} }
res := fmt.Sprintf("%.3f", v) res := fmt.Sprintf("%.3f", v)
res += fmt.Sprintf("e%d", exp) res += fmt.Sprintf("e%d", exp)
return res
}
func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
v := float32(*s)
res := formatMbar(v)
return []byte(res), nil return []byte(res), nil
} }