Skip to content

Commit df8a74b

Browse files
committed
Rename endian.h to portable_endian.h
This change renames the endian.h file to portable_endian.h to avoid conflicts caused by circular includes. The third-party endian.h file includes the system's endian.h, which can lead to circular imports due to overlapping filenames. By renaming the file, we eliminate this issue and ensure compatibility in the CMake build process. Additionally, this commit reduces the number of headers that include endian.h, simplifying the library's usage for external projects. Finally, a macOS CI build has been added to verify that the library builds successfully on macOS, ensuring cross-platform compatibility.
1 parent 542731a commit df8a74b

21 files changed

Lines changed: 268 additions & 80 deletions

.github/workflows/mac-build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: macOS build and tests
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
mac-build:
11+
name: macOS (${{ matrix.arch }})
12+
timeout-minutes: 30
13+
runs-on: ${{ matrix.runner }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- runner: macos-15
19+
arch: arm64
20+
- runner: macos-15-intel
21+
arch: x86_64
22+
23+
steps:
24+
- uses: actions/checkout@v6
25+
- name: configure
26+
run: mkdir build && cd build && cmake .. -DBUILDING_TESTS=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
27+
- name: build
28+
run: cmake --build build
29+
- name: test
30+
run: cd build && ctest --output-on-failure
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// endian.h
2+
// portable_endian.h
33
//
44
// https://gist.github.com/panzi/6856583
55
//
@@ -53,7 +53,6 @@
5353
# define be64toh(x) betoh64(x)
5454
# define le64toh(x) letoh64(x)
5555
#elif defined(_WIN32)
56-
# include <stdlib.h>
5756
# if BYTE_ORDER == LITTLE_ENDIAN
5857
# if defined(_MSC_VER)
5958
# define htobe16(x) _byteswap_ushort(x)

CMakeLists.txt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ endif()
1515

1616

1717
add_library(urcl
18+
src/comm/bin_parser.cpp
19+
src/comm/package_serializer.cpp
1820
src/comm/tcp_socket.cpp
1921
src/comm/tcp_server.cpp
2022
src/control/motion_primitives.cpp
@@ -23,6 +25,7 @@ add_library(urcl
2325
src/control/script_sender.cpp
2426
src/control/trajectory_point_interface.cpp
2527
src/control/script_command_interface.cpp
28+
src/primary/package_header.cpp
2629
src/primary/primary_package.cpp
2730
src/primary/primary_client.cpp
2831
src/primary/robot_message.cpp
@@ -35,6 +38,7 @@ add_library(urcl
3538
src/primary/robot_state/kinematics_info.cpp
3639
src/primary/robot_state/robot_mode_data.cpp
3740
src/primary/robot_state/configuration_data.cpp
41+
src/rtde/package_header.cpp
3842
src/rtde/control_package_pause.cpp
3943
src/rtde/control_package_setup_inputs.cpp
4044
src/rtde/control_package_setup_outputs.cpp
@@ -65,17 +69,9 @@ target_compile_features(urcl PUBLIC cxx_std_17)
6569

6670
if(MSVC)
6771
target_link_libraries(urcl ws2_32)
68-
target_include_directories(urcl PUBLIC
69-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/endian>
70-
$<INSTALL_INTERFACE:include/${PROJECT_NAME}/3rdparty>
71-
)
72-
else()
73-
if(APPLE)
74-
target_include_directories(urcl PUBLIC
75-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/endian>
76-
$<INSTALL_INTERFACE:include/${PROJECT_NAME}/3rdparty>
77-
)
78-
endif()
72+
endif()
73+
74+
if(NOT MSVC)
7975
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
8076
target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter)
8177

@@ -120,11 +116,6 @@ install(TARGETS urcl EXPORT urcl_targets
120116
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
121117
)
122118
install(DIRECTORY include/ DESTINATION include)
123-
if(MSVC OR APPLE)
124-
install(DIRECTORY 3rdparty/endian/ DESTINATION include/${PROJECT_NAME}/3rdparty
125-
FILES_MATCHING PATTERN "*.h"
126-
)
127-
endif()
128119

129120
install(EXPORT urcl_targets
130121
DESTINATION lib/cmake/ur_client_library

include/ur_client_library/comm/bin_parser.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#pragma once
2222

2323
#include <assert.h>
24-
#include <endian.h>
2524
#include <inttypes.h>
2625
#include <array>
2726
#include <bitset>
@@ -53,30 +52,12 @@ class BinParser
5352
{
5453
return val;
5554
}
56-
uint16_t decode(uint16_t val)
57-
{
58-
return be16toh(val);
59-
}
60-
uint32_t decode(uint32_t val)
61-
{
62-
return be32toh(val);
63-
}
64-
uint64_t decode(uint64_t val)
65-
{
66-
return be64toh(val);
67-
}
68-
int16_t decode(int16_t val)
69-
{
70-
return be16toh(val);
71-
}
72-
int32_t decode(int32_t val)
73-
{
74-
return be32toh(val);
75-
}
76-
int64_t decode(int64_t val)
77-
{
78-
return be64toh(val);
79-
}
55+
uint16_t decode(uint16_t val);
56+
uint32_t decode(uint32_t val);
57+
uint64_t decode(uint64_t val);
58+
int16_t decode(int16_t val);
59+
int32_t decode(int32_t val);
60+
int64_t decode(int64_t val);
8061

8162
public:
8263
/*!

include/ur_client_library/comm/package_serializer.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#ifndef UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED
3030
#define UR_CLIENT_LIBRARY_PACKAGE_SERIALIZER_H_INCLUDED
3131

32-
#include <endian.h>
3332
#include <cstdint>
3433
#include <cstring>
3534
#include <string>
@@ -146,30 +145,12 @@ class PackageSerializer
146145
{
147146
return val;
148147
}
149-
static uint16_t encode(uint16_t val)
150-
{
151-
return htobe16(val);
152-
}
153-
static uint32_t encode(uint32_t val)
154-
{
155-
return htobe32(val);
156-
}
157-
static uint64_t encode(uint64_t val)
158-
{
159-
return htobe64(val);
160-
}
161-
static int16_t encode(int16_t val)
162-
{
163-
return htobe16(val);
164-
}
165-
static int32_t encode(int32_t val)
166-
{
167-
return htobe32(val);
168-
}
169-
static int64_t encode(int64_t val)
170-
{
171-
return htobe64(val);
172-
}
148+
static uint16_t encode(uint16_t val);
149+
static uint32_t encode(uint32_t val);
150+
static uint64_t encode(uint64_t val);
151+
static int16_t encode(int16_t val);
152+
static int32_t encode(int32_t val);
153+
static int64_t encode(int64_t val);
173154
};
174155

175156
} // namespace comm

include/ur_client_library/control/reverse_interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "ur_client_library/ur/robot_receive_timeout.h"
3737
#include "ur_client_library/ur/version_information.h"
3838
#include <cstring>
39-
#include <endian.h>
4039
#include <condition_variable>
4140
#include <list>
4241

include/ur_client_library/primary/package_header.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#include <inttypes.h>
3434
#include <cstddef>
35-
#include <endian.h>
3635
#include "ur_client_library/types.h"
3736

3837
namespace urcl
@@ -74,10 +73,7 @@ class PackageHeader
7473
*
7574
* \returns The size of the given serialized package
7675
*/
77-
static size_t getPackageLength(uint8_t* buf)
78-
{
79-
return be32toh(*(reinterpret_cast<_package_size_type*>(buf)));
80-
}
76+
static size_t getPackageLength(uint8_t* buf);
8177
};
8278
} // namespace primary_interface
8379
} // namespace urcl

include/ur_client_library/rtde/package_header.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#define UR_CLIENT_LIBRARY_RTDE__HEADER_H_INCLUDED
3232

3333
#include <cstddef>
34-
#include <endian.h>
3534
#include "ur_client_library/types.h"
3635
#include "ur_client_library/comm/package_serializer.h"
3736

@@ -71,10 +70,7 @@ class PackageHeader
7170
*
7271
* \returns The size of the given serialized package
7372
*/
74-
static size_t getPackageLength(uint8_t* buf)
75-
{
76-
return be16toh(*(reinterpret_cast<_package_size_type*>(buf)));
77-
}
73+
static size_t getPackageLength(uint8_t* buf);
7874

7975
/*!
8076
* \brief Creates a serialization of a header based on given values.

src/comm/bin_parser.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2026 Universal Robots A/S
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Rune Søe-Knudsen rsk@universal-robots.com
23+
* \date 2026-02-13
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#include <ur_client_library/comm/bin_parser.h>
29+
#include <endian/portable_endian.h>
30+
31+
namespace urcl
32+
{
33+
namespace comm
34+
{
35+
uint16_t BinParser::decode(uint16_t val)
36+
{
37+
return be16toh(val);
38+
}
39+
uint32_t BinParser::decode(uint32_t val)
40+
{
41+
return be32toh(val);
42+
}
43+
uint64_t BinParser::decode(uint64_t val)
44+
{
45+
return be64toh(val);
46+
}
47+
int16_t BinParser::decode(int16_t val)
48+
{
49+
return be16toh(val);
50+
}
51+
int32_t BinParser::decode(int32_t val)
52+
{
53+
return be32toh(val);
54+
}
55+
int64_t BinParser::decode(int64_t val)
56+
{
57+
return be64toh(val);
58+
}
59+
60+
} // namespace comm
61+
} // namespace urcl

src/comm/package_serializer.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2+
3+
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4+
// Copyright 2026 Universal Robots A/S
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
// -- END LICENSE BLOCK ------------------------------------------------
18+
19+
//----------------------------------------------------------------------
20+
/*!\file
21+
*
22+
* \author Rune Søe-Knudsen rsk@universal-robots.com
23+
* \date 2026-02-13
24+
*
25+
*/
26+
//----------------------------------------------------------------------
27+
28+
#include <ur_client_library/comm/package_serializer.h>
29+
#include <endian/portable_endian.h>
30+
31+
namespace urcl
32+
{
33+
namespace comm
34+
{
35+
uint16_t PackageSerializer::encode(uint16_t val)
36+
{
37+
return htobe16(val);
38+
}
39+
uint32_t PackageSerializer::encode(uint32_t val)
40+
{
41+
return htobe32(val);
42+
}
43+
uint64_t PackageSerializer::encode(uint64_t val)
44+
{
45+
return htobe64(val);
46+
}
47+
int16_t PackageSerializer::encode(int16_t val)
48+
{
49+
return htobe16(val);
50+
}
51+
int32_t PackageSerializer::encode(int32_t val)
52+
{
53+
return htobe32(val);
54+
}
55+
int64_t PackageSerializer::encode(int64_t val)
56+
{
57+
return htobe64(val);
58+
}
59+
60+
} // namespace comm
61+
} // namespace urcl

0 commit comments

Comments
 (0)