summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/audio_switch.go179
-rw-r--r--src/rhctl/switch_control.go6
-rw-r--r--src/rhctl/telnet.go6
3 files changed, 167 insertions, 24 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go
index 3bb4abb..31ecbc4 100644
--- a/src/rhctl/audio_switch.go
+++ b/src/rhctl/audio_switch.go
@@ -23,6 +23,7 @@ package main
import (
"fmt"
+ "strings"
"time"
)
@@ -101,6 +102,138 @@ type AudioSwitch struct {
Updates chan SwitchUpdate
}
+func (sw *AudioSwitch) updateStateAudio(data string) {
+ if len(data) < int(4+2*SwitchInputNumMax) {
+ rhl.Printf("Audioswitch: invalid audio status update (too short)", data)
+ return
+ }
+ var out SwitchOutputNum
+ if err := out.FromString(data[3:4]); err != nil {
+ rhl.Printf("Audioswitch: invalid audio status update (%s)", err)
+ return
+ }
+ ins := strings.Split(data[5:int(4+2*SwitchInputNumMax)], ",")
+ if len(ins) != int(SwitchInputNumMax) {
+ rhl.Printf("Audioswitch: invalid audio status update (wrong number of inputs)")
+ return
+ }
+ for i := 0; i < int(SwitchInputNumMax); i++ {
+ switch ins[i] {
+ case "0":
+ sw.state.Audio[out-1].Inputs[i] = false
+ case "1":
+ sw.state.Audio[out-1].Inputs[i] = true
+ default:
+ rhl.Printf("Audioswitch: invalid audio status update (state must be either \"1\" or \"0\" but is %q)", ins[i])
+ }
+ }
+ sw.StateChanges <- sw.state
+}
+
+func (sw *AudioSwitch) updateStateGPI(data string) {
+ if len(data) < 5 {
+ rhl.Printf("Audioswitch: invalid gpi status update (too short)", data)
+ return
+ }
+ if data[4] != 'A' {
+ return // TODO: parse single GPI status...
+ }
+
+ if len(data) < int(5+2*SwitchGPINumMax) {
+ rhl.Printf("Audioswitch: invalid gpi status update (too short)", data)
+ return
+ }
+
+ ins := strings.Split(data[6:int(5+2*SwitchGPINumMax)], ",")
+ if len(ins) != int(SwitchGPINumMax) {
+ rhl.Printf("Audioswitch: invalid gpi status update (wrong number of inputs)")
+ return
+ }
+ for i := 0; i < int(SwitchGPINumMax); i++ {
+ switch ins[i] {
+ case "0":
+ sw.state.GPI[i] = false
+ case "1":
+ sw.state.GPI[i] = true
+ default:
+ rhl.Printf("Audioswitch: invalid gpi status update (state must be either \"1\" or \"0\" but is %q)", ins[i])
+ }
+ }
+ sw.StateChanges <- sw.state
+}
+
+func (sw *AudioSwitch) updateStateRelay(data string) {
+ if len(data) < int(3+2*SwitchRelayNumMax) {
+ rhl.Printf("Audioswitch: invalid relay status update (too short)", data)
+ return
+ }
+
+ outs := strings.Split(data[4:int(3+2*SwitchRelayNumMax)], ",")
+ if len(outs) != int(SwitchRelayNumMax) {
+ rhl.Printf("Audioswitch: invalid relay status update (wrong number of outputs)")
+ return
+ }
+ for i := 0; i < int(SwitchRelayNumMax); i++ {
+ switch outs[i] {
+ case "0":
+ sw.state.Relay[i] = false
+ case "1":
+ sw.state.Relay[i] = true
+ default:
+ rhl.Printf("Audioswitch: invalid relay status update (state must be either \"1\" or \"0\" but is %q)", outs[i])
+ }
+ }
+ sw.StateChanges <- sw.state
+}
+
+func (sw *AudioSwitch) updateStateOC(data string) {
+ if len(data) < int(3+2*SwitchOCNumMax) {
+ rhl.Printf("Audioswitch: invalid oc status update (too short)", data)
+ return
+ }
+
+ outs := strings.Split(data[4:int(3+2*SwitchOCNumMax)], ",")
+ if len(outs) != int(SwitchOCNumMax) {
+ rhl.Printf("Audioswitch: invalid oc status update (wrong number of outputs)")
+ return
+ }
+ for i := 0; i < int(SwitchOCNumMax); i++ {
+ switch outs[i] {
+ case "0":
+ sw.state.OC[i] = false
+ case "1":
+ sw.state.OC[i] = true
+ default:
+ rhl.Printf("Audioswitch: invalid oc status update (state must be either \"1\" or \"0\" but is %q)", outs[i])
+ }
+ }
+ sw.StateChanges <- sw.state
+}
+
+func (sw *AudioSwitch) updateStateSilence(data string) {
+ if len(data) < int(3+2*SwitchOutputNumMax) {
+ rhl.Printf("Audioswitch: invalid silence status update (too short)", data)
+ return
+ }
+
+ outs := strings.Split(data[4:int(3+2*SwitchOutputNumMax)], ",")
+ if len(outs) != int(SwitchOutputNumMax) {
+ rhl.Printf("Audioswitch: invalid silence status update (wrong number of outputs)")
+ return
+ }
+ for i := 0; i < int(SwitchOutputNumMax); i++ {
+ switch outs[i] {
+ case "0":
+ sw.state.Audio[i].Silence = false
+ case "1":
+ sw.state.Audio[i].Silence = true
+ default:
+ rhl.Printf("Audioswitch: invalid silence status update (state must be either \"1\" or \"0\" but is %q)", outs[i])
+ }
+ }
+ sw.StateChanges <- sw.state
+}
+
func (sw *AudioSwitch) handleData(data string) {
if len(data) < 3 {
rhl.Printf("Audioswitch: ignoring short line")
@@ -108,10 +241,7 @@ func (sw *AudioSwitch) handleData(data string) {
}
rhdl.Printf("Audioswitch: got data: %q", data)
- switch data[0:3] {
- case "RRR":
- fallthrough
- case "EEE":
+ if data[0:3] == "RRR" || data[0:3] == "EEE" {
if sw.current != nil {
resp := SwitchResponse{Message: data}
resp.Result = SwitchError
@@ -125,24 +255,31 @@ func (sw *AudioSwitch) handleData(data string) {
} else {
rhl.Printf("Audioswitch: ignoring unexpected response: %q", data)
}
- case "S0L":
- sw.Updates <- SwitchUpdate{SwitchAudio, data}
- // TODO: update state and send it out
- case "S0P":
- sw.Updates <- SwitchUpdate{SwitchGPI, data}
- // TODO: update state and send it out
- case "S0O":
- sw.Updates <- SwitchUpdate{SwitchOC, data}
- // TODO: update state and send it out
- case "S0R":
- sw.Updates <- SwitchUpdate{SwitchRelay, data}
- // TODO: update state and send it out
- case "S0S":
- sw.Updates <- SwitchUpdate{SwitchSilence, data}
- // TODO: update state and send it out
- default:
- rhl.Printf("Audioswitch: ignoring invalid data: %q", data)
+ return
}
+
+ if data[0] == 'S' && data[1] == ('0'+byte(sw.unit)) {
+ switch data[2] {
+ case 'L':
+ sw.Updates <- SwitchUpdate{SwitchAudio, data}
+ sw.updateStateAudio(data)
+ case 'P':
+ sw.Updates <- SwitchUpdate{SwitchGPI, data}
+ sw.updateStateGPI(data)
+ case 'R':
+ sw.Updates <- SwitchUpdate{SwitchRelay, data}
+ sw.updateStateRelay(data)
+ case 'O':
+ sw.Updates <- SwitchUpdate{SwitchOC, data}
+ sw.updateStateOC(data)
+ case 'S':
+ sw.Updates <- SwitchUpdate{SwitchSilence, data}
+ sw.updateStateSilence(data)
+ }
+ return
+ }
+
+ rhl.Printf("Audioswitch: ignoring invalid data: %q", data)
}
func (sw *AudioSwitch) Run() {
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 463c97e..2864cc9 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -127,9 +127,9 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
// TODO: set mood dependent on overall-state
- // TODO: send out commands to switch, server to get missing infos
+ // TODO: send out commands to switch and/or server to get missing infos
- // TODO: change active server it fails or on request
+ // TODO: change active server if it fails or on request
// return true if requested server got selected
// TODO: change switch output mappings if servers change channels or fail
@@ -154,7 +154,7 @@ func (ctrl *SwitchControl) Run() {
}
ctrl.Updates.Pub(update, "switch:"+update.Type.String())
case state := <-ctrl.sw.StateChanges:
- rhdl.Printf("got switch state update: %+v", state)
+ // rhdl.Printf("got switch state update: %+v", state)
ctrl.Updates.Pub(state, "switch:state")
ctrl.state.Switch = state
ctrl.reconcile("")
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index 4735956..2623602 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -111,6 +111,12 @@ func telnetUpdateListener(c *telgo.Client, ctrl *SwitchControl) {
ctrl.Updates.Unsub(ch)
return
}
+ case SwitchState:
+ //state := data.(SwitchState)
+ // TODO: implement this
+ case State:
+ //state := data.(State)
+ // TOOD: implement this
default:
if !c.Sayln("unknown update of type: %T", data) {
ctrl.Updates.Unsub(ch)