-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: wep21 <daisuke.nishimatsu1021@gmail.com>
- Loading branch information
Showing
2 changed files
with
340 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,295 @@ | ||
diff --git a/include/ur_client_library/portable_endian.h b/include/ur_client_library/portable_endian.h | ||
new file mode 100644 | ||
index 0000000..2b43378 | ||
--- /dev/null | ||
+++ b/include/ur_client_library/portable_endian.h | ||
@@ -0,0 +1,118 @@ | ||
+// "License": Public Domain | ||
+// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like. | ||
+// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to | ||
+// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it | ||
+// an example on how to get the endian conversion functions on different platforms. | ||
+ | ||
+#ifndef PORTABLE_ENDIAN_H__ | ||
+#define PORTABLE_ENDIAN_H__ | ||
+ | ||
+#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) | ||
+ | ||
+# define __WINDOWS__ | ||
+ | ||
+#endif | ||
+ | ||
+#if defined(__linux__) || defined(__CYGWIN__) | ||
+ | ||
+# include <endian.h> | ||
+ | ||
+#elif defined(__APPLE__) | ||
+ | ||
+# include <libkern/OSByteOrder.h> | ||
+ | ||
+# define htobe16(x) OSSwapHostToBigInt16(x) | ||
+# define htole16(x) OSSwapHostToLittleInt16(x) | ||
+# define be16toh(x) OSSwapBigToHostInt16(x) | ||
+# define le16toh(x) OSSwapLittleToHostInt16(x) | ||
+ | ||
+# define htobe32(x) OSSwapHostToBigInt32(x) | ||
+# define htole32(x) OSSwapHostToLittleInt32(x) | ||
+# define be32toh(x) OSSwapBigToHostInt32(x) | ||
+# define le32toh(x) OSSwapLittleToHostInt32(x) | ||
+ | ||
+# define htobe64(x) OSSwapHostToBigInt64(x) | ||
+# define htole64(x) OSSwapHostToLittleInt64(x) | ||
+# define be64toh(x) OSSwapBigToHostInt64(x) | ||
+# define le64toh(x) OSSwapLittleToHostInt64(x) | ||
+ | ||
+# define __BYTE_ORDER BYTE_ORDER | ||
+# define __BIG_ENDIAN BIG_ENDIAN | ||
+# define __LITTLE_ENDIAN LITTLE_ENDIAN | ||
+# define __PDP_ENDIAN PDP_ENDIAN | ||
+ | ||
+#elif defined(__OpenBSD__) | ||
+ | ||
+# include <sys/endian.h> | ||
+ | ||
+#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) | ||
+ | ||
+# include <sys/endian.h> | ||
+ | ||
+# define be16toh(x) betoh16(x) | ||
+# define le16toh(x) letoh16(x) | ||
+ | ||
+# define be32toh(x) betoh32(x) | ||
+# define le32toh(x) letoh32(x) | ||
+ | ||
+# define be64toh(x) betoh64(x) | ||
+# define le64toh(x) letoh64(x) | ||
+ | ||
+#elif defined(__WINDOWS__) | ||
+ | ||
+# include <winsock2.h> | ||
+# include <sys/param.h> | ||
+ | ||
+# if BYTE_ORDER == LITTLE_ENDIAN | ||
+ | ||
+# define htobe16(x) htons(x) | ||
+# define htole16(x) (x) | ||
+# define be16toh(x) ntohs(x) | ||
+# define le16toh(x) (x) | ||
+ | ||
+# define htobe32(x) htonl(x) | ||
+# define htole32(x) (x) | ||
+# define be32toh(x) ntohl(x) | ||
+# define le32toh(x) (x) | ||
+ | ||
+# define htobe64(x) htonll(x) | ||
+# define htole64(x) (x) | ||
+# define be64toh(x) ntohll(x) | ||
+# define le64toh(x) (x) | ||
+ | ||
+# elif BYTE_ORDER == BIG_ENDIAN | ||
+ | ||
+ /* that would be xbox 360 */ | ||
+# define htobe16(x) (x) | ||
+# define htole16(x) __builtin_bswap16(x) | ||
+# define be16toh(x) (x) | ||
+# define le16toh(x) __builtin_bswap16(x) | ||
+ | ||
+# define htobe32(x) (x) | ||
+# define htole32(x) __builtin_bswap32(x) | ||
+# define be32toh(x) (x) | ||
+# define le32toh(x) __builtin_bswap32(x) | ||
+ | ||
+# define htobe64(x) (x) | ||
+# define htole64(x) __builtin_bswap64(x) | ||
+# define be64toh(x) (x) | ||
+# define le64toh(x) __builtin_bswap64(x) | ||
+ | ||
+# else | ||
+ | ||
+# error byte order not supported | ||
+ | ||
+# endif | ||
+ | ||
+# define __BYTE_ORDER BYTE_ORDER | ||
+# define __BIG_ENDIAN BIG_ENDIAN | ||
+# define __LITTLE_ENDIAN LITTLE_ENDIAN | ||
+# define __PDP_ENDIAN PDP_ENDIAN | ||
+ | ||
+#else | ||
+ | ||
+# error platform not supported | ||
+ | ||
+#endif | ||
+ | ||
+#endif | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 878ffed..a1b176e 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -1,4 +1,4 @@ | ||
-cmake_minimum_required(VERSION 3.0.2) | ||
+cmake_minimum_required(VERSION 3.14.0) | ||
project(ur_client_library) | ||
|
||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/" ${CMAKE_MODULE_PATH}) | ||
@@ -10,13 +10,6 @@ endif() | ||
|
||
option(WITH_ASAN "Compile with address sanitizer support" OFF) | ||
|
||
-## | ||
-## Check C++11 support / enable global pedantic and Wall | ||
-## | ||
-include(DefineCXX17CompilerFlag) | ||
-DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG) | ||
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") | ||
- | ||
add_library(urcl SHARED | ||
src/comm/tcp_socket.cpp | ||
src/comm/tcp_server.cpp | ||
@@ -51,8 +44,11 @@ add_library(urcl SHARED | ||
src/helpers.cpp | ||
) | ||
add_library(ur_client_library::urcl ALIAS urcl) | ||
-target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter) | ||
-target_compile_options(urcl PUBLIC ${CXX17_FLAG}) | ||
+target_compile_options(urcl PRIVATE | ||
+ $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX> | ||
+ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wno-unused-parameter> | ||
+) | ||
+target_compile_features(urcl PUBLIC cxx_std_17) | ||
if(WITH_ASAN) | ||
target_compile_options(urcl PUBLIC -fsanitize=address) | ||
target_link_options(urcl PUBLIC -fsanitize=address) | ||
@@ -69,6 +65,9 @@ endif() | ||
if(CMAKE_THREAD_LIBS_INIT) | ||
target_link_libraries(urcl PUBLIC "${CMAKE_THREAD_LIBS_INIT}") | ||
endif() | ||
+if(UNIX AND NOT APPLE) | ||
+ target_link_libraries(urcl PUBLIC "rt") | ||
+endif() | ||
|
||
## | ||
## Build testing if enabled by option | ||
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt | ||
index eb4c313..6972cf4 100644 | ||
--- a/examples/CMakeLists.txt | ||
+++ b/examples/CMakeLists.txt | ||
@@ -3,13 +3,6 @@ project(ur_driver_examples) | ||
|
||
# find_package(ur_client_library REQUIRED) | ||
|
||
-# # | ||
-# # Check C++11 support / enable global pedantic and Wall | ||
-# # | ||
-include(DefineCXX17CompilerFlag) | ||
-DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG) | ||
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") | ||
- | ||
add_executable(driver_example | ||
full_driver.cpp) | ||
target_compile_options(driver_example PUBLIC ${CXX17_FLAG}) | ||
diff --git a/include/ur_client_library/comm/bin_parser.h b/include/ur_client_library/comm/bin_parser.h | ||
index e13aba6..83f8e6c 100644 | ||
--- a/include/ur_client_library/comm/bin_parser.h | ||
+++ b/include/ur_client_library/comm/bin_parser.h | ||
@@ -21,7 +21,6 @@ | ||
#pragma once | ||
|
||
#include <assert.h> | ||
-#include <endian.h> | ||
#include <inttypes.h> | ||
#include <array> | ||
#include <bitset> | ||
@@ -29,6 +28,7 @@ | ||
#include <cstring> | ||
#include <string> | ||
#include <memory> | ||
+#include "ur_client_library/portable_endian.h" | ||
#include "ur_client_library/log.h" | ||
#include "ur_client_library/types.h" | ||
#include "ur_client_library/exceptions.h" | ||
diff --git a/include/ur_client_library/comm/package_serializer.h b/include/ur_client_library/comm/package_serializer.h | ||
index 7745da9..ded500a 100644 | ||
--- a/include/ur_client_library/comm/package_serializer.h | ||
+++ b/include/ur_client_library/comm/package_serializer.h | ||
@@ -29,8 +29,8 @@ | ||
#ifndef UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED | ||
#define UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED | ||
|
||
-#include <endian.h> | ||
#include <cstring> | ||
+#include "ur_client_library/portable_endian.h" | ||
|
||
namespace urcl | ||
{ | ||
diff --git a/include/ur_client_library/control/reverse_interface.h b/include/ur_client_library/control/reverse_interface.h | ||
index 707c455..ee8c318 100644 | ||
--- a/include/ur_client_library/control/reverse_interface.h | ||
+++ b/include/ur_client_library/control/reverse_interface.h | ||
@@ -35,8 +35,8 @@ | ||
#include "ur_client_library/log.h" | ||
#include "ur_client_library/ur/robot_receive_timeout.h" | ||
#include <cstring> | ||
-#include <endian.h> | ||
#include <condition_variable> | ||
+#include "ur_client_library/portable_endian.h" | ||
|
||
namespace urcl | ||
{ | ||
diff --git a/include/ur_client_library/primary/package_header.h b/include/ur_client_library/primary/package_header.h | ||
index cd64bda..440b2e4 100644 | ||
--- a/include/ur_client_library/primary/package_header.h | ||
+++ b/include/ur_client_library/primary/package_header.h | ||
@@ -32,7 +32,7 @@ | ||
|
||
#include <inttypes.h> | ||
#include <cstddef> | ||
-#include <endian.h> | ||
+#include "ur_client_library/portable_endian.h" | ||
#include "ur_client_library/types.h" | ||
|
||
namespace urcl | ||
diff --git a/include/ur_client_library/rtde/package_header.h b/include/ur_client_library/rtde/package_header.h | ||
index f910a08..eb509ea 100644 | ||
--- a/include/ur_client_library/rtde/package_header.h | ||
+++ b/include/ur_client_library/rtde/package_header.h | ||
@@ -31,7 +31,7 @@ | ||
#define UR_CLIENT_LIBRARY_RTDE__HEADER_H_INCLUDED | ||
|
||
#include <cstddef> | ||
-#include <endian.h> | ||
+#include "ur_client_library/portable_endian.h" | ||
#include "ur_client_library/types.h" | ||
#include "ur_client_library/comm/package_serializer.h" | ||
|
||
diff --git a/src/comm/tcp_socket.cpp b/src/comm/tcp_socket.cpp | ||
index 8803664..1d92880 100644 | ||
--- a/src/comm/tcp_socket.cpp | ||
+++ b/src/comm/tcp_socket.cpp | ||
@@ -21,7 +21,6 @@ | ||
*/ | ||
|
||
#include <arpa/inet.h> | ||
-#include <endian.h> | ||
#include <netinet/tcp.h> | ||
#include <unistd.h> | ||
#include <chrono> | ||
@@ -29,6 +28,7 @@ | ||
#include <sstream> | ||
#include <thread> | ||
|
||
+#include "ur_client_library/portable_endian.h" | ||
#include "ur_client_library/log.h" | ||
#include "ur_client_library/comm/tcp_socket.h" | ||
|
||
@@ -48,7 +48,9 @@ void TCPSocket::setupOptions() | ||
{ | ||
int flag = 1; | ||
setsockopt(socket_fd_, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)); | ||
+#ifndef __APPLE__ | ||
setsockopt(socket_fd_, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(int)); | ||
+#endif | ||
|
||
if (recv_timeout_ != nullptr) | ||
{ |
Oops, something went wrong.