Allow setting custom baudrates on serial ports (mac and linux version)

Co-authored-by: Jan-Philipp Benecke <github@bnck.me>
This commit is contained in:
Cristian Maglie
2021-07-01 00:00:16 +02:00
parent 01c367d024
commit cff9b2347b
3 changed files with 58 additions and 20 deletions

View File

@@ -14,3 +14,18 @@ const regexFilter = "^(cu|tty)\\..*"
const ioctlTcgetattr = unix.TIOCGETA
const ioctlTcsetattr = unix.TIOCSETA
const ioctlTcflsh = unix.TIOCFLUSH
func setTermSettingsBaudrate(speed int, settings *unix.Termios) (error, bool) {
baudrate, ok := baudrateMap[speed]
if !ok {
return nil, true
}
settings.Ispeed = toTermiosSpeedType(baudrate)
settings.Ospeed = toTermiosSpeedType(baudrate)
return nil, false
}
func (port *unixPort) setSpecialBaudrate(speed uint32) error {
const kIOSSIOSPEED = 0x80045402
return unix.IoctlSetPointerInt(port.handle, kIOSSIOSPEED, int(speed))
}