diff options
Diffstat (limited to 'src/rhctl')
-rw-r--r-- | src/rhctl/audio_switch.go | 4 | ||||
-rw-r--r-- | src/rhctl/audio_switch_command.go | 51 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go index b3a526e..bb94f61 100644 --- a/src/rhctl/audio_switch.go +++ b/src/rhctl/audio_switch.go @@ -153,8 +153,10 @@ func (sw *AudioSwitch) Run() { case <-stop: return case cmd := <-sw.Commands: + c := cmd.Cmd.Generate(append(cmd.Args, sw.unit)...) + rhdl.Printf("sending '%s' to switch", c) sw.current = cmd - sw.port.tx <- cmd.Cmd.Generate(append(cmd.Args, sw.unit)...) + sw.port.tx <- c sw.timer = time.NewTimer(sw.timeout) case data := <-sw.port.rx: sw.handleData(data) 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) } |