From d71d7e739591b66b5505bc6bb812349f69287ef3 Mon Sep 17 00:00:00 2001 From: David Betz Date: Sat, 7 Feb 2015 09:40:01 -0500 Subject: [PATCH] Fix the mingw build by adding the serial_baud function to osint_mingw.c. --- osint_linux.c | 13 ++++++------ osint_mingw.c | 59 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/osint_linux.c b/osint_linux.c index 64f43cf..ac0191d 100644 --- a/osint_linux.c +++ b/osint_linux.c @@ -147,12 +147,12 @@ static void sigint_handler(int signum) /** * open serial port * @param port - COMn port name + * @param baud - baud rate * @returns hSerial - file handle to serial port */ int serial_init(const char* port, unsigned long baud) { struct termios sparm; - int tbaud = 0; /* open the port */ #ifdef MACOSX @@ -174,8 +174,6 @@ int serial_init(const char* port, unsigned long baud) return 0; } - fcntl(hSerial, F_SETFL, 0); - /* set the baud rate */ if (!serial_baud(baud)) { close(hSerial); @@ -193,7 +191,6 @@ int serial_init(const char* port, unsigned long baud) cfmakeraw(&sparm); sparm.c_cc[VTIME] = 0; sparm.c_cc[VMIN] = 1; - chk("cfsetspeed", cfsetspeed(&sparm, tbaud)); #else memset(&sparm, 0, sizeof(sparm)); sparm.c_cflag = CS8 | CLOCAL | CREAD; @@ -203,8 +200,6 @@ int serial_init(const char* port, unsigned long baud) sparm.c_iflag = IGNPAR | IGNBRK; sparm.c_cc[VTIME] = 0; sparm.c_cc[VMIN] = 1; - chk("cfsetispeed", cfsetispeed(&sparm, tbaud)); - chk("cfsetospeed", cfsetospeed(&sparm, tbaud)); #endif /* set the options */ @@ -269,8 +264,11 @@ int serial_baud(unsigned long baud) tbaud = B9600; break; default: + // try just using the supplied baud rate + tbaud = baud; + break; +#if 0 printf("Unsupported baudrate. Use "); - tbaud = baud; break; #ifdef B921600 printf("921600, "); #endif @@ -289,6 +287,7 @@ int serial_baud(unsigned long baud) printf("115200, 57600, 38400, 19200, or 9600\n"); serial_done(); exit(2); +#endif break; } diff --git a/osint_mingw.c b/osint_mingw.c index 3c4e701..9dd96d4 100644 --- a/osint_mingw.c +++ b/osint_mingw.c @@ -72,26 +72,13 @@ int serial_init(const char *port, unsigned long baud) if (hSerial == INVALID_HANDLE_VALUE) return FALSE; - GetCommState(hSerial, &state); - switch (baud) { - case 9600: - state.BaudRate = CBR_9600; - break; - case 19200: - state.BaudRate = CBR_19200; - break; - case 38400: - state.BaudRate = CBR_38400; - break; - case 57600: - state.BaudRate = CBR_57600; - break; - case 115200: - state.BaudRate = CBR_115200; - break; - default: - return FALSE; + /* set the baud rate */ + if (!serial_baud(baud)) { + CloseHandle(hSerial); + return 0; } + + GetCommState(hSerial, &state); state.ByteSize = 8; state.Parity = NOPARITY; state.StopBits = ONESTOPBIT; @@ -123,6 +110,40 @@ int serial_init(const char *port, unsigned long baud) return TRUE; } +/** + * change the baud rate of the serial port + * @param baud - baud rate + * @returns 1 for success and 0 for failure + */ +int serial_baud(unsigned long baud) +{ + DCB state; + + GetCommState(hSerial, &state); + switch (baud) { + case 9600: + state.BaudRate = CBR_9600; + break; + case 19200: + state.BaudRate = CBR_19200; + break; + case 38400: + state.BaudRate = CBR_38400; + break; + case 57600: + state.BaudRate = CBR_57600; + break; + case 115200: + state.BaudRate = CBR_115200; + break; + default: + return FALSE; + } + SetCommState(hSerial, &state); + + return TRUE; +} + void serial_done(void) { if (hSerial != INVALID_HANDLE_VALUE) {