Add message IDs, transport interface, client package, extract protocol headers

This commit is contained in:
Ian Gulliver
2026-04-03 17:41:44 +09:00
parent 302f7fdb6a
commit 64953ef985
10 changed files with 251 additions and 152 deletions

View File

@@ -7,9 +7,9 @@ import (
"path/filepath"
"time"
"github.com/theater/picomap/lib/client"
"github.com/theater/picomap/lib/picoserial"
"github.com/theater/picomap/lib/picotool"
"github.com/theater/picomap/lib/wire"
)
func main() {
@@ -40,27 +40,18 @@ func run(buildDir string) error {
return err
}
if dev != "" {
fmt.Printf("Sending bootsel request to %s...\n", dev)
req, err := wire.EncodeMessage(&wire.RequestBOOTSEL{})
if err != nil {
return fmt.Errorf("encoding request: %w", err)
}
resp, err := picoserial.SendAndReceive(dev, req, 2*time.Second)
fmt.Printf("Sending BOOTSEL request to %s...\n", dev)
t, err := picoserial.Open(dev)
if err != nil {
return err
}
if len(resp) > 0 {
msg, err := wire.DecodeMessage(resp)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: failed to decode response: %v\n", err)
} else {
switch msg.(type) {
case *wire.ResponseBOOTSEL:
fmt.Println("Device confirmed reboot into BOOTSEL mode.")
default:
fmt.Printf("Unexpected response type: %T\n", msg)
}
}
c := client.New(t, 2*time.Second)
err = c.BOOTSEL()
c.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "warning: BOOTSEL request failed: %v\n", err)
} else {
fmt.Println("Device confirmed reboot into BOOTSEL mode.")
}
time.Sleep(2 * time.Second)
}