update Mutex

This commit is contained in:
2025-09-09 20:40:58 +02:00
parent c8d85898ca
commit 55a8067be6
2 changed files with 9 additions and 19 deletions

View File

@@ -88,10 +88,8 @@ 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()
} }
}() }()
@@ -99,51 +97,38 @@ func (c *TCPClient) StartClient() {
} }
func (c *TCPClient) Close() { func (c *TCPClient) Close() {
c.Writer.WriteString("bye") c.Writer.Write([]byte("bye\r\n"))
time.Sleep(time.Second * 2)
} }
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()
} }
} }
@@ -211,12 +196,14 @@ func (c *TCPClient) ReadLine() {
} }
// Write sends raw data to remove telnet server // Write sends raw data to remove telnet server
func (tc *TCPClient) Write(data []byte) (n int, err error) { func (c *TCPClient) Write(data []byte) (n int, err error) {
n, err = tc.Writer.Write(data) Mutex.Lock()
n, err = c.Writer.Write(data)
if err != nil { if err != nil {
Log.Errorf("Error while sending command to telnet client: %s", err) Log.Errorf("Error while sending command to telnet client: %s", err)
} else { } else {
err = tc.Writer.Flush() err = c.Writer.Flush()
} }
Mutex.Unlock()
return return
} }

View File

@@ -5,8 +5,11 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"sync"
) )
var Mutex sync.Mutex
func ParseFlags() (string, error) { func ParseFlags() (string, error) {
// String that contains the configured configuration path // String that contains the configured configuration path
var configPath string var configPath string