diff options
Diffstat (limited to 'src/rhctl/audio_switch.go')
-rw-r--r-- | src/rhctl/audio_switch.go | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go index 8c698b4..dd61f46 100644 --- a/src/rhctl/audio_switch.go +++ b/src/rhctl/audio_switch.go @@ -85,9 +85,10 @@ type SwitchState struct { Inputs [SwitchInputNumMax]bool Silence bool } - GPI [SwitchGPINumMax]bool - Relay [SwitchRelayNumMax]bool - OC [SwitchOCNumMax]bool + GPI [SwitchGPINumMax]bool + Relay [SwitchRelayNumMax]bool + OC [SwitchOCNumMax]bool + Changed time.Time } type AudioSwitch struct { @@ -127,6 +128,7 @@ func (sw *AudioSwitch) updateStateAudio(data string) { rhl.Printf("Audioswitch: invalid audio status update (state must be either '1' or '0' but is '%s')", ins[i]) } } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state } @@ -152,6 +154,7 @@ func (sw *AudioSwitch) updateStateGPI(data string) { rhl.Printf("Audioswitch: invalid gpi status update (state must be either '1' or '0' but is '%s')", data[7:8]) return } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state return } @@ -177,6 +180,7 @@ func (sw *AudioSwitch) updateStateGPI(data string) { rhl.Printf("Audioswitch: invalid gpi status update (state must be either '1' or '0' but is '%s')", ins[i]) } } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state } @@ -201,6 +205,7 @@ func (sw *AudioSwitch) updateStateRelay(data string) { rhl.Printf("Audioswitch: invalid relay status update (state must be either '1' or '0' but is '%s')", outs[i]) } } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state } @@ -225,6 +230,7 @@ func (sw *AudioSwitch) updateStateOC(data string) { rhl.Printf("Audioswitch: invalid oc status update (state must be either '1' or '0' but is '%s')", outs[i]) } } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state } @@ -249,6 +255,7 @@ func (sw *AudioSwitch) updateStateSilence(data string) { rhl.Printf("Audioswitch: invalid silence status update (state must be either '1' or '0' but is '%s')", outs[i]) } } + sw.state.Changed = time.Now() sw.StateChanges <- sw.state } @@ -261,12 +268,14 @@ func (sw *AudioSwitch) handleData(data string) { rhdl.Printf("Audioswitch: got data: %q", data) if data[0:3] == "RRR" || data[0:3] == "EEE" { if sw.current != nil { - resp := SwitchResponse{Message: data} - resp.Result = SwitchError - if data[0] == 'R' { - resp.Result = SwitchOK + if sw.current.Response != nil { + resp := SwitchResponse{Message: data} + resp.Result = SwitchError + if data[0] == 'R' { + resp.Result = SwitchOK + } + sw.current.Response <- resp } - sw.current.Response <- resp sw.current = nil sw.timer.Stop() sw.timer = nil @@ -313,7 +322,9 @@ func (sw *AudioSwitch) Run() { case <-stop: return case <-sw.timer.C: - sw.current.Response <- fmt.Errorf("command timed out") + if sw.current.Response != nil { + sw.current.Response <- fmt.Errorf("command timed out") + } sw.current = nil sw.timer = nil case data := <-sw.port.rx: @@ -326,7 +337,9 @@ func (sw *AudioSwitch) Run() { case cmd := <-sw.Commands: c, err := cmd.Cmd.Generate(append(cmd.Args, sw.unit)...) if err != nil { - cmd.Response <- err + if cmd.Response != nil { + cmd.Response <- err + } } else { rhdl.Printf("sending '%s' to switch", c) sw.current = cmd @@ -348,7 +361,7 @@ func SwitchInit(conf *Config) (sw *AudioSwitch, err error) { } sw.unit = conf.Audioswitch.Unit sw.StateChanges = make(chan SwitchState, 16) - sw.Commands = make(chan *SwitchCommand, 8) + sw.Commands = make(chan *SwitchCommand, 16) sw.Updates = make(chan SwitchUpdate, 32) if sw.port, err = SerialOpen(conf.Audioswitch.Device, conf.Audioswitch.Baudrate, ""); err != nil { |