]> git.tdb.fi Git - libs/core.git/commitdiff
Use direct constant values for non-POSIX baud rates
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 10:48:57 +0000 (13:48 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Oct 2014 10:48:57 +0000 (13:48 +0300)
Not all systems (particularly older ones) have #defines for the extended
baud rates, and the standard doesn't provide anything to check their
existence either.

source/io/unix/serial.cpp

index 2be5dc589f6efe57c5a83d9434776912d290faac..70286b7ddd34294a98eea656704849501c681c85 100644 (file)
@@ -65,26 +65,29 @@ void Serial::DeviceState::set_baud_rate(unsigned baud)
        case 9600:   speed = B9600; break;
        case 19200:  speed = B19200; break;
        case 38400:  speed = B38400; break;
-       case 57600:  speed = B57600; break;
-       case 115200: speed = B115200; break;
-       case 230400: speed = B230400; break;
-       case 460800: speed = B460800; break;
-       case 500000: speed = B500000; break;
-       case 576000: speed = B576000; break;
-       case 921600: speed = B921600; break;
-       case 1000000: speed = B1000000; break;
-       case 1152000: speed = B1152000; break;
-       case 1500000: speed = B1500000; break;
-       case 2000000: speed = B2000000; break;
-       case 2500000: speed = B2500000; break;
-       case 3000000: speed = B3000000; break;
-       case 3500000: speed = B3500000; break;
-       case 4000000: speed = B4000000; break;
+       case 57600:  speed = 0010001; break;
+       case 115200: speed = 0010002; break;
+       case 230400: speed = 0010003; break;
+       case 460800: speed = 0010004; break;
+       case 500000: speed = 0010005; break;
+       case 576000: speed = 0010006; break;
+       case 921600: speed = 0010007; break;
+       case 1000000: speed = 0010010; break;
+       case 1152000: speed = 0010011; break;
+       case 1500000: speed = 0010012; break;
+       case 2000000: speed = 0010013; break;
+       case 2500000: speed = 0010014; break;
+       case 3000000: speed = 0010015; break;
+       case 3500000: speed = 0010016; break;
+       case 4000000: speed = 0010017; break;
        default: throw invalid_argument("set_baud_rate");
        }
 
-       cfsetospeed(&state, speed);
-       cfsetispeed(&state, speed);
+       int ret = cfsetospeed(&state, speed);
+       if(ret==0)
+               ret = cfsetispeed(&state, speed);
+       if(ret<0)
+               throw invalid_argument("set_baud_rate");
 }
 
 void Serial::DeviceState::set_data_bits(unsigned bits)