...
 
Commits (2)
......@@ -166,7 +166,7 @@ events = {
"EventBadAC": "Poll of mains reports bad AC voltage",
"EventBatteryWarn": "Poll of BMS reports Time ToEmpty <= ShutdownTime + WarningTime",
"EventBatteryLow": "Poll of BMS reports TimeToEmpty <= ShutdownTime",
"EventHostOff": "Poll of host load sensor shows no current draw",
"EventHostOff": "Poll of host load sensor shows current draw less than threshold",
"EventUnreachable": "Code cannot reach this event",
}
......@@ -189,7 +189,8 @@ MAINSOFF = production("MainsOff",
alarm="DOWN")
MAINSDROP = production("MainsDrop",
trigger="EventBadAC",
meaning="Mains power has dropped")
meaning="Mains power has dropped",
alarm="DOWN")
RESTORED = production("Restored",
trigger="EventGoodAC",
meaning="Power is restored",
......@@ -239,7 +240,7 @@ if __name__ == '__main__':
render.state("OnBattery", "On battery power")
render.action("MainsUp", "OnBattery", MAINSDROP)
render.action("OnBattery", "Overtime", DWELLWARNING)
render.state("Overtime", "User warned of shutdown")
render.state("Overtime", "User warned of upcoming shutdown")
render.action("Overtime", "PreShutdown", DWELLTIMEOUT)
render.state("PreShutdown", "Awaiting power drop")
render.action("PreShutdown", "ChargeWait", RESTORED)
......
......@@ -110,6 +110,7 @@ These policy parameters control the state transitions:
| Parameter | Default | Meaning
| ShutdownTime | 30 sec | Time required for host shutdown
| WarningTime | 60 sec | Desired warning margin before shutdown
| HostDrainThreshold | 10V | Lowest expected draw of shut down host.
|========================================================================
In the following state diagram, ovals are are possible values of a
......
......@@ -28,6 +28,7 @@ type policyConfig struct {
WarningTime time.Duration
QuietTime time.Duration
VoltageThreshold float32
HostDrainThreshold int
HostPair int
MasterSlaves [][]string
PowerButton uint
......@@ -116,6 +117,7 @@ func init() {
PolicyConfiguration = policyConfig{
ShutdownTime: 30 * time.Second, // Time required for host shutdown
WarningTime: 60 * time.Second, // Desired warning margin before shutdown
HostDrainThreshold: 10,
QuietTime: 10 * time.Millisecond,
VoltageThreshold: 0.90,
HostPair: 1,
......@@ -309,7 +311,7 @@ func fireEvents(prev *Observables, ob *Observables) {
hostSensor := PolicyConfiguration.HostSensor()
nv := ob.LoadMap[hostSensor]
ov := prev.LoadMap[hostSensor]
if ov != 0 && nv == 0 {
if ov >= PolicyConfiguration.HostDrainThreshold && nv < PolicyConfiguration.HostDrainThreshold {
Transition(EventHostOff)
}
......