diff options
-rw-r--r-- | src/rhctl/audio_switch.go | 46 | ||||
-rw-r--r-- | src/rhctl/main.go | 11 | ||||
-rw-r--r-- | src/rhctl/playout_server.go | 15 | ||||
-rw-r--r-- | src/rhctl/serial_port.go | 16 |
4 files changed, 66 insertions, 22 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go new file mode 100644 index 0000000..8202e60 --- /dev/null +++ b/src/rhctl/audio_switch.go @@ -0,0 +1,46 @@ +// +// 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 AudioSwitch struct { + port *SerialPort +} + +func (sw *AudioSwitch) Run() { + rhdl.Printf("running audio switch") + sw.port.tx <- "hello switch" +} + +func SwitchInit(dev string, rate Baudrate) (sw *AudioSwitch, err error) { + sw = &AudioSwitch{} + + if sw.port, err = SerialOpenAndHandle(dev, rate); err != nil { + err = fmt.Errorf("Error opening switch port: %s", err) + return + } + + return +} diff --git a/src/rhctl/main.go b/src/rhctl/main.go index 2788b46..f6742d8 100644 --- a/src/rhctl/main.go +++ b/src/rhctl/main.go @@ -82,18 +82,25 @@ func main() { }() } - master, err := ServerInit("master", "/dev/ttyUSB0", "/dev/ttyUSB1", B38400) + 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/ttyUSB2", "/dev/ttyUSB3", B38400) + 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) diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go index 02533de..c3cfcf1 100644 --- a/src/rhctl/playout_server.go +++ b/src/rhctl/playout_server.go @@ -32,32 +32,25 @@ const ( Alive = true ) -type ServerChannel uint - -const ( - Main ServerChannel = iota - Music -) - type PlayoutServer struct { name string control *SerialPort heartbeat *SerialPort health ServerHealth - channel ServerChannel + channel string } func (srv *PlayoutServer) Run() { rhdl.Printf("running playout server: %s", srv.name) - srv.control.tx <- "hello world" - srv.heartbeat.tx <- "hello world" + srv.control.tx <- fmt.Sprintf("hello %s", srv.name) + srv.heartbeat.tx <- fmt.Sprintf("beat %s", srv.name) } func ServerInit(name string, ctrldev, hbdev string, rate Baudrate) (srv *PlayoutServer, err error) { srv = &PlayoutServer{} srv.name = name srv.health = Dead - srv.channel = Music + srv.channel = "music" if srv.control, err = SerialOpenAndHandle(ctrldev, rate); err != nil { err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err) diff --git a/src/rhctl/serial_port.go b/src/rhctl/serial_port.go index d805bdc..e8bfd92 100644 --- a/src/rhctl/serial_port.go +++ b/src/rhctl/serial_port.go @@ -41,15 +41,13 @@ const ( B115200 = syscall.B115200 ) -type SerialLine string - type SerialPort struct { port *sio.Port - rx <-chan SerialLine - tx chan<- SerialLine + rx <-chan string + tx chan<- string } -func SerialRead(c chan<- SerialLine, port *sio.Port) { +func SerialRead(c chan<- string, port *sio.Port) { scanner := bufio.NewScanner(port) scanner.Split(bufio.ScanLines) for scanner.Scan() { @@ -60,11 +58,11 @@ func SerialRead(c chan<- SerialLine, port *sio.Port) { if len(data) == 0 { continue } - c <- SerialLine(data) + c <- string(data) } } -func SerialWrite(c <-chan SerialLine, port *sio.Port) { +func SerialWrite(c <-chan string, port *sio.Port) { for data := range c { port.Write([]byte(data)) } @@ -76,8 +74,8 @@ func SerialOpenAndHandle(device string, speed Baudrate) (port *SerialPort, err e if port.port, err = sio.Open(device, uint32(speed)); err != nil { return } - tx := make(chan SerialLine, 1) - rx := make(chan SerialLine, 20) + tx := make(chan string, 1) + rx := make(chan string, 20) go SerialRead(rx, port.port) go SerialWrite(tx, port.port) |