Skip to content

Commit

Permalink
Yaesu: Allow to connect to a rotator via TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
ea4tx authored Jan 5, 2024
1 parent 0ec01f3 commit d4fba9d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions rotator/yaesu/yaesu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bufio"
"fmt"
"io"
"net"
"regexp"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -53,7 +55,7 @@ type Yaesu struct {
// functional options.
// Default settings are:
// hasAzimuth: true,
// portname: /dev/ttyACM0,
// portname: /dev/ttyACM0 (or 127.0.0.1:6001),
// pollingInterval: 5sec,
// baudrate: 9600.
func New(opts ...func(*Yaesu)) (*Yaesu, error) {
Expand All @@ -78,23 +80,29 @@ func New(opts ...func(*Yaesu)) (*Yaesu, error) {
for _, opt := range opts {
opt(r)
}

config := &serial.Config{
Name: r.spPortName,
Baud: r.spBaudrate,
ReadTimeout: time.Millisecond * 100,
Parity: serial.ParityNone,
Size: 8,
StopBits: 1,
}

sp, err := serial.OpenPort(config)
if err != nil {
return nil, err

if strings.Contains(r.spPortName, ":") {
tcpConn, err := net.Dial("tcp", r.spPortName)
if err != nil {
return nil, err
}
r.sp = tcpConn
} else {
spConfig := &serial.Config{
Name: r.spPortName,
Baud: r.spBaudrate,
ReadTimeout: time.Second,
Parity: serial.ParityNone,
Size: 8,
StopBits: 1,
}
sp, err := serial.OpenPort(spConfig)
if err != nil {
return nil, err
}
r.sp = sp
}

r.sp = sp

go r.start()

return r, nil
Expand Down

0 comments on commit d4fba9d

Please sign in to comment.