summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-02 23:52:24 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-02 23:52:24 (GMT)
commit04a00559a15f3e94520c5ff26fc90f26b1a37707 (patch)
tree545a042023dfdde1ba853249f53dae113aa31619
parent2f34a5e62285a3c5334c270c6111e43fc12e8dbf (diff)
telnet state command almost done
-rw-r--r--sample-config.toml10
-rw-r--r--src/rhctl/switch_control.go1
-rw-r--r--src/rhctl/telnet.go39
3 files changed, 43 insertions, 7 deletions
diff --git a/sample-config.toml b/sample-config.toml
index 3a57bef..cdd27da 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -10,11 +10,11 @@ ports = [ { name = "master_main", number = 1 },
[servers]
- #[servers.master]
- #ctrl_dev = "/dev/ttyUSB1"
- #ctrl_baud = 38400
- #heartbeat_dev = "/dev/ttyUSB2"
- #heartbeat_baud = 19200
+ # [servers.master]
+ # ctrl_dev = "/dev/ttyUSB1"
+ # ctrl_baud = 38400
+ # heartbeat_dev = "/dev/ttyUSB2"
+ # heartbeat_baud = 19200
# [servers.standby]
# ctrl_dev = "/dev/ttyUSB3"
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 91cc161..523269f 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -113,6 +113,7 @@ type SwitchControl struct {
func (ctrl *SwitchControl) handleCommand(cmd *Command) {
switch cmd.Type {
case CmdState:
+ cmd.Response <- ctrl.state
case CmdServer:
case CmdSwitch:
if len(cmd.Args) == 0 {
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index de98475..e4044ef 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -22,6 +22,8 @@
package main
import (
+ "sort"
+
"github.com/spreadspace/telgo"
)
@@ -30,8 +32,41 @@ type TelnetInterface struct {
}
func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
- ctrl.Commands <- &Command{Type: CmdState}
- // TODO: implement this
+ resp := make(chan interface{})
+ ctrl.Commands <- &Command{Type: CmdState, Response: resp}
+
+ r := <-resp
+ switch r.(type) {
+ case error:
+ c.Sayln("%v", r)
+ case State:
+ s := r.(State)
+ c.Sayln("Mood: %v", s.Mood)
+
+ c.Sayln("Switch:")
+ c.Sayln(" audio:") //
+ c.Sayln(" output 1: ? (silence!!)?") //
+ c.Sayln(" output 2: ? (silence!!)?") // TODO: fill this with actual data
+ c.Sayln(" relays: ?") //
+ c.Sayln(" oc: ?") //
+
+ c.Sayln("Server:")
+ var names []string
+ for n, _ := range s.Server {
+ names = append(names, n)
+ }
+ sort.Strings(names)
+ for _, name := range names {
+ if name == s.ActiveServer {
+ c.Say(" * ")
+ } else {
+ c.Say(" ")
+ }
+ c.Sayln("%s(%s): '%s'", name, s.Server[name].Health, s.Server[name].Channel)
+ }
+ default:
+ c.Sayln("invalid response of type %T: %+v", r, r)
+ }
return false
}