Use unsigned values for termios setting

This allows the last (most significant) bit to be set without
overflow errors. The error becomes visible after adding the
CRTSCTS constant on linux/386:

   const tcCRTSCTS uint = 0x80000000
This commit is contained in:
Cristian Maglie
2016-10-20 23:55:06 +02:00
parent 7178181a28
commit 9398f35b69
6 changed files with 23 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ const regexFilter = "^(cu|tty)\\..*"
// termios manipulation functions // termios manipulation functions
var baudrateMap = map[int]int{ var baudrateMap = map[int]uint{
0: syscall.B9600, // Default to 9600 0: syscall.B9600, // Default to 9600
50: syscall.B50, 50: syscall.B50,
75: syscall.B75, 75: syscall.B75,
@@ -35,7 +35,7 @@ var baudrateMap = map[int]int{
230400: syscall.B230400, 230400: syscall.B230400,
} }
var databitsMap = map[int]int{ var databitsMap = map[int]uint{
0: syscall.CS8, // Default to 8 bits 0: syscall.CS8, // Default to 8 bits
5: syscall.CS5, 5: syscall.CS5,
6: syscall.CS6, 6: syscall.CS6,
@@ -43,13 +43,13 @@ var databitsMap = map[int]int{
8: syscall.CS8, 8: syscall.CS8,
} }
const tcCMSPAR int = 0 // may be CMSPAR or PAREXT const tcCMSPAR uint = 0 // may be CMSPAR or PAREXT
const tcIUCLC int = 0 const tcIUCLC uint = 0
const tcCCTS_OFLOW int = 0x00010000 const tcCCTS_OFLOW uint = 0x00010000
const tcCRTS_IFLOW int = 0x00020000 const tcCRTS_IFLOW uint = 0x00020000
const tcCRTSCTS int = (tcCCTS_OFLOW | tcCRTS_IFLOW) const tcCRTSCTS uint = (tcCCTS_OFLOW | tcCRTS_IFLOW)
// syscall wrappers // syscall wrappers

View File

@@ -6,6 +6,6 @@
package serial // import "go.bug.st/serial.v1" package serial // import "go.bug.st/serial.v1"
func termiosMask(data int) uint32 { func termiosMask(data uint) uint32 {
return uint32(data) return uint32(data)
} }

View File

@@ -8,6 +8,6 @@ package serial // import "go.bug.st/serial.v1"
// termios manipulation functions // termios manipulation functions
func termiosMask(data int) uint64 { func termiosMask(data uint) uint64 {
return uint64(data) return uint64(data)
} }

View File

@@ -13,7 +13,7 @@ const regexFilter = "^(cu|tty)\\..*"
// termios manipulation functions // termios manipulation functions
var baudrateMap = map[int]int{ var baudrateMap = map[int]uint{
0: syscall.B9600, // Default to 9600 0: syscall.B9600, // Default to 9600
50: syscall.B50, 50: syscall.B50,
75: syscall.B75, 75: syscall.B75,
@@ -37,7 +37,7 @@ var baudrateMap = map[int]int{
921600: syscall.B921600, 921600: syscall.B921600,
} }
var databitsMap = map[int]int{ var databitsMap = map[int]uint{
0: syscall.CS8, // Default to 8 bits 0: syscall.CS8, // Default to 8 bits
5: syscall.CS5, 5: syscall.CS5,
6: syscall.CS6, 6: syscall.CS6,
@@ -45,15 +45,15 @@ var databitsMap = map[int]int{
8: syscall.CS8, 8: syscall.CS8,
} }
const tcCMSPAR int = 0 // may be CMSPAR or PAREXT const tcCMSPAR uint = 0 // may be CMSPAR or PAREXT
const tcIUCLC int = 0 const tcIUCLC uint = 0
const tcCCTS_OFLOW int = 0x00010000 const tcCCTS_OFLOW uint = 0x00010000
const tcCRTS_IFLOW int = 0x00020000 const tcCRTS_IFLOW uint = 0x00020000
const tcCRTSCTS int = tcCCTS_OFLOW const tcCRTSCTS uint = tcCCTS_OFLOW
func termiosMask(data int) uint32 { func termiosMask(data uint) uint32 {
return uint32(data) return uint32(data)
} }

View File

@@ -13,7 +13,7 @@ const regexFilter = "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO)[0-9]{1,3}"
// termios manipulation functions // termios manipulation functions
var baudrateMap = map[int]int{ var baudrateMap = map[int]uint{
0: syscall.B9600, // Default to 9600 0: syscall.B9600, // Default to 9600
50: syscall.B50, 50: syscall.B50,
75: syscall.B75, 75: syscall.B75,
@@ -47,7 +47,7 @@ var baudrateMap = map[int]int{
4000000: syscall.B4000000, 4000000: syscall.B4000000,
} }
var databitsMap = map[int]int{ var databitsMap = map[int]uint{
0: syscall.CS8, // Default to 8 bits 0: syscall.CS8, // Default to 8 bits
5: syscall.CS5, 5: syscall.CS5,
6: syscall.CS6, 6: syscall.CS6,
@@ -55,12 +55,12 @@ var databitsMap = map[int]int{
8: syscall.CS8, 8: syscall.CS8,
} }
const tcCMSPAR int = 0 // may be CMSPAR or PAREXT const tcCMSPAR uint = 0 // may be CMSPAR or PAREXT
const tcIUCLC = syscall.IUCLC const tcIUCLC = syscall.IUCLC
const tcCRTSCTS int = 0x80000000 const tcCRTSCTS uint = 0x80000000
func termiosMask(data int) uint32 { func termiosMask(data uint) uint32 {
return uint32(data) return uint32(data)
} }

View File

@@ -143,7 +143,7 @@ func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error {
return &PortError{code: InvalidSpeed} return &PortError{code: InvalidSpeed}
} }
// revert old baudrate // revert old baudrate
BAUDMASK := 0 var BAUDMASK uint
for _, rate := range baudrateMap { for _, rate := range baudrateMap {
BAUDMASK |= rate BAUDMASK |= rate
} }