Add message IDs, transport interface, client package, extract protocol headers
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user