From 291dcfc1fee00f2b9ca51b81427dafe7f574b157 Mon Sep 17 00:00:00 2001 From: Denis De Mesmaeker Date: Wed, 23 Feb 2022 16:06:58 +0100 Subject: [PATCH] - added support for mac os - add serial speed 230400 --- com.c | 16 ++++++++++------ main.c | 2 +- sleep.c | 2 +- sleep.h | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/com.c b/com.c index ebf94d8..7350674 100644 --- a/com.c +++ b/com.c @@ -2,7 +2,7 @@ #include #include #endif -#ifdef __linux +#if defined(__APPLE__) || defined(__linux) #include #include #include @@ -16,7 +16,7 @@ #ifdef __MINGW32__ static HANDLE hSerial; #endif -#ifdef __linux +#if defined(__APPLE__) || defined(__linux) static int fd; #endif @@ -70,7 +70,7 @@ bool COM_Open(char *port, uint32_t baudrate, bool have_parity, bool two_stopbits //COM_Bytes = 0; #endif - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) fd = open(port, O_RDWR | O_NOCTTY ); if (fd <0) return false; @@ -100,6 +100,10 @@ bool COM_Open(char *port, uint32_t baudrate, bool have_parity, bool two_stopbits cfsetispeed(&SerialPortSettings, B115200); cfsetospeed(&SerialPortSettings, B115200); break; + case 230400: + cfsetispeed(&SerialPortSettings, B230400); + cfsetospeed(&SerialPortSettings, B230400); + break; } cfmakeraw(&SerialPortSettings); /* Set raw mode (special processing disabled) */ if (have_parity == true) @@ -148,7 +152,7 @@ int COM_Write(uint8_t *data, uint16_t len) // CloseHandle(ov.hEvent); // return res; #endif - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) int iOut = write(fd, data, len); if (iOut < 0) return -1; @@ -192,7 +196,7 @@ int COM_Read(uint8_t *data, uint16_t len) // } ReadFile(hSerial, data, len, &dwBytesRead, NULL); #endif - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) int dwBytesRead = read(fd, data, len); if (dwBytesRead < 0) return -1; @@ -234,7 +238,7 @@ void COM_Close(void) #ifdef __MINGW32__ CloseHandle(hSerial); #endif - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) close(fd); #endif } diff --git a/main.c b/main.c index 3b05bfa..b32044f 100644 --- a/main.c +++ b/main.c @@ -314,7 +314,7 @@ int main(int argc, char* argv[]) #ifdef __MINGW32__ ch = '\\'; #endif // __MINGW32__ - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) ch = '/'; #endif // __linux if (strchr(parameters.rd_file, ch) != NULL) diff --git a/sleep.c b/sleep.c index a1ff557..c86a323 100644 --- a/sleep.c +++ b/sleep.c @@ -5,7 +5,7 @@ void msleep(uint32_t msec) #ifdef __MINGW32__ SleepEx(msec, false); #endif // __MINGW32__ - #ifdef __linux + #if defined(__APPLE__) || defined(__linux) usleep(msec*1000); #endif // __linux } diff --git a/sleep.h b/sleep.h index 4f2dd08..60534bf 100644 --- a/sleep.h +++ b/sleep.h @@ -7,7 +7,7 @@ #include #include #endif // __MINGW32__ -#ifdef __linux +#if defined(__APPLE__) || defined(__linux) #include #endif // __linux