Skip to content

Commit

Permalink
fix: linux baudRate and latency errors
Browse files Browse the repository at this point in the history
- linuxGetLowLatencyMode would incorrectly get an error
- linuxSetLowLatencyMode would incorrectly get an error
- linuxGetSystemBaudRate would incorrectly get an error
- linuxSetCustomBaudRate would incorrectly get an error
  • Loading branch information
reconbot committed May 26, 2021
1 parent fb53b99 commit 3340a40
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/bindings/src/serialport_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
int linuxSetCustomBaudRate(const int fd, const unsigned int baudrate) {
struct termios2 t;

if (ioctl(fd, TCGETS2, &t)) {
if (ioctl(fd, TCGETS2, &t) == -1) {
return -1;
}

t.c_cflag &= ~CBAUD;
t.c_cflag |= BOTHER;
t.c_ospeed = t.c_ispeed = baudrate;

if (ioctl(fd, TCSETS2, &t) < 0) {
if (ioctl(fd, TCSETS2, &t) == -1) {
return -2;
}

Expand All @@ -28,7 +28,7 @@ int linuxSetCustomBaudRate(const int fd, const unsigned int baudrate) {
int linuxGetSystemBaudRate(const int fd, int* const outbaud) {
struct termios2 t;

if (ioctl(fd, TCGETS2, &t)) {
if (ioctl(fd, TCGETS2, &t) == -1) {
return -1;
}

Expand All @@ -40,29 +40,31 @@ int linuxGetSystemBaudRate(const int fd, int* const outbaud) {
int linuxSetLowLatencyMode(const int fd, const bool enable) {
struct serial_struct ss;

if (ioctl(fd, TIOCGSERIAL, &ss)) {
if (ioctl(fd, TIOCGSERIAL, &ss) == -1) {
return -1;
}

if (ss.flags & ASYNC_LOW_LATENCY != enable) {

if (enable) {
ss.flags |= ASYNC_LOW_LATENCY;
} else {
ss.flags &= ~ASYNC_LOW_LATENCY;
}
if (ss.flags & ASYNC_LOW_LATENCY == enable) {
return 0;
}

if (ioctl(fd, TIOCSSERIAL, &ss) < 0) {
return -2;
}
if (enable) {
ss.flags |= ASYNC_LOW_LATENCY;
} else {
ss.flags &= ~ASYNC_LOW_LATENCY;
}

if (ioctl(fd, TIOCSSERIAL, &ss) == -1) {
return -2;
}

return 0;
}

int linuxGetLowLatencyMode(const int fd, bool* const enabled) {
struct serial_struct ss;

if (ioctl(fd, TIOCGSERIAL, &ss)) {
if (ioctl(fd, TIOCGSERIAL, &ss) == -1) {
return -1;
}

Expand Down

0 comments on commit 3340a40

Please sign in to comment.