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>
This commit is contained in:
@@ -40,25 +40,6 @@ 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 decodeBatteryStatusPayload(payload []byte) (*pb.BatteryStatusResponse, error) {
|
||||
if len(payload) < 2 {
|
||||
return nil, fmt.Errorf("short battery response")
|
||||
@@ -222,43 +203,6 @@ func decodeCacheStatusPayload(payload []byte) (*pb.CacheStatusResponse, error) {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (m *managedSerial) readTapSnapshotPoll(clientID uint32) (*pb.TapSnapshotResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_TAP_SNAPSHOT,
|
||||
Payload: &pb.UartMessage_TapSnapshotRequest{
|
||||
TapSnapshotRequest: &pb.TapSnapshotRequest{ClientId: clientID},
|
||||
},
|
||||
}
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode: %w", err)
|
||||
}
|
||||
payload := append([]byte{byte(pb.MessageType_TAP_SNAPSHOT)}, body...)
|
||||
respPayload, err := m.exchangePayloadPoll(payload, "TAP_SNAPSHOT")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeTapSnapshotPayload(respPayload)
|
||||
}
|
||||
|
||||
func decodeTapSnapshotPayload(payload []byte) (*pb.TapSnapshotResponse, 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_TAP_SNAPSHOT {
|
||||
return nil, fmt.Errorf("unexpected type %v", msg.GetType())
|
||||
}
|
||||
r := msg.GetTapSnapshotResponse()
|
||||
if r == nil {
|
||||
return nil, fmt.Errorf("missing tap_snapshot_response")
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (m *managedSerial) accelStreamVia(
|
||||
portFn func(func(*serialPort) error) error,
|
||||
req *pb.AccelStreamRequest,
|
||||
@@ -333,43 +277,6 @@ func decodeClientsPayload(payload []byte) ([]*pb.ClientInfo, error) {
|
||||
return info.GetClients(), nil
|
||||
}
|
||||
|
||||
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_SNAPSHOT {
|
||||
return nil, fmt.Errorf("unexpected type %v", msg.GetType())
|
||||
}
|
||||
r := msg.GetAccelSnapshotResponse()
|
||||
if r == nil {
|
||||
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 {
|
||||
@@ -448,25 +355,6 @@ func (s *serialPort) readCacheStatus() (*pb.CacheStatusResponse, error) {
|
||||
return decodeCacheStatusPayload(payload)
|
||||
}
|
||||
|
||||
func (s *serialPort) readTapSnapshot(clientID uint32) (*pb.TapSnapshotResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_TAP_SNAPSHOT,
|
||||
Payload: &pb.UartMessage_TapSnapshotRequest{
|
||||
TapSnapshotRequest: &pb.TapSnapshotRequest{ClientId: clientID},
|
||||
},
|
||||
}
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode: %w", err)
|
||||
}
|
||||
payload := append([]byte{byte(pb.MessageType_TAP_SNAPSHOT)}, body...)
|
||||
respPayload, err := s.exchangePayload(payload, "TAP_SNAPSHOT")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeTapSnapshotPayload(respPayload)
|
||||
}
|
||||
|
||||
func (s *serialPort) accelDeadzone(req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_ACCEL_DEADZONE,
|
||||
|
||||
Reference in New Issue
Block a user