Add LiPo battery monitoring with ESP-NOW cache and dashboard API.

Slaves report pack voltages every 30s; the master caches them for fast
BATTERY_STATUS reads. goTool exposes REST/WebSocket and shows values in
the dashboard, with a nanopb fix so optional lipo submessages encode.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 20:14:28 +02:00
co-authored by Cursor
parent eb67a46158
commit 3cb0b5bbe9
30 changed files with 1618 additions and 150 deletions
+12 -2
View File
@@ -87,7 +87,7 @@ Polling runs only when at least one connection has `receive_accel: true` **and**
**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","set_led_ring"]}
{"type":"hello","serial_port":"/dev/ttyUSB0","interval_ms":16,"commands":["set_stream","get_stream","set_accel_stream","get_accel_stream","set_led_ring","get_battery"]}
```
**Receive accel on this connection** (optional `interval_ms`, default from `-accel-interval`):
@@ -167,7 +167,7 @@ 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`, `GET/PUT /api/clients/{id}/accel-stream`, `POST /api/accel-stream` (legacy / `all_clients`), `POST /api/led-ring`, `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`), `GET/POST /api/battery`, `POST /api/led-ring`, `POST /api/unicast-test`, `POST /api/find-me`, `POST /api/restart`, `POST /api/ota` (multipart field `firmware`, max 2 MiB).
**LED ring** (`POST /api/led-ring` and WebSocket `set_led_ring` on `:8081`):
@@ -179,6 +179,16 @@ HTTP API (used by the web UI): `GET/POST /api/deadzone`, `GET/PUT /api/clients/{
Modes: `clear`, `color` (full ring), `progress` (0100), `digit` (010 symbols), `blink`, `find-me`. Use `client_id` (0 = master), or `all_clients` (+ optional `slaves_only`) for broadcast.
**Battery** (`GET/POST /api/battery`, WebSocket `get_battery` on `:8081`):
```json
{"all_clients":true}
{"client_id":0}
{"client_id":16}
```
Response: `samples[]` with `client_id`, `lipo1`/`lipo2` (`valid`, `voltage_mv`, `percent`), `age_ms`. Slaves push to the master every **30 s**; UART reads the cache (fast). Dashboard polls with `all_clients`.
**Accel stream per slave** (must be enabled before values appear; goTool polls only while at least one slave has stream on):
```http
+60
View File
@@ -0,0 +1,60 @@
package main
import (
"encoding/json"
"net/http"
"strconv"
)
func mountBatteryAPI(mux *http.ServeMux, link *managedSerial) {
mux.HandleFunc("/api/battery", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
serveBatteryGet(w, r, link)
case http.MethodPost:
serveBatteryPost(w, r, link)
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
})
}
func serveBatteryGet(w http.ResponseWriter, r *http.Request, link *managedSerial) {
req := batteryAPIRequest{}
if v := r.URL.Query().Get("all_clients"); v == "1" || v == "true" {
req.AllClients = true
}
if s := r.URL.Query().Get("client_id"); s != "" {
id, err := strconv.ParseUint(s, 10, 32)
if err != nil {
writeJSON(w, http.StatusBadRequest, batteryAPIResponse{Error: "invalid client_id"})
return
}
req.ClientID = uint32(id)
} else if !req.AllClients {
req.AllClients = true
}
out := applyBatteryStatus(link, req)
status := http.StatusOK
if out.Error != "" || !out.Success {
status = http.StatusServiceUnavailable
}
writeJSON(w, status, out)
}
func serveBatteryPost(w http.ResponseWriter, r *http.Request, link *managedSerial) {
var body batteryAPIRequest
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
writeJSON(w, http.StatusBadRequest, batteryAPIResponse{Error: "invalid JSON"})
return
}
if !body.AllClients && body.ClientID == 0 {
body.AllClients = true
}
out := applyBatteryStatus(link, body)
status := http.StatusOK
if out.Error != "" || !out.Success {
status = http.StatusServiceUnavailable
}
writeJSON(w, status, out)
}
+1
View File
@@ -70,6 +70,7 @@ type otaAPIResponse struct {
func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, streamCtl *accelStreamCtl) {
mountAccelStreamAPI(mux, link, hub, streamCtl)
mountLedRingAPI(mux, link)
mountBatteryAPI(mux, link)
mux.HandleFunc("/api/deadzone", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
+24 -2
View File
@@ -133,7 +133,8 @@ func (h *accelStreamHub) register(conn *websocket.Conn, portName string) *wsSubs
Serial: portName,
IntervalMs: int(h.defaultInterval / time.Millisecond),
Commands: []string{
"set_stream", "get_stream", "set_accel_stream", "get_accel_stream", "set_led_ring",
"set_stream", "get_stream", "set_accel_stream", "get_accel_stream",
"set_led_ring", "get_battery",
},
}
if data, err := json.Marshal(hello); err == nil {
@@ -319,6 +320,15 @@ func writeStreamStatus(conn *websocket.Conn, msg StreamStatusMessage) {
_ = conn.WriteMessage(websocket.TextMessage, data)
}
func writeBatteryStatus(conn *websocket.Conn, out batteryAPIResponse) {
out.Type = "battery_status"
data, err := json.Marshal(out)
if err != nil {
return
}
_ = conn.WriteMessage(websocket.TextMessage, data)
}
func writeLedRingStatus(conn *websocket.Conn, out ledRingAPIResponse) {
out.Type = "led_ring_status"
data, err := json.Marshal(out)
@@ -416,10 +426,21 @@ func handleAccelWSCommand(conn *websocket.Conn, sub *wsSubscriber, data []byte,
}
writeLedRingStatus(conn, applyLedRing(link, body))
case "get_battery":
var body batteryAPIRequest
if err := json.Unmarshal(data, &body); err != nil {
writeBatteryStatus(conn, batteryAPIResponse{Error: "invalid JSON"})
return
}
if !body.AllClients && body.ClientID == 0 {
body.AllClients = true
}
writeBatteryStatus(conn, applyBatteryStatus(link, body))
default:
writeStreamStatus(conn, StreamStatusMessage{
Type: "stream_status",
Error: "unknown type (set_stream, get_stream, set_accel_stream, get_accel_stream, set_led_ring)",
Error: "unknown type (set_stream, get_stream, set_accel_stream, get_accel_stream, set_led_ring, get_battery)",
})
}
}
@@ -478,6 +499,7 @@ func runAPIServer(portName string, link *managedSerial, addr string, defaultInte
mux := http.NewServeMux()
mountExternalAPI(mux, portName, defaultInterval, hub, link, dash, ctl)
mountLedRingAPI(mux, link)
mountBatteryAPI(mux, link)
srv := &http.Server{Addr: addr, Handler: mux}
go func() {
+120
View File
@@ -0,0 +1,120 @@
package main
import (
"powerpod/gotool/pb"
)
const (
lipoMinMv = 3000
lipoMaxMv = 4200
)
type lipoReadingJSON struct {
Valid bool `json:"valid"`
VoltageMv uint32 `json:"voltage_mv"`
Percent int `json:"percent,omitempty"`
}
type batterySampleJSON struct {
ClientID uint32 `json:"client_id"`
Lipo1 lipoReadingJSON `json:"lipo1"`
Lipo2 lipoReadingJSON `json:"lipo2"`
AgeMs uint32 `json:"age_ms,omitempty"`
}
type batteryAPIRequest struct {
ClientID uint32 `json:"client_id"`
AllClients bool `json:"all_clients"`
}
type batteryAPIResponse struct {
Type string `json:"type,omitempty"` // battery_status (WebSocket)
Success bool `json:"success"`
Samples []batterySampleJSON `json:"samples,omitempty"`
Error string `json:"error,omitempty"`
}
func lipoPercent(mv uint32) int {
if mv <= lipoMinMv {
return 0
}
if mv >= lipoMaxMv {
return 100
}
return int((mv - lipoMinMv) * 100 / (lipoMaxMv - lipoMinMv))
}
func lipoFromPBMsg(l *pb.LipoReading) lipoReadingJSON {
if l == nil {
return lipoReadingJSON{}
}
return lipoFromPB(l.GetValid(), l.GetVoltageMv())
}
func lipoFromPB(valid bool, mv uint32) lipoReadingJSON {
out := lipoReadingJSON{Valid: valid, VoltageMv: mv}
if valid {
out.Percent = lipoPercent(mv)
}
return out
}
func batterySamplesFromPB(samples []*pb.BatterySample) []batterySampleJSON {
out := make([]batterySampleJSON, 0, len(samples))
for _, s := range samples {
out = append(out, batterySampleJSON{
ClientID: s.GetClientId(),
Lipo1: lipoFromPBMsg(s.GetLipo1()),
Lipo2: lipoFromPBMsg(s.GetLipo2()),
AgeMs: s.GetAgeMs(),
})
}
return out
}
func applyBatteryStatus(link *managedSerial, in batteryAPIRequest) batteryAPIResponse {
resp, err := link.BatteryStatus(&pb.BatteryStatusRequest{
ClientId: in.ClientID,
AllClients: in.AllClients,
})
if err != nil {
return batteryAPIResponse{Error: err.Error()}
}
samples := batterySamplesFromPB(resp.GetSamples())
out := batteryAPIResponse{
Success: resp.GetSuccess() || len(samples) > 0,
Samples: samples,
}
if len(samples) == 0 && out.Error == "" {
out.Error = "battery status unavailable"
}
return out
}
func findBatterySample(samples []batterySampleJSON, clientID uint32) (batterySampleJSON, bool) {
for _, s := range samples {
if s.ClientID == clientID {
return s, true
}
}
return batterySampleJSON{}, false
}
// applyBatterySamplesToState merges UART/REST battery samples into dashboard views.
func applyBatterySamplesToState(st *DashboardState, samples []batterySampleJSON) {
if st == nil || len(samples) == 0 {
return
}
if m, ok := findBatterySample(samples, 0); ok {
st.Master.Lipo1 = m.Lipo1
st.Master.Lipo2 = m.Lipo2
st.Master.BatteryAgeMs = m.AgeMs
}
for i := range st.Clients {
if s, ok := findBatterySample(samples, st.Clients[i].ID); ok {
st.Clients[i].Lipo1 = s.Lipo1
st.Clients[i].Lipo2 = s.Lipo2
st.Clients[i].BatteryAgeMs = s.AgeMs
}
}
}
+80
View File
@@ -59,6 +59,86 @@ func (m *managedSerial) readAccelSnapshotPoll(clientID uint32) (*pb.AccelSnapsho
return decodeAccelSnapshotPayload(respPayload)
}
func decodeBatteryStatusPayload(payload []byte) (*pb.BatteryStatusResponse, error) {
if len(payload) < 2 {
return nil, fmt.Errorf("short battery response")
}
if payload[0] != byte(pb.MessageType_BATTERY_STATUS) {
return nil, fmt.Errorf("unexpected command id 0x%02x (want 0x%02x)",
payload[0], byte(pb.MessageType_BATTERY_STATUS))
}
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_BATTERY_STATUS {
return nil, fmt.Errorf("unexpected type %v", msg.GetType())
}
r := msg.GetBatteryStatusResponse()
if r == nil {
return nil, fmt.Errorf("missing battery_status_response")
}
return r, nil
}
func (m *managedSerial) BatteryStatus(req *pb.BatteryStatusRequest) (*pb.BatteryStatusResponse, error) {
var resp *pb.BatteryStatusResponse
err := m.withPort(func(sp *serialPort) error {
var e error
resp, e = sp.batteryStatus(req)
return e
})
return resp, err
}
func (m *managedSerial) BatteryStatusPoll(req *pb.BatteryStatusRequest) (*pb.BatteryStatusResponse, error) {
msg := &pb.UartMessage{
Type: pb.MessageType_BATTERY_STATUS,
Payload: &pb.UartMessage_BatteryStatusRequest{
BatteryStatusRequest: req,
},
}
body, err := proto.Marshal(msg)
if err != nil {
return nil, fmt.Errorf("encode: %w", err)
}
payload := append([]byte{byte(pb.MessageType_BATTERY_STATUS)}, body...)
respPayload, err := m.batteryStatusPayloadPoll(payload)
if err != nil {
return nil, err
}
return decodeBatteryStatusPayload(respPayload)
}
func (m *managedSerial) batteryStatusPayloadPoll(payload []byte) ([]byte, error) {
var resp []byte
err := m.withPortPoll(func(sp *serialPort) error {
var e error
resp, e = sp.exchangePayloadForBattery(payload, "BATTERY_STATUS")
return e
})
return resp, err
}
func (s *serialPort) batteryStatus(req *pb.BatteryStatusRequest) (*pb.BatteryStatusResponse, error) {
msg := &pb.UartMessage{
Type: pb.MessageType_BATTERY_STATUS,
Payload: &pb.UartMessage_BatteryStatusRequest{
BatteryStatusRequest: req,
},
}
body, err := proto.Marshal(msg)
if err != nil {
return nil, fmt.Errorf("encode: %w", err)
}
payload := append([]byte{byte(pb.MessageType_BATTERY_STATUS)}, body...)
respPayload, err := s.exchangePayloadForBattery(payload, "BATTERY_STATUS")
if err != nil {
return nil, err
}
return decodeBatteryStatusPayload(respPayload)
}
func (m *managedSerial) AccelStream(req *pb.AccelStreamRequest) (*pb.AccelStreamResponse, error) {
return m.accelStreamVia(m.withPort, req)
}
+1
View File
@@ -41,6 +41,7 @@ func runServe(portName string, baud int, args []string) error {
stop := make(chan struct{})
defer close(stop)
go runPoller(link, portName, hub, streamCtl, *interval, stop)
go runBatteryPoller(link, hub, 5*time.Second, stop)
go runAccelDashboardPoller(link, hub, *accelInterval, stop)
var apiSrv *http.Server
+100 -4
View File
@@ -19,7 +19,10 @@ type MasterView struct {
GitHash string `json:"git_hash"`
RunningPartition string `json:"running_partition,omitempty"`
Deadzone uint32 `json:"deadzone,omitempty"`
OK bool `json:"ok"`
Lipo1 lipoReadingJSON `json:"lipo1"`
Lipo2 lipoReadingJSON `json:"lipo2"`
BatteryAgeMs uint32 `json:"battery_age_ms,omitempty"`
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
}
@@ -37,7 +40,10 @@ type ClientView struct {
AccelY int32 `json:"accel_y"`
AccelZ int32 `json:"accel_z"`
AccelAgeMs uint32 `json:"accel_age_ms"`
AccelStream bool `json:"accel_stream"`
AccelStream bool `json:"accel_stream"`
Lipo1 lipoReadingJSON `json:"lipo1"`
Lipo2 lipoReadingJSON `json:"lipo2"`
BatteryAgeMs uint32 `json:"battery_age_ms,omitempty"`
}
type DashboardState struct {
@@ -62,8 +68,16 @@ func newWSHub() *wsHub {
func (h *wsHub) setState(st DashboardState) {
h.mu.Lock()
prev := h.state.Clients
st.Clients = preserveClientAccel(st.Clients, prev)
prev := h.state
st.Clients = preserveClientAccel(st.Clients, prev.Clients)
st.Clients = preserveClientBattery(st.Clients, prev.Clients)
if !st.Master.Lipo1.Valid && !st.Master.Lipo2.Valid {
if prev.Master.Lipo1.Valid || prev.Master.Lipo2.Valid {
st.Master.Lipo1 = prev.Master.Lipo1
st.Master.Lipo2 = prev.Master.Lipo2
st.Master.BatteryAgeMs = prev.Master.BatteryAgeMs
}
}
h.state = st
conns := make([]*websocket.Conn, 0, len(h.clients))
for c := range h.clients {
@@ -156,6 +170,33 @@ func preserveClientAccel(newClients, oldClients []ClientView) []ClientView {
return out
}
func preserveClientBattery(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.Lipo1.Valid || c.Lipo2.Valid {
continue
}
prev, ok := oldByID[c.ID]
if !ok {
continue
}
if prev.Lipo1.Valid || prev.Lipo2.Valid {
out[i].Lipo1 = prev.Lipo1
out[i].Lipo2 = prev.Lipo2
out[i].BatteryAgeMs = prev.BatteryAgeMs
}
}
return out
}
func anyClientAccelStream(clients []ClientView) bool {
for _, c := range clients {
if c.AccelStream {
@@ -294,6 +335,7 @@ func pollDashboard(link *managedSerial, portName string, last *DashboardState, s
}
st.Clients = append(st.Clients, cv)
}
applyBatteryToState(link, &st)
if anyClientAccelStream(st.Clients) {
for i := range st.Clients {
if !st.Clients[i].AccelStream {
@@ -319,6 +361,60 @@ func pollDashboard(link *managedSerial, portName string, last *DashboardState, s
return st
}
func applyBatteryToState(link *managedSerial, st *DashboardState) {
bat, err := link.BatteryStatusPoll(&pb.BatteryStatusRequest{AllClients: true})
if err != nil {
log.Printf("battery poll: %v", err)
return
}
applyBatterySamplesToState(st, batterySamplesFromPB(bat.GetSamples()))
}
func (h *wsHub) mergeBattery(samples []batterySampleJSON) {
if len(samples) == 0 {
return
}
h.mu.Lock()
st := h.state
applyBatterySamplesToState(&st, 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 runBatteryPoller(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 {
continue
}
bat, err := link.BatteryStatusPoll(&pb.BatteryStatusRequest{AllClients: true})
if err != nil {
continue
}
hub.mergeBattery(batterySamplesFromPB(bat.GetSamples()))
}
}
}
func runAccelDashboardPoller(link *managedSerial, hub *wsHub, interval time.Duration, stop <-chan struct{}) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
+398 -104
View File
@@ -43,6 +43,7 @@ const (
MessageType_RESTART MessageType = 23
MessageType_ACCEL_SNAPSHOT MessageType = 24
MessageType_ACCEL_STREAM MessageType = 25
MessageType_BATTERY_STATUS MessageType = 26
)
// Enum value maps for MessageType.
@@ -67,6 +68,7 @@ var (
23: "RESTART",
24: "ACCEL_SNAPSHOT",
25: "ACCEL_STREAM",
26: "BATTERY_STATUS",
}
MessageType_value = map[string]int32{
"UNKNOWN": 0,
@@ -88,6 +90,7 @@ var (
"RESTART": 23,
"ACCEL_SNAPSHOT": 24,
"ACCEL_STREAM": 25,
"BATTERY_STATUS": 26,
}
)
@@ -148,6 +151,8 @@ type UartMessage struct {
// *UartMessage_AccelSnapshotResponse
// *UartMessage_AccelStreamRequest
// *UartMessage_AccelStreamResponse
// *UartMessage_BatteryStatusRequest
// *UartMessage_BatteryStatusResponse
Payload isUartMessage_Payload `protobuf_oneof:"payload"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -422,6 +427,24 @@ func (x *UartMessage) GetAccelStreamResponse() *AccelStreamResponse {
return nil
}
func (x *UartMessage) GetBatteryStatusRequest() *BatteryStatusRequest {
if x != nil {
if x, ok := x.Payload.(*UartMessage_BatteryStatusRequest); ok {
return x.BatteryStatusRequest
}
}
return nil
}
func (x *UartMessage) GetBatteryStatusResponse() *BatteryStatusResponse {
if x != nil {
if x, ok := x.Payload.(*UartMessage_BatteryStatusResponse); ok {
return x.BatteryStatusResponse
}
}
return nil
}
type isUartMessage_Payload interface {
isUartMessage_Payload()
}
@@ -526,6 +549,14 @@ type UartMessage_AccelStreamResponse struct {
AccelStreamResponse *AccelStreamResponse `protobuf:"bytes,26,opt,name=accel_stream_response,json=accelStreamResponse,proto3,oneof"`
}
type UartMessage_BatteryStatusRequest struct {
BatteryStatusRequest *BatteryStatusRequest `protobuf:"bytes,27,opt,name=battery_status_request,json=batteryStatusRequest,proto3,oneof"`
}
type UartMessage_BatteryStatusResponse struct {
BatteryStatusResponse *BatteryStatusResponse `protobuf:"bytes,28,opt,name=battery_status_response,json=batteryStatusResponse,proto3,oneof"`
}
func (*UartMessage_AckPayload) isUartMessage_Payload() {}
func (*UartMessage_EchoPayload) isUartMessage_Payload() {}
@@ -576,6 +607,10 @@ func (*UartMessage_AccelStreamRequest) isUartMessage_Payload() {}
func (*UartMessage_AccelStreamResponse) isUartMessage_Payload() {}
func (*UartMessage_BatteryStatusRequest) isUartMessage_Payload() {}
func (*UartMessage_BatteryStatusResponse) isUartMessage_Payload() {}
type Ack struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
@@ -1251,6 +1286,235 @@ func (x *AccelStreamResponse) GetSlavesUpdated() uint32 {
return 0
}
// * Host → master: read LiPo ADC voltages (master local and/or slaves via ESP-NOW).
type BatteryStatusRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
// * 0 = master only; >0 = one slave; ignored when all_clients
ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
// * Master (client_id 0) plus every registered slave
AllClients bool `protobuf:"varint,2,opt,name=all_clients,json=allClients,proto3" json:"all_clients,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *BatteryStatusRequest) Reset() {
*x = BatteryStatusRequest{}
mi := &file_uart_messages_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *BatteryStatusRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BatteryStatusRequest) ProtoMessage() {}
func (x *BatteryStatusRequest) 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 BatteryStatusRequest.ProtoReflect.Descriptor instead.
func (*BatteryStatusRequest) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{12}
}
func (x *BatteryStatusRequest) GetClientId() uint32 {
if x != nil {
return x.ClientId
}
return 0
}
func (x *BatteryStatusRequest) GetAllClients() bool {
if x != nil {
return x.AllClients
}
return false
}
type LipoReading struct {
state protoimpl.MessageState `protogen:"open.v1"`
Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"`
// * Estimated pack voltage in millivolts from ADC
VoltageMv uint32 `protobuf:"varint,2,opt,name=voltage_mv,json=voltageMv,proto3" json:"voltage_mv,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LipoReading) Reset() {
*x = LipoReading{}
mi := &file_uart_messages_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LipoReading) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LipoReading) ProtoMessage() {}
func (x *LipoReading) 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 LipoReading.ProtoReflect.Descriptor instead.
func (*LipoReading) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{13}
}
func (x *LipoReading) GetValid() bool {
if x != nil {
return x.Valid
}
return false
}
func (x *LipoReading) GetVoltageMv() uint32 {
if x != nil {
return x.VoltageMv
}
return 0
}
type BatterySample struct {
state protoimpl.MessageState `protogen:"open.v1"`
ClientId uint32 `protobuf:"varint,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
Lipo1 *LipoReading `protobuf:"bytes,2,opt,name=lipo1,proto3" json:"lipo1,omitempty"`
Lipo2 *LipoReading `protobuf:"bytes,3,opt,name=lipo2,proto3" json:"lipo2,omitempty"`
// * Milliseconds since last ESP-NOW battery report from this pod.
AgeMs uint32 `protobuf:"varint,4,opt,name=age_ms,json=ageMs,proto3" json:"age_ms,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *BatterySample) Reset() {
*x = BatterySample{}
mi := &file_uart_messages_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *BatterySample) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BatterySample) ProtoMessage() {}
func (x *BatterySample) 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 BatterySample.ProtoReflect.Descriptor instead.
func (*BatterySample) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{14}
}
func (x *BatterySample) GetClientId() uint32 {
if x != nil {
return x.ClientId
}
return 0
}
func (x *BatterySample) GetLipo1() *LipoReading {
if x != nil {
return x.Lipo1
}
return nil
}
func (x *BatterySample) GetLipo2() *LipoReading {
if x != nil {
return x.Lipo2
}
return nil
}
func (x *BatterySample) GetAgeMs() uint32 {
if x != nil {
return x.AgeMs
}
return 0
}
type BatteryStatusResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
Samples []*BatterySample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *BatteryStatusResponse) Reset() {
*x = BatteryStatusResponse{}
mi := &file_uart_messages_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *BatteryStatusResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BatteryStatusResponse) ProtoMessage() {}
func (x *BatteryStatusResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[15]
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 BatteryStatusResponse.ProtoReflect.Descriptor instead.
func (*BatteryStatusResponse) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{15}
}
func (x *BatteryStatusResponse) GetSuccess() bool {
if x != nil {
return x.Success
}
return false
}
func (x *BatteryStatusResponse) GetSamples() []*BatterySample {
if x != nil {
return x.Samples
}
return nil
}
// Host → master: read cached accel samples from slaves (only while stream enabled).
// client_id 0 = all registered slaves; otherwise one slave.
type AccelSnapshotRequest struct {
@@ -1262,7 +1526,7 @@ type AccelSnapshotRequest struct {
func (x *AccelSnapshotRequest) Reset() {
*x = AccelSnapshotRequest{}
mi := &file_uart_messages_proto_msgTypes[12]
mi := &file_uart_messages_proto_msgTypes[16]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1274,7 +1538,7 @@ func (x *AccelSnapshotRequest) String() string {
func (*AccelSnapshotRequest) ProtoMessage() {}
func (x *AccelSnapshotRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[12]
mi := &file_uart_messages_proto_msgTypes[16]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1287,7 +1551,7 @@ func (x *AccelSnapshotRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use AccelSnapshotRequest.ProtoReflect.Descriptor instead.
func (*AccelSnapshotRequest) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{12}
return file_uart_messages_proto_rawDescGZIP(), []int{16}
}
func (x *AccelSnapshotRequest) GetClientId() uint32 {
@@ -1312,7 +1576,7 @@ type AccelSample struct {
func (x *AccelSample) Reset() {
*x = AccelSample{}
mi := &file_uart_messages_proto_msgTypes[13]
mi := &file_uart_messages_proto_msgTypes[17]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1324,7 +1588,7 @@ func (x *AccelSample) String() string {
func (*AccelSample) ProtoMessage() {}
func (x *AccelSample) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[13]
mi := &file_uart_messages_proto_msgTypes[17]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1337,7 +1601,7 @@ func (x *AccelSample) ProtoReflect() protoreflect.Message {
// Deprecated: Use AccelSample.ProtoReflect.Descriptor instead.
func (*AccelSample) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{13}
return file_uart_messages_proto_rawDescGZIP(), []int{17}
}
func (x *AccelSample) GetClientId() uint32 {
@@ -1391,7 +1655,7 @@ type AccelSnapshotResponse struct {
func (x *AccelSnapshotResponse) Reset() {
*x = AccelSnapshotResponse{}
mi := &file_uart_messages_proto_msgTypes[14]
mi := &file_uart_messages_proto_msgTypes[18]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1403,7 +1667,7 @@ func (x *AccelSnapshotResponse) String() string {
func (*AccelSnapshotResponse) ProtoMessage() {}
func (x *AccelSnapshotResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[14]
mi := &file_uart_messages_proto_msgTypes[18]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1416,7 +1680,7 @@ func (x *AccelSnapshotResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use AccelSnapshotResponse.ProtoReflect.Descriptor instead.
func (*AccelSnapshotResponse) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{14}
return file_uart_messages_proto_rawDescGZIP(), []int{18}
}
func (x *AccelSnapshotResponse) GetSamples() []*AccelSample {
@@ -1436,7 +1700,7 @@ type EspNowUnicastTestRequest struct {
func (x *EspNowUnicastTestRequest) Reset() {
*x = EspNowUnicastTestRequest{}
mi := &file_uart_messages_proto_msgTypes[15]
mi := &file_uart_messages_proto_msgTypes[19]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1448,7 +1712,7 @@ func (x *EspNowUnicastTestRequest) String() string {
func (*EspNowUnicastTestRequest) ProtoMessage() {}
func (x *EspNowUnicastTestRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[15]
mi := &file_uart_messages_proto_msgTypes[19]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1461,7 +1725,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{15}
return file_uart_messages_proto_rawDescGZIP(), []int{19}
}
func (x *EspNowUnicastTestRequest) GetClientId() uint32 {
@@ -1488,7 +1752,7 @@ type EspNowUnicastTestResponse struct {
func (x *EspNowUnicastTestResponse) Reset() {
*x = EspNowUnicastTestResponse{}
mi := &file_uart_messages_proto_msgTypes[16]
mi := &file_uart_messages_proto_msgTypes[20]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1500,7 +1764,7 @@ func (x *EspNowUnicastTestResponse) String() string {
func (*EspNowUnicastTestResponse) ProtoMessage() {}
func (x *EspNowUnicastTestResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[16]
mi := &file_uart_messages_proto_msgTypes[20]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1513,7 +1777,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{16}
return file_uart_messages_proto_rawDescGZIP(), []int{20}
}
func (x *EspNowUnicastTestResponse) GetSuccess() bool {
@@ -1560,7 +1824,7 @@ type LedRingProgressRequest struct {
func (x *LedRingProgressRequest) Reset() {
*x = LedRingProgressRequest{}
mi := &file_uart_messages_proto_msgTypes[17]
mi := &file_uart_messages_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1572,7 +1836,7 @@ func (x *LedRingProgressRequest) String() string {
func (*LedRingProgressRequest) ProtoMessage() {}
func (x *LedRingProgressRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[17]
mi := &file_uart_messages_proto_msgTypes[21]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1585,7 +1849,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{17}
return file_uart_messages_proto_rawDescGZIP(), []int{21}
}
func (x *LedRingProgressRequest) GetMode() uint32 {
@@ -1686,7 +1950,7 @@ type LedRingProgressResponse struct {
func (x *LedRingProgressResponse) Reset() {
*x = LedRingProgressResponse{}
mi := &file_uart_messages_proto_msgTypes[18]
mi := &file_uart_messages_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1698,7 +1962,7 @@ func (x *LedRingProgressResponse) String() string {
func (*LedRingProgressResponse) ProtoMessage() {}
func (x *LedRingProgressResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[18]
mi := &file_uart_messages_proto_msgTypes[22]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1711,7 +1975,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{18}
return file_uart_messages_proto_rawDescGZIP(), []int{22}
}
func (x *LedRingProgressResponse) GetSuccess() bool {
@@ -1766,7 +2030,7 @@ type EspNowFindMeRequest struct {
func (x *EspNowFindMeRequest) Reset() {
*x = EspNowFindMeRequest{}
mi := &file_uart_messages_proto_msgTypes[19]
mi := &file_uart_messages_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1778,7 +2042,7 @@ func (x *EspNowFindMeRequest) String() string {
func (*EspNowFindMeRequest) ProtoMessage() {}
func (x *EspNowFindMeRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[19]
mi := &file_uart_messages_proto_msgTypes[23]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1791,7 +2055,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{19}
return file_uart_messages_proto_rawDescGZIP(), []int{23}
}
func (x *EspNowFindMeRequest) GetClientId() uint32 {
@@ -1811,7 +2075,7 @@ type EspNowFindMeResponse struct {
func (x *EspNowFindMeResponse) Reset() {
*x = EspNowFindMeResponse{}
mi := &file_uart_messages_proto_msgTypes[20]
mi := &file_uart_messages_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1823,7 +2087,7 @@ func (x *EspNowFindMeResponse) String() string {
func (*EspNowFindMeResponse) ProtoMessage() {}
func (x *EspNowFindMeResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[20]
mi := &file_uart_messages_proto_msgTypes[24]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1836,7 +2100,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{20}
return file_uart_messages_proto_rawDescGZIP(), []int{24}
}
func (x *EspNowFindMeResponse) GetSuccess() bool {
@@ -1863,7 +2127,7 @@ type RestartRequest struct {
func (x *RestartRequest) Reset() {
*x = RestartRequest{}
mi := &file_uart_messages_proto_msgTypes[21]
mi := &file_uart_messages_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1875,7 +2139,7 @@ func (x *RestartRequest) String() string {
func (*RestartRequest) ProtoMessage() {}
func (x *RestartRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[21]
mi := &file_uart_messages_proto_msgTypes[25]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1888,7 +2152,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{21}
return file_uart_messages_proto_rawDescGZIP(), []int{25}
}
func (x *RestartRequest) GetClientId() uint32 {
@@ -1908,7 +2172,7 @@ type RestartResponse struct {
func (x *RestartResponse) Reset() {
*x = RestartResponse{}
mi := &file_uart_messages_proto_msgTypes[22]
mi := &file_uart_messages_proto_msgTypes[26]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1920,7 +2184,7 @@ func (x *RestartResponse) String() string {
func (*RestartResponse) ProtoMessage() {}
func (x *RestartResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[22]
mi := &file_uart_messages_proto_msgTypes[26]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1933,7 +2197,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{22}
return file_uart_messages_proto_rawDescGZIP(), []int{26}
}
func (x *RestartResponse) GetSuccess() bool {
@@ -1960,7 +2224,7 @@ type OtaStartPayload struct {
func (x *OtaStartPayload) Reset() {
*x = OtaStartPayload{}
mi := &file_uart_messages_proto_msgTypes[23]
mi := &file_uart_messages_proto_msgTypes[27]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1972,7 +2236,7 @@ func (x *OtaStartPayload) String() string {
func (*OtaStartPayload) ProtoMessage() {}
func (x *OtaStartPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[23]
mi := &file_uart_messages_proto_msgTypes[27]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1985,7 +2249,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{23}
return file_uart_messages_proto_rawDescGZIP(), []int{27}
}
func (x *OtaStartPayload) GetTotalSize() uint32 {
@@ -2006,7 +2270,7 @@ type OtaPayload struct {
func (x *OtaPayload) Reset() {
*x = OtaPayload{}
mi := &file_uart_messages_proto_msgTypes[24]
mi := &file_uart_messages_proto_msgTypes[28]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2018,7 +2282,7 @@ func (x *OtaPayload) String() string {
func (*OtaPayload) ProtoMessage() {}
func (x *OtaPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[24]
mi := &file_uart_messages_proto_msgTypes[28]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2031,7 +2295,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{24}
return file_uart_messages_proto_rawDescGZIP(), []int{28}
}
func (x *OtaPayload) GetSeq() uint32 {
@@ -2057,7 +2321,7 @@ type OtaEndPayload struct {
func (x *OtaEndPayload) Reset() {
*x = OtaEndPayload{}
mi := &file_uart_messages_proto_msgTypes[25]
mi := &file_uart_messages_proto_msgTypes[29]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2069,7 +2333,7 @@ func (x *OtaEndPayload) String() string {
func (*OtaEndPayload) ProtoMessage() {}
func (x *OtaEndPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[25]
mi := &file_uart_messages_proto_msgTypes[29]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2082,7 +2346,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{25}
return file_uart_messages_proto_rawDescGZIP(), []int{29}
}
// Device → host status (also used as ACK after each 4 KiB written).
@@ -2099,7 +2363,7 @@ type OtaStatusPayload struct {
func (x *OtaStatusPayload) Reset() {
*x = OtaStatusPayload{}
mi := &file_uart_messages_proto_msgTypes[26]
mi := &file_uart_messages_proto_msgTypes[30]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2111,7 +2375,7 @@ func (x *OtaStatusPayload) String() string {
func (*OtaStatusPayload) ProtoMessage() {}
func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[26]
mi := &file_uart_messages_proto_msgTypes[30]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2124,7 +2388,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{26}
return file_uart_messages_proto_rawDescGZIP(), []int{30}
}
func (x *OtaStatusPayload) GetStatus() uint32 {
@@ -2165,7 +2429,7 @@ type OtaSlaveProgressRequest struct {
func (x *OtaSlaveProgressRequest) Reset() {
*x = OtaSlaveProgressRequest{}
mi := &file_uart_messages_proto_msgTypes[27]
mi := &file_uart_messages_proto_msgTypes[31]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2177,7 +2441,7 @@ func (x *OtaSlaveProgressRequest) String() string {
func (*OtaSlaveProgressRequest) ProtoMessage() {}
func (x *OtaSlaveProgressRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[27]
mi := &file_uart_messages_proto_msgTypes[31]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2190,7 +2454,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{27}
return file_uart_messages_proto_rawDescGZIP(), []int{31}
}
func (x *OtaSlaveProgressRequest) GetClientId() uint32 {
@@ -2214,7 +2478,7 @@ type OtaSlaveProgressEntry struct {
func (x *OtaSlaveProgressEntry) Reset() {
*x = OtaSlaveProgressEntry{}
mi := &file_uart_messages_proto_msgTypes[28]
mi := &file_uart_messages_proto_msgTypes[32]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2226,7 +2490,7 @@ func (x *OtaSlaveProgressEntry) String() string {
func (*OtaSlaveProgressEntry) ProtoMessage() {}
func (x *OtaSlaveProgressEntry) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[28]
mi := &file_uart_messages_proto_msgTypes[32]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2239,7 +2503,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{28}
return file_uart_messages_proto_rawDescGZIP(), []int{32}
}
func (x *OtaSlaveProgressEntry) GetClientId() uint32 {
@@ -2290,7 +2554,7 @@ type OtaSlaveProgressResponse struct {
func (x *OtaSlaveProgressResponse) Reset() {
*x = OtaSlaveProgressResponse{}
mi := &file_uart_messages_proto_msgTypes[29]
mi := &file_uart_messages_proto_msgTypes[33]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -2302,7 +2566,7 @@ func (x *OtaSlaveProgressResponse) String() string {
func (*OtaSlaveProgressResponse) ProtoMessage() {}
func (x *OtaSlaveProgressResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[29]
mi := &file_uart_messages_proto_msgTypes[33]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -2315,7 +2579,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{29}
return file_uart_messages_proto_rawDescGZIP(), []int{33}
}
func (x *OtaSlaveProgressResponse) GetActive() bool {
@@ -2357,7 +2621,7 @@ var File_uart_messages_proto protoreflect.FileDescriptor
const file_uart_messages_proto_rawDesc = "" +
"\n" +
"\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\xba\x0f\n" +
"\x13uart_messages.proto\x12\x04alox\x1a\fnanopb.proto\"\xe5\x10\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" +
@@ -2388,7 +2652,9 @@ const file_uart_messages_proto_rawDesc = "" +
"\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" +
"\x15accel_stream_response\x18\x1a \x01(\v2\x19.alox.AccelStreamResponseH\x00R\x13accelStreamResponse\x12R\n" +
"\x16battery_status_request\x18\x1b \x01(\v2\x1a.alox.BatteryStatusRequestH\x00R\x14batteryStatusRequest\x12U\n" +
"\x17battery_status_response\x18\x1c \x01(\v2\x1b.alox.BatteryStatusResponseH\x00R\x15batteryStatusResponseB\t\n" +
"\apayload\"\x05\n" +
"\x03Ack\"!\n" +
"\vEchoPayload\x12\x12\n" +
@@ -2437,7 +2703,23 @@ const file_uart_messages_proto_rawDesc = "" +
"\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" +
"\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"T\n" +
"\x14BatteryStatusRequest\x12\x1b\n" +
"\tclient_id\x18\x01 \x01(\rR\bclientId\x12\x1f\n" +
"\vall_clients\x18\x02 \x01(\bR\n" +
"allClients\"B\n" +
"\vLipoReading\x12\x14\n" +
"\x05valid\x18\x01 \x01(\bR\x05valid\x12\x1d\n" +
"\n" +
"voltage_mv\x18\x02 \x01(\rR\tvoltageMv\"\x95\x01\n" +
"\rBatterySample\x12\x1b\n" +
"\tclient_id\x18\x01 \x01(\rR\bclientId\x12'\n" +
"\x05lipo1\x18\x02 \x01(\v2\x11.alox.LipoReadingR\x05lipo1\x12'\n" +
"\x05lipo2\x18\x03 \x01(\v2\x11.alox.LipoReadingR\x05lipo2\x12\x15\n" +
"\x06age_ms\x18\x04 \x01(\rR\x05ageMs\"g\n" +
"\x15BatteryStatusResponse\x12\x18\n" +
"\asuccess\x18\x01 \x01(\bR\asuccess\x124\n" +
"\asamples\x18\x02 \x03(\v2\x13.alox.BatterySampleB\x05\x92?\x02\x10\x11R\asamples\"3\n" +
"\x14AccelSnapshotRequest\x12\x1b\n" +
"\tclient_id\x18\x01 \x01(\rR\bclientId\"\x81\x01\n" +
"\vAccelSample\x12\x1b\n" +
@@ -2519,7 +2801,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*\xc3\x02\n" +
"\x06slaves\x18\x05 \x03(\v2\x1b.alox.OtaSlaveProgressEntryB\x05\x92?\x02\x10\x10R\x06slaves*\xd7\x02\n" +
"\vMessageType\x12\v\n" +
"\aUNKNOWN\x10\x00\x12\a\n" +
"\x03ACK\x10\x01\x12\b\n" +
@@ -2540,7 +2822,8 @@ const file_uart_messages_proto_rawDesc = "" +
"\aFIND_ME\x10\x16\x12\v\n" +
"\aRESTART\x10\x17\x12\x12\n" +
"\x0eACCEL_SNAPSHOT\x10\x18\x12\x10\n" +
"\fACCEL_STREAM\x10\x19b\x06proto3"
"\fACCEL_STREAM\x10\x19\x12\x12\n" +
"\x0eBATTERY_STATUS\x10\x1ab\x06proto3"
var (
file_uart_messages_proto_rawDescOnce sync.Once
@@ -2555,7 +2838,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, 30)
var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 34)
var file_uart_messages_proto_goTypes = []any{
(MessageType)(0), // 0: alox.MessageType
(*UartMessage)(nil), // 1: alox.UartMessage
@@ -2570,24 +2853,28 @@ var file_uart_messages_proto_goTypes = []any{
(*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse
(*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
(*BatteryStatusRequest)(nil), // 13: alox.BatteryStatusRequest
(*LipoReading)(nil), // 14: alox.LipoReading
(*BatterySample)(nil), // 15: alox.BatterySample
(*BatteryStatusResponse)(nil), // 16: alox.BatteryStatusResponse
(*AccelSnapshotRequest)(nil), // 17: alox.AccelSnapshotRequest
(*AccelSample)(nil), // 18: alox.AccelSample
(*AccelSnapshotResponse)(nil), // 19: alox.AccelSnapshotResponse
(*EspNowUnicastTestRequest)(nil), // 20: alox.EspNowUnicastTestRequest
(*EspNowUnicastTestResponse)(nil), // 21: alox.EspNowUnicastTestResponse
(*LedRingProgressRequest)(nil), // 22: alox.LedRingProgressRequest
(*LedRingProgressResponse)(nil), // 23: alox.LedRingProgressResponse
(*EspNowFindMeRequest)(nil), // 24: alox.EspNowFindMeRequest
(*EspNowFindMeResponse)(nil), // 25: alox.EspNowFindMeResponse
(*RestartRequest)(nil), // 26: alox.RestartRequest
(*RestartResponse)(nil), // 27: alox.RestartResponse
(*OtaStartPayload)(nil), // 28: alox.OtaStartPayload
(*OtaPayload)(nil), // 29: alox.OtaPayload
(*OtaEndPayload)(nil), // 30: alox.OtaEndPayload
(*OtaStatusPayload)(nil), // 31: alox.OtaStatusPayload
(*OtaSlaveProgressRequest)(nil), // 32: alox.OtaSlaveProgressRequest
(*OtaSlaveProgressEntry)(nil), // 33: alox.OtaSlaveProgressEntry
(*OtaSlaveProgressResponse)(nil), // 34: alox.OtaSlaveProgressResponse
}
var file_uart_messages_proto_depIdxs = []int32{
0, // 0: alox.UartMessage.type:type_name -> alox.MessageType
@@ -2596,35 +2883,40 @@ 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
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
28, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload
29, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload
30, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload
31, // 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
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
20, // 12: alox.UartMessage.espnow_unicast_test_request:type_name -> alox.EspNowUnicastTestRequest
21, // 13: alox.UartMessage.espnow_unicast_test_response:type_name -> alox.EspNowUnicastTestResponse
32, // 14: alox.UartMessage.ota_slave_progress_request:type_name -> alox.OtaSlaveProgressRequest
34, // 15: alox.UartMessage.ota_slave_progress_response:type_name -> alox.OtaSlaveProgressResponse
22, // 16: alox.UartMessage.led_ring_progress_request:type_name -> alox.LedRingProgressRequest
23, // 17: alox.UartMessage.led_ring_progress_response:type_name -> alox.LedRingProgressResponse
24, // 18: alox.UartMessage.espnow_find_me_request:type_name -> alox.EspNowFindMeRequest
25, // 19: alox.UartMessage.espnow_find_me_response:type_name -> alox.EspNowFindMeResponse
26, // 20: alox.UartMessage.restart_request:type_name -> alox.RestartRequest
27, // 21: alox.UartMessage.restart_response:type_name -> alox.RestartResponse
17, // 22: alox.UartMessage.accel_snapshot_request:type_name -> alox.AccelSnapshotRequest
19, // 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
13, // 26: alox.UartMessage.battery_status_request:type_name -> alox.BatteryStatusRequest
16, // 27: alox.UartMessage.battery_status_response:type_name -> alox.BatteryStatusResponse
5, // 28: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo
7, // 29: alox.ClientInputResponse.clients:type_name -> alox.ClientInput
14, // 30: alox.BatterySample.lipo1:type_name -> alox.LipoReading
14, // 31: alox.BatterySample.lipo2:type_name -> alox.LipoReading
15, // 32: alox.BatteryStatusResponse.samples:type_name -> alox.BatterySample
18, // 33: alox.AccelSnapshotResponse.samples:type_name -> alox.AccelSample
33, // 34: alox.OtaSlaveProgressResponse.slaves:type_name -> alox.OtaSlaveProgressEntry
35, // [35:35] is the sub-list for method output_type
35, // [35:35] is the sub-list for method input_type
35, // [35:35] is the sub-list for extension type_name
35, // [35:35] is the sub-list for extension extendee
0, // [0:35] is the sub-list for field type_name
}
func init() { file_uart_messages_proto_init() }
@@ -2658,6 +2950,8 @@ func file_uart_messages_proto_init() {
(*UartMessage_AccelSnapshotResponse)(nil),
(*UartMessage_AccelStreamRequest)(nil),
(*UartMessage_AccelStreamResponse)(nil),
(*UartMessage_BatteryStatusRequest)(nil),
(*UartMessage_BatteryStatusResponse)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -2665,7 +2959,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: 30,
NumMessages: 34,
NumExtensions: 0,
NumServices: 0,
},
+1 -1
View File
@@ -119,7 +119,7 @@ func (m *managedSerial) exchangePayloadVia(
var resp []byte
err := portFn(func(sp *serialPort) error {
var e error
resp, e = sp.exchangePayloadLocked(payload, cmdName)
resp, e = sp.exchangePayloadLocked(payload, cmdName, readTimeout)
return e
})
return resp, err
+19 -2
View File
@@ -12,6 +12,9 @@ import (
const readTimeout = 3 * time.Second
// batteryReadTimeout: master may query each slave over ESP-NOW (~400 ms each).
const batteryReadTimeout = 12 * time.Second
type serialPort struct {
port serial.Port
mu sync.Mutex
@@ -44,10 +47,16 @@ func (s *serialPort) Close() error {
func (s *serialPort) exchangePayload(payload []byte, cmdName string) ([]byte, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.exchangePayloadLocked(payload, cmdName)
return s.exchangePayloadLocked(payload, cmdName, readTimeout)
}
func (s *serialPort) exchangePayloadLocked(payload []byte, cmdName string) ([]byte, error) {
func (s *serialPort) exchangePayloadForBattery(payload []byte, cmdName string) ([]byte, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.exchangePayloadLocked(payload, cmdName, batteryReadTimeout)
}
func (s *serialPort) exchangePayloadLocked(payload []byte, cmdName string, timeout time.Duration) ([]byte, error) {
if len(payload) == 0 {
return nil, fmt.Errorf("empty payload")
}
@@ -63,6 +72,14 @@ func (s *serialPort) exchangePayloadLocked(payload []byte, cmdName string) ([]by
return nil, fmt.Errorf("write: %w", err)
}
if timeout <= 0 {
timeout = readTimeout
}
if err := s.port.SetReadTimeout(timeout); err != nil {
return nil, fmt.Errorf("set read timeout: %w", err)
}
defer func() { _ = s.port.SetReadTimeout(readTimeout) }()
respPayload, err := uartframe.ReadFrame(s.port, nil)
if err != nil {
return nil, fmt.Errorf("read response: %w", err)
+96 -2
View File
@@ -200,6 +200,10 @@
<dd class="col-7" x-text="state.master.running_partition || '—'"></dd>
<dt class="col-5 text-muted">Deadzone</dt>
<dd class="col-7" x-text="state.master.deadzone != null ? state.master.deadzone + ' LSB' : '—'"></dd>
<dt class="col-5 text-muted">LiPo 1</dt>
<dd class="col-7" x-text="formatLipo(state.master?.lipo1)"></dd>
<dt class="col-5 text-muted">LiPo 2</dt>
<dd class="col-7" x-text="formatLipo(state.master?.lipo2)"></dd>
</dl>
</template>
<template x-if="state.master && !state.master.ok">
@@ -280,13 +284,14 @@
<th>Status</th>
<th>Deadzone</th>
<th>Accel (LSB)</th>
<th>Akku</th>
<th>Stream</th>
<th>Aktion</th>
</tr>
</thead>
<tbody>
<template x-if="!(state.clients || []).length">
<tr><td colspan="8" class="text-muted text-center py-4">No clients</td></tr>
<tr><td colspan="9" class="text-muted text-center py-4">No clients</td></tr>
</template>
<template x-for="c in (state.clients || [])" :key="c.id + c.mac">
<tr>
@@ -305,6 +310,7 @@
x-text="formatAccel(c)"
:title="accelTitle(c)"></span>
</td>
<td class="small" x-text="formatLipoPair(c)" :title="lipoTitle(c)"></td>
<td>
<button type="button"
class="btn btn-sm"
@@ -576,9 +582,14 @@
connect() {
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
const url = proto + '//' + location.host + '/ws';
if (this._batteryTimer) clearInterval(this._batteryTimer);
this._batteryTimer = setInterval(() => this.refreshBattery(), 5000);
const connect = () => {
this.ws = new WebSocket(url);
this.ws.onopen = () => { this.wsConnected = true; };
this.ws.onopen = () => {
this.wsConnected = true;
this.refreshBattery();
};
this.ws.onclose = () => {
this.wsConnected = false;
setTimeout(connect, 2000);
@@ -590,7 +601,13 @@
this.applyOTAProgress(msg);
return;
}
if (msg.type === 'battery_status') {
if (msg.samples?.length) this.applyBatterySamples(msg.samples);
return;
}
const prev = this.state;
this.state = msg;
this.preserveBatteryInState(prev, this.state);
if (msg.master?.deadzone != null) {
this.masterDz = msg.master.deadzone;
}
@@ -604,10 +621,87 @@
};
connect();
},
preserveBatteryInState(prev, next) {
if (!prev || !next) return;
const keepLipo = (oldL, newL) => {
if (newL?.valid) return newL;
if (oldL?.valid) return oldL;
return newL ?? oldL;
};
const keepAge = (oldAge, newAge, hasValid) => {
if (hasValid && newAge != null) return newAge;
if (oldAge != null && !hasValid) return oldAge;
return newAge ?? oldAge;
};
if (next.master) {
const pm = prev.master || {};
const l1 = keepLipo(pm.lipo1, next.master.lipo1);
const l2 = keepLipo(pm.lipo2, next.master.lipo2);
next.master.lipo1 = l1;
next.master.lipo2 = l2;
next.master.battery_age_ms = keepAge(
pm.battery_age_ms, next.master.battery_age_ms, !!(l1?.valid || l2?.valid));
}
if (!Array.isArray(next.clients)) return;
const prevById = Object.fromEntries((prev.clients || []).map((c) => [c.id, c]));
next.clients = next.clients.map((c) => {
const p = prevById[c.id];
if (!p) return c;
const l1 = keepLipo(p.lipo1, c.lipo1);
const l2 = keepLipo(p.lipo2, c.lipo2);
return {
...c,
lipo1: l1,
lipo2: l2,
battery_age_ms: keepAge(p.battery_age_ms, c.battery_age_ms, !!(l1?.valid || l2?.valid))
};
});
},
applyBatterySamples(samples) {
if (!samples?.length) return;
for (const s of samples) {
if (s.client_id === 0) {
if (!this.state.master) this.state.master = {};
this.state.master.lipo1 = s.lipo1;
this.state.master.lipo2 = s.lipo2;
this.state.master.battery_age_ms = s.age_ms;
continue;
}
const c = (this.state.clients || []).find((x) => x.id === s.client_id);
if (c) {
c.lipo1 = s.lipo1;
c.lipo2 = s.lipo2;
c.battery_age_ms = s.age_ms;
}
}
},
async refreshBattery() {
if (!this.state?.uart_connected) return;
try {
const r = await fetch('/api/battery?all_clients=1');
if (!r.ok) return;
const data = await r.json();
if (data.samples?.length) this.applyBatterySamples(data.samples);
} catch (_) {}
},
formatMac(hex) {
if (!hex || hex.length !== 12) return hex || '';
return hex.match(/.{2}/g).join(':');
},
formatLipo(l) {
if (!l?.valid) return '—';
const v = (l.voltage_mv / 1000).toFixed(2);
return l.percent != null ? `${v} V (${l.percent}%)` : `${v} V`;
},
formatLipoPair(c) {
return `1: ${this.formatLipo(c?.lipo1)} · 2: ${this.formatLipo(c?.lipo2)}`;
},
lipoTitle(c) {
if (!c?.lipo1?.valid && !c?.lipo2?.valid) return 'Keine ADC-Daten (Cache ~30 s)';
let t = `LiPo1 ${c.lipo1?.voltage_mv ?? '—'} mV, LiPo2 ${c.lipo2?.voltage_mv ?? '—'} mV`;
if (c.battery_age_ms != null) t += `, Alter ${c.battery_age_ms} ms`;
return t;
},
formatAccel(c) {
if (!c?.accel_stream) return '—';
if (!c?.accel_valid) return '…';