updated README, avoid gooutinges for TCP handling, force disconnects when client is gone.

This commit is contained in:
Torsten Harenberg
2025-10-26 17:49:59 +01:00
parent 4ed3ce9b10
commit fb72775735
3 changed files with 19 additions and 14 deletions

View File

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

13
ptc.go
View File

@@ -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,8 +915,10 @@ func (p *Modem) read(readsize int) (int, []byte, error) {
writeDebug("ERROR in ReadyToRead: "+err.Error(), 3)
} else {
chunkSize = int(t)
if chunkSize > 0 {
writeDebug(fmt.Sprintf("chunksize: %d", chunkSize), 3)
}
}
} else {
chunkSize = readsize
}

View File

@@ -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)
}
}