170 lines
5.3 KiB
Diff
170 lines
5.3 KiB
Diff
this fixes the serial driver on musl as well as on ppc
|
|
|
|
diff --git a/EmptyEpsilon/src/hardware/serialDriver.cpp a/EmptyEpsilon/src/hardware/serialDriver.cpp
|
|
index 0bb0228..d935c63 100644
|
|
--- a/EmptyEpsilon/src/hardware/serialDriver.cpp
|
|
+++ b/EmptyEpsilon/src/hardware/serialDriver.cpp
|
|
@@ -2,20 +2,31 @@
|
|
#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" {
|
|
+#ifdef __GLIBC__
|
|
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
|
|
extern int tcsendbreak (int __fd, int __duration) __THROW;
|
|
+#else
|
|
+ extern int ioctl (int, int, ...);
|
|
+ extern int tcsendbreak (int, int);
|
|
+#endif
|
|
}
|
|
#endif
|
|
#include <asm/termios.h>
|
|
#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>
|
|
@@ -57,7 +68,7 @@ SerialPort::SerialPort(string name)
|
|
}
|
|
}
|
|
#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);
|
|
@@ -76,7 +87,7 @@ SerialPort::~SerialPort()
|
|
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
|
|
@@ -87,7 +98,7 @@ bool SerialPort::isOpen()
|
|
#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;
|
|
@@ -163,7 +174,7 @@ void SerialPort::configure(int baudrate, int databits, EParity parity, EStopBits
|
|
LOG(ERROR) << "SetCommState failed!" << error;
|
|
}
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
fsync(handle);
|
|
|
|
struct termios2 tio;
|
|
@@ -317,7 +328,7 @@ void SerialPort::send(void* data, int data_size)
|
|
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);
|
|
@@ -345,7 +356,7 @@ int SerialPort::recv(void* data, int data_size)
|
|
}
|
|
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;
|
|
@@ -361,7 +372,7 @@ void SerialPort::setDTR()
|
|
#ifdef __WIN32__
|
|
EscapeCommFunction(handle, SETDTR);
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
int bit = TIOCM_DTR;
|
|
ioctl(handle, TIOCMBIS, &bit);
|
|
#endif
|
|
@@ -377,7 +388,7 @@ void SerialPort::clearDTR()
|
|
#ifdef __WIN32__
|
|
EscapeCommFunction(handle, CLRDTR);
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
int bit = TIOCM_DTR;
|
|
ioctl(handle, TIOCMBIC, &bit);
|
|
#endif
|
|
@@ -393,7 +404,7 @@ void SerialPort::setRTS()
|
|
#ifdef __WIN32__
|
|
EscapeCommFunction(handle, SETRTS);
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
int bit = TIOCM_RTS;
|
|
ioctl(handle, TIOCMBIS, &bit);
|
|
#endif
|
|
@@ -409,7 +420,7 @@ void SerialPort::clearRTS()
|
|
#ifdef __WIN32__
|
|
EscapeCommFunction(handle, CLRRTS);
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
int bit = TIOCM_RTS;
|
|
ioctl(handle, TIOCMBIC, &bit);
|
|
#endif
|
|
@@ -425,7 +436,7 @@ void SerialPort::sendBreak()
|
|
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
|
|
}
|
|
@@ -456,7 +467,7 @@ std::vector<string> SerialPort::getAvailablePorts()
|
|
LOG(ERROR) << "Failed to open registry key for serial port list.";
|
|
}
|
|
#endif
|
|
-#ifdef __gnu_linux__
|
|
+#ifdef __linux__
|
|
DIR* dir = opendir("/dev/");
|
|
if (dir)
|
|
{
|
|
@@ -511,7 +522,7 @@ string SerialPort::getPseudoDriverName(string port)
|
|
}
|
|
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 a/EmptyEpsilon/src/hardware/serialDriver.h a/EmptyEpsilon/src/hardware/serialDriver.h
|
|
index 29cc0b5..9513457 100644
|
|
--- a/EmptyEpsilon/src/hardware/serialDriver.h
|
|
+++ b/EmptyEpsilon/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
|
|
|