powerpods/goTool/cmd_ota.go
simon 4bf43d8a5e Add web dashboard OTA upload with live progress.
Share UART OTA logic between CLI and serve via POST /api/ota, WebSocket progress events, and a dashboard upload UI showing the running partition.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 00:45:54 +02:00

33 lines
609 B
Go

package main
import (
"fmt"
"os"
)
func runOTA(sp *serialPort, args []string) error {
if len(args) < 1 {
return fmt.Errorf("usage: ota <firmware.bin>")
}
data, err := os.ReadFile(args[0])
if err != nil {
return err
}
sp.mu.Lock()
defer sp.mu.Unlock()
m := &managedSerial{quiet: false, sp: sp}
return runOTAOnPortUnlocked(m, data, func(p OTAProgress) {
switch p.Phase {
case "preparing", "ready":
fmt.Println(p.Message)
case "uploading":
if p.Percent%10 == 0 {
fmt.Printf(" %s (%d%%)\n", p.Message, p.Percent)
}
case "done", "error":
fmt.Println(p.Message)
}
})
}