Remove USB/serial support: network-only protocol, drop tinyusb and PICOBOOT
This commit is contained in:
@@ -100,11 +100,6 @@ func first[T any](results []Response[T], err error) (*T, error) {
|
||||
return results[0].Value, nil
|
||||
}
|
||||
|
||||
func (c *Client) PICOBOOT() error {
|
||||
_, err := first(roundTrip[ResponsePICOBOOT](c, &RequestPICOBOOT{}))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Info() (*ResponseInfo, error) {
|
||||
return first(roundTrip[ResponseInfo](c, &RequestInfo{}))
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/theater/picomap/lib/msgpack"
|
||||
"go.bug.st/serial"
|
||||
"go.bug.st/serial/enumerator"
|
||||
)
|
||||
|
||||
func ListSerial() ([]string, error) {
|
||||
ports, err := enumerator.GetDetailedPortsList()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("enumerating ports: %w", err)
|
||||
}
|
||||
type entry struct {
|
||||
name string
|
||||
serial string
|
||||
}
|
||||
var entries []entry
|
||||
for _, p := range ports {
|
||||
if p.IsUSB && p.VID == "2E8A" && strings.HasPrefix(p.Name, "/dev/cu.") {
|
||||
entries = append(entries, entry{p.Name, p.SerialNumber})
|
||||
}
|
||||
}
|
||||
slices.SortFunc(entries, func(a, b entry) int {
|
||||
return strings.Compare(a.serial, b.serial)
|
||||
})
|
||||
var result []string
|
||||
for _, e := range entries {
|
||||
result = append(result, e.name)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type serialTransport struct {
|
||||
port serial.Port
|
||||
portName string
|
||||
dec *msgpack.Decoder
|
||||
}
|
||||
|
||||
func NewSerial(portName string, timeout time.Duration) (*Client, error) {
|
||||
port, err := serial.Open(portName, &serial.Mode{BaudRate: 115200})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("opening %s: %w", portName, err)
|
||||
}
|
||||
t := &serialTransport{port: port, portName: portName, dec: msgpack.NewDecoder(port)}
|
||||
return &Client{transport: t, timeout: timeout}, nil
|
||||
}
|
||||
|
||||
func (t *serialTransport) Send(data []byte) error {
|
||||
_, err := t.port.Write(data)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *serialTransport) SetReadTimeout(timeout time.Duration) {
|
||||
t.port.SetReadTimeout(timeout)
|
||||
}
|
||||
|
||||
func (t *serialTransport) Recv() ([]byte, string, error) {
|
||||
var raw msgpack.RawMessage
|
||||
if err := t.dec.Decode(&raw); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return []byte(raw), t.portName, nil
|
||||
}
|
||||
|
||||
func (t *serialTransport) Broadcast() bool { return false }
|
||||
|
||||
func (t *serialTransport) Close() error {
|
||||
return t.port.Close()
|
||||
}
|
||||
@@ -2,9 +2,6 @@ package client
|
||||
|
||||
import "github.com/theater/picomap/lib/msgpack"
|
||||
|
||||
type RequestPICOBOOT struct{}
|
||||
type ResponsePICOBOOT struct{}
|
||||
|
||||
type RequestInfo struct{}
|
||||
type BootReason uint8
|
||||
|
||||
@@ -108,8 +105,6 @@ type Envelope struct {
|
||||
func init() {
|
||||
msgpack.RegisterExt(0, (*Envelope)(nil))
|
||||
msgpack.RegisterExt(1, (*DeviceError)(nil))
|
||||
msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil))
|
||||
msgpack.RegisterExt(3, (*ResponsePICOBOOT)(nil))
|
||||
msgpack.RegisterExt(4, (*RequestInfo)(nil))
|
||||
msgpack.RegisterExt(5, (*ResponseInfo)(nil))
|
||||
msgpack.RegisterExt(6, (*RequestLog)(nil))
|
||||
|
||||
Reference in New Issue
Block a user