diff --git a/goTool/README.md b/goTool/README.md index 3f7b122..51fe065 100644 --- a/goTool/README.md +++ b/goTool/README.md @@ -25,7 +25,7 @@ go run . -port /dev/ttyUSB0 clients | `version` | `0x03` | Prints `version` and `git_hash` from firmware | | `clients` | `0x04` | Lists slaves registered on the master via ESP-NOW | | `deadzone` | `0x06` | Get/set accelerometer deadzone LSB (`-set`, `-value`, `-client`, `-all`) | -| `accel` | `0x18` | Read current BMA456 XYZ (raw LSB, ±2g); alias `accel-read` | +| `accel` | `0x18` | Cached slave accel snapshot from master (`ACCEL_SNAPSHOT`); alias `accel-read` | | `unicast-test` | `0x07` | Sends ESP-NOW unicast test to one slave (`-client`, `-seq`) | | `test` | — | Run an automated scenario (JSON configs under `testdata/`) | | `serve` | — | Web dashboard at `http://localhost:8080` (WebSocket live updates) | @@ -62,11 +62,91 @@ Polls the master over UART and pushes state to the browser via WebSocket (Alpine ```bash go run . -port /dev/ttyUSB0 serve go run . -port /dev/ttyUSB0 serve -addr :8080 -interval 2s +go run . -port /dev/ttyUSB0 serve -api-addr :8081 -accel-interval 16ms make gotool-serve PORT=/dev/ttyUSB0 ``` Open [http://localhost:8080](http://localhost:8080) — shows master firmware info and the ESP-NOW client table from `CLIENT_INFO`. +### External API (second HTTP server) + +`serve` starts a separate listener (default **`:8081`**, disable with `-api-addr ""`) for external programs. It shares the same UART connection as the dashboard. + +| Endpoint | Description | +|----------|-------------| +| `GET /` or `GET /api/v1/` | JSON service info (`default_interval_ms`, min/max, `serial_port`) | +| `WebSocket /ws` | Per-connection accel receive + interval; slave ESP-NOW stream control | + +Two layers: + +1. **`set_stream`** — this WebSocket connection: whether to receive `accel` JSON and at what poll rate (1 ms … 10 s per client; server UART poll uses the minimum among active subscribers). +2. **`set_accel_stream`** — firmware: whether a slave sends accel to the master over ESP-NOW (16 ms on the pod). + +Polling runs only when at least one connection has `receive_accel: true` **and** at least one slave streams (via `set_accel_stream` or dashboard `:8080`). + +**Hello** (on connect; accel is off until `set_stream`): + +```json +{"type":"hello","serial_port":"/dev/ttyUSB0","interval_ms":16,"commands":["set_stream","get_stream","set_accel_stream","get_accel_stream"]} +``` + +**Receive accel on this connection** (optional `interval_ms`, default from `-accel-interval`): + +```json +{"type":"set_stream","enable":true,"interval_ms":32} +{"type":"get_stream"} +``` + +Reply: + +```json +{"type":"stream_status","receive_accel":true,"interval_ms":32,"success":true} +``` + +**Slave ESP-NOW stream** (per `client_id`): + +```json +{"type":"set_accel_stream","client_id":16,"enable":true} +{"type":"get_accel_stream","client_id":16} +``` + +Reply: + +```json +{"type":"accel_stream_status","client_id":16,"enabled":true,"success":true} +``` + +**Accel** (only to connections with `receive_accel: true`, and only while slaves stream): + +```json +{"type":"accel","t":1716900123456789012,"success":true,"clients":[{"client_id":16,"valid":true,"x":12,"y":-34,"z":16384,"age_ms":8}]} +``` + +`t` is Unix time in nanoseconds. Each `clients[]` entry is one slave's latest cached sample (raw LSB, ±2g). + +Example (Python): + +```python +import asyncio, json, websockets + +async def main(): + async with websockets.connect("ws://127.0.0.1:8081/ws") as ws: + print(await ws.recv()) # hello + await ws.send(json.dumps({"type": "set_stream", "enable": True, "interval_ms": 16})) + print(await ws.recv()) # stream_status + await ws.send(json.dumps({"type": "set_accel_stream", "client_id": 16, "enable": True})) + print(await ws.recv()) # accel_stream_status + while True: + msg = json.loads(await ws.recv()) + if msg.get("type") != "accel" or not msg.get("success"): + continue + for c in msg.get("clients", []): + if c.get("valid"): + print(c["client_id"], c["x"], c["y"], c["z"]) + +asyncio.run(main()) +``` + If the UART device is unplugged or the port disappears, `serve` keeps running and retries on each poll interval; the UI shows **UART off** until the port is available again. The dashboard can configure nodes using the same UART commands as the CLI: @@ -78,7 +158,21 @@ The dashboard can configure nodes using the same UART commands as the CLI: | Alle Slaves | per-slave ESP-NOW (Master bleibt unverändert; CLI `-all` setzt auch den Master) | | Unicast test | `unicast-test -client ID` | -HTTP API (used by the web UI): `GET/POST /api/deadzone`, `POST /api/unicast-test`, `POST /api/find-me`, `POST /api/restart`, `POST /api/ota` (multipart field `firmware`, max 2 MiB). +HTTP API (used by the web UI): `GET/POST /api/deadzone`, `GET/PUT /api/clients/{id}/accel-stream`, `POST /api/accel-stream` (legacy / `all_clients`), `POST /api/unicast-test`, `POST /api/find-me`, `POST /api/restart`, `POST /api/ota` (multipart field `firmware`, max 2 MiB). + +**Accel stream per slave** (must be enabled before values appear; goTool polls only while at least one slave has stream on): + +```http +GET /api/clients/16/accel-stream +→ {"enabled":false,"client_id":16,"success":true} + +PUT /api/clients/16/accel-stream +Content-Type: application/json +{"enable": true} +→ {"enabled":true,"client_id":16,"success":true} +``` + +Enable all slaves: `POST /api/accel-stream` with `{"write":true,"enable":true,"all_clients":true}`. | UI / API | Behaviour | |----------|-----------| diff --git a/goTool/accel_stream_ctl.go b/goTool/accel_stream_ctl.go new file mode 100644 index 0000000..c434f43 --- /dev/null +++ b/goTool/accel_stream_ctl.go @@ -0,0 +1,40 @@ +package main + +import "sync" + +// accelStreamCtl tracks which slaves the host wants to poll for accel (mirrors firmware). +type accelStreamCtl struct { + mu sync.Mutex + enabled map[uint32]struct{} +} + +func newAccelStreamCtl() *accelStreamCtl { + return &accelStreamCtl{enabled: make(map[uint32]struct{})} +} + +func (c *accelStreamCtl) Set(clientID uint32, on bool) { + c.mu.Lock() + defer c.mu.Unlock() + if on { + c.enabled[clientID] = struct{}{} + } else { + delete(c.enabled, clientID) + } +} + +func (c *accelStreamCtl) Any() bool { + c.mu.Lock() + defer c.mu.Unlock() + return len(c.enabled) > 0 +} + +func (c *accelStreamCtl) SyncFromClients(clients []ClientView) { + c.mu.Lock() + defer c.mu.Unlock() + c.enabled = make(map[uint32]struct{}) + for _, cl := range clients { + if cl.AccelStream { + c.enabled[cl.ID] = struct{}{} + } + } +} diff --git a/goTool/api_accel_stream.go b/goTool/api_accel_stream.go new file mode 100644 index 0000000..cab1cbb --- /dev/null +++ b/goTool/api_accel_stream.go @@ -0,0 +1,220 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "strconv" + + "powerpod/gotool/pb" +) + +type accelStreamAPIRequest struct { + Write bool `json:"write"` + Enable bool `json:"enable"` + ClientID uint32 `json:"client_id"` + AllClients bool `json:"all_clients"` +} + +type accelStreamAPIResponse struct { + Enabled bool `json:"enabled"` + ClientID uint32 `json:"client_id"` + Success bool `json:"success"` + SlavesUpdated uint32 `json:"slaves_updated"` + Error string `json:"error,omitempty"` +} + +type clientAccelStreamBody struct { + Enable bool `json:"enable"` +} + +func mountAccelStreamAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, ctl *accelStreamCtl) { + mux.HandleFunc("GET /api/clients/{clientID}/accel-stream", func(w http.ResponseWriter, r *http.Request) { + clientID, err := parsePathClientID(r) + if err != nil { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: err.Error()}) + return + } + serveAccelStreamGet(w, clientID, link, hub, ctl) + }) + mux.HandleFunc("PUT /api/clients/{clientID}/accel-stream", func(w http.ResponseWriter, r *http.Request) { + clientID, err := parsePathClientID(r) + if err != nil { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: err.Error()}) + return + } + serveClientAccelStreamPut(w, r, clientID, link, hub, ctl) + }) + + mux.HandleFunc("/api/accel-stream", func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodGet: + serveAccelStreamGetQuery(w, r, link, hub, ctl) + case http.MethodPost: + serveAccelStreamPost(w, r, link, hub, ctl) + default: + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + } + }) +} + +func parsePathClientID(r *http.Request) (uint32, error) { + s := r.PathValue("clientID") + if s == "" { + return 0, fmt.Errorf("client_id required") + } + v, err := strconv.ParseUint(s, 10, 32) + if err != nil || v == 0 { + return 0, fmt.Errorf("invalid client_id") + } + return uint32(v), nil +} + +func applyAccelStreamClient(link *managedSerial, hub *wsHub, ctl *accelStreamCtl, clientID uint32, enable bool) accelStreamAPIResponse { + resp, err := link.AccelStream(&pb.AccelStreamRequest{ + Write: true, + Enable: enable, + ClientId: clientID, + }) + if err != nil { + return accelStreamAPIResponse{ + ClientID: clientID, + Error: err.Error(), + } + } + out := accelStreamAPIResponse{ + Enabled: enable, + ClientID: resp.GetClientId(), + Success: resp.GetSuccess(), + SlavesUpdated: resp.GetSlavesUpdated(), + } + if resp.GetSuccess() { + if ctl != nil { + ctl.Set(clientID, enable) + } + if hub != nil { + hub.patchClientAccelStream(clientID, enable) + } + } else { + out.Enabled = resp.GetEnabled() + } + return out +} + +func serveAccelStreamGet(w http.ResponseWriter, clientID uint32, link *managedSerial, hub *wsHub, ctl *accelStreamCtl) { + resp, err := link.AccelStreamPoll(&pb.AccelStreamRequest{ + Write: false, + ClientId: clientID, + }) + if err != nil { + writeJSON(w, http.StatusServiceUnavailable, accelStreamAPIResponse{ + ClientID: clientID, + Error: err.Error(), + }) + return + } + if ctl != nil { + ctl.Set(clientID, resp.GetEnabled()) + } + writeJSON(w, http.StatusOK, accelStreamAPIResponse{ + Enabled: resp.GetEnabled(), + ClientID: resp.GetClientId(), + Success: resp.GetSuccess(), + }) +} + +func serveAccelStreamGetQuery(w http.ResponseWriter, r *http.Request, link *managedSerial, hub *wsHub, ctl *accelStreamCtl) { + clientID, err := parseUintQuery(r, "client_id", 0) + if err != nil || clientID == 0 { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: "client_id required"}) + return + } + serveAccelStreamGet(w, clientID, link, hub, ctl) +} + +func serveClientAccelStreamPut(w http.ResponseWriter, r *http.Request, clientID uint32, link *managedSerial, hub *wsHub, ctl *accelStreamCtl) { + var body clientAccelStreamBody + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: "invalid JSON"}) + return + } + out := applyAccelStreamClient(link, hub, ctl, clientID, body.Enable) + status := http.StatusOK + if out.Error != "" { + status = http.StatusServiceUnavailable + } else if !out.Success { + status = http.StatusServiceUnavailable + } + writeJSON(w, status, out) +} + +func serveAccelStreamPost(w http.ResponseWriter, r *http.Request, link *managedSerial, hub *wsHub, ctl *accelStreamCtl) { + var body accelStreamAPIRequest + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: "invalid JSON"}) + return + } + + if body.AllClients { + updated, err := applyAccelStreamAll(link, body.Enable) + if err != nil { + writeJSON(w, http.StatusServiceUnavailable, accelStreamAPIResponse{Error: err.Error()}) + return + } + clients, _ := link.listClientsPoll() + for _, c := range clients { + if ctl != nil { + ctl.Set(c.GetId(), body.Enable) + } + if hub != nil { + hub.patchClientAccelStream(c.GetId(), body.Enable) + } + } + writeJSON(w, http.StatusOK, accelStreamAPIResponse{ + Enabled: body.Enable, + Success: updated > 0, + SlavesUpdated: updated, + }) + return + } + + if body.ClientID == 0 { + writeJSON(w, http.StatusBadRequest, accelStreamAPIResponse{Error: "client_id required"}) + return + } + + out := applyAccelStreamClient(link, hub, ctl, body.ClientID, body.Enable) + status := http.StatusOK + if out.Error != "" || !out.Success { + status = http.StatusServiceUnavailable + } + writeJSON(w, status, out) +} + +func applyAccelStreamAll(link *managedSerial, enable bool) (uint32, error) { + clients, err := link.listClients() + if err != nil { + return 0, err + } + var updated uint32 + for _, c := range clients { + resp, err := link.AccelStream(&pb.AccelStreamRequest{ + Write: true, + Enable: enable, + ClientId: c.GetId(), + }) + if err != nil { + continue + } + if resp.GetSuccess() { + updated++ + } + } + if len(clients) == 0 { + return 0, fmt.Errorf("no slaves registered") + } + if updated == 0 { + return 0, fmt.Errorf("accel stream not applied to any slave") + } + return updated, nil +} diff --git a/goTool/api_serve.go b/goTool/api_serve.go index b7dc7e4..9de85bf 100644 --- a/goTool/api_serve.go +++ b/goTool/api_serve.go @@ -67,7 +67,8 @@ type otaAPIResponse struct { Error string `json:"error,omitempty"` } -func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub) { +func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, streamCtl *accelStreamCtl) { + mountAccelStreamAPI(mux, link, hub, streamCtl) mux.HandleFunc("/api/deadzone", func(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: diff --git a/goTool/api_stream.go b/goTool/api_stream.go new file mode 100644 index 0000000..7e7b6f8 --- /dev/null +++ b/goTool/api_stream.go @@ -0,0 +1,476 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "log" + "net/http" + "sync" + "time" + + "github.com/gorilla/websocket" + "powerpod/gotool/pb" +) + +const ( + defaultAccelStreamInterval = 16 * time.Millisecond + minAPIStreamInterval = 1 * time.Millisecond + maxAPIStreamInterval = 10 * time.Second +) + +// AccelClientSample is one slave's cached accel on the master. +type AccelClientSample struct { + ClientID uint32 `json:"client_id"` + Valid bool `json:"valid"` + X int32 `json:"x,omitempty"` + Y int32 `json:"y,omitempty"` + Z int32 `json:"z,omitempty"` + AgeMs uint32 `json:"age_ms,omitempty"` +} + +// AccelStreamMessage is sent to external WebSocket clients. +type AccelStreamMessage struct { + Type string `json:"type"` // "hello" | "accel" + Serial string `json:"serial_port,omitempty"` + IntervalMs int `json:"interval_ms,omitempty"` + Commands []string `json:"commands,omitempty"` + + T int64 `json:"t,omitempty"` // Unix nanoseconds + Success bool `json:"success,omitempty"` + Clients []AccelClientSample `json:"clients,omitempty"` + Error string `json:"error,omitempty"` +} + +// StreamStatusMessage is the reply to set_stream / get_stream (this connection). +type StreamStatusMessage struct { + Type string `json:"type"` // "stream_status" + ReceiveAccel bool `json:"receive_accel"` + IntervalMs int `json:"interval_ms"` + Success bool `json:"success"` + Error string `json:"error,omitempty"` +} + +// AccelStreamStatusMessage is the reply to set_accel_stream / get_accel_stream (slave). +type AccelStreamStatusMessage struct { + Type string `json:"type"` // "accel_stream_status" + ClientID uint32 `json:"client_id"` + Enabled bool `json:"enabled"` + Success bool `json:"success"` + SlavesUpdated uint32 `json:"slaves_updated,omitempty"` + Error string `json:"error,omitempty"` +} + +type accelWSCommand struct { + Type string `json:"type"` + ClientID uint32 `json:"client_id"` + Enable *bool `json:"enable"` + IntervalMs *int `json:"interval_ms"` +} + +type APIInfoResponse struct { + Name string `json:"name"` + Version string `json:"version"` + SerialPort string `json:"serial_port"` + WebSocket string `json:"websocket"` + DefaultIntervalMs int `json:"default_interval_ms"` + MinIntervalMs int `json:"min_interval_ms"` + MaxIntervalMs int `json:"max_interval_ms"` + Description string `json:"description"` +} + +type wsSubscriber struct { + conn *websocket.Conn + receiveAccel bool + interval time.Duration + lastSent time.Time +} + +type accelStreamHub struct { + mu sync.RWMutex + clients map[*websocket.Conn]*wsSubscriber + defaultInterval time.Duration + configChanged chan struct{} +} + +func newAccelStreamHub(defaultInterval time.Duration) *accelStreamHub { + return &accelStreamHub{ + clients: make(map[*websocket.Conn]*wsSubscriber), + defaultInterval: defaultInterval, + configChanged: make(chan struct{}, 1), + } +} + +func (h *accelStreamHub) notifyConfigChanged() { + select { + case h.configChanged <- struct{}{}: + default: + } +} + +func clampAPIInterval(d time.Duration) time.Duration { + if d < minAPIStreamInterval { + return minAPIStreamInterval + } + if d > maxAPIStreamInterval { + return maxAPIStreamInterval + } + return d +} + +func (h *accelStreamHub) register(conn *websocket.Conn, portName string) *wsSubscriber { + sub := &wsSubscriber{ + conn: conn, + receiveAccel: false, + interval: h.defaultInterval, + } + h.mu.Lock() + h.clients[conn] = sub + h.mu.Unlock() + + hello := AccelStreamMessage{ + Type: "hello", + Serial: portName, + IntervalMs: int(h.defaultInterval / time.Millisecond), + Commands: []string{"set_stream", "get_stream", "set_accel_stream", "get_accel_stream"}, + } + if data, err := json.Marshal(hello); err == nil { + _ = conn.WriteMessage(websocket.TextMessage, data) + } + return sub +} + +func (h *accelStreamHub) unregister(conn *websocket.Conn) { + h.mu.Lock() + delete(h.clients, conn) + h.mu.Unlock() + h.notifyConfigChanged() +} + +func (h *accelStreamHub) anyWantsAccel() bool { + h.mu.RLock() + defer h.mu.RUnlock() + for _, sub := range h.clients { + if sub.receiveAccel { + return true + } + } + return false +} + +func (h *accelStreamHub) minWantedInterval() time.Duration { + h.mu.RLock() + defer h.mu.RUnlock() + var min time.Duration + for _, sub := range h.clients { + if !sub.receiveAccel { + continue + } + if min == 0 || sub.interval < min { + min = sub.interval + } + } + if min == 0 { + return h.defaultInterval + } + return min +} + +func (h *accelStreamHub) setStream(sub *wsSubscriber, enable bool, intervalMs *int) StreamStatusMessage { + h.mu.Lock() + sub.receiveAccel = enable + if intervalMs != nil { + sub.interval = clampAPIInterval(time.Duration(*intervalMs) * time.Millisecond) + } + ms := int(sub.interval / time.Millisecond) + h.mu.Unlock() + h.notifyConfigChanged() + + return StreamStatusMessage{ + Type: "stream_status", + ReceiveAccel: enable, + IntervalMs: ms, + Success: true, + } +} + +func (h *accelStreamHub) getStream(sub *wsSubscriber) StreamStatusMessage { + h.mu.RLock() + defer h.mu.RUnlock() + return StreamStatusMessage{ + Type: "stream_status", + ReceiveAccel: sub.receiveAccel, + IntervalMs: int(sub.interval / time.Millisecond), + Success: true, + } +} + +func (h *accelStreamHub) deliver(msg AccelStreamMessage) { + data, err := json.Marshal(msg) + if err != nil { + return + } + + now := time.Now() + h.mu.Lock() + defer h.mu.Unlock() + for conn, sub := range h.clients { + if !sub.receiveAccel { + continue + } + if !sub.lastSent.IsZero() && now.Sub(sub.lastSent) < sub.interval { + continue + } + sub.lastSent = now + if err := conn.WriteMessage(websocket.TextMessage, data); err != nil { + delete(h.clients, conn) + _ = conn.Close() + } + } +} + +func runAccelStreamer(link *managedSerial, hub *accelStreamHub, dash *wsHub, ctl *accelStreamCtl, stop <-chan struct{}) { + var ticker *time.Ticker + var tick <-chan time.Time + + resetTicker := func() { + if ticker != nil { + ticker.Stop() + } + interval := hub.minWantedInterval() + ticker = time.NewTicker(interval) + tick = ticker.C + } + resetTicker() + defer func() { + if ticker != nil { + ticker.Stop() + } + }() + + for { + select { + case <-stop: + return + case <-hub.configChanged: + resetTicker() + case <-tick: + if !hub.anyWantsAccel() { + continue + } + if !accelStreamPollingActive(dash, ctl) { + continue + } + now := time.Now().UnixNano() + resp, err := link.readAccelSnapshotPoll(0) + if errors.Is(err, errUARTBusy) { + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: false, + Error: "uart busy", + }) + continue + } + if err != nil { + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: false, + Error: err.Error(), + }) + continue + } + clients := make([]AccelClientSample, 0, len(resp.GetSamples())) + for _, s := range resp.GetSamples() { + clients = append(clients, AccelClientSample{ + ClientID: s.GetClientId(), + Valid: s.GetValid(), + X: s.GetX(), + Y: s.GetY(), + Z: s.GetZ(), + AgeMs: s.GetAgeMs(), + }) + } + hub.deliver(AccelStreamMessage{ + Type: "accel", + T: now, + Success: true, + Clients: clients, + }) + } + } +} + +func accelStreamPollingActive(dash *wsHub, ctl *accelStreamCtl) bool { + if ctl != nil && ctl.Any() { + return true + } + return dash != nil && dash.anyAccelStreamEnabled() +} + +func writeStreamStatus(conn *websocket.Conn, msg StreamStatusMessage) { + data, err := json.Marshal(msg) + if err != nil { + return + } + _ = conn.WriteMessage(websocket.TextMessage, data) +} + +func writeAccelStreamStatus(conn *websocket.Conn, out accelStreamAPIResponse) { + msg := AccelStreamStatusMessage{ + Type: "accel_stream_status", + ClientID: out.ClientID, + Enabled: out.Enabled, + Success: out.Success, + SlavesUpdated: out.SlavesUpdated, + Error: out.Error, + } + data, err := json.Marshal(msg) + if err != nil { + return + } + _ = conn.WriteMessage(websocket.TextMessage, data) +} + +func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, hub *accelStreamHub) { + var cmd accelWSCommand + if err := json.Unmarshal(data, &cmd); err != nil { + writeStreamStatus(conn, StreamStatusMessage{Type: "stream_status", Error: "invalid JSON"}) + return + } + + switch cmd.Type { + case "set_stream": + if cmd.Enable == nil { + writeStreamStatus(conn, StreamStatusMessage{ + Type: "stream_status", + Error: "enable required", + }) + return + } + writeStreamStatus(conn, hub.setStream(sub, *cmd.Enable, cmd.IntervalMs)) + + case "get_stream": + writeStreamStatus(conn, hub.getStream(sub)) + + case "set_accel_stream": + if cmd.ClientID == 0 { + writeAccelStreamStatus(conn, accelStreamAPIResponse{Error: "client_id required"}) + return + } + if cmd.Enable == nil { + writeAccelStreamStatus(conn, accelStreamAPIResponse{ + ClientID: cmd.ClientID, + Error: "enable required", + }) + return + } + writeAccelStreamStatus(conn, applyAccelStreamClient(link, dash, ctl, cmd.ClientID, *cmd.Enable)) + + case "get_accel_stream": + if cmd.ClientID == 0 { + writeAccelStreamStatus(conn, accelStreamAPIResponse{Error: "client_id required"}) + return + } + resp, err := link.AccelStreamPoll(&pb.AccelStreamRequest{ + Write: false, + ClientId: cmd.ClientID, + }) + if err != nil { + writeAccelStreamStatus(conn, accelStreamAPIResponse{ + ClientID: cmd.ClientID, + Error: err.Error(), + }) + return + } + if ctl != nil { + ctl.Set(cmd.ClientID, resp.GetEnabled()) + } + writeAccelStreamStatus(conn, accelStreamAPIResponse{ + Enabled: resp.GetEnabled(), + ClientID: resp.GetClientId(), + Success: resp.GetSuccess(), + }) + + default: + writeStreamStatus(conn, StreamStatusMessage{ + Type: "stream_status", + Error: "unknown type (set_stream, get_stream, set_accel_stream, get_accel_stream)", + }) + } +} + +func serveExternalWS(conn *websocket.Conn, link *managedSerial, dash *wsHub, ctl *accelStreamCtl, portName string, hub *accelStreamHub) { + sub := hub.register(conn, portName) + defer hub.unregister(conn) + defer conn.Close() + + for { + _, data, err := conn.ReadMessage() + if err != nil { + return + } + handleAccelWSCommand(conn, sub, data, link, dash, ctl, hub) + } +} + +func mountExternalAPI(mux *http.ServeMux, portName string, defaultInterval time.Duration, hub *accelStreamHub, link *managedSerial, dash *wsHub, ctl *accelStreamCtl) { + defMs := int(defaultInterval / time.Millisecond) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" && r.URL.Path != "/api/v1" && r.URL.Path != "/api/v1/" { + http.NotFound(w, r) + return + } + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + writeJSON(w, http.StatusOK, APIInfoResponse{ + Name: "powerpod-external-api", + Version: "1", + SerialPort: portName, + WebSocket: "/ws", + DefaultIntervalMs: defMs, + MinIntervalMs: int(minAPIStreamInterval / time.Millisecond), + MaxIntervalMs: int(maxAPIStreamInterval / time.Millisecond), + Description: "WebSocket: per-connection accel receive + interval; slave stream via set_accel_stream", + }) + }) + + mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { + conn, err := wsUpgrader.Upgrade(w, r, nil) + if err != nil { + log.Printf("api websocket upgrade: %v", err) + return + } + serveExternalWS(conn, link, dash, ctl, portName, hub) + }) +} + +func runAPIServer(portName string, link *managedSerial, addr string, defaultInterval time.Duration, dash *wsHub, ctl *accelStreamCtl, stop <-chan struct{}) *http.Server { + hub := newAccelStreamHub(defaultInterval) + go runAccelStreamer(link, hub, dash, ctl, stop) + + mux := http.NewServeMux() + mountExternalAPI(mux, portName, defaultInterval, hub, link, dash, ctl) + + srv := &http.Server{Addr: addr, Handler: mux} + go func() { + log.Printf("external API http://localhost%s WebSocket ws://localhost%s/ws (default accel interval %s, per-client via set_stream)", + addr, addr, defaultInterval.String()) + if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + log.Printf("external API server: %v", err) + } + }() + return srv +} + +func shutdownAPIServer(srv *http.Server) { + if srv == nil { + return + } + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + _ = srv.Shutdown(ctx) +} diff --git a/goTool/client_api.go b/goTool/client_api.go index e91a108..5bf7920 100644 --- a/goTool/client_api.go +++ b/goTool/client_api.go @@ -40,6 +40,70 @@ func (m *managedSerial) listClientsPoll() ([]*pb.ClientInfo, error) { return decodeClientsPayload(payload) } +func (m *managedSerial) readAccelSnapshotPoll(clientID uint32) (*pb.AccelSnapshotResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_ACCEL_SNAPSHOT, + Payload: &pb.UartMessage_AccelSnapshotRequest{ + AccelSnapshotRequest: &pb.AccelSnapshotRequest{ClientId: clientID}, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_ACCEL_SNAPSHOT)}, body...) + respPayload, err := m.exchangePayloadPoll(payload, "ACCEL_SNAPSHOT") + if err != nil { + return nil, err + } + return decodeAccelSnapshotPayload(respPayload) +} + +func (m *managedSerial) AccelStream(req *pb.AccelStreamRequest) (*pb.AccelStreamResponse, error) { + return m.accelStreamVia(m.withPort, req) +} + +func (m *managedSerial) AccelStreamPoll(req *pb.AccelStreamRequest) (*pb.AccelStreamResponse, error) { + return m.accelStreamVia(m.withPortPoll, req) +} + +// SetAccelStream enables or disables the ESP-NOW accel stream for one slave (master UART). +func (m *managedSerial) SetAccelStream(clientID uint32, enable bool) (*pb.AccelStreamResponse, error) { + return m.AccelStream(&pb.AccelStreamRequest{ + Write: true, + Enable: enable, + ClientId: clientID, + }) +} + +// GetAccelStream returns whether the accel stream is enabled for a slave on the master. +func (m *managedSerial) GetAccelStream(clientID uint32) (bool, error) { + resp, err := m.AccelStreamPoll(&pb.AccelStreamRequest{ + Write: false, + ClientId: clientID, + }) + if err != nil { + return false, err + } + if !resp.GetSuccess() { + return false, fmt.Errorf("accel stream read failed for client %d", clientID) + } + return resp.GetEnabled(), nil +} + +func (m *managedSerial) accelStreamVia( + portFn func(func(*serialPort) error) error, + req *pb.AccelStreamRequest, +) (*pb.AccelStreamResponse, error) { + var resp *pb.AccelStreamResponse + err := portFn(func(sp *serialPort) error { + var e error + resp, e = sp.AccelStream(req) + return e + }) + return resp, err +} + func (m *managedSerial) AccelDeadzone(req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) { return m.accelDeadzoneVia(m.withPort, req) } @@ -101,25 +165,43 @@ func decodeClientsPayload(payload []byte) ([]*pb.ClientInfo, error) { return info.GetClients(), nil } -func (s *serialPort) readAccel() (*pb.AccelReadResponse, error) { - payload, err := s.exchange(byte(pb.MessageType_ACCEL_READ), "ACCEL_READ") - if err != nil { - return nil, err +func decodeAccelSnapshotPayload(payload []byte) (*pb.AccelSnapshotResponse, error) { + if len(payload) < 1 { + return nil, fmt.Errorf("empty response payload") } var msg pb.UartMessage if err := proto.Unmarshal(payload[1:], &msg); err != nil { return nil, fmt.Errorf("decode: %w", err) } - if msg.GetType() != pb.MessageType_ACCEL_READ { + if msg.GetType() != pb.MessageType_ACCEL_SNAPSHOT { return nil, fmt.Errorf("unexpected type %v", msg.GetType()) } - r := msg.GetAccelReadResponse() + r := msg.GetAccelSnapshotResponse() if r == nil { - return nil, fmt.Errorf("missing accel_read_response") + return nil, fmt.Errorf("missing accel_snapshot_response") } return r, nil } +func (s *serialPort) readAccelSnapshot(clientID uint32) (*pb.AccelSnapshotResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_ACCEL_SNAPSHOT, + Payload: &pb.UartMessage_AccelSnapshotRequest{ + AccelSnapshotRequest: &pb.AccelSnapshotRequest{ClientId: clientID}, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_ACCEL_SNAPSHOT)}, body...) + respPayload, err := s.exchangePayload(payload, "ACCEL_SNAPSHOT") + if err != nil { + return nil, err + } + return decodeAccelSnapshotPayload(respPayload) +} + func (s *serialPort) getVersion() (*pb.VersionResponse, error) { payload, err := s.exchange(byte(pb.MessageType_VERSION), "VERSION") if err != nil { @@ -136,6 +218,33 @@ func (s *serialPort) listClients() ([]*pb.ClientInfo, error) { return decodeClientsPayload(payload) } +func (s *serialPort) AccelStream(req *pb.AccelStreamRequest) (*pb.AccelStreamResponse, error) { + msg := &pb.UartMessage{ + Type: pb.MessageType_ACCEL_STREAM, + Payload: &pb.UartMessage_AccelStreamRequest{ + AccelStreamRequest: req, + }, + } + body, err := proto.Marshal(msg) + if err != nil { + return nil, fmt.Errorf("encode: %w", err) + } + payload := append([]byte{byte(pb.MessageType_ACCEL_STREAM)}, body...) + respPayload, err := s.exchangePayload(payload, "ACCEL_STREAM") + if err != nil { + return nil, err + } + var respMsg pb.UartMessage + if err := proto.Unmarshal(respPayload[1:], &respMsg); err != nil { + return nil, fmt.Errorf("decode: %w", err) + } + r := respMsg.GetAccelStreamResponse() + if r == nil { + return nil, fmt.Errorf("missing accel_stream_response") + } + return r, nil +} + func (s *serialPort) accelDeadzone(req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) { msg := &pb.UartMessage{ Type: pb.MessageType_ACCEL_DEADZONE, @@ -234,6 +343,28 @@ func (s *serialPort) GetVersion() (*pb.VersionResponse, error) { return s.getVer func (s *serialPort) ListClients() ([]*pb.ClientInfo, error) { return s.listClients() } +func (s *serialPort) SetAccelStream(clientID uint32, enable bool) (*pb.AccelStreamResponse, error) { + return s.AccelStream(&pb.AccelStreamRequest{ + Write: true, + Enable: enable, + ClientId: clientID, + }) +} + +func (s *serialPort) GetAccelStream(clientID uint32) (bool, error) { + resp, err := s.AccelStream(&pb.AccelStreamRequest{ + Write: false, + ClientId: clientID, + }) + if err != nil { + return false, err + } + if !resp.GetSuccess() { + return false, fmt.Errorf("accel stream read failed for client %d", clientID) + } + return resp.GetEnabled(), nil +} + func (s *serialPort) AccelDeadzone(req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) { return s.accelDeadzone(req) } diff --git a/goTool/cmd_accel.go b/goTool/cmd_accel.go index 7ab5351..4b60249 100644 --- a/goTool/cmd_accel.go +++ b/goTool/cmd_accel.go @@ -5,13 +5,26 @@ import ( ) func runAccel(sp *serialPort) error { - r, err := sp.readAccel() + return runAccelSnapshot(sp, 0) +} + +func runAccelSnapshot(sp *serialPort, clientID uint32) error { + r, err := sp.readAccelSnapshot(clientID) if err != nil { return err } - if !r.GetSuccess() { - return fmt.Errorf("accel read failed (sensor not ready?)") + samples := r.GetSamples() + if len(samples) == 0 { + fmt.Println("no accel samples (no slaves or no ESP-NOW stream yet)") + return nil + } + for _, s := range samples { + if !s.GetValid() { + fmt.Printf("client %d: no sample yet\n", s.GetClientId()) + continue + } + fmt.Printf("client %d: x=%d y=%d z=%d (age %d ms, raw LSB ±2g)\n", + s.GetClientId(), s.GetX(), s.GetY(), s.GetZ(), s.GetAgeMs()) } - fmt.Printf("accel: x=%d y=%d z=%d (raw LSB, ±2g)\n", r.GetX(), r.GetY(), r.GetZ()) return nil } diff --git a/goTool/cmd_serve.go b/goTool/cmd_serve.go index 71e430f..e8dfb87 100644 --- a/goTool/cmd_serve.go +++ b/goTool/cmd_serve.go @@ -21,7 +21,9 @@ var wsUpgrader = websocket.Upgrader{ func runServe(portName string, baud int, args []string) error { serveFlags := flag.NewFlagSet("serve", flag.ExitOnError) - addr := serveFlags.String("addr", ":8080", "HTTP listen address") + addr := serveFlags.String("addr", ":8080", "dashboard HTTP listen address") + apiAddr := serveFlags.String("api-addr", ":8081", "external API HTTP listen address (empty to disable)") + accelInterval := serveFlags.Duration("accel-interval", defaultAccelStreamInterval, "accel WebSocket sample period on API server") interval := serveFlags.Duration("interval", 2*time.Second, "UART poll interval") if err := serveFlags.Parse(args); err != nil { return err @@ -35,12 +37,20 @@ func runServe(portName string, baud int, args []string) error { defer link.Close() hub := newWSHub() + streamCtl := newAccelStreamCtl() stop := make(chan struct{}) defer close(stop) - go runPoller(link, portName, hub, *interval, stop) + go runPoller(link, portName, hub, streamCtl, *interval, stop) + go runAccelDashboardPoller(link, hub, *accelInterval, stop) + + var apiSrv *http.Server + if *apiAddr != "" { + apiSrv = runAPIServer(portName, link, *apiAddr, *accelInterval, hub, streamCtl, stop) + defer shutdownAPIServer(apiSrv) + } mux := http.NewServeMux() - mountServeAPI(mux, link, hub) + mountServeAPI(mux, link, hub, streamCtl) mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { conn, err := wsUpgrader.Upgrade(w, r, nil) if err != nil { @@ -64,7 +74,10 @@ func runServe(portName string, baud int, args []string) error { } mux.Handle("/", http.FileServer(http.FS(ui))) - log.Printf("dashboard http://localhost%s (UART %s @ %d baud, poll %s, auto-reconnect)", - *addr, portName, baud, interval.String()) + log.Printf("dashboard http://localhost%s (UART %s @ %d baud, poll %s, accel %s, auto-reconnect)", + *addr, portName, baud, interval.String(), accelInterval.String()) + if *apiAddr == "" { + log.Printf("external API disabled (-api-addr \"\")") + } return http.ListenAndServe(*addr, mux) } diff --git a/goTool/dashboard.go b/goTool/dashboard.go index 2477286..43fe43a 100644 --- a/goTool/dashboard.go +++ b/goTool/dashboard.go @@ -32,6 +32,12 @@ type ClientView struct { Used bool `json:"used"` LastPing uint32 `json:"last_ping"` LastSuccessPing uint32 `json:"last_success_ping"` + AccelValid bool `json:"accel_valid"` + AccelX int32 `json:"accel_x"` + AccelY int32 `json:"accel_y"` + AccelZ int32 `json:"accel_z"` + AccelAgeMs uint32 `json:"accel_age_ms"` + AccelStream bool `json:"accel_stream"` } type DashboardState struct { @@ -56,6 +62,8 @@ func newWSHub() *wsHub { func (h *wsHub) setState(st DashboardState) { h.mu.Lock() + prev := h.state.Clients + st.Clients = preserveClientAccel(st.Clients, prev) h.state = st conns := make([]*websocket.Conn, 0, len(h.clients)) for c := range h.clients { @@ -89,6 +97,136 @@ func (h *wsHub) unregister(c *websocket.Conn) { h.mu.Unlock() } +func applyAccelSamples(clients []ClientView, samples []*pb.AccelSample) []ClientView { + if len(samples) == 0 { + return clients + } + byID := make(map[uint32]*pb.AccelSample, len(samples)) + for _, s := range samples { + byID[s.GetClientId()] = s + } + out := make([]ClientView, len(clients)) + for i, c := range clients { + out[i] = c + if !c.AccelStream { + out[i].AccelValid = false + continue + } + s, ok := byID[c.ID] + if !ok { + continue + } + out[i].AccelValid = s.GetValid() + if s.GetValid() { + out[i].AccelX = s.GetX() + out[i].AccelY = s.GetY() + out[i].AccelZ = s.GetZ() + out[i].AccelAgeMs = s.GetAgeMs() + } + } + return out +} + +func preserveClientAccel(newClients, oldClients []ClientView) []ClientView { + if len(oldClients) == 0 { + return newClients + } + oldByID := make(map[uint32]ClientView, len(oldClients)) + for _, c := range oldClients { + oldByID[c.ID] = c + } + out := make([]ClientView, len(newClients)) + for i, c := range newClients { + out[i] = c + if !c.AccelStream { + continue + } + prev, ok := oldByID[c.ID] + if !ok || !prev.AccelValid { + continue + } + if !c.AccelValid { + out[i].AccelValid = prev.AccelValid + out[i].AccelX = prev.AccelX + out[i].AccelY = prev.AccelY + out[i].AccelZ = prev.AccelZ + out[i].AccelAgeMs = prev.AccelAgeMs + } + } + return out +} + +func anyClientAccelStream(clients []ClientView) bool { + for _, c := range clients { + if c.AccelStream { + return true + } + } + return false +} + +// patchClientAccelStream updates stream flag immediately (e.g. after REST) and pushes WS. +func (h *wsHub) patchClientAccelStream(clientID uint32, enabled bool) { + h.mu.Lock() + for i := range h.state.Clients { + if h.state.Clients[i].ID != clientID { + continue + } + h.state.Clients[i].AccelStream = enabled + if !enabled { + h.state.Clients[i].AccelValid = false + h.state.Clients[i].AccelX = 0 + h.state.Clients[i].AccelY = 0 + h.state.Clients[i].AccelZ = 0 + h.state.Clients[i].AccelAgeMs = 0 + } + break + } + st := h.state + st.UpdatedAt = time.Now().Format(time.RFC3339) + conns := make([]*websocket.Conn, 0, len(h.clients)) + for c := range h.clients { + conns = append(conns, c) + } + h.mu.Unlock() + + data, err := json.Marshal(st) + if err != nil { + return + } + for _, c := range conns { + _ = c.WriteMessage(websocket.TextMessage, data) + } +} + +func (h *wsHub) anyAccelStreamEnabled() bool { + h.mu.RLock() + defer h.mu.RUnlock() + return anyClientAccelStream(h.state.Clients) +} + +// mergeAccel updates cached accel on clients and pushes state to dashboard WebSockets. +func (h *wsHub) mergeAccel(samples []*pb.AccelSample) { + h.mu.Lock() + st := h.state + st.Clients = applyAccelSamples(st.Clients, samples) + st.UpdatedAt = time.Now().Format(time.RFC3339) + h.state = st + conns := make([]*websocket.Conn, 0, len(h.clients)) + for c := range h.clients { + conns = append(conns, c) + } + h.mu.Unlock() + + data, err := json.Marshal(st) + if err != nil { + return + } + for _, c := range conns { + _ = c.WriteMessage(websocket.TextMessage, data) + } +} + func (h *wsHub) broadcastRaw(v any) { h.mu.RLock() conns := make([]*websocket.Conn, 0, len(h.clients)) @@ -106,7 +244,7 @@ func (h *wsHub) broadcastRaw(v any) { } } -func pollDashboard(link *managedSerial, portName string, last *DashboardState) DashboardState { +func pollDashboard(link *managedSerial, portName string, last *DashboardState, streamCtl *accelStreamCtl) DashboardState { st := DashboardState{ UpdatedAt: time.Now().Format(time.RFC3339), SerialPort: portName, @@ -152,15 +290,63 @@ func pollDashboard(link *managedSerial, portName string, last *DashboardState) D Used: c.GetUsed(), LastPing: c.GetLastPing(), LastSuccessPing: c.GetLastSuccessPing(), - } - if dz, err := readDeadzonePoll(link, c.GetId()); err == nil { - cv.Deadzone = dz + AccelStream: c.GetAccelStreamEnabled(), } st.Clients = append(st.Clients, cv) } + if anyClientAccelStream(st.Clients) { + for i := range st.Clients { + if !st.Clients[i].AccelStream { + continue + } + if dz, err := readDeadzonePoll(link, st.Clients[i].ID); err == nil { + st.Clients[i].Deadzone = dz + } + } + if snap, err := link.readAccelSnapshotPoll(0); err == nil { + st.Clients = applyAccelSamples(st.Clients, snap.GetSamples()) + } + } else { + for i, c := range clients { + if dz, err := readDeadzonePoll(link, c.GetId()); err == nil { + st.Clients[i].Deadzone = dz + } + } + } + if streamCtl != nil { + streamCtl.SyncFromClients(st.Clients) + } return st } +func runAccelDashboardPoller(link *managedSerial, hub *wsHub, interval time.Duration, stop <-chan struct{}) { + ticker := time.NewTicker(interval) + defer ticker.Stop() + + for { + select { + case <-stop: + return + case <-ticker.C: + if hub.clientCount() == 0 || !hub.anyAccelStreamEnabled() { + continue + } + snap, err := link.readAccelSnapshotPoll(0) + if err != nil { + continue + } + hub.mergeAccel(snap.GetSamples()) + } + } +} + +func (h *wsHub) clientCount() int { + h.mu.RLock() + n := len(h.clients) + h.mu.RUnlock() + return n +} + func pausedPollState(portName string, last *DashboardState) DashboardState { if last != nil && last.UARTConnected { st := *last @@ -208,14 +394,15 @@ func formatMAC(mac []byte) string { return hex.EncodeToString(mac) } -func runPoller(link *managedSerial, portName string, hub *wsHub, interval time.Duration, stop <-chan struct{}) { +func runPoller(link *managedSerial, portName string, hub *wsHub, streamCtl *accelStreamCtl, interval time.Duration, stop <-chan struct{}) { + // streamCtl kept for external API; dashboard uses hub.state AccelStream flags. ticker := time.NewTicker(interval) defer ticker.Stop() uartUp := false var lastGood DashboardState publish := func() { - st := pollDashboard(link, portName, &lastGood) + st := pollDashboard(link, portName, &lastGood, streamCtl) if st.UARTConnected && st.SerialOK { lastGood = st } diff --git a/goTool/main.go b/goTool/main.go index 0a80570..b97c0b8 100644 --- a/goTool/main.go +++ b/goTool/main.go @@ -16,7 +16,7 @@ func usage() { fmt.Fprintf(os.Stderr, " version firmware version and git hash\n") fmt.Fprintf(os.Stderr, " clients registered ESP-NOW slaves on the master\n") fmt.Fprintf(os.Stderr, " deadzone get/set accelerometer deadzone (LSB)\n") - fmt.Fprintf(os.Stderr, " accel read current accelerometer XYZ (raw LSB)\n") + fmt.Fprintf(os.Stderr, " accel read cached slave accel snapshot from master\n") fmt.Fprintf(os.Stderr, " unicast-test send ESP-NOW unicast test to one slave\n") fmt.Fprintf(os.Stderr, " test run automated scenario (see testdata/)\n") fmt.Fprintf(os.Stderr, " serve web dashboard (Bootstrap + WebSocket)\n") diff --git a/goTool/pb/uart_messages.pb.go b/goTool/pb/uart_messages.pb.go index a82da2d..e03a68b 100644 --- a/goTool/pb/uart_messages.pb.go +++ b/goTool/pb/uart_messages.pb.go @@ -41,7 +41,8 @@ const ( MessageType_OTA_SLAVE_PROGRESS MessageType = 21 MessageType_FIND_ME MessageType = 22 MessageType_RESTART MessageType = 23 - MessageType_ACCEL_READ MessageType = 24 + MessageType_ACCEL_SNAPSHOT MessageType = 24 + MessageType_ACCEL_STREAM MessageType = 25 ) // Enum value maps for MessageType. @@ -64,7 +65,8 @@ var ( 21: "OTA_SLAVE_PROGRESS", 22: "FIND_ME", 23: "RESTART", - 24: "ACCEL_READ", + 24: "ACCEL_SNAPSHOT", + 25: "ACCEL_STREAM", } MessageType_value = map[string]int32{ "UNKNOWN": 0, @@ -84,7 +86,8 @@ var ( "OTA_SLAVE_PROGRESS": 21, "FIND_ME": 22, "RESTART": 23, - "ACCEL_READ": 24, + "ACCEL_SNAPSHOT": 24, + "ACCEL_STREAM": 25, } ) @@ -141,8 +144,10 @@ type UartMessage struct { // *UartMessage_EspnowFindMeResponse // *UartMessage_RestartRequest // *UartMessage_RestartResponse - // *UartMessage_AccelReadRequest - // *UartMessage_AccelReadResponse + // *UartMessage_AccelSnapshotRequest + // *UartMessage_AccelSnapshotResponse + // *UartMessage_AccelStreamRequest + // *UartMessage_AccelStreamResponse Payload isUartMessage_Payload `protobuf_oneof:"payload"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -381,19 +386,37 @@ func (x *UartMessage) GetRestartResponse() *RestartResponse { return nil } -func (x *UartMessage) GetAccelReadRequest() *AccelReadRequest { +func (x *UartMessage) GetAccelSnapshotRequest() *AccelSnapshotRequest { if x != nil { - if x, ok := x.Payload.(*UartMessage_AccelReadRequest); ok { - return x.AccelReadRequest + if x, ok := x.Payload.(*UartMessage_AccelSnapshotRequest); ok { + return x.AccelSnapshotRequest } } return nil } -func (x *UartMessage) GetAccelReadResponse() *AccelReadResponse { +func (x *UartMessage) GetAccelSnapshotResponse() *AccelSnapshotResponse { if x != nil { - if x, ok := x.Payload.(*UartMessage_AccelReadResponse); ok { - return x.AccelReadResponse + if x, ok := x.Payload.(*UartMessage_AccelSnapshotResponse); ok { + return x.AccelSnapshotResponse + } + } + return nil +} + +func (x *UartMessage) GetAccelStreamRequest() *AccelStreamRequest { + if x != nil { + if x, ok := x.Payload.(*UartMessage_AccelStreamRequest); ok { + return x.AccelStreamRequest + } + } + return nil +} + +func (x *UartMessage) GetAccelStreamResponse() *AccelStreamResponse { + if x != nil { + if x, ok := x.Payload.(*UartMessage_AccelStreamResponse); ok { + return x.AccelStreamResponse } } return nil @@ -487,12 +510,20 @@ type UartMessage_RestartResponse struct { RestartResponse *RestartResponse `protobuf:"bytes,22,opt,name=restart_response,json=restartResponse,proto3,oneof"` } -type UartMessage_AccelReadRequest struct { - AccelReadRequest *AccelReadRequest `protobuf:"bytes,23,opt,name=accel_read_request,json=accelReadRequest,proto3,oneof"` +type UartMessage_AccelSnapshotRequest struct { + AccelSnapshotRequest *AccelSnapshotRequest `protobuf:"bytes,23,opt,name=accel_snapshot_request,json=accelSnapshotRequest,proto3,oneof"` } -type UartMessage_AccelReadResponse struct { - AccelReadResponse *AccelReadResponse `protobuf:"bytes,24,opt,name=accel_read_response,json=accelReadResponse,proto3,oneof"` +type UartMessage_AccelSnapshotResponse struct { + AccelSnapshotResponse *AccelSnapshotResponse `protobuf:"bytes,24,opt,name=accel_snapshot_response,json=accelSnapshotResponse,proto3,oneof"` +} + +type UartMessage_AccelStreamRequest struct { + AccelStreamRequest *AccelStreamRequest `protobuf:"bytes,25,opt,name=accel_stream_request,json=accelStreamRequest,proto3,oneof"` +} + +type UartMessage_AccelStreamResponse struct { + AccelStreamResponse *AccelStreamResponse `protobuf:"bytes,26,opt,name=accel_stream_response,json=accelStreamResponse,proto3,oneof"` } func (*UartMessage_AckPayload) isUartMessage_Payload() {} @@ -537,9 +568,13 @@ func (*UartMessage_RestartRequest) isUartMessage_Payload() {} func (*UartMessage_RestartResponse) isUartMessage_Payload() {} -func (*UartMessage_AccelReadRequest) isUartMessage_Payload() {} +func (*UartMessage_AccelSnapshotRequest) isUartMessage_Payload() {} -func (*UartMessage_AccelReadResponse) isUartMessage_Payload() {} +func (*UartMessage_AccelSnapshotResponse) isUartMessage_Payload() {} + +func (*UartMessage_AccelStreamRequest) isUartMessage_Payload() {} + +func (*UartMessage_AccelStreamResponse) isUartMessage_Payload() {} type Ack struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -691,8 +726,10 @@ type ClientInfo struct { LastPing uint32 `protobuf:"varint,5,opt,name=last_ping,json=lastPing,proto3" json:"last_ping,omitempty"` LastSuccessPing uint32 `protobuf:"varint,6,opt,name=last_success_ping,json=lastSuccessPing,proto3" json:"last_success_ping,omitempty"` Version uint32 `protobuf:"varint,7,opt,name=version,proto3" json:"version,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // * Master: ESP-NOW accel stream enabled for this slave. + AccelStreamEnabled bool `protobuf:"varint,8,opt,name=accel_stream_enabled,json=accelStreamEnabled,proto3" json:"accel_stream_enabled,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *ClientInfo) Reset() { @@ -774,6 +811,13 @@ func (x *ClientInfo) GetVersion() uint32 { return 0 } +func (x *ClientInfo) GetAccelStreamEnabled() bool { + if x != nil { + return x.AccelStreamEnabled + } + return false +} + type ClientInfoResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Clients []*ClientInfo `protobuf:"bytes,1,rep,name=clients,proto3" json:"clients,omitempty"` @@ -1069,27 +1113,32 @@ func (x *AccelDeadzoneResponse) GetSlavesUpdated() uint32 { return 0 } -// Host → device: read current BMA456 accelerometer sample (raw LSB, ±2g range). -type AccelReadRequest struct { +// Host → master: enable/disable slave accel ESP-NOW stream (~16 ms per slave). +// write=false: read; write=true: apply. client_id 0 invalid for write (use >0 or all_clients). +type AccelStreamRequest struct { state protoimpl.MessageState `protogen:"open.v1"` + Write bool `protobuf:"varint,1,opt,name=write,proto3" json:"write,omitempty"` + Enable bool `protobuf:"varint,2,opt,name=enable,proto3" json:"enable,omitempty"` + ClientId uint32 `protobuf:"varint,3,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + AllClients bool `protobuf:"varint,4,opt,name=all_clients,json=allClients,proto3" json:"all_clients,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *AccelReadRequest) Reset() { - *x = AccelReadRequest{} +func (x *AccelStreamRequest) Reset() { + *x = AccelStreamRequest{} mi := &file_uart_messages_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *AccelReadRequest) String() string { +func (x *AccelStreamRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*AccelReadRequest) ProtoMessage() {} +func (*AccelStreamRequest) ProtoMessage() {} -func (x *AccelReadRequest) ProtoReflect() protoreflect.Message { +func (x *AccelStreamRequest) ProtoReflect() protoreflect.Message { mi := &file_uart_messages_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1101,35 +1150,63 @@ func (x *AccelReadRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use AccelReadRequest.ProtoReflect.Descriptor instead. -func (*AccelReadRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use AccelStreamRequest.ProtoReflect.Descriptor instead. +func (*AccelStreamRequest) Descriptor() ([]byte, []int) { return file_uart_messages_proto_rawDescGZIP(), []int{10} } -type AccelReadResponse struct { +func (x *AccelStreamRequest) GetWrite() bool { + if x != nil { + return x.Write + } + return false +} + +func (x *AccelStreamRequest) GetEnable() bool { + if x != nil { + return x.Enable + } + return false +} + +func (x *AccelStreamRequest) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *AccelStreamRequest) GetAllClients() bool { + if x != nil { + return x.AllClients + } + return false +} + +type AccelStreamResponse struct { state protoimpl.MessageState `protogen:"open.v1"` - Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` - X int32 `protobuf:"zigzag32,2,opt,name=x,proto3" json:"x,omitempty"` - Y int32 `protobuf:"zigzag32,3,opt,name=y,proto3" json:"y,omitempty"` - Z int32 `protobuf:"zigzag32,4,opt,name=z,proto3" json:"z,omitempty"` + Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"` + ClientId uint32 `protobuf:"varint,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + Success bool `protobuf:"varint,3,opt,name=success,proto3" json:"success,omitempty"` + SlavesUpdated uint32 `protobuf:"varint,4,opt,name=slaves_updated,json=slavesUpdated,proto3" json:"slaves_updated,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *AccelReadResponse) Reset() { - *x = AccelReadResponse{} +func (x *AccelStreamResponse) Reset() { + *x = AccelStreamResponse{} mi := &file_uart_messages_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *AccelReadResponse) String() string { +func (x *AccelStreamResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*AccelReadResponse) ProtoMessage() {} +func (*AccelStreamResponse) ProtoMessage() {} -func (x *AccelReadResponse) ProtoReflect() protoreflect.Message { +func (x *AccelStreamResponse) ProtoReflect() protoreflect.Message { mi := &file_uart_messages_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1141,39 +1218,214 @@ func (x *AccelReadResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use AccelReadResponse.ProtoReflect.Descriptor instead. -func (*AccelReadResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use AccelStreamResponse.ProtoReflect.Descriptor instead. +func (*AccelStreamResponse) Descriptor() ([]byte, []int) { return file_uart_messages_proto_rawDescGZIP(), []int{11} } -func (x *AccelReadResponse) GetSuccess() bool { +func (x *AccelStreamResponse) GetEnabled() bool { + if x != nil { + return x.Enabled + } + return false +} + +func (x *AccelStreamResponse) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *AccelStreamResponse) GetSuccess() bool { if x != nil { return x.Success } return false } -func (x *AccelReadResponse) GetX() int32 { +func (x *AccelStreamResponse) GetSlavesUpdated() uint32 { + if x != nil { + return x.SlavesUpdated + } + return 0 +} + +// Host → master: read cached accel samples from slaves (only while stream enabled). +// client_id 0 = all registered slaves; otherwise one slave. +type AccelSnapshotRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccelSnapshotRequest) Reset() { + *x = AccelSnapshotRequest{} + mi := &file_uart_messages_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccelSnapshotRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccelSnapshotRequest) ProtoMessage() {} + +func (x *AccelSnapshotRequest) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccelSnapshotRequest.ProtoReflect.Descriptor instead. +func (*AccelSnapshotRequest) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{12} +} + +func (x *AccelSnapshotRequest) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +type AccelSample struct { + state protoimpl.MessageState `protogen:"open.v1"` + ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + Valid bool `protobuf:"varint,2,opt,name=valid,proto3" json:"valid,omitempty"` + X int32 `protobuf:"zigzag32,3,opt,name=x,proto3" json:"x,omitempty"` + Y int32 `protobuf:"zigzag32,4,opt,name=y,proto3" json:"y,omitempty"` + Z int32 `protobuf:"zigzag32,5,opt,name=z,proto3" json:"z,omitempty"` + // * Milliseconds since last ESP-NOW sample from this slave. + AgeMs uint32 `protobuf:"varint,6,opt,name=age_ms,json=ageMs,proto3" json:"age_ms,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccelSample) Reset() { + *x = AccelSample{} + mi := &file_uart_messages_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccelSample) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccelSample) ProtoMessage() {} + +func (x *AccelSample) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccelSample.ProtoReflect.Descriptor instead. +func (*AccelSample) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{13} +} + +func (x *AccelSample) GetClientId() uint32 { + if x != nil { + return x.ClientId + } + return 0 +} + +func (x *AccelSample) GetValid() bool { + if x != nil { + return x.Valid + } + return false +} + +func (x *AccelSample) GetX() int32 { if x != nil { return x.X } return 0 } -func (x *AccelReadResponse) GetY() int32 { +func (x *AccelSample) GetY() int32 { if x != nil { return x.Y } return 0 } -func (x *AccelReadResponse) GetZ() int32 { +func (x *AccelSample) GetZ() int32 { if x != nil { return x.Z } return 0 } +func (x *AccelSample) GetAgeMs() uint32 { + if x != nil { + return x.AgeMs + } + return 0 +} + +type AccelSnapshotResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Samples []*AccelSample `protobuf:"bytes,1,rep,name=samples,proto3" json:"samples,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccelSnapshotResponse) Reset() { + *x = AccelSnapshotResponse{} + mi := &file_uart_messages_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccelSnapshotResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccelSnapshotResponse) ProtoMessage() {} + +func (x *AccelSnapshotResponse) ProtoReflect() protoreflect.Message { + mi := &file_uart_messages_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccelSnapshotResponse.ProtoReflect.Descriptor instead. +func (*AccelSnapshotResponse) Descriptor() ([]byte, []int) { + return file_uart_messages_proto_rawDescGZIP(), []int{14} +} + +func (x *AccelSnapshotResponse) GetSamples() []*AccelSample { + if x != nil { + return x.Samples + } + return nil +} + type EspNowUnicastTestRequest struct { state protoimpl.MessageState `protogen:"open.v1"` ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` @@ -1184,7 +1436,7 @@ type EspNowUnicastTestRequest struct { func (x *EspNowUnicastTestRequest) Reset() { *x = EspNowUnicastTestRequest{} - mi := &file_uart_messages_proto_msgTypes[12] + mi := &file_uart_messages_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1196,7 +1448,7 @@ func (x *EspNowUnicastTestRequest) String() string { func (*EspNowUnicastTestRequest) ProtoMessage() {} func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[12] + mi := &file_uart_messages_proto_msgTypes[15] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1209,7 +1461,7 @@ func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowUnicastTestRequest.ProtoReflect.Descriptor instead. func (*EspNowUnicastTestRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{12} + return file_uart_messages_proto_rawDescGZIP(), []int{15} } func (x *EspNowUnicastTestRequest) GetClientId() uint32 { @@ -1236,7 +1488,7 @@ type EspNowUnicastTestResponse struct { func (x *EspNowUnicastTestResponse) Reset() { *x = EspNowUnicastTestResponse{} - mi := &file_uart_messages_proto_msgTypes[13] + mi := &file_uart_messages_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1248,7 +1500,7 @@ func (x *EspNowUnicastTestResponse) String() string { func (*EspNowUnicastTestResponse) ProtoMessage() {} func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[13] + mi := &file_uart_messages_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1261,7 +1513,7 @@ func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowUnicastTestResponse.ProtoReflect.Descriptor instead. func (*EspNowUnicastTestResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{13} + return file_uart_messages_proto_rawDescGZIP(), []int{16} } func (x *EspNowUnicastTestResponse) GetSuccess() bool { @@ -1302,7 +1554,7 @@ type LedRingProgressRequest struct { func (x *LedRingProgressRequest) Reset() { *x = LedRingProgressRequest{} - mi := &file_uart_messages_proto_msgTypes[14] + mi := &file_uart_messages_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1314,7 +1566,7 @@ func (x *LedRingProgressRequest) String() string { func (*LedRingProgressRequest) ProtoMessage() {} func (x *LedRingProgressRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[14] + mi := &file_uart_messages_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1327,7 +1579,7 @@ func (x *LedRingProgressRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LedRingProgressRequest.ProtoReflect.Descriptor instead. func (*LedRingProgressRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{14} + return file_uart_messages_proto_rawDescGZIP(), []int{17} } func (x *LedRingProgressRequest) GetMode() uint32 { @@ -1405,7 +1657,7 @@ type LedRingProgressResponse struct { func (x *LedRingProgressResponse) Reset() { *x = LedRingProgressResponse{} - mi := &file_uart_messages_proto_msgTypes[15] + mi := &file_uart_messages_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1417,7 +1669,7 @@ func (x *LedRingProgressResponse) String() string { func (*LedRingProgressResponse) ProtoMessage() {} func (x *LedRingProgressResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[15] + mi := &file_uart_messages_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1430,7 +1682,7 @@ func (x *LedRingProgressResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use LedRingProgressResponse.ProtoReflect.Descriptor instead. func (*LedRingProgressResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{15} + return file_uart_messages_proto_rawDescGZIP(), []int{18} } func (x *LedRingProgressResponse) GetSuccess() bool { @@ -1471,7 +1723,7 @@ type EspNowFindMeRequest struct { func (x *EspNowFindMeRequest) Reset() { *x = EspNowFindMeRequest{} - mi := &file_uart_messages_proto_msgTypes[16] + mi := &file_uart_messages_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1483,7 +1735,7 @@ func (x *EspNowFindMeRequest) String() string { func (*EspNowFindMeRequest) ProtoMessage() {} func (x *EspNowFindMeRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[16] + mi := &file_uart_messages_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1496,7 +1748,7 @@ func (x *EspNowFindMeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowFindMeRequest.ProtoReflect.Descriptor instead. func (*EspNowFindMeRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{16} + return file_uart_messages_proto_rawDescGZIP(), []int{19} } func (x *EspNowFindMeRequest) GetClientId() uint32 { @@ -1516,7 +1768,7 @@ type EspNowFindMeResponse struct { func (x *EspNowFindMeResponse) Reset() { *x = EspNowFindMeResponse{} - mi := &file_uart_messages_proto_msgTypes[17] + mi := &file_uart_messages_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1528,7 +1780,7 @@ func (x *EspNowFindMeResponse) String() string { func (*EspNowFindMeResponse) ProtoMessage() {} func (x *EspNowFindMeResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[17] + mi := &file_uart_messages_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1541,7 +1793,7 @@ func (x *EspNowFindMeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EspNowFindMeResponse.ProtoReflect.Descriptor instead. func (*EspNowFindMeResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{17} + return file_uart_messages_proto_rawDescGZIP(), []int{20} } func (x *EspNowFindMeResponse) GetSuccess() bool { @@ -1568,7 +1820,7 @@ type RestartRequest struct { func (x *RestartRequest) Reset() { *x = RestartRequest{} - mi := &file_uart_messages_proto_msgTypes[18] + mi := &file_uart_messages_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1580,7 +1832,7 @@ func (x *RestartRequest) String() string { func (*RestartRequest) ProtoMessage() {} func (x *RestartRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[18] + mi := &file_uart_messages_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1593,7 +1845,7 @@ func (x *RestartRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RestartRequest.ProtoReflect.Descriptor instead. func (*RestartRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{18} + return file_uart_messages_proto_rawDescGZIP(), []int{21} } func (x *RestartRequest) GetClientId() uint32 { @@ -1613,7 +1865,7 @@ type RestartResponse struct { func (x *RestartResponse) Reset() { *x = RestartResponse{} - mi := &file_uart_messages_proto_msgTypes[19] + mi := &file_uart_messages_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1625,7 +1877,7 @@ func (x *RestartResponse) String() string { func (*RestartResponse) ProtoMessage() {} func (x *RestartResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[19] + mi := &file_uart_messages_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1638,7 +1890,7 @@ func (x *RestartResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RestartResponse.ProtoReflect.Descriptor instead. func (*RestartResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{19} + return file_uart_messages_proto_rawDescGZIP(), []int{22} } func (x *RestartResponse) GetSuccess() bool { @@ -1665,7 +1917,7 @@ type OtaStartPayload struct { func (x *OtaStartPayload) Reset() { *x = OtaStartPayload{} - mi := &file_uart_messages_proto_msgTypes[20] + mi := &file_uart_messages_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1677,7 +1929,7 @@ func (x *OtaStartPayload) String() string { func (*OtaStartPayload) ProtoMessage() {} func (x *OtaStartPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[20] + mi := &file_uart_messages_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1690,7 +1942,7 @@ func (x *OtaStartPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaStartPayload.ProtoReflect.Descriptor instead. func (*OtaStartPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{20} + return file_uart_messages_proto_rawDescGZIP(), []int{23} } func (x *OtaStartPayload) GetTotalSize() uint32 { @@ -1711,7 +1963,7 @@ type OtaPayload struct { func (x *OtaPayload) Reset() { *x = OtaPayload{} - mi := &file_uart_messages_proto_msgTypes[21] + mi := &file_uart_messages_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1723,7 +1975,7 @@ func (x *OtaPayload) String() string { func (*OtaPayload) ProtoMessage() {} func (x *OtaPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[21] + mi := &file_uart_messages_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1736,7 +1988,7 @@ func (x *OtaPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaPayload.ProtoReflect.Descriptor instead. func (*OtaPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{21} + return file_uart_messages_proto_rawDescGZIP(), []int{24} } func (x *OtaPayload) GetSeq() uint32 { @@ -1762,7 +2014,7 @@ type OtaEndPayload struct { func (x *OtaEndPayload) Reset() { *x = OtaEndPayload{} - mi := &file_uart_messages_proto_msgTypes[22] + mi := &file_uart_messages_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1774,7 +2026,7 @@ func (x *OtaEndPayload) String() string { func (*OtaEndPayload) ProtoMessage() {} func (x *OtaEndPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[22] + mi := &file_uart_messages_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1787,7 +2039,7 @@ func (x *OtaEndPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaEndPayload.ProtoReflect.Descriptor instead. func (*OtaEndPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{22} + return file_uart_messages_proto_rawDescGZIP(), []int{25} } // Device → host status (also used as ACK after each 4 KiB written). @@ -1804,7 +2056,7 @@ type OtaStatusPayload struct { func (x *OtaStatusPayload) Reset() { *x = OtaStatusPayload{} - mi := &file_uart_messages_proto_msgTypes[23] + mi := &file_uart_messages_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1816,7 +2068,7 @@ func (x *OtaStatusPayload) String() string { func (*OtaStatusPayload) ProtoMessage() {} func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[23] + mi := &file_uart_messages_proto_msgTypes[26] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1829,7 +2081,7 @@ func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaStatusPayload.ProtoReflect.Descriptor instead. func (*OtaStatusPayload) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{23} + return file_uart_messages_proto_rawDescGZIP(), []int{26} } func (x *OtaStatusPayload) GetStatus() uint32 { @@ -1870,7 +2122,7 @@ type OtaSlaveProgressRequest struct { func (x *OtaSlaveProgressRequest) Reset() { *x = OtaSlaveProgressRequest{} - mi := &file_uart_messages_proto_msgTypes[24] + mi := &file_uart_messages_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1882,7 +2134,7 @@ func (x *OtaSlaveProgressRequest) String() string { func (*OtaSlaveProgressRequest) ProtoMessage() {} func (x *OtaSlaveProgressRequest) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[24] + mi := &file_uart_messages_proto_msgTypes[27] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1895,7 +2147,7 @@ func (x *OtaSlaveProgressRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressRequest.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressRequest) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{24} + return file_uart_messages_proto_rawDescGZIP(), []int{27} } func (x *OtaSlaveProgressRequest) GetClientId() uint32 { @@ -1919,7 +2171,7 @@ type OtaSlaveProgressEntry struct { func (x *OtaSlaveProgressEntry) Reset() { *x = OtaSlaveProgressEntry{} - mi := &file_uart_messages_proto_msgTypes[25] + mi := &file_uart_messages_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1931,7 +2183,7 @@ func (x *OtaSlaveProgressEntry) String() string { func (*OtaSlaveProgressEntry) ProtoMessage() {} func (x *OtaSlaveProgressEntry) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[25] + mi := &file_uart_messages_proto_msgTypes[28] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1944,7 +2196,7 @@ func (x *OtaSlaveProgressEntry) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressEntry.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressEntry) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{25} + return file_uart_messages_proto_rawDescGZIP(), []int{28} } func (x *OtaSlaveProgressEntry) GetClientId() uint32 { @@ -1995,7 +2247,7 @@ type OtaSlaveProgressResponse struct { func (x *OtaSlaveProgressResponse) Reset() { *x = OtaSlaveProgressResponse{} - mi := &file_uart_messages_proto_msgTypes[26] + mi := &file_uart_messages_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2007,7 +2259,7 @@ func (x *OtaSlaveProgressResponse) String() string { func (*OtaSlaveProgressResponse) ProtoMessage() {} func (x *OtaSlaveProgressResponse) ProtoReflect() protoreflect.Message { - mi := &file_uart_messages_proto_msgTypes[26] + mi := &file_uart_messages_proto_msgTypes[29] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2020,7 +2272,7 @@ func (x *OtaSlaveProgressResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use OtaSlaveProgressResponse.ProtoReflect.Descriptor instead. func (*OtaSlaveProgressResponse) Descriptor() ([]byte, []int) { - return file_uart_messages_proto_rawDescGZIP(), []int{26} + return file_uart_messages_proto_rawDescGZIP(), []int{29} } func (x *OtaSlaveProgressResponse) GetActive() bool { @@ -2062,7 +2314,7 @@ var File_uart_messages_proto protoreflect.FileDescriptor const file_uart_messages_proto_rawDesc = "" + "\n" + - "\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\x83\x0e\n" + + "\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\xba\x0f\n" + "\vUartMessage\x12%\n" + "\x04type\x18\x01 \x01(\x0e2\x11.alox.MessageTypeR\x04type\x12,\n" + "\vack_payload\x18\x02 \x01(\v2\t.alox.AckH\x00R\n" + @@ -2089,9 +2341,11 @@ const file_uart_messages_proto_rawDesc = "" + "\x16espnow_find_me_request\x18\x13 \x01(\v2\x19.alox.EspNowFindMeRequestH\x00R\x13espnowFindMeRequest\x12S\n" + "\x17espnow_find_me_response\x18\x14 \x01(\v2\x1a.alox.EspNowFindMeResponseH\x00R\x14espnowFindMeResponse\x12?\n" + "\x0frestart_request\x18\x15 \x01(\v2\x14.alox.RestartRequestH\x00R\x0erestartRequest\x12B\n" + - "\x10restart_response\x18\x16 \x01(\v2\x15.alox.RestartResponseH\x00R\x0frestartResponse\x12F\n" + - "\x12accel_read_request\x18\x17 \x01(\v2\x16.alox.AccelReadRequestH\x00R\x10accelReadRequest\x12I\n" + - "\x13accel_read_response\x18\x18 \x01(\v2\x17.alox.AccelReadResponseH\x00R\x11accelReadResponseB\t\n" + + "\x10restart_response\x18\x16 \x01(\v2\x15.alox.RestartResponseH\x00R\x0frestartResponse\x12R\n" + + "\x16accel_snapshot_request\x18\x17 \x01(\v2\x1a.alox.AccelSnapshotRequestH\x00R\x14accelSnapshotRequest\x12U\n" + + "\x17accel_snapshot_response\x18\x18 \x01(\v2\x1b.alox.AccelSnapshotResponseH\x00R\x15accelSnapshotResponse\x12L\n" + + "\x14accel_stream_request\x18\x19 \x01(\v2\x18.alox.AccelStreamRequestH\x00R\x12accelStreamRequest\x12O\n" + + "\x15accel_stream_response\x18\x1a \x01(\v2\x19.alox.AccelStreamResponseH\x00R\x13accelStreamResponseB\t\n" + "\apayload\"\x05\n" + "\x03Ack\"!\n" + "\vEchoPayload\x12\x12\n" + @@ -2099,7 +2353,7 @@ const file_uart_messages_proto_rawDesc = "" + "\x0fVersionResponse\x12\x18\n" + "\aversion\x18\x01 \x01(\rR\aversion\x12\x19\n" + "\bgit_hash\x18\x02 \x01(\tR\agitHash\x12+\n" + - "\x11running_partition\x18\x03 \x01(\tR\x10runningPartition\"\xc3\x01\n" + + "\x11running_partition\x18\x03 \x01(\tR\x10runningPartition\"\xf5\x01\n" + "\n" + "ClientInfo\x12\x0e\n" + "\x02id\x18\x01 \x01(\rR\x02id\x12\x1c\n" + @@ -2108,7 +2362,8 @@ const file_uart_messages_proto_rawDesc = "" + "\x03mac\x18\x04 \x01(\fR\x03mac\x12\x1b\n" + "\tlast_ping\x18\x05 \x01(\rR\blastPing\x12*\n" + "\x11last_success_ping\x18\x06 \x01(\rR\x0flastSuccessPing\x12\x18\n" + - "\aversion\x18\a \x01(\rR\aversion\"@\n" + + "\aversion\x18\a \x01(\rR\aversion\x120\n" + + "\x14accel_stream_enabled\x18\b \x01(\bR\x12accelStreamEnabled\"@\n" + "\x12ClientInfoResponse\x12*\n" + "\aclients\x18\x01 \x03(\v2\x10.alox.ClientInfoR\aclients\"e\n" + "\vClientInput\x12\x0e\n" + @@ -2128,13 +2383,29 @@ const file_uart_messages_proto_rawDesc = "" + "\bdeadzone\x18\x01 \x01(\rR\bdeadzone\x12\x1b\n" + "\tclient_id\x18\x02 \x01(\rR\bclientId\x12\x18\n" + "\asuccess\x18\x03 \x01(\bR\asuccess\x12%\n" + - "\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"\x12\n" + - "\x10AccelReadRequest\"W\n" + - "\x11AccelReadResponse\x12\x18\n" + - "\asuccess\x18\x01 \x01(\bR\asuccess\x12\f\n" + - "\x01x\x18\x02 \x01(\x11R\x01x\x12\f\n" + - "\x01y\x18\x03 \x01(\x11R\x01y\x12\f\n" + - "\x01z\x18\x04 \x01(\x11R\x01z\"I\n" + + "\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"\x80\x01\n" + + "\x12AccelStreamRequest\x12\x14\n" + + "\x05write\x18\x01 \x01(\bR\x05write\x12\x16\n" + + "\x06enable\x18\x02 \x01(\bR\x06enable\x12\x1b\n" + + "\tclient_id\x18\x03 \x01(\rR\bclientId\x12\x1f\n" + + "\vall_clients\x18\x04 \x01(\bR\n" + + "allClients\"\x8d\x01\n" + + "\x13AccelStreamResponse\x12\x18\n" + + "\aenabled\x18\x01 \x01(\bR\aenabled\x12\x1b\n" + + "\tclient_id\x18\x02 \x01(\rR\bclientId\x12\x18\n" + + "\asuccess\x18\x03 \x01(\bR\asuccess\x12%\n" + + "\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"3\n" + + "\x14AccelSnapshotRequest\x12\x1b\n" + + "\tclient_id\x18\x01 \x01(\rR\bclientId\"\x81\x01\n" + + "\vAccelSample\x12\x1b\n" + + "\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x14\n" + + "\x05valid\x18\x02 \x01(\bR\x05valid\x12\f\n" + + "\x01x\x18\x03 \x01(\x11R\x01x\x12\f\n" + + "\x01y\x18\x04 \x01(\x11R\x01y\x12\f\n" + + "\x01z\x18\x05 \x01(\x11R\x01z\x12\x15\n" + + "\x06age_ms\x18\x06 \x01(\rR\x05ageMs\"K\n" + + "\x15AccelSnapshotResponse\x122\n" + + "\asamples\x18\x01 \x03(\v2\x11.alox.AccelSampleB\x05\x92?\x02\x10\x10R\asamples\"I\n" + "\x18EspNowUnicastTestRequest\x12\x1b\n" + "\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x10\n" + "\x03seq\x18\x02 \x01(\rR\x03seq\"G\n" + @@ -2197,7 +2468,7 @@ const file_uart_messages_proto_rawDesc = "" + "\x0faggregate_bytes\x18\x03 \x01(\rR\x0eaggregateBytes\x12\x1f\n" + "\vslave_count\x18\x04 \x01(\rR\n" + "slaveCount\x12:\n" + - "\x06slaves\x18\x05 \x03(\v2\x1b.alox.OtaSlaveProgressEntryB\x05\x92?\x02\x10\x10R\x06slaves*\xad\x02\n" + + "\x06slaves\x18\x05 \x03(\v2\x1b.alox.OtaSlaveProgressEntryB\x05\x92?\x02\x10\x10R\x06slaves*\xc3\x02\n" + "\vMessageType\x12\v\n" + "\aUNKNOWN\x10\x00\x12\a\n" + "\x03ACK\x10\x01\x12\b\n" + @@ -2216,9 +2487,9 @@ const file_uart_messages_proto_rawDesc = "" + "\x10OTA_START_ESPNOW\x10\x14\x12\x16\n" + "\x12OTA_SLAVE_PROGRESS\x10\x15\x12\v\n" + "\aFIND_ME\x10\x16\x12\v\n" + - "\aRESTART\x10\x17\x12\x0e\n" + - "\n" + - "ACCEL_READ\x10\x18b\x06proto3" + "\aRESTART\x10\x17\x12\x12\n" + + "\x0eACCEL_SNAPSHOT\x10\x18\x12\x10\n" + + "\fACCEL_STREAM\x10\x19b\x06proto3" var ( file_uart_messages_proto_rawDescOnce sync.Once @@ -2233,7 +2504,7 @@ func file_uart_messages_proto_rawDescGZIP() []byte { } var file_uart_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 27) +var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 30) var file_uart_messages_proto_goTypes = []any{ (MessageType)(0), // 0: alox.MessageType (*UartMessage)(nil), // 1: alox.UartMessage @@ -2246,23 +2517,26 @@ var file_uart_messages_proto_goTypes = []any{ (*ClientInputResponse)(nil), // 8: alox.ClientInputResponse (*AccelDeadzoneRequest)(nil), // 9: alox.AccelDeadzoneRequest (*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse - (*AccelReadRequest)(nil), // 11: alox.AccelReadRequest - (*AccelReadResponse)(nil), // 12: alox.AccelReadResponse - (*EspNowUnicastTestRequest)(nil), // 13: alox.EspNowUnicastTestRequest - (*EspNowUnicastTestResponse)(nil), // 14: alox.EspNowUnicastTestResponse - (*LedRingProgressRequest)(nil), // 15: alox.LedRingProgressRequest - (*LedRingProgressResponse)(nil), // 16: alox.LedRingProgressResponse - (*EspNowFindMeRequest)(nil), // 17: alox.EspNowFindMeRequest - (*EspNowFindMeResponse)(nil), // 18: alox.EspNowFindMeResponse - (*RestartRequest)(nil), // 19: alox.RestartRequest - (*RestartResponse)(nil), // 20: alox.RestartResponse - (*OtaStartPayload)(nil), // 21: alox.OtaStartPayload - (*OtaPayload)(nil), // 22: alox.OtaPayload - (*OtaEndPayload)(nil), // 23: alox.OtaEndPayload - (*OtaStatusPayload)(nil), // 24: alox.OtaStatusPayload - (*OtaSlaveProgressRequest)(nil), // 25: alox.OtaSlaveProgressRequest - (*OtaSlaveProgressEntry)(nil), // 26: alox.OtaSlaveProgressEntry - (*OtaSlaveProgressResponse)(nil), // 27: alox.OtaSlaveProgressResponse + (*AccelStreamRequest)(nil), // 11: alox.AccelStreamRequest + (*AccelStreamResponse)(nil), // 12: alox.AccelStreamResponse + (*AccelSnapshotRequest)(nil), // 13: alox.AccelSnapshotRequest + (*AccelSample)(nil), // 14: alox.AccelSample + (*AccelSnapshotResponse)(nil), // 15: alox.AccelSnapshotResponse + (*EspNowUnicastTestRequest)(nil), // 16: alox.EspNowUnicastTestRequest + (*EspNowUnicastTestResponse)(nil), // 17: alox.EspNowUnicastTestResponse + (*LedRingProgressRequest)(nil), // 18: alox.LedRingProgressRequest + (*LedRingProgressResponse)(nil), // 19: alox.LedRingProgressResponse + (*EspNowFindMeRequest)(nil), // 20: alox.EspNowFindMeRequest + (*EspNowFindMeResponse)(nil), // 21: alox.EspNowFindMeResponse + (*RestartRequest)(nil), // 22: alox.RestartRequest + (*RestartResponse)(nil), // 23: alox.RestartResponse + (*OtaStartPayload)(nil), // 24: alox.OtaStartPayload + (*OtaPayload)(nil), // 25: alox.OtaPayload + (*OtaEndPayload)(nil), // 26: alox.OtaEndPayload + (*OtaStatusPayload)(nil), // 27: alox.OtaStatusPayload + (*OtaSlaveProgressRequest)(nil), // 28: alox.OtaSlaveProgressRequest + (*OtaSlaveProgressEntry)(nil), // 29: alox.OtaSlaveProgressEntry + (*OtaSlaveProgressResponse)(nil), // 30: alox.OtaSlaveProgressResponse } var file_uart_messages_proto_depIdxs = []int32{ 0, // 0: alox.UartMessage.type:type_name -> alox.MessageType @@ -2271,32 +2545,35 @@ var file_uart_messages_proto_depIdxs = []int32{ 4, // 3: alox.UartMessage.version_response:type_name -> alox.VersionResponse 6, // 4: alox.UartMessage.client_info_response:type_name -> alox.ClientInfoResponse 8, // 5: alox.UartMessage.client_input_response:type_name -> alox.ClientInputResponse - 21, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload - 22, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload - 23, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload - 24, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload + 24, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload + 25, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload + 26, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload + 27, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload 9, // 10: alox.UartMessage.accel_deadzone_request:type_name -> alox.AccelDeadzoneRequest 10, // 11: alox.UartMessage.accel_deadzone_response:type_name -> alox.AccelDeadzoneResponse - 13, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest - 14, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse - 25, // 14: alox.UartMessage.ota_slave_progress_request:type_name -> alox.OtaSlaveProgressRequest - 27, // 15: alox.UartMessage.ota_slave_progress_response:type_name -> alox.OtaSlaveProgressResponse - 15, // 16: alox.UartMessage.led_ring_progress_request:type_name -> alox.LedRingProgressRequest - 16, // 17: alox.UartMessage.led_ring_progress_response:type_name -> alox.LedRingProgressResponse - 17, // 18: alox.UartMessage.espnow_find_me_request:type_name -> alox.EspNowFindMeRequest - 18, // 19: alox.UartMessage.espnow_find_me_response:type_name -> alox.EspNowFindMeResponse - 19, // 20: alox.UartMessage.restart_request:type_name -> alox.RestartRequest - 20, // 21: alox.UartMessage.restart_response:type_name -> alox.RestartResponse - 11, // 22: alox.UartMessage.accel_read_request:type_name -> alox.AccelReadRequest - 12, // 23: alox.UartMessage.accel_read_response:type_name -> alox.AccelReadResponse - 5, // 24: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo - 7, // 25: alox.ClientInputResponse.clients:type_name -> alox.ClientInput - 26, // 26: alox.OtaSlaveProgressResponse.slaves:type_name -> alox.OtaSlaveProgressEntry - 27, // [27:27] is the sub-list for method output_type - 27, // [27:27] is the sub-list for method input_type - 27, // [27:27] is the sub-list for extension type_name - 27, // [27:27] is the sub-list for extension extendee - 0, // [0:27] is the sub-list for field type_name + 16, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest + 17, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse + 28, // 14: alox.UartMessage.ota_slave_progress_request:type_name -> alox.OtaSlaveProgressRequest + 30, // 15: alox.UartMessage.ota_slave_progress_response:type_name -> alox.OtaSlaveProgressResponse + 18, // 16: alox.UartMessage.led_ring_progress_request:type_name -> alox.LedRingProgressRequest + 19, // 17: alox.UartMessage.led_ring_progress_response:type_name -> alox.LedRingProgressResponse + 20, // 18: alox.UartMessage.espnow_find_me_request:type_name -> alox.EspNowFindMeRequest + 21, // 19: alox.UartMessage.espnow_find_me_response:type_name -> alox.EspNowFindMeResponse + 22, // 20: alox.UartMessage.restart_request:type_name -> alox.RestartRequest + 23, // 21: alox.UartMessage.restart_response:type_name -> alox.RestartResponse + 13, // 22: alox.UartMessage.accel_snapshot_request:type_name -> alox.AccelSnapshotRequest + 15, // 23: alox.UartMessage.accel_snapshot_response:type_name -> alox.AccelSnapshotResponse + 11, // 24: alox.UartMessage.accel_stream_request:type_name -> alox.AccelStreamRequest + 12, // 25: alox.UartMessage.accel_stream_response:type_name -> alox.AccelStreamResponse + 5, // 26: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo + 7, // 27: alox.ClientInputResponse.clients:type_name -> alox.ClientInput + 14, // 28: alox.AccelSnapshotResponse.samples:type_name -> alox.AccelSample + 29, // 29: alox.OtaSlaveProgressResponse.slaves:type_name -> alox.OtaSlaveProgressEntry + 30, // [30:30] is the sub-list for method output_type + 30, // [30:30] is the sub-list for method input_type + 30, // [30:30] is the sub-list for extension type_name + 30, // [30:30] is the sub-list for extension extendee + 0, // [0:30] is the sub-list for field type_name } func init() { file_uart_messages_proto_init() } @@ -2326,8 +2603,10 @@ func file_uart_messages_proto_init() { (*UartMessage_EspnowFindMeResponse)(nil), (*UartMessage_RestartRequest)(nil), (*UartMessage_RestartResponse)(nil), - (*UartMessage_AccelReadRequest)(nil), - (*UartMessage_AccelReadResponse)(nil), + (*UartMessage_AccelSnapshotRequest)(nil), + (*UartMessage_AccelSnapshotResponse)(nil), + (*UartMessage_AccelStreamRequest)(nil), + (*UartMessage_AccelStreamResponse)(nil), } type x struct{} out := protoimpl.TypeBuilder{ @@ -2335,7 +2614,7 @@ func file_uart_messages_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_uart_messages_proto_rawDesc), len(file_uart_messages_proto_rawDesc)), NumEnums: 1, - NumMessages: 27, + NumMessages: 30, NumExtensions: 0, NumServices: 0, }, diff --git a/goTool/webui/index.html b/goTool/webui/index.html index 9a34b47..5b66838 100644 --- a/goTool/webui/index.html +++ b/goTool/webui/index.html @@ -55,11 +55,12 @@ .badge-offline { background: #5c6570; color: #f0f3f5; } .badge.bg-secondary { background: #4a5560 !important; color: #f0f3f5; } - .mac { + .mac, .accel { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--pp-accent); } + .accel-stale { color: var(--pp-text-muted); } .pp-table { --bs-table-color: var(--pp-text); @@ -265,7 +266,9 @@ -
Slaves per ESP-NOW — Master-Deadzone bleibt separat.
++ Accel-Stream pro Slave per „Stream an“ aktivieren (~16 ms ESP-NOW). Ohne Aktivierung keine Werte. +
| Ver | Status | Deadzone | +Accel (LSB) | +Stream | Aktion | -||
|---|---|---|---|---|---|---|---|
| No clients | |||||||
| No clients | |||||||
| + | + + | ++ + |
200) return 'accel-stale';
+ return '';
+ },
formatSize(n) {
if (n == null) return '';
if (n < 1024) return n + ' B';
@@ -732,6 +767,44 @@
async setMasterDeadzone() {
await this.setDeadzone(0, this.masterDz);
},
+ patchClientAccelStream(clientId, enabled) {
+ const clients = (this.state.clients || []).map((c) => {
+ if (c.id !== clientId) {
+ return c;
+ }
+ const next = { ...c, accel_stream: enabled };
+ if (!enabled) {
+ next.accel_valid = false;
+ next.accel_x = 0;
+ next.accel_y = 0;
+ next.accel_z = 0;
+ next.accel_age_ms = 0;
+ }
+ return next;
+ });
+ this.state = { ...this.state, clients };
+ },
+ async setAccelStream(clientId, enable) {
+ this.busy = true;
+ try {
+ const r = await fetch(`/api/clients/${clientId}/accel-stream`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ enable: enable })
+ });
+ const data = await r.json();
+ if (!r.ok || !data.success) {
+ this.flash(data.error || `Accel-Stream Slave ${clientId} fehlgeschlagen`, false);
+ return;
+ }
+ this.patchClientAccelStream(clientId, !!data.enabled);
+ this.flash(`Slave ${clientId}: Accel-Stream ${data.enabled ? 'an' : 'aus'}`, true);
+ } catch (e) {
+ this.flash(String(e), false);
+ } finally {
+ this.busy = false;
+ }
+ },
async setDeadzoneAll(deadzone) {
if (deadzone == null || deadzone < 0) {
this.flash('Ungültiger Deadzone-Wert', false);
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 60db932..def6bd4 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -18,7 +18,8 @@ idf_component_register(
"cmd/cmd_version.c"
"cmd/cmd_client_info.c"
"cmd/cmd_accel_deadzone.c"
- "cmd/cmd_accel_read.c"
+ "cmd/cmd_accel_snapshot.c"
+ "cmd/cmd_accel_stream.c"
"cmd/cmd_espnow_unicast_test.c"
"cmd/cmd_espnow_find_me.c"
"cmd/cmd_restart.c"
diff --git a/main/README.md b/main/README.md
index ec94ddd..2370200 100644
--- a/main/README.md
+++ b/main/README.md
@@ -115,6 +115,7 @@ Schema: `proto/esp_now_messages.proto`. Encode/decode: `esp_now_proto.c`. The ES
| `ESPNOW_UNICAST_TEST` | Master → slave | `EspNowUnicastTest` (`seq`) |
| `ESPNOW_FIND_ME` | Master → slave | `EspNowFindMe` (`client_id` filter) — LED locate sequence |
| `ESPNOW_RESTART` | Master → slave | `EspNowRestart` (`client_id` filter) — reboot slave |
+| `ESPNOW_ACCEL_SAMPLE` | Slave → master | `EspNowAccelSample` (`slave_id`, `x`, `y`, `z` raw LSB) — ~every 16 ms |
| `ESPNOW_OTA_START` | Master → slave (unicast) | `EspNowOtaStart` (`total_size`) |
| `ESPNOW_OTA_PAYLOAD` | Master → slave | `EspNowOtaPayload` (`seq`, up to 200 B `data`) |
| `ESPNOW_OTA_END` | Master → slave | `EspNowOtaEnd` |
@@ -217,7 +218,7 @@ Host and master speak nanopb-encoded `UartMessage` inside UART frames (byte 0 =
| 21 | `OTA_SLAVE_PROGRESS` | Implemented (`cmd/cmd_ota_slave_progress.c`) — query per-slave ESP-NOW OTA progress |
| 22 | `FIND_ME` | Implemented (`cmd/cmd_espnow_find_me.c`) — `client_id=0` local ring, `>0` ESP-NOW to slave |
| 23 | `RESTART` | Implemented (`cmd/cmd_restart.c`) — `client_id=0` reboot master, `>0` ESP-NOW reboot slave |
-| 24 | `ACCEL_READ` | Implemented (`cmd/cmd_accel_read.c`) — on-demand BMA456 XYZ (raw LSB) |
+| 24 | `ACCEL_SNAPSHOT` | Implemented (`cmd/cmd_accel_snapshot.c`) — cached slave accel from ESP-NOW stream |
Regenerate C code:
@@ -311,20 +312,20 @@ Sets the **software** deadzone used by `bosch456.c` when logging accel (see [BMA
**Response:** `accel_deadzone_response` with applied `deadzone`, `success`, and `slaves_updated` (ESP-NOW count).
-### ACCEL_READ command
+### ACCEL_SNAPSHOT command
-Read the **current** BMA456 accelerometer sample on this node (master or slave with sensor). Values are raw LSB in the configured **±2g** range; they are **not** filtered by the software deadzone (unlike periodic `ACC X=…` logs in `bosch456.c`).
+Read **cached** accelerometer samples on the **master** (one entry per registered slave). Slaves send `ESPNOW_ACCEL_SAMPLE` to the master every **16 ms** (`esp_now_comm.c`); the master stores the latest value per client in `client_registry.c`.
-**Request:** framed `18` (`0x18`) only, or `18` + empty `accel_read_request`.
+**Request:** framed `18` (`0x18`) + optional `accel_snapshot_request` (`client_id`: `0` = all slaves, `>0` = one id).
-**Response:** `accel_read_response`:
+**Response:** `accel_snapshot_response.samples[]`:
| Field | Meaning |
|-------|---------|
-| `success` | `true` if BMA456 is ready and I2C read succeeded |
-| `x`, `y`, `z` | Raw accel LSB (`sint32`; meaningful only when `success`) |
-
-If the sensor was not probed at boot (`bma456_is_ready()` false), `success` is `false` and axes are zero.
+| `client_id` | Slave id (registry) |
+| `valid` | At least one ESP-NOW sample received since boot |
+| `x`, `y`, `z` | Raw BMA456 LSB (±2g) |
+| `age_ms` | Ms since last sample from that slave |
Host:
@@ -332,7 +333,7 @@ Host:
go run . -port /dev/ttyUSB0 accel
```
-Implementation: `bma456_read_accel()` in `bosch456.c` (mutex with the 10 Hz poll task), handler in `cmd/cmd_accel_read.c`.
+External API (`serve -api-addr :8081`) polls this command every 16 ms and streams JSON over WebSocket.
### ESPNOW_UNICAST_TEST command
@@ -479,7 +480,7 @@ Target: ESP32-S3. Close serial monitor on the UART adapter port before running `
| `cmd/cmd_client_info.c/h` | CLIENT_INFO handler |
| `client_registry.c/h` | Registered slave table |
| `bosch456.c/h` | BMA456H I2C driver, accel poll, on-demand read, tap INT, deadzone filter |
-| `cmd/cmd_accel_read.c` | UART `ACCEL_READ` — current accel XYZ |
+| `cmd/cmd_accel_snapshot.c` | UART `ACCEL_SNAPSHOT` — cached slave accel |
| `board_input.c/h` | Taster GPIO12, LiPo ADC on GPIO1 / GPIO12 |
| `pod_settings.c/h` | NVS persistence (accel deadzone, …) |
| `led_ring.c/h` | LED ring (digit display, progress bar) |
diff --git a/main/bosch456.c b/main/bosch456.c
index 097856c..0d580ee 100644
--- a/main/bosch456.c
+++ b/main/bosch456.c
@@ -2,7 +2,7 @@
* BMA456H integration for Powerpod (ESP-IDF I2C master + Bosch SensorAPI).
*
* Polls accelerometer at 10 Hz; tap events arrive on BMA456_INT_GPIO.
- * Accel logging is filtered in software (deadzone); see ACCEL_DEADZONE UART command.
+ * Accel logging is filtered in software (deadzone); slaves stream samples via ESP-NOW.
*/
#include "bosch456.h"
diff --git a/main/client_registry.c b/main/client_registry.c
index 5a59e0b..3ffef88 100644
--- a/main/client_registry.c
+++ b/main/client_registry.c
@@ -241,6 +241,85 @@ size_t client_registry_set_accel_deadzone_all(uint32_t deadzone) {
return n;
}
+static void clear_client_accel(client_slot_t *slot) {
+ if (slot == NULL) {
+ return;
+ }
+ slot->info.accel_valid = false;
+ slot->info.accel_x = 0;
+ slot->info.accel_y = 0;
+ slot->info.accel_z = 0;
+ slot->info.accel_updated_at = 0;
+}
+
+esp_err_t client_registry_set_accel_stream(uint32_t client_id, bool enabled) {
+ for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
+ if (!s_clients[i].active || s_clients[i].info.id != client_id) {
+ continue;
+ }
+ s_clients[i].info.accel_stream_enabled = enabled;
+ if (!enabled) {
+ clear_client_accel(&s_clients[i]);
+ }
+ return ESP_OK;
+ }
+ return ESP_ERR_NOT_FOUND;
+}
+
+esp_err_t client_registry_get_accel_stream(uint32_t client_id,
+ bool *enabled_out) {
+ if (enabled_out == NULL) {
+ return ESP_ERR_INVALID_ARG;
+ }
+ const client_info_t *info = client_registry_find_by_id(client_id);
+ if (info == NULL) {
+ return ESP_ERR_NOT_FOUND;
+ }
+ *enabled_out = info->accel_stream_enabled;
+ return ESP_OK;
+}
+
+size_t client_registry_set_accel_stream_all(bool enabled) {
+ size_t n = 0;
+ for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
+ if (!s_clients[i].active) {
+ continue;
+ }
+ s_clients[i].info.accel_stream_enabled = enabled;
+ if (!enabled) {
+ clear_client_accel(&s_clients[i]);
+ }
+ n++;
+ }
+ return n;
+}
+
+esp_err_t client_registry_update_accel(const uint8_t mac[CLIENT_MAC_LEN],
+ uint32_t slave_id, int16_t x, int16_t y,
+ int16_t z) {
+ if (mac == NULL) {
+ return ESP_ERR_INVALID_ARG;
+ }
+
+ client_slot_t *slot = find_slot(mac);
+ if (slot == NULL) {
+ return ESP_ERR_NOT_FOUND;
+ }
+ if (slot->info.id != slave_id) {
+ return ESP_ERR_INVALID_ARG;
+ }
+ if (!slot->info.accel_stream_enabled) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ slot->info.accel_x = x;
+ slot->info.accel_y = y;
+ slot->info.accel_z = z;
+ slot->info.accel_valid = true;
+ slot->info.accel_updated_at = now_ms();
+ return ESP_OK;
+}
+
const client_info_t *client_registry_at(size_t index) {
size_t n = 0;
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
diff --git a/main/client_registry.h b/main/client_registry.h
index 49c488f..20f151c 100644
--- a/main/client_registry.h
+++ b/main/client_registry.h
@@ -21,6 +21,14 @@ typedef struct {
uint32_t version;
/** Accel deadzone in raw LSB per axis (master copy for ESP-NOW config). */
uint32_t accel_deadzone;
+ /** Latest accel from slave ESP-NOW stream (master only). */
+ bool accel_valid;
+ int16_t accel_x;
+ int16_t accel_y;
+ int16_t accel_z;
+ uint32_t accel_updated_at;
+ /** Host-enabled ESP-NOW accel stream to master. */
+ bool accel_stream_enabled;
} client_info_t;
#define CLIENT_REGISTRY_DEFAULT_ACCEL_DEADZONE 100u
@@ -63,4 +71,13 @@ esp_err_t client_registry_get_accel_deadzone(uint32_t client_id,
/** Push deadzone to all active registry entries; returns count updated. */
size_t client_registry_set_accel_deadzone_all(uint32_t deadzone);
+/** Store latest accel sample from a slave (matched by sender MAC). */
+esp_err_t client_registry_update_accel(const uint8_t mac[CLIENT_MAC_LEN],
+ uint32_t slave_id, int16_t x, int16_t y,
+ int16_t z);
+
+esp_err_t client_registry_set_accel_stream(uint32_t client_id, bool enabled);
+esp_err_t client_registry_get_accel_stream(uint32_t client_id, bool *enabled_out);
+size_t client_registry_set_accel_stream_all(bool enabled);
+
#endif
diff --git a/main/cmd/cmd_accel_read.c b/main/cmd/cmd_accel_read.c
deleted file mode 100644
index 8ea041b..0000000
--- a/main/cmd/cmd_accel_read.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "bosch456.h"
-#include "cmd_accel_read.h"
-#include "uart_cmd.h"
-
-static const char *TAG = "[ACCEL_READ]";
-
-static void reply(bool success, int16_t x, int16_t y, int16_t z) {
- alox_UartMessage response;
- uart_cmd_init_response(&response, alox_MessageType_ACCEL_READ,
- alox_UartMessage_accel_read_response_tag);
- response.payload.accel_read_response.success = success;
- response.payload.accel_read_response.x = x;
- response.payload.accel_read_response.y = y;
- response.payload.accel_read_response.z = z;
- uart_cmd_send(&response, TAG);
-}
-
-static void handle_accel_read(const uint8_t *data, size_t len) {
- (void)data;
- (void)len;
-
- int16_t x = 0;
- int16_t y = 0;
- int16_t z = 0;
- if (bma456_read_accel(&x, &y, &z) == ESP_OK) {
- reply(true, x, y, z);
- return;
- }
- reply(false, 0, 0, 0);
-}
-
-void cmd_accel_read_register(void) {
- uart_cmd_register(alox_MessageType_ACCEL_READ, handle_accel_read);
-}
diff --git a/main/cmd/cmd_accel_read.h b/main/cmd/cmd_accel_read.h
deleted file mode 100644
index d8e85d7..0000000
--- a/main/cmd/cmd_accel_read.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CMD_ACCEL_READ_H
-#define CMD_ACCEL_READ_H
-
-void cmd_accel_read_register(void);
-
-#endif
diff --git a/main/cmd/cmd_accel_snapshot.c b/main/cmd/cmd_accel_snapshot.c
new file mode 100644
index 0000000..521a71d
--- /dev/null
+++ b/main/cmd/cmd_accel_snapshot.c
@@ -0,0 +1,68 @@
+#include "client_registry.h"
+#include "cmd_accel_snapshot.h"
+#include "uart_cmd.h"
+
+static const char *TAG = "[ACCEL_SNAP]";
+
+static void fill_accel_snapshot(alox_AccelSnapshotResponse *out,
+ uint32_t filter_client_id) {
+ if (out == NULL) {
+ return;
+ }
+
+ out->samples_count = 0;
+ size_t count = client_registry_count();
+
+ for (size_t i = 0; i < count; i++) {
+ const client_info_t *client = client_registry_at(i);
+ if (client == NULL) {
+ continue;
+ }
+ if (filter_client_id != 0 && client->id != filter_client_id) {
+ continue;
+ }
+ if (!client->accel_stream_enabled) {
+ continue;
+ }
+ if (out->samples_count >=
+ sizeof(out->samples) / sizeof(out->samples[0])) {
+ break;
+ }
+
+ alox_AccelSample *sample = &out->samples[out->samples_count++];
+ sample->client_id = client->id;
+ sample->valid = client->accel_valid;
+ sample->x = client->accel_x;
+ sample->y = client->accel_y;
+ sample->z = client->accel_z;
+ if (client->accel_valid) {
+ sample->age_ms = client_registry_ms_since(client->accel_updated_at);
+ }
+ }
+}
+
+static void handle_accel_snapshot(const uint8_t *data, size_t len) {
+ uint32_t filter_client_id = 0;
+
+ if (len > 0) {
+ alox_UartMessage req;
+ if (uart_cmd_decode(data, len, &req) == ESP_OK) {
+ alox_AccelSnapshotRequest *snap_req = UART_CMD_REQ(
+ &req, alox_UartMessage_accel_snapshot_request_tag, accel_snapshot_request);
+ if (snap_req != NULL) {
+ filter_client_id = snap_req->client_id;
+ }
+ }
+ }
+
+ alox_UartMessage response;
+ uart_cmd_init_response(&response, alox_MessageType_ACCEL_SNAPSHOT,
+ alox_UartMessage_accel_snapshot_response_tag);
+ fill_accel_snapshot(&response.payload.accel_snapshot_response, filter_client_id);
+
+ uart_cmd_send(&response, TAG);
+}
+
+void cmd_accel_snapshot_register(void) {
+ uart_cmd_register(alox_MessageType_ACCEL_SNAPSHOT, handle_accel_snapshot);
+}
diff --git a/main/cmd/cmd_accel_snapshot.h b/main/cmd/cmd_accel_snapshot.h
new file mode 100644
index 0000000..0f43396
--- /dev/null
+++ b/main/cmd/cmd_accel_snapshot.h
@@ -0,0 +1,6 @@
+#ifndef CMD_ACCEL_SNAPSHOT_H
+#define CMD_ACCEL_SNAPSHOT_H
+
+void cmd_accel_snapshot_register(void);
+
+#endif
diff --git a/main/cmd/cmd_accel_stream.c b/main/cmd/cmd_accel_stream.c
new file mode 100644
index 0000000..0d3501e
--- /dev/null
+++ b/main/cmd/cmd_accel_stream.c
@@ -0,0 +1,96 @@
+#include "client_registry.h"
+#include "cmd_accel_stream.h"
+#include "esp_log.h"
+#include "esp_now_comm.h"
+#include "uart_cmd.h"
+
+static const char *TAG = "[ACCEL_STREAM]";
+
+static void reply(bool enabled, uint32_t client_id, bool success,
+ uint32_t slaves_updated) {
+ alox_UartMessage response;
+ uart_cmd_init_response(&response, alox_MessageType_ACCEL_STREAM,
+ alox_UartMessage_accel_stream_response_tag);
+ response.payload.accel_stream_response.enabled = enabled;
+ response.payload.accel_stream_response.client_id = client_id;
+ response.payload.accel_stream_response.success = success;
+ response.payload.accel_stream_response.slaves_updated = slaves_updated;
+ uart_cmd_send(&response, TAG);
+}
+
+static esp_err_t push_stream_to_slave(const client_info_t *client, bool enable) {
+ if (client == NULL) {
+ return ESP_ERR_INVALID_ARG;
+ }
+ esp_err_t err = client_registry_set_accel_stream(client->id, enable);
+ if (err != ESP_OK) {
+ return err;
+ }
+ return esp_now_comm_send_accel_stream(client->mac, client->id, enable);
+}
+
+static void handle_accel_stream(const uint8_t *data, size_t len) {
+ alox_UartMessage uart_msg;
+ alox_AccelStreamRequest req = alox_AccelStreamRequest_init_zero;
+
+ if (uart_cmd_decode(data, len, &uart_msg) == ESP_OK) {
+ const alox_AccelStreamRequest *req_ptr = UART_CMD_REQ(
+ &uart_msg, alox_UartMessage_accel_stream_request_tag, accel_stream_request);
+ if (req_ptr != NULL) {
+ req = *req_ptr;
+ }
+ }
+
+ if (req.write) {
+ if (req.all_clients) {
+ size_t n = client_registry_set_accel_stream_all(req.enable);
+ uint32_t sent = 0;
+
+ for (size_t i = 0; i < client_registry_count(); i++) {
+ const client_info_t *client = client_registry_at(i);
+ if (client == NULL) {
+ continue;
+ }
+ if (esp_now_comm_send_accel_stream(client->mac, client->id,
+ req.enable) == ESP_OK) {
+ sent++;
+ }
+ }
+
+ ESP_LOGI(TAG, "accel stream %s for %u/%u slaves",
+ req.enable ? "on" : "off", (unsigned)sent, (unsigned)n);
+ reply(req.enable, 0, sent > 0, sent);
+ return;
+ }
+
+ if (req.client_id == 0) {
+ ESP_LOGW(TAG, "client_id required (or all_clients)");
+ reply(req.enable, 0, false, 0);
+ return;
+ }
+
+ const client_info_t *client = client_registry_find_by_id(req.client_id);
+ if (client == NULL) {
+ ESP_LOGW(TAG, "client id %lu not found", (unsigned long)req.client_id);
+ reply(req.enable, req.client_id, false, 0);
+ return;
+ }
+
+ esp_err_t err = push_stream_to_slave(client, req.enable);
+ reply(req.enable, req.client_id, err == ESP_OK, err == ESP_OK ? 1u : 0u);
+ return;
+ }
+
+ if (req.all_clients || req.client_id == 0) {
+ reply(false, 0, false, 0);
+ return;
+ }
+
+ bool enabled = false;
+ esp_err_t err = client_registry_get_accel_stream(req.client_id, &enabled);
+ reply(enabled, req.client_id, err == ESP_OK, 0);
+}
+
+void cmd_accel_stream_register(void) {
+ uart_cmd_register(alox_MessageType_ACCEL_STREAM, handle_accel_stream);
+}
diff --git a/main/cmd/cmd_accel_stream.h b/main/cmd/cmd_accel_stream.h
new file mode 100644
index 0000000..13e2909
--- /dev/null
+++ b/main/cmd/cmd_accel_stream.h
@@ -0,0 +1,6 @@
+#ifndef CMD_ACCEL_STREAM_H
+#define CMD_ACCEL_STREAM_H
+
+void cmd_accel_stream_register(void);
+
+#endif
diff --git a/main/cmd/cmd_client_info.c b/main/cmd/cmd_client_info.c
index fe21c74..6f8e4f0 100644
--- a/main/cmd/cmd_client_info.c
+++ b/main/cmd/cmd_client_info.c
@@ -27,6 +27,7 @@ static bool encode_clients_list(pb_ostream_t *stream, const pb_field_t *field,
proto.last_success_ping =
client_registry_ms_since(client->last_success_ping_at);
proto.version = client->version;
+ proto.accel_stream_enabled = client->accel_stream_enabled;
proto.mac.funcs.encode = uart_cmd_encode_bytes;
proto.mac.arg = &mac;
diff --git a/main/cmd/cmd_handler.c b/main/cmd/cmd_handler.c
index bafd7d0..8c8131c 100644
--- a/main/cmd/cmd_handler.c
+++ b/main/cmd/cmd_handler.c
@@ -48,8 +48,10 @@ static const char *message_type_name(uint16_t id) {
return "FIND_ME";
case alox_MessageType_RESTART:
return "RESTART";
- case alox_MessageType_ACCEL_READ:
- return "ACCEL_READ";
+ case alox_MessageType_ACCEL_SNAPSHOT:
+ return "ACCEL_SNAPSHOT";
+ case alox_MessageType_ACCEL_STREAM:
+ return "ACCEL_STREAM";
default:
return "UNKNOWN";
}
diff --git a/main/esp_now_comm.c b/main/esp_now_comm.c
index 366451f..ec7a758 100644
--- a/main/esp_now_comm.c
+++ b/main/esp_now_comm.c
@@ -29,6 +29,7 @@
#define ESPNOW_CLIENT_TIMEOUT_MS \
(ESPNOW_HEARTBEAT_INTERVAL_MS * ESPNOW_HEARTBEAT_MISS_COUNT)
#define SLAVE_MASTER_LOST_MS (ESPNOW_HEARTBEAT_INTERVAL_MS * 5)
+#define ESPNOW_ACCEL_INTERVAL_MS 16
static const uint8_t ESPNOW_BCAST[ESP_NOW_ETH_ALEN] = {0xff, 0xff, 0xff,
0xff, 0xff, 0xff};
@@ -39,6 +40,7 @@ static app_config_t s_config;
static uint8_t s_wifi_channel;
static uint8_t s_own_mac[ESP_NOW_ETH_ALEN];
static bool s_slave_joined;
+static bool s_accel_stream_enabled;
static uint8_t s_master_mac[ESP_NOW_ETH_ALEN];
static uint32_t s_last_discover_ms;
@@ -111,6 +113,18 @@ static esp_err_t send_message(const uint8_t *dest_mac,
return send_message_ex(dest_mac, msg, false);
}
+static esp_err_t send_accel_sample(const uint8_t *dest_mac, uint32_t slave_id,
+ int16_t x, int16_t y, int16_t z) {
+ alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
+ msg.type = alox_EspNowMessageType_ESPNOW_ACCEL_SAMPLE;
+ msg.which_payload = alox_EspNowMessage_accel_sample_tag;
+ msg.payload.accel_sample.slave_id = slave_id;
+ msg.payload.accel_sample.x = x;
+ msg.payload.accel_sample.y = y;
+ msg.payload.accel_sample.z = z;
+ return send_message(dest_mac, &msg);
+}
+
static esp_err_t send_message_ex(const uint8_t *dest_mac,
const alox_EspNowMessage *msg, bool wait_done) {
uint8_t buf[ESPNOW_PB_MAX_SIZE];
@@ -151,6 +165,18 @@ static esp_err_t send_message_ex(const uint8_t *dest_mac,
return err;
}
+static esp_err_t send_accel_stream(const uint8_t *dest_mac, uint32_t client_id,
+ bool enable) {
+ alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
+
+ msg.type = alox_EspNowMessageType_ESPNOW_SET_ACCEL_STREAM;
+ msg.which_payload = alox_EspNowMessage_accel_stream_tag;
+ msg.payload.accel_stream.enable = enable;
+ msg.payload.accel_stream.client_id = client_id;
+
+ return send_message(dest_mac, &msg);
+}
+
static esp_err_t send_accel_deadzone(const uint8_t *dest_mac, uint32_t client_id,
uint32_t deadzone) {
alox_EspNowMessage msg = alox_EspNowMessage_init_zero;
@@ -338,6 +364,25 @@ esp_err_t esp_now_comm_send_unicast_test(const uint8_t mac[CLIENT_MAC_LEN],
return err;
}
+esp_err_t esp_now_comm_send_accel_stream(const uint8_t mac[CLIENT_MAC_LEN],
+ uint32_t client_id, bool enable) {
+ if (mac == NULL || !s_config.master) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ char mac_str[18];
+ mac_to_str(mac, mac_str, sizeof(mac_str));
+ esp_err_t err = send_accel_stream(mac, client_id, enable);
+ if (err == ESP_OK) {
+ ESP_LOGI(TAG, "unicast SET_ACCEL_STREAM to %s: %s client_id=%lu", mac_str,
+ enable ? "on" : "off", (unsigned long)client_id);
+ } else {
+ ESP_LOGW(TAG, "unicast SET_ACCEL_STREAM to %s failed: %s", mac_str,
+ esp_err_to_name(err));
+ }
+ return err;
+}
+
esp_err_t esp_now_comm_send_accel_deadzone(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id, uint32_t deadzone) {
if (mac == NULL || !s_config.master) {
@@ -377,6 +422,7 @@ static void send_presence(const uint8_t *dest_mac,
static void slave_reset_join(void) {
s_slave_joined = false;
+ s_accel_stream_enabled = false;
memset(s_master_mac, 0, sizeof(s_master_mac));
s_last_discover_ms = 0;
}
@@ -426,6 +472,25 @@ static void handle_slave_find_me(const uint8_t *master_mac,
led_ring_find_me();
}
+static void handle_slave_accel_stream(const uint8_t *master_mac,
+ const alox_EspNowAccelStream *cfg) {
+ uint32_t my_id = s_own_mac[5];
+
+ if (cfg->client_id != 0 && cfg->client_id != my_id) {
+ return;
+ }
+
+ if (s_slave_joined && !mac_equal(master_mac, s_master_mac)) {
+ return;
+ }
+
+ s_accel_stream_enabled = cfg->enable;
+ char mac_str[18];
+ mac_to_str(master_mac, mac_str, sizeof(mac_str));
+ ESP_LOGI(TAG, "accel stream %s from master %s (id=%lu)",
+ cfg->enable ? "on" : "off", mac_str, (unsigned long)my_id);
+}
+
static void handle_slave_accel_deadzone(const uint8_t *master_mac,
const alox_EspNowAccelDeadzone *cfg) {
uint32_t my_id = s_own_mac[5];
@@ -453,6 +518,23 @@ static void handle_slave_accel_deadzone(const uint8_t *master_mac,
}
}
+static void handle_master_accel_sample(const uint8_t mac[CLIENT_MAC_LEN],
+ const alox_EspNowAccelSample *sample) {
+ if (sample == NULL) {
+ return;
+ }
+
+ esp_err_t err = client_registry_update_accel(
+ mac, sample->slave_id, (int16_t)sample->x, (int16_t)sample->y,
+ (int16_t)sample->z);
+ if (err == ESP_ERR_NOT_FOUND) {
+ return;
+ }
+ if (err != ESP_OK) {
+ ESP_LOGW(TAG, "accel sample id mismatch from %02x:…:%02x", mac[0], mac[5]);
+ }
+}
+
static void handle_client_presence(const alox_EspNowSlavePresence *presence,
const uint8_t mac[CLIENT_MAC_LEN]) {
if (presence->network != s_config.network) {
@@ -533,6 +615,30 @@ static void slave_check_master_timeout(void) {
}
}
+static void slave_accel_stream_task(void *param) {
+ (void)param;
+
+ ESP_LOGI(TAG, "slave accel stream task (interval %u ms)",
+ (unsigned)ESPNOW_ACCEL_INTERVAL_MS);
+
+ while (1) {
+ vTaskDelay(pdMS_TO_TICKS(ESPNOW_ACCEL_INTERVAL_MS));
+
+ if (!s_slave_joined || !s_accel_stream_enabled || !bma456_is_ready()) {
+ continue;
+ }
+
+ int16_t x = 0;
+ int16_t y = 0;
+ int16_t z = 0;
+ if (bma456_read_accel(&x, &y, &z) != ESP_OK) {
+ continue;
+ }
+
+ (void)send_accel_sample(s_master_mac, s_own_mac[5], x, y, z);
+ }
+}
+
static void slave_heartbeat_task(void *param) {
(void)param;
@@ -592,6 +698,12 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
case alox_EspNowMessage_accel_deadzone_tag:
handle_slave_accel_deadzone(info->src_addr, &msg.payload.accel_deadzone);
break;
+ case alox_EspNowMessage_accel_stream_tag:
+ if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
+ break;
+ }
+ handle_slave_accel_stream(info->src_addr, &msg.payload.accel_stream);
+ break;
case alox_EspNowMessage_find_me_tag:
if (!s_slave_joined || !mac_equal(info->src_addr, s_master_mac)) {
break;
@@ -639,6 +751,12 @@ static void espnow_recv_cb(const esp_now_recv_info_t *info, const uint8_t *data,
return;
}
+ if (msg.which_payload == alox_EspNowMessage_accel_sample_tag) {
+ ensure_peer(info->src_addr);
+ handle_master_accel_sample(info->src_addr, &msg.payload.accel_sample);
+ return;
+ }
+
const alox_EspNowSlavePresence *presence = esp_now_proto_get_presence(&msg);
if (presence != NULL) {
/* Registry key is the ESP-NOW sender MAC, not the optional protobuf mac field. */
@@ -739,6 +857,11 @@ esp_err_t esp_now_comm_init(const app_config_t *config) {
ESP_LOGE(TAG, "failed to create heartbeat task");
return ESP_FAIL;
}
+ if (xTaskCreate(slave_accel_stream_task, "espnow_accel", 4096, NULL, 5,
+ NULL) != pdPASS) {
+ ESP_LOGE(TAG, "failed to create accel stream task");
+ return ESP_FAIL;
+ }
}
return ESP_OK;
diff --git a/main/esp_now_comm.h b/main/esp_now_comm.h
index acb869d..b34252e 100644
--- a/main/esp_now_comm.h
+++ b/main/esp_now_comm.h
@@ -7,6 +7,10 @@
esp_err_t esp_now_comm_init(const app_config_t *config);
+/** Master: enable/disable accel ESP-NOW stream on one slave. */
+esp_err_t esp_now_comm_send_accel_stream(const uint8_t mac[CLIENT_MAC_LEN],
+ uint32_t client_id, bool enable);
+
/** Master: unicast accel deadzone to one slave (client_id is echoed for filtering). */
esp_err_t esp_now_comm_send_accel_deadzone(const uint8_t mac[CLIENT_MAC_LEN],
uint32_t client_id, uint32_t deadzone);
diff --git a/main/powerpod.c b/main/powerpod.c
index ac1d067..a7405f5 100644
--- a/main/powerpod.c
+++ b/main/powerpod.c
@@ -1,7 +1,8 @@
#include "app_config.h"
#include "cmd_handler.h"
#include "cmd_accel_deadzone.h"
-#include "cmd_accel_read.h"
+#include "cmd_accel_snapshot.h"
+#include "cmd_accel_stream.h"
#include "cmd_espnow_unicast_test.h"
#include "cmd_espnow_find_me.h"
#include "cmd_restart.h"
@@ -178,7 +179,8 @@ void app_main(void) {
cmd_version_register();
cmd_client_info_register();
cmd_accel_deadzone_register();
- cmd_accel_read_register();
+ cmd_accel_snapshot_register();
+ cmd_accel_stream_register();
cmd_espnow_unicast_test_register();
cmd_espnow_find_me_register();
cmd_restart_register();
diff --git a/main/proto/esp_now_messages.pb.c b/main/proto/esp_now_messages.pb.c
index 320b19b..aca1be1 100644
--- a/main/proto/esp_now_messages.pb.c
+++ b/main/proto/esp_now_messages.pb.c
@@ -24,6 +24,12 @@ PB_BIND(alox_EspNowSlavePresence, alox_EspNowSlavePresence, AUTO)
PB_BIND(alox_EspNowAccelDeadzone, alox_EspNowAccelDeadzone, AUTO)
+PB_BIND(alox_EspNowAccelStream, alox_EspNowAccelStream, AUTO)
+
+
+PB_BIND(alox_EspNowAccelSample, alox_EspNowAccelSample, AUTO)
+
+
PB_BIND(alox_EspNowOtaStart, alox_EspNowOtaStart, AUTO)
diff --git a/main/proto/esp_now_messages.pb.h b/main/proto/esp_now_messages.pb.h
index 3f2c44b..be8e98e 100644
--- a/main/proto/esp_now_messages.pb.h
+++ b/main/proto/esp_now_messages.pb.h
@@ -22,7 +22,9 @@ typedef enum _alox_EspNowMessageType {
alox_EspNowMessageType_ESPNOW_OTA_END = 8,
alox_EspNowMessageType_ESPNOW_OTA_STATUS = 9,
alox_EspNowMessageType_ESPNOW_FIND_ME = 10,
- alox_EspNowMessageType_ESPNOW_RESTART = 11
+ alox_EspNowMessageType_ESPNOW_RESTART = 11,
+ alox_EspNowMessageType_ESPNOW_ACCEL_SAMPLE = 12,
+ alox_EspNowMessageType_ESPNOW_SET_ACCEL_STREAM = 13
} alox_EspNowMessageType;
/* Struct definitions */
@@ -59,6 +61,20 @@ typedef struct _alox_EspNowAccelDeadzone {
uint32_t client_id; /* 0 = all slaves; otherwise only matching slave_id applies */
} alox_EspNowAccelDeadzone;
+/* * Master → slave: enable/disable periodic accel ESP-NOW stream (~16 ms). */
+typedef struct _alox_EspNowAccelStream {
+ bool enable;
+ uint32_t client_id;
+} alox_EspNowAccelStream;
+
+/* * Slave → master: latest BMA456 sample (sent ~every 16 ms). */
+typedef struct _alox_EspNowAccelSample {
+ uint32_t slave_id;
+ int32_t x;
+ int32_t y;
+ int32_t z;
+} alox_EspNowAccelSample;
+
/* Master → slave: begin OTA (erase inactive slot; slave replies ESPNOW_OTA_STATUS). */
typedef struct _alox_EspNowOtaStart {
uint32_t total_size;
@@ -98,6 +114,8 @@ typedef struct _alox_EspNowMessage {
alox_EspNowOtaStatus ota_status;
alox_EspNowFindMe find_me;
alox_EspNowRestart restart;
+ alox_EspNowAccelSample accel_sample;
+ alox_EspNowAccelStream accel_stream;
} payload;
} alox_EspNowMessage;
@@ -108,8 +126,10 @@ extern "C" {
/* Helper constants for enums */
#define _alox_EspNowMessageType_MIN alox_EspNowMessageType_ESPNOW_UNKNOWN
-#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_RESTART
-#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_RESTART+1))
+#define _alox_EspNowMessageType_MAX alox_EspNowMessageType_ESPNOW_SET_ACCEL_STREAM
+#define _alox_EspNowMessageType_ARRAYSIZE ((alox_EspNowMessageType)(alox_EspNowMessageType_ESPNOW_SET_ACCEL_STREAM+1))
+
+
@@ -131,6 +151,8 @@ extern "C" {
#define alox_EspNowDiscover_init_default {0}
#define alox_EspNowSlavePresence_init_default {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_default {0, 0}
+#define alox_EspNowAccelStream_init_default {0, 0}
+#define alox_EspNowAccelSample_init_default {0, 0, 0, 0}
#define alox_EspNowOtaStart_init_default {0}
#define alox_EspNowOtaPayload_init_default {0, {0, {0}}}
#define alox_EspNowOtaEnd_init_default {0}
@@ -142,6 +164,8 @@ extern "C" {
#define alox_EspNowDiscover_init_zero {0}
#define alox_EspNowSlavePresence_init_zero {0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_EspNowAccelDeadzone_init_zero {0, 0}
+#define alox_EspNowAccelStream_init_zero {0, 0}
+#define alox_EspNowAccelSample_init_zero {0, 0, 0, 0}
#define alox_EspNowOtaStart_init_zero {0}
#define alox_EspNowOtaPayload_init_zero {0, {0, {0}}}
#define alox_EspNowOtaEnd_init_zero {0}
@@ -161,6 +185,12 @@ extern "C" {
#define alox_EspNowSlavePresence_used_tag 6
#define alox_EspNowAccelDeadzone_deadzone_tag 1
#define alox_EspNowAccelDeadzone_client_id_tag 2
+#define alox_EspNowAccelStream_enable_tag 1
+#define alox_EspNowAccelStream_client_id_tag 2
+#define alox_EspNowAccelSample_slave_id_tag 1
+#define alox_EspNowAccelSample_x_tag 2
+#define alox_EspNowAccelSample_y_tag 3
+#define alox_EspNowAccelSample_z_tag 4
#define alox_EspNowOtaStart_total_size_tag 1
#define alox_EspNowOtaPayload_seq_tag 1
#define alox_EspNowOtaPayload_data_tag 2
@@ -179,6 +209,8 @@ extern "C" {
#define alox_EspNowMessage_ota_status_tag 10
#define alox_EspNowMessage_find_me_tag 11
#define alox_EspNowMessage_restart_tag 12
+#define alox_EspNowMessage_accel_sample_tag 13
+#define alox_EspNowMessage_accel_stream_tag 14
/* Struct field encoding specification for nanopb */
#define alox_EspNowUnicastTest_FIELDLIST(X, a) \
@@ -217,6 +249,20 @@ X(a, STATIC, SINGULAR, UINT32, client_id, 2)
#define alox_EspNowAccelDeadzone_CALLBACK NULL
#define alox_EspNowAccelDeadzone_DEFAULT NULL
+#define alox_EspNowAccelStream_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, BOOL, enable, 1) \
+X(a, STATIC, SINGULAR, UINT32, client_id, 2)
+#define alox_EspNowAccelStream_CALLBACK NULL
+#define alox_EspNowAccelStream_DEFAULT NULL
+
+#define alox_EspNowAccelSample_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, UINT32, slave_id, 1) \
+X(a, STATIC, SINGULAR, SINT32, x, 2) \
+X(a, STATIC, SINGULAR, SINT32, y, 3) \
+X(a, STATIC, SINGULAR, SINT32, z, 4)
+#define alox_EspNowAccelSample_CALLBACK NULL
+#define alox_EspNowAccelSample_DEFAULT NULL
+
#define alox_EspNowOtaStart_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, total_size, 1)
#define alox_EspNowOtaStart_CALLBACK NULL
@@ -252,7 +298,9 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,ota_payload,payload.ota_payload),
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_end,payload.ota_end), 9) \
X(a, STATIC, ONEOF, MESSAGE, (payload,ota_status,payload.ota_status), 10) \
X(a, STATIC, ONEOF, MESSAGE, (payload,find_me,payload.find_me), 11) \
-X(a, STATIC, ONEOF, MESSAGE, (payload,restart,payload.restart), 12)
+X(a, STATIC, ONEOF, MESSAGE, (payload,restart,payload.restart), 12) \
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_sample,payload.accel_sample), 13) \
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream,payload.accel_stream), 14)
#define alox_EspNowMessage_CALLBACK NULL
#define alox_EspNowMessage_DEFAULT NULL
#define alox_EspNowMessage_payload_discover_MSGTYPE alox_EspNowDiscover
@@ -266,6 +314,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,restart,payload.restart), 12)
#define alox_EspNowMessage_payload_ota_status_MSGTYPE alox_EspNowOtaStatus
#define alox_EspNowMessage_payload_find_me_MSGTYPE alox_EspNowFindMe
#define alox_EspNowMessage_payload_restart_MSGTYPE alox_EspNowRestart
+#define alox_EspNowMessage_payload_accel_sample_MSGTYPE alox_EspNowAccelSample
+#define alox_EspNowMessage_payload_accel_stream_MSGTYPE alox_EspNowAccelStream
extern const pb_msgdesc_t alox_EspNowUnicastTest_msg;
extern const pb_msgdesc_t alox_EspNowFindMe_msg;
@@ -273,6 +323,8 @@ extern const pb_msgdesc_t alox_EspNowRestart_msg;
extern const pb_msgdesc_t alox_EspNowDiscover_msg;
extern const pb_msgdesc_t alox_EspNowSlavePresence_msg;
extern const pb_msgdesc_t alox_EspNowAccelDeadzone_msg;
+extern const pb_msgdesc_t alox_EspNowAccelStream_msg;
+extern const pb_msgdesc_t alox_EspNowAccelSample_msg;
extern const pb_msgdesc_t alox_EspNowOtaStart_msg;
extern const pb_msgdesc_t alox_EspNowOtaPayload_msg;
extern const pb_msgdesc_t alox_EspNowOtaEnd_msg;
@@ -286,6 +338,8 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
#define alox_EspNowDiscover_fields &alox_EspNowDiscover_msg
#define alox_EspNowSlavePresence_fields &alox_EspNowSlavePresence_msg
#define alox_EspNowAccelDeadzone_fields &alox_EspNowAccelDeadzone_msg
+#define alox_EspNowAccelStream_fields &alox_EspNowAccelStream_msg
+#define alox_EspNowAccelSample_fields &alox_EspNowAccelSample_msg
#define alox_EspNowOtaStart_fields &alox_EspNowOtaStart_msg
#define alox_EspNowOtaPayload_fields &alox_EspNowOtaPayload_msg
#define alox_EspNowOtaEnd_fields &alox_EspNowOtaEnd_msg
@@ -297,6 +351,8 @@ extern const pb_msgdesc_t alox_EspNowMessage_msg;
/* alox_EspNowMessage_size depends on runtime parameters */
#define ALOX_ESP_NOW_MESSAGES_PB_H_MAX_SIZE alox_EspNowOtaPayload_size
#define alox_EspNowAccelDeadzone_size 12
+#define alox_EspNowAccelSample_size 24
+#define alox_EspNowAccelStream_size 8
#define alox_EspNowDiscover_size 6
#define alox_EspNowFindMe_size 6
#define alox_EspNowOtaEnd_size 0
diff --git a/main/proto/esp_now_messages.proto b/main/proto/esp_now_messages.proto
index 363cc46..def3642 100644
--- a/main/proto/esp_now_messages.proto
+++ b/main/proto/esp_now_messages.proto
@@ -17,6 +17,8 @@ enum EspNowMessageType {
ESPNOW_OTA_STATUS = 9;
ESPNOW_FIND_ME = 10;
ESPNOW_RESTART = 11;
+ ESPNOW_ACCEL_SAMPLE = 12;
+ ESPNOW_SET_ACCEL_STREAM = 13;
}
message EspNowUnicastTest {
@@ -52,6 +54,20 @@ message EspNowAccelDeadzone {
uint32 client_id = 2; // 0 = all slaves; otherwise only matching slave_id applies
}
+/** Master → slave: enable/disable periodic accel ESP-NOW stream (~16 ms). */
+message EspNowAccelStream {
+ bool enable = 1;
+ uint32 client_id = 2;
+}
+
+/** Slave → master: latest BMA456 sample (sent ~every 16 ms). */
+message EspNowAccelSample {
+ uint32 slave_id = 1;
+ sint32 x = 2;
+ sint32 y = 3;
+ sint32 z = 4;
+}
+
// Master → slave: begin OTA (erase inactive slot; slave replies ESPNOW_OTA_STATUS).
message EspNowOtaStart {
uint32 total_size = 1;
@@ -87,5 +103,7 @@ message EspNowMessage {
EspNowOtaStatus ota_status = 10;
EspNowFindMe find_me = 11;
EspNowRestart restart = 12;
+ EspNowAccelSample accel_sample = 13;
+ EspNowAccelStream accel_stream = 14;
}
}
diff --git a/main/proto/uart_messages.pb.c b/main/proto/uart_messages.pb.c
index 3bd7821..d20157d 100644
--- a/main/proto/uart_messages.pb.c
+++ b/main/proto/uart_messages.pb.c
@@ -36,10 +36,19 @@ PB_BIND(alox_AccelDeadzoneRequest, alox_AccelDeadzoneRequest, AUTO)
PB_BIND(alox_AccelDeadzoneResponse, alox_AccelDeadzoneResponse, AUTO)
-PB_BIND(alox_AccelReadRequest, alox_AccelReadRequest, AUTO)
+PB_BIND(alox_AccelStreamRequest, alox_AccelStreamRequest, AUTO)
-PB_BIND(alox_AccelReadResponse, alox_AccelReadResponse, AUTO)
+PB_BIND(alox_AccelStreamResponse, alox_AccelStreamResponse, AUTO)
+
+
+PB_BIND(alox_AccelSnapshotRequest, alox_AccelSnapshotRequest, AUTO)
+
+
+PB_BIND(alox_AccelSample, alox_AccelSample, AUTO)
+
+
+PB_BIND(alox_AccelSnapshotResponse, alox_AccelSnapshotResponse, 2)
PB_BIND(alox_EspNowUnicastTestRequest, alox_EspNowUnicastTestRequest, AUTO)
diff --git a/main/proto/uart_messages.pb.h b/main/proto/uart_messages.pb.h
index fb6febf..950d8a6 100644
--- a/main/proto/uart_messages.pb.h
+++ b/main/proto/uart_messages.pb.h
@@ -28,7 +28,8 @@ typedef enum _alox_MessageType {
alox_MessageType_OTA_SLAVE_PROGRESS = 21,
alox_MessageType_FIND_ME = 22,
alox_MessageType_RESTART = 23,
- alox_MessageType_ACCEL_READ = 24
+ alox_MessageType_ACCEL_SNAPSHOT = 24,
+ alox_MessageType_ACCEL_STREAM = 25
} alox_MessageType;
/* Struct definitions */
@@ -55,6 +56,8 @@ typedef struct _alox_ClientInfo {
uint32_t last_ping;
uint32_t last_success_ping;
uint32_t version;
+ /* * Master: ESP-NOW accel stream enabled for this slave. */
+ bool accel_stream_enabled;
} alox_ClientInfo;
typedef struct _alox_ClientInfoResponse {
@@ -89,17 +92,42 @@ typedef struct _alox_AccelDeadzoneResponse {
uint32_t slaves_updated;
} alox_AccelDeadzoneResponse;
-/* Host → device: read current BMA456 accelerometer sample (raw LSB, ±2g range). */
-typedef struct _alox_AccelReadRequest {
- char dummy_field;
-} alox_AccelReadRequest;
+/* Host → master: enable/disable slave accel ESP-NOW stream (~16 ms per slave).
+ write=false: read; write=true: apply. client_id 0 invalid for write (use >0 or all_clients). */
+typedef struct _alox_AccelStreamRequest {
+ bool write;
+ bool enable;
+ uint32_t client_id;
+ bool all_clients;
+} alox_AccelStreamRequest;
-typedef struct _alox_AccelReadResponse {
+typedef struct _alox_AccelStreamResponse {
+ bool enabled;
+ uint32_t client_id;
bool success;
+ uint32_t slaves_updated;
+} alox_AccelStreamResponse;
+
+/* Host → master: read cached accel samples from slaves (only while stream enabled).
+ client_id 0 = all registered slaves; otherwise one slave. */
+typedef struct _alox_AccelSnapshotRequest {
+ uint32_t client_id;
+} alox_AccelSnapshotRequest;
+
+typedef struct _alox_AccelSample {
+ uint32_t client_id;
+ bool valid;
int32_t x;
int32_t y;
int32_t z;
-} alox_AccelReadResponse;
+ /* * Milliseconds since last ESP-NOW sample from this slave. */
+ uint32_t age_ms;
+} alox_AccelSample;
+
+typedef struct _alox_AccelSnapshotResponse {
+ pb_size_t samples_count;
+ alox_AccelSample samples[16];
+} alox_AccelSnapshotResponse;
typedef struct _alox_EspNowUnicastTestRequest {
uint32_t client_id;
@@ -231,8 +259,10 @@ typedef struct _alox_UartMessage {
alox_EspNowFindMeResponse espnow_find_me_response;
alox_RestartRequest restart_request;
alox_RestartResponse restart_response;
- alox_AccelReadRequest accel_read_request;
- alox_AccelReadResponse accel_read_response;
+ alox_AccelSnapshotRequest accel_snapshot_request;
+ alox_AccelSnapshotResponse accel_snapshot_response;
+ alox_AccelStreamRequest accel_stream_request;
+ alox_AccelStreamResponse accel_stream_response;
} payload;
} alox_UartMessage;
@@ -243,8 +273,8 @@ extern "C" {
/* Helper constants for enums */
#define _alox_MessageType_MIN alox_MessageType_UNKNOWN
-#define _alox_MessageType_MAX alox_MessageType_ACCEL_READ
-#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_ACCEL_READ+1))
+#define _alox_MessageType_MAX alox_MessageType_ACCEL_STREAM
+#define _alox_MessageType_ARRAYSIZE ((alox_MessageType)(alox_MessageType_ACCEL_STREAM+1))
#define alox_UartMessage_type_ENUMTYPE alox_MessageType
@@ -271,6 +301,9 @@ extern "C" {
+
+
+
@@ -280,14 +313,17 @@ extern "C" {
#define alox_Ack_init_default {0}
#define alox_EchoPayload_init_default {{{NULL}, NULL}}
#define alox_VersionResponse_init_default {0, {{NULL}, NULL}, {{NULL}, NULL}}
-#define alox_ClientInfo_init_default {0, 0, 0, {{NULL}, NULL}, 0, 0, 0}
+#define alox_ClientInfo_init_default {0, 0, 0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_ClientInfoResponse_init_default {{{NULL}, NULL}}
#define alox_ClientInput_init_default {0, 0, 0, 0}
#define alox_ClientInputResponse_init_default {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_default {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_default {0, 0, 0, 0}
-#define alox_AccelReadRequest_init_default {0}
-#define alox_AccelReadResponse_init_default {0, 0, 0, 0}
+#define alox_AccelStreamRequest_init_default {0, 0, 0, 0}
+#define alox_AccelStreamResponse_init_default {0, 0, 0, 0}
+#define alox_AccelSnapshotRequest_init_default {0}
+#define alox_AccelSample_init_default {0, 0, 0, 0, 0, 0}
+#define alox_AccelSnapshotResponse_init_default {0, {alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default, alox_AccelSample_init_default}}
#define alox_EspNowUnicastTestRequest_init_default {0, 0}
#define alox_EspNowUnicastTestResponse_init_default {0, 0}
#define alox_LedRingProgressRequest_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0}
@@ -307,14 +343,17 @@ extern "C" {
#define alox_Ack_init_zero {0}
#define alox_EchoPayload_init_zero {{{NULL}, NULL}}
#define alox_VersionResponse_init_zero {0, {{NULL}, NULL}, {{NULL}, NULL}}
-#define alox_ClientInfo_init_zero {0, 0, 0, {{NULL}, NULL}, 0, 0, 0}
+#define alox_ClientInfo_init_zero {0, 0, 0, {{NULL}, NULL}, 0, 0, 0, 0}
#define alox_ClientInfoResponse_init_zero {{{NULL}, NULL}}
#define alox_ClientInput_init_zero {0, 0, 0, 0}
#define alox_ClientInputResponse_init_zero {{{NULL}, NULL}}
#define alox_AccelDeadzoneRequest_init_zero {0, 0, 0, 0}
#define alox_AccelDeadzoneResponse_init_zero {0, 0, 0, 0}
-#define alox_AccelReadRequest_init_zero {0}
-#define alox_AccelReadResponse_init_zero {0, 0, 0, 0}
+#define alox_AccelStreamRequest_init_zero {0, 0, 0, 0}
+#define alox_AccelStreamResponse_init_zero {0, 0, 0, 0}
+#define alox_AccelSnapshotRequest_init_zero {0}
+#define alox_AccelSample_init_zero {0, 0, 0, 0, 0, 0}
+#define alox_AccelSnapshotResponse_init_zero {0, {alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero, alox_AccelSample_init_zero}}
#define alox_EspNowUnicastTestRequest_init_zero {0, 0}
#define alox_EspNowUnicastTestResponse_init_zero {0, 0}
#define alox_LedRingProgressRequest_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0}
@@ -343,6 +382,7 @@ extern "C" {
#define alox_ClientInfo_last_ping_tag 5
#define alox_ClientInfo_last_success_ping_tag 6
#define alox_ClientInfo_version_tag 7
+#define alox_ClientInfo_accel_stream_enabled_tag 8
#define alox_ClientInfoResponse_clients_tag 1
#define alox_ClientInput_id_tag 1
#define alox_ClientInput_lage_x_tag 2
@@ -357,10 +397,22 @@ extern "C" {
#define alox_AccelDeadzoneResponse_client_id_tag 2
#define alox_AccelDeadzoneResponse_success_tag 3
#define alox_AccelDeadzoneResponse_slaves_updated_tag 4
-#define alox_AccelReadResponse_success_tag 1
-#define alox_AccelReadResponse_x_tag 2
-#define alox_AccelReadResponse_y_tag 3
-#define alox_AccelReadResponse_z_tag 4
+#define alox_AccelStreamRequest_write_tag 1
+#define alox_AccelStreamRequest_enable_tag 2
+#define alox_AccelStreamRequest_client_id_tag 3
+#define alox_AccelStreamRequest_all_clients_tag 4
+#define alox_AccelStreamResponse_enabled_tag 1
+#define alox_AccelStreamResponse_client_id_tag 2
+#define alox_AccelStreamResponse_success_tag 3
+#define alox_AccelStreamResponse_slaves_updated_tag 4
+#define alox_AccelSnapshotRequest_client_id_tag 1
+#define alox_AccelSample_client_id_tag 1
+#define alox_AccelSample_valid_tag 2
+#define alox_AccelSample_x_tag 3
+#define alox_AccelSample_y_tag 4
+#define alox_AccelSample_z_tag 5
+#define alox_AccelSample_age_ms_tag 6
+#define alox_AccelSnapshotResponse_samples_tag 1
#define alox_EspNowUnicastTestRequest_client_id_tag 1
#define alox_EspNowUnicastTestRequest_seq_tag 2
#define alox_EspNowUnicastTestResponse_success_tag 1
@@ -424,8 +476,10 @@ extern "C" {
#define alox_UartMessage_espnow_find_me_response_tag 20
#define alox_UartMessage_restart_request_tag 21
#define alox_UartMessage_restart_response_tag 22
-#define alox_UartMessage_accel_read_request_tag 23
-#define alox_UartMessage_accel_read_response_tag 24
+#define alox_UartMessage_accel_snapshot_request_tag 23
+#define alox_UartMessage_accel_snapshot_response_tag 24
+#define alox_UartMessage_accel_stream_request_tag 25
+#define alox_UartMessage_accel_stream_response_tag 26
/* Struct field encoding specification for nanopb */
#define alox_UartMessage_FIELDLIST(X, a) \
@@ -451,8 +505,10 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_request,payload.espno
X(a, STATIC, ONEOF, MESSAGE, (payload,espnow_find_me_response,payload.espnow_find_me_response), 20) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart_request,payload.restart_request), 21) \
X(a, STATIC, ONEOF, MESSAGE, (payload,restart_response,payload.restart_response), 22) \
-X(a, STATIC, ONEOF, MESSAGE, (payload,accel_read_request,payload.accel_read_request), 23) \
-X(a, STATIC, ONEOF, MESSAGE, (payload,accel_read_response,payload.accel_read_response), 24)
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_request,payload.accel_snapshot_request), 23) \
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_snapshot_response,payload.accel_snapshot_response), 24) \
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_request,payload.accel_stream_request), 25) \
+X(a, STATIC, ONEOF, MESSAGE, (payload,accel_stream_response,payload.accel_stream_response), 26)
#define alox_UartMessage_CALLBACK NULL
#define alox_UartMessage_DEFAULT NULL
#define alox_UartMessage_payload_ack_payload_MSGTYPE alox_Ack
@@ -476,8 +532,10 @@ X(a, STATIC, ONEOF, MESSAGE, (payload,accel_read_response,payload.accel_re
#define alox_UartMessage_payload_espnow_find_me_response_MSGTYPE alox_EspNowFindMeResponse
#define alox_UartMessage_payload_restart_request_MSGTYPE alox_RestartRequest
#define alox_UartMessage_payload_restart_response_MSGTYPE alox_RestartResponse
-#define alox_UartMessage_payload_accel_read_request_MSGTYPE alox_AccelReadRequest
-#define alox_UartMessage_payload_accel_read_response_MSGTYPE alox_AccelReadResponse
+#define alox_UartMessage_payload_accel_snapshot_request_MSGTYPE alox_AccelSnapshotRequest
+#define alox_UartMessage_payload_accel_snapshot_response_MSGTYPE alox_AccelSnapshotResponse
+#define alox_UartMessage_payload_accel_stream_request_MSGTYPE alox_AccelStreamRequest
+#define alox_UartMessage_payload_accel_stream_response_MSGTYPE alox_AccelStreamResponse
#define alox_Ack_FIELDLIST(X, a) \
@@ -503,7 +561,8 @@ X(a, STATIC, SINGULAR, BOOL, used, 3) \
X(a, CALLBACK, SINGULAR, BYTES, mac, 4) \
X(a, STATIC, SINGULAR, UINT32, last_ping, 5) \
X(a, STATIC, SINGULAR, UINT32, last_success_ping, 6) \
-X(a, STATIC, SINGULAR, UINT32, version, 7)
+X(a, STATIC, SINGULAR, UINT32, version, 7) \
+X(a, STATIC, SINGULAR, BOOL, accel_stream_enabled, 8)
#define alox_ClientInfo_CALLBACK pb_default_field_callback
#define alox_ClientInfo_DEFAULT NULL
@@ -543,18 +602,42 @@ X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
#define alox_AccelDeadzoneResponse_CALLBACK NULL
#define alox_AccelDeadzoneResponse_DEFAULT NULL
-#define alox_AccelReadRequest_FIELDLIST(X, a) \
+#define alox_AccelStreamRequest_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, BOOL, write, 1) \
+X(a, STATIC, SINGULAR, BOOL, enable, 2) \
+X(a, STATIC, SINGULAR, UINT32, client_id, 3) \
+X(a, STATIC, SINGULAR, BOOL, all_clients, 4)
+#define alox_AccelStreamRequest_CALLBACK NULL
+#define alox_AccelStreamRequest_DEFAULT NULL
-#define alox_AccelReadRequest_CALLBACK NULL
-#define alox_AccelReadRequest_DEFAULT NULL
+#define alox_AccelStreamResponse_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, BOOL, enabled, 1) \
+X(a, STATIC, SINGULAR, UINT32, client_id, 2) \
+X(a, STATIC, SINGULAR, BOOL, success, 3) \
+X(a, STATIC, SINGULAR, UINT32, slaves_updated, 4)
+#define alox_AccelStreamResponse_CALLBACK NULL
+#define alox_AccelStreamResponse_DEFAULT NULL
-#define alox_AccelReadResponse_FIELDLIST(X, a) \
-X(a, STATIC, SINGULAR, BOOL, success, 1) \
-X(a, STATIC, SINGULAR, SINT32, x, 2) \
-X(a, STATIC, SINGULAR, SINT32, y, 3) \
-X(a, STATIC, SINGULAR, SINT32, z, 4)
-#define alox_AccelReadResponse_CALLBACK NULL
-#define alox_AccelReadResponse_DEFAULT NULL
+#define alox_AccelSnapshotRequest_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, UINT32, client_id, 1)
+#define alox_AccelSnapshotRequest_CALLBACK NULL
+#define alox_AccelSnapshotRequest_DEFAULT NULL
+
+#define alox_AccelSample_FIELDLIST(X, a) \
+X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
+X(a, STATIC, SINGULAR, BOOL, valid, 2) \
+X(a, STATIC, SINGULAR, SINT32, x, 3) \
+X(a, STATIC, SINGULAR, SINT32, y, 4) \
+X(a, STATIC, SINGULAR, SINT32, z, 5) \
+X(a, STATIC, SINGULAR, UINT32, age_ms, 6)
+#define alox_AccelSample_CALLBACK NULL
+#define alox_AccelSample_DEFAULT NULL
+
+#define alox_AccelSnapshotResponse_FIELDLIST(X, a) \
+X(a, STATIC, REPEATED, MESSAGE, samples, 1)
+#define alox_AccelSnapshotResponse_CALLBACK NULL
+#define alox_AccelSnapshotResponse_DEFAULT NULL
+#define alox_AccelSnapshotResponse_samples_MSGTYPE alox_AccelSample
#define alox_EspNowUnicastTestRequest_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, client_id, 1) \
@@ -669,8 +752,11 @@ extern const pb_msgdesc_t alox_ClientInput_msg;
extern const pb_msgdesc_t alox_ClientInputResponse_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneRequest_msg;
extern const pb_msgdesc_t alox_AccelDeadzoneResponse_msg;
-extern const pb_msgdesc_t alox_AccelReadRequest_msg;
-extern const pb_msgdesc_t alox_AccelReadResponse_msg;
+extern const pb_msgdesc_t alox_AccelStreamRequest_msg;
+extern const pb_msgdesc_t alox_AccelStreamResponse_msg;
+extern const pb_msgdesc_t alox_AccelSnapshotRequest_msg;
+extern const pb_msgdesc_t alox_AccelSample_msg;
+extern const pb_msgdesc_t alox_AccelSnapshotResponse_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestRequest_msg;
extern const pb_msgdesc_t alox_EspNowUnicastTestResponse_msg;
extern const pb_msgdesc_t alox_LedRingProgressRequest_msg;
@@ -698,8 +784,11 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
#define alox_ClientInputResponse_fields &alox_ClientInputResponse_msg
#define alox_AccelDeadzoneRequest_fields &alox_AccelDeadzoneRequest_msg
#define alox_AccelDeadzoneResponse_fields &alox_AccelDeadzoneResponse_msg
-#define alox_AccelReadRequest_fields &alox_AccelReadRequest_msg
-#define alox_AccelReadResponse_fields &alox_AccelReadResponse_msg
+#define alox_AccelStreamRequest_fields &alox_AccelStreamRequest_msg
+#define alox_AccelStreamResponse_fields &alox_AccelStreamResponse_msg
+#define alox_AccelSnapshotRequest_fields &alox_AccelSnapshotRequest_msg
+#define alox_AccelSample_fields &alox_AccelSample_msg
+#define alox_AccelSnapshotResponse_fields &alox_AccelSnapshotResponse_msg
#define alox_EspNowUnicastTestRequest_fields &alox_EspNowUnicastTestRequest_msg
#define alox_EspNowUnicastTestResponse_fields &alox_EspNowUnicastTestResponse_msg
#define alox_LedRingProgressRequest_fields &alox_LedRingProgressRequest_msg
@@ -723,11 +812,14 @@ extern const pb_msgdesc_t alox_OtaSlaveProgressResponse_msg;
/* alox_ClientInfo_size depends on runtime parameters */
/* alox_ClientInfoResponse_size depends on runtime parameters */
/* alox_ClientInputResponse_size depends on runtime parameters */
-#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_OtaSlaveProgressResponse_size
+#define ALOX_UART_MESSAGES_PB_H_MAX_SIZE alox_AccelSnapshotResponse_size
#define alox_AccelDeadzoneRequest_size 16
#define alox_AccelDeadzoneResponse_size 20
-#define alox_AccelReadRequest_size 0
-#define alox_AccelReadResponse_size 20
+#define alox_AccelSample_size 32
+#define alox_AccelSnapshotRequest_size 6
+#define alox_AccelSnapshotResponse_size 544
+#define alox_AccelStreamRequest_size 12
+#define alox_AccelStreamResponse_size 16
#define alox_Ack_size 0
#define alox_ClientInput_size 22
#define alox_EspNowFindMeRequest_size 6
diff --git a/main/proto/uart_messages.proto b/main/proto/uart_messages.proto
index 1f50a74..20b63e0 100644
--- a/main/proto/uart_messages.proto
+++ b/main/proto/uart_messages.proto
@@ -22,7 +22,8 @@ enum MessageType {
OTA_SLAVE_PROGRESS = 21;
FIND_ME = 22;
RESTART = 23;
- ACCEL_READ = 24;
+ ACCEL_SNAPSHOT = 24;
+ ACCEL_STREAM = 25;
}
message UartMessage {
@@ -49,8 +50,10 @@ message UartMessage {
EspNowFindMeResponse espnow_find_me_response = 20;
RestartRequest restart_request = 21;
RestartResponse restart_response = 22;
- AccelReadRequest accel_read_request = 23;
- AccelReadResponse accel_read_response = 24;
+ AccelSnapshotRequest accel_snapshot_request = 23;
+ AccelSnapshotResponse accel_snapshot_response = 24;
+ AccelStreamRequest accel_stream_request = 25;
+ AccelStreamResponse accel_stream_response = 26;
}
}
@@ -75,6 +78,8 @@ message ClientInfo {
uint32 last_ping = 5;
uint32 last_success_ping = 6;
uint32 version = 7;
+ /** Master: ESP-NOW accel stream enabled for this slave. */
+ bool accel_stream_enabled = 8;
}
message ClientInfoResponse {
@@ -109,14 +114,40 @@ message AccelDeadzoneResponse {
uint32 slaves_updated = 4;
}
-// Host → device: read current BMA456 accelerometer sample (raw LSB, ±2g range).
-message AccelReadRequest {}
+// Host → master: enable/disable slave accel ESP-NOW stream (~16 ms per slave).
+// write=false: read; write=true: apply. client_id 0 invalid for write (use >0 or all_clients).
+message AccelStreamRequest {
+ bool write = 1;
+ bool enable = 2;
+ uint32 client_id = 3;
+ bool all_clients = 4;
+}
-message AccelReadResponse {
- bool success = 1;
- sint32 x = 2;
- sint32 y = 3;
- sint32 z = 4;
+message AccelStreamResponse {
+ bool enabled = 1;
+ uint32 client_id = 2;
+ bool success = 3;
+ uint32 slaves_updated = 4;
+}
+
+// Host → master: read cached accel samples from slaves (only while stream enabled).
+// client_id 0 = all registered slaves; otherwise one slave.
+message AccelSnapshotRequest {
+ uint32 client_id = 1;
+}
+
+message AccelSample {
+ uint32 client_id = 1;
+ bool valid = 2;
+ sint32 x = 3;
+ sint32 y = 4;
+ sint32 z = 5;
+ /** Milliseconds since last ESP-NOW sample from this slave. */
+ uint32 age_ms = 6;
+}
+
+message AccelSnapshotResponse {
+ repeated AccelSample samples = 1 [(nanopb).max_count = 16];
}
message EspNowUnicastTestRequest {
diff --git a/main/uart.h b/main/uart.h
index f652468..2023219 100644
--- a/main/uart.h
+++ b/main/uart.h
@@ -9,8 +9,12 @@
#define UART_NUM UART_NUM_1
#define UART_BAUD_RATE 921600
-#define UART_TXD_PIN 3
-#define UART_RXD_PIN 2
+// #define UART_TXD_PIN 3
+// #define UART_RXD_PIN 2
+
+#define UART_TXD_PIN 2
+#define UART_RXD_PIN 3
+
#define UART_BUF_SIZE 2048
#define START_MARKER 0xAA
| ||||