First api draft for ui communication
This commit is contained in:
parent
f4f3c695af
commit
7534459e73
@ -4,8 +4,44 @@ const (
|
||||
TopicFrontendCmd = "front:cmd"
|
||||
)
|
||||
|
||||
type FrontendCmd struct {
|
||||
Action string `json:"action"`
|
||||
ID byte `json:"id"`
|
||||
const (
|
||||
CmdUpdateValue = "update_value"
|
||||
CmdInitState = "init_state"
|
||||
CmdConnect = "connect"
|
||||
CmdDisconnect = "disconnect"
|
||||
CmdRX = "uart_rx"
|
||||
CmdTX = "uart_tx"
|
||||
)
|
||||
|
||||
type WsMessage struct {
|
||||
Cmd string `json:"cmd"`
|
||||
Payload any `json:"payload"`
|
||||
}
|
||||
|
||||
type SystemState struct {
|
||||
Adapters []string `json:"adapters"`
|
||||
SelectedAdapter string `json:"selected_adapter"`
|
||||
Baudrates string `json:"baudrates"`
|
||||
SelectedBaudrate string `json:"selected_baudrate"`
|
||||
UartConnected bool `json:"uart_connected"`
|
||||
}
|
||||
|
||||
type WsUartConnect struct {
|
||||
SelectedAdapter string `json:"selected_adapter"`
|
||||
Baudrates string `json:"baudrates"`
|
||||
}
|
||||
|
||||
type WsUartDisconnect struct {
|
||||
}
|
||||
|
||||
type WsUartSendMessage struct {
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
type WsUartRX struct {
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
type WsUartTX struct {
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ const (
|
||||
TopicUARTRx = "uart:rx"
|
||||
TopicUARTTx = "uart:tx"
|
||||
TopicUARTError = "uart:error"
|
||||
TopicUartAction = "uart:action"
|
||||
|
||||
TopicOTA = "ota"
|
||||
)
|
||||
|
||||
@ -78,14 +78,14 @@ func (fsrv *FServer) handleWS(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// READER: Commands from Browser
|
||||
for {
|
||||
var cmd api.FrontendCmd
|
||||
var cmd api.WsMessage
|
||||
if err := conn.ReadJSON(&cmd); err != nil {
|
||||
log.Printf("WS Read Error: %v", err)
|
||||
break
|
||||
}
|
||||
|
||||
fsrv.bus.Publish(api.TopicFrontendCmd, cmd)
|
||||
log.Printf("Browser Action: %s auf ID 0x%02X", cmd.Action, cmd.ID)
|
||||
log.Printf("Browser Action: %s auf with %v", cmd.Cmd, cmd.Payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user