From f067dae87d4d95fb05de64da27c2c35a68d37c2a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 22 Sep 2016 21:45:01 +0200 Subject: playout server use a single serial device now diff --git a/sample-config.toml b/sample-config.toml index 09bb5ad..5597ff2 100644 --- a/sample-config.toml +++ b/sample-config.toml @@ -1,6 +1,6 @@ [audioswitch] dev = "/dev/ttyUSB0" -baud = 19200 +baud = 38400 timeout = "500ms" unit = 0 inputs = [ { number = 1, server = "master", channel = "main" }, @@ -11,16 +11,12 @@ inputs = [ { number = 1, server = "master", channel = "main" }, [servers] [servers.master] - ctrl_dev = "/dev/ttyUSB1" - ctrl_baud = 38400 - heartbeat_dev = "/dev/ttyUSB2" - heartbeat_baud = 19200 + dev = "/dev/ttyUSB1" + baud = 38400 # [servers.standby] - # ctrl_dev = "/dev/ttyUSB3" - # ctrl_baud = 38400 - # heartbeat_dev = "/dev/ttyUSB4" - # heartbeat_baud = 19200 + # dev = "/dev/ttyUSB2" + # baud = 38400 [clients] diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go index 3cfaeac..8df11f0 100644 --- a/src/rhctl/conf.go +++ b/src/rhctl/conf.go @@ -67,10 +67,8 @@ type Config struct { } Servers map[string]struct { - ControlDevice string `toml:"ctrl_dev"` - ControlBaudrate Baudrate `toml:"ctrl_baud"` - HeartbeatDevice string `toml:"heartbeat_dev"` - HeartbeatBaudrate Baudrate `toml:"heartbeat_baud"` + Device string `toml:"dev"` + Baudrate Baudrate `toml:"baud"` HeartbeatTimeout Duration `toml:"heartbeat_timeout"` HeartbeatThreshold uint `toml:"heartbeat_threshold"` } diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go index fbcfeff..5fc1dfd 100644 --- a/src/rhctl/playout_server.go +++ b/src/rhctl/playout_server.go @@ -53,8 +53,7 @@ type ServerState struct { type PlayoutServer struct { name string - control *SerialPort - heartbeat *SerialPort + device *SerialPort hbtimeout time.Duration hbtimer *time.Timer hbthreshold uint @@ -65,9 +64,33 @@ type PlayoutServer struct { SwitchUpdates chan SwitchUpdate } -func (srv *PlayoutServer) handleControl(data string) { - rhdl.Printf("Server(%s): got control message: %q", srv.name, data) +func (srv *PlayoutServer) handleHeartbeat() { + rhdl.Printf("Server(%s): got heartbeat message", srv.name) + srv.hbtimer.Reset(srv.hbtimeout) + if (srv.hbcnt + 1) < srv.hbthreshold { + srv.hbcnt++ + return + } + old := srv.state.Health + srv.state.Health = ServerAlive + srv.state.Changed = time.Now() + if old != srv.state.Health { + srv.StateChanges <- srv.state + rhl.Printf("Server(%s): is back from the dead!", srv.name) + if srv.state.Channel == "" { + srv.device.tx <- "channel ?" + } + } +} + +func (srv *PlayoutServer) handleMessage(data string) { + rhdl.Printf("Server(%s): got message: %q", srv.name, data) + + if data == "hb" { + srv.handleHeartbeat() + return + } if strings.HasPrefix(data, "channel ") { if len(data) <= 8 { rhl.Printf("Server(%s) sent empty channel name", srv.name) @@ -86,27 +109,7 @@ func (srv *PlayoutServer) handleControl(data string) { // TODO: send command to swichctrl: &Command{Type: CmdServer, Args: data[9:], Response: nil} return } - rhl.Printf("Server(%s): ignoring unknown control message: %q", srv.name, data) -} - -func (srv *PlayoutServer) handleHeartbeat(data string) { - rhdl.Printf("Server(%s): got heartbeat message: %q", srv.name, data) - srv.hbtimer.Reset(srv.hbtimeout) - if (srv.hbcnt + 1) < srv.hbthreshold { - srv.hbcnt++ - return - } - - old := srv.state.Health - srv.state.Health = ServerAlive - srv.state.Changed = time.Now() - if old != srv.state.Health { - srv.StateChanges <- srv.state - rhl.Printf("Server(%s): is back from the dead!", srv.name) - if srv.state.Channel == "" { - srv.control.tx <- "channel ?" - } - } + rhl.Printf("Server(%s): ignoring unknown message: %q", srv.name, data) } func (srv *PlayoutServer) handleHBTimeout() { @@ -119,8 +122,7 @@ func (srv *PlayoutServer) handleHBTimeout() { func (srv *PlayoutServer) Run() { stop := make(chan bool) - srv.control.Run(stop) - srv.heartbeat.Run(stop) + srv.device.Run(stop) srv.hbtimer = time.NewTimer(srv.hbtimeout) srv.hbcnt = 0 @@ -129,20 +131,18 @@ func (srv *PlayoutServer) Run() { select { case <-stop: return - case data := <-srv.control.rx: - srv.handleControl(data) - case data := <-srv.heartbeat.rx: - srv.handleHeartbeat(data) + case data := <-srv.device.rx: + srv.handleMessage(data) case <-srv.hbtimer.C: srv.handleHBTimeout() case <-srv.UpdateRequest: if srv.state.Health == ServerDead { srv.StateChanges <- srv.state } else { - srv.control.tx <- "channel ?" + srv.device.tx <- "channel ?" } case update := <-srv.SwitchUpdates: - srv.control.tx <- update.Data + srv.device.tx <- update.Data } } } @@ -165,12 +165,8 @@ func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) { srv.UpdateRequest = make(chan bool, 8) srv.SwitchUpdates = make(chan SwitchUpdate, 32) - if srv.control, err = SerialOpen(conf.Servers[name].ControlDevice, conf.Servers[name].ControlBaudrate, "\n"); err != nil { - err = fmt.Errorf("Server(%s): error opening control port: %s", srv.name, err) - return - } - if srv.heartbeat, err = SerialOpen(conf.Servers[name].HeartbeatDevice, conf.Servers[name].HeartbeatBaudrate, "\n"); err != nil { - err = fmt.Errorf("Server(%s): error opening heartbeat port: %s", srv.name, err) + if srv.device, err = SerialOpen(conf.Servers[name].Device, conf.Servers[name].Baudrate, "\n"); err != nil { + err = fmt.Errorf("Server(%s): error opening serial port: %s", srv.name, err) return } -- cgit v0.10.2