This commit is contained in:
Gregory Salaun 2024-10-24 01:16:25 +07:00
parent 40a6b71865
commit 6bef3f45cd
5 changed files with 84 additions and 80 deletions

View File

@ -25,28 +25,30 @@ type New struct {
NewDXCC bool NewDXCC bool
NewMode bool NewMode bool
NewBand bool NewBand bool
Worked bool
MyCall bool
} }
type HTTPServer struct { type HTTPServer struct {
router *mux.Router router *mux.Router
Log4OMRepo Log4OMContactsRepository Log4OMRepo Log4OMContactsRepository
Repo FlexDXClusterRepository Repo FlexDXClusterRepository
Log *log.Logger Log *log.Logger
FlexClient FlexClient TCPServer TCPServer
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() gRouter := mux.NewRouter()
return &HTTPServer{ return &HTTPServer{
router: gRouter, router: gRouter,
Log4OMRepo: cRepo, Log4OMRepo: cRepo,
Repo: fRepo, Repo: fRepo,
Log: log, Log: log,
FlexClient: *FlexClient, TCPServer: *TCPServer,
TCPServer: *TCPServer, SpotChanToHTTPServer: SpotChanToHTTPServer,
} }
} }
@ -63,7 +65,7 @@ func (s *HTTPServer) SetRoutes() {
func (s *HTTPServer) StartHTTPServer() { func (s *HTTPServer) StartHTTPServer() {
go func() { go func() {
for spot := range s.FlexClient.FlexSpotChan { for spot := range s.SpotChanToHTTPServer {
s.GetListofNew(spot) s.GetListofNew(spot)
} }
}() }()
@ -105,7 +107,7 @@ func (s *HTTPServer) GetNew(w http.ResponseWriter, r *http.Request) {
tmpl.ExecuteTemplate(w, "new", listNew) tmpl.ExecuteTemplate(w, "new", listNew)
} }
func (s *HTTPServer) GetListofNew(spot FlexSpot) { func (s *HTTPServer) GetListofNew(spot TelnetSpot) {
new := New{} new := New{}
new.DX = spot.DX new.DX = spot.DX

View File

@ -15,37 +15,37 @@ var spotRe *regexp.Regexp = regexp.MustCompile(`DX\sde\s([\w\d]+).*:\s+(\d+.\d)\
var count int = 0 var count int = 0
type TCPClient struct { type TCPClient struct {
Login string Login string
Password string Password string
Address string Address string
Port string Port string
Timeout time.Duration Timeout time.Duration
LogWriter *bufio.Writer LogWriter *bufio.Writer
Reader *bufio.Reader Reader *bufio.Reader
Writer *bufio.Writer Writer *bufio.Writer
Conn *net.TCPConn Conn *net.TCPConn
TCPServer TCPServer TCPServer TCPServer
FlexClient FlexClient MsgChan chan string
MsgChan chan string CmdChan chan string
CmdChan chan string SpotChanToFlex chan TelnetSpot
SpotChan chan TelnetSpot SpotChanToHTTPServer chan TelnetSpot
Log *log.Logger Log *log.Logger
Config *Config Config *Config
Countries Countries 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{ return &TCPClient{
Address: Cfg.Cluster.Server, Address: Cfg.Cluster.Server,
Port: Cfg.Cluster.Port, Port: Cfg.Cluster.Port,
Login: Cfg.Cluster.Login, Login: Cfg.Cluster.Login,
MsgChan: TCPServer.MsgChan, MsgChan: TCPServer.MsgChan,
CmdChan: TCPServer.CmdChan, CmdChan: TCPServer.CmdChan,
SpotChan: FlexClient.SpotChan, SpotChanToFlex: make(chan TelnetSpot, 100),
Log: log, Log: log,
TCPServer: *TCPServer, TCPServer: *TCPServer,
FlexClient: *FlexClient, SpotChanToHTTPServer: make(chan TelnetSpot, 100),
Countries: Countries, Countries: Countries,
} }
} }
@ -151,7 +151,7 @@ func (c *TCPClient) ReadLine() {
} }
// start := time.Now() // 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) // elapsed := time.Since(start)
// Log.Infof("Total time for processing spot: %s", elapsed) // Log.Infof("Total time for processing spot: %s", elapsed)

View File

@ -38,31 +38,29 @@ type FlexSpot struct {
} }
type FlexClient struct { type FlexClient struct {
Address string Address string
Port string Port string
Timeout time.Duration Timeout time.Duration
LogWriter *bufio.Writer LogWriter *bufio.Writer
Reader *bufio.Reader Reader *bufio.Reader
Writer *bufio.Writer Writer *bufio.Writer
Conn *net.TCPConn Conn *net.TCPConn
SpotChan chan TelnetSpot SpotChanToFlex chan TelnetSpot
MsgChan chan string MsgChan chan string
FlexSpotChan chan FlexSpot Repo FlexDXClusterRepository
Repo FlexDXClusterRepository TCPServer *TCPServer
TCPServer *TCPServer IsConnected bool
IsConnected bool
} }
func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer) *FlexClient { func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer, SpotChanToFlex chan TelnetSpot) *FlexClient {
return &FlexClient{ return &FlexClient{
Address: Cfg.Flex.IP, Address: Cfg.Flex.IP,
Port: "4992", Port: "4992",
SpotChan: make(chan TelnetSpot, 100), SpotChanToFlex: SpotChanToFlex,
FlexSpotChan: make(chan FlexSpot, 100), MsgChan: TCPServer.MsgChan,
MsgChan: TCPServer.MsgChan, Repo: repo,
Repo: repo, TCPServer: TCPServer,
TCPServer: TCPServer, IsConnected: false,
IsConnected: false,
} }
} }
@ -91,7 +89,7 @@ func (fc *FlexClient) StartFlexClient() {
fc.IsConnected = true fc.IsConnected = true
go func() { go func() {
for message := range fc.SpotChan { for message := range fc.SpotChanToFlex {
fc.SendSpottoFlex(message) fc.SendSpottoFlex(message)
} }
}() }()
@ -188,11 +186,6 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
Log.Debugf("could not find the DX in the database: ", err) 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 var stringSpot string
if srcFlexSpot.DX == "" { if srcFlexSpot.DX == "" {
fc.Repo.CreateSpot(flexSpot) fc.Repo.CreateSpot(flexSpot)

12
main.go
View File

@ -67,15 +67,17 @@ func main() {
defer cRepo.db.Close() defer cRepo.db.Close()
TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port, log) TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port, log)
TCPClient := NewTCPClient(TCPServer, log, Countries)
FlexClient := NewFlexClient(*fRepo, TCPServer) FlexClient := NewFlexClient(*fRepo, TCPServer, TCPClient.SpotChanToFlex)
TCPClient := NewTCPClient(TCPServer, FlexClient, log, Countries) HTTPServer := NewHTTPServer(*cRepo, *fRepo, TCPServer, TCPClient.SpotChanToHTTPServer, log)
HTTPServer := NewHTTPServer(*cRepo, *fRepo, FlexClient, TCPServer, log)
sigCh := make(chan os.Signal, 1) sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) 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 TCPClient.StartClient()
go TCPServer.StartServer() go TCPServer.StartServer()

13
spot.go
View File

@ -25,7 +25,7 @@ type TelnetSpot struct {
CallsignWorked bool 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) match := re.FindStringSubmatch(spotRaw)
if len(match) != 0 { 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 // 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 { 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", 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 { if freqInt >= 7074 && freqInt < 7078 {
spot.Mode = "FT8" spot.Mode = "FT8"
} }
if freqInt >= 7078 && freqInt <= 7200 { if freqInt >= 7078 && freqInt <= 7300 {
spot.Mode = "LSB" spot.Mode = "LSB"
} }
case "30M": case "30M":