├── inc └── uxr │ └── client │ ├── core │ ├── session │ │ ├── time_sync.h │ │ ├── stream │ │ │ ├── seq_num.h │ │ │ ├── reliable_stream.h │ │ │ ├── input_best_effort_stream.h │ │ │ ├── output_best_effort_stream.h │ │ │ ├── output_reliable_stream.h │ │ │ ├── input_reliable_stream.h │ │ │ ├── stream_storage.h │ │ │ └── stream_id.h │ │ ├── object_id.h │ │ ├── common_create_entities.h │ │ └── session_info.h │ └── communication │ │ └── communication.h │ ├── profile │ ├── transport │ │ ├── ip │ │ │ ├── tcp │ │ │ │ ├── tcp_transport_external.h │ │ │ │ └── tcp_transport.h │ │ │ ├── udp │ │ │ │ ├── udp_transport_external.h │ │ │ │ └── udp_transport.h │ │ │ └── ip.h │ │ └── serial │ │ │ ├── serial_transport_external.h │ │ │ ├── serial_transport_posix.h │ │ │ ├── serial_transport_platform.h │ │ │ ├── serial_protocol.h │ │ │ └── serial_transport.h │ └── discovery │ │ └── discovery.h │ ├── defines.h │ ├── util │ └── time.h │ ├── visibility.h │ ├── client.h │ ├── config.h │ ├── transport.h │ └── config.h.in ├── docs ├── port.md ├── principle.md ├── figures │ └── micro-ROS_architecture.png ├── user-guide.md ├── version.md ├── README.md ├── introduction.md ├── api.md └── samples.md ├── src ├── ucdr │ ├── test │ │ ├── case │ │ │ ├── packaging │ │ │ │ ├── main.c │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── Packaging.cmake │ │ │ ├── installation │ │ │ │ └── InstallationTest.cmake │ │ │ └── CMakeLists.txt │ │ ├── serialization │ │ │ ├── StringSerialization.cpp │ │ │ ├── StringSerialization.hpp │ │ │ ├── BasicSerialization.cpp │ │ │ ├── ArraySerialization.cpp │ │ │ └── SequenceSerialization.cpp │ │ ├── cross_serialization │ │ │ ├── FastCDRSerialization.cpp │ │ │ └── FastCDRSerialization.hpp │ │ ├── FullBuffer.cpp │ │ ├── Alignment.cpp │ │ ├── CMakeLists.txt │ │ ├── SequenceOverflow.cpp │ │ ├── FullBufferCallback.cpp │ │ ├── fragmentation │ │ │ └── BasicFragmentation.cpp │ │ └── endianness │ │ │ └── BasicEndianness.cpp │ ├── .gitignore │ ├── colcon.pkg │ ├── ci │ │ ├── valgrind.supp │ │ ├── windows │ │ │ └── CMakeLists.txt │ │ └── linux │ │ │ └── CMakeLists.txt │ ├── valgrind.supp │ ├── examples │ │ ├── basic │ │ │ ├── CMakeLists.txt │ │ │ └── basic.c │ │ └── fragmentation │ │ │ ├── CMakeLists.txt │ │ │ └── fragmentation.c │ ├── include │ │ └── ucdr │ │ │ ├── config.h │ │ │ ├── config.h.in │ │ │ └── visibility.h │ ├── CTestConfig.cmake │ ├── cmake │ │ ├── packaging │ │ │ └── Config.cmake.in │ │ └── SuperBuild.cmake │ └── src │ │ └── c │ │ ├── common_internal.h │ │ └── types │ │ └── string.c ├── c │ ├── core │ │ ├── serialization │ │ │ ├── xrce_subheader.c │ │ │ ├── xrce_header.c │ │ │ ├── xrce_subheader_internal.h │ │ │ └── xrce_header_internal.h │ │ ├── session │ │ │ ├── object_id.c │ │ │ ├── stream │ │ │ │ ├── input_best_effort_stream.c │ │ │ │ ├── seq_num.c │ │ │ │ ├── seq_num_internal.h │ │ │ │ ├── input_best_effort_stream_internal.h │ │ │ │ ├── output_best_effort_stream_internal.h │ │ │ │ ├── stream_id.c │ │ │ │ ├── output_best_effort_stream.c │ │ │ │ ├── input_reliable_stream_internal.h │ │ │ │ ├── output_reliable_stream_internal.h │ │ │ │ ├── common_reliable_stream_internal.h │ │ │ │ └── stream_storage_internal.h │ │ │ ├── common_create_entities_internal.h │ │ │ ├── submessage.c │ │ │ ├── session_internal.h │ │ │ ├── session_info_internal.h │ │ │ ├── submessage_internal.h │ │ │ ├── common_create_entities.c │ │ │ └── write_access.c │ │ └── log │ │ │ └── log_internal.h │ ├── util │ │ ├── time_internal.h │ │ └── time.c │ └── profile │ │ ├── transport │ │ ├── ip │ │ │ ├── udp │ │ │ │ ├── udp_transport_internal.h │ │ │ │ ├── udp_transport.c │ │ │ │ └── udp_transport_external.c │ │ │ ├── tcp │ │ │ │ ├── tcp_transport_internal.h │ │ │ │ └── tcp_transport_external.c │ │ │ └── ip_posix.c │ │ └── serial │ │ │ ├── serial_transport_posix.c │ │ │ ├── serial_transport_external.c │ │ │ └── serial_protocol_internal.h │ │ └── discovery │ │ └── transport │ │ ├── udp_transport_datagram_posix.c │ │ ├── udp_transport_datagram_posix_nopoll.c │ │ ├── udp_transport_datagram_internal.h │ │ ├── udp_transport_datagram_windows.c │ │ └── udp_transport_datagram_freertos_plus_tcp.c └── SConscript ├── examples ├── msgs │ ├── Time.idl │ ├── Header.idl │ ├── Time.h │ ├── Header.h │ ├── Time.c │ └── Header.c └── SConscript ├── SConscript └── README.md /inc/uxr/client/core/session/time_sync.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/port.md: -------------------------------------------------------------------------------- 1 | # 移植说明 2 | 3 | > 在不同的硬件平台上使用,需要做的移植工作说明。 -------------------------------------------------------------------------------- /docs/principle.md: -------------------------------------------------------------------------------- 1 | # hello 工作原理 2 | 3 | > 介绍 hello 的工作原理 4 | -------------------------------------------------------------------------------- /src/ucdr/test/case/packaging/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /src/ucdr/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | examples/performance_cmp_versions 3 | .vscode 4 | .color_coded 5 | .ycm_extra_conf.py 6 | -------------------------------------------------------------------------------- /docs/figures/micro-ROS_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JcZou/Micro-XRCE-DDS-Client/HEAD/docs/figures/micro-ROS_architecture.png -------------------------------------------------------------------------------- /src/ucdr/colcon.pkg: -------------------------------------------------------------------------------- 1 | { 2 | "name": "microcdr", 3 | "type": "cmake", 4 | "cmake-args":[ 5 | "-DUCDR_ISOLATED_INSTALL=OFF" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /docs/user-guide.md: -------------------------------------------------------------------------------- 1 | # hello 使用说明 2 | 3 | > 简短说明 4 | 5 | ## 准备工作(可选) 6 | 7 | ## 背景信息(可选) 8 | 9 | ## 步骤一(可选) 10 | 11 | ## 步骤二(可选) 12 | 13 | ## 步骤三(可选) 14 | 15 | ## 预期结果(可选) 16 | 17 | ## 示例(可选) 18 | 19 | ## 完成后的操作(可选) 20 | 21 | ## 引用链接(可选) -------------------------------------------------------------------------------- /docs/version.md: -------------------------------------------------------------------------------- 1 | # 版本和修订 # 2 | 3 | | Date | Version | Author | Note | 4 | | -------- | :-----: | :---- | :---- | 5 | | 2018-04-28 | v0.1 | Armink | 初始版本 | 6 | | 2018-05-28 | v1.0 | Armink | 同步更新 | 7 | | | | | | -------------------------------------------------------------------------------- /examples/msgs/Time.idl: -------------------------------------------------------------------------------- 1 | // generated from rosidl_adapter/resource/msg.idl.em 2 | // with input from builtin_interfaces/msg/Time.msg 3 | // generated code does not contain a copyright notice 4 | 5 | 6 | struct Time { 7 | long sec; 8 | unsigned long nanosec; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /examples/msgs/Header.idl: -------------------------------------------------------------------------------- 1 | // generated from rosidl_adapter/resource/msg.idl.em 2 | // with input from std_msgs/msg/Header.msg 3 | // generated code does not contain a copyright notice 4 | 5 | #include "Time.idl" 6 | 7 | struct Header { 8 | Time stamp; 9 | string frame_id; 10 | }; 11 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # 文档 2 | 3 | ## 软件包地址 4 | 5 | - https://github.com/JcZou/Micro-XRCE-DDS-Client 6 | 7 | ## 文档列表 8 | 9 | |文件名 |描述| 10 | |:----- |:----| 11 | |[introduction.md](introduction.md) |详细介绍| 12 | |[samples.md](samples.md) |示例说明| 13 | 14 | -------------------------------------------------------------------------------- /examples/SConscript: -------------------------------------------------------------------------------- 1 | from building import * 2 | 3 | cwd = GetCurrentDir() 4 | src = Glob('*.c') + Glob('msgs/*.c') + Glob('*.cpp') 5 | CPPPATH = [cwd, cwd + '/msgs'] 6 | 7 | group = DefineGroup('Micro-XRCE-DDS-Client', src, depend = ['MICRO_XRCE_DDS_CLIENT_USING_EXAMPLE'], LOCAL_CPPPATH = CPPPATH) 8 | 9 | Return('group') 10 | -------------------------------------------------------------------------------- /src/ucdr/ci/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Leak 4 | match-leak-kinds: reachable 5 | fun:*alloc 6 | ... 7 | obj:*ld-* 8 | ... 9 | } 10 | { 11 | 12 | Memcheck:Leak 13 | fun:malloc 14 | fun:CRYPTO_zalloc 15 | ... 16 | obj:*libcrypto* 17 | } 18 | -------------------------------------------------------------------------------- /src/ucdr/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Leak 4 | match-leak-kinds: reachable 5 | fun:*alloc 6 | ... 7 | obj:*ld-* 8 | ... 9 | } 10 | { 11 | 12 | Memcheck:Leak 13 | fun:malloc 14 | fun:CRYPTO_zalloc 15 | ... 16 | obj:*libcrypto* 17 | } 18 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | # RT-Thread building script for bridge 2 | 3 | import os 4 | from building import * 5 | 6 | cwd = GetCurrentDir() 7 | objs = [] 8 | list = os.listdir(cwd) 9 | 10 | if GetDepend('PKG_USING_MICRO_XRCE_DDS_CLIENT'): 11 | for d in list: 12 | path = os.path.join(cwd, d) 13 | if os.path.isfile(os.path.join(path, 'SConscript')): 14 | objs = objs + SConscript(os.path.join(d, 'SConscript')) 15 | 16 | Return('objs') 17 | -------------------------------------------------------------------------------- /docs/introduction.md: -------------------------------------------------------------------------------- 1 | # Micro-XRCE-DDS-Client 介绍 2 | 3 | Micro-XRCE-DDS-Client是Micro-ROS的中间层通信组件,是一个主要针对嵌入式设备实现OMG DDS通信的开源的有线通信协议。DDS-XRCE协议的目的是为嵌入式设备提供访问DDS Global-Data-Space的能力。 4 | 5 | ## 软件架构 6 | 7 | ![Micro-ROS Architecture](./figures/micro-ROS_architecture.png) 8 | 9 | 该软件包主要包括icro-XRCE-DDS-Client的代码实现,作为桥梁跟ROS Agent进行通信。 10 | 11 | ## 功能 12 | 13 | 该软件包可以通过TCP,UDP,Serial链路来跟ROS进行消息的通信,主要通过发布/订阅机制。 14 | 通信链路的选择可以在`Micro-XRCE-DDS-Client/inc/uxr/client/config.h`进行配置 15 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/ip/tcp/tcp_transport_external.h: -------------------------------------------------------------------------------- 1 | #ifndef UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ 2 | #define UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | #include 11 | #include "netdb.h" 12 | #include 13 | 14 | typedef struct uxrTCPPlatform 15 | { 16 | int sock; 17 | } uxrTCPPlatform; 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/ip/udp/udp_transport_external.h: -------------------------------------------------------------------------------- 1 | #ifndef UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ 2 | #define UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | #include 11 | #include "netdb.h" 12 | #include 13 | 14 | typedef struct uxrUDPPlatform 15 | { 16 | int sock; 17 | } uxrUDPPlatform; 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/serial/serial_transport_external.h: -------------------------------------------------------------------------------- 1 | #ifndef UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ 2 | #define UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | // Place here your includes 10 | #include 11 | 12 | typedef struct uxrSerialPlatform 13 | { 14 | // Place here your platform data 15 | rt_device_t dev; 16 | } uxrSerialPlatform; 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ -------------------------------------------------------------------------------- /docs/api.md: -------------------------------------------------------------------------------- 1 | # Hello API 2 | 3 | ## 打招呼 4 | 5 | > 注意:对于函数介绍,必须遵循下面的格式 6 | 7 | `int hello_func(void)` 8 | 9 | > 在这里需要介绍 hello_func 函数的主要功能 10 | 11 | | 参数 | 描述 | 12 | |:------------------|:------------------------------------| 13 | |`无` | 无参数 | 14 | | **返回** | **描述** | 15 | |0 | 正确执行 | 16 | |-1 | 失败 | 17 | 18 | 示例(可选) 19 | 20 | ```c 21 | #include 22 | 23 | int func() 24 | { 25 | hello_func(); 26 | 27 | return 0; 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /src/ucdr/examples/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(basic_example) 2 | 3 | add_executable(${PROJECT_NAME} basic.c) 4 | if(MSVC OR MSVC_IDE) 5 | target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) 6 | endif() 7 | 8 | set_target_properties(${PROJECT_NAME} PROPERTIES 9 | C_STANDARD 99 10 | C_STANDARD_REQUIRED YES 11 | ) 12 | 13 | target_link_libraries(${PROJECT_NAME} microcdr) 14 | 15 | install(TARGETS ${PROJECT_NAME} 16 | RUNTIME DESTINATION examples/ucdr/${PROJECT_NAME}/${BIN_INSTALL_DIR} 17 | ) 18 | 19 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/ 20 | DESTINATION examples/ucdr/${PROJECT_NAME} 21 | FILES_MATCHING PATTERN "*.h" 22 | PATTERN "*.c" 23 | ) 24 | -------------------------------------------------------------------------------- /src/ucdr/examples/fragmentation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(fragmentation_example) 2 | 3 | add_executable(${PROJECT_NAME} fragmentation.c) 4 | if(MSVC OR MSVC_IDE) 5 | target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) 6 | endif() 7 | 8 | set_target_properties(${PROJECT_NAME} PROPERTIES 9 | C_STANDARD 99 10 | C_STANDARD_REQUIRED YES 11 | ) 12 | 13 | target_link_libraries(${PROJECT_NAME} microcdr) 14 | 15 | install(TARGETS ${PROJECT_NAME} 16 | RUNTIME DESTINATION examples/ucdr/${PROJECT_NAME}/${BIN_INSTALL_DIR} 17 | ) 18 | 19 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/ 20 | DESTINATION examples/ucdr/${PROJECT_NAME} 21 | FILES_MATCHING PATTERN "*.h" 22 | PATTERN "*.c" 23 | ) 24 | -------------------------------------------------------------------------------- /src/ucdr/test/serialization/StringSerialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "StringSerialization.hpp" 16 | 17 | TEST_F(StringSerialization, String) 18 | { 19 | string_serialization(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/c/core/serialization/xrce_subheader.c: -------------------------------------------------------------------------------- 1 | #include "xrce_subheader_internal.h" 2 | 3 | //================================================================== 4 | // PUBLIC 5 | //================================================================== 6 | void uxr_serialize_submessage_header(ucdrBuffer* ub, uint8_t id, uint8_t flags, uint16_t length) 7 | { 8 | (void) ucdr_serialize_uint8_t(ub, id); 9 | (void) ucdr_serialize_uint8_t(ub, flags); 10 | (void) ucdr_serialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, length); 11 | } 12 | 13 | void uxr_deserialize_submessage_header(ucdrBuffer* ub, uint8_t* id, uint8_t* flags, uint16_t* length) 14 | { 15 | (void) ucdr_deserialize_uint8_t(ub, id); 16 | (void) ucdr_deserialize_uint8_t(ub, flags); 17 | (void) ucdr_deserialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, length); 18 | } 19 | -------------------------------------------------------------------------------- /src/c/core/session/object_id.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //================================================================== 4 | // PUBLIC 5 | //================================================================== 6 | uxrObjectId uxr_object_id(uint16_t id, uint8_t type) 7 | { 8 | uxrObjectId object_id; 9 | object_id.id = id; 10 | object_id.type = type; 11 | return object_id; 12 | } 13 | 14 | uxrObjectId uxr_object_id_from_raw(const uint8_t* raw) 15 | { 16 | uxrObjectId object_id; 17 | object_id.id = (uint16_t)((((uint16_t)raw[0]) << 4) + (raw[1] >> 4)); 18 | object_id.type = raw[1] & 0x0F; 19 | return object_id; 20 | } 21 | 22 | void uxr_object_id_to_raw(uxrObjectId object_id, uint8_t* raw) 23 | { 24 | raw[0] = (uint8_t) (object_id.id >> 4); 25 | raw[1] = (uint8_t)((((uint8_t) (object_id.id)) << 4) + (object_id.type & 0x0F)); 26 | } 27 | -------------------------------------------------------------------------------- /src/c/core/session/stream/input_best_effort_stream.c: -------------------------------------------------------------------------------- 1 | #include "input_best_effort_stream_internal.h" 2 | #include "seq_num_internal.h" 3 | 4 | //================================================================== 5 | // PUBLIC 6 | //================================================================== 7 | void uxr_init_input_best_effort_stream(uxrInputBestEffortStream* stream) 8 | { 9 | stream->last_handled = SEQ_NUM_MAX; 10 | } 11 | 12 | void uxr_reset_input_best_effort_stream(uxrInputBestEffortStream* stream) 13 | { 14 | stream->last_handled = SEQ_NUM_MAX; 15 | } 16 | 17 | bool uxr_receive_best_effort_message(uxrInputBestEffortStream* stream, uxrSeqNum seq_num) 18 | { 19 | bool available_to_read = (0 > uxr_seq_num_cmp(stream->last_handled, seq_num)); 20 | if(available_to_read) 21 | { 22 | stream->last_handled = seq_num; 23 | } 24 | 25 | return available_to_read; 26 | } 27 | -------------------------------------------------------------------------------- /inc/uxr/client/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_DEFINES_H_ 16 | #define _UXR_CLIENT_DEFINES_H_ 17 | 18 | #ifdef __cplusplus 19 | #define COMPOUND_LITERAL(x) x 20 | #else 21 | #define COMPOUND_LITERAL(x) (x) 22 | #endif 23 | 24 | #endif // _UXR_CLIENT_DEFINES_H_ 25 | -------------------------------------------------------------------------------- /src/ucdr/test/cross_serialization/FastCDRSerialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "FastCDRSerialization.hpp" 16 | 17 | TEST_F(FastCDRSerialization, double_sequence_with_aligment_serialization) 18 | { 19 | double_sequence_with_aligment_serialization(); 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/ucdr/test/case/packaging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) 16 | 17 | project(packaging LANGUAGES C) 18 | 19 | find_package(microcdr EXACT ${REQUIRED_VERSION} REQUIRED) 20 | 21 | add_executable(${PROJECT_NAME} main.c) 22 | 23 | target_link_libraries(${PROJECT_NAME} microcdr) -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/seq_num.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_STREAM_SEQ_NUM_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_STREAM_SEQ_NUM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | typedef uint16_t uxrSeqNum; 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // _UXR_CLIENT_CORE_SESSION_STREAM_SEQ_NUM_H_ 32 | -------------------------------------------------------------------------------- /src/ucdr/include/ucdr/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _MICROCDR_CONFIG_H_ 16 | #define _MICROCDR_CONFIG_H_ 17 | 18 | // Version defines 19 | #define MICROCDR_VERSION_MAJOR 1 20 | #define MICROCDR_VERSION_MINOR 2 21 | #define MICROCDR_VERSION_MICRO 0 22 | #define MICROCDR_VERSION_STR "1.2.0" 23 | 24 | // ucdrEndianness defines 25 | #define UCDR_MACHINE_ENDIANNESS UCDR_LITTLE_ENDIANNESS 26 | 27 | #endif // _MICROCDR_CONFIG_H_ 28 | -------------------------------------------------------------------------------- /inc/uxr/client/util/time.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_UTIL_TIME_H_ 16 | #define UXR_CLIENT_UTIL_TIME_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | UXRDLLAPI int64_t uxr_millis(void); 27 | 28 | UXRDLLAPI int64_t uxr_nanos(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif // UXR_CLIENT_UTIL_TIME_H_ 35 | -------------------------------------------------------------------------------- /src/ucdr/test/case/installation/InstallationTest.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Check directories. 16 | set(_directories "lib" "include" "share") 17 | foreach(_dir ${_directories}) 18 | if(NOT EXISTS ${INSTALL_PATH}/${_dir}) 19 | message(FATAL_ERROR "Directory ${_dir} not found.") 20 | endif() 21 | endforeach() 22 | 23 | # Check library. 24 | if(NOT EXISTS ${INSTALL_PATH}/lib/${LIBRARY_NAME}) 25 | message(FATAL_ERROR "Library lib/${LIBRARY_NAME} not found.") 26 | endif() -------------------------------------------------------------------------------- /src/c/util/time_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SRC_C_UTIL_TIME_H_ 16 | #define SRC_C_UTIL_TIME_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | static inline int64_t uxr_convert_to_nanos(int32_t sec, uint32_t nsec) 27 | { 28 | return ((int64_t)sec * 1000000000) + nsec; 29 | } 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif // SRC_C_UTIL_TIME_H_ 36 | -------------------------------------------------------------------------------- /src/ucdr/include/ucdr/config.h.in: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _MICROCDR_CONFIG_H_ 16 | #define _MICROCDR_CONFIG_H_ 17 | 18 | // Version defines 19 | #define MICROCDR_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 20 | #define MICROCDR_VERSION_MINOR @PROJECT_VERSION_MINOR@ 21 | #define MICROCDR_VERSION_MICRO @PROJECT_VERSION_PATCH@ 22 | #define MICROCDR_VERSION_STR "@PROJECT_VERSION@" 23 | 24 | // ucdrEndianness defines 25 | #define UCDR_MACHINE_ENDIANNESS @CONFIG_MACHINE_ENDIANNESS@ 26 | 27 | #endif // _MICROCDR_CONFIG_H_ 28 | -------------------------------------------------------------------------------- /src/ucdr/CTestConfig.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 16 | # MemoryCheck configuration. 17 | find_program(MEMORYCHECK_COMMAND NAMES valgrind) 18 | set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --quiet --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=50 --xml=yes --xml-file=test_%p_memcheck.xml \"--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/ci/valgrind.supp\"") 19 | 20 | # Coverage configuration. 21 | find_program(COVERAGE_COMMAND NAMES gcov) 22 | endif() -------------------------------------------------------------------------------- /src/ucdr/include/ucdr/visibility.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #ifndef _MICROCDR_VISIBILITY_H_ 17 | #define _MICROCDR_VISIBILITY_H_ 18 | 19 | #if defined(_WIN32) 20 | #if defined(microcdr_SHARED) 21 | #if defined(microcdr_EXPORTS) 22 | #define UCDRDLLAPI __declspec( dllexport ) 23 | #else 24 | #define UCDRDLLAPI __declspec( dllimport ) 25 | #endif // microcdr_EXPORTS 26 | #else 27 | #define UCDRDLLAPI 28 | #endif // BUILDING_SHARED_LIBS 29 | #else 30 | #define UCDRDLLAPI 31 | #endif // _WIN32 32 | 33 | #endif // _MICROCDR_VISIBILITY_H_ 34 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/serial/serial_transport_posix.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIALTRANSPORTPOSIX_H_ 16 | #define UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIALTRANSPORTPOSIX_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | typedef struct uxrSerialPlatform 26 | { 27 | struct pollfd poll_fd; 28 | 29 | } uxrSerialPlatform; 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif // UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIALTRANSPORTPOSIX_H_ 36 | -------------------------------------------------------------------------------- /inc/uxr/client/visibility.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #ifndef _UXR_CLIENT_VISIBILITY_H_ 17 | #define _UXR_CLIENT_VISIBILITY_H_ 18 | 19 | #if defined(_WIN32) 20 | #if defined(microxrcedds_client_SHARED) 21 | #if defined(microxrcedds_client_EXPORTS) 22 | #define UXRDLLAPI __declspec( dllexport ) 23 | #else 24 | #define UXRDLLAPI __declspec( dllimport ) 25 | #endif // micro_xrce_client_dds_EXPORTS 26 | #else 27 | #define UXRDLLAPI 28 | #endif // BUILDING_SHARED_LIBS 29 | #else 30 | #define UXRDLLAPI 31 | #endif // _WIN32 32 | 33 | #endif // _UXR_CLIENT_VISIBILITY_H_ 34 | -------------------------------------------------------------------------------- /src/c/core/session/stream/seq_num.c: -------------------------------------------------------------------------------- 1 | #include "seq_num_internal.h" 2 | 3 | #include 4 | #define SEQ_NUM_SIZE (1 << 16) 5 | #define SEQ_NUM_MIDSIZE (SEQ_NUM_SIZE >> 1) 6 | 7 | //================================================================== 8 | // PUBLIC 9 | //================================================================== 10 | uxrSeqNum uxr_seq_num_add(uxrSeqNum seq_num, uint16_t increment) 11 | { 12 | return (uxrSeqNum)((seq_num + increment) % SEQ_NUM_SIZE); 13 | } 14 | 15 | uxrSeqNum uxr_seq_num_sub(uxrSeqNum seq_num, uint16_t decrement) 16 | { 17 | return (uxrSeqNum)((decrement > seq_num) 18 | ? seq_num + (SEQ_NUM_SIZE - decrement) 19 | : seq_num - decrement); 20 | } 21 | 22 | int uxr_seq_num_cmp(uxrSeqNum seq_num_1, uxrSeqNum seq_num_2) 23 | { 24 | int result; 25 | if(seq_num_1 == seq_num_2) 26 | { 27 | result = 0; 28 | } 29 | else if((seq_num_1 < seq_num_2 && (seq_num_2 - seq_num_1) < SEQ_NUM_MIDSIZE) || 30 | (seq_num_1 > seq_num_2 && (seq_num_1 - seq_num_2) > SEQ_NUM_MIDSIZE)) 31 | { 32 | result = -1; 33 | } 34 | else 35 | { 36 | result = 1; 37 | } 38 | return result; 39 | } 40 | -------------------------------------------------------------------------------- /src/c/core/serialization/xrce_header.c: -------------------------------------------------------------------------------- 1 | #include "xrce_header_internal.h" 2 | 3 | //================================================================== 4 | // PUBLIC 5 | //================================================================== 6 | void uxr_serialize_message_header(ucdrBuffer* ub, uint8_t session_id, uint8_t stream_id, uint16_t seq_num, const uint8_t* key) 7 | { 8 | (void) ucdr_serialize_uint8_t(ub, session_id); 9 | (void) ucdr_serialize_uint8_t(ub, stream_id); 10 | (void) ucdr_serialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, seq_num); 11 | if(SESSION_ID_WITHOUT_CLIENT_KEY > session_id) 12 | { 13 | (void) ucdr_serialize_array_uint8_t(ub, key, CLIENT_KEY_SIZE); 14 | } 15 | } 16 | 17 | void uxr_deserialize_message_header(ucdrBuffer* ub, uint8_t* session_id, uint8_t* stream_id, uint16_t* seq_num, uint8_t* key) 18 | { 19 | (void) ucdr_deserialize_uint8_t(ub, session_id); 20 | (void) ucdr_deserialize_uint8_t(ub, stream_id); 21 | (void) ucdr_deserialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, seq_num); 22 | if(SESSION_ID_WITHOUT_CLIENT_KEY > *session_id) 23 | { 24 | (void) ucdr_deserialize_array_uint8_t(ub, key, CLIENT_KEY_SIZE); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/ucdr/cmake/packaging/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@) 16 | 17 | @PACKAGE_INIT@ 18 | 19 | if((MSVC OR MSVC_IDE) AND EXISTS "@PACKAGE_BIN_INSTALL_DIR@") 20 | set_and_check(@PROJECT_NAME@_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@") 21 | endif() 22 | set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 23 | set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") 24 | set_and_check(@PROJECT_NAME@_DATA_DIR "@PACKAGE_DATA_INSTALL_DIR@") 25 | 26 | include(${@PROJECT_NAME@_DATA_DIR}/@PROJECT_NAME@/cmake/@PROJECT_NAME@Targets.cmake) 27 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/reliable_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR__CLIENT__CORE__SESSION__STREAM__RELIABLE_STREAM_H_ 16 | #define UXR__CLIENT__CORE__SESSION__STREAM__RELIABLE_STREAM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | typedef struct uxrReliableStream 27 | { 28 | uint8_t * buffer; 29 | size_t size; 30 | uint16_t history; 31 | 32 | } uxrReliableStream; 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // UXR__CLIENT__CORE__SESSION__STREAM__RELIABLE_STREAM_H_ 39 | -------------------------------------------------------------------------------- /src/c/core/serialization/xrce_subheader_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SERIALIZATION_SUBHEADER_H_ 16 | #define _SRC_C_CORE_SERIALIZATION_SUBHEADER_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | void uxr_serialize_submessage_header(ucdrBuffer* buffer, uint8_t id, uint8_t flags, uint16_t length); 28 | void uxr_deserialize_submessage_header(ucdrBuffer* buffer, uint8_t* id, uint8_t* flags, uint16_t* length); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif // _SRC_C_CORE_SERIALIZATION_SUBHEADER_H_ 35 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/input_best_effort_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_STREAM_INPUT_BEST_EFFORT_STREAM_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_STREAM_INPUT_BEST_EFFORT_STREAM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | typedef struct uxrInputBestEffortStream 29 | { 30 | uxrSeqNum last_handled; 31 | 32 | } uxrInputBestEffortStream; 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // _UXR_CLIENT_CORE_SESSION_STREAM_INPUT_BEST_EFFORT_STREAM_H_ 39 | -------------------------------------------------------------------------------- /inc/uxr/client/client.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CLIENT_H_ 16 | #define _UXR_CLIENT_CLIENT_H_ 17 | 18 | #include 19 | 20 | #ifdef UCLIENT_PROFILE_DISCOVERY 21 | #include 22 | #endif //UCLIENT_PROFILE_DISCOVERY 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #endif // _UXR_CLIENT_CLIENT_H_ 33 | -------------------------------------------------------------------------------- /src/c/core/session/stream/seq_num_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_STREAM_SEQ_NUM_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_STREAM_SEQ_NUM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | 24 | #include 25 | 26 | #define SEQ_NUM_MAX UINT16_MAX 27 | 28 | uxrSeqNum uxr_seq_num_add(uxrSeqNum seq_num, uint16_t increment); 29 | uxrSeqNum uxr_seq_num_sub(uxrSeqNum seq_num, uint16_t decrement); 30 | int uxr_seq_num_cmp(uxrSeqNum seq_num_1, uxrSeqNum seq_num_2); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif // _SRC_C_CORE_SESSION_STREAM_SEQ_NUM_INTERNAL_H_ 37 | -------------------------------------------------------------------------------- /src/ucdr/test/case/packaging/Packaging.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | execute_process( 16 | COMMAND 17 | ${CMAKE_COMMAND} ${ORIGINAL_DIR} 18 | -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} 19 | -DREQUIRED_VERSION=${REQUIRED_VERSION} 20 | -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} 21 | -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} 22 | RESULT_VARIABLE _result 23 | ) 24 | 25 | if(_result) 26 | message(FATAL_ERROR "Error in find_package.") 27 | endif() 28 | 29 | execute_process( 30 | COMMAND 31 | ${CMAKE_COMMAND} --build . 32 | RESULT_VARIABLE _result 33 | ) 34 | 35 | if(_result) 36 | message(FATAL_ERROR "Error compiling example.") 37 | endif() -------------------------------------------------------------------------------- /src/SConscript: -------------------------------------------------------------------------------- 1 | Import('rtconfig') 2 | from building import * 3 | 4 | cwd = GetCurrentDir() 5 | 6 | # micro-xrce-dds-client 7 | src = Glob('c/core/log/*.c') 8 | src += Glob('c/core/serialization/*.c') 9 | src += Glob('c/core/session/*.c') 10 | src += Glob('c/core/session/stream/*.c') 11 | src += Glob('c/profile/transport/serial/serial_transport_external.c') 12 | src += Glob('c/profile/transport/serial/serial_transport.c') 13 | src += Glob('c/profile/transport/serial/serial_protocol.c') 14 | src += Glob('c/profile/transport/ip/udp/udp_transport_external.c') 15 | src += Glob('c/profile/transport/ip/udp/udp_transport.c') 16 | src += Glob('c/profile/transport/ip/tcp/tcp_transport_external.c') 17 | src += Glob('c/profile/transport/ip/tcp/tcp_transport.c') 18 | src += Glob('c/util/*.c') 19 | # ucdr 20 | src += Glob('ucdr/src/c/*.c') 21 | src += Glob('ucdr/src/c/types/*.c') 22 | 23 | CPPPATH = [cwd + '/../inc', 24 | cwd + '/c/core/log', 25 | cwd + '/c/core/serialization', 26 | cwd + '/c/core/session', 27 | cwd + '/c/core/session/stream', 28 | cwd + '/c/profile/transport/serial', 29 | cwd + '/c/profile/transport/ip/udp', 30 | cwd + '/c/profile/transport/ip/tcp', 31 | cwd + '/c/util', 32 | cwd + '/ucdr/src/c', 33 | cwd + '/ucdr/include'] 34 | 35 | group = DefineGroup('Micro-XRCE-DDS-Client', src, depend = ['PKG_USING_MICRO_XRCE_DDS_CLIENT'], CPPPATH = CPPPATH) 36 | 37 | Return('group') 38 | -------------------------------------------------------------------------------- /src/c/core/session/common_create_entities_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_COMMON_CREATE_ENTITIES_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_COMMON_CREATE_ENTITIES_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | struct CREATE_Payload; 26 | 27 | uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, 28 | uxrObjectId object_id, uint16_t xml_ref_size, uint8_t mode, 29 | struct CREATE_Payload* payload); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif //_SRC_C_CORE_SESSION_COMMON_CREATE_ENTITIES_INTERNAL_H_ 36 | -------------------------------------------------------------------------------- /src/ucdr/src/c/common_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_COMMON_INTERNAL_H_ 16 | #define _SRC_COMMON_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | 24 | // ------------------------------------------------------------------- 25 | // INTERNAL UTIL FUNCTIONS 26 | // ------------------------------------------------------------------- 27 | bool ucdr_check_buffer_available_for(ucdrBuffer* ub, size_t bytes); 28 | bool ucdr_check_final_buffer_behavior(ucdrBuffer* ub, size_t bytes); 29 | size_t ucdr_check_final_buffer_behavior_array(ucdrBuffer* ub, size_t bytes, size_t data_size); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif //_SRC_COMMON_INTERNAL_H_ 36 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/output_best_effort_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | struct ucdrBuffer; 29 | typedef struct uxrOutputBestEffortStream 30 | { 31 | uint8_t* buffer; 32 | size_t writer; 33 | size_t size; 34 | uint8_t offset; 35 | 36 | uxrSeqNum last_send; 37 | 38 | } uxrOutputBestEffortStream; 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif // _UXR_CLIENT_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_H 45 | -------------------------------------------------------------------------------- /src/c/core/session/submessage.c: -------------------------------------------------------------------------------- 1 | #include "submessage_internal.h" 2 | #include "../serialization/xrce_subheader_internal.h" 3 | 4 | //================================================================== 5 | // PUBLIC 6 | //================================================================== 7 | bool uxr_buffer_submessage_header(ucdrBuffer* ub, uint8_t submessage_id, uint16_t length, uint8_t flags) 8 | { 9 | ucdr_align_to(ub, 4); 10 | ub->endianness = UCDR_MACHINE_ENDIANNESS; 11 | flags = (uint8_t)(flags | ub->endianness); 12 | uxr_serialize_submessage_header(ub, submessage_id, flags, length); 13 | 14 | return ucdr_buffer_remaining(ub) >= length; 15 | } 16 | 17 | bool uxr_read_submessage_header(ucdrBuffer* ub, uint8_t* submessage_id, uint16_t* length, uint8_t* flags) 18 | { 19 | ucdr_align_to(ub, 4); 20 | bool ready_to_read = ucdr_buffer_remaining(ub) >= SUBHEADER_SIZE; 21 | if(ready_to_read) 22 | { 23 | uxr_deserialize_submessage_header(ub, submessage_id, flags, length); 24 | 25 | uint8_t endiannes_flag = *flags & FLAG_ENDIANNESS; 26 | *flags = (uint8_t)(*flags & ~endiannes_flag); 27 | ub->endianness = endiannes_flag ? UCDR_LITTLE_ENDIANNESS : UCDR_BIG_ENDIANNESS; 28 | } 29 | 30 | return ready_to_read; 31 | } 32 | 33 | size_t uxr_submessage_padding(size_t length) 34 | { 35 | return (length % SUBHEADER_SIZE != 0) ? SUBHEADER_SIZE - (length % SUBHEADER_SIZE) : 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/c/core/session/session_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_SESSION_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_SESSION_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | struct ucdrBuffer; 26 | 27 | bool uxr_prepare_stream_to_write_submessage(uxrSession* session, 28 | uxrStreamId stream_id, 29 | size_t payload_size, 30 | struct ucdrBuffer* ub, 31 | uint8_t submessage_id, 32 | uint8_t mode); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // _SRC_C_CORE_SESSION_SESSION_INTERNAL_H_ 39 | 40 | -------------------------------------------------------------------------------- /src/c/core/serialization/xrce_header_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SERIALIZATION_XRCE_HEADER_INTERNAL_H_ 16 | #define _SRC_C_CORE_SERIALIZATION_XRCE_HEADER_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #define CLIENT_KEY_SIZE 4 28 | 29 | #define SESSION_ID_WITH_CLIENT_KEY 0x00 30 | #define SESSION_ID_WITHOUT_CLIENT_KEY 0x80 31 | 32 | void uxr_serialize_message_header(ucdrBuffer* ub, uint8_t session_id, uint8_t stream_id, uint16_t seq_num, const uint8_t* key); 33 | void uxr_deserialize_message_header(ucdrBuffer* ub, uint8_t* session_id, uint8_t* stream_id, uint16_t* seq_num, uint8_t* key); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif // _SRC_C_CORE_SERIALIZATION_XRCE_HEADER_INTERNAL_H_ 40 | -------------------------------------------------------------------------------- /src/c/core/session/stream/input_best_effort_stream_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_INPUT_STREAM_BEST_EFFORT_STREAM_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_INPUT_STREAM_BEST_EFFORT_STREAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | void uxr_init_input_best_effort_stream(uxrInputBestEffortStream* stream); 30 | void uxr_reset_input_best_effort_stream(uxrInputBestEffortStream* stream); 31 | bool uxr_receive_best_effort_message(uxrInputBestEffortStream* stream, uxrSeqNum seq_num); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // _SRC_C_CORE_SESSION_INPUT_STREAM_BEST_EFFORT_STREAM_INTERNAL_H_ 38 | -------------------------------------------------------------------------------- /src/ucdr/test/serialization/StringSerialization.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _STRING_SERIALIZATION_HPP_ 16 | #define _STRING_SERIALIZATION_HPP_ 17 | 18 | #include "BasicSerialization.hpp" 19 | 20 | #define MAX_STRING_LENGTH 64 21 | 22 | class StringSerialization : public BasicSerialization 23 | { 24 | public: 25 | StringSerialization() 26 | { 27 | } 28 | 29 | virtual ~StringSerialization() 30 | { 31 | } 32 | 33 | void string_serialization() 34 | { 35 | char input[MAX_STRING_LENGTH] = "This is a message test"; 36 | char output[MAX_STRING_LENGTH] = {0}; 37 | 38 | EXPECT_TRUE(ucdr_serialize_string(&writer, input)); 39 | EXPECT_TRUE(ucdr_deserialize_string(&reader, output, MAX_STRING_LENGTH)); 40 | 41 | EXPECT_STREQ(input, output); 42 | } 43 | }; 44 | 45 | #endif //_STRING_SERIALIZATION_HPP_ 46 | -------------------------------------------------------------------------------- /src/ucdr/test/case/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_test( 16 | NAME 17 | test-case-installation 18 | COMMAND 19 | ${CMAKE_COMMAND} 20 | -DINSTALL_PATH=${CMAKE_INSTALL_PREFIX} 21 | -DLIBRARY_NAME=$ 22 | -P ${CMAKE_CURRENT_SOURCE_DIR}/installation/InstallationTest.cmake 23 | ) 24 | 25 | add_test( 26 | NAME 27 | test-case-packaging 28 | COMMAND 29 | ${CMAKE_COMMAND} 30 | -DORIGINAL_DIR=${CMAKE_CURRENT_SOURCE_DIR}/packaging 31 | -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} 32 | -DREQUIRED_VERSION=${PROJECT_VERSION} 33 | -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} 34 | -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} 35 | -P ${CMAKE_CURRENT_SOURCE_DIR}/packaging/Packaging.cmake 36 | ) -------------------------------------------------------------------------------- /inc/uxr/client/core/communication/communication.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_COMMUNICATION_COMMUNICATION_H_ 16 | #define _UXR_CLIENT_CORE_COMMUNICATION_COMMUNICATION_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | typedef bool (*send_msg_func)(void* instance, const uint8_t* buf, size_t len); 28 | typedef bool (*recv_msg_func)(void* instance, uint8_t** buf, size_t* len, int timeout); 29 | typedef uint8_t (*comm_error_func)(void); 30 | 31 | typedef struct uxrCommunication 32 | { 33 | void* instance; 34 | send_msg_func send_msg; 35 | recv_msg_func recv_msg; 36 | comm_error_func comm_error; 37 | uint16_t mtu; 38 | 39 | } uxrCommunication; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif //_UXR_CLIENT_CORE_COMMUNICATION_COMMUNICATION_H_ 46 | -------------------------------------------------------------------------------- /src/ucdr/examples/basic/basic.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #define BUFFER_LENGTH 256 19 | 20 | int main() 21 | { 22 | // Data buffer 23 | uint8_t buffer[BUFFER_LENGTH]; 24 | 25 | // Structs for handle the buffer. 26 | ucdrBuffer writer; 27 | ucdrBuffer reader; 28 | 29 | // Initialize the MicroBuffers for working with an user-managed buffer. 30 | ucdr_init_buffer(&writer, buffer, BUFFER_LENGTH); 31 | ucdr_init_buffer(&reader, buffer, BUFFER_LENGTH); 32 | 33 | // Serialize data 34 | char input[16] = "Hello MicroCDR!"; //16 characters 35 | ucdr_serialize_array_char(&writer, input, 16); 36 | 37 | // Deserialize data 38 | char output[16]; 39 | ucdr_deserialize_array_char(&reader, output, 16); 40 | 41 | printf("Input: %s\n", input); 42 | printf("Output: %s\n", output); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/ucdr/ci/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) 16 | 17 | project(microcdr_ci LANGUAGES C CXX) 18 | 19 | include(ExternalProject) 20 | 21 | ExternalProject_Add(microcdr 22 | SOURCE_DIR 23 | ${CMAKE_CURRENT_SOURCE_DIR}/../../ 24 | BINARY_DIR 25 | ${PROJECT_BINARY_DIR}/microcdr-build 26 | INSTALL_DIR 27 | ${PROJECT_BINARY_DIR}/temp_install 28 | TEST_AFTER_INSTALL 29 | TRUE 30 | TEST_COMMAND 31 | COMMAND ${CMAKE_CTEST_COMMAND} -VV -C ${CMAKE_BUILD_TYPE} -T Test 32 | CMAKE_CACHE_ARGS 33 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 34 | -DCMAKE_GENERATOR_TOOLSET:STRING=${CMAKE_GENERATOR_TOOLSET} 35 | -DCMAKE_GENERATOR_PLATFORM:STRING=${CMAKE_GENERATOR_PLATFORM} 36 | -DCMAKE_INSTALL_PREFIX:PATH= 37 | -DUCDR_BUILD_CI_TESTS:BOOL=ON 38 | -DGTEST_INDIVIDUAL:BOOL=ON 39 | ) -------------------------------------------------------------------------------- /examples/msgs/Time.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /*! 16 | * @file Time.h 17 | * This header file contains the declaration of the described types in the IDL file. 18 | * 19 | * This file was generated by the tool gen. 20 | */ 21 | 22 | #ifndef _Time_H_ 23 | #define _Time_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | /*! 34 | * @brief This struct represents the structure Time defined by the user in the IDL file. 35 | * @ingroup TIME 36 | */ 37 | typedef struct Time 38 | { 39 | int32_t sec; 40 | uint32_t nanosec; 41 | } Time; 42 | 43 | struct ucdrBuffer; 44 | 45 | bool Time_serialize_topic(struct ucdrBuffer* writer, const Time* topic); 46 | bool Time_deserialize_topic(struct ucdrBuffer* reader, Time* topic); 47 | uint32_t Time_size_of_topic(const Time* topic, uint32_t size); 48 | 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif // _Time_H_ -------------------------------------------------------------------------------- /examples/msgs/Header.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /*! 16 | * @file Header.h 17 | * This header file contains the declaration of the described types in the IDL file. 18 | * 19 | * This file was generated by the tool gen. 20 | */ 21 | 22 | #ifndef _Header_H_ 23 | #define _Header_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #include 31 | #include 32 | #include "Time.h" 33 | 34 | /*! 35 | * @brief This struct represents the structure Header defined by the user in the IDL file. 36 | * @ingroup HEADER 37 | */ 38 | typedef struct Header 39 | { 40 | Time stamp; 41 | char frame_id[255]; 42 | 43 | } Header; 44 | 45 | struct ucdrBuffer; 46 | 47 | bool Header_serialize_topic(struct ucdrBuffer* writer, const Header* topic); 48 | bool Header_deserialize_topic(struct ucdrBuffer* reader, Header* topic); 49 | uint32_t Header_size_of_topic(const Header* topic, uint32_t size); 50 | 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif // _Header_H_ -------------------------------------------------------------------------------- /examples/msgs/Time.c: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /*! 16 | * @file Time.c 17 | * This source file contains the definition of the described types in the IDL file. 18 | * 19 | * This file was generated by the tool gen. 20 | */ 21 | 22 | #include "Time.h" 23 | 24 | #include 25 | #include 26 | 27 | bool Time_serialize_topic(ucdrBuffer* writer, const Time* topic) 28 | { 29 | (void) ucdr_serialize_int32_t(writer, topic->sec); 30 | 31 | (void) ucdr_serialize_uint32_t(writer, topic->nanosec); 32 | 33 | return !writer->error; 34 | } 35 | 36 | bool Time_deserialize_topic(ucdrBuffer* reader, Time* topic) 37 | { 38 | (void) ucdr_deserialize_int32_t(reader, &topic->sec); 39 | 40 | (void) ucdr_deserialize_uint32_t(reader, &topic->nanosec); 41 | 42 | return !reader->error; 43 | } 44 | 45 | uint32_t Time_size_of_topic(const Time* topic, uint32_t size) 46 | { 47 | uint32_t previousSize = size; 48 | size += ucdr_alignment(size, 4) + 4; 49 | 50 | size += ucdr_alignment(size, 4) + 4; 51 | 52 | return size - previousSize; 53 | } 54 | -------------------------------------------------------------------------------- /src/c/core/session/stream/output_best_effort_stream_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8_t* buffer, size_t size, uint8_t offset); 30 | void uxr_reset_output_best_effort_stream(uxrOutputBestEffortStream* stream); 31 | bool uxr_prepare_best_effort_buffer_to_write(uxrOutputBestEffortStream* stream, size_t size, struct ucdrBuffer* ub); 32 | bool uxr_prepare_best_effort_buffer_to_send(uxrOutputBestEffortStream* stream, uint8_t** buffer, size_t* length, uint16_t* seq_num); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif // _SRC_C_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_INTERNAL_H_ 39 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/object_id.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_OBJECT_ID_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_OBJECT_ID_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #define UXR_INVALID_ID 0x00 27 | #define UXR_PARTICIPANT_ID 0x01 28 | #define UXR_TOPIC_ID 0x02 29 | #define UXR_PUBLISHER_ID 0x03 30 | #define UXR_SUBSCRIBER_ID 0x04 31 | #define UXR_DATAWRITER_ID 0x05 32 | #define UXR_DATAREADER_ID 0x06 33 | #define UXR_REQUESTER_ID 0x07 34 | #define UXR_REPLIER_ID 0x08 35 | #define UXR_OTHER_ID 0x0F 36 | 37 | typedef struct uxrObjectId 38 | { 39 | uint16_t id; 40 | uint8_t type; 41 | 42 | } uxrObjectId; 43 | 44 | UXRDLLAPI uxrObjectId uxr_object_id(uint16_t id, uint8_t type); 45 | 46 | UXRDLLAPI uxrObjectId uxr_object_id_from_raw(const uint8_t* raw); 47 | UXRDLLAPI void uxr_object_id_to_raw(uxrObjectId object_id, uint8_t* raw); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif //_UXR_CLIENT_CORE_SESSION_OBJECT_ID_H_ 54 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/udp/udp_transport_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SRC_C_PROFILE_TRANSPORT_UDP_UDP_TRANSPORT_INTERNAL_H_ 16 | #define SRC_C_PROFILE_TRANSPORT_UDP_UDP_TRANSPORT_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | bool uxr_init_udp_platform( 26 | struct uxrUDPPlatform* platform, 27 | uxrIpProtocol ip_protocol, 28 | const char* ip, 29 | const char* port); 30 | 31 | bool uxr_close_udp_platform( 32 | struct uxrUDPPlatform* platform); 33 | 34 | size_t uxr_write_udp_data_platform( 35 | struct uxrUDPPlatform* platform, 36 | const uint8_t* buf, 37 | size_t len, 38 | uint8_t* errcode); 39 | 40 | size_t uxr_read_udp_data_platform( 41 | struct uxrUDPPlatform* platform, 42 | uint8_t* buf, 43 | size_t len, 44 | int timeout, 45 | uint8_t* errcode); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif // SRC_C_PROFILE_TRANSPORT_UDP_UDP_TRANSPORT_INTERNAL_H_ 52 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/output_reliable_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR__CLIENT__CORE__SESSION__STREAM__OUTPUT_RELIABLE_STREAM_H_ 16 | #define UXR__CLIENT__CORE__SESSION__STREAM__OUTPUT_RELIABLE_STREAM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | struct ucdrBuffer; 29 | struct uxrOutputReliableStream; 30 | 31 | typedef void (*OnNewFragment)(struct ucdrBuffer* ub, struct uxrOutputReliableStream* stream); 32 | 33 | typedef struct uxrOutputReliableStream 34 | { 35 | uxrReliableStream base; 36 | uint8_t offset; 37 | 38 | uxrSeqNum last_written; 39 | uxrSeqNum last_sent; 40 | uxrSeqNum last_acknown; 41 | 42 | int64_t next_heartbeat_timestamp; 43 | uint8_t next_heartbeat_tries; 44 | bool send_lost; 45 | 46 | } uxrOutputReliableStream; 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif // UXR__CLIENT__CORE__SESSION__STREAM__OUTPUT_RELIABLE_STREAM_H_ 53 | -------------------------------------------------------------------------------- /examples/msgs/Header.c: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /*! 16 | * @file Header.c 17 | * This source file contains the definition of the described types in the IDL file. 18 | * 19 | * This file was generated by the tool gen. 20 | */ 21 | 22 | #include "Header.h" 23 | 24 | #include 25 | #include 26 | 27 | bool Header_serialize_topic(ucdrBuffer* writer, const Header* topic) 28 | { 29 | (void) Time_serialize_topic(writer, &topic->stamp); 30 | (void) ucdr_serialize_string(writer, topic->frame_id); 31 | 32 | return !writer->error; 33 | } 34 | 35 | bool Header_deserialize_topic(ucdrBuffer* reader, Header* topic) 36 | { 37 | (void) Time_deserialize_topic(reader, &topic->stamp); 38 | (void) ucdr_deserialize_string(reader, topic->frame_id, 255); 39 | 40 | return !reader->error; 41 | } 42 | 43 | uint32_t Header_size_of_topic(const Header* topic, uint32_t size) 44 | { 45 | uint32_t previousSize = size; 46 | size += Time_size_of_topic(&topic->stamp, size); 47 | size += ucdr_alignment(size, 4) + 4 + (uint32_t)strlen(topic->frame_id) + 1; 48 | 49 | return size - previousSize; 50 | } 51 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/input_reliable_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR__CLIENT__CORE__SESSION__STREAM__INPUT_RELIABLE_STREAM_H_ 16 | #define UXR__CLIENT__CORE__SESSION__STREAM__INPUT_RELIABLE_STREAM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | struct ucdrBuffer; 29 | 30 | typedef enum FragmentationInfo 31 | { 32 | NO_FRAGMENTED, 33 | INTERMEDIATE_FRAGMENT, 34 | LAST_FRAGMENT 35 | 36 | } FragmentationInfo; 37 | 38 | typedef FragmentationInfo (*OnGetFragmentationInfo)(uint8_t* buffer); 39 | 40 | typedef struct uxrInputReliableStream 41 | { 42 | uxrReliableStream base; 43 | 44 | uxrSeqNum last_handled; 45 | uxrSeqNum last_announced; 46 | 47 | OnGetFragmentationInfo on_get_fragmentation_info; 48 | 49 | bool cleanup_flag; 50 | 51 | } uxrInputReliableStream; 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif // UXR__CLIENT__CORE__SESSION__STREAM__INPUT_RELIABLE_STREAM_H_ 58 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/tcp/tcp_transport_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SRC_C_PROFILE_TRANSPORT_TCP_TCP_TRANSPORT_INTERNAL_H_ 16 | #define SRC_C_PROFILE_TRANSPORT_TCP_TCP_TRANSPORT_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | bool uxr_init_tcp_platform( 26 | struct uxrTCPPlatform* platform, 27 | uxrIpProtocol ip_protocol, 28 | const char* ip, 29 | const char* port); 30 | 31 | bool uxr_close_tcp_platform( 32 | struct uxrTCPPlatform* platform); 33 | 34 | size_t uxr_write_tcp_data_platform( 35 | struct uxrTCPPlatform* platform, 36 | const uint8_t* buf, 37 | size_t len, 38 | uint8_t* errcode); 39 | 40 | size_t uxr_read_tcp_data_platform( 41 | struct uxrTCPPlatform* platform, 42 | uint8_t* buf, 43 | size_t len, 44 | int timeout, 45 | uint8_t* errcode); 46 | 47 | void uxr_disconnect_tcp_platform( 48 | struct uxrTCPPlatform* platform); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif // SRC_C_PROFILE_TRANSPORT_TCP_TCP_TRANSPORT_INTERNAL_H_ 55 | -------------------------------------------------------------------------------- /src/ucdr/test/serialization/BasicSerialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "BasicSerialization.hpp" 16 | 17 | TEST_F(BasicSerialization, Bool) 18 | { 19 | bool_serialization(); 20 | } 21 | 22 | TEST_F(BasicSerialization, Char) 23 | { 24 | char_serialization(); 25 | } 26 | 27 | TEST_F(BasicSerialization, Int8) 28 | { 29 | int8_t_serialization(); 30 | } 31 | 32 | TEST_F(BasicSerialization, Uint8) 33 | { 34 | uint8_t_serialization(); 35 | } 36 | 37 | TEST_F(BasicSerialization, Int16) 38 | { 39 | int16_t_serialization(); 40 | } 41 | 42 | TEST_F(BasicSerialization, Uint16) 43 | { 44 | uint16_t_serialization(); 45 | } 46 | 47 | TEST_F(BasicSerialization, Int32) 48 | { 49 | int32_t_serialization(); 50 | } 51 | 52 | TEST_F(BasicSerialization, Uint32) 53 | { 54 | uint32_t_serialization(); 55 | } 56 | 57 | TEST_F(BasicSerialization, Int64) 58 | { 59 | int64_t_serialization(); 60 | } 61 | 62 | TEST_F(BasicSerialization, Uint64) 63 | { 64 | uint64_t_serialization(); 65 | } 66 | 67 | TEST_F(BasicSerialization, Float) 68 | { 69 | float_serialization(); 70 | } 71 | 72 | TEST_F(BasicSerialization, Double) 73 | { 74 | double_serialization(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/ucdr/src/c/types/string.c: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include 17 | 18 | #include 19 | 20 | // ------------------------------------------------------------------- 21 | // PUBLIC SERIALIZATION IMPLEMENTATIONS 22 | // ------------------------------------------------------------------- 23 | 24 | bool ucdr_serialize_string(ucdrBuffer* ub, const char* string) 25 | { 26 | return ucdr_serialize_sequence_char(ub, string, (uint32_t)strlen(string) + 1); 27 | } 28 | 29 | bool ucdr_serialize_endian_string(ucdrBuffer* ub, ucdrEndianness endianness, const char* string) 30 | { 31 | return ucdr_serialize_endian_sequence_char(ub, endianness, string, (uint32_t)strlen(string) + 1); 32 | } 33 | 34 | bool ucdr_deserialize_string(ucdrBuffer* ub, char* string, size_t string_capacity) 35 | { 36 | uint32_t length; 37 | return ucdr_deserialize_sequence_char(ub, string, string_capacity, &length); 38 | } 39 | 40 | bool ucdr_deserialize_endian_string(ucdrBuffer* ub, ucdrEndianness endianness, char* string, size_t string_capacity) 41 | { 42 | uint32_t length; 43 | return ucdr_deserialize_endian_sequence_char(ub, endianness, string, string_capacity, &length); 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Micro-XRCE-DDS-Client 2 | 3 | ## 1、Introduction 4 | 5 | eProsima Micro XRCE-DDS is an open-source wire protocol that implements the OMG DDS for eXtremely Resource Constrained Environment standard (DDS-XRCE). The aim of the DDS-XRCE protocol is to provide access to the DDS Global-Data-Space from resource-constrained devices. This is achieved thanks to a client-server architecture, where low resource devices, called XRCE Clients, are connected to a server, called XRCE Agent, which acts on behalf of its clients in the DDS Global-Data-Space. 6 | 7 | This repository is a package for RT-Thread which includes Micro XRCE-DDS Client library and provide the ROS2 topic public/subscribe ability. 8 | 9 | ![Micro-ROS Architecture](./docs/figures/micro-ROS_architecture.png) 10 | 11 | ### 1.1 Content Architecture 12 | 13 | | Name | Description | 14 | | ---- | ---- | 15 | | docs | Document folder | 16 | | examples | Example folder | 17 | | inc | Header folder | 18 | | src | Source folder | 19 | 20 | ### 1.2 License 21 | 22 | Apache license v2.0 23 | 24 | ### 1.3 Dependency 25 | 26 | - RT-Thread 3.0+ 27 | 28 | ## 2、How to Enable Micro-XRCE_DDS-Client 29 | 30 | Enable Micro-XRCE-DDS-Client package in menuconfig at the belowing path: 31 | 32 | ``` 33 | RT-Thread online packages 34 | tools packages ---> 35 | [*] Micro-XRCE-DDS-Client 36 | ``` 37 | 38 | > To enable examples, add `MICRO_XRCE_DDS_CLIENT_USING_EXAMPLE` in rtconfig.h 39 | 40 | ## 3、Usage 41 | 42 | * [eProsima Document](https://micro-xrce-dds.docs.eprosima.com/en/latest/) 43 | * [Micro-ROS Document](https://micro-ros.github.io/docs/concepts/middleware/Micro_XRCE-DDS/) 44 | * For more documemt, please check `doc` folder. 45 | 46 | ## 4、Notice 47 | 48 | This package is only tested on ROS2 Foxy, for other ROS distribution is not tested. 49 | 50 | ## 5、Communication 51 | 52 | * Maintainer:Jiachi 53 | -------------------------------------------------------------------------------- /src/c/profile/transport/serial/serial_transport_posix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, int fd, uint8_t remote_addr, uint8_t local_addr) 8 | { 9 | (void) remote_addr; 10 | (void) local_addr; 11 | 12 | /* Poll setup. */ 13 | platform->poll_fd.fd = fd; 14 | platform->poll_fd.events = POLLIN; 15 | 16 | return true; 17 | } 18 | 19 | bool uxr_close_serial_platform(struct uxrSerialPlatform* platform) 20 | { 21 | return (-1 == platform->poll_fd.fd) ? true : (0 == close(platform->poll_fd.fd)); 22 | } 23 | 24 | size_t uxr_write_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, uint8_t* errcode) 25 | { 26 | size_t rv = 0; 27 | 28 | ssize_t bytes_written = write(platform->poll_fd.fd, (void*)buf, (size_t)len); 29 | if (-1 != bytes_written) 30 | { 31 | rv = (size_t)bytes_written; 32 | *errcode = 0; 33 | } 34 | else 35 | { 36 | *errcode = 1; 37 | } 38 | return rv; 39 | } 40 | 41 | size_t uxr_read_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, int timeout, uint8_t* errcode) 42 | { 43 | size_t rv = 0; 44 | 45 | int poll_rv = poll(&platform->poll_fd, 1, timeout); 46 | if (0 < poll_rv) 47 | { 48 | ssize_t bytes_read = read(platform->poll_fd.fd, buf, len); 49 | if (-1 != bytes_read) 50 | { 51 | rv = (size_t)bytes_read; 52 | *errcode = 0; 53 | } 54 | else 55 | { 56 | *errcode = 1; 57 | } 58 | } 59 | else 60 | { 61 | *errcode = (0 == poll_rv) ? 0 : 1; 62 | } 63 | return rv; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/serial/serial_transport_platform.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_TRANSPORT_PLATFORM_H_ 16 | #define _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_TRANSPORT_PLATFORM_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, const int fd, uint8_t remote_addr, uint8_t local_addr); 26 | bool uxr_close_serial_platform(struct uxrSerialPlatform* platform); 27 | 28 | size_t uxr_write_serial_data_platform(struct uxrSerialPlatform* platform, 29 | uint8_t* buf, 30 | size_t len, 31 | uint8_t* errcode); 32 | 33 | size_t uxr_read_serial_data_platform(struct uxrSerialPlatform* platform, 34 | uint8_t* buf, 35 | size_t len, 36 | int timeout, 37 | uint8_t* errcode); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif //_SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_TRANSPORT_PLATFORM_H_ 44 | -------------------------------------------------------------------------------- /src/c/util/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef WIN32 7 | #include 8 | #elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) 9 | #include "FreeRTOS.h" 10 | #include "task.h" 11 | #endif 12 | 13 | //================================================================== 14 | // PUBLIC 15 | //================================================================== 16 | int64_t uxr_millis(void) 17 | { 18 | return uxr_nanos() / 1000000; 19 | } 20 | 21 | int64_t uxr_nanos(void) 22 | { 23 | #ifdef WIN32 24 | SYSTEMTIME epoch_tm = {1970, 1, 4, 1, 0, 0, 0, 0}; 25 | FILETIME epoch_ft; 26 | SystemTimeToFileTime(&epoch_tm, &epoch_ft); 27 | uint64_t epoch_time = (((uint64_t) epoch_ft.dwHighDateTime) << 32) + epoch_ft.dwLowDateTime; 28 | 29 | SYSTEMTIME tm; 30 | FILETIME ft; 31 | GetSystemTime(&tm); 32 | SystemTimeToFileTime(&tm, &ft); 33 | uint64_t current_time = (((uint64_t) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; 34 | 35 | return (current_time - epoch_time) * 100; 36 | #elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) 37 | TimeOut_t tick_count; 38 | 39 | /* Get the current tick count. */ 40 | vTaskSetTimeOutState(&tick_count); 41 | 42 | /* Pack the current tick count in int64_t. */ 43 | int64_t total_tick = (int64_t) tick_count.xOverflowCount; 44 | #if( configUSE_16_BIT_TICKS == 1 ) /* Use 16-bit tick type. */ 45 | total_tick <<= 16; 46 | #else //( configUSE_16_BIT_TICKS == 1 ) /* Use 32-bit tick type. */ 47 | total_tick <<= 32; 48 | #endif // ( configUSE_16_BIT_TICKS == 1 ) 49 | total_tick |= (int64_t) tick_count.xTimeOnEntering; 50 | return ( ( total_tick / (int64_t) portTICK_PERIOD_MS ) * 1000000 ); 51 | #else 52 | uint64_t now_ms = (uint64_t)rt_tick_get_millisecond(); 53 | return now_ms * 1000000; 54 | #endif 55 | } 56 | -------------------------------------------------------------------------------- /src/ucdr/test/serialization/ArraySerialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "ArraySerialization.hpp" 16 | 17 | TEST_F(ArraySerialization, Bool) 18 | { 19 | bool_array_serialization(); 20 | } 21 | 22 | TEST_F(ArraySerialization, Char) 23 | { 24 | char_array_serialization(); 25 | } 26 | 27 | TEST_F(ArraySerialization, Int8) 28 | { 29 | int8_t_array_serialization(); 30 | } 31 | 32 | TEST_F(ArraySerialization, Uint8) 33 | { 34 | uint8_t_array_serialization(); 35 | } 36 | 37 | TEST_F(ArraySerialization, Int16) 38 | { 39 | int16_t_array_serialization(); 40 | } 41 | 42 | TEST_F(ArraySerialization, Uint16) 43 | { 44 | uint16_t_array_serialization(); 45 | } 46 | 47 | TEST_F(ArraySerialization, Int32) 48 | { 49 | int32_t_array_serialization(); 50 | } 51 | 52 | TEST_F(ArraySerialization, Uint32) 53 | { 54 | uint32_t_array_serialization(); 55 | } 56 | 57 | TEST_F(ArraySerialization, Int64) 58 | { 59 | int64_t_array_serialization(); 60 | } 61 | 62 | TEST_F(ArraySerialization, Uint64) 63 | { 64 | uint64_t_array_serialization(); 65 | } 66 | 67 | TEST_F(ArraySerialization, Float) 68 | { 69 | float_array_serialization(); 70 | } 71 | 72 | TEST_F(ArraySerialization, Double) 73 | { 74 | double_array_serialization(); 75 | } 76 | -------------------------------------------------------------------------------- /src/ucdr/test/FullBuffer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "FullBuffer.hpp" 16 | 17 | TEST_F(FullBuffer, Block_8) 18 | { 19 | fill_buffer_except(7); 20 | try_block_8(); 21 | } 22 | 23 | TEST_F(FullBuffer, Block_4) 24 | { 25 | fill_buffer_except(3); 26 | try_block_4(); 27 | } 28 | 29 | TEST_F(FullBuffer, Block_2) 30 | { 31 | fill_buffer_except(1); 32 | try_block_2(); 33 | } 34 | 35 | TEST_F(FullBuffer, Block_1) 36 | { 37 | fill_buffer_except(0); 38 | try_block_1(); 39 | } 40 | 41 | # define SUCCESSFUL_SERIALIZATION 3 42 | # define ARRAY_SERIALIZATION (SUCCESSFUL_SERIALIZATION + 1) 43 | TEST_F(FullBuffer, ArrayBlock_8) 44 | { 45 | fill_buffer_except(8 * SUCCESSFUL_SERIALIZATION + 7); 46 | try_array_block_8(ARRAY_SERIALIZATION); 47 | } 48 | 49 | TEST_F(FullBuffer, ArrayBlock_4) 50 | { 51 | fill_buffer_except(4 * SUCCESSFUL_SERIALIZATION + 3); 52 | try_array_block_4(ARRAY_SERIALIZATION); 53 | } 54 | 55 | TEST_F(FullBuffer, ArrayBlock_2) 56 | { 57 | fill_buffer_except(2 * SUCCESSFUL_SERIALIZATION + 1); 58 | try_array_block_2(ARRAY_SERIALIZATION); 59 | } 60 | 61 | TEST_F(FullBuffer, ArrayBlock_1) 62 | { 63 | fill_buffer_except(SUCCESSFUL_SERIALIZATION); 64 | try_array_block_1(ARRAY_SERIALIZATION); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/ucdr/test/Alignment.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "serialization/BasicSerialization.hpp" 16 | 17 | class Alignment : public BasicSerialization, public ::testing::WithParamInterface 18 | { 19 | public: 20 | 21 | Alignment() 22 | { 23 | int offset = GetParam(); 24 | for(int i = 0; i < offset; ++i) 25 | { 26 | uint8_t_serialization(); 27 | } 28 | } 29 | 30 | void check_alignment(int alignment) 31 | { 32 | EXPECT_EQ(static_cast(ucdr_buffer_length(&writer)) % alignment, 0); 33 | EXPECT_EQ(static_cast(ucdr_buffer_length(&reader)) % alignment, 0); 34 | } 35 | 36 | virtual ~Alignment() 37 | { 38 | } 39 | }; 40 | 41 | INSTANTIATE_TEST_CASE_P(Offset, Alignment, ::testing::Range(0, 17), ::testing::PrintToStringParamName()); 42 | 43 | TEST_P(Alignment, Block_8) 44 | { 45 | uint64_t_serialization(); 46 | check_alignment(8); 47 | } 48 | 49 | TEST_P(Alignment, Block_4) 50 | { 51 | uint32_t_serialization(); 52 | check_alignment(4); 53 | } 54 | 55 | TEST_P(Alignment, Block_2) 56 | { 57 | uint16_t_serialization(); 58 | check_alignment(2); 59 | } 60 | 61 | TEST_P(Alignment, Block_1) 62 | { 63 | uint8_t_serialization(); 64 | check_alignment(1); 65 | } 66 | -------------------------------------------------------------------------------- /src/c/core/session/stream/stream_id.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../../serialization/xrce_header_internal.h" 4 | 5 | #define BEST_EFFORT_STREAM_THRESHOLD 1 6 | #define RELIABLE_STREAM_THRESHOLD 128 7 | 8 | //================================================================== 9 | // PUBLIC 10 | //================================================================== 11 | uxrStreamId uxr_stream_id(uint8_t index, uxrStreamType type, uxrStreamDirection direction) 12 | { 13 | uxrStreamId stream_id; 14 | stream_id.direction = (uint8_t)direction; 15 | stream_id.index = index; 16 | stream_id.type = (uint8_t)type; 17 | 18 | switch(type) 19 | { 20 | case UXR_NONE_STREAM: 21 | stream_id.raw = 0; 22 | break; 23 | case UXR_BEST_EFFORT_STREAM: 24 | stream_id.raw = (uint8_t)(index + BEST_EFFORT_STREAM_THRESHOLD); 25 | break; 26 | case UXR_RELIABLE_STREAM: 27 | stream_id.raw = (uint8_t)(index + RELIABLE_STREAM_THRESHOLD); 28 | break; 29 | } 30 | 31 | return stream_id; 32 | } 33 | 34 | uxrStreamId uxr_stream_id_from_raw(uint8_t stream_id_raw, uxrStreamDirection direction) 35 | { 36 | uxrStreamId stream_id; 37 | stream_id.raw = stream_id_raw; 38 | stream_id.direction = (uint8_t)direction; 39 | 40 | if(BEST_EFFORT_STREAM_THRESHOLD > stream_id_raw) 41 | { 42 | stream_id.index = stream_id_raw; 43 | stream_id.type = UXR_NONE_STREAM; 44 | } 45 | else if(RELIABLE_STREAM_THRESHOLD > stream_id_raw) 46 | { 47 | stream_id.index = (uint8_t)(stream_id_raw - BEST_EFFORT_STREAM_THRESHOLD); 48 | stream_id.type = UXR_BEST_EFFORT_STREAM; 49 | } 50 | else 51 | { 52 | stream_id.index = (uint8_t)(stream_id_raw - RELIABLE_STREAM_THRESHOLD); 53 | stream_id.type = UXR_RELIABLE_STREAM; 54 | } 55 | 56 | return stream_id; 57 | } 58 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/serial/serial_protocol.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 16 | #define _UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #include 23 | 24 | #define UXR_FRAMING_BEGIN_FLAG 0x7E 25 | #define UXR_FRAMING_ESC_FLAG 0x7D 26 | #define UXR_FRAMING_XOR_FLAG 0x20 27 | 28 | typedef enum uxrSerialInputState 29 | { 30 | UXR_SERIAL_UNINITIALIZED, 31 | UXR_SERIAL_READING_SRC_ADDR, 32 | UXR_SERIAL_READING_DST_ADDR, 33 | UXR_SERIAL_READING_LEN_LSB, 34 | UXR_SERIAL_READING_LEN_MSB, 35 | UXR_SERIAL_READING_PAYLOAD, 36 | UXR_SERIAL_READING_CRC_LSB, 37 | UXR_SERIAL_READING_CRC_MSB, 38 | 39 | } uxrSerialInputState; 40 | 41 | typedef struct uxrSerialIO 42 | { 43 | uxrSerialInputState state; 44 | uint8_t local_addr; 45 | uint8_t rb[42]; 46 | uint8_t rb_head; 47 | uint8_t rb_tail; 48 | uint8_t src_addr; 49 | uint16_t msg_len; 50 | uint16_t msg_pos; 51 | uint16_t msg_crc; 52 | uint16_t cmp_crc; 53 | uint8_t wb[42]; 54 | uint8_t wb_pos; 55 | 56 | } uxrSerialIO; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif //_UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 63 | -------------------------------------------------------------------------------- /src/ucdr/test/serialization/SequenceSerialization.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "SequenceSerialization.hpp" 16 | 17 | TEST_F(SequenceSerialization, Bool) 18 | { 19 | bool_sequence_serialization(); 20 | } 21 | 22 | TEST_F(SequenceSerialization, Char) 23 | { 24 | char_sequence_serialization(); 25 | } 26 | 27 | TEST_F(SequenceSerialization, Int8) 28 | { 29 | int8_t_sequence_serialization(); 30 | } 31 | 32 | TEST_F(SequenceSerialization, Uint8) 33 | { 34 | uint8_t_sequence_serialization(); 35 | } 36 | 37 | TEST_F(SequenceSerialization, Int16) 38 | { 39 | int16_t_sequence_serialization(); 40 | } 41 | 42 | TEST_F(SequenceSerialization, Uint16) 43 | { 44 | uint16_t_sequence_serialization(); 45 | } 46 | 47 | TEST_F(SequenceSerialization, Int32) 48 | { 49 | int32_t_sequence_serialization(); 50 | } 51 | 52 | TEST_F(SequenceSerialization, Uint32) 53 | { 54 | uint32_t_sequence_serialization(); 55 | } 56 | 57 | TEST_F(SequenceSerialization, Int64) 58 | { 59 | int64_t_sequence_serialization(); 60 | } 61 | 62 | TEST_F(SequenceSerialization, Uint64) 63 | { 64 | uint64_t_sequence_serialization(); 65 | } 66 | 67 | TEST_F(SequenceSerialization, Float) 68 | { 69 | float_sequence_serialization(); 70 | } 71 | 72 | TEST_F(SequenceSerialization, Double) 73 | { 74 | double_sequence_serialization(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/common_create_entities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_CORE_SESSION_COMMON_CREATE_ENTITIES_H_ 16 | #define UXR_CLIENT_CORE_SESSION_COMMON_CREATE_ENTITIES_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | /** 26 | * @brief Buffers into the stream identified by `stream_id` an XRCE DELETE submessage. 27 | * The submessage will be sent when `uxr_flash_output_stream` or `uxr_run_session` function are called. 28 | * As a result of the reception of this submessage, the Agent will delete an XRCE entity. 29 | * @param session A uxrSession structure previously initialized. 30 | * @param stream_id The output stream identifier where the CREATE submessage will be buffered. 31 | * @param object_id The identifier of the XRCE entity. 32 | * @return A `request_id` that identifies the request made by the Client. 33 | * This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions. 34 | */ 35 | UXRDLLAPI uint16_t uxr_buffer_delete_entity( 36 | uxrSession* session, 37 | uxrStreamId stream_id, 38 | uxrObjectId object_id); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif // UXR_CLIENT_CORE_SESSION_COMMON_CREATE_ENTITIES_H_ 45 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/stream_storage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_STREAM_STREAM_STORAGE_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_STREAM_STREAM_STORAGE_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | typedef struct uxrStreamStorage 31 | { 32 | uxrOutputBestEffortStream output_best_effort[UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS]; 33 | uint8_t output_best_effort_size; 34 | uxrOutputReliableStream output_reliable[UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS]; 35 | uint8_t output_reliable_size; 36 | uxrInputBestEffortStream input_best_effort[UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS]; 37 | uint8_t input_best_effort_size; 38 | uxrInputReliableStream input_reliable[UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS]; 39 | uint8_t input_reliable_size; 40 | 41 | } uxrStreamStorage; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // _UXR_CLIENT_CORE_SESSION_STREAM_STREAM_STORAGE_H 48 | -------------------------------------------------------------------------------- /src/c/core/session/stream/output_best_effort_stream.c: -------------------------------------------------------------------------------- 1 | #include "output_best_effort_stream_internal.h" 2 | 3 | #include "../submessage_internal.h" 4 | #include "seq_num_internal.h" 5 | 6 | #include 7 | 8 | //================================================================== 9 | // PUBLIC 10 | //================================================================== 11 | void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8_t* buffer, size_t size, uint8_t offset) 12 | { 13 | stream->buffer = buffer; 14 | stream->offset = offset; 15 | stream->size = size; 16 | 17 | uxr_reset_output_best_effort_stream(stream); 18 | } 19 | 20 | void uxr_reset_output_best_effort_stream(uxrOutputBestEffortStream* stream) 21 | { 22 | stream->writer = stream->offset; 23 | stream->last_send = SEQ_NUM_MAX; 24 | } 25 | 26 | bool uxr_prepare_best_effort_buffer_to_write(uxrOutputBestEffortStream* stream, size_t size, ucdrBuffer* ub) 27 | { 28 | 29 | size_t current_padding = uxr_submessage_padding(stream->writer); 30 | size_t future_length = stream->writer + current_padding + size; 31 | bool available_to_write = future_length <= stream->size; 32 | if(available_to_write) 33 | { 34 | ucdr_init_buffer_origin_offset(ub, stream->buffer, (uint32_t)future_length, 0u, (uint32_t)(stream->writer + current_padding)); 35 | stream->writer += size; 36 | } 37 | 38 | return available_to_write; 39 | } 40 | 41 | bool uxr_prepare_best_effort_buffer_to_send(uxrOutputBestEffortStream* stream, uint8_t** buffer, size_t* length, uint16_t* seq_num) 42 | { 43 | bool data_to_send = stream->writer > stream->offset; 44 | if(data_to_send) 45 | { 46 | stream->last_send = uxr_seq_num_add(stream->last_send, 1); 47 | 48 | *seq_num = stream->last_send; 49 | *buffer = stream->buffer; 50 | *length = stream->writer; 51 | 52 | stream->writer = stream->offset; 53 | } 54 | 55 | return data_to_send; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/c/core/log/log_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_LOG_LOG_INTERNAL_H_ 16 | #define _SRC_C_CORE_LOG_LOG_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #define UXR_SEND 1 27 | #define UXR_ERROR_SEND ~1 28 | #define UXR_RECV 2 29 | #define UXR_ERROR_RECV ~2 30 | 31 | #ifdef UXR_MESSAGE_LOGS 32 | #define UXR_MESSAGE_LOGS_AVAILABLE 1 33 | #else 34 | #define UXR_MESSAGE_LOGS_AVAILABLE 0 35 | #endif 36 | 37 | #ifdef UXR_SERIALIZATION_LOGS 38 | #define UXR_SERIALIZATION_LOGS_AVAILABLE 1 39 | #else 40 | #define UXR_SERIALIZATION_LOGS_AVAILABLE 0 41 | #endif 42 | 43 | void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_t* client_key); 44 | void uxr_print_serialization(int direction, const uint8_t* buffer, size_t size); 45 | 46 | #if defined(UXR_MESSAGE_LOGS) || defined(UXR_SERIALIZATION_LOGS) 47 | #define UXR_DEBUG_PRINT_MESSAGE(direction, buffer, size, client_key) \ 48 | do \ 49 | { \ 50 | if (UXR_MESSAGE_LOGS_AVAILABLE) uxr_print_message(direction, buffer, size, client_key); \ 51 | if (UXR_SERIALIZATION_LOGS_AVAILABLE) uxr_print_serialization(direction, buffer, size); \ 52 | } while (0) 53 | #else 54 | #define UXR_DEBUG_PRINT_MESSAGE(direction, buffer, size, client_key) do {} while(0) 55 | #endif 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif // _SRC_C_CORE_LOG_LOG_INTERNAL_H_ 62 | -------------------------------------------------------------------------------- /src/c/core/session/stream/input_reliable_stream_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_INPUT_STREAM_RELIABLE_STREAM_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_INPUT_STREAM_RELIABLE_STREAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define ACKNACK_PAYLOAD_SIZE 5 30 | 31 | struct ucdrBuffer; 32 | 33 | void uxr_init_input_reliable_stream(uxrInputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info); 34 | void uxr_reset_input_reliable_stream(uxrInputReliableStream* stream); 35 | bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_num, uint8_t* buffer, size_t length, bool* message_stored); 36 | bool uxr_next_input_reliable_buffer_available(uxrInputReliableStream* stream, struct ucdrBuffer* ub, size_t fragment_offset); 37 | 38 | uint16_t uxr_compute_acknack(const uxrInputReliableStream* stream, uxrSeqNum* from); 39 | void uxr_process_heartbeat(uxrInputReliableStream* stream, uxrSeqNum first_seq_num, uxrSeqNum last_seq_num); 40 | 41 | bool uxr_is_input_up_to_date(const uxrInputReliableStream* stream); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // _SRC_C_CORE_SESSION_INPUT_STREAM_RELIABLE_STREAM_INTERNAL_H_ 48 | -------------------------------------------------------------------------------- /src/c/profile/transport/serial/serial_transport_external.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // Place here your includes 7 | 8 | bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, int fd, uint8_t remote_addr, uint8_t local_addr) 9 | { 10 | // Place here your initialization platform code 11 | // console_printf("init serial platform 0x%x\n", fd); 12 | 13 | platform->dev = (rt_device_t)fd; 14 | 15 | // Return true if success 16 | return true; 17 | } 18 | 19 | bool uxr_close_serial_platform(struct uxrSerialPlatform* platform) 20 | { 21 | // Place here your closing platform code 22 | // console_printf("close serial platform\n"); 23 | 24 | if (platform->dev) { 25 | rt_device_close(platform->dev); 26 | } 27 | 28 | // Return true if success 29 | return true; 30 | } 31 | 32 | size_t uxr_write_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, uint8_t* errcode) 33 | { 34 | // Place here your writing bytes platform code 35 | ssize_t bytes_written = rt_device_write(platform->dev, 0, (void*)buf, (rt_size_t)len); 36 | // console_printf("write serial platform: %d %d\n", len, bytes_written); 37 | 38 | // Return number of bytes written 39 | return bytes_written; 40 | } 41 | 42 | size_t uxr_read_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, int timeout, uint8_t* errcode) 43 | { 44 | // Place here your reading bytes platform code 45 | rt_size_t bytes_read = 0; 46 | uint32_t time_start_ms = rt_tick_get_millisecond(); 47 | 48 | do { 49 | bytes_read += rt_device_read(platform->dev, 0, (void*)&buf[bytes_read], (rt_size_t)(len - bytes_read)); 50 | } while (bytes_read < len && (rt_tick_get_millisecond() - time_start_ms < timeout)); 51 | 52 | // console_printf("read serial platform: %d %d\n", len, bytes_read); 53 | 54 | // Return number of bytes read (max bytes: len) 55 | return bytes_read; 56 | } 57 | -------------------------------------------------------------------------------- /inc/uxr/client/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CONFIG_H_ 16 | #define _UXR_CLIENT_CONFIG_H_ 17 | 18 | #define UXR_CLIENT_VERSION_MAJOR 1 19 | #define UXR_CLIENT_VERSION_MINOR 2 20 | #define UXR_CLIENT_VERSION_MICRO 5 21 | #define UXR_CLIENT_VERSION_STR "1.2.5" 22 | 23 | /* #undef UCLIENT_PROFILE_DISCOVERY */ 24 | 25 | #define UCLIENT_PROFILE_SERIAL 26 | #define UCLIENT_PROFILE_UDP 27 | #define UCLIENT_PROFILE_TCP 28 | 29 | /* #define UCLIENT_PLATFORM_POSIX */ 30 | /* #undef UCLIENT_PLATFORM_POSIX_NOPOLL */ 31 | /* #undef UCLIENT_PLATFORM_WINDOWS */ 32 | /* #undef UCLIENT_PLATFORM_FREERTOS_PLUS_TCP */ 33 | 34 | #define UCLIENT_EXTERNAL_SERIAL 35 | #define UCLIENT_EXTERNAL_UDP 36 | #define UCLIENT_EXTERNAL_TCP 37 | 38 | #define UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS 1 39 | #define UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS 1 40 | #define UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS 1 41 | #define UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS 1 42 | 43 | #define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS 5 44 | #define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL 25 45 | #define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL 1 46 | 47 | #ifdef UCLIENT_PROFILE_UDP 48 | #define UXR_CONFIG_UDP_TRANSPORT_MTU 512 49 | #endif 50 | #ifdef UCLIENT_PROFILE_TCP 51 | #define UXR_CONFIG_TCP_TRANSPORT_MTU 512 52 | #endif 53 | #ifdef UCLIENT_PROFILE_SERIAL 54 | #define UXR_CONFIG_SERIAL_TRANSPORT_MTU 512 55 | #endif 56 | 57 | #endif // _UXR_CLIENT_CONFIG_H_ 58 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/session_info.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CORE_SESSION_SESSION_INFO_H_ 16 | #define _UXR_CLIENT_CORE_SESSION_SESSION_INFO_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #define UXR_STATUS_OK 0x00 28 | #define UXR_STATUS_OK_MATCHED 0x01 29 | #define UXR_STATUS_ERR_DDS_ERROR 0x80 30 | #define UXR_STATUS_ERR_MISMATCH 0x81 31 | #define UXR_STATUS_ERR_ALREADY_EXISTS 0x82 32 | #define UXR_STATUS_ERR_DENIED 0x83 33 | #define UXR_STATUS_ERR_UNKNOWN_REFERENCE 0x84 34 | #define UXR_STATUS_ERR_INVALID_DATA 0x85 35 | #define UXR_STATUS_ERR_INCOMPATIBLE 0x86 36 | #define UXR_STATUS_ERR_RESOURCES 0x87 37 | #define UXR_STATUS_NONE 0xFF //Never sent or received. It is used for managing an unknown status 38 | 39 | #define UXR_REUSE 0x01 << 1 40 | #define UXR_REPLACE 0x01 << 2 41 | #ifdef PERFORMANCE_TESTING 42 | #define UXR_ECHO 0x01 << 7 43 | #endif 44 | 45 | #define UXR_INVALID_REQUEST_ID 0 46 | 47 | #define UXR_REQUEST_NONE 0x00 48 | #define UXR_REQUEST_LOGIN 0x01 49 | #define UXR_REQUEST_LOGOUT 0x02 50 | 51 | typedef struct uxrSessionInfo 52 | { 53 | uint8_t id; 54 | uint8_t key[4]; 55 | uint8_t last_requested_status; 56 | uint16_t last_request_id; 57 | 58 | } uxrSessionInfo; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif // _UXR_CLIENT_CORE_SESSION_SESSION_INFO_H 65 | -------------------------------------------------------------------------------- /src/c/core/session/stream/output_reliable_stream_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_STREAM_OUTPUT_RELIABLE_STREAM_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_STREAM_OUTPUT_RELIABLE_STREAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #define HEARTBEAT_PAYLOAD_SIZE 5 30 | 31 | void uxr_init_output_reliable_stream(uxrOutputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset); 32 | void uxr_reset_output_reliable_stream(uxrOutputReliableStream* stream); 33 | bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_t size, struct ucdrBuffer* ub); 34 | bool uxr_prepare_next_reliable_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t* length, uxrSeqNum* seq_num); 35 | 36 | bool uxr_update_output_stream_heartbeat_timestamp(uxrOutputReliableStream* stream, int64_t current_timestamp); 37 | uxrSeqNum uxr_begin_output_nack_buffer_it(const uxrOutputReliableStream* stream); 38 | bool uxr_next_reliable_nack_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t *length, uxrSeqNum* seq_num_it); 39 | void uxr_process_acknack(uxrOutputReliableStream* stream, uint16_t bitmap, uxrSeqNum first_unacked_seq_num); 40 | 41 | bool uxr_is_output_up_to_date(const uxrOutputReliableStream* stream); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // _SRC_C_CORE_SESSION_STREAM_OUTPUT_RELIABLE_STREAM_INTERNAL_H_ 48 | -------------------------------------------------------------------------------- /src/ucdr/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) 16 | 17 | # New project because of the CXX GTest dependency. 18 | if(CMAKE_VERSION VERSION_LESS 3.0) 19 | project(microcdr_tests C CXX) 20 | else() 21 | cmake_policy(SET CMP0048 NEW) 22 | project(microcdr_tests LANGUAGES C CXX) 23 | endif() 24 | 25 | check_gtest() 26 | if(GTEST_FOUND) 27 | include(CTest) 28 | find_package(fastcdr REQUIRED) 29 | set(SRCS 30 | CommonFunctions.cpp 31 | serialization/BasicSerialization.cpp 32 | serialization/ArraySerialization.cpp 33 | serialization/SequenceSerialization.cpp 34 | serialization/StringSerialization.cpp 35 | endianness/BasicEndianness.cpp 36 | endianness/ArrayEndianness.cpp 37 | endianness/SequenceEndianness.cpp 38 | fragmentation/BasicFragmentation.cpp 39 | fragmentation/ArrayFragmentation.cpp 40 | SequenceOverflow.cpp 41 | Alignment.cpp 42 | FullBuffer.cpp 43 | FullBufferCallback.cpp 44 | cross_serialization/FastCDRSerialization.cpp 45 | ) 46 | add_executable(${PROJECT_NAME} ${SRCS}) 47 | set_common_compile_options(${PROJECT_NAME}) 48 | add_gtest(${PROJECT_NAME} 49 | SOURCES 50 | ${SRCS} 51 | DEPENDENCIES 52 | microcdr 53 | fastcdr 54 | ) 55 | target_include_directories(${PROJECT_NAME} PRIVATE ${GTEST_INCLUDE_DIRS} ${FASTCDR_INCLUDE_DIRS}) 56 | target_link_libraries(${PROJECT_NAME} microcdr fastcdr ${GTEST_BOTH_LIBRARIES}) 57 | 58 | set_target_properties(${PROJECT_NAME} PROPERTIES 59 | CXX_STANDARD 11 60 | CXX_STANDARD_REQUIRED YES 61 | ) 62 | endif() 63 | 64 | -------------------------------------------------------------------------------- /src/c/core/session/session_info_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_SESSION_INFO_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_SESSION_INFO_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include "../serialization/xrce_header_internal.h" 25 | 26 | #define CREATE_CLIENT_PAYLOAD_SIZE 16 27 | #define DELETE_CLIENT_PAYLOAD_SIZE 4 28 | 29 | #define MIN_HEADER_SIZE 4 30 | #define MAX_HEADER_SIZE (MIN_HEADER_SIZE + CLIENT_KEY_SIZE) 31 | 32 | struct ucdrBuffer; 33 | struct BaseObjectRequest; 34 | 35 | void uxr_init_session_info(uxrSessionInfo* info, uint8_t id, uint32_t key); 36 | 37 | void uxr_buffer_create_session(uxrSessionInfo* info, struct ucdrBuffer* ub, uint16_t mtu); 38 | void uxr_buffer_delete_session(uxrSessionInfo* info, struct ucdrBuffer* ub); 39 | void uxr_read_create_session_status(uxrSessionInfo* info, struct ucdrBuffer* ub); 40 | void uxr_read_delete_session_status(uxrSessionInfo* info, struct ucdrBuffer* ub); 41 | 42 | void uxr_stamp_create_session_header(const uxrSessionInfo* info, uint8_t* buffer); 43 | void uxr_stamp_session_header(const uxrSessionInfo* info, uint8_t stream_id_raw, uxrSeqNum seq_num, uint8_t* buffer); 44 | bool uxr_read_session_header(const uxrSessionInfo* info, struct ucdrBuffer* ub, uint8_t* stream_id_raw, uxrSeqNum* seq_num); 45 | 46 | uint8_t uxr_session_header_offset(const uxrSessionInfo* info); 47 | 48 | uint16_t uxr_init_base_object_request(uxrSessionInfo* info, uxrObjectId object_id, struct BaseObjectRequest* base); 49 | void uxr_parse_base_object_request(const struct BaseObjectRequest* base, uxrObjectId* object_id, uint16_t* request_id); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif // _SRC_C_CORE_SESSION_SESSION_INFO_INTERNAL_H_ 56 | 57 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/ip/udp/udp_transport.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_UDP_TRANSPORT_H_ 16 | #define UXR_CLIENT_UDP_TRANSPORT_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct uxrUDPPlatform; 29 | 30 | typedef struct uxrUDPTransport 31 | { 32 | uint8_t buffer[UXR_CONFIG_UDP_TRANSPORT_MTU]; 33 | uxrCommunication comm; 34 | struct uxrUDPPlatform* platform; 35 | 36 | } uxrUDPTransport; 37 | 38 | /** 39 | * @brief Initializes a UDP transport. 40 | * @param transport The uninitialized transport structure used for managing the transport. 41 | * This structure must be accesible during the connection. 42 | * @param platform A structure that contains the platform dependencies. 43 | * @param ip_protocol The IP protocol, it could be UXR_IPv4 or UXR_IPv6. 44 | * @param ip The IP address of the Agent. 45 | * @param port The port of the Agent. 46 | * @return `true` in case of successful initialization. `false` in other case. 47 | */ 48 | UXRDLLAPI bool uxr_init_udp_transport( 49 | uxrUDPTransport* transport, 50 | struct uxrUDPPlatform* platform, 51 | uxrIpProtocol ip_protocol, 52 | const char* ip, 53 | const char* port); 54 | 55 | /** 56 | * @brief Closes a UDP transport. 57 | * @param transport The transport structure. 58 | * @return `true` in case of successful closing. `false` in other case. 59 | */ 60 | UXRDLLAPI bool uxr_close_udp_transport( 61 | uxrUDPTransport* transport); 62 | 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif // UXR_CLIENT_UDP_TRANSPORT_H_ 69 | -------------------------------------------------------------------------------- /inc/uxr/client/transport.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_TRANSPORT_H_ 16 | #define UXR_CLIENT_TRANSPORT_H_ 17 | 18 | #include 19 | 20 | #ifdef UCLIENT_PROFILE_UDP 21 | #include 22 | #if defined(UCLIENT_EXTERNAL_UDP) 23 | #include 24 | #elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) 25 | #include 26 | #elif defined(UCLIENT_PLATFORM_POSIX) 27 | #include 28 | #elif defined(UCLIENT_PLATFORM_WINDOWS) 29 | #include 30 | #elif defined(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) 31 | #include 32 | #endif 33 | #endif //UCLIENT_PROFILE_UDP 34 | 35 | #ifdef UCLIENT_PROFILE_TCP 36 | #include 37 | #if defined(UCLIENT_EXTERNAL_TCP) 38 | #include 39 | #elif defined(UCLIENT_PLATFORM_POSIX) 40 | #include 41 | #elif defined(UCLIENT_PLATFORM_WINDOWS) 42 | #include 43 | #endif 44 | #endif //UCLIENT_PROFILE_TCP 45 | 46 | #ifdef UCLIENT_PROFILE_SERIAL 47 | #include 48 | #if defined(UCLIENT_EXTERNAL_SERIAL) 49 | #include 50 | #elif defined(UCLIENT_PLATFORM_POSIX) 51 | #include 52 | #elif defined(UCLIENT_PLATFORM_WINDOWS) 53 | #endif 54 | #endif //UCLIENT_PROFILE_SERIAL 55 | 56 | #endif // UXR_CLIENT_TRANSPORT_H_ 57 | -------------------------------------------------------------------------------- /src/c/profile/transport/serial/serial_protocol_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 16 | #define _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define UXR_FRAMING_BEGIN_FLAG 0x7E 27 | #define UXR_FRAMING_ESC_FLAG 0x7D 28 | #define UXR_FRAMING_XOR_FLAG 0x20 29 | 30 | void uxr_init_serial_io(uxrSerialIO* serial_io, uint8_t local_addr); 31 | 32 | void uxr_update_crc(uint16_t* crc, const uint8_t data); 33 | bool uxr_get_next_octet(uxrSerialIO* serial_io, uint8_t* octet); 34 | bool uxr_add_next_octet(uxrSerialIO* serial_io, uint8_t octet); 35 | 36 | struct uxrSerialPlatform; 37 | typedef size_t (*uxr_write_cb)(struct uxrSerialPlatform*, uint8_t*, size_t, uint8_t*); 38 | typedef size_t (*uxr_read_cb)(struct uxrSerialPlatform*, uint8_t*, size_t, int, uint8_t*); 39 | 40 | size_t uxr_write_serial_msg(uxrSerialIO* serial_io, 41 | uxr_write_cb write_cb, 42 | void* cb_arg, 43 | const uint8_t* buf, 44 | size_t len, 45 | uint8_t remote_addr, 46 | uint8_t* errcode); 47 | 48 | size_t uxr_read_serial_msg(uxrSerialIO* serial_io, 49 | uxr_read_cb read_cb, 50 | void* cb_arg, 51 | uint8_t* buf, 52 | size_t len, 53 | uint8_t* remote_addr, 54 | int timeout, 55 | uint8_t* errcode); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif //_SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ 62 | -------------------------------------------------------------------------------- /inc/uxr/client/config.h.in: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _UXR_CLIENT_CONFIG_H_ 16 | #define _UXR_CLIENT_CONFIG_H_ 17 | 18 | #define UXR_CLIENT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 19 | #define UXR_CLIENT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 20 | #define UXR_CLIENT_VERSION_MICRO @PROJECT_VERSION_PATCH@ 21 | #define UXR_CLIENT_VERSION_STR "@PROJECT_VERSION@" 22 | 23 | #cmakedefine UCLIENT_PROFILE_DISCOVERY 24 | 25 | #cmakedefine UCLIENT_PROFILE_UDP 26 | #cmakedefine UCLIENT_PROFILE_TCP 27 | #cmakedefine UCLIENT_PROFILE_SERIAL 28 | 29 | #cmakedefine UCLIENT_PLATFORM_POSIX 30 | #cmakedefine UCLIENT_PLATFORM_POSIX_NOPOLL 31 | #cmakedefine UCLIENT_PLATFORM_WINDOWS 32 | #cmakedefine UCLIENT_PLATFORM_FREERTOS_PLUS_TCP 33 | 34 | #cmakedefine UCLIENT_EXTERNAL_TCP 35 | #cmakedefine UCLIENT_EXTERNAL_UDP 36 | #cmakedefine UCLIENT_EXTERNAL_SERIAL 37 | 38 | #define UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS @UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS@ 39 | #define UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS @UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS@ 40 | #define UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS @UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS@ 41 | #define UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS @UCLIENT_MAX_INPUT_RELIABLE_STREAMS@ 42 | 43 | #define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS @UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS@ 44 | #define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL @UCLIENT_MIN_SESSION_CONNECTION_INTERVAL@ 45 | #define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL @UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL@ 46 | 47 | #ifdef UCLIENT_PROFILE_UDP 48 | #define UXR_CONFIG_UDP_TRANSPORT_MTU @UCLIENT_UDP_TRANSPORT_MTU@ 49 | #endif 50 | #ifdef UCLIENT_PROFILE_TCP 51 | #define UXR_CONFIG_TCP_TRANSPORT_MTU @UCLIENT_TCP_TRANSPORT_MTU@ 52 | #endif 53 | #ifdef UCLIENT_PROFILE_SERIAL 54 | #define UXR_CONFIG_SERIAL_TRANSPORT_MTU @UCLIENT_SERIAL_TRANSPORT_MTU@ 55 | #endif 56 | 57 | #endif // _UXR_CLIENT_CONFIG_H_ 58 | -------------------------------------------------------------------------------- /src/ucdr/test/SequenceOverflow.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "serialization/SequenceSerialization.hpp" 16 | 17 | #define SEQUENCE_SIZE_OVERFLOW ARRAY_CAPACITY + 1 18 | 19 | class SequenceOverflow : public SequenceSerialization 20 | { 21 | public: 22 | SequenceOverflow() 23 | { 24 | set_sequence_size(SEQUENCE_SIZE_OVERFLOW); 25 | } 26 | 27 | ~SequenceOverflow() 28 | { 29 | EXPECT_TRUE(reader.error); 30 | 31 | // To satisfy the base destructor 32 | reader.error = false; 33 | reader.iterator = writer.iterator; 34 | } 35 | 36 | private: 37 | }; 38 | 39 | TEST_F(SequenceOverflow, Block1) 40 | { 41 | uint8_t input[SEQUENCE_SIZE_OVERFLOW]; 42 | uint8_t output[ARRAY_CAPACITY]; 43 | 44 | EXPECT_TRUE(ucdr_serialize_sequence_uint8_t(&writer, input, SEQUENCE_SIZE_OVERFLOW)); 45 | EXPECT_FALSE(ucdr_deserialize_sequence_uint8_t(&reader, output, ARRAY_CAPACITY, &output_size)); 46 | } 47 | 48 | TEST_F(SequenceOverflow, Block2) 49 | { 50 | uint16_t input[SEQUENCE_SIZE_OVERFLOW]; 51 | uint16_t output[ARRAY_CAPACITY]; 52 | 53 | EXPECT_TRUE(ucdr_serialize_sequence_uint16_t(&writer, input, SEQUENCE_SIZE_OVERFLOW)); 54 | EXPECT_FALSE(ucdr_deserialize_sequence_uint16_t(&reader, output, ARRAY_CAPACITY, &output_size)); 55 | } 56 | 57 | TEST_F(SequenceOverflow, Block4) 58 | { 59 | uint32_t input[SEQUENCE_SIZE_OVERFLOW]; 60 | uint32_t output[ARRAY_CAPACITY]; 61 | 62 | EXPECT_TRUE(ucdr_serialize_sequence_uint32_t(&writer, input, SEQUENCE_SIZE_OVERFLOW)); 63 | EXPECT_FALSE(ucdr_deserialize_sequence_uint32_t(&reader, output, ARRAY_CAPACITY, &output_size)); 64 | } 65 | 66 | TEST_F(SequenceOverflow, Block8) 67 | { 68 | uint64_t input[SEQUENCE_SIZE_OVERFLOW]; 69 | uint64_t output[ARRAY_CAPACITY]; 70 | 71 | EXPECT_TRUE(ucdr_serialize_sequence_uint64_t(&writer, input, SEQUENCE_SIZE_OVERFLOW)); 72 | EXPECT_FALSE(ucdr_deserialize_sequence_uint64_t(&reader, output, ARRAY_CAPACITY, &output_size)); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/ucdr/test/FullBufferCallback.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "FullBuffer.hpp" 16 | 17 | class FullBufferCallback : public FullBuffer 18 | { 19 | public: 20 | FullBufferCallback() 21 | { 22 | ucdr_set_on_full_buffer_callback(&writer, on_full_buffer, buffer); 23 | ucdr_set_on_full_buffer_callback(&reader, on_full_buffer, buffer); 24 | } 25 | 26 | protected: 27 | static bool on_full_buffer(ucdrBuffer* ub, void* args) 28 | { 29 | uint8_t* buffer = static_cast(args); 30 | 31 | EXPECT_EQ(buffer, ub->init); 32 | EXPECT_EQ(buffer + BUFFER_LENGTH, ub->final); //only satisfied if BUFFER_LENGTH is alignment to 8. 33 | 34 | return true; 35 | } 36 | }; 37 | 38 | TEST_F(FullBufferCallback, Block_8_callback) 39 | { 40 | fill_buffer_except(7); 41 | try_block_8(); 42 | } 43 | 44 | TEST_F(FullBufferCallback, Block_4_callback) 45 | { 46 | fill_buffer_except(3); 47 | try_block_4(); 48 | } 49 | 50 | TEST_F(FullBufferCallback, Block_2_callback) 51 | { 52 | fill_buffer_except(1); 53 | try_block_2(); 54 | } 55 | 56 | TEST_F(FullBufferCallback, Block_1_callback) 57 | { 58 | fill_buffer_except(0); 59 | try_block_1(); 60 | } 61 | 62 | # define SUCCESSFUL_SERIALIZATION 3 63 | # define ARRAY_SERIALIZATION (SUCCESSFUL_SERIALIZATION + 1) 64 | TEST_F(FullBufferCallback, ArrayBlock_8_callback) 65 | { 66 | fill_buffer_except(8 * SUCCESSFUL_SERIALIZATION + 7); 67 | try_array_block_8(ARRAY_SERIALIZATION); 68 | } 69 | 70 | TEST_F(FullBufferCallback, ArrayBlock_4_callback) 71 | { 72 | fill_buffer_except(4 * SUCCESSFUL_SERIALIZATION + 3); 73 | try_array_block_4(ARRAY_SERIALIZATION); 74 | } 75 | 76 | TEST_F(FullBufferCallback, ArrayBlock_2_callback) 77 | { 78 | fill_buffer_except(2 * SUCCESSFUL_SERIALIZATION + 1); 79 | try_array_block_2(ARRAY_SERIALIZATION); 80 | } 81 | 82 | TEST_F(FullBufferCallback, ArrayBlock_1_callback) 83 | { 84 | fill_buffer_except(SUCCESSFUL_SERIALIZATION); 85 | try_array_block_1(ARRAY_SERIALIZATION); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/ip/ip.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_PROFILE_TRANSPORT_IP_IP_H_ 16 | #define UXR_CLIENT_PROFILE_TRANSPORT_IP_IP_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | typedef enum uxrIpProtocol 27 | { 28 | UXR_IPv4, 29 | UXR_IPv6 30 | 31 | } uxrIpProtocol; 32 | 33 | /** 34 | * @brief Converts IPv4/IPv6 address + port to a TransportLocator. 35 | * 36 | * @param ip The IP address to convert. 37 | * It could be IPv4 or IPv6 address. 38 | * @param port The port to convert. 39 | * @param ip_protocol The IP protocol of the IP address. 40 | * @param locator The TransportLocator resulted from the conversion. 41 | * In case of error it will be NULL. 42 | * @return true In case of successful conversion. 43 | * @return false In other case. 44 | */ 45 | UXRDLLAPI bool uxr_ip_to_locator( 46 | char const * ip, 47 | uint16_t port, 48 | uxrIpProtocol ip_protocol, 49 | TransportLocator * locator); 50 | 51 | /** 52 | * @brief Converts a TrasnportLocator to an IPv4/IPv6 address + port. 53 | * 54 | * @param locator The TransportLocator resulted from the conversion. 55 | * In case of error it will be NULL. 56 | * @param ip A char buffer there the address will be copied. 57 | * @param size The size of the IP buffer. 58 | * @param port The resulted port. 59 | * @param ip_protocol The resulted IP protocol of the IP address. 60 | * @return true In case of successful conversion. 61 | * @return false In other case. 62 | */ 63 | UXRDLLAPI bool uxr_locator_to_ip( 64 | TransportLocator const * locator, 65 | char * ip, 66 | size_t size, 67 | uint16_t * port, 68 | uxrIpProtocol * ip_protocol); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_IP_H_ 75 | -------------------------------------------------------------------------------- /src/c/core/session/submessage_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_SUBMESSAGE_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_SUBMESSAGE_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define SUBHEADER_SIZE 4 29 | 30 | struct ucdrBuffer; 31 | 32 | typedef enum SubmessageId 33 | { 34 | SUBMESSAGE_ID_CREATE_CLIENT = 0, 35 | SUBMESSAGE_ID_CREATE = 1, 36 | SUBMESSAGE_ID_GET_INFO = 2, 37 | SUBMESSAGE_ID_DELETE = 3, 38 | SUBMESSAGE_ID_STATUS_AGENT = 4, 39 | SUBMESSAGE_ID_STATUS = 5, 40 | SUBMESSAGE_ID_INFO = 6, 41 | SUBMESSAGE_ID_WRITE_DATA = 7, 42 | SUBMESSAGE_ID_READ_DATA = 8, 43 | SUBMESSAGE_ID_DATA = 9, 44 | SUBMESSAGE_ID_ACKNACK = 10, 45 | SUBMESSAGE_ID_HEARTBEAT = 11, 46 | SUBMESSAGE_ID_RESET = 12, 47 | SUBMESSAGE_ID_FRAGMENT = 13, 48 | SUBMESSAGE_ID_TIMESTAMP = 14, 49 | SUBMESSAGE_ID_TIMESTAMP_REPLY = 15 50 | #ifdef PERFORMANCE_TESTING 51 | , 52 | SUBMESSAGE_ID_PERFORMANCE = 14 53 | #endif 54 | 55 | } SubmessageId; 56 | 57 | typedef enum SubmessageFlags 58 | { 59 | FLAG_ENDIANNESS = 0x01, 60 | FLAG_LAST_FRAGMENT = 0x01 << 1, 61 | FLAG_FORMAT_DATA = 0x00, 62 | FLAG_FORMAT_SAMPLE = 0x02, 63 | FLAG_FORMAT_DATA_SEQ = 0x08, 64 | FLAG_FORMAT_SAMPLE_SEQ = 0x0A, 65 | FLAG_FORMAT_PACKED_SAMPLES = 0x0E 66 | 67 | } SubmessageFlags; 68 | 69 | bool uxr_buffer_submessage_header(struct ucdrBuffer* ub, uint8_t submessage_id, uint16_t length, uint8_t flags); 70 | bool uxr_read_submessage_header(struct ucdrBuffer* ub, uint8_t* submessage_id, uint16_t* length, uint8_t* flags); 71 | size_t uxr_submessage_padding(size_t length); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif // _SRC_C_CORE_SESSION_SUBMESSAGE_INTERNAL_H_ 78 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/ip_posix.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #if defined(UCLIENT_PLATFORM_POSIX) 19 | #include 20 | #elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) 21 | #include 22 | #endif 23 | 24 | bool uxr_ip_to_locator( 25 | char const * ip, 26 | uint16_t port, 27 | uxrIpProtocol ip_protocol, 28 | TransportLocator * locator) 29 | { 30 | bool result = false; 31 | switch (ip_protocol) 32 | { 33 | case UXR_IPv4: 34 | locator->format = ADDRESS_FORMAT_MEDIUM; 35 | locator->_.medium_locator.locator_port = port; 36 | result = (1 == inet_pton(AF_INET, ip, locator->_.medium_locator.address)); 37 | break; 38 | case UXR_IPv6: 39 | locator->format = ADDRESS_FORMAT_LARGE; 40 | locator->_.large_locator.locator_port = port; 41 | result = (1 == inet_pton(AF_INET6, ip, locator->_.large_locator.address)); 42 | break; 43 | default: 44 | break; 45 | } 46 | return result; 47 | } 48 | 49 | bool uxr_locator_to_ip( 50 | TransportLocator const * locator, 51 | char * ip, 52 | size_t size, 53 | uint16_t * port, 54 | uxrIpProtocol * ip_protocol) 55 | { 56 | bool result = false; 57 | switch (locator->format) 58 | { 59 | case ADDRESS_FORMAT_MEDIUM: 60 | *port = locator->_.medium_locator.locator_port; 61 | *ip_protocol = UXR_IPv4; 62 | result = (NULL != inet_ntop(AF_INET, locator->_.medium_locator.address, ip, (socklen_t)size)); 63 | break; 64 | case ADDRESS_FORMAT_LARGE: 65 | *port = (uint16_t)locator->_.large_locator.locator_port; 66 | *ip_protocol = UXR_IPv6; 67 | result = (NULL != inet_ntop(AF_INET6, locator->_.large_locator.address, ip, (socklen_t)size)); 68 | break; 69 | default: 70 | break; 71 | } 72 | return result; 73 | } -------------------------------------------------------------------------------- /src/c/profile/discovery/transport/udp_transport_datagram_posix.c: -------------------------------------------------------------------------------- 1 | #include "udp_transport_datagram_internal.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | bool uxr_init_udp_transport_datagram( 9 | uxrUDPTransportDatagram* transport) 10 | { 11 | int fd = socket(PF_INET, SOCK_DGRAM, 0); 12 | transport->poll_fd.fd = fd; 13 | transport->poll_fd.events = POLLIN; 14 | 15 | return fd != -1; 16 | } 17 | 18 | bool uxr_close_udp_transport_datagram( 19 | uxrUDPTransportDatagram* transport) 20 | { 21 | return (0 == close(transport->poll_fd.fd)); 22 | } 23 | 24 | bool uxr_udp_send_datagram_to( 25 | uxrUDPTransportDatagram* transport, 26 | const uint8_t* buf, 27 | size_t len, 28 | const TransportLocator* locator) 29 | { 30 | bool rv = true; 31 | switch (locator->format) 32 | { 33 | case ADDRESS_FORMAT_MEDIUM: 34 | { 35 | struct sockaddr_in remote_addr; 36 | memcpy(&remote_addr.sin_addr, locator->_.medium_locator.address, sizeof(remote_addr.sin_addr)); 37 | remote_addr.sin_family = AF_INET; 38 | remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); 39 | 40 | ssize_t bytes_sent = sendto(transport->poll_fd.fd, (const void*)buf, len, 0, 41 | (struct sockaddr*)&remote_addr, sizeof(remote_addr)); 42 | if (0 > bytes_sent) 43 | { 44 | rv = false; 45 | } 46 | break; 47 | } 48 | default: 49 | rv = false; 50 | break; 51 | } 52 | return rv; 53 | } 54 | 55 | bool uxr_udp_recv_datagram( 56 | uxrUDPTransportDatagram* transport, 57 | uint8_t** buf, 58 | size_t* len, 59 | int timeout) 60 | { 61 | bool rv = false; 62 | 63 | int poll_rv = poll(&transport->poll_fd, 1, timeout); 64 | if (0 < poll_rv) 65 | { 66 | ssize_t bytes_received = recv(transport->poll_fd.fd, (void*)transport->buffer, sizeof(transport->buffer), 0); 67 | if (0 < bytes_received) 68 | { 69 | *len = (size_t)bytes_received; 70 | *buf = transport->buffer; 71 | rv = true; 72 | } 73 | } 74 | else if (0 == poll_rv) 75 | { 76 | errno = ETIME; 77 | } 78 | 79 | return rv; 80 | } 81 | 82 | void uxr_bytes_to_ip( 83 | const uint8_t* bytes, 84 | char* ip) 85 | { 86 | struct in_addr addr; 87 | addr.s_addr = (in_addr_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); 88 | char* internal_ip = inet_ntoa(addr); 89 | strcpy(ip, internal_ip); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c: -------------------------------------------------------------------------------- 1 | #include "udp_transport_datagram_internal.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | bool uxr_init_udp_transport_datagram( 11 | uxrUDPTransportDatagram* transport) 12 | { 13 | int fd = socket(PF_INET, SOCK_DGRAM, 0); 14 | transport->fd = fd; 15 | 16 | return fd != -1; 17 | } 18 | 19 | bool uxr_close_udp_transport_datagram( 20 | uxrUDPTransportDatagram* transport) 21 | { 22 | return (0 == close(transport->fd)); 23 | } 24 | 25 | bool uxr_udp_send_datagram_to( 26 | uxrUDPTransportDatagram* transport, 27 | const uint8_t* buf, 28 | size_t len, 29 | const TransportLocator* locator) 30 | { 31 | bool rv = true; 32 | switch (locator->format) 33 | { 34 | case ADDRESS_FORMAT_MEDIUM: 35 | { 36 | struct sockaddr_in remote_addr; 37 | memcpy(&remote_addr.sin_addr, locator->_.medium_locator.address, sizeof(remote_addr.sin_addr)); 38 | remote_addr.sin_family = AF_INET; 39 | remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); 40 | 41 | ssize_t bytes_sent = sendto(transport->fd, (const void*)buf, len, 0, 42 | (struct sockaddr*)&remote_addr, sizeof(remote_addr)); 43 | if (0 > bytes_sent) 44 | { 45 | rv = false; 46 | } 47 | break; 48 | } 49 | default: 50 | rv = false; 51 | break; 52 | } 53 | return rv; 54 | } 55 | 56 | bool uxr_udp_recv_datagram( 57 | uxrUDPTransportDatagram* transport, 58 | uint8_t** buf, 59 | size_t* len, 60 | int timeout) 61 | { 62 | bool rv = false; 63 | 64 | timeout = (timeout <= 0) ? 1 : timeout; 65 | 66 | struct timeval tv; 67 | tv.tv_sec = timeout / 1000; 68 | tv.tv_usec = (timeout % 1000) * 1000; 69 | 70 | setsockopt(transport->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); 71 | 72 | ssize_t bytes_received = recv(transport->fd, (void*)transport->buffer, sizeof(transport->buffer), 0); 73 | if (-1 != bytes_received) 74 | { 75 | *len = (size_t)bytes_received; 76 | *buf = transport->buffer; 77 | rv = true; 78 | } 79 | 80 | return rv; 81 | } 82 | 83 | void uxr_bytes_to_ip( 84 | const uint8_t* bytes, 85 | char* ip) 86 | { 87 | struct in_addr addr; 88 | addr.s_addr = (in_addr_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); 89 | char* internal_ip = inet_ntoa(addr); 90 | strcpy(ip, internal_ip); 91 | } 92 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/serial/serial_transport.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_SERIAL_TRANSPORT_H_ 16 | #define UXR_CLIENT_SERIAL_TRANSPORT_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct uxrSerialPlatform; 29 | 30 | typedef struct uxrSerialTransport 31 | { 32 | uint8_t buffer[UXR_CONFIG_SERIAL_TRANSPORT_MTU]; 33 | uxrSerialIO serial_io; 34 | uint8_t remote_addr; 35 | uxrCommunication comm; 36 | struct uxrSerialPlatform* platform; 37 | 38 | } uxrSerialTransport; 39 | 40 | 41 | /** 42 | * @brief Initializes a UDP transport. 43 | * @param transport The uninitialized transport structure used for managing the transport. 44 | * This structure must be accesible during the connection. 45 | * @param platform A structure that contains the platform dependencies. 46 | * @param fd The file descriptor of the serial connection. 47 | * The fd usually comes from the `open` OS function. 48 | * @param remote_addr The addresss of the Agent in the serial connection. 49 | * By default, the Agent address' in a serial transport is 0. 50 | * @param local_addr The address of the Client in the serial connection. 51 | * @return `true` in case of successful initialization. `false` in other case. 52 | */ 53 | UXRDLLAPI bool uxr_init_serial_transport( 54 | uxrSerialTransport* transport, 55 | struct uxrSerialPlatform* platform, 56 | const int fd, 57 | uint8_t remote_addr, 58 | uint8_t local_addr); 59 | 60 | /** 61 | * @brief Closes a Serial transport. 62 | * @param transport The transport structure. 63 | * @return `true` in case of successful closing. `false` in other case. 64 | */ 65 | UXRDLLAPI bool uxr_close_serial_transport(uxrSerialTransport* transport); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif // UXR_CLIENT_SERIAL_TRANSPORT_H_ 72 | -------------------------------------------------------------------------------- /src/c/core/session/common_create_entities.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "common_create_entities_internal.h" 4 | #include "session_internal.h" 5 | #include "session_info_internal.h" 6 | #include "submessage_internal.h" 7 | 8 | //================================================================== 9 | // PUBLIC 10 | //================================================================== 11 | uint16_t uxr_buffer_delete_entity(uxrSession* session, uxrStreamId stream_id, uxrObjectId object_id) 12 | { 13 | uint16_t request_id = UXR_INVALID_REQUEST_ID; 14 | 15 | DELETE_Payload payload; 16 | 17 | // Change this when microcdr supports size_of function. 18 | size_t payload_length = 0; //DELETE_Payload_size(&payload); 19 | payload_length = (uint16_t)(payload_length + 4); // delete payload (request id + object_id), no padding. 20 | 21 | ucdrBuffer ub; 22 | if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_DELETE, 0)) 23 | { 24 | request_id = uxr_init_base_object_request(&session->info, object_id, &payload.base); 25 | (void) uxr_serialize_DELETE_Payload(&ub, &payload); 26 | } 27 | 28 | return request_id; 29 | } 30 | 31 | uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, 32 | uxrObjectId object_id, uint16_t xml_ref_size, uint8_t mode, 33 | CREATE_Payload* payload) 34 | { 35 | uint16_t request_id = UXR_INVALID_REQUEST_ID; 36 | 37 | // Change this when microcdr supports size_of function. Currently, DOMAIN_ID is not supported. 38 | size_t payload_length = 0; //CREATE_Payload_size(&payload); 39 | payload_length = (uint16_t)(payload_length + 4); // base 40 | payload_length = (uint16_t)(payload_length + 1); // objk type 41 | payload_length = (uint16_t)(payload_length + 1); // base3 type => xml 42 | payload_length = (uint16_t)(payload_length + 2); // padding 43 | payload_length = (uint16_t)(payload_length + 4); // xml length 44 | payload_length = (uint16_t)(payload_length + xml_ref_size); // xml data (note: compiler executes strlen one time this function) 45 | payload_length = (uint16_t)(payload_length + ((object_id.type == DDS_XRCE_OBJK_PARTICIPANT && payload_length % 2 != 0) ? 1 : 0)); // necessary padding 46 | payload_length = (uint16_t)(payload_length + 2); //object id ref 47 | 48 | ucdrBuffer ub; 49 | if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_CREATE, mode)) 50 | { 51 | request_id = uxr_init_base_object_request(&session->info, object_id, &payload->base); 52 | (void) uxr_serialize_CREATE_Payload(&ub, payload); 53 | } 54 | 55 | return request_id; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/ucdr/test/fragmentation/BasicFragmentation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "../serialization/BasicSerialization.hpp" 16 | 17 | class BasicFragmentation : public BasicSerialization 18 | { 19 | public: 20 | BasicFragmentation() 21 | { 22 | ucdr_set_on_full_buffer_callback(&writer, on_full_buffer, this); 23 | ucdr_set_on_full_buffer_callback(&reader, on_full_buffer, this); 24 | std::memset(buffer2, 0, BUFFER_LENGTH); 25 | for(int i = 0; i < BUFFER_LENGTH; ++i) 26 | { 27 | uint8_t_serialization(); 28 | } 29 | } 30 | 31 | protected: 32 | static bool on_full_buffer(ucdrBuffer* ub, void* args) 33 | { 34 | BasicFragmentation* obj = static_cast(args); 35 | 36 | ub->init = obj->buffer2; 37 | ub->iterator = ub->init; 38 | ub->final = ub->init + BUFFER_LENGTH; 39 | 40 | return false; 41 | } 42 | 43 | uint8_t buffer2[BUFFER_LENGTH]; 44 | }; 45 | 46 | TEST_F(BasicFragmentation, Bool) 47 | { 48 | bool_serialization(); 49 | } 50 | 51 | TEST_F(BasicFragmentation, Char) 52 | { 53 | char_serialization(); 54 | } 55 | 56 | TEST_F(BasicFragmentation, Int8) 57 | { 58 | int8_t_serialization(); 59 | } 60 | 61 | TEST_F(BasicFragmentation, Uint8) 62 | { 63 | uint8_t_serialization(); 64 | } 65 | 66 | TEST_F(BasicFragmentation, Int16) 67 | { 68 | int16_t_serialization(); 69 | } 70 | 71 | TEST_F(BasicFragmentation, Uint16) 72 | { 73 | uint16_t_serialization(); 74 | } 75 | 76 | TEST_F(BasicFragmentation, Int32) 77 | { 78 | int32_t_serialization(); 79 | } 80 | 81 | TEST_F(BasicFragmentation, Uint32) 82 | { 83 | uint32_t_serialization(); 84 | } 85 | 86 | TEST_F(BasicFragmentation, Int64) 87 | { 88 | int64_t_serialization(); 89 | } 90 | 91 | TEST_F(BasicFragmentation, Uint64) 92 | { 93 | uint64_t_serialization(); 94 | } 95 | 96 | TEST_F(BasicFragmentation, Float) 97 | { 98 | float_serialization(); 99 | } 100 | 101 | TEST_F(BasicFragmentation, Double) 102 | { 103 | double_serialization(); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/discovery/discovery.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_PROFILE_DISCOVERY_DISCOVERY_H_ 16 | #define UXR_CLIENT_PROFILE_DISCOVERY_DISCOVERY_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | typedef bool (*uxrOnAgentFound) (const TransportLocator* locator, void* args); 32 | 33 | /** 34 | * @brief Discovers Agents within the network using UDP/IP multicast with address "239.255.0.2" and port 7400. 35 | * @param attempts The times a discovery message is sent across the network. 36 | * @param period The period using to send multicast messages through the network. 37 | * @param on_agent_func The callback function that will be called when an Agent is discovered. 38 | * @param args The user argument provided to the callback function. 39 | */ 40 | UXRDLLAPI void uxr_discovery_agents_default( 41 | uint32_t attempts, 42 | int period, 43 | uxrOnAgentFound on_agent_func, 44 | void* args); 45 | 46 | /** 47 | * @brief Discovers Agents within the network using UDP/IP unicast with the address and port set by the user. 48 | * @param attempts The times a discovery message is sent across the network. 49 | * @param period The period using to send unicast messages through the network. 50 | * @param on_agent_func The callback function that will called when an Agent is discovered. 51 | * @param args The user argument provided to the callback function. 52 | * @param agent_list The list of addresses used for discovering Agents. 53 | * @param agent_list_size The size of the address list. 54 | */ 55 | UXRDLLAPI void uxr_discovery_agents( 56 | uint32_t attempts, 57 | int period, 58 | uxrOnAgentFound on_agent_func, 59 | void* args, 60 | const TransportLocator* agent_list, 61 | size_t agent_list_size); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif // UXR_CLIENT_PROFILE_DISCOVERY_DISCOVERY_H_ 68 | -------------------------------------------------------------------------------- /src/c/profile/discovery/transport/udp_transport_datagram_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SRC_C_CLIENT_UDP_TRANSPORT_DATAGRAM_INTERNAL_H_ 16 | #define SRC_C_CLIENT_UDP_TRANSPORT_DATAGRAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #if defined(UCLIENT_PLATFORM_POSIX) 32 | #include 33 | #include 34 | #include 35 | #elif defined(UCLIENT_PLATFORM_WINDOWS) 36 | #include 37 | #elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) 38 | #include "FreeRTOS.h" 39 | #include "list.h" 40 | #include "FreeRTOS_IP.h" 41 | #include "FreeRTOS_Sockets.h" 42 | #endif 43 | 44 | 45 | // TODO (julibert): move this to CMake flag. 46 | #define UXR_UDP_TRANSPORT_MTU_DATAGRAM 200 //Adjusted to the minimun necessary buffer for discovery messages. 47 | 48 | typedef struct uxrUDPTransportDatagram 49 | { 50 | uint8_t buffer[UXR_UDP_TRANSPORT_MTU_DATAGRAM]; 51 | #if defined(UCLIENT_PLATFORM_POSIX) 52 | struct pollfd poll_fd; 53 | #elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) 54 | int fd; 55 | #elif defined(UCLIENT_PLATFORM_WINDOWS) 56 | WSAPOLLFD poll_fd; 57 | #elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) 58 | SocketSet_t poll_fd; 59 | Socket_t fd; 60 | #endif 61 | 62 | } uxrUDPTransportDatagram; 63 | 64 | bool uxr_init_udp_transport_datagram( 65 | struct uxrUDPTransportDatagram* transport); 66 | 67 | bool uxr_udp_send_datagram_to( 68 | struct uxrUDPTransportDatagram* transport, 69 | const uint8_t* buf, 70 | size_t length, 71 | const TransportLocator* locator); 72 | 73 | bool uxr_udp_recv_datagram( 74 | struct uxrUDPTransportDatagram* transport, 75 | uint8_t** buf, 76 | size_t* len, 77 | int timeout); 78 | 79 | bool uxr_close_udp_transport_datagram( 80 | struct uxrUDPTransportDatagram* transport); 81 | 82 | void uxr_bytes_to_ip( 83 | const uint8_t* bytes, 84 | char* ip); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif // SRC_C_CLIENT_UDP_TRANSPORT_DATAGRAM_INTERNAL_H_ 91 | -------------------------------------------------------------------------------- /inc/uxr/client/profile/transport/ip/tcp/tcp_transport.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_TCP_TRANSPORT_H_ 16 | #define UXR_CLIENT_TCP_TRANSPORT_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | typedef enum uxrTCPInputBufferState 29 | { 30 | UXR_TCP_BUFFER_EMPTY, 31 | UXR_TCP_SIZE_INCOMPLETE, 32 | UXR_TCP_SIZE_READ, 33 | UXR_TCP_MESSAGE_INCOMPLETE, 34 | UXR_TCP_MESSAGE_AVAILABLE 35 | 36 | } uxrTCPInputBufferState; 37 | 38 | typedef struct uxrTCPInputBuffer 39 | { 40 | uint8_t buffer[UXR_CONFIG_TCP_TRANSPORT_MTU]; 41 | size_t position; 42 | uxrTCPInputBufferState state; 43 | size_t msg_size; 44 | 45 | } uxrTCPInputBuffer; 46 | 47 | struct uxrTCPPlatform; 48 | 49 | typedef struct uxrTCPTransport 50 | { 51 | uxrTCPInputBuffer input_buffer; 52 | uxrCommunication comm; 53 | struct uxrTCPPlatform* platform; 54 | 55 | } uxrTCPTransport; 56 | 57 | /** 58 | * @brief Initializes a TCP transport. 59 | * @param transport The uninitialized transport structure used for managing the transport. 60 | * This structure must be accesible during the connection. 61 | * @param platform A structure that contains the platform dependencies. 62 | * @param ip_protocol The IP protocol, it could be UXR_IPv4 or UXR_IPv6. 63 | * @param ip The IP address of the Agent. 64 | * @param port The port of the Agent. 65 | * @return `true` in case of successful initialization. `false` in other case. 66 | */ 67 | UXRDLLAPI bool uxr_init_tcp_transport( 68 | uxrTCPTransport* transport, 69 | struct uxrTCPPlatform* platform, 70 | uxrIpProtocol ip_protocol, 71 | const char* ip, 72 | const char* port); 73 | 74 | /** 75 | * @brief Closes a TCP transport. 76 | * @param transport The transport structure. 77 | * @return `true` in case of successful closing. `false` in other case. 78 | */ 79 | UXRDLLAPI bool uxr_close_tcp_transport( 80 | uxrTCPTransport* transport); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif // UXR_CLIENT_TCP_TRANSPORT_H_ 87 | -------------------------------------------------------------------------------- /src/c/core/session/stream/common_reliable_stream_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SRC__C__CORE__SESSION__STREAM__COMMON_RELIABLE_STREAM_INTERNAL_H_ 16 | #define SRC__C__CORE__SESSION__STREAM__COMMON_RELIABLE_STREAM_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | typedef uint32_t length_t; 31 | #define INTERNAL_RELIABLE_BUFFER_OFFSET sizeof(length_t) 32 | 33 | static inline uint8_t * uxr_get_reliable_buffer( 34 | uxrReliableStream const * stream, 35 | uint16_t seq_num) 36 | { 37 | return stream->buffer 38 | + ((seq_num % stream->history) * (stream->size / stream->history)) 39 | + INTERNAL_RELIABLE_BUFFER_OFFSET; 40 | } 41 | 42 | static inline size_t uxr_get_reliable_buffer_capacity( 43 | uxrReliableStream const * stream) 44 | { 45 | return stream->size / stream->history - INTERNAL_RELIABLE_BUFFER_OFFSET; 46 | } 47 | 48 | static inline uint16_t uxr_get_reliable_buffer_history_position( 49 | uxrReliableStream const * stream, 50 | uint8_t const * current_position) 51 | { 52 | return (uint16_t)((size_t)(current_position - stream->buffer) / (stream->size / stream->history)); 53 | } 54 | 55 | static inline size_t uxr_get_reliable_buffer_size( 56 | uxrReliableStream const * stream, 57 | uint16_t seq_num) 58 | { 59 | length_t length; 60 | memcpy( 61 | &length, 62 | uxr_get_reliable_buffer(stream, (seq_num % stream->history)) - INTERNAL_RELIABLE_BUFFER_OFFSET, 63 | sizeof(length_t)); 64 | return (size_t)length; 65 | } 66 | 67 | static inline void uxr_set_reliable_buffer_size( 68 | uxrReliableStream const * stream, 69 | uint16_t seq_num, 70 | size_t length) 71 | { 72 | length_t temp_length = (length_t)length; 73 | memcpy( 74 | uxr_get_reliable_buffer(stream, (seq_num % stream->history)) - INTERNAL_RELIABLE_BUFFER_OFFSET, 75 | &temp_length, 76 | INTERNAL_RELIABLE_BUFFER_OFFSET); 77 | } 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif // SRC__C__CORE__SESSION__STREAM__COMMON_RELIABLE_STREAM_INTERNAL_H_ 84 | -------------------------------------------------------------------------------- /src/ucdr/examples/fragmentation/fragmentation.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define BUFFER_LENGTH 12 21 | #define SLOTS 12 22 | #define STRING_MAX 128 23 | 24 | bool on_full_buffer(ucdrBuffer* ub, void* args) 25 | { 26 | uint8_t* buffer = (uint8_t*) args; 27 | 28 | // This value correspong with the ub->error, and will be returned by this function to indicates 29 | // if the serialization must continue or must stop because of an error. 30 | bool error = true; 31 | 32 | // Leave the odd slots empty. 33 | uint32_t next_slot = 2 + (uint32_t)(ub->init - buffer) / BUFFER_LENGTH; 34 | if(next_slot < SLOTS) 35 | { 36 | // Modify the internal buffer 37 | ub->init = buffer + BUFFER_LENGTH * next_slot; 38 | ub->iterator = ub->init; 39 | ub->final = ub->init + BUFFER_LENGTH; 40 | 41 | printf(" Extend buffer to slot %u\n", next_slot); 42 | 43 | // As we want to continue the serialization without errors, we return false. 44 | error = false; 45 | } 46 | 47 | return error; 48 | } 49 | 50 | int main() 51 | { 52 | // Data buffer 53 | uint8_t buffer[SLOTS * BUFFER_LENGTH]; 54 | 55 | // Structs for handle the buffer. 56 | ucdrBuffer writer; 57 | ucdrBuffer reader; 58 | 59 | // Initialize the MicroBuffers for working with an user-managed buffer. 60 | ucdr_init_buffer(&writer, buffer, BUFFER_LENGTH); 61 | ucdr_init_buffer(&reader, buffer, BUFFER_LENGTH); 62 | 63 | // Add a full buffer behavior to the writer and the reader 64 | ucdr_set_on_full_buffer_callback(&writer, on_full_buffer, buffer); 65 | ucdr_set_on_full_buffer_callback(&reader, on_full_buffer, buffer); 66 | 67 | // Serialize data 68 | printf("Serializing...\n"); 69 | char input[STRING_MAX] = "Hello MicroCDR! this message is fragmented"; 70 | ucdr_serialize_string(&writer, input); 71 | printf("\n"); 72 | 73 | // Deserialize data 74 | printf("Deserializing...\n"); 75 | char output[STRING_MAX]; 76 | ucdr_deserialize_string(&reader, output, STRING_MAX); 77 | printf("\n"); 78 | 79 | printf("Input: %s\n", input); 80 | printf("Output: %s\n", output); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /docs/samples.md: -------------------------------------------------------------------------------- 1 | # 示例程序 # 2 | 3 | `examples/example_uros.c`: 包含了uros ping-pong的实例代码。Client端(BSP)订阅/microROS/ping消息,收到消息后,发送/microROS/pong消息到Agent端(ROS2). 4 | 5 | ## 准备工作 ## 6 | - 在Ubuntu 20.04 LTS上安装ROS 2 Foxy FitzRoy,参考[链接](https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Install-Debians/) 7 | - 安装完ROS2后,使用如下指令安装Micro-ROS 8 | ``` 9 | # Source the ROS 2 installation 10 | source /opt/ros/foxy/setup.bash 11 | 12 | # Create a workspace and download the micro-ROS tools 13 | mkdir microros_ws 14 | cd microros_ws 15 | git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup 16 | 17 | # Update dependencies using rosdep 18 | sudo apt update && rosdep update 19 | rosdep install --from-path src --ignore-src -y 20 | 21 | # Install pip 22 | sudo apt-get install python3-pip 23 | 24 | # Build micro-ROS tools and source them 25 | colcon build 26 | source install/local_setup.bash 27 | ``` 28 | - 创建Micro-ROS Agent 29 | ``` 30 | # Download micro-ROS-Agent packages 31 | ros2 run micro_ros_setup create_agent_ws.sh 32 | # Build step 33 | ros2 run micro_ros_setup build_agent.sh 34 | source install/local_setup.bash 35 | ``` 36 | - 运行Micro-ROS Agent 37 | - UDP: `ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888` 38 | - TCP: `ros2 run micro_ros_agent micro_ros_agent tcp4 --port 8888` 39 | - Serial: `ros2 run micro_ros_agent micro_ros_agent serial --dev [device]` 40 | 41 | ## 运行示例 ## 42 | 43 | - 配置menuconfig使能Micro-XRCE-DDS-Client软件包并包含示例代码 44 | - pkgs --update获取软件包代码 45 | - 编译运行`bsp/qemu-vexpress-a9` 46 | - 在控制台输入`uros_test`指令 47 | - 如果成功将创建跟Micro-ROS Agent的连接,并等待/microROS/ping的消息 48 | - 在电脑上打开新的终端,输入如下指令监听/microROS/pong。注意这时还没有消息发过来,因为还未发送ping指令给Client 49 | ``` 50 | source /opt/ros/foxy/setup.bash 51 | ros2 topic echo /microROS/pong 52 | ``` 53 | - 打开另外一个新的终端,输入如下指令,发送/microROS/ping消息给Client端 54 | ``` 55 | source /opt/ros/foxy/setup.bash 56 | # Send a fake ping 57 | ros2 topic pub /microROS/ping std_msgs/msg/Header '{frame_id: "fake_ping"}' 58 | ``` 59 | 60 | ## 示例结果 ## 61 | 62 | RTT控制台输出结果: 63 | ``` 64 | msh />uros_test 65 | Micro-ROS ping-pong demo. 66 | msh />Wait for ping topic 67 | Received topic: fake_ping, sec: 0 68 | Send pong topic: Hello RT-Thread!, sec: 120 69 | Received topic: fake_ping, sec: 0 70 | Send pong topic: Hello RT-Thread!, sec: 121 71 | Received topic: fake_ping, sec: 0 72 | Send pong topic: Hello RT-Thread!, sec: 122 73 | Received topic: fake_ping, sec: 0 74 | Send pong topic: Hello RT-Thread!, sec: 123 75 | ``` 76 | 77 | 终端输出结果: 78 | ``` 79 | ~/src/microros_ws$ ros2 topic echo /microROS/pong 80 | stamp: 81 | sec: 120 82 | nanosec: 450000000 83 | frame_id: Hello RT-Thread! 84 | --- 85 | stamp: 86 | sec: 121 87 | nanosec: 450000000 88 | frame_id: Hello RT-Thread! 89 | --- 90 | stamp: 91 | sec: 122 92 | nanosec: 450000000 93 | frame_id: Hello RT-Thread! 94 | --- 95 | stamp: 96 | sec: 123 97 | nanosec: 450000000 98 | frame_id: Hello RT-Thread! 99 | --- 100 | 101 | ``` 102 | -------------------------------------------------------------------------------- /src/c/profile/discovery/transport/udp_transport_datagram_windows.c: -------------------------------------------------------------------------------- 1 | #include "udp_transport_datagram_internal.h" 2 | 3 | #include 4 | #include 5 | 6 | bool uxr_init_udp_transport_datagram( 7 | uxrUDPTransportDatagram* transport) 8 | { 9 | bool rv = false; 10 | 11 | /* WSA initialization. */ 12 | WSADATA wsa_data; 13 | if (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data)) 14 | { 15 | return false; 16 | } 17 | 18 | /* Socket initialization. */ 19 | transport->poll_fd.fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 20 | if (INVALID_SOCKET != transport->poll_fd.fd) 21 | { 22 | transport->poll_fd.events = POLLIN; 23 | rv = true; 24 | } 25 | return rv; 26 | } 27 | 28 | bool uxr_close_udp_transport_datagram( 29 | uxrUDPTransportDatagram* transport) 30 | { 31 | bool rv = (INVALID_SOCKET == transport->poll_fd.fd) ? true : (0 == closesocket(transport->poll_fd.fd)); 32 | return (0 == WSACleanup()) && rv; 33 | } 34 | 35 | bool uxr_udp_send_datagram_to( 36 | uxrUDPTransportDatagram* transport, 37 | const uint8_t* buf, 38 | size_t len, 39 | const TransportLocator* locator) 40 | { 41 | bool rv = false; 42 | switch (locator->format) 43 | { 44 | case ADDRESS_FORMAT_MEDIUM: 45 | { 46 | struct sockaddr_in remote_addr; 47 | memcpy(&remote_addr.sin_addr, locator->_.medium_locator.address, sizeof(remote_addr.sin_addr)); 48 | remote_addr.sin_family = AF_INET; 49 | remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); 50 | 51 | int bytes_sent = sendto(transport->poll_fd.fd, (const char*)buf, (int)len, 0, 52 | (struct sockaddr*)&remote_addr, sizeof(remote_addr)); 53 | rv = (SOCKET_ERROR != bytes_sent); 54 | break; 55 | } 56 | default: 57 | break; 58 | } 59 | return rv; 60 | } 61 | 62 | bool uxr_udp_recv_datagram( 63 | uxrUDPTransportDatagram* transport, 64 | uint8_t** buf, 65 | size_t* len, 66 | int timeout) 67 | { 68 | bool rv = false; 69 | 70 | int poll_rv = WSAPoll(&transport->poll_fd, 1, timeout); 71 | if (0 < poll_rv) 72 | { 73 | int bytes_received = recv(transport->poll_fd.fd, (char*)transport->buffer, (int)sizeof(transport->buffer), 0); 74 | if ( bytes_received) 75 | { 76 | *len = (size_t)bytes_received; 77 | *buf = transport->buffer; 78 | rv = true; 79 | } 80 | } 81 | else if (0 == poll_rv) 82 | { 83 | WSASetLastError(WSAETIMEDOUT); 84 | } 85 | 86 | return rv; 87 | } 88 | 89 | void uxr_bytes_to_ip( 90 | const uint8_t* bytes, 91 | char* ip) 92 | { 93 | struct in_addr addr; 94 | addr.s_addr = (unsigned long)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); 95 | inet_ntop(AF_INET, &(addr.s_addr), ip, INET_ADDRSTRLEN); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/c/core/session/stream/stream_storage_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SRC_C_CORE_SESSION_STREAM_STREAM_STORAGE_INTERNAL_H_ 16 | #define _SRC_C_CORE_SESSION_STREAM_STREAM_STORAGE_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void uxr_init_stream_storage(uxrStreamStorage* storage); 32 | void uxr_reset_stream_storage(uxrStreamStorage* storage); 33 | 34 | uxrStreamId uxr_add_output_best_effort_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint8_t header_offset); 35 | uxrStreamId uxr_add_output_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset); 36 | uxrStreamId uxr_add_input_best_effort_buffer(uxrStreamStorage* storage); 37 | uxrStreamId uxr_add_input_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info); 38 | 39 | uxrOutputBestEffortStream* uxr_get_output_best_effort_stream_id(uxrStreamStorage* storage, uint8_t index); 40 | uxrOutputReliableStream* uxr_get_output_reliable_stream_id(uxrStreamStorage* storage, uint8_t index); 41 | uxrInputBestEffortStream* uxr_get_input_best_effort_stream_id(uxrStreamStorage* storage, uint8_t index); 42 | uxrInputReliableStream* uxr_get_input_reliable_stream_id(uxrStreamStorage* storage, uint8_t index); 43 | 44 | uxrOutputBestEffortStream* uxr_get_output_best_effort_stream(uxrStreamStorage* storage, uint8_t index); 45 | uxrOutputReliableStream* uxr_get_output_reliable_stream(uxrStreamStorage* storage, uint8_t index); 46 | uxrInputBestEffortStream* uxr_get_input_best_effort_stream(uxrStreamStorage* storage, uint8_t index); 47 | uxrInputReliableStream* uxr_get_input_reliable_stream(uxrStreamStorage* storage, uint8_t index); 48 | 49 | bool uxr_output_streams_confirmed(const uxrStreamStorage* storage); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif // _SRC_C_CORE_SESSION_STREAM_STREAM_STORAGE_INTERNAL_H_ 56 | -------------------------------------------------------------------------------- /src/ucdr/test/cross_serialization/FastCDRSerialization.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _FASTCDR_SERIALIZATION_HPP_ 16 | #define _FASTCDR_SERIALIZATION_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #define BUFFER_LENGTH 2014 26 | 27 | class FastCDRSerialization : public ::testing::Test 28 | { 29 | public: 30 | 31 | void double_sequence_with_aligment_serialization() 32 | { 33 | using namespace eprosima::fastcdr; 34 | 35 | char buffer_fastcdr[BUFFER_LENGTH] = {0}; 36 | 37 | ucdrBuffer reader_fastcdr; 38 | ucdr_init_buffer(&reader_fastcdr, reinterpret_cast(buffer_fastcdr), BUFFER_LENGTH); 39 | 40 | FastBuffer cdrbuffer(buffer_fastcdr, BUFFER_LENGTH); 41 | Cdr cdr_ser(cdrbuffer); 42 | 43 | // Serialize 2 bytes 44 | const uint8_t octet_array[2] = {0xAA, 0xAA}; 45 | cdr_ser.serializeArray(octet_array, 2); 46 | 47 | uint8_t octet_array_out[2] = {}; 48 | EXPECT_TRUE(ucdr_deserialize_array_uint8_t(&reader_fastcdr, octet_array_out, 2)); 49 | EXPECT_EQ(octet_array[0], octet_array_out[0]); 50 | EXPECT_EQ(octet_array[1], octet_array_out[1]); 51 | 52 | // Serialize 2 doubles = 16 Bytes + 1 Header 53 | const double double_seq[2] = {3.14, 3.14}; 54 | cdr_ser.serializeSequence(double_seq, 2); 55 | 56 | double double_seq_out[2]; 57 | uint32_t double_seq_len; 58 | EXPECT_TRUE(ucdr_deserialize_sequence_double(&reader_fastcdr, double_seq_out, 2, &double_seq_len)); 59 | EXPECT_EQ(double_seq_len, 2u); 60 | 61 | // Serialize 0 doubles = 1 header 62 | std::vector double_vector; 63 | cdr_ser.serializeSequence(double_seq, 0); 64 | 65 | EXPECT_TRUE(ucdr_deserialize_sequence_double(&reader_fastcdr, double_seq_out, 2, &double_seq_len)); 66 | EXPECT_EQ(double_seq_len, 0u); 67 | 68 | // Serialize 2 bytes 69 | cdr_ser.serializeArray(octet_array, 2); 70 | 71 | EXPECT_TRUE(ucdr_deserialize_array_uint8_t(&reader_fastcdr, octet_array_out, 2)); 72 | EXPECT_EQ(octet_array[0], octet_array_out[0]); 73 | EXPECT_EQ(octet_array[1], octet_array_out[1]); 74 | 75 | } 76 | }; 77 | 78 | #endif //_FASTCDR_SERIALIZATION_HPP_ 79 | -------------------------------------------------------------------------------- /src/c/core/session/write_access.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "session_internal.h" 5 | #include "session_info_internal.h" 6 | #include "submessage_internal.h" 7 | 8 | #define WRITE_DATA_PAYLOAD_SIZE 4 9 | #define SAMPLE_IDENTITY_SIZE 24 10 | 11 | //================================================================== 12 | // PUBLIC 13 | //================================================================== 14 | uint16_t uxr_buffer_request( 15 | uxrSession* session, 16 | uxrStreamId stream_id, 17 | uxrObjectId requester_id, 18 | uint8_t* buffer, 19 | size_t len) 20 | { 21 | uint16_t rv = UXR_INVALID_REQUEST_ID; 22 | ucdrBuffer ub; 23 | size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + len; 24 | 25 | ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); 26 | if (!ub.error) 27 | { 28 | WRITE_DATA_Payload_Data payload; 29 | rv = uxr_init_base_object_request(&session->info, requester_id, &payload.base); 30 | uxr_serialize_WRITE_DATA_Payload_Data(&ub, &payload); 31 | ucdr_serialize_array_uint8_t(&ub, buffer, len); 32 | } 33 | 34 | return rv; 35 | } 36 | 37 | uint16_t uxr_buffer_reply( 38 | uxrSession* session, 39 | uxrStreamId stream_id, 40 | uxrObjectId replier_id, 41 | SampleIdentity* sample_id, 42 | uint8_t* buffer, 43 | size_t len) 44 | { 45 | uint16_t rv = UXR_INVALID_REQUEST_ID; 46 | ucdrBuffer ub; 47 | size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + SAMPLE_IDENTITY_SIZE + len; 48 | 49 | ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); 50 | if (!ub.error) 51 | { 52 | WRITE_DATA_Payload_Data payload; 53 | rv = uxr_init_base_object_request(&session->info, replier_id, &payload.base); 54 | uxr_serialize_WRITE_DATA_Payload_Data(&ub, &payload); 55 | uxr_serialize_SampleIdentity(&ub, sample_id); 56 | ucdr_serialize_array_uint8_t(&ub, buffer, len); 57 | } 58 | 59 | return rv; 60 | } 61 | 62 | bool uxr_prepare_output_stream(uxrSession* session, uxrStreamId stream_id, uxrObjectId datawriter_id, 63 | ucdrBuffer* ub, uint32_t topic_size) 64 | { 65 | size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + topic_size; 66 | ub->error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); 67 | if(!ub->error) 68 | { 69 | WRITE_DATA_Payload_Data payload; 70 | uxr_init_base_object_request(&session->info, datawriter_id, &payload.base); 71 | (void) uxr_serialize_WRITE_DATA_Payload_Data(ub, &payload); 72 | 73 | OnFullBuffer on_full_buffer = ub->on_full_buffer; 74 | void* args = ub->args; 75 | ucdr_init_buffer(ub, ub->iterator, (size_t)(ub->final - ub->iterator)); 76 | ucdr_set_on_full_buffer_callback(ub, on_full_buffer, args); 77 | } 78 | 79 | return !ub->error; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/udp/udp_transport.c: -------------------------------------------------------------------------------- 1 | #include "udp_transport_internal.h" 2 | 3 | /******************************************************************************* 4 | * Static members. 5 | *******************************************************************************/ 6 | static uint8_t error_code; 7 | 8 | /******************************************************************************* 9 | * Private function declarations. 10 | *******************************************************************************/ 11 | static bool send_udp_msg(void* instance, const uint8_t* buf, size_t len); 12 | static bool recv_udp_msg(void* instance, uint8_t** buf, size_t* len, int timeout); 13 | static uint8_t get_udp_error(void); 14 | 15 | /******************************************************************************* 16 | * Private function definitions. 17 | *******************************************************************************/ 18 | static bool send_udp_msg(void* instance, const uint8_t* buf, size_t len) 19 | { 20 | bool rv = false; 21 | uxrUDPTransport* transport = (uxrUDPTransport*)instance; 22 | 23 | uint8_t errcode; 24 | size_t bytes_sent = uxr_write_udp_data_platform(transport->platform, buf, len, &errcode); 25 | if (0 < bytes_sent) 26 | { 27 | rv = (bytes_sent == len); 28 | } 29 | else 30 | { 31 | error_code = errcode; 32 | } 33 | return rv; 34 | } 35 | 36 | static bool recv_udp_msg(void* instance, uint8_t** buf, size_t* len, int timeout) 37 | { 38 | bool rv = false; 39 | uxrUDPTransport* transport = (uxrUDPTransport*)instance; 40 | 41 | uint8_t errcode; 42 | size_t bytes_received = uxr_read_udp_data_platform(transport->platform, 43 | transport->buffer, 44 | sizeof(transport->buffer), 45 | timeout, 46 | &errcode); 47 | if (0 < bytes_received) 48 | { 49 | *buf = transport->buffer; 50 | *len = bytes_received; 51 | rv = true; 52 | } 53 | else 54 | { 55 | error_code = errcode; 56 | } 57 | return rv; 58 | } 59 | 60 | static uint8_t get_udp_error(void) 61 | { 62 | return error_code; 63 | } 64 | 65 | /******************************************************************************* 66 | * Public function definitions. 67 | *******************************************************************************/ 68 | bool uxr_init_udp_transport( 69 | uxrUDPTransport* transport, 70 | struct uxrUDPPlatform* platform, 71 | uxrIpProtocol ip_protocol, 72 | const char* ip, 73 | const char* port) 74 | { 75 | bool rv = false; 76 | 77 | if (uxr_init_udp_platform(platform, ip_protocol, ip, port)) 78 | { 79 | /* Setup platform. */ 80 | transport->platform = platform; 81 | 82 | /* Setup interface. */ 83 | transport->comm.instance = (void*)transport; 84 | transport->comm.send_msg = send_udp_msg; 85 | transport->comm.recv_msg = recv_udp_msg; 86 | transport->comm.comm_error = get_udp_error; 87 | transport->comm.mtu = UXR_CONFIG_UDP_TRANSPORT_MTU; 88 | rv = true; 89 | } 90 | return rv; 91 | } 92 | 93 | bool uxr_close_udp_transport(uxrUDPTransport* transport) 94 | { 95 | return uxr_close_udp_platform(transport->platform); 96 | } 97 | -------------------------------------------------------------------------------- /src/ucdr/cmake/SuperBuild.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | include(ExternalProject) 16 | 17 | unset(_deps) 18 | 19 | enable_language(C) 20 | enable_language(CXX) 21 | 22 | if(UCDR_BUILD_TESTS) 23 | unset(googletest_DIR CACHE) 24 | enable_language(CXX) 25 | find_package(GTest QUIET) 26 | find_package(GMock QUIET) 27 | if(NOT GTest_FOUND OR NOT GMock_FOUND) 28 | unset(GTEST_ROOT CACHE) 29 | unset(GMOCK_ROOT CACHE) 30 | ExternalProject_Add(googletest 31 | GIT_REPOSITORY 32 | https://github.com/google/googletest.git 33 | GIT_TAG 34 | 2fe3bd994b3189899d93f1d5a881e725e046fdc2 35 | PREFIX 36 | ${PROJECT_BINARY_DIR}/googletest 37 | INSTALL_DIR 38 | ${PROJECT_BINARY_DIR}/temp_install/googletest 39 | CMAKE_ARGS 40 | -DCMAKE_INSTALL_PREFIX:PATH= 41 | $<$:-Dgtest_force_shared_crt:BOOL=ON> 42 | BUILD_COMMAND 43 | COMMAND ${CMAKE_COMMAND} --build --config Release --target install 44 | COMMAND ${CMAKE_COMMAND} --build --config Debug --target install 45 | INSTALL_COMMAND 46 | "" 47 | ) 48 | set(GTEST_ROOT ${PROJECT_BINARY_DIR}/temp_install/googletest CACHE PATH "" FORCE) 49 | set(GMOCK_ROOT ${PROJECT_BINARY_DIR}/temp_install/googletest CACHE PATH "" FORCE) 50 | list(APPEND _deps googletest) 51 | endif() 52 | 53 | unset(fastcdr_DIR CACHE) 54 | enable_language(CXX) 55 | unset(FASTCDR_ROOT CACHE) 56 | ExternalProject_Add(fastcdr 57 | GIT_REPOSITORY 58 | https://github.com/eProsima/Fast-CDR 59 | GIT_TAG 60 | v1.0.13 61 | PREFIX 62 | ${PROJECT_BINARY_DIR}/fastcdr 63 | INSTALL_DIR 64 | ${PROJECT_BINARY_DIR}/temp_install/fastcdr 65 | CMAKE_ARGS 66 | -DCMAKE_INSTALL_PREFIX:PATH= 67 | -DCMAKE_BUILD_TYPE=${DCMAKE_BUILD_TYPE} 68 | BUILD_COMMAND 69 | COMMAND ${CMAKE_COMMAND} --build --config Release --target install 70 | COMMAND ${CMAKE_COMMAND} --build --config Debug --target install 71 | INSTALL_COMMAND 72 | "" 73 | ) 74 | set(FASTCDR_ROOT ${PROJECT_BINARY_DIR}/temp_install/fastcdr CACHE PATH "" FORCE) 75 | set(FASTCDR_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/temp_install/fastcdr/include CACHE PATH "" FORCE) 76 | 77 | list(APPEND _deps fastcdr) 78 | endif() 79 | 80 | # Client project. 81 | ExternalProject_Add(ucdr 82 | SOURCE_DIR 83 | ${PROJECT_SOURCE_DIR} 84 | BINARY_DIR 85 | ${CMAKE_CURRENT_BINARY_DIR} 86 | CMAKE_CACHE_ARGS 87 | -DUCDR_SUPERBUILD:BOOL=OFF 88 | INSTALL_COMMAND 89 | "" 90 | DEPENDS 91 | ${_deps} 92 | ) 93 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/udp/udp_transport_external.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "udp_transport_internal.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | bool uxr_init_udp_platform( 15 | uxrUDPPlatform* platform, 16 | uxrIpProtocol ip_protocol, 17 | const char* ip, 18 | const char* port) 19 | { 20 | bool rv = false; 21 | struct hostent *host = RT_NULL; 22 | struct sockaddr_in server_addr; 23 | 24 | if (ip_protocol != UXR_IPv4) { 25 | printf("Unsupported ip protocol\n"); 26 | goto __exit; 27 | } 28 | 29 | host = (struct hostent *)gethostbyname(ip); 30 | if (host == RT_NULL) 31 | { 32 | printf("Get host by name failed!"); 33 | goto __exit; 34 | } 35 | 36 | if((platform->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { 37 | printf("Create socket error\n"); 38 | goto __exit; 39 | } 40 | 41 | server_addr.sin_family = AF_INET; 42 | server_addr.sin_port = htons(atoi(port)); 43 | server_addr.sin_addr = *((struct in_addr *)host->h_addr); 44 | rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); 45 | 46 | if (connect(platform->sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) 47 | { 48 | printf("Connect fail!\n"); 49 | if (platform->sock >= 0) 50 | { 51 | closesocket(platform->sock); 52 | platform->sock = -1; 53 | } 54 | goto __exit; 55 | } 56 | 57 | rv = true; 58 | __exit: 59 | return rv; 60 | } 61 | 62 | bool uxr_close_udp_platform( 63 | uxrUDPPlatform* platform) 64 | { 65 | if (platform->sock >= 0) 66 | { 67 | closesocket(platform->sock); 68 | platform->sock = -1; 69 | } 70 | return true; 71 | } 72 | 73 | size_t uxr_write_udp_data_platform( 74 | uxrUDPPlatform* platform, 75 | const uint8_t* buf, 76 | size_t len, 77 | uint8_t* errcode) 78 | { 79 | size_t rv = 0; 80 | ssize_t bytes_sent = send(platform->sock, (void*)buf, len, 0); 81 | if (-1 != bytes_sent) 82 | { 83 | rv = (size_t)bytes_sent; 84 | *errcode = 0; 85 | } 86 | else 87 | { 88 | *errcode = 1; 89 | } 90 | return rv; 91 | } 92 | 93 | size_t uxr_read_udp_data_platform( 94 | uxrUDPPlatform* platform, 95 | uint8_t* buf, 96 | size_t len, 97 | int timeout, 98 | uint8_t* errcode) 99 | { 100 | size_t rv = 0; 101 | fd_set readset; 102 | struct timeval timeout_val; 103 | timeout_val.tv_sec = timeout/1000; 104 | timeout_val.tv_usec = (timeout % 1000) * 1000; 105 | 106 | FD_ZERO(&readset); 107 | FD_SET(platform->sock, &readset); 108 | 109 | int poll_rv = select(platform->sock + 1, &readset, RT_NULL, RT_NULL, &timeout_val); 110 | 111 | if (0 < poll_rv) 112 | { 113 | ssize_t bytes_received = recv(platform->sock, (void*)buf, len, 0); 114 | if (-1 != bytes_received) 115 | { 116 | rv = (size_t)bytes_received; 117 | *errcode = 0; 118 | } 119 | else 120 | { 121 | *errcode = 1; 122 | } 123 | } 124 | else 125 | { 126 | *errcode = (0 == poll_rv) ? 0 : 1; 127 | } 128 | 129 | return rv; 130 | } -------------------------------------------------------------------------------- /src/ucdr/ci/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) 16 | 17 | project(microcdr_ci LANGUAGES C CXX) 18 | 19 | include(ExternalProject) 20 | include(CheckCXXCompilerFlag) 21 | include(CheckCCompilerFlag) 22 | 23 | set(_c_flags "-fwrapv -fprofile-arcs -ftest-coverage") 24 | set(_cxx_flags "-fwrapv -fprofile-arcs -ftest-coverage") 25 | set(_exe_linker_flags "-fprofile-arcs -ftest-coverage") 26 | set(_shared_linker_flags "-fprofile-arcs -ftest-coverage") 27 | 28 | check_cxx_compiler_flag("-fprofile-abs-path" _have_cxx_fprofile_abs_path) 29 | if(_have_cxx_fprofile_abs_path) 30 | set(_cxx_flags "${_cxx_flags} -fprofile-abs-path") 31 | endif() 32 | check_c_compiler_flag("-fprofile-abs-path" _have_c_fprofile_abs_path) 33 | if(_have_c_fprofile_abs_path) 34 | set(_c_flags "${_c_flags} -fprofile-abs-path") 35 | endif() 36 | 37 | ExternalProject_Add(microcdr_isolated 38 | SOURCE_DIR 39 | ${CMAKE_CURRENT_SOURCE_DIR}/../../ 40 | BINARY_DIR 41 | ${PROJECT_BINARY_DIR}/microcdr-build 42 | INSTALL_DIR 43 | ${PROJECT_BINARY_DIR}/temp_install/isolated 44 | TEST_AFTER_INSTALL 45 | TRUE 46 | TEST_COMMAND 47 | COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Test 48 | COMMAND ${CMAKE_CTEST_COMMAND} -VV -T MemCheck -E "test-case*" 49 | COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Coverage -E "test-case*" 50 | CMAKE_CACHE_ARGS 51 | -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} 52 | -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} 53 | -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} 54 | -DCMAKE_C_FLAGS:STRING=${_c_flags} 55 | -DCMAKE_CXX_FLAGS:STRING=${_cxx_flags} 56 | -DCMAKE_EXE_LINKER_FLAGS:STRING=${_exe_linker_flags} 57 | -DCMAKE_SHARED_LINKER_FLAGS:STRING=${_shared_linker_flags} 58 | -DCMAKE_INSTALL_PREFIX:PATH= 59 | -DUCDR_BUILD_CI_TESTS:BOOL=ON 60 | -DGTEST_INDIVIDUAL:BOOL=ON 61 | ) 62 | 63 | ExternalProject_Add(microcdr_non_isolated 64 | SOURCE_DIR 65 | ${CMAKE_CURRENT_SOURCE_DIR}/../../ 66 | BINARY_DIR 67 | ${PROJECT_BINARY_DIR}/microcdr-build 68 | INSTALL_DIR 69 | ${PROJECT_BINARY_DIR}/temp_install/non_isolated 70 | TEST_AFTER_INSTALL 71 | TRUE 72 | BUILD_COMMAND 73 | "" 74 | TEST_COMMAND 75 | COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Test -R "test-case*" 76 | CMAKE_CACHE_ARGS 77 | -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} 78 | -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} 79 | -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} 80 | -DCMAKE_C_FLAGS:STRING=${_c_flags} 81 | -DCMAKE_CXX_FLAGS:STRING=${_cxx_flags} 82 | -DCMAKE_EXE_LINKER_FLAGS:STRING=${_exe_linker_flags} 83 | -DCMAKE_SHARED_LINKER_FLAGS:STRING=${_shared_linker_flags} 84 | -DCMAKE_INSTALL_PREFIX:PATH= 85 | -DUCDR_BUILD_CI_TESTS:BOOL=ON 86 | -DUCDR_ISOLATED_INSTALL:BOOL=OFF 87 | -DGTEST_INDIVIDUAL:BOOL=ON 88 | DEPENDS 89 | microcdr_isolated 90 | ) -------------------------------------------------------------------------------- /src/c/profile/discovery/transport/udp_transport_datagram_freertos_plus_tcp.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 eSOL Co.,Ltd. 2 | // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include "udp_transport_datagram_internal.h" 17 | #include "FreeRTOS.h" 18 | #include "FreeRTOS_Sockets.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | bool uxr_init_udp_transport_datagram(uxrUDPTransportDatagram* transport) 25 | { 26 | bool rv = false; 27 | 28 | transport->fd = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP); 29 | 30 | if (FREERTOS_INVALID_SOCKET != transport->fd) 31 | { 32 | transport->poll_fd = FreeRTOS_CreateSocketSet(); 33 | 34 | if (NULL != transport->poll_fd) 35 | { 36 | /* FreeRTOS_FD_SET() is a void function. */ 37 | FreeRTOS_FD_SET(transport->fd, transport->poll_fd, eSELECT_READ); 38 | rv = true; 39 | } 40 | } 41 | 42 | return rv; 43 | } 44 | 45 | bool uxr_close_udp_transport_datagram(uxrUDPTransportDatagram* transport) 46 | { 47 | /* FreeRTOS_closesocket() always returns 0. */ 48 | (void) FreeRTOS_closesocket(transport->fd); 49 | 50 | return true; 51 | } 52 | 53 | bool uxr_udp_send_datagram_to(uxrUDPTransportDatagram* transport, const uint8_t* buf, size_t len, const TransportLocator* locator) 54 | { 55 | bool rv = true; 56 | 57 | struct freertos_sockaddr remote_addr; 58 | memcpy(&remote_addr.sin_addr, &locator->_.medium_locator.address, sizeof(locator->_.medium_locator.address)); 59 | if (0 != remote_addr.sin_addr) 60 | { 61 | remote_addr.sin_family = FREERTOS_AF_INET; 62 | remote_addr.sin_port = FreeRTOS_htons(locator->_.medium_locator.locator_port); 63 | 64 | int32_t bytes_sent = FreeRTOS_sendto(transport->fd, (void*)buf, len, 0, 65 | (struct freertos_sockaddr*)&remote_addr, sizeof(remote_addr)); 66 | 67 | /* FreeRTOS_sendto() returns 0 if an error or timeout occurred. */ 68 | if (0 >= bytes_sent) 69 | { 70 | rv = false; 71 | } 72 | } 73 | 74 | return rv; 75 | } 76 | 77 | bool uxr_udp_recv_datagram(uxrUDPTransportDatagram* transport, uint8_t** buf, size_t* len, int timeout) 78 | { 79 | bool rv = false; 80 | 81 | BaseType_t poll_rv = FreeRTOS_select(transport->poll_fd, pdMS_TO_TICKS(timeout)); 82 | if (0 < poll_rv) 83 | { 84 | int32_t bytes_received = FreeRTOS_recvfrom(transport->fd, (void*)transport->buffer, sizeof(transport->buffer), 0, NULL, NULL); 85 | if (0 < bytes_received) 86 | { 87 | *len = (size_t)bytes_received; 88 | *buf = transport->buffer; 89 | rv = true; 90 | } 91 | } 92 | else if (0 == poll_rv) 93 | { 94 | errno = ETIME; 95 | } 96 | 97 | return rv; 98 | } 99 | 100 | void uxr_bytes_to_ip(const uint8_t* bytes, char* ip) 101 | { 102 | uint32_t addr; 103 | addr = (uint32_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); 104 | FreeRTOS_inet_ntoa(addr, ip); 105 | } 106 | -------------------------------------------------------------------------------- /src/ucdr/test/endianness/BasicEndianness.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "../serialization/BasicSerialization.hpp" 16 | 17 | class BasicEndianness : public BasicSerialization, public ::testing::WithParamInterface 18 | { 19 | public: 20 | 21 | BasicEndianness() 22 | { 23 | endianness = GetParam(); 24 | } 25 | 26 | virtual ~BasicEndianness() 27 | { 28 | } 29 | 30 | protected: 31 | ucdrEndianness endianness; 32 | }; 33 | 34 | TEST_P(BasicEndianness, Int16) 35 | { 36 | int16_t input = 0x0A0B; 37 | int16_t output = 0; 38 | 39 | EXPECT_TRUE(ucdr_serialize_endian_int16_t(&writer, endianness, input)); 40 | EXPECT_TRUE(ucdr_deserialize_endian_int16_t(&reader, endianness, &output)); 41 | 42 | EXPECT_EQ(input, output); 43 | } 44 | 45 | TEST_P(BasicEndianness, Uint16) 46 | { 47 | uint16_t input = 0x0A0B; 48 | uint16_t output = 0; 49 | 50 | EXPECT_TRUE(ucdr_serialize_endian_uint16_t(&writer, endianness, input)); 51 | EXPECT_TRUE(ucdr_deserialize_endian_uint16_t(&reader, endianness, &output)); 52 | 53 | EXPECT_EQ(input, output); 54 | } 55 | 56 | TEST_P(BasicEndianness, Int32) 57 | { 58 | int32_t input = 0x0C0D0E0F; 59 | int32_t output = 0; 60 | 61 | EXPECT_TRUE(ucdr_serialize_endian_int32_t(&writer, endianness, input)); 62 | EXPECT_TRUE(ucdr_deserialize_endian_int32_t(&reader, endianness, &output)); 63 | 64 | EXPECT_EQ(input, output); 65 | } 66 | 67 | TEST_P(BasicEndianness, Uint32) 68 | { 69 | uint32_t input = 0x0C0D0E0F; 70 | uint32_t output = 0; 71 | 72 | EXPECT_TRUE(ucdr_serialize_endian_uint32_t(&writer, endianness, input)); 73 | EXPECT_TRUE(ucdr_deserialize_endian_uint32_t(&reader, endianness, &output)); 74 | 75 | EXPECT_EQ(input, output); 76 | } 77 | 78 | TEST_P(BasicEndianness, Int64) 79 | { 80 | int64_t input = 0x0102030405060708L; 81 | int64_t output = 0; 82 | 83 | EXPECT_TRUE(ucdr_serialize_endian_int64_t(&writer, endianness, input)); 84 | EXPECT_TRUE(ucdr_deserialize_endian_int64_t(&reader, endianness, &output)); 85 | 86 | EXPECT_EQ(input, output); 87 | } 88 | 89 | TEST_P(BasicEndianness, Uint64) 90 | { 91 | uint64_t input = 0x0102030405060708L; 92 | uint64_t output = 0; 93 | 94 | EXPECT_TRUE(ucdr_serialize_endian_uint64_t(&writer, endianness, input)); 95 | EXPECT_TRUE(ucdr_deserialize_endian_uint64_t(&reader, endianness, &output)); 96 | 97 | EXPECT_EQ(input, output); 98 | } 99 | 100 | TEST_P(BasicEndianness, Float) 101 | { 102 | float input = 3.141592653589793238462f; 103 | float output = 0; 104 | 105 | EXPECT_TRUE(ucdr_serialize_endian_float(&writer, endianness, input)); 106 | EXPECT_TRUE(ucdr_deserialize_endian_float(&reader, endianness, &output)); 107 | 108 | EXPECT_EQ(input, output); 109 | } 110 | 111 | TEST_P(BasicEndianness, Double) 112 | { 113 | double input = 3.141592653589793238462; 114 | double output = 0; 115 | 116 | EXPECT_TRUE(ucdr_serialize_endian_double(&writer, endianness, input)); 117 | EXPECT_TRUE(ucdr_deserialize_endian_double(&reader, endianness, &output)); 118 | 119 | EXPECT_EQ(input, output); 120 | } 121 | 122 | INSTANTIATE_TEST_CASE_P(ucdrEndianness, BasicEndianness, ::testing::Values(UCDR_LITTLE_ENDIANNESS, UCDR_BIG_ENDIANNESS)); 123 | -------------------------------------------------------------------------------- /src/c/profile/transport/ip/tcp/tcp_transport_external.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tcp_transport_internal.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef UCLIENT_PLATFORM_LINUX 15 | static void sigpipe_handler(int fd) 16 | { 17 | (void)fd; 18 | } 19 | #endif 20 | 21 | bool uxr_init_tcp_platform( 22 | struct uxrTCPPlatform* platform, 23 | uxrIpProtocol ip_protocol, 24 | const char* ip, 25 | const char* port) 26 | { 27 | bool rv = false; 28 | struct hostent *host = RT_NULL; 29 | struct sockaddr_in server_addr; 30 | 31 | if (ip_protocol != UXR_IPv4) { 32 | printf("Unsupported ip protocol\n"); 33 | goto __exit; 34 | } 35 | 36 | host = (struct hostent *)gethostbyname(ip); 37 | if (host == RT_NULL) 38 | { 39 | printf("Get host by name failed!"); 40 | goto __exit; 41 | } 42 | 43 | if((platform->sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 44 | printf("Create socket error\n"); 45 | goto __exit; 46 | } 47 | 48 | server_addr.sin_family = AF_INET; 49 | server_addr.sin_port = htons(atoi(port)); 50 | server_addr.sin_addr = *((struct in_addr *)host->h_addr); 51 | rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero)); 52 | 53 | if (connect(platform->sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) 54 | { 55 | printf("Connect fail!\n"); 56 | if (platform->sock >= 0) 57 | { 58 | closesocket(platform->sock); 59 | platform->sock = -1; 60 | } 61 | goto __exit; 62 | } 63 | 64 | rv = true; 65 | __exit: 66 | return rv; 67 | } 68 | 69 | bool uxr_close_tcp_platform( 70 | struct uxrTCPPlatform* platform) 71 | { 72 | if (platform->sock >= 0) 73 | { 74 | closesocket(platform->sock); 75 | platform->sock = -1; 76 | } 77 | return true; 78 | } 79 | 80 | size_t uxr_write_tcp_data_platform( 81 | struct uxrTCPPlatform* platform, 82 | const uint8_t* buf, 83 | size_t len, 84 | uint8_t* errcode) 85 | { 86 | size_t rv = 0; 87 | ssize_t bytes_sent = send(platform->sock, (void*)buf, len, 0); 88 | if (-1 != bytes_sent) 89 | { 90 | rv = (size_t)bytes_sent; 91 | *errcode = 0; 92 | } 93 | else 94 | { 95 | *errcode = 1; 96 | } 97 | return rv; 98 | } 99 | 100 | size_t uxr_read_tcp_data_platform( 101 | struct uxrTCPPlatform* platform, 102 | uint8_t* buf, 103 | size_t len, 104 | int timeout, 105 | uint8_t* errcode) 106 | { 107 | size_t rv = 0; 108 | fd_set readset; 109 | struct timeval timeout_val; 110 | timeout_val.tv_sec = timeout/1000; 111 | timeout_val.tv_usec = (timeout % 1000) * 1000; 112 | 113 | FD_ZERO(&readset); 114 | FD_SET(platform->sock, &readset); 115 | 116 | int poll_rv = select(platform->sock + 1, &readset, RT_NULL, RT_NULL, &timeout_val); 117 | 118 | if (0 < poll_rv) 119 | { 120 | ssize_t bytes_received = recv(platform->sock, (void*)buf, len, 0); 121 | if (-1 != bytes_received) 122 | { 123 | rv = (size_t)bytes_received; 124 | *errcode = 0; 125 | } 126 | else 127 | { 128 | *errcode = 1; 129 | } 130 | } 131 | else 132 | { 133 | *errcode = (0 == poll_rv) ? 0 : 1; 134 | } 135 | 136 | return rv; 137 | } 138 | 139 | void uxr_disconnect_tcp_platform( 140 | struct uxrTCPPlatform* platform) 141 | { 142 | if (platform->sock >= 0) 143 | { 144 | closesocket(platform->sock); 145 | platform->sock = -1; 146 | } 147 | return; 148 | } 149 | -------------------------------------------------------------------------------- /inc/uxr/client/core/session/stream/stream_id.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef UXR_CLIENT_CORE_SESSION_STREAM_STREAM_ID_H_ 16 | #define UXR_CLIENT_CORE_SESSION_STREAM_STREAM_ID_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | /** 27 | * The enum that identifies the kind of stream. 28 | * According to the XRCE standard, a stream represents an independent flow of messages within a session. 29 | * The XRCE standard defines 3 different kinds of streams: 30 | * * **none** streams do not provide neither non-out-of-order delivery nor guarantee for the delivery. 31 | * * **best-effort** streams provide non-out-of-order delivery but they do not provide guarantee for delivery. 32 | * * **reliable** streams provide both non-out-of-order delivery and guarantee for delivery. 33 | * 34 | * The streams are identified by an octet. Each session is able to handle 35 | * 1 none stream (id 0x00), 36 | * 127 best-effort streams (id 0x01 - 0x7F), 37 | * and 128 reliable streams (id 0x80 - 0xFF), 38 | * for each direction: output (Client to Agent) and input (Agent to Client). 39 | */ 40 | typedef enum uxrStreamType 41 | { 42 | /** Identifies a none stream. */ 43 | UXR_NONE_STREAM, 44 | /** Identifies a best-effort stream. */ 45 | UXR_BEST_EFFORT_STREAM, 46 | /** Identifies a reliable stream. */ 47 | UXR_RELIABLE_STREAM 48 | 49 | } uxrStreamType; 50 | 51 | /** 52 | * The enum that identifies the direction of a stream. 53 | * There are two different directions: output (Client to Agent) and input (Agent to Client). 54 | */ 55 | typedef enum uxrStreamDirection 56 | { 57 | /** Indicates the input direction of the stream. */ 58 | UXR_INPUT_STREAM, 59 | /** Indicates the output direction of the stream. */ 60 | UXR_OUTPUT_STREAM 61 | 62 | } uxrStreamDirection; 63 | 64 | typedef struct uxrStreamId 65 | { 66 | uint8_t raw; 67 | uint8_t index; 68 | uint8_t type; 69 | uint8_t direction; 70 | 71 | } uxrStreamId; 72 | 73 | /** 74 | * @brief Creates a stream identifier. 75 | * This function does not create a new stream, but only creates the identifier to be used in the Client API. 76 | * @param index The identifier of the stream. 77 | * Its value corresponds to the creation order of each kind of stream. 78 | * @param type The uxrStreamType of the stream. 79 | * @param direction The uxrStreamDirection of the stream. 80 | * @return A identifier of a stream. 81 | */ 82 | UXRDLLAPI uxrStreamId uxr_stream_id( 83 | uint8_t index, 84 | uxrStreamType type, 85 | uxrStreamDirection direction); 86 | 87 | /** 88 | * @brief Creates a stream identifier. 89 | * This function does not create a new stream, but only creates the identifier to be used in the Client API. 90 | * @param stream_id_raw The identifier of the stream. 91 | * 0 corresponds to the UXR_NONE_STREAM; 92 | * from 1 to 127 correspond to a UXR_BEST_EFFORT_STREAM; 93 | * from 128 to 255 correspond to a UXR_RELIABLE_STREAM; 94 | * @param direction The uxrStreamDirection of the stream. 95 | * @return A identifier of a stream. 96 | */ 97 | UXRDLLAPI uxrStreamId uxr_stream_id_from_raw( 98 | uint8_t stream_id_raw, 99 | uxrStreamDirection direction); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif // UXR_CLIENT_CORE_SESSION_STREAM_STREAM_ID_H 106 | --------------------------------------------------------------------------------