Add web dashboard configuration for master and slaves.
Expose deadzone and unicast-test via HTTP API and UI, reusing the same UART commands as the CLI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+32
-6
@@ -3,24 +3,29 @@ package main
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"powerpod/gotool/pb"
|
||||
)
|
||||
|
||||
type MasterView struct {
|
||||
Version uint32 `json:"version"`
|
||||
GitHash string `json:"git_hash"`
|
||||
OK bool `json:"ok"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Version uint32 `json:"version"`
|
||||
GitHash string `json:"git_hash"`
|
||||
Deadzone uint32 `json:"deadzone,omitempty"`
|
||||
OK bool `json:"ok"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type ClientView struct {
|
||||
ID uint32 `json:"id"`
|
||||
MAC string `json:"mac"`
|
||||
Version uint32 `json:"version"`
|
||||
Deadzone uint32 `json:"deadzone,omitempty"`
|
||||
Available bool `json:"available"`
|
||||
Used bool `json:"used"`
|
||||
LastPing uint32 `json:"last_ping"`
|
||||
@@ -100,6 +105,9 @@ func pollDashboard(link *managedSerial, portName string) DashboardState {
|
||||
GitHash: ver.GetGitHash(),
|
||||
OK: true,
|
||||
}
|
||||
if dz, err := readDeadzone(link, 0); err == nil {
|
||||
st.Master.Deadzone = dz
|
||||
}
|
||||
|
||||
clients, err := link.listClients()
|
||||
if err != nil {
|
||||
@@ -110,7 +118,7 @@ func pollDashboard(link *managedSerial, portName string) DashboardState {
|
||||
}
|
||||
|
||||
for _, c := range clients {
|
||||
st.Clients = append(st.Clients, ClientView{
|
||||
cv := ClientView{
|
||||
ID: c.GetId(),
|
||||
MAC: formatMAC(c.GetMac()),
|
||||
Version: c.GetVersion(),
|
||||
@@ -118,11 +126,29 @@ func pollDashboard(link *managedSerial, portName string) DashboardState {
|
||||
Used: c.GetUsed(),
|
||||
LastPing: c.GetLastPing(),
|
||||
LastSuccessPing: c.GetLastSuccessPing(),
|
||||
})
|
||||
}
|
||||
if dz, err := readDeadzone(link, c.GetId()); err == nil {
|
||||
cv.Deadzone = dz
|
||||
}
|
||||
st.Clients = append(st.Clients, cv)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
func readDeadzone(link *managedSerial, clientID uint32) (uint32, error) {
|
||||
r, err := link.AccelDeadzone(&pb.AccelDeadzoneRequest{
|
||||
Write: false,
|
||||
ClientId: clientID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if !r.GetSuccess() {
|
||||
return 0, fmt.Errorf("deadzone read failed for client %d", clientID)
|
||||
}
|
||||
return r.GetDeadzone(), nil
|
||||
}
|
||||
|
||||
func formatMAC(mac []byte) string {
|
||||
if len(mac) == 0 {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user