JSON configs describe network and node MACs; scenarios run command sequences with expect checks. Share UART client API across CLI and tests. Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
const defaultBaud = 921600
|
|
|
|
func usage() {
|
|
fmt.Fprintf(os.Stderr, "usage: gotool -port /dev/ttyUSB0 <command>\n\n")
|
|
fmt.Fprintf(os.Stderr, "commands:\n")
|
|
fmt.Fprintf(os.Stderr, " version firmware version and git hash\n")
|
|
fmt.Fprintf(os.Stderr, " clients registered ESP-NOW slaves on the master\n")
|
|
fmt.Fprintf(os.Stderr, " deadzone get/set accelerometer deadzone (LSB)\n")
|
|
fmt.Fprintf(os.Stderr, " unicast-test send ESP-NOW unicast test to one slave\n")
|
|
fmt.Fprintf(os.Stderr, " test run automated scenario (see testdata/)\n\n")
|
|
flag.PrintDefaults()
|
|
}
|
|
|
|
func main() {
|
|
portName := flag.String("port", "", "serial port (e.g. /dev/ttyUSB0)")
|
|
baud := flag.Int("baud", defaultBaud, "UART baud rate")
|
|
flag.Parse()
|
|
|
|
if *portName == "" || flag.NArg() < 1 {
|
|
usage()
|
|
os.Exit(2)
|
|
}
|
|
|
|
cmd := flag.Arg(0)
|
|
|
|
sp, err := openSerial(*portName, *baud)
|
|
if err != nil {
|
|
log.Fatalf("open serial: %v", err)
|
|
}
|
|
defer sp.Close()
|
|
|
|
var runErr error
|
|
switch cmd {
|
|
case "version":
|
|
runErr = runVersion(sp)
|
|
case "clients", "client-info":
|
|
runErr = runClients(sp)
|
|
case "deadzone", "accel-deadzone":
|
|
runErr = runDeadzone(sp, flag.Args()[1:])
|
|
case "unicast-test", "unicast_test":
|
|
runErr = runUnicastTest(sp, flag.Args()[1:])
|
|
case "test", "autotest":
|
|
runErr = runTest(sp, flag.Args()[1:])
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "unknown command %q\n\n", cmd)
|
|
usage()
|
|
os.Exit(2)
|
|
}
|
|
|
|
if runErr != nil {
|
|
log.Fatal(runErr)
|
|
}
|
|
}
|