diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dc9721b --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/ptc/modem.go b/ptc/modem.go index 8da48e7..23dc738 100755 --- a/ptc/modem.go +++ b/ptc/modem.go @@ -11,8 +11,9 @@ import ( "sync" "errors" "strings" + "io" - "github.com/tarm/serial" + "github.com/jacobsa/go-serial/serial" ) const network = "pactor" @@ -55,7 +56,7 @@ type Modem struct { state State stateOld State - device *serial.Port + device io.ReadWriteCloser mux pmux wg sync.WaitGroup flags pflags @@ -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 @@ -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 diff --git a/ptc/pactor.go b/ptc/pactor.go index b319416..aeb251f 100755 --- a/ptc/pactor.go +++ b/ptc/pactor.go @@ -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 diff --git a/ptc/vendor/github.com/jacobsa/go-serial b/ptc/vendor/github.com/jacobsa/go-serial new file mode 160000 index 0000000..15cf729 --- /dev/null +++ b/ptc/vendor/github.com/jacobsa/go-serial @@ -0,0 +1 @@ +Subproject commit 15cf729a72d49e837fa047a4142fa6e4d5ab45a1