diff --git a/TCPClient.go b/TCPClient.go index 66f180a..986ba78 100644 --- a/TCPClient.go +++ b/TCPClient.go @@ -6,6 +6,7 @@ import ( "os" "regexp" "strings" + "sync" "time" log "github.com/sirupsen/logrus" @@ -26,6 +27,7 @@ type TCPClient struct { Reader *bufio.Reader Writer *bufio.Writer Scanner *bufio.Scanner + Mutex sync.Mutex Conn net.Conn TCPServer TCPServer MsgChan chan string @@ -86,8 +88,10 @@ func (c *TCPClient) StartClient() { go func() { for message := range c.TCPServer.CmdChan { + c.Mutex.Lock() Log.Infof("Received Command: %s", message) c.Write([]byte(message + "\r\n")) + c.Mutex.Unlock() } }() @@ -101,40 +105,52 @@ func (c *TCPClient) Close() { func (c *TCPClient) SetFilters() { if Cfg.Cluster.FT8 { + c.Mutex.Lock() c.Write([]byte("set/ft8\r\n")) Log.Info("FT8: On") + c.Mutex.Unlock() } if Cfg.Cluster.Skimmer { + c.Mutex.Lock() c.Write([]byte("set/skimmer\r\n")) Log.Info("Skimmer: On") + c.Mutex.Unlock() } if Cfg.Cluster.FT4 { + c.Mutex.Lock() c.Write([]byte("set/ft4\r\n")) Log.Info("FT4: On") + c.Mutex.Unlock() } if !Cfg.Cluster.FT8 { + c.Mutex.Lock() c.Write([]byte("set/noft8\r\n")) Log.Info("FT8: Off") + c.Mutex.Unlock() } if !Cfg.Cluster.FT4 { + c.Mutex.Lock() c.Write([]byte("set/noft4\r\n")) Log.Info("FT4: Off") + c.Mutex.Unlock() } if !Cfg.Cluster.Skimmer { + c.Mutex.Lock() c.Write([]byte("set/noskimmer\r\n")) Log.Info("Skimmer: Off") + c.Mutex.Unlock() } } func (c *TCPClient) ReadLine() { for { - // Need to check data with space first to find login and then use \n + if !c.LoggedIn { message, err := c.Reader.ReadBytes(':') if err != nil { @@ -143,9 +159,6 @@ func (c *TCPClient) ReadLine() { c.StartClient() } - // message, _ = strings.CutSuffix(message, "\n") - // message, _ = strings.CutSuffix(message, "\r") - if strings.Contains(string(message), Cfg.Cluster.LoginPrompt) || strings.Contains(string(message), "login:") { time.Sleep(time.Second * 1) Log.Debug("Found login prompt...sending callsign") @@ -159,7 +172,6 @@ func (c *TCPClient) ReadLine() { if c.LoggedIn { message, err := c.Reader.ReadBytes('\n') messageString := string(message) - // Log.Println(messageString) if messageString != "" { if err != nil { diff --git a/config.yml b/config.yml index d715499..63c0c35 100644 --- a/config.yml +++ b/config.yml @@ -2,7 +2,7 @@ general: delete_log_file_at_start: true callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone log_to_file: true - log_level: INFO # INFO or DEBUG or WARN + log_level: DEBUG # INFO or DEBUG or WARN telnetserver: true # not in use for now flexradiospot: true # not in use for now database: @@ -20,10 +20,10 @@ cluster: port: 7300 login: f4bpo password: 89DGgg - skimmer: false + skimmer: true ft8: false ft4: false - command: "SET/FILTER DOC/PASS 1A,3A,4O,9A,9H,C3,CT,CU,DL,E7,EA,EA6,EI,ER,ES,EU,F,G,GD,GI,GJ,GM,GU,GW,HA,HB,HB0,HV,I,IS,IT9,JW,JX,LA,LX,LY,LZ,OE,OH,OH0,OJ0,OK,OM,ON,OY,OZ,PA,S5,SM,SP,SV,SV5,SV9,T7,TA1,TF,TK,UA,UR,YL,YO,YU,Z6,Z3,ZA,ZB" #"SET/FILTER DOC/PASS 1A,3A,4O,9A,9H,C3,CT,CU,DL,E7,EA,EA6,EI,ER,ES,EU,F,G,GD,GI,GJ,GM,GU,GW,HA,HB,HB0,HV,I,IS,IT9,JW,JX,LA,LX,LY,LZ,OE,OH,OH0,OJ0,OK,OM,ON,OY,OZ,PA,S5,SM,SP,SV,SV5,SV9,T7,TA1,TF,TK,UA,UR,YL,YO,YU,Z6,Z3,ZA,ZB" + command: "SET/FILTER DOC/PASS 1A,3A,4O,9A,9H,C3,CT,CU,DL,E7,EA,EA6,EI,ER,ES,EU,F,G,GD,GI,GJ,GM,GU,GW,HA,HB,HB0,HV,I,IS,IT9,JW,JX,LA,LX,LY,LZ,OE,OH,OH0,OJ0,OK,OM,ON,OY,OZ,PA,S5,SM,SP,SV,SV5,SV9,T7,TA1,TF,TK,UA,UR,YL,YO,YU,Z6,Z3" #"SET/FILTER DOC/PASS 1A,3A,4O,9A,9H,C3,CT,CU,DL,E7,EA,EA6,EI,ER,ES,EU,F,G,GD,GI,GJ,GM,GU,GW,HA,HB,HB0,HV,I,IS,IT9,JW,JX,LA,LX,LY,LZ,OE,OH,OH0,OJ0,OK,OM,ON,OY,OZ,PA,S5,SM,SP,SV,SV5,SV9,T7,TA1,TF,TK,UA,UR,YL,YO,YU,Z6,Z3,ZA,ZB" login_prompt: "login:" flex: discovery: true # Radio must be on same LAN than the program diff --git a/flexradio.go b/flexradio.go index 00d2ae9..7dd75d1 100644 --- a/flexradio.go +++ b/flexradio.go @@ -320,7 +320,7 @@ func (fc *FlexClient) Write(data string) (n int, err error) { func DiscoverFlexRadio() (bool, *Discovery) { if Cfg.Flex.Discover { - Log.Infoln("FlexRadio Discovery is turned on...searching for radio on the network") + Log.Debugln("FlexRadio Discovery is turned on...searching for radio on the network") pc, err := net.ListenPacket("udp", ":4992") if err != nil { diff --git a/main.go b/main.go index 4f5627b..6e6505e 100644 --- a/main.go +++ b/main.go @@ -42,14 +42,14 @@ func main() { cfg := NewConfig(cfgPath) log := NewLog() - log.Info("Running FlexDXCluster version 0.8") + log.Info("Running FlexDXCluster version 0.9") log.Infof("Callsign: %s", cfg.General.Callsign) DeleteDatabase("./flex.sqlite", log) - log.Infof("Gotify Push Enabled: %v", cfg.Gotify.Enable) + log.Debugf("Gotify Push Enabled: %v", cfg.Gotify.Enable) if cfg.Gotify.Enable { - log.Infof("Gotify Push NewDXCC: %v - NewBand: %v - NewMode: %v - NewBandAndMode: %v", cfg.Gotify.NewDXCC, cfg.Gotify.NewBand, cfg.Gotify.NewMode, cfg.Gotify.NewBandAndMode) + log.Debugf("Gotify Push NewDXCC: %v - NewBand: %v - NewMode: %v - NewBandAndMode: %v", cfg.Gotify.NewDXCC, cfg.Gotify.NewBand, cfg.Gotify.NewMode, cfg.Gotify.NewBandAndMode) } // Load country.xml to get all the DXCC number