Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Polarisru/updiprog
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kiselev committed Mar 9, 2023
2 parents 48bd158 + 99df4f8 commit d05be65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions com.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <windows.h>
#include <winbase.h>
#endif
#ifdef __linux
#if defined(__APPLE__) || defined(__linux)
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
Expand All @@ -16,7 +16,7 @@
#ifdef __MINGW32__
static HANDLE hSerial;
#endif
#ifdef __linux
#if defined(__APPLE__) || defined(__linux)
static int fd;
#endif

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -234,7 +238,7 @@ void COM_Close(void)
#ifdef __MINGW32__
CloseHandle(hSerial);
#endif
#ifdef __linux
#if defined(__APPLE__) || defined(__linux)
close(fd);
#endif
}
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <windows.h>
#include <unistd.h>
#endif // __MINGW32__
#ifdef __linux
#if defined(__APPLE__) || defined(__linux)
#include <unistd.h>
#endif // __linux

Expand Down

0 comments on commit d05be65

Please sign in to comment.