From 8b2b622690024a59538e569c25ad1d42855f89f1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 24 Mar 2016 21:43:25 +0100 Subject: added basic server struct 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 +// +// 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 . +// + +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 +} -- cgit v0.10.2