mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-05-25 16:00:35 +00:00
style(tools): wrap serial lines for golines
This commit is contained in:
@@ -23,7 +23,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
unixSerialPortPattern = regexp.MustCompile(`^(?:/dev/)?(?:ttyS\d+|ttyUSB\d+|ttyACM\d+|ttyAMA\d+|rfcomm\d+|tty\.[A-Za-z0-9._-]+|cu\.[A-Za-z0-9._-]+)$`)
|
||||
unixSerialPortPattern = regexp.MustCompile(
|
||||
`^(?:/dev/)?(?:ttyS\d+|ttyUSB\d+|ttyACM\d+|ttyAMA\d+|rfcomm\d+|tty\.[A-Za-z0-9._-]+|cu\.[A-Za-z0-9._-]+)$`,
|
||||
)
|
||||
windowsSerialPortPattern = regexp.MustCompile(`^(?:\\\\\.\\)?COM[1-9]\d*$`)
|
||||
unixSerialBaudRates = map[int]struct{}{
|
||||
50: {}, 75: {}, 110: {}, 134: {}, 150: {}, 200: {}, 300: {}, 600: {}, 1200: {}, 1800: {},
|
||||
@@ -219,7 +221,9 @@ func parseSerialConfig(args map[string]any) (serialConfig, *ToolResult) {
|
||||
port, ok := args["port"].(string)
|
||||
port = strings.TrimSpace(port)
|
||||
if !ok || port == "" {
|
||||
return serialConfig{}, ErrorResult("port is required (for example /dev/ttyUSB0, /dev/cu.usbserial-0001, or COM3)")
|
||||
return serialConfig{}, ErrorResult(
|
||||
"port is required (for example /dev/ttyUSB0, /dev/cu.usbserial-0001, or COM3)",
|
||||
)
|
||||
}
|
||||
|
||||
normalizedPort, err := normalizeSerialPort(port)
|
||||
|
||||
@@ -103,7 +103,12 @@ func TestSerialReadCanceledBeforeOpen(t *testing.T) {
|
||||
port = "COM3"
|
||||
}
|
||||
|
||||
_, err := serialRead(ctx, serialConfig{Port: port, Baud: 115200, DataBits: 8, Parity: "none", StopBits: 1}, 1, time.Second)
|
||||
_, err := serialRead(
|
||||
ctx,
|
||||
serialConfig{Port: port, Baud: 115200, DataBits: 8, Parity: "none", StopBits: 1},
|
||||
1,
|
||||
time.Second,
|
||||
)
|
||||
if err == nil || !strings.Contains(err.Error(), context.Canceled.Error()) {
|
||||
t.Fatalf("serialRead() error = %v, want context canceled", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user