summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-03-24 20:43:25 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-03-24 20:43:25 (GMT)
commit8b2b622690024a59538e569c25ad1d42855f89f1 (patch)
tree7158e78ab3fc28563fc7f8b0bc0dcee2d74c00b0 /src
parent2db0caf47dbc642428dc260832090af83f6a8e1c (diff)
added basic server struct
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/main.go42
-rw-r--r--src/rhctl/playout_server.go72
2 files changed, 88 insertions, 26 deletions
diff --git a/src/rhctl/main.go b/src/rhctl/main.go
index e86eeb0..2788b46 100644
--- a/src/rhctl/main.go
+++ b/src/rhctl/main.go
@@ -27,8 +27,7 @@ import (
"io/ioutil"
"log"
"os"
- "os/signal"
- "sync"
+ "time"
)
var (
@@ -72,39 +71,30 @@ func main() {
return
}
- var wg sync.WaitGroup
-
- port, err := SerialOpenAndHandle("/dev/ttyUSB0", B38400)
- if err != nil {
- rhl.Println("Error opening serial:", err)
- return
- }
- port.tx <- "hello world\n"
-
if webAddr.Get().(string) != "" {
- wg.Add(1)
go func() {
- defer wg.Done()
rhl.Println("starting web-api:", webAddr.Get().(string))
+ for {
+ time.Sleep(time.Second)
+ }
//StartWeb(webAddr.Get().(string))
rhl.Println("web-api finished")
}()
}
- alldone := make(chan bool)
- go func() {
- defer func() { alldone <- true }()
- wg.Wait()
- }()
-
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
-
- select {
- case <-c:
- rhl.Println("received interrupt, shutdown")
+ master, err := ServerInit("master", "/dev/ttyUSB0", "/dev/ttyUSB1", B38400)
+ if err != nil {
+ rhl.Println("error master server: ", err)
return
- case <-alldone:
+ }
+
+ standby, err := ServerInit("standby", "/dev/ttyUSB2", "/dev/ttyUSB3", B38400)
+ if err != nil {
+ rhl.Println("error standby server: ", err)
return
}
+
+ master.Run()
+ standby.Run()
+ time.Sleep(time.Second)
}
diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go
new file mode 100644
index 0000000..02533de
--- /dev/null
+++ b/src/rhctl/playout_server.go
@@ -0,0 +1,72 @@
+//
+// 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 (
+ "fmt"
+)
+
+type ServerHealth bool
+
+const (
+ Dead ServerHealth = false
+ Alive = true
+)
+
+type ServerChannel uint
+
+const (
+ Main ServerChannel = iota
+ Music
+)
+
+type PlayoutServer struct {
+ name string
+ control *SerialPort
+ heartbeat *SerialPort
+ health ServerHealth
+ channel ServerChannel
+}
+
+func (srv *PlayoutServer) Run() {
+ rhdl.Printf("running playout server: %s", srv.name)
+ srv.control.tx <- "hello world"
+ srv.heartbeat.tx <- "hello world"
+}
+
+func ServerInit(name string, ctrldev, hbdev string, rate Baudrate) (srv *PlayoutServer, err error) {
+ srv = &PlayoutServer{}
+ srv.name = name
+ srv.health = Dead
+ srv.channel = Music
+
+ if srv.control, err = SerialOpenAndHandle(ctrldev, rate); err != nil {
+ err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err)
+ return
+ }
+ if srv.heartbeat, err = SerialOpenAndHandle(hbdev, rate); err != nil {
+ err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err)
+ return
+ }
+
+ return
+}