summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-03-26 19:00:49 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-03-26 19:00:49 (GMT)
commit9c3fc8f9fa3f54566286f2e2222ab16f7634c325 (patch)
tree0cebfc23050c4a45dbc9db7c2639507370f1a5c2 /src
parent7cfc7644c284b72997eb3b31b98fab447fe06bed (diff)
basic process handling is working
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/audio_switch.go7
-rw-r--r--src/rhctl/conf.go10
-rw-r--r--src/rhctl/main.go61
-rw-r--r--src/rhctl/playout_server.go9
4 files changed, 53 insertions, 34 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go
index 3da62ca..1368da8 100644
--- a/src/rhctl/audio_switch.go
+++ b/src/rhctl/audio_switch.go
@@ -23,6 +23,7 @@ package main
import (
"fmt"
+ "time"
)
type AudioSwitch struct {
@@ -32,12 +33,14 @@ type AudioSwitch struct {
func (sw *AudioSwitch) Run() {
rhdl.Printf("running audio switch")
sw.port.tx <- "hello switch"
+
+ time.Sleep(10 * time.Second)
}
-func SwitchInit(dev string, rate Baudrate) (sw *AudioSwitch, err error) {
+func SwitchInit(conf *Config) (sw *AudioSwitch, err error) {
sw = &AudioSwitch{}
- if sw.port, err = SerialOpenAndHandle(dev, rate, ""); err != nil {
+ if sw.port, err = SerialOpenAndHandle(conf.Audioswitch.Device, conf.Audioswitch.Baudrate, ""); err != nil {
err = fmt.Errorf("Error opening switch port: %s", err)
return
}
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index fda09a6..acd5cd1 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -34,15 +34,15 @@ type Config struct {
}
Servers map[string]struct {
- ControlDevice string `toml:"ctrl_dev"`
- ControlBaud Baudrate `toml:"ctrl_baud"`
- HeartbeatDev string `toml:"heartbeat_dev"`
- HeartbeatBaud Baudrate `toml:"heartbeat_baud"`
+ ControlDevice string `toml:"ctrl_dev"`
+ ControlBaudrate Baudrate `toml:"ctrl_baud"`
+ HeartbeatDevice string `toml:"heartbeat_dev"`
+ HeartbeatBaudrate Baudrate `toml:"heartbeat_baud"`
}
Clients struct {
Web struct {
- Addr string `toml:"addr"`
+ Address string `toml:"addr"`
}
}
}
diff --git a/src/rhctl/main.go b/src/rhctl/main.go
index 14a86bc..dff1758 100644
--- a/src/rhctl/main.go
+++ b/src/rhctl/main.go
@@ -75,29 +75,42 @@ func main() {
rhl.Println("Error reading configuration:", err.Error())
return
}
+ rhl.Printf("just started...")
- rhdl.Printf("config: %+v", conf)
-
- // sw, err := SwitchInit("/dev/ttyUSB0", B9600)
- // if err != nil {
- // rhl.Println("error audio switch: ", err)
- // return
- // }
-
- // master, err := ServerInit("master", "/dev/ttyUSB1", "/dev/ttyUSB2", B38400)
- // if err != nil {
- // rhl.Println("error master server: ", err)
- // return
- // }
-
- // standby, err := ServerInit("standby", "/dev/ttyUSB3", "/dev/ttyUSB4", B38400)
- // if err != nil {
- // rhl.Println("error standby server: ", err)
- // return
- // }
-
- // sw.Run()
- // master.Run()
- // standby.Run()
- // time.Sleep(time.Second)
+ stop := make(chan bool)
+
+ sw, err := SwitchInit(conf)
+ if err != nil {
+ rhl.Println("error initializing audio switch: ", err)
+ return
+ }
+
+ var servers []*PlayoutServer
+ for s, _ := range conf.Servers {
+ server, err := ServerInit(s, conf)
+ if err != nil {
+ rhl.Printf("error initializing playout-server(%s): %v", s, err)
+ return
+ }
+ servers = append(servers, server)
+ }
+
+ go func() {
+ rhl.Printf("starting audioswitch handler")
+ sw.Run()
+ rhl.Printf("audioswitch handler has stopped")
+ stop <- true
+ }()
+
+ for _, server := range servers {
+ go func(server *PlayoutServer) {
+ rhl.Printf("starting playout-server(%s) handler", server.name)
+ server.Run()
+ rhl.Printf("playout-server(%s) handler has stopped", server.name)
+ stop <- true
+ }(server)
+ }
+
+ <-stop
+ rhl.Printf("at least one essential part has stopped - bringing down the whole process")
}
diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go
index 118d69f..5491b23 100644
--- a/src/rhctl/playout_server.go
+++ b/src/rhctl/playout_server.go
@@ -23,6 +23,7 @@ package main
import (
"fmt"
+ "time"
)
type ServerHealth bool
@@ -44,19 +45,21 @@ func (srv *PlayoutServer) Run() {
rhdl.Printf("running playout server: %s", srv.name)
srv.control.tx <- fmt.Sprintf("hello %s", srv.name)
srv.heartbeat.tx <- fmt.Sprintf("beat %s", srv.name)
+
+ time.Sleep(5 * time.Second)
}
-func ServerInit(name string, ctrldev, hbdev string, rate Baudrate) (srv *PlayoutServer, err error) {
+func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) {
srv = &PlayoutServer{}
srv.name = name
srv.health = Dead
srv.channel = "music"
- if srv.control, err = SerialOpenAndHandle(ctrldev, rate, "\r\n"); err != nil {
+ if srv.control, err = SerialOpenAndHandle(conf.Servers[name].ControlDevice, conf.Servers[name].ControlBaudrate, "\r\n"); err != nil {
err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err)
return
}
- if srv.heartbeat, err = SerialOpenAndHandle(hbdev, rate, "\r\n"); err != nil {
+ if srv.heartbeat, err = SerialOpenAndHandle(conf.Servers[name].HeartbeatDevice, conf.Servers[name].HeartbeatBaudrate, "\r\n"); err != nil {
err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err)
return
}