From fef133ba130d6d78b58ce0b42b351b06e89d6a82 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 27 Mar 2016 21:20:55 +0200 Subject: added channel to request server status updates diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go index 96e6fb7..bc31019 100644 --- a/src/rhctl/playout_server.go +++ b/src/rhctl/playout_server.go @@ -50,15 +50,16 @@ type ServerStatus struct { } type PlayoutServer struct { - name string - control *SerialPort - heartbeat *SerialPort - hbtimeout time.Duration - hbtimer *time.Timer - hbthreshold uint - hbcnt uint - status ServerStatus - Updates chan ServerStatus + name string + control *SerialPort + heartbeat *SerialPort + hbtimeout time.Duration + hbtimer *time.Timer + hbthreshold uint + hbcnt uint + status ServerStatus + Updates chan ServerStatus + UpdateRequest chan bool } func (srv *PlayoutServer) handleControl(data string) { @@ -89,6 +90,9 @@ func (srv *PlayoutServer) handleHeartbeat(data string) { if old != srv.status.Health { srv.Updates <- srv.status rhl.Printf("Server(%s): is back from the dead!", srv.name) + if srv.status.Channel == "" { + srv.control.tx <- "channel ?" + } } } @@ -117,6 +121,12 @@ func (srv *PlayoutServer) Run() { srv.handleHeartbeat(data) case <-srv.hbtimer.C: srv.handleHBTimeout() + case <-srv.UpdateRequest: + if srv.status.Health == ServerDead { + srv.Updates <- srv.status + } else { + srv.control.tx <- "channel ?" + } } } } @@ -135,12 +145,13 @@ func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) { srv.status.Health = ServerDead srv.status.Channel = "" srv.Updates = make(chan ServerStatus, 8) + srv.UpdateRequest = make(chan bool, 8) - if srv.control, err = SerialOpen(conf.Servers[name].ControlDevice, conf.Servers[name].ControlBaudrate, "\r\n"); err != nil { + 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, "\r\n"); err != nil { + 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) return } -- cgit v0.10.2