From d85bbb17765c5101038bc20c7c6cda46cfe8479b Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Mon, 25 Mar 2024 12:58:10 -0400 Subject: [PATCH 1/6] Added some overrides for FreeBSD --- serial_darwin.go | 3 +++ serial_freebsd.go | 11 +++-------- serial_linux.go | 3 +++ serial_unix.go | 2 ++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/serial_darwin.go b/serial_darwin.go index a87458e..5871598 100644 --- a/serial_darwin.go +++ b/serial_darwin.go @@ -22,6 +22,9 @@ const ioctlTcflsh = unix.TIOCFLUSH const ioctlTioccbrk = unix.TIOCCBRK const ioctlTiocsbrk = unix.TIOCSBRK +const tcSetOflags uint64 = 0 +const tcClearOflags uint64 = 0 + func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) { baudrate, ok := baudrateMap[speed] if !ok { diff --git a/serial_freebsd.go b/serial_freebsd.go index 775b7a6..033d6ad 100644 --- a/serial_freebsd.go +++ b/serial_freebsd.go @@ -58,6 +58,9 @@ const tcCRTS_IFLOW uint32 = 0x00020000 const tcCRTSCTS uint32 = tcCCTS_OFLOW +const tcSetOflags uint32 = 0 +const tcClearOflags uint32 = unix.OPOST + const ioctlTcgetattr = unix.TIOCGETA const ioctlTcsetattr = unix.TIOCSETA const ioctlTcflsh = unix.TIOCFLUSH @@ -73,14 +76,6 @@ func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) { if !ok { return nil, true } - // XXX: Is Cflag really needed - // revert old baudrate - for _, rate := range baudrateMap { - settings.Cflag &^= rate - } - // set new baudrate - settings.Cflag |= baudrate - settings.Ispeed = toTermiosSpeedType(baudrate) settings.Ospeed = toTermiosSpeedType(baudrate) return nil, false diff --git a/serial_linux.go b/serial_linux.go index a1218bb..fc51233 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -63,6 +63,9 @@ var databitsMap = map[int]uint32{ const tcCMSPAR = unix.CMSPAR const tcIUCLC = unix.IUCLC +const tcSetOflags uint32 = 0 +const tcClearOflags uint32 = 0 + const tcCRTSCTS uint32 = unix.CRTSCTS const ioctlTcgetattr = unix.TCGETS diff --git a/serial_unix.go b/serial_unix.go index 54e55a8..ecc0d55 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -434,6 +434,8 @@ func setRawMode(settings *unix.Termios) { settings.Iflag &^= tcIUCLC settings.Oflag &^= unix.OPOST + settings.Oflag &^= tcClearOflags // Needed to clear platform specific flags + settings.Oflag |= tcSetOflags // Needed to set platform specific flags // Block reads until at least one char is available (no timeout) settings.Cc[unix.VMIN] = 1 From e2740259eb4b9b3f09526eb713106acaf77d2b3d Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Mon, 25 Mar 2024 13:07:29 -0400 Subject: [PATCH 2/6] Reversed the FreeBSD OP flags --- serial_freebsd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serial_freebsd.go b/serial_freebsd.go index 033d6ad..28f3dcb 100644 --- a/serial_freebsd.go +++ b/serial_freebsd.go @@ -58,8 +58,8 @@ const tcCRTS_IFLOW uint32 = 0x00020000 const tcCRTSCTS uint32 = tcCCTS_OFLOW -const tcSetOflags uint32 = 0 -const tcClearOflags uint32 = unix.OPOST +const tcSetOflags uint32 = unix.OPOST +const tcClearOflags uint32 = 0 const ioctlTcgetattr = unix.TIOCGETA const ioctlTcsetattr = unix.TIOCSETA From b0e04c539ea1e2c68706c49099720d19930be3ae Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Mon, 25 Mar 2024 13:46:47 -0400 Subject: [PATCH 3/6] Changed go.mod to reflect forked package name --- go.mod | 3 ++- go.sum | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 61d0d6d..035f569 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ -module go.bug.st/serial +module github.com/timstpierre-tc/go-serial go 1.17 require ( github.com/creack/goselect v0.1.2 github.com/stretchr/testify v1.8.4 + go.bug.st/serial v1.6.2 golang.org/x/sys v0.17.0 ) diff --git a/go.sum b/go.sum index 43d4dac..ce9c899 100644 --- a/go.sum +++ b/go.sum @@ -8,10 +8,14 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +go.bug.st/serial v1.6.2 h1:kn9LRX3sdm+WxWKufMlIRndwGfPWsH1/9lCWXQCasq8= +go.bug.st/serial v1.6.2/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= +golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= From ff11df7f1205838dc56cd0100e067e314924fb81 Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Mon, 25 Mar 2024 13:49:49 -0400 Subject: [PATCH 4/6] Fixing go.mod --- go.mod | 8 ++++---- go.sum | 17 ++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 035f569..962aa4d 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ -module github.com/timstpierre-tc/go-serial +module github.com/tstpierre-tc/go-serial -go 1.17 +go 1.21.6 require ( github.com/creack/goselect v0.1.2 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 go.bug.st/serial v1.6.2 - golang.org/x/sys v0.17.0 + golang.org/x/sys v0.18.0 ) require ( diff --git a/go.sum b/go.sum index ce9c899..5e72173 100644 --- a/go.sum +++ b/go.sum @@ -1,25 +1,16 @@ github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.bug.st/serial v1.6.2 h1:kn9LRX3sdm+WxWKufMlIRndwGfPWsH1/9lCWXQCasq8= go.bug.st/serial v1.6.2/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 58092333f859f47aa9fedaf95b06d7f1455496f3 Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Mon, 25 Mar 2024 13:56:45 -0400 Subject: [PATCH 5/6] Wrong repo in go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 962aa4d..d7a4d44 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tstpierre-tc/go-serial +module github.com/timstpierre-tc/go-serial go 1.21.6 From 8cb68b6fa762c23fcd4d70d101bec4c23a40e82e Mon Sep 17 00:00:00 2001 From: "Tim St. Pierre" Date: Tue, 26 Mar 2024 11:48:56 -0400 Subject: [PATCH 6/6] Putting back un-necessary changes to tty modes --- serial_darwin.go | 3 --- serial_freebsd.go | 3 --- serial_linux.go | 3 --- serial_unix.go | 2 -- 4 files changed, 11 deletions(-) diff --git a/serial_darwin.go b/serial_darwin.go index 5871598..a87458e 100644 --- a/serial_darwin.go +++ b/serial_darwin.go @@ -22,9 +22,6 @@ const ioctlTcflsh = unix.TIOCFLUSH const ioctlTioccbrk = unix.TIOCCBRK const ioctlTiocsbrk = unix.TIOCSBRK -const tcSetOflags uint64 = 0 -const tcClearOflags uint64 = 0 - func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) { baudrate, ok := baudrateMap[speed] if !ok { diff --git a/serial_freebsd.go b/serial_freebsd.go index 28f3dcb..5c66c69 100644 --- a/serial_freebsd.go +++ b/serial_freebsd.go @@ -58,9 +58,6 @@ const tcCRTS_IFLOW uint32 = 0x00020000 const tcCRTSCTS uint32 = tcCCTS_OFLOW -const tcSetOflags uint32 = unix.OPOST -const tcClearOflags uint32 = 0 - const ioctlTcgetattr = unix.TIOCGETA const ioctlTcsetattr = unix.TIOCSETA const ioctlTcflsh = unix.TIOCFLUSH diff --git a/serial_linux.go b/serial_linux.go index fc51233..a1218bb 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -63,9 +63,6 @@ var databitsMap = map[int]uint32{ const tcCMSPAR = unix.CMSPAR const tcIUCLC = unix.IUCLC -const tcSetOflags uint32 = 0 -const tcClearOflags uint32 = 0 - const tcCRTSCTS uint32 = unix.CRTSCTS const ioctlTcgetattr = unix.TCGETS diff --git a/serial_unix.go b/serial_unix.go index ecc0d55..54e55a8 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -434,8 +434,6 @@ func setRawMode(settings *unix.Termios) { settings.Iflag &^= tcIUCLC settings.Oflag &^= unix.OPOST - settings.Oflag &^= tcClearOflags // Needed to clear platform specific flags - settings.Oflag |= tcSetOflags // Needed to set platform specific flags // Block reads until at least one char is available (no timeout) settings.Cc[unix.VMIN] = 1