powerpods/goTool/cache_status.go
simon 31e539052a Unify cache polling on CACHE_STATUS and split API docs.
Replace separate accel/tap snapshot UART commands with one clients[] response
that omits unsubscribed fields; remove snapshot handlers and CLI commands.
Add goTool/docs for WebSocket streams and REST; tap-snapshot REST uses CACHE_STATUS.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 21:23:09 +02:00

50 lines
1.2 KiB
Go

package main
import "powerpod/gotool/pb"
// accelSamplesFromCacheStatus maps combined CACHE_STATUS entries to AccelSample
// (for dashboard / WebSocket accel push).
func accelSamplesFromCacheStatus(r *pb.CacheStatusResponse) []*pb.AccelSample {
if r == nil {
return nil
}
out := make([]*pb.AccelSample, 0, len(r.GetClients()))
for _, c := range r.GetClients() {
if c.GetAccel() == nil {
continue
}
a := c.GetAccel()
out = append(out, &pb.AccelSample{
ClientId: c.GetClientId(),
Valid: a.GetValid(),
X: a.GetX(),
Y: a.GetY(),
Z: a.GetZ(),
AgeMs: a.GetAgeMs(),
})
}
return out
}
// tapEventsFromCacheStatus maps combined CACHE_STATUS entries to TapEvent
// (only clients with a consumed pending tap).
func tapEventsFromCacheStatus(r *pb.CacheStatusResponse) []*pb.TapEvent {
if r == nil {
return nil
}
out := make([]*pb.TapEvent, 0, len(r.GetClients()))
for _, c := range r.GetClients() {
if c.GetTap() == nil {
continue
}
t := c.GetTap()
out = append(out, &pb.TapEvent{
ClientId: c.GetClientId(),
Valid: true,
Kind: t.GetKind(),
AgeMs: t.GetAgeMs(),
})
}
return out
}