TRX control through the modem using rigctl

This commit is contained in:
Torsten Harenberg
2025-02-26 14:58:07 +01:00
parent 89c19cf9b8
commit 29ae056488
4 changed files with 103 additions and 6 deletions

58
trxcontrol.go Normal file
View File

@@ -0,0 +1,58 @@
package main
import (
"bufio"
"fmt"
"github.com/augustoroman/hexdump"
"github.com/creack/pty"
"os"
"strconv"
"time"
)
func trxControl() {
ptypath := "/tmp/my_virtual_serial"
master, slave, err := pty.Open()
if err != nil {
writeDebug(fmt.Sprintf("trxControl: error opening PTY: %v", err), 0)
}
defer master.Close()
defer slave.Close()
err = os.Remove(ptypath)
if err := os.Symlink(slave.Name(), ptypath); err != nil {
writeDebug(fmt.Sprintf("trxControl: error creating link: %v", err), 0)
}
writeDebug(fmt.Sprintf("trxControl: opening PTY: %s\n", ptypath), 0)
// Receive from TRX
go func() {
for {
cmd, err := s.FromTRX.Dequeue(1024)
if err == nil {
master.Write(cmd)
writeDebug("From TRX response ("+strconv.Itoa(len(cmd))+"):\n"+hexdump.Dump(cmd), 1)
}
time.Sleep(30 * time.Millisecond)
}
}()
//scanner := bufio.NewScanner(master)
//for scanner.Scan() {
//t := scanner.Text()
rd := bufio.NewReader(master)
for {
time.Sleep(100 * time.Millisecond)
// looks like gpsd does not expect \n terminated lines so read what is there from the socket
master.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
buff := make([]byte, 1024)
n, err := rd.Read(buff)
t := buff[:n]
writeDebug("To TRX data ("+strconv.Itoa(len(t))+"):\n"+hexdump.Dump(t), 1)
// Send to TRX
err = s.ToTRX.Enqueue(t)
if err != nil {
writeDebug(fmt.Sprintf("trxControl: error enqueuing command: %v", err), 0)
}
}
}