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