Files
mesh-catalog/modules/power/cmd/power/main.go
T
jochen 76b63744e6 Carry the power draw to the bar over the bus, not through a file (hq ADR 0260)
Modules talk over the bus. The power module's bundle puts each fresh reading of its own
sampler in its state draw, keyed by the machine; the bar's block shows that state, which
the bar's bundle watches under the read the mesh grants it. A new catalogue check refuses
a module naming another module's path under /run or /var/lib.
2026-10-08 16:12:37 +02:00

45 lines
1.3 KiB
Go

// The power module's Go bundle (novox/hq ADR 0211, ADR 0198): one process the node's runtime
// launches, serving the module's tools over MCP on stdio and running its watcher beside them, which
// publishes the machine's power states on the bus.
//
// Started as `power draw` it is the module's other process instead: the sampler that publishes the
// power the machine draws for the bar, as root, because the energy counter is root's (draw.go).
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
stdio "git.novox.be/novox/mesh-sdk/go"
)
func main() {
if len(os.Args) > 1 {
if os.Args[1] != "draw" || len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "usage: power [draw]")
os.Exit(2)
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
defer stop()
if err := RunDraw(ctx, Here()); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return
}
m := Here()
w := NewWatcher(m, func(eventType string, body any) error { return stdio.Emit(eventType, body) }, DialLogin1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go w.Run(ctx)
// And the power drawn, from the module's own sampler onto the bus (novox/hq ADR 0260).
go ShareDraw(m)
if err := stdio.Serve("", Tools(m, w)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}