Skip to content

Commit

Permalink
Support custom baud rate
Browse files Browse the repository at this point in the history
In order to support P4 Dragon (DR-7x00) modem, this driver must support custom baud rates (see #3). Furthermore it should be independant of C (cgo).
Therefore github.com/tarm/serial has been replaced with github.com/jacobsa/go-serial.

Closing #24
  • Loading branch information
blockmurder committed Oct 6, 2019
1 parent ce311fe commit f9d8e4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ptc/vendor/github.com/jacobsa/go-serial"]
path = ptc/vendor/github.com/jacobsa/go-serial
url = https://github.com/jacobsa/go-serial.git
25 changes: 18 additions & 7 deletions ptc/modem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"sync"
"errors"
"strings"
"io"

"github.com/tarm/serial"
"github.com/jacobsa/go-serial/serial"
)

const network = "pactor"
Expand Down Expand Up @@ -55,7 +56,7 @@ type Modem struct {
state State
stateOld State

device *serial.Port
device io.ReadWriteCloser
mux pmux
wg sync.WaitGroup
flags pflags
Expand Down Expand Up @@ -83,7 +84,7 @@ func (p *Modem) LocalAddr() net.Addr { return Addr{p.localAddr} }
//
// Will abort if modem reports failed link setup, Close() is called or timeout
// has occured (90 seconds)
func OpenModem(path string, baudRate int, myCall string, initScript string) (p *Modem, err error) {
func OpenModem(path string, baudRate uint, myCall string, initScript string) (p *Modem, err error) {

p = &Modem {
// Initialise variables
Expand Down Expand Up @@ -117,14 +118,24 @@ func OpenModem(path string, baudRate int, myCall string, initScript string) (p *
}

//Setup serial device
c := &serial.Config{Name: p.devicePath, Baud: baudRate, ReadTimeout: time.Second * SerialTimeout}
if p.device, err = serial.OpenPort(c); err != nil {
options := serial.OpenOptions{
PortName: p.devicePath,
BaudRate: baudRate,
DataBits: 8,
StopBits: 1,
ParityMode: serial.PARITY_NONE,
RTSCTSFlowControl: false,
MinimumReadSize: 0,
InterCharacterTimeout: SerialTimeout,

Rs485Enable: false,
}

if p.device, err = serial.Open(options); err != nil {
writeDebug(err.Error(), 1)
return nil, err
}

p.device.Flush()

p.hostmodeQuit() // throws error if not in hostmode (e.g. from previous connection)
if _, _, err = p.writeAndGetResponse("", -1, false, 10240); err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions ptc/pactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"sync"
)

// SerialTimeout: Timeout for read operations on serial bus
// SerialTimeout: Timeout (ms) for read operations on serial bus
// PactorChannel: Pactor channel, 31 should work for both, PTC-IIex and P4 Dragon
// MaxSendData: Pactor internal command buffer is 256 byte
// MaxFrameNotTX: Max. number of frames not transmitted at time.
// MaxFrameNotTX: Max. number of frames not transmitted at time.
const (
SerialTimeout = 1
SerialTimeout = 1000
PactorChannel = 31
MaxSendData = 256
MaxFrameNotTX = 2
Expand Down
1 change: 1 addition & 0 deletions ptc/vendor/github.com/jacobsa/go-serial
Submodule go-serial added at 15cf72

0 comments on commit f9d8e4d

Please sign in to comment.