|
| 1 | +diff --git a/include/ur_client_library/portable_endian.h b/include/ur_client_library/portable_endian.h |
| 2 | +new file mode 100644 |
| 3 | +index 0000000..2b43378 |
| 4 | +--- /dev/null |
| 5 | ++++ b/include/ur_client_library/portable_endian.h |
| 6 | +@@ -0,0 +1,118 @@ |
| 7 | ++// "License": Public Domain |
| 8 | ++// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like. |
| 9 | ++// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to |
| 10 | ++// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it |
| 11 | ++// an example on how to get the endian conversion functions on different platforms. |
| 12 | ++ |
| 13 | ++#ifndef PORTABLE_ENDIAN_H__ |
| 14 | ++#define PORTABLE_ENDIAN_H__ |
| 15 | ++ |
| 16 | ++#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) |
| 17 | ++ |
| 18 | ++# define __WINDOWS__ |
| 19 | ++ |
| 20 | ++#endif |
| 21 | ++ |
| 22 | ++#if defined(__linux__) || defined(__CYGWIN__) |
| 23 | ++ |
| 24 | ++# include <endian.h> |
| 25 | ++ |
| 26 | ++#elif defined(__APPLE__) |
| 27 | ++ |
| 28 | ++# include <libkern/OSByteOrder.h> |
| 29 | ++ |
| 30 | ++# define htobe16(x) OSSwapHostToBigInt16(x) |
| 31 | ++# define htole16(x) OSSwapHostToLittleInt16(x) |
| 32 | ++# define be16toh(x) OSSwapBigToHostInt16(x) |
| 33 | ++# define le16toh(x) OSSwapLittleToHostInt16(x) |
| 34 | ++ |
| 35 | ++# define htobe32(x) OSSwapHostToBigInt32(x) |
| 36 | ++# define htole32(x) OSSwapHostToLittleInt32(x) |
| 37 | ++# define be32toh(x) OSSwapBigToHostInt32(x) |
| 38 | ++# define le32toh(x) OSSwapLittleToHostInt32(x) |
| 39 | ++ |
| 40 | ++# define htobe64(x) OSSwapHostToBigInt64(x) |
| 41 | ++# define htole64(x) OSSwapHostToLittleInt64(x) |
| 42 | ++# define be64toh(x) OSSwapBigToHostInt64(x) |
| 43 | ++# define le64toh(x) OSSwapLittleToHostInt64(x) |
| 44 | ++ |
| 45 | ++# define __BYTE_ORDER BYTE_ORDER |
| 46 | ++# define __BIG_ENDIAN BIG_ENDIAN |
| 47 | ++# define __LITTLE_ENDIAN LITTLE_ENDIAN |
| 48 | ++# define __PDP_ENDIAN PDP_ENDIAN |
| 49 | ++ |
| 50 | ++#elif defined(__OpenBSD__) |
| 51 | ++ |
| 52 | ++# include <sys/endian.h> |
| 53 | ++ |
| 54 | ++#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) |
| 55 | ++ |
| 56 | ++# include <sys/endian.h> |
| 57 | ++ |
| 58 | ++# define be16toh(x) betoh16(x) |
| 59 | ++# define le16toh(x) letoh16(x) |
| 60 | ++ |
| 61 | ++# define be32toh(x) betoh32(x) |
| 62 | ++# define le32toh(x) letoh32(x) |
| 63 | ++ |
| 64 | ++# define be64toh(x) betoh64(x) |
| 65 | ++# define le64toh(x) letoh64(x) |
| 66 | ++ |
| 67 | ++#elif defined(__WINDOWS__) |
| 68 | ++ |
| 69 | ++# include <winsock2.h> |
| 70 | ++# include <sys/param.h> |
| 71 | ++ |
| 72 | ++# if BYTE_ORDER == LITTLE_ENDIAN |
| 73 | ++ |
| 74 | ++# define htobe16(x) htons(x) |
| 75 | ++# define htole16(x) (x) |
| 76 | ++# define be16toh(x) ntohs(x) |
| 77 | ++# define le16toh(x) (x) |
| 78 | ++ |
| 79 | ++# define htobe32(x) htonl(x) |
| 80 | ++# define htole32(x) (x) |
| 81 | ++# define be32toh(x) ntohl(x) |
| 82 | ++# define le32toh(x) (x) |
| 83 | ++ |
| 84 | ++# define htobe64(x) htonll(x) |
| 85 | ++# define htole64(x) (x) |
| 86 | ++# define be64toh(x) ntohll(x) |
| 87 | ++# define le64toh(x) (x) |
| 88 | ++ |
| 89 | ++# elif BYTE_ORDER == BIG_ENDIAN |
| 90 | ++ |
| 91 | ++ /* that would be xbox 360 */ |
| 92 | ++# define htobe16(x) (x) |
| 93 | ++# define htole16(x) __builtin_bswap16(x) |
| 94 | ++# define be16toh(x) (x) |
| 95 | ++# define le16toh(x) __builtin_bswap16(x) |
| 96 | ++ |
| 97 | ++# define htobe32(x) (x) |
| 98 | ++# define htole32(x) __builtin_bswap32(x) |
| 99 | ++# define be32toh(x) (x) |
| 100 | ++# define le32toh(x) __builtin_bswap32(x) |
| 101 | ++ |
| 102 | ++# define htobe64(x) (x) |
| 103 | ++# define htole64(x) __builtin_bswap64(x) |
| 104 | ++# define be64toh(x) (x) |
| 105 | ++# define le64toh(x) __builtin_bswap64(x) |
| 106 | ++ |
| 107 | ++# else |
| 108 | ++ |
| 109 | ++# error byte order not supported |
| 110 | ++ |
| 111 | ++# endif |
| 112 | ++ |
| 113 | ++# define __BYTE_ORDER BYTE_ORDER |
| 114 | ++# define __BIG_ENDIAN BIG_ENDIAN |
| 115 | ++# define __LITTLE_ENDIAN LITTLE_ENDIAN |
| 116 | ++# define __PDP_ENDIAN PDP_ENDIAN |
| 117 | ++ |
| 118 | ++#else |
| 119 | ++ |
| 120 | ++# error platform not supported |
| 121 | ++ |
| 122 | ++#endif |
| 123 | ++ |
| 124 | ++#endif |
| 125 | + |
| 126 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 127 | +index 878ffed..a1b176e 100644 |
| 128 | +--- a/CMakeLists.txt |
| 129 | ++++ b/CMakeLists.txt |
| 130 | +@@ -1,4 +1,4 @@ |
| 131 | +-cmake_minimum_required(VERSION 3.0.2) |
| 132 | ++cmake_minimum_required(VERSION 3.14.0) |
| 133 | + project(ur_client_library) |
| 134 | + |
| 135 | + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/" ${CMAKE_MODULE_PATH}) |
| 136 | +@@ -10,13 +10,6 @@ endif() |
| 137 | + |
| 138 | + option(WITH_ASAN "Compile with address sanitizer support" OFF) |
| 139 | + |
| 140 | +-## |
| 141 | +-## Check C++11 support / enable global pedantic and Wall |
| 142 | +-## |
| 143 | +-include(DefineCXX17CompilerFlag) |
| 144 | +-DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG) |
| 145 | +-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") |
| 146 | +- |
| 147 | + add_library(urcl SHARED |
| 148 | + src/comm/tcp_socket.cpp |
| 149 | + src/comm/tcp_server.cpp |
| 150 | +@@ -51,8 +44,11 @@ add_library(urcl SHARED |
| 151 | + src/helpers.cpp |
| 152 | + ) |
| 153 | + add_library(ur_client_library::urcl ALIAS urcl) |
| 154 | +-target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter) |
| 155 | +-target_compile_options(urcl PUBLIC ${CXX17_FLAG}) |
| 156 | ++target_compile_options(urcl PRIVATE |
| 157 | ++ $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX> |
| 158 | ++ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wno-unused-parameter> |
| 159 | ++) |
| 160 | ++target_compile_features(urcl PUBLIC cxx_std_17) |
| 161 | + if(WITH_ASAN) |
| 162 | + target_compile_options(urcl PUBLIC -fsanitize=address) |
| 163 | + target_link_options(urcl PUBLIC -fsanitize=address) |
| 164 | +@@ -69,6 +65,9 @@ endif() |
| 165 | + if(CMAKE_THREAD_LIBS_INIT) |
| 166 | + target_link_libraries(urcl PUBLIC "${CMAKE_THREAD_LIBS_INIT}") |
| 167 | + endif() |
| 168 | ++if(UNIX AND NOT APPLE) |
| 169 | ++ target_link_libraries(urcl PUBLIC "rt") |
| 170 | ++endif() |
| 171 | + |
| 172 | + ## |
| 173 | + ## Build testing if enabled by option |
| 174 | +diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt |
| 175 | +index eb4c313..6972cf4 100644 |
| 176 | +--- a/examples/CMakeLists.txt |
| 177 | ++++ b/examples/CMakeLists.txt |
| 178 | +@@ -3,13 +3,6 @@ project(ur_driver_examples) |
| 179 | + |
| 180 | + # find_package(ur_client_library REQUIRED) |
| 181 | + |
| 182 | +-# # |
| 183 | +-# # Check C++11 support / enable global pedantic and Wall |
| 184 | +-# # |
| 185 | +-include(DefineCXX17CompilerFlag) |
| 186 | +-DEFINE_CXX_17_COMPILER_FLAG(CXX17_FLAG) |
| 187 | +-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") |
| 188 | +- |
| 189 | + add_executable(driver_example |
| 190 | + full_driver.cpp) |
| 191 | + target_compile_options(driver_example PUBLIC ${CXX17_FLAG}) |
| 192 | +diff --git a/include/ur_client_library/comm/bin_parser.h b/include/ur_client_library/comm/bin_parser.h |
| 193 | +index e13aba6..83f8e6c 100644 |
| 194 | +--- a/include/ur_client_library/comm/bin_parser.h |
| 195 | ++++ b/include/ur_client_library/comm/bin_parser.h |
| 196 | +@@ -21,7 +21,6 @@ |
| 197 | + #pragma once |
| 198 | + |
| 199 | + #include <assert.h> |
| 200 | +-#include <endian.h> |
| 201 | + #include <inttypes.h> |
| 202 | + #include <array> |
| 203 | + #include <bitset> |
| 204 | +@@ -29,6 +28,7 @@ |
| 205 | + #include <cstring> |
| 206 | + #include <string> |
| 207 | + #include <memory> |
| 208 | ++#include "ur_client_library/portable_endian.h" |
| 209 | + #include "ur_client_library/log.h" |
| 210 | + #include "ur_client_library/types.h" |
| 211 | + #include "ur_client_library/exceptions.h" |
| 212 | +diff --git a/include/ur_client_library/comm/package_serializer.h b/include/ur_client_library/comm/package_serializer.h |
| 213 | +index 7745da9..ded500a 100644 |
| 214 | +--- a/include/ur_client_library/comm/package_serializer.h |
| 215 | ++++ b/include/ur_client_library/comm/package_serializer.h |
| 216 | +@@ -29,8 +29,8 @@ |
| 217 | + #ifndef UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED |
| 218 | + #define UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED |
| 219 | + |
| 220 | +-#include <endian.h> |
| 221 | + #include <cstring> |
| 222 | ++#include "ur_client_library/portable_endian.h" |
| 223 | + |
| 224 | + namespace urcl |
| 225 | + { |
| 226 | +diff --git a/include/ur_client_library/control/reverse_interface.h b/include/ur_client_library/control/reverse_interface.h |
| 227 | +index 707c455..ee8c318 100644 |
| 228 | +--- a/include/ur_client_library/control/reverse_interface.h |
| 229 | ++++ b/include/ur_client_library/control/reverse_interface.h |
| 230 | +@@ -35,8 +35,8 @@ |
| 231 | + #include "ur_client_library/log.h" |
| 232 | + #include "ur_client_library/ur/robot_receive_timeout.h" |
| 233 | + #include <cstring> |
| 234 | +-#include <endian.h> |
| 235 | + #include <condition_variable> |
| 236 | ++#include "ur_client_library/portable_endian.h" |
| 237 | + |
| 238 | + namespace urcl |
| 239 | + { |
| 240 | +diff --git a/include/ur_client_library/primary/package_header.h b/include/ur_client_library/primary/package_header.h |
| 241 | +index cd64bda..440b2e4 100644 |
| 242 | +--- a/include/ur_client_library/primary/package_header.h |
| 243 | ++++ b/include/ur_client_library/primary/package_header.h |
| 244 | +@@ -32,7 +32,7 @@ |
| 245 | + |
| 246 | + #include <inttypes.h> |
| 247 | + #include <cstddef> |
| 248 | +-#include <endian.h> |
| 249 | ++#include "ur_client_library/portable_endian.h" |
| 250 | + #include "ur_client_library/types.h" |
| 251 | + |
| 252 | + namespace urcl |
| 253 | +diff --git a/include/ur_client_library/rtde/package_header.h b/include/ur_client_library/rtde/package_header.h |
| 254 | +index f910a08..eb509ea 100644 |
| 255 | +--- a/include/ur_client_library/rtde/package_header.h |
| 256 | ++++ b/include/ur_client_library/rtde/package_header.h |
| 257 | +@@ -31,7 +31,7 @@ |
| 258 | + #define UR_CLIENT_LIBRARY_RTDE__HEADER_H_INCLUDED |
| 259 | + |
| 260 | + #include <cstddef> |
| 261 | +-#include <endian.h> |
| 262 | ++#include "ur_client_library/portable_endian.h" |
| 263 | + #include "ur_client_library/types.h" |
| 264 | + #include "ur_client_library/comm/package_serializer.h" |
| 265 | + |
| 266 | +diff --git a/src/comm/tcp_socket.cpp b/src/comm/tcp_socket.cpp |
| 267 | +index 8803664..1d92880 100644 |
| 268 | +--- a/src/comm/tcp_socket.cpp |
| 269 | ++++ b/src/comm/tcp_socket.cpp |
| 270 | +@@ -21,7 +21,6 @@ |
| 271 | + */ |
| 272 | + |
| 273 | + #include <arpa/inet.h> |
| 274 | +-#include <endian.h> |
| 275 | + #include <netinet/tcp.h> |
| 276 | + #include <unistd.h> |
| 277 | + #include <chrono> |
| 278 | +@@ -29,6 +28,7 @@ |
| 279 | + #include <sstream> |
| 280 | + #include <thread> |
| 281 | + |
| 282 | ++#include "ur_client_library/portable_endian.h" |
| 283 | + #include "ur_client_library/log.h" |
| 284 | + #include "ur_client_library/comm/tcp_socket.h" |
| 285 | + |
| 286 | +@@ -48,7 +48,9 @@ void TCPSocket::setupOptions() |
| 287 | + { |
| 288 | + int flag = 1; |
| 289 | + setsockopt(socket_fd_, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)); |
| 290 | ++#ifndef __APPLE__ |
| 291 | + setsockopt(socket_fd_, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(int)); |
| 292 | ++#endif |
| 293 | + |
| 294 | + if (recv_timeout_ != nullptr) |
| 295 | + { |
0 commit comments