Documentation
¶
Overview ¶
Package podsim simulates a BenchPod for tests and local development: the cloud side of its firmware (stm32h563/src/cloud_client.c), with the pod's hardware and command layer in a benchsim.Sim behind it. It has an Ed25519 identity, logs in to the server's pod WebSocket exactly like the firmware (challenge, signed nonce, host-bound v2), announces its capabilities, runs the JSON commands the server and the web app send through the Sim, and carries tunnels as the Sim's LAN protocol.
What it models on purpose, because the real pod does and the server's bugs live there:
- ONE cloud command runs at a time; a second gets the error "device busy" at once.
- A reboot is a new boot id, the LA I/O voltage unset again, target power off, the lease gone and an OTA image staged in PSRAM lost, with the connection down for a while.
- A reconnect without a reboot (a dropped link) keeps all of that, like the firmware.
- While a cloud consumer holds the pod's lease (lease.state frames), LAN commands are limited to light reads.
It is dev/test only: nothing in the production image imports it.
Index ¶
- type CmdLogEntry
- type Config
- type OTASummary
- type Pod
- func (p *Pod) Close()
- func (p *Pod) Commands() []CmdLogEntry
- func (p *Pod) ControlHandler() http.Handler
- func (p *Pod) DeviceID() string
- func (p *Pod) Drop(down time.Duration)
- func (p *Pod) PublicKey() string
- func (p *Pod) Reboot(down time.Duration)
- func (p *Pod) Register(ctx context.Context) error
- func (p *Pod) Reregister(ctx context.Context, name string) error
- func (p *Pod) Run(ctx context.Context) error
- func (p *Pod) RunLAN(cmd map[string]any) (data any, errMsg string)
- func (p *Pod) ServeLAN(ln net.Listener) error
- func (p *Pod) SetLatency(cmd string, d time.Duration)
- func (p *Pod) Snapshot() State
- func (p *Pod) Unregister(ctx context.Context) error
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdLogEntry ¶
type CmdLogEntry struct {
Seq int `json:"seq"`
At time.Time `json:"at"`
Source string `json:"source"` // cloud | lan
Cmd string `json:"cmd"`
Args map[string]any `json:"args,omitempty"`
Status string `json:"status"` // ok | error
Error string `json:"error,omitempty"`
Boot string `json:"boot_id"`
}
CmdLogEntry is one command the pod saw, for tests to assert on.
type Config ¶
type Config struct {
// Server is the server's origin, e.g. http://127.0.0.1:8080 (the API is under /api).
Server string
// Name is the pod's name on the owner's account.
Name string
// Email and Password sign in the owner, for registering the pod.
Email, Password string
// Firmware is the version the pod announces.
Firmware string
// Board is the announced board (the firmware's BOARD_NAME, "stm32h563", by default).
Board string
// OTAVersion is the version the pod runs after a committed OTA (default Firmware + ".1").
OTAVersion string
// V1Auth makes the pod log in with the original nonce-only signature instead of host-bound v2.
V1Auth bool
// Logf receives the pod's log lines (default log.Printf).
Logf func(format string, args ...any)
}
Config is how a simulated pod is set up.
type OTASummary ¶
type OTASummary struct {
State string `json:"state"`
Size int `json:"size"`
Received int `json:"received"`
Error string `json:"error,omitempty"`
}
OTASummary is the OTA session as tests see it.
type Pod ¶
type Pod struct {
// contains filtered or unexported fields
}
Pod is one simulated BenchPod.
func (*Pod) Close ¶
func (p *Pod) Close()
Close ends the simulated hardware and every connection to it.
func (*Pod) Commands ¶
func (p *Pod) Commands() []CmdLogEntry
Commands returns the commands the pod saw, oldest first.
func (*Pod) ControlHandler ¶
ControlHandler is the simulated pod's side door for tests that run it as its own process: read its state and command log, reboot it, drop its link, slow a command down, and talk to it like a LAN client would.
GET /healthz
GET /state State
GET /commands the commands it saw, oldest first
POST /reboot?down_ms=500 power-cycle
POST /drop?down_ms=500 the link drops, no reboot
POST /unregister delete the pod from the account (disconnects it)
POST /register?name=N register it again as a new pod (new identity)
POST /latency?cmd=X&ms=300 how long command X takes (0 = no delay)
POST /lan/command {"cmd":...} as a LAN client: {"status":"ok","data":..} or {"status":"error","message":..}
func (*Pod) Drop ¶
Drop ends the connection without a reboot (the network went away); the pod reconnects after down with its boot id and state intact.
func (*Pod) PublicKey ¶
PublicKey is the pod's identity as the server stores it (base64url, no padding).
func (*Pod) Reboot ¶
Reboot power-cycles the pod: the connection drops, the pod comes back after down with a new boot id and everything the firmware loses on a reset lost.
func (*Pod) Register ¶
Register signs the owner in and registers (or re-registers) the pod with its public key.
func (*Pod) Reregister ¶
Reregister gives the pod a fresh identity, registers it under name (when not empty) and lets the connect loop log in with it.
func (*Pod) Run ¶
Run connects the pod and keeps it connected (reconnecting after drops and reboots) until ctx ends. Register first.
func (*Pod) RunLAN ¶
RunLAN runs a command as a LAN client would (the pod's own command port): the lease gate applies, and so does the one-command-at-a-time rule.
func (*Pod) ServeLAN ¶
ServeLAN answers the pod's LAN API on ln until ln closes (the firmware's :8080).
func (*Pod) SetLatency ¶
SetLatency sets how long the pod takes to run cmd (0 removes the delay).
type State ¶
type State struct {
DeviceID string `json:"device_id"`
BootID string `json:"boot_id"`
BootCount int `json:"boot_count"`
Firmware string `json:"firmware"`
Connected bool `json:"connected"`
Busy bool `json:"busy"`
LaMV int `json:"la_mv"`
Efuse1 bool `json:"efuse1"`
Efuse2 bool `json:"efuse2"`
LeaseHeld bool `json:"lease_held"`
Holder string `json:"lease_holder,omitempty"`
OTA OTASummary `json:"ota"`
}
State is a snapshot of the pod for tests.