diff --git a/HTTPServer.go b/HTTPServer.go index 5f68690..39a4734 100644 --- a/HTTPServer.go +++ b/HTTPServer.go @@ -25,28 +25,30 @@ type New struct { NewDXCC bool NewMode bool NewBand bool + Worked bool + MyCall bool } type HTTPServer struct { - router *mux.Router - Log4OMRepo Log4OMContactsRepository - Repo FlexDXClusterRepository - Log *log.Logger - FlexClient FlexClient - TCPServer TCPServer + router *mux.Router + Log4OMRepo Log4OMContactsRepository + Repo FlexDXClusterRepository + Log *log.Logger + TCPServer TCPServer + SpotChanToHTTPServer chan TelnetSpot } -func NewHTTPServer(cRepo Log4OMContactsRepository, fRepo FlexDXClusterRepository, FlexClient *FlexClient, TCPServer *TCPServer, log *log.Logger) *HTTPServer { +func NewHTTPServer(cRepo Log4OMContactsRepository, fRepo FlexDXClusterRepository, TCPServer *TCPServer, SpotChanToHTTPServer chan TelnetSpot, log *log.Logger) *HTTPServer { gRouter := mux.NewRouter() return &HTTPServer{ - router: gRouter, - Log4OMRepo: cRepo, - Repo: fRepo, - Log: log, - FlexClient: *FlexClient, - TCPServer: *TCPServer, + router: gRouter, + Log4OMRepo: cRepo, + Repo: fRepo, + Log: log, + TCPServer: *TCPServer, + SpotChanToHTTPServer: SpotChanToHTTPServer, } } @@ -63,7 +65,7 @@ func (s *HTTPServer) SetRoutes() { func (s *HTTPServer) StartHTTPServer() { go func() { - for spot := range s.FlexClient.FlexSpotChan { + for spot := range s.SpotChanToHTTPServer { s.GetListofNew(spot) } }() @@ -105,7 +107,7 @@ func (s *HTTPServer) GetNew(w http.ResponseWriter, r *http.Request) { tmpl.ExecuteTemplate(w, "new", listNew) } -func (s *HTTPServer) GetListofNew(spot FlexSpot) { +func (s *HTTPServer) GetListofNew(spot TelnetSpot) { new := New{} new.DX = spot.DX diff --git a/TCPClient.go b/TCPClient.go index d0b79d9..65df7c8 100644 --- a/TCPClient.go +++ b/TCPClient.go @@ -15,37 +15,37 @@ var spotRe *regexp.Regexp = regexp.MustCompile(`DX\sde\s([\w\d]+).*:\s+(\d+.\d)\ var count int = 0 type TCPClient struct { - Login string - Password string - Address string - Port string - Timeout time.Duration - LogWriter *bufio.Writer - Reader *bufio.Reader - Writer *bufio.Writer - Conn *net.TCPConn - TCPServer TCPServer - FlexClient FlexClient - MsgChan chan string - CmdChan chan string - SpotChan chan TelnetSpot - Log *log.Logger - Config *Config - Countries Countries + Login string + Password string + Address string + Port string + Timeout time.Duration + LogWriter *bufio.Writer + Reader *bufio.Reader + Writer *bufio.Writer + Conn *net.TCPConn + TCPServer TCPServer + MsgChan chan string + CmdChan chan string + SpotChanToFlex chan TelnetSpot + SpotChanToHTTPServer chan TelnetSpot + Log *log.Logger + Config *Config + Countries Countries } -func NewTCPClient(TCPServer *TCPServer, FlexClient *FlexClient, log *log.Logger, Countries Countries) *TCPClient { +func NewTCPClient(TCPServer *TCPServer, log *log.Logger, Countries Countries) *TCPClient { return &TCPClient{ - Address: Cfg.Cluster.Server, - Port: Cfg.Cluster.Port, - Login: Cfg.Cluster.Login, - MsgChan: TCPServer.MsgChan, - CmdChan: TCPServer.CmdChan, - SpotChan: FlexClient.SpotChan, - Log: log, - TCPServer: *TCPServer, - FlexClient: *FlexClient, - Countries: Countries, + Address: Cfg.Cluster.Server, + Port: Cfg.Cluster.Port, + Login: Cfg.Cluster.Login, + MsgChan: TCPServer.MsgChan, + CmdChan: TCPServer.CmdChan, + SpotChanToFlex: make(chan TelnetSpot, 100), + Log: log, + TCPServer: *TCPServer, + SpotChanToHTTPServer: make(chan TelnetSpot, 100), + Countries: Countries, } } @@ -151,7 +151,7 @@ func (c *TCPClient) ReadLine() { } // start := time.Now() - go ProcessTelnetSpot(spotRe, message, c.SpotChan, c.Countries) + go ProcessTelnetSpot(spotRe, message, c.SpotChanToFlex, c.SpotChanToHTTPServer, c.Countries) // elapsed := time.Since(start) // Log.Infof("Total time for processing spot: %s", elapsed) diff --git a/flexradio.go b/flexradio.go index 4ca4f53..70383a3 100644 --- a/flexradio.go +++ b/flexradio.go @@ -38,31 +38,29 @@ type FlexSpot struct { } type FlexClient struct { - Address string - Port string - Timeout time.Duration - LogWriter *bufio.Writer - Reader *bufio.Reader - Writer *bufio.Writer - Conn *net.TCPConn - SpotChan chan TelnetSpot - MsgChan chan string - FlexSpotChan chan FlexSpot - Repo FlexDXClusterRepository - TCPServer *TCPServer - IsConnected bool + Address string + Port string + Timeout time.Duration + LogWriter *bufio.Writer + Reader *bufio.Reader + Writer *bufio.Writer + Conn *net.TCPConn + SpotChanToFlex chan TelnetSpot + MsgChan chan string + Repo FlexDXClusterRepository + TCPServer *TCPServer + IsConnected bool } -func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer) *FlexClient { +func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer, SpotChanToFlex chan TelnetSpot) *FlexClient { return &FlexClient{ - Address: Cfg.Flex.IP, - Port: "4992", - SpotChan: make(chan TelnetSpot, 100), - FlexSpotChan: make(chan FlexSpot, 100), - MsgChan: TCPServer.MsgChan, - Repo: repo, - TCPServer: TCPServer, - IsConnected: false, + Address: Cfg.Flex.IP, + Port: "4992", + SpotChanToFlex: SpotChanToFlex, + MsgChan: TCPServer.MsgChan, + Repo: repo, + TCPServer: TCPServer, + IsConnected: false, } } @@ -91,7 +89,7 @@ func (fc *FlexClient) StartFlexClient() { fc.IsConnected = true go func() { - for message := range fc.SpotChan { + for message := range fc.SpotChanToFlex { fc.SendSpottoFlex(message) } }() @@ -188,11 +186,6 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) { Log.Debugf("could not find the DX in the database: ", err) } - // send FlexSpot to HTTP Server - if Cfg.General.HTTPServer { - fc.FlexSpotChan <- flexSpot - } - var stringSpot string if srcFlexSpot.DX == "" { fc.Repo.CreateSpot(flexSpot) diff --git a/main.go b/main.go index 3e44c71..ee0d8cf 100644 --- a/main.go +++ b/main.go @@ -67,15 +67,17 @@ func main() { defer cRepo.db.Close() TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port, log) - - FlexClient := NewFlexClient(*fRepo, TCPServer) - TCPClient := NewTCPClient(TCPServer, FlexClient, log, Countries) - HTTPServer := NewHTTPServer(*cRepo, *fRepo, FlexClient, TCPServer, log) + TCPClient := NewTCPClient(TCPServer, log, Countries) + FlexClient := NewFlexClient(*fRepo, TCPServer, TCPClient.SpotChanToFlex) + HTTPServer := NewHTTPServer(*cRepo, *fRepo, TCPServer, TCPClient.SpotChanToHTTPServer, log) sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) - go FlexClient.StartFlexClient() + if Cfg.General.FlexRadioSpot { + go FlexClient.StartFlexClient() + } + go TCPClient.StartClient() go TCPServer.StartServer() diff --git a/spot.go b/spot.go index 2389920..71c83d3 100644 --- a/spot.go +++ b/spot.go @@ -25,7 +25,7 @@ type TelnetSpot struct { CallsignWorked bool } -func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChan chan TelnetSpot, Countries Countries) { +func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan TelnetSpot, SpotChanToHTTPServer chan TelnetSpot, Countries Countries) { match := re.FindStringSubmatch(spotRaw) if len(match) != 0 { @@ -76,7 +76,14 @@ func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChan chan TelnetSp } // send spot to SpotChan to Flex Client to send the spot to Flex radio - SpotChan <- spot + if Cfg.General.FlexRadioSpot { + SpotChanToFlex <- spot + } + + // send FlexSpot to HTTP Server + if Cfg.General.HTTPServer { + SpotChanToHTTPServer <- spot + } if spot.NewDXCC { Log.Debugf("(** New DXCC **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - Command: %v, FlexSpot: %v", @@ -195,7 +202,7 @@ func (spot *TelnetSpot) GuessMode() { if freqInt >= 7074 && freqInt < 7078 { spot.Mode = "FT8" } - if freqInt >= 7078 && freqInt <= 7200 { + if freqInt >= 7078 && freqInt <= 7300 { spot.Mode = "LSB" } case "30M":