From 04a00559a15f3e94520c5ff26fc90f26b1a37707 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 3 Apr 2016 01:52:24 +0200 Subject: telnet state command almost done 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 } -- cgit v0.10.2