summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-03-29 20:25:48 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-03-29 20:25:48 (GMT)
commit59f010d9d418992e30fc9c798019a76b9d3df07b (patch)
tree910047f631f90809cd2e1618c4cbb092165a459d
parentd3efdc817664bb48a66e9b64c9167c02d0e1304c (diff)
added telnet control interface
-rw-r--r--Makefile3
-rw-r--r--sample-config.toml15
-rw-r--r--src/rhctl/conf.go3
-rw-r--r--src/rhctl/main.go22
-rw-r--r--src/rhctl/telnet.go59
5 files changed, 91 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 0ac1f91..34a8e2e 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,8 @@ GOCMD := GOPATH=$(curdir) go
EXECUTEABLE := rhctl
LIBS := "github.com/schleibinger/sio" \
- "github.com/naoina/toml"
+ "github.com/naoina/toml" \
+ "github.com/spreadspace/telgo"
.PHONY: getlibs updatelibs vet format build clean distclean
all: build
diff --git a/sample-config.toml b/sample-config.toml
index 800f764..af68f76 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -1,6 +1,6 @@
[audioswitch]
dev = "/dev/ttyUSB0"
-baud = 9600
+baud = 19200
timeout = "500ms"
ports = [ { name = "master_main", number = 1 },
{ name = "master_music", number = 2 },
@@ -9,11 +9,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"
@@ -25,3 +25,6 @@ ports = [ { name = "master_main", number = 1 },
[clients.web]
addr = ":4080"
+
+ [clients.telnet]
+ addr = "localhost:4023"
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index 47a51b8..e740bde 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -53,6 +53,9 @@ type Config struct {
Web struct {
Address string `toml:"addr"`
}
+ Telnet struct {
+ Address string `toml:"addr"`
+ }
}
}
diff --git a/src/rhctl/main.go b/src/rhctl/main.go
index 2aaf7aa..923a287 100644
--- a/src/rhctl/main.go
+++ b/src/rhctl/main.go
@@ -78,6 +78,8 @@ func main() {
rhl.Printf("just started...")
rhdl.Printf("configuration: %+v", conf)
+ //**************************************************
+ // initializing essential parts
sw, err := SwitchInit(conf)
if err != nil {
rhl.Println("error initializing audio switch: ", err)
@@ -93,13 +95,17 @@ func main() {
}
servers = append(servers, server)
}
- if len(servers) <= 0 {
- rhl.Printf("Error: there is no playout server configured...")
- return
- }
+ // if len(servers) <= 0 {
+ // rhl.Printf("Error: there is no playout server configured...")
+ // return
+ // }
ctrl := SwitchControlInit(conf, sw, servers)
+ // running non-essential parts aka clients
+ telnet := TelnetInit(conf, ctrl)
+
+ //**************************************************
// running essential parts
stop := make(chan bool)
@@ -126,6 +132,14 @@ func main() {
stop <- true
}()
+ // running non-essential parts aka clients
+ if conf.Clients.Telnet.Address != "" {
+ rhl.Printf("starting telnet interface")
+ telnet.Run()
+ rhl.Printf("telnet interface just stopped")
+ }
+
+ //**************************************************
<-stop
rhl.Printf("at least one essential part has stopped - bringing down the whole process")
}
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
new file mode 100644
index 0000000..3cc2b44
--- /dev/null
+++ b/src/rhctl/telnet.go
@@ -0,0 +1,59 @@
+//
+// rhctl
+//
+// Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at>
+//
+// This file is part of rhctl.
+//
+// rhctl is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// rhctl is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with rhctl. If not, see <http://www.gnu.org/licenses/>.
+//
+
+package main
+
+import (
+ "github.com/spreadspace/telgo"
+)
+
+type TelnetInterface struct {
+ server *telgo.Server
+}
+
+func status(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
+ // TODO: get status from ctrl
+ c.Sayln("not yet implemented!")
+ return false
+}
+
+func quit(c *telgo.Client, args []string) bool {
+ return true
+}
+
+func (telnet *TelnetInterface) Run() {
+ rhdl.Printf("Telnet: handler running...")
+ if err := telnet.server.Run(); err != nil {
+ rhl.Printf("Telnet: server returned: %s", err)
+ }
+}
+
+func TelnetInit(conf *Config, ctrl *SwitchControl) (telnet *TelnetInterface) {
+ telnet = &TelnetInterface{}
+
+ cmdlist := make(telgo.CmdList)
+ cmdlist["status"] = func(c *telgo.Client, args []string) bool { return status(c, args, ctrl) }
+ cmdlist["quit"] = quit
+
+ telnet.server = telgo.NewServer(conf.Clients.Telnet.Address, "rhctl> ", cmdlist, ctrl)
+
+ return
+}