+ if (!GetCommState(hdl, &dcb)) {
+ /* TODO: Error handling. */
+ }
+
+ /* TODO: Rename 'speed' to 'baudrate'. */
+ switch(speed) {
+ case 115200:
+ dcb.BaudRate = CBR_115200;
+ break;
+ case 57600:
+ dcb.BaudRate = CBR_57600;
+ break;
+ case 38400:
+ dcb.BaudRate = CBR_38400;
+ break;
+ case 19200:
+ dcb.BaudRate = CBR_19200;
+ break;
+ case 9600:
+ dcb.BaudRate = CBR_9600;
+ break;
+ default:
+ /* TODO: Error handling. */
+ break;
+ }
+ dcb.ByteSize = bits;
+ dcb.Parity = NOPARITY; /* TODO: Don't hardcode. */
+ dcb.StopBits = ONESTOPBIT; /* TODO: Don't hardcode. */
+
+ if (!SetCommState(hdl, &dcb)) {
+ /* TODO: Error handling. */
+ }
+#else
+ struct termios term;
+
+ /* Only supporting what we need really, currently the OLS driver. */
+ if (speed != 115200 || bits != 8 || parity != 0 || stopbits != 1
+ || flowcontrol != 2)
+ return SIGROK_ERR;
+
+ if (tcgetattr(fd, &term) < 0)
+ return SIGROK_ERR;
+ if (cfsetispeed(&term, B115200) < 0)
+ return SIGROK_ERR;
+ term.c_cflag &= ~CSIZE;
+ term.c_cflag |= CS8;
+ term.c_cflag &= ~CSTOPB;
+ term.c_cflag |= IXON | IXOFF;
+ term.c_iflag |= IGNPAR;
+ if (tcsetattr(fd, TCSADRAIN, &term) < 0)
+ return SIGROK_ERR;
+#endif
+
+ return SIGROK_OK;
+}