diff --git a/.travis.yml b/.travis.yml index 270c7e5..e962e65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,9 @@ env: - TEST_OS=darwin TEST_ARCH=amd64 - TEST_OS=freebsd TEST_ARCH=amd64 - TEST_OS=dragonfly TEST_ARCH=amd64 + - TEST_OS=openbsd TEST_ARCH=amd64 + - TEST_OS=openbsd TEST_ARCH=386 + - TEST_OS=openbsd TEST_ARCH=arm matrix: allow_failures: diff --git a/serial_darwin_386.go b/serial_darwin_386.go index 4200f26..9b9e7fd 100644 --- a/serial_darwin_386.go +++ b/serial_darwin_386.go @@ -47,3 +47,7 @@ const tcCCTS_OFLOW uint32 = 0x00010000 const tcCRTS_IFLOW uint32 = 0x00020000 const tcCRTSCTS uint32 = (tcCCTS_OFLOW | tcCRTS_IFLOW) + +func toTermiosSpeedType(speed uint32) uint32 { + return speed +} diff --git a/serial_darwin_amd64.go b/serial_darwin_amd64.go index d7109c0..b0b155d 100644 --- a/serial_darwin_amd64.go +++ b/serial_darwin_amd64.go @@ -47,3 +47,7 @@ const tcCCTS_OFLOW uint64 = 0x00010000 const tcCRTS_IFLOW uint64 = 0x00020000 const tcCRTSCTS uint64 = (tcCCTS_OFLOW | tcCRTS_IFLOW) + +func toTermiosSpeedType(speed uint64) uint64 { + return speed +} diff --git a/serial_freebsd.go b/serial_freebsd.go index a7fde38..4083cd6 100644 --- a/serial_freebsd.go +++ b/serial_freebsd.go @@ -56,3 +56,7 @@ const tcCRTSCTS uint32 = tcCCTS_OFLOW const ioctlTcgetattr = unix.TIOCGETA const ioctlTcsetattr = unix.TIOCSETA const ioctlTcflsh = unix.TIOCFLUSH + +func toTermiosSpeedType(speed uint32) uint32 { + return speed +} diff --git a/serial_linux.go b/serial_linux.go index c8f5927..e49a847 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -63,3 +63,7 @@ const tcCRTSCTS uint32 = unix.CRTSCTS const ioctlTcgetattr = unix.TCGETS const ioctlTcsetattr = unix.TCSETS const ioctlTcflsh = unix.TCFLSH + +func toTermiosSpeedType(speed uint32) uint32 { + return speed +} diff --git a/serial_openbsd.go b/serial_openbsd.go new file mode 100644 index 0000000..f163529 --- /dev/null +++ b/serial_openbsd.go @@ -0,0 +1,62 @@ +// +// Copyright 2014-2017 Cristian Maglie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// + +package serial // import "go.bug.st/serial.v1" + +import "golang.org/x/sys/unix" + +const devFolder = "/dev" +const regexFilter = "^(cu|tty)\\..*" + +// termios manipulation functions + +var baudrateMap = map[int]uint32{ + 0: unix.B9600, // Default to 9600 + 50: unix.B50, + 75: unix.B75, + 110: unix.B110, + 134: unix.B134, + 150: unix.B150, + 200: unix.B200, + 300: unix.B300, + 600: unix.B600, + 1200: unix.B1200, + 1800: unix.B1800, + 2400: unix.B2400, + 4800: unix.B4800, + 9600: unix.B9600, + 19200: unix.B19200, + 38400: unix.B38400, + 57600: unix.B57600, + 115200: unix.B115200, + 230400: unix.B230400, + //460800: unix.B460800, + //921600: unix.B921600, +} + +var databitsMap = map[int]uint32{ + 0: unix.CS8, // Default to 8 bits + 5: unix.CS5, + 6: unix.CS6, + 7: unix.CS7, + 8: unix.CS8, +} + +const tcCMSPAR uint32 = 0 // may be CMSPAR or PAREXT +const tcIUCLC uint32 = 0 + +const tcCCTS_OFLOW uint32 = 0x00010000 +const tcCRTS_IFLOW uint32 = 0x00020000 + +const tcCRTSCTS uint32 = tcCCTS_OFLOW + +const ioctlTcgetattr = unix.TIOCGETA +const ioctlTcsetattr = unix.TIOCSETA +const ioctlTcflsh = unix.TIOCFLUSH + +func toTermiosSpeedType(speed uint32) int32 { + return int32(speed) +} diff --git a/serial_unix.go b/serial_unix.go index 69bbceb..1cf690f 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file. // -// +build linux darwin freebsd +// +build linux darwin freebsd openbsd package serial // import "go.bug.st/serial.v1" @@ -252,8 +252,8 @@ func setTermSettingsBaudrate(speed int, settings *unix.Termios) error { } // set new baudrate settings.Cflag |= baudrate - settings.Ispeed = baudrate - settings.Ospeed = baudrate + settings.Ispeed = toTermiosSpeedType(baudrate) + settings.Ospeed = toTermiosSpeedType(baudrate) return nil } diff --git a/syscall_openbsd.go b/syscall_openbsd.go new file mode 100644 index 0000000..670a257 --- /dev/null +++ b/syscall_openbsd.go @@ -0,0 +1,9 @@ +// +// Copyright 2014-2017 Cristian Maglie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// + +package serial // import "go.bug.st/serial.v1" + +//sys ioctl(fd int, req uint64, data uintptr) (err error) diff --git a/unixutils/pipe.go b/unixutils/pipe.go index 941b6eb..93f3486 100644 --- a/unixutils/pipe.go +++ b/unixutils/pipe.go @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file. // -// +build linux darwin freebsd +// +build linux darwin freebsd openbsd package unixutils // import "go.bug.st/serial.v1/unixutils" diff --git a/unixutils/select.go b/unixutils/select.go index 7ad60a8..0bd1d9a 100644 --- a/unixutils/select.go +++ b/unixutils/select.go @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file. // -// +build linux darwin freebsd +// +build linux darwin freebsd openbsd package unixutils // "go.bug.st/serial.v1/unixutils" diff --git a/zsyscall_openbsd.go b/zsyscall_openbsd.go new file mode 100644 index 0000000..3d8cee4 --- /dev/null +++ b/zsyscall_openbsd.go @@ -0,0 +1,21 @@ +// +// Copyright 2014-2017 Cristian Maglie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// + +// This file is machine generated by the command: +// mksyscall.pl serial_openbsd.go +// The generated stub is modified to make it compile under the "serial" package + +package serial // import "go.bug.st/serial.v1" + +import "syscall" + +func ioctl(fd int, req uint64, data uintptr) (err error) { + _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data)) + if e1 != 0 { + err = e1 + } + return +}