added mutex to writer
This commit is contained in:
22
TCPClient.go
22
TCPClient.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -26,6 +27,7 @@ type TCPClient struct {
|
|||||||
Reader *bufio.Reader
|
Reader *bufio.Reader
|
||||||
Writer *bufio.Writer
|
Writer *bufio.Writer
|
||||||
Scanner *bufio.Scanner
|
Scanner *bufio.Scanner
|
||||||
|
Mutex sync.Mutex
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
TCPServer TCPServer
|
TCPServer TCPServer
|
||||||
MsgChan chan string
|
MsgChan chan string
|
||||||
@@ -86,8 +88,10 @@ func (c *TCPClient) StartClient() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for message := range c.TCPServer.CmdChan {
|
for message := range c.TCPServer.CmdChan {
|
||||||
|
c.Mutex.Lock()
|
||||||
Log.Infof("Received Command: %s", message)
|
Log.Infof("Received Command: %s", message)
|
||||||
c.Write([]byte(message + "\r\n"))
|
c.Write([]byte(message + "\r\n"))
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -101,40 +105,52 @@ func (c *TCPClient) Close() {
|
|||||||
|
|
||||||
func (c *TCPClient) SetFilters() {
|
func (c *TCPClient) SetFilters() {
|
||||||
if Cfg.Cluster.FT8 {
|
if Cfg.Cluster.FT8 {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/ft8\r\n"))
|
c.Write([]byte("set/ft8\r\n"))
|
||||||
Log.Info("FT8: On")
|
Log.Info("FT8: On")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if Cfg.Cluster.Skimmer {
|
if Cfg.Cluster.Skimmer {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/skimmer\r\n"))
|
c.Write([]byte("set/skimmer\r\n"))
|
||||||
Log.Info("Skimmer: On")
|
Log.Info("Skimmer: On")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if Cfg.Cluster.FT4 {
|
if Cfg.Cluster.FT4 {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/ft4\r\n"))
|
c.Write([]byte("set/ft4\r\n"))
|
||||||
Log.Info("FT4: On")
|
Log.Info("FT4: On")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Cfg.Cluster.FT8 {
|
if !Cfg.Cluster.FT8 {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/noft8\r\n"))
|
c.Write([]byte("set/noft8\r\n"))
|
||||||
Log.Info("FT8: Off")
|
Log.Info("FT8: Off")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Cfg.Cluster.FT4 {
|
if !Cfg.Cluster.FT4 {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/noft4\r\n"))
|
c.Write([]byte("set/noft4\r\n"))
|
||||||
Log.Info("FT4: Off")
|
Log.Info("FT4: Off")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Cfg.Cluster.Skimmer {
|
if !Cfg.Cluster.Skimmer {
|
||||||
|
c.Mutex.Lock()
|
||||||
c.Write([]byte("set/noskimmer\r\n"))
|
c.Write([]byte("set/noskimmer\r\n"))
|
||||||
Log.Info("Skimmer: Off")
|
Log.Info("Skimmer: Off")
|
||||||
|
c.Mutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TCPClient) ReadLine() {
|
func (c *TCPClient) ReadLine() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Need to check data with space first to find login and then use \n
|
|
||||||
if !c.LoggedIn {
|
if !c.LoggedIn {
|
||||||
message, err := c.Reader.ReadBytes(':')
|
message, err := c.Reader.ReadBytes(':')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -143,9 +159,6 @@ func (c *TCPClient) ReadLine() {
|
|||||||
c.StartClient()
|
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:") {
|
if strings.Contains(string(message), Cfg.Cluster.LoginPrompt) || strings.Contains(string(message), "login:") {
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
Log.Debug("Found login prompt...sending callsign")
|
Log.Debug("Found login prompt...sending callsign")
|
||||||
@@ -159,7 +172,6 @@ func (c *TCPClient) ReadLine() {
|
|||||||
if c.LoggedIn {
|
if c.LoggedIn {
|
||||||
message, err := c.Reader.ReadBytes('\n')
|
message, err := c.Reader.ReadBytes('\n')
|
||||||
messageString := string(message)
|
messageString := string(message)
|
||||||
// Log.Println(messageString)
|
|
||||||
|
|
||||||
if messageString != "" {
|
if messageString != "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -2,7 +2,7 @@ general:
|
|||||||
delete_log_file_at_start: true
|
delete_log_file_at_start: true
|
||||||
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
||||||
log_to_file: true
|
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
|
telnetserver: true # not in use for now
|
||||||
flexradiospot: true # not in use for now
|
flexradiospot: true # not in use for now
|
||||||
database:
|
database:
|
||||||
@@ -20,10 +20,10 @@ cluster:
|
|||||||
port: 7300
|
port: 7300
|
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"
|
||||||
login_prompt: "login:"
|
login_prompt: "login:"
|
||||||
flex:
|
flex:
|
||||||
discovery: true # Radio must be on same LAN than the program
|
discovery: true # Radio must be on same LAN than the program
|
||||||
|
@@ -320,7 +320,7 @@ func (fc *FlexClient) Write(data string) (n int, err error) {
|
|||||||
|
|
||||||
func DiscoverFlexRadio() (bool, *Discovery) {
|
func DiscoverFlexRadio() (bool, *Discovery) {
|
||||||
if Cfg.Flex.Discover {
|
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")
|
pc, err := net.ListenPacket("udp", ":4992")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
6
main.go
6
main.go
@@ -42,14 +42,14 @@ func main() {
|
|||||||
cfg := NewConfig(cfgPath)
|
cfg := NewConfig(cfgPath)
|
||||||
|
|
||||||
log := NewLog()
|
log := NewLog()
|
||||||
log.Info("Running FlexDXCluster version 0.8")
|
log.Info("Running FlexDXCluster version 0.9")
|
||||||
log.Infof("Callsign: %s", cfg.General.Callsign)
|
log.Infof("Callsign: %s", cfg.General.Callsign)
|
||||||
|
|
||||||
DeleteDatabase("./flex.sqlite", log)
|
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 {
|
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
|
// Load country.xml to get all the DXCC number
|
||||||
|
Reference in New Issue
Block a user