From 937730f54a68281dccfcb06629342e5259f00aad Mon Sep 17 00:00:00 2001 From: jet tsang zeon-git Date: Wed, 5 Aug 2020 15:41:15 +0800 Subject: Add lobotctl for debug instruction bytes Signed-off-by: jet tsang zeon-git --- .gitignore | 1 + cmd/lobotctl/lobotctl.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/lobotctl/lobotctl.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a50fb76 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +cmd/lobotctl/lobotctl diff --git a/cmd/lobotctl/lobotctl.go b/cmd/lobotctl/lobotctl.go new file mode 100644 index 0000000..c5533df --- /dev/null +++ b/cmd/lobotctl/lobotctl.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "strconv" + "strings" + + "git.jettsang.com/drivers/lobot/network" + "git.jettsang.com/drivers/lobot/servo" + "git.jettsang.com/drivers/lobot/servo/lx" + "github.com/jacobsa/go-serial/serial" +) + +var ( + portName = flag.String("port", "/dev/tty.usbserial-A9ITPZVR", "the serial port path") + servoID = flag.Int("id", 1, "the ID of the servo") + instruction = flag.String("instruction", "", "instruction") + argument = flag.String("arguments", "1,1000", "uint16 txt break on comma") + debug = flag.Bool("debug", false, "show serial traffic") +) + +func main() { + flag.Parse() + + options := serial.OpenOptions{ + PortName: *portName, + BaudRate: 115200, + DataBits: 8, + StopBits: 1, + MinimumReadSize: 0, + InterCharacterTimeout: 100, + } + + serial, err := serial.Open(options) + if err != nil { + fmt.Printf("open error: %s\n", err) + os.Exit(1) + } + + network := network.New(serial) + if *debug { + network.Logger = log.New(os.Stderr, "", log.LstdFlags) + } + + network.Flush() + + // var servo *servo.Servo + srv, err := lx.New(network, *servoID) + if err != nil { + log.Fatalln(err) + } + + var params []uint16 + textArguments := strings.Split(*argument, ",") + for _, v := range textArguments { + value, _ := strconv.Atoi(v) + params = append(params, uint16(value)) + } + + instRun := servo.GetInstName(*instruction) + log.Println(instRun.String(), params) + if err = srv.SendInstruction(instRun, params); err != nil { + log.Fatalln(err) + } + +} -- cgit v1.2.3