First api draft for ui communication
This commit is contained in:
parent
f4f3c695af
commit
7534459e73
@ -4,8 +4,44 @@ const (
|
|||||||
TopicFrontendCmd = "front:cmd"
|
TopicFrontendCmd = "front:cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FrontendCmd struct {
|
const (
|
||||||
Action string `json:"action"`
|
CmdUpdateValue = "update_value"
|
||||||
ID byte `json:"id"`
|
CmdInitState = "init_state"
|
||||||
Data []byte `json:"data"`
|
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"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,10 @@ package api
|
|||||||
|
|
||||||
// Topics
|
// Topics
|
||||||
const (
|
const (
|
||||||
TopicUARTRx = "uart:rx"
|
TopicUARTRx = "uart:rx"
|
||||||
TopicUARTTx = "uart:tx"
|
TopicUARTTx = "uart:tx"
|
||||||
TopicUARTError = "uart:error"
|
TopicUARTError = "uart:error"
|
||||||
|
TopicUartAction = "uart:action"
|
||||||
|
|
||||||
TopicOTA = "ota"
|
TopicOTA = "ota"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -78,14 +78,14 @@ func (fsrv *FServer) handleWS(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// READER: Commands from Browser
|
// READER: Commands from Browser
|
||||||
for {
|
for {
|
||||||
var cmd api.FrontendCmd
|
var cmd api.WsMessage
|
||||||
if err := conn.ReadJSON(&cmd); err != nil {
|
if err := conn.ReadJSON(&cmd); err != nil {
|
||||||
log.Printf("WS Read Error: %v", err)
|
log.Printf("WS Read Error: %v", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
fsrv.bus.Publish(api.TopicFrontendCmd, cmd)
|
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