diff --git a/README.md b/README.md index 15931a1..4291e0c 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,8 @@ use `rigctl` normally. ## GPS(d) mode -The PTC offer the possibility to attach a NMEA compatible GNSS receiver to them. To use them with Pat, the -PACTOR-TCP-bridge contains a small server which provides a [gpsd](https://gpsd.gitlab.io/gpsd/) compatible server. +The PTC offer the possibility to attach a NMEA compatible GNSS receiver to it. To use this with Pat, the +PACTOR-TCP-bridge contains a small server code which provides a [gpsd](https://gpsd.gitlab.io/gpsd/) compatible TCP socket. So your setup looks like this: diff --git a/ptc.go b/ptc.go index 7d9e69b..ac0fefa 100644 --- a/ptc.go +++ b/ptc.go @@ -7,9 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/TwiN/go-color" - "github.com/albenik/go-serial/v2" - "github.com/augustoroman/hexdump" "log" "math" "math/bits" @@ -22,6 +19,10 @@ import ( "sync" "time" + "github.com/TwiN/go-color" + "github.com/albenik/go-serial/v2" + "github.com/augustoroman/hexdump" + "github.com/howeyc/crc16" ) @@ -320,7 +321,7 @@ func (p *Modem) modemThread() { time.Sleep(time.Second) const chunkSize = 1024 p.wg.Add(1) - for !p.flags.stopmodem { + for !(p.flags.stopmodem && s.Command.Cmd.GetLen() == 0) { // TX data if p.getNumFramesNotTransmitted() < MaxFrameNotTX { @@ -358,7 +359,7 @@ func (p *Modem) modemThread() { s.Command.Response.Enqueue(ans[2:]) } } - writeDebug("Answer from modem: "+ans, 1) + writeDebug("Answer from modem: "+hex.EncodeToString([]byte(ans)), 1) // TODO: Catch errors! } @@ -914,7 +915,9 @@ func (p *Modem) read(readsize int) (int, []byte, error) { writeDebug("ERROR in ReadyToRead: "+err.Error(), 3) } else { chunkSize = int(t) - writeDebug(fmt.Sprintf("chunksize: %d", chunkSize), 3) + if chunkSize > 0 { + writeDebug(fmt.Sprintf("chunksize: %d", chunkSize), 3) + } } } else { chunkSize = readsize diff --git a/tcpserver.go b/tcpserver.go index 7df5577..1684823 100644 --- a/tcpserver.go +++ b/tcpserver.go @@ -5,12 +5,13 @@ import ( "context" "errors" "fmt" - "github.com/TwiN/go-color" "log" "net" "regexp" "strings" "time" + + "github.com/TwiN/go-color" ) // Chunks splits a string into chunks of chunkSize length @@ -41,6 +42,7 @@ func Chunks(s string, chunkSize int) []string { func handleTCPCmdConnection(conn net.Conn) { defer func() { s.Status &^= StatusTCPCmdActive + s.Command.Cmd.Enqueue("DD") // force stop all connetions if TCP connection is closing err := conn.Close() if err != nil { writeDebug(err.Error(), 0) @@ -158,7 +160,7 @@ func handleTCPDataConnection(conn net.Conn) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { - for { + for ctx.Err() == nil { msg, err := s.Data.Response.DequeueOrWaitContext(ctx, 1) if err != nil { s.Protocol <- fmt.Sprintf(color.InRed("End of TCP Data Connection %s\n"), conn.RemoteAddr()) @@ -326,8 +328,8 @@ func tcpCmdServer(Config *Userconfig) { continue } - // Handle connection in a separate goroutine - go handleTCPCmdConnection(conn) + // don't handle in goroutine as you normally would. There shouldn't be more than one connection. + handleTCPCmdConnection(conn) } } @@ -354,7 +356,7 @@ func tcpDataServer(Config *Userconfig) { continue } - // Handle connection in a separate goroutine - go handleTCPDataConnection(conn) + // don't handle in goroutine as you normally would. There shouldn't be more than one connection. + handleTCPDataConnection(conn) } }