Added some basic command handling for the devices
This commit is contained in:
+28
-19
@@ -62,29 +62,38 @@ func replCmdAction(cmd *cobra.Command, args []string) {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
// selectDeviceREPLCmd := repl.Command{
|
||||
// Name: "select",
|
||||
// Usage: "Selects a given device - pass its ID",
|
||||
// Action: func(r *repl.REPL, args []string) error {
|
||||
// // We should add this to the REPL instead
|
||||
// if len(args) < 1 {
|
||||
// return fmt.Errorf("requires at least on argument")
|
||||
// }
|
||||
//
|
||||
// // First and only argument should be the ID of the device we want to use
|
||||
// targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
|
||||
runDeviceAPIREPLCmd := repl.Command{
|
||||
Name: "v-run",
|
||||
Usage: "runs a funcion of a device - pass its ID and function name",
|
||||
Action: func(r *repl.REPL, args []string) error {
|
||||
// We should add this to the REPL instead
|
||||
if len(args) < 3 {
|
||||
return fmt.Errorf("requires at least on argument")
|
||||
}
|
||||
|
||||
// First and only argument should be the ID of the device we want to use
|
||||
targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fnName := args[1]
|
||||
fnArgs := args[2:]
|
||||
|
||||
err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
r.RegisterCMD(discoverDevicesREPLCmd)
|
||||
r.RegisterCMD(listDevicesREPLCmd)
|
||||
// r.RegisterCMD(selectDeviceREPLCmd)
|
||||
r.RegisterCMD(listDeviceAPIREPLCmd)
|
||||
r.RegisterCMD(runDeviceAPIREPLCmd)
|
||||
|
||||
r.Start()
|
||||
r.Close()
|
||||
|
||||
Reference in New Issue
Block a user