powerpods/goTool/cmd_clients.go
simon 16bfbd1091 Add goTool clients subcommand for CLIENT_INFO query.
Refactor into version/clients subcommands with shared serial framing
to list registered slaves from the master over UART.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-18 22:26:42 +02:00

47 lines
1.1 KiB
Go

package main
import (
"encoding/hex"
"fmt"
"google.golang.org/protobuf/proto"
"powerpod/gotool/pb"
)
func runClients(sp *serialPort) error {
payload, err := sp.exchange(byte(pb.MessageType_CLIENT_INFO), "CLIENT_INFO")
if err != nil {
return err
}
var msg pb.UartMessage
if err := proto.Unmarshal(payload[1:], &msg); err != nil {
return fmt.Errorf("decode protobuf: %w", err)
}
if msg.GetType() != pb.MessageType_CLIENT_INFO {
return fmt.Errorf("unexpected message type %v", msg.GetType())
}
info := msg.GetClientInfoResponse()
if info == nil {
return fmt.Errorf("response missing client_info_response")
}
clients := info.GetClients()
if len(clients) == 0 {
fmt.Println("no clients registered")
return nil
}
fmt.Printf("clients (%d):\n", len(clients))
for i, c := range clients {
mac := hex.EncodeToString(c.GetMac())
fmt.Printf(" [%d] id=%d mac=%s ver=%d available=%v used=%v last_ping=%d last_success_ping=%d\n",
i, c.GetId(), mac, c.GetVersion(), c.GetAvailable(), c.GetUsed(),
c.GetLastPing(), c.GetLastSuccessPing())
}
return nil
}