summaryrefslogtreecommitdiff
path: root/src/rhctl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl')
-rw-r--r--src/rhctl/audio_switch.go24
-rw-r--r--src/rhctl/audio_switch_command.go12
-rw-r--r--src/rhctl/switch_control.go29
-rw-r--r--src/rhctl/telnet.go13
4 files changed, 48 insertions, 30 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go
index dd61f46..f3cb5df 100644
--- a/src/rhctl/audio_switch.go
+++ b/src/rhctl/audio_switch.go
@@ -85,10 +85,14 @@ type SwitchState struct {
Inputs [SwitchInputNumMax]bool
Silence bool
}
- GPI [SwitchGPINumMax]bool
- Relay [SwitchRelayNumMax]bool
- OC [SwitchOCNumMax]bool
- Changed time.Time
+ AudioInputsChanged time.Time
+ AudioSilenceChanged time.Time
+ GPI [SwitchGPINumMax]bool
+ GPIChanged time.Time
+ Relay [SwitchRelayNumMax]bool
+ RelayChanged time.Time
+ OC [SwitchOCNumMax]bool
+ OCChanged time.Time
}
type AudioSwitch struct {
@@ -128,7 +132,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.state.AudioInputsChanged = time.Now()
sw.StateChanges <- sw.state
}
@@ -154,7 +158,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.state.GPIChanged = time.Now()
sw.StateChanges <- sw.state
return
}
@@ -180,7 +184,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.state.GPIChanged = time.Now()
sw.StateChanges <- sw.state
}
@@ -205,7 +209,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.state.RelayChanged = time.Now()
sw.StateChanges <- sw.state
}
@@ -230,7 +234,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.state.OCChanged = time.Now()
sw.StateChanges <- sw.state
}
@@ -255,7 +259,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.state.AudioSilenceChanged = time.Now()
sw.StateChanges <- sw.state
}
diff --git a/src/rhctl/audio_switch_command.go b/src/rhctl/audio_switch_command.go
index 1c2e2fb..a2c5a09 100644
--- a/src/rhctl/audio_switch_command.go
+++ b/src/rhctl/audio_switch_command.go
@@ -156,11 +156,11 @@ type SwitchCmdString string
const (
SwitchCmdStateAudio SwitchCmdString = "*uSL"
+ SwitchCmdStateSilence SwitchCmdString = "*uSS"
SwitchCmdStateGPI SwitchCmdString = "*uSPgg"
SwitchCmdStateGPIAll SwitchCmdString = "*uSPA"
- SwitchCmdStateOC SwitchCmdString = "*uSO"
SwitchCmdStateRelay SwitchCmdString = "*uSR"
- SwitchCmdStateSilence SwitchCmdString = "*uSS"
+ SwitchCmdStateOC SwitchCmdString = "*uSO"
SwitchCmdAudioApplyInput SwitchCmdString = "*uiio"
SwitchCmdAudioApplyInputAll SwitchCmdString = "*uiiA"
@@ -237,14 +237,14 @@ func SwitchCommandParseState(args []string) (cmdstr SwitchCmdString, cmdargs []i
switch strings.ToLower(args[0]) {
case "audio":
cmdstr = SwitchCmdStateAudio
+ case "silence":
+ cmdstr = SwitchCmdStateSilence
case "gpi":
cmdstr = SwitchCmdStateGPIAll
- case "oc":
- cmdstr = SwitchCmdStateOC
case "relay":
cmdstr = SwitchCmdStateRelay
- case "silence":
- cmdstr = SwitchCmdStateSilence
+ case "oc":
+ cmdstr = SwitchCmdStateOC
default:
err = fmt.Errorf("unknown state-type: '%s'", args[0])
return
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 4211d9d..822c044 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -125,25 +125,38 @@ func handleServer(in <-chan ServerState, out chan<- ServerState) {
}
}
-func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
- rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
-
- // send out commands to switch and/or server to get missing infos
- if time.Since(ctrl.state.Switch.Changed) > (2 * time.Hour) { // TODO: hardcoded value
+func (ctrl *SwitchControl) checkMissingOrStaleStates(maxAge time.Duration) {
+ if time.Since(ctrl.state.Switch.AudioInputsChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateAudio, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.AudioSilenceChanged) > maxAge {
+ ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateSilence, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.GPIChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateGPIAll, nil, nil}
- ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateOC, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.RelayChanged) > maxAge {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateRelay, nil, nil}
- ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateSilence, nil, nil}
+ }
+ if time.Since(ctrl.state.Switch.OCChanged) > maxAge {
+ ctrl.sw.Commands <- &SwitchCommand{SwitchCmdStateOC, nil, nil}
}
for _, server := range ctrl.servers {
s, exists := ctrl.state.Server[server.name]
- if !exists || time.Since(s.Changed) > (2*time.Hour) { // TODO: hardcoded value
+ if !exists || time.Since(s.Changed) > maxAge {
server.UpdateRequest <- true
}
}
+}
+
+func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
+ rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
+
+ // send out commands to switch and/or server to get missing infos
+ ctrl.checkMissingOrStaleStates(2 * time.Hour) // TODO: hardcoded value
+
if ctrl.state.Mood == MoodAwakening && time.Since(ctrl.startup) < (time.Minute) { // TODO: hardcoded value
// it's to early to take actions - let's learn i little bit more about current state
return
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index 43e571e..c849bd8 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -24,6 +24,7 @@ package main
import (
"sort"
"strings"
+ "time"
"github.com/spreadspace/telgo"
)
@@ -57,19 +58,19 @@ func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
c.Sayln("Mood: %v", s.Mood)
c.Sayln("Switch:")
- c.Sayln(" audio:")
+ c.Sayln(" audio: (last changed: %v ago)", time.Since(s.Switch.AudioInputsChanged))
for num, out := range s.Switch.Audio {
c.Say(" out %d: ", num+1)
if out.Silence {
- c.Sayln("%s (silence!!!)", genStateString(out.Inputs[:]))
+ c.Sayln("%s (silent, since > %v)", genStateString(out.Inputs[:]), time.Since(s.Switch.AudioSilenceChanged))
} else {
c.Sayln("%s", genStateString(out.Inputs[:]))
}
}
- c.Sayln(" gpi: %s", genStateString(s.Switch.GPI[:]))
- c.Sayln(" relay: %s", genStateString(s.Switch.Relay[:]))
- c.Sayln(" oc: %s", genStateString(s.Switch.OC[:]))
+ c.Sayln(" gpi: %s (last changed: %v ago)", genStateString(s.Switch.GPI[:]), time.Since(s.Switch.GPIChanged))
+ c.Sayln(" relay: %s (last changed: %v ago)", genStateString(s.Switch.Relay[:]), time.Since(s.Switch.GPIChanged))
+ c.Sayln(" oc: %s (last changed: %v ago)", genStateString(s.Switch.OC[:]), time.Since(s.Switch.GPIChanged))
c.Sayln("Server:")
var names []string
@@ -83,7 +84,7 @@ func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
} else {
c.Say(" ")
}
- c.Sayln("%s(%s): '%s'", name, s.Server[name].Health, s.Server[name].Channel)
+ c.Sayln("%s(%s): '%s' (last changed: %v ago)", name, s.Server[name].Health, s.Server[name].Channel, time.Since(s.Server[name].Changed))
}
default:
c.Sayln("invalid response of type %T: %+v", r, r)