summaryrefslogtreecommitdiff
path: root/src/rhctl/audio_switch_command.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-04-01 00:08:18 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-04-01 00:08:18 (GMT)
commitad2a03f383474c3eecf7b2f4eb90dfda2540fa58 (patch)
treec0ee62089b9f5851f6b0fce47ea2e3218fec7a35 /src/rhctl/audio_switch_command.go
parent50efc53ea340a311961c2f44646da031bee480c3 (diff)
implemented oc and relay commands
Diffstat (limited to 'src/rhctl/audio_switch_command.go')
-rw-r--r--src/rhctl/audio_switch_command.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/rhctl/audio_switch_command.go b/src/rhctl/audio_switch_command.go
index e865a90..2aed51f 100644
--- a/src/rhctl/audio_switch_command.go
+++ b/src/rhctl/audio_switch_command.go
@@ -200,12 +200,63 @@ func SwitchCommandParseStatus(args []string) (cmdstr SwitchCmdString, cmdargs []
}
return
}
+func SwitchCommandParseRelay(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) {
+ if len(args) != 2 {
+ err = fmt.Errorf("wrong number of arguments, expecting: <oc-num> (latch|unlatch|pulse)")
+ return
+ }
+ var num SwitchRelayNum
+ if err = num.FromString(args[0]); err != nil {
+ return
+ }
+ cmdargs = append(cmdargs, num)
+ switch args[1] {
+ case "latch":
+ cmdstr = SwitchCmdRelayLatch
+ case "unlatch":
+ cmdstr = SwitchCmdRelayUnlatch
+ case "pulse":
+ cmdstr = SwitchCmdRelayPulse
+ default:
+ err = fmt.Errorf("unknown operation: '%s', must be one of latch, unlatch, pulse", args[1])
+ return
+ }
+ return
+}
+
+func SwitchCommandParseOC(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) {
+ if len(args) != 2 {
+ err = fmt.Errorf("wrong number of arguments, expecting: <oc-num> (latch|unlatch|pulse)")
+ return
+ }
+ var num SwitchOCNum
+ if err = num.FromString(args[0]); err != nil {
+ return
+ }
+ cmdargs = append(cmdargs, num)
+ switch args[1] {
+ case "latch":
+ cmdstr = SwitchCmdOCLatch
+ case "unlatch":
+ cmdstr = SwitchCmdOCUnlatch
+ case "pulse":
+ cmdstr = SwitchCmdOCPulse
+ default:
+ err = fmt.Errorf("unknown operation: '%s', must be one of latch, unlatch, pulse", args[1])
+ return
+ }
+ return
+}
func NewSwitchCommandFromStrings(cmd string, args ...string) (c *SwitchCommand, err error) {
c = &SwitchCommand{}
switch cmd {
case "status":
c.Cmd, c.Args, err = SwitchCommandParseStatus(args)
+ case "relay":
+ c.Cmd, c.Args, err = SwitchCommandParseRelay(args)
+ case "oc":
+ c.Cmd, c.Args, err = SwitchCommandParseOC(args)
default:
return nil, fmt.Errorf("unknown command '%s'", cmd)
}