2024-09-12 01:02:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
"k8s.io/klog"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-09-27 00:11:04 +00:00
|
|
|
flagFake bool
|
|
|
|
flagListenHTTP string
|
|
|
|
flagPressureThresholdRough = ScientificNotationValue(1e-1)
|
|
|
|
flagPressureThresholdHigh = ScientificNotationValue(1e-4)
|
2024-09-12 01:02:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.BoolVar(&flagFake, "fake", false, "Enable fake mode which allows to run succd for tests outside the succbone")
|
|
|
|
flag.StringVar(&flagListenHTTP, "listen_http", ":8080", "Address at which to listen for HTTP requests")
|
2024-09-27 00:11:04 +00:00
|
|
|
flag.TextVar(&flagPressureThresholdRough, "pressure_threshold_rough", &flagPressureThresholdRough, "Threshold for opening up diffusion pump (mbar)")
|
|
|
|
flag.TextVar(&flagPressureThresholdHigh, "pressure_threshold_high", &flagPressureThresholdHigh, "Threshold for enabling high voltage circuits (mbar)")
|
2024-09-12 01:02:57 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
|
|
|
2024-09-28 06:10:33 +00:00
|
|
|
d := daemon{}
|
|
|
|
d.daemonState.rpOn = true
|
|
|
|
|
2024-09-27 00:11:04 +00:00
|
|
|
d.aboveRough.threshold = float64(flagPressureThresholdRough)
|
|
|
|
d.aboveHigh.threshold = float64(flagPressureThresholdHigh)
|
2024-09-12 01:02:57 +00:00
|
|
|
if flagFake {
|
2024-09-25 21:28:57 +00:00
|
|
|
klog.Infof("Starting with fake peripherals")
|
2024-09-12 01:02:57 +00:00
|
|
|
d.adcPirani = &fakeADC{}
|
2024-09-25 21:28:57 +00:00
|
|
|
d.gpioRoughingPump = &fakeGPIO{desc: "rp"}
|
|
|
|
d.gpioDiffusionPump = &fakeGPIO{desc: "~dp"}
|
|
|
|
d.gpioBtnPumpDown = &fakeGPIO{desc: "~pd"}
|
|
|
|
d.gpioBtnVent = &fakeGPIO{desc: "~vent"}
|
2024-09-27 00:11:04 +00:00
|
|
|
d.gpioBelowRough = &fakeGPIO{desc: "~rough"}
|
|
|
|
d.gpioBelowHigh = &fakeGPIO{desc: "~high"}
|
2024-09-12 01:02:57 +00:00
|
|
|
} else {
|
|
|
|
adc, err := newBBADC(0)
|
|
|
|
if err != nil {
|
|
|
|
klog.Exitf("Failed to setup Pirani ADC: %v", err)
|
|
|
|
}
|
|
|
|
d.adcPirani = adc
|
2024-09-25 21:28:57 +00:00
|
|
|
|
|
|
|
for _, c := range []struct {
|
|
|
|
out *gpio
|
|
|
|
num int
|
|
|
|
}{
|
|
|
|
{&d.gpioRoughingPump, 115},
|
|
|
|
{&d.gpioDiffusionPump, 49},
|
|
|
|
{&d.gpioBtnPumpDown, 48},
|
|
|
|
{&d.gpioBtnVent, 60},
|
2024-09-27 00:11:04 +00:00
|
|
|
{&d.gpioBelowRough, 30},
|
|
|
|
{&d.gpioBelowHigh, 7},
|
2024-09-25 21:28:57 +00:00
|
|
|
} {
|
|
|
|
*c.out, err = newBBGPIO(c.num, true)
|
|
|
|
if err != nil {
|
|
|
|
klog.Exitf("Failed to setup GPIO: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 06:10:33 +00:00
|
|
|
httpServer := httpServer{
|
|
|
|
d: &d,
|
|
|
|
}
|
|
|
|
httpServer.setupViews()
|
2024-09-12 01:02:57 +00:00
|
|
|
|
|
|
|
klog.Infof("Listening for HTTP at %s", flagListenHTTP)
|
|
|
|
go func() {
|
|
|
|
if err := http.ListenAndServe(flagListenHTTP, nil); err != nil {
|
|
|
|
klog.Errorf("HTTP listen failed: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
go d.process(ctx)
|
|
|
|
<-ctx.Done()
|
|
|
|
}
|