added mutex to writer

This commit is contained in:
2025-09-07 20:49:29 +02:00
parent a7716a65c7
commit c6a765f286
4 changed files with 24 additions and 12 deletions

View File

@@ -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 {