2021-03-09 13:13:53 +01:00
this fixes the serial driver on musl as well as on ppc
diff --git src/hardware/serialDriver.cpp src/hardware/serialDriver.cpp
2021-03-09 13:31:58 +01:00
index 0bb0228..d935c63 100644
2021-03-09 13:13:53 +01:00
--- src/hardware/serialDriver.cpp
+++ src/hardware/serialDriver.cpp
2021-03-09 13:31:58 +01:00
@@ -2,20 +2,31 @@
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
#include <windows.h>
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
//Including ioctl or termios conflicts with asm/termios.h which we need for TCGETS2. So locally define the ioctl and tcsendbreak functions. Yes, it's dirty, but it works.
//#include <sys/ioctl.h>
//#include <termios.h>
#ifndef ANDROID
extern "C" {
2021-03-09 13:31:58 +01:00
+#ifdef __GLIBC__
2021-03-09 13:13:53 +01:00
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
extern int tcsendbreak (int __fd, int __duration) __THROW;
2021-03-09 13:31:58 +01:00
+#else
+ extern int ioctl (int, int, ...);
+ extern int tcsendbreak (int, int);
+#endif
}
#endif
#include <asm/termios.h>
2021-03-09 13:13:53 +01:00
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#ifdef __powerpc__
+ /* ppc has no tcgets2 or termios2, but termios covers the same stuff */
+ #define termios2 termios
+ #define TCGETS2 TCGETS
+ #define TCSETS2 TCSETS
+#endif
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <IOKit/serial/ioss.h>
2021-03-09 13:31:58 +01:00
@@ -57,7 +68,7 @@ SerialPort::SerialPort(string name)
2021-03-09 13:13:53 +01:00
}
}
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
if (!name.startswith("/dev/"))
name = "/dev/" + name;
handle = open(name.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
2021-03-09 13:31:58 +01:00
@@ -76,7 +87,7 @@ SerialPort::~SerialPort()
2021-03-09 13:13:53 +01:00
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
close(handle);
handle = 0;
#endif
2021-03-09 13:31:58 +01:00
@@ -87,7 +98,7 @@ bool SerialPort::isOpen()
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
return handle != INVALID_HANDLE_VALUE;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
return handle;
#endif
return false;
2021-03-09 13:31:58 +01:00
@@ -163,7 +174,7 @@ void SerialPort::configure(int baudrate, int databits, EParity parity, EStopBits
2021-03-09 13:13:53 +01:00
LOG(ERROR) << "SetCommState failed!" << error;
}
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
fsync(handle);
struct termios2 tio;
2021-03-09 13:31:58 +01:00
@@ -317,7 +328,7 @@ void SerialPort::send(void* data, int data_size)
2021-03-09 13:13:53 +01:00
data_size -= written;
}
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
while(data_size > 0)
{
int written = write(handle, data, data_size);
2021-03-09 13:31:58 +01:00
@@ -345,7 +356,7 @@ int SerialPort::recv(void* data, int data_size)
2021-03-09 13:13:53 +01:00
}
return read_size;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
int bytes_read = read(handle, data, data_size);
if (bytes_read > 0)
return bytes_read;
2021-03-09 13:31:58 +01:00
@@ -361,7 +372,7 @@ void SerialPort::setDTR()
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
EscapeCommFunction(handle, SETDTR);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_DTR;
ioctl(handle, TIOCMBIS, &bit);
#endif
2021-03-09 13:31:58 +01:00
@@ -377,7 +388,7 @@ void SerialPort::clearDTR()
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
EscapeCommFunction(handle, CLRDTR);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_DTR;
ioctl(handle, TIOCMBIC, &bit);
#endif
2021-03-09 13:31:58 +01:00
@@ -393,7 +404,7 @@ void SerialPort::setRTS()
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
EscapeCommFunction(handle, SETRTS);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_RTS;
ioctl(handle, TIOCMBIS, &bit);
#endif
2021-03-09 13:31:58 +01:00
@@ -409,7 +420,7 @@ void SerialPort::clearRTS()
2021-03-09 13:13:53 +01:00
#ifdef __WIN32__
EscapeCommFunction(handle, CLRRTS);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_RTS;
ioctl(handle, TIOCMBIC, &bit);
#endif
2021-03-09 13:31:58 +01:00
@@ -425,7 +436,7 @@ void SerialPort::sendBreak()
2021-03-09 13:13:53 +01:00
Sleep(1);
ClearCommBreak(handle);
#endif
-#if (defined(__gnu_linux__) && !defined(ANDROID)) || (defined(__APPLE__) && defined(__MACH__))
+#if (defined(__linux__) && !defined(ANDROID)) || (defined(__APPLE__) && defined(__MACH__))
tcsendbreak(handle, 0);
#endif
}
2021-03-09 13:31:58 +01:00
@@ -456,7 +467,7 @@ std::vector<string> SerialPort::getAvailablePorts()
2021-03-09 13:13:53 +01:00
LOG(ERROR) << "Failed to open registry key for serial port list.";
}
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
DIR* dir = opendir("/dev/");
if (dir)
{
2021-03-09 13:31:58 +01:00
@@ -511,7 +522,7 @@ string SerialPort::getPseudoDriverName(string port)
2021-03-09 13:13:53 +01:00
}
return ret;
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
FILE* f = fopen(("/sys/class/tty/" + port + "/device/modalias").c_str(), "rt");
if (!f)
return "";
diff --git src/hardware/serialDriver.h src/hardware/serialDriver.h
index 29cc0b5..9513457 100644
--- src/hardware/serialDriver.h
+++ src/hardware/serialDriver.h
@@ -14,7 +14,7 @@ private:
#ifdef __WIN32__
HANDLE handle;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
int handle;
#endif