diff --git a/examples/zenoh-pico/CMakeLists.txt b/examples/zenoh-pico/CMakeLists.txt new file mode 100644 index 0000000..f400859 --- /dev/null +++ b/examples/zenoh-pico/CMakeLists.txt @@ -0,0 +1,66 @@ +cmake_minimum_required(VERSION 3.8) +project(zenoh_pico_example) + +set(CMAKE_BUILD_TYPE DEBUG) + +include(FetchContent) +FetchContent_declare( + c_backend + GIT_REPOSITORY "https://github.com/eclipse-zenoh/zenoh-pico.git" + GIT_TAG main) +set(BUILD_SHARED_LIBS OFF) +FetchContent_MakeAvailable(c_backend) + +include(FetchContent) +FetchContent_declare( + cyclonedds + GIT_REPOSITORY "https://github.com/eclipse-cyclonedds/cyclonedds.git" + GIT_TAG origin/master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/cyclonedds" + SOURCE_SUBDIR src/core/cdr +) +set(BUILD_SHARED_LIBS OFF) +set(CMAKE_BUILD_TYPE DEBUG) + +FetchContent_MakeAvailable(cyclonedds) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/idlc) + +add_executable(add_two_ints_client + add_two_ints_client.c + idlc/example_interfaces/srv/AddTwoInts.c +) +target_link_libraries(add_two_ints_client + zenohpico + cdr +) + +add_executable(listener + listener.c + idlc/rcl_interfaces/msg/Log.c + idlc/builtin_interfaces/msg/Time.c +) + +target_link_libraries(listener + zenohpico + cdr +) + +add_executable(talker + talker.c + idlc/rcl_interfaces/msg/Log.c + idlc/builtin_interfaces/msg/Time.c +) + +target_link_libraries(talker + zenohpico + cdr +) + +install(TARGETS add_two_ints_client listener talker + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + + diff --git a/examples/zenoh-pico/README.md b/examples/zenoh-pico/README.md new file mode 100644 index 0000000..d9d79af --- /dev/null +++ b/examples/zenoh-pico/README.md @@ -0,0 +1,106 @@ +# Examples of Zenoh Pico applications communicating with ROS 2 Nodes + + +## Messages Publication: [talker.c](talker.c) + +This code mimics the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp). It's compatible with the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp) running those commands: +- Terminal 1 + ``` + source /opt/ros/iron/local_setup.bash + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + ros2 topic echo /rosout + ``` + +- Terminal 2 + ``` + source /opt/ros/iron/local_setup.bash + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + zenho-bridge-ros2dds -l tcp/0.0.0.0:7447 + ``` + +- Terminal 3 + ``` + talker + ``` + | Here we publish to the `rosout` topic because there is a conflict when using `idlc` to compile `std_msgs/msg/String.idl` + + +## Messages Subscription: [listener.c](listener.c) + +This code mimics the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp). It's compatible with the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp) running those commands: + +- Terminal 1 + ``` + source /opt/ros/iron/local_setup.bash + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + ros2 run demo_nodes_cpp talker + ``` + +- Terminal 2 + ``` + source /opt/ros/iron/local_setup.bash + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + zenho-bridge-ros2dds -l tcp/0.0.0.0:7447 + ``` + +- Terminal 3 + ``` + listener + ``` + | Here we subscribe to the `rosout` topic because there is a conflict when using `idlc` to compile `std_msgs/msg/String.idl` + +## Services Client: [add_two_ints_client.c](add_two_ints_client.c) + +This code mimics the ROS 2 [Services "add_two_ints_client" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_client.cpp). It's compatible with the ROS 2 [Services "add_two_ints_server" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_server.cpp) running those commands: + + +- Terminal 1 + + ``` + source /opt/ros/iron/local_setup.bash + export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + ros2 run demo_nodes_cpp add_two_ints_server + ``` + +- Terminal 2 + ``` + source /opt/ros/iron/local_setup.bash + zenho-bridge-ros2dds -l tcp/0.0.0.0:7447 + ``` + +- Terminal 3 + ``` + add_two_ints_client -a 1000 -b 2000 + ``` + + + +## How to use idlc to compile *.idl + +> rmw_cyclonedds_cpp doesn't expect XCDR encoding, but CDR encoding. Thus, we shall use -x final with idlc command. + +> ROS2 env must be set up first. ( ROS Iron recommended ) + +``` +find_package(CycloneDDS REQUIRED) +find_package(rcl_interfaces REQUIRED) +find_package(builtin_interfaces REQUIRED) + +foreach(_idl ${rcl_interfaces_IDL_FILES}) + configure_file(${rcl_interfaces_DIR}/../${_idl} ${IDL_OUT_PATH}/rcl_interfaces/${_idl} COPYONLY) + list(APPEND IDL_FILES "${IDL_OUT_PATH}/rcl_interfaces/${_idl}") +endforeach() + +foreach(_idl ${builtin_interfaces_IDL_FILES}) + configure_file(${builtin_interfaces_DIR}/../${_idl} ${IDL_OUT_PATH}/builtin_interfaces/${_idl} COPYONLY) + list(APPEND IDL_FILES "${IDL_OUT_PATH}/builtin_interfaces/${_idl}") +endforeach() + +foreach(_idl ${IDL_FILES}) + execute_process( + COMMAND mkdir -p ${CMAKE_BINARY_DIR}/src + COMMAND idlc -I ${CMAKE_BINARY_DIR}/idl -o ${CMAKE_BINARY_DIR}/src -b ${CMAKE_BINARY_DIR}/idl -x final ${_idl} + OUTPUT_VARIABLE cmd_output + ) +endforeach() +``` \ No newline at end of file diff --git a/examples/zenoh-pico/add_two_ints_client.c b/examples/zenoh-pico/add_two_ints_client.c new file mode 100644 index 0000000..0045533 --- /dev/null +++ b/examples/zenoh-pico/add_two_ints_client.c @@ -0,0 +1,214 @@ +#include +#include +#include +#include +#include + +#include +#include "example_interfaces/srv/AddTwoInts.h" +// CycloneDDS CDR Deserializer +#include + +// CDR Xtypes header {0x00, 0x01} indicates it's Little Endian (CDR_LE representation) +const uint8_t ros2_header[4] = {0x00, 0x01, 0x00, 0x00}; + +static dds_cdrstream_allocator_t allocator = {.malloc = malloc, .realloc = realloc, .free = free}; + +z_condvar_t cond; +z_mutex_t mutex; + +void reply_dropper(void *ctx) { + (void)(ctx); + printf(">> Received query final notification\n"); + z_condvar_signal(&cond); + z_condvar_free(&cond); +} + +void reply_handler(z_owned_reply_t *reply, void *ctx) { + (void)(ctx); + if (z_reply_is_ok(reply)) { + z_sample_t sample = z_reply_ok(reply); + z_owned_str_t keystr = z_keyexpr_to_string(sample.keyexpr); + + struct dds_cdrstream_desc desc_rd; + dds_cdrstream_desc_init(&desc_rd, &allocator, + example_interfaces_srv_AddTwoInts_Response_desc.m_size, + example_interfaces_srv_AddTwoInts_Response_desc.m_align, + example_interfaces_srv_AddTwoInts_Response_desc.m_flagset, + example_interfaces_srv_AddTwoInts_Response_desc.m_ops, + example_interfaces_srv_AddTwoInts_Response_desc.m_keys, + example_interfaces_srv_AddTwoInts_Response_desc.m_nkeys); + + uint32_t actual_size; + const bool byteswap = (sample.payload.start[1] != DDSRT_LITTLE_ENDIAN); + const bool norm_ok = dds_stream_normalize( + sample.payload.start + 4, + sample.payload.len, + byteswap, + DDSI_RTPS_CDR_ENC_VERSION_2, &desc_rd, false, &actual_size); + + if (!norm_ok) { + printf("dds_stream_normalize failed\n"); + return; + } + + dds_istream_t is; + is.m_buffer = sample.payload.start + 4; + is.m_index = 0; + is.m_size = sample.payload.len; + is.m_xcdr_version = DDSI_RTPS_CDR_ENC_VERSION_2; + + example_interfaces_srv_AddTwoInts_Response *data = calloc(1, desc_rd.size); + dds_stream_read_sample(&is, data, &allocator, &desc_rd); + + printf(">> Received ('%s': %ld)\n", z_str_loan(&keystr), data->sum); + + z_str_drop(z_str_move(&keystr)); + + dds_cdrstream_desc_fini(&desc_rd, &allocator); + } else { + printf(">> Received an error\n"); + } +} + +int main(int argc, char **argv) { + const char *keyexpr = "add_two_ints"; + const char *mode = "client"; + const char *clocator = NULL; + const char *llocator = NULL; + const char *req_a = "1000"; + const char *req_b = "2000"; + + int opt; + while ((opt = getopt(argc, argv, "k:e:m:v:a:b:l:")) != -1) { + switch (opt) { + case 'k': + keyexpr = optarg; + break; + case 'e': + clocator = optarg; + break; + case 'm': + mode = optarg; + break; + case 'l': + llocator = optarg; + break; + case 'a': + req_a = optarg; + break; + case 'b': + req_b = optarg; + break; + case '?': + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else { + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + } + return 1; + default: + return -1; + } + } + + allocator.malloc = malloc; + allocator.free = free; + allocator.realloc = realloc; + + z_mutex_init(&mutex); + z_condvar_init(&cond); + + z_owned_config_t config = z_config_default(); + zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); + } + + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_config_move(&config)); + if (!z_session_check(&s)) { + printf("Unable to open session!\n"); + return -1; + } + + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); + return -1; + } + + z_keyexpr_t ke = z_keyexpr(keyexpr); + if (!z_keyexpr_is_initialized(&ke)) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } + + z_mutex_lock(&mutex); + + // Setup ostream for serializer + dds_ostream_t os; + os.m_buffer = NULL; + os.m_index = 0; + os.m_size = 0; + os.m_xcdr_version = DDSI_RTPS_CDR_ENC_VERSION_2; + + example_interfaces_srv_AddTwoInts_Request req; + req.a = (int64_t)(atoi(req_a)); + req.b = (int64_t)(atoi(req_b)); + + printf("Sending Query '%s'... with a = %ld, b = %ld\n", keyexpr, req.a, req.b); + // Allocate buffer for serialized message + uint8_t *buf = malloc(sizeof(ros2_header)); + + // Add ROS2 header + memcpy(buf, ros2_header, sizeof(ros2_header)); + os.m_buffer = buf; + os.m_index = sizeof(ros2_header); // Offset for CDR Xtypes header + os.m_size = sizeof(ros2_header); + os.m_xcdr_version = DDSI_RTPS_CDR_ENC_VERSION_2; + + struct dds_cdrstream_desc desc_wr; + dds_cdrstream_desc_init(&desc_wr, &allocator, + example_interfaces_srv_AddTwoInts_Request_desc.m_size, + example_interfaces_srv_AddTwoInts_Request_desc.m_align, + example_interfaces_srv_AddTwoInts_Request_desc.m_flagset, + example_interfaces_srv_AddTwoInts_Request_desc.m_ops, + example_interfaces_srv_AddTwoInts_Request_desc.m_keys, + example_interfaces_srv_AddTwoInts_Request_desc.m_nkeys); + + // Do serialization + bool ret = dds_stream_write_sample(&os, &allocator, (void *)&req, &desc_wr); + if (!ret) { + printf("dds_stream_write_sampleLE failed\n"); + exit(-1); + } + + z_get_options_t opts = z_get_options_default(); + opts.value.payload.start = os.m_buffer; + opts.value.payload.len = os.m_index; + opts.value.payload._is_alloc = false; + + z_owned_closure_reply_t callback = z_closure_reply(reply_handler, reply_dropper, NULL); + if (z_get(z_session_loan(&s), ke, "", z_closure_reply_move(&callback), &opts) < 0) { + printf("Unable to send query.\n"); + return -1; + } + + z_condvar_wait(&cond, &mutex); + z_mutex_unlock(&mutex); + + dds_cdrstream_desc_fini(&desc_wr, &allocator); + + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_session_loan(&s)); + zp_stop_lease_task(z_session_loan(&s)); + + z_close(z_session_move(&s)); + + return 0; +} diff --git a/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.c b/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.c new file mode 100644 index 0000000..0850181 --- /dev/null +++ b/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.c @@ -0,0 +1,66 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: builtin_interfaces/msg/Time.c + Source: builtin_interfaces/msg/Time.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#include "Time.h" + +static const uint32_t builtin_interfaces_msg_Time_ops [] = +{ + /* Time */ + DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_SGN, offsetof (builtin_interfaces_msg_Time, sec), + DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (builtin_interfaces_msg_Time, nanosec), + DDS_OP_RTS +}; + +/* Type Information: + [MINIMAL 567c5a93541c3b1086a4ba46f98d] (#deps: 0) + [COMPLETE 8002f4258a57323b30e23d570ec1] (#deps: 0) +*/ +#define TYPE_INFO_CDR_builtin_interfaces_msg_Time (unsigned char []){ \ + 0x60, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf1, 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, 0x3b, 0x10, 0x86, 0xa4, 0xba, \ + 0x46, 0xf9, 0x8d, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, \ + 0x57, 0x0e, 0xc1, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00\ +} +#define TYPE_INFO_CDR_SZ_builtin_interfaces_msg_Time 100u +#define TYPE_MAP_CDR_builtin_interfaces_msg_Time (unsigned char []){ \ + 0x4b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf1, 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, 0x3b, \ + 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d, 0x00, 0x33, 0x00, 0x00, 0x00, 0xf1, 0x51, 0x01, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x74, 0x45, 0x9c, 0xa3, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xe2, 0x04, 0x64, 0xd5, 0x00, \ + 0x82, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, \ + 0x3b, 0x30, 0xe2, 0x3d, 0x57, 0x0e, 0xc1, 0x00, 0x6a, 0x00, 0x00, 0x00, 0xf2, 0x51, 0x01, 0x00, \ + 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x62, 0x75, 0x69, 0x6c, \ + 0x74, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x3a, \ + 0x6d, 0x73, 0x67, 0x3a, 0x3a, 0x54, 0x69, 0x6d, 0x65, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, \ + 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, \ + 0x04, 0x00, 0x00, 0x00, 0x73, 0x65, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6e, 0x6f, \ + 0x73, 0x65, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \ + 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, 0x57, 0x0e, 0xc1, 0xf1, \ + 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, 0x3b, 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d\ +} +#define TYPE_MAP_CDR_SZ_builtin_interfaces_msg_Time 254u +const dds_topic_descriptor_t builtin_interfaces_msg_Time_desc = +{ + .m_size = sizeof (builtin_interfaces_msg_Time), + .m_align = dds_alignof (builtin_interfaces_msg_Time), + .m_flagset = DDS_TOPIC_FIXED_SIZE | DDS_TOPIC_XTYPES_METADATA, + .m_nkeys = 0u, + .m_typename = "builtin_interfaces::msg::Time", + .m_keys = NULL, + .m_nops = 3, + .m_ops = builtin_interfaces_msg_Time_ops, + .m_meta = "", + .type_information = { .data = TYPE_INFO_CDR_builtin_interfaces_msg_Time, .sz = TYPE_INFO_CDR_SZ_builtin_interfaces_msg_Time }, + .type_mapping = { .data = TYPE_MAP_CDR_builtin_interfaces_msg_Time, .sz = TYPE_MAP_CDR_SZ_builtin_interfaces_msg_Time } +}; + diff --git a/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.h b/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.h new file mode 100644 index 0000000..80ee890 --- /dev/null +++ b/examples/zenoh-pico/idlc/builtin_interfaces/msg/Time.h @@ -0,0 +1,36 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: builtin_interfaces/msg/Time.h + Source: builtin_interfaces/msg/Time.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#ifndef DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_BUILTIN_INTERFACES_MSG_TIME_H +#define DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_BUILTIN_INTERFACES_MSG_TIME_H + +#include "dds/ddsc/dds_public_impl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct builtin_interfaces_msg_Time +{ + int32_t sec; + uint32_t nanosec; +} builtin_interfaces_msg_Time; + +extern const dds_topic_descriptor_t builtin_interfaces_msg_Time_desc; + +#define builtin_interfaces_msg_Time__alloc() \ +((builtin_interfaces_msg_Time*) dds_alloc (sizeof (builtin_interfaces_msg_Time))); + +#define builtin_interfaces_msg_Time_free(d,o) \ +dds_sample_free ((d), &builtin_interfaces_msg_Time_desc, (o)) + +#ifdef __cplusplus +} +#endif + +#endif /* DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_BUILTIN_INTERFACES_MSG_TIME_H */ diff --git a/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.c b/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.c new file mode 100644 index 0000000..3732caf --- /dev/null +++ b/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.c @@ -0,0 +1,120 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: example_interfaces/srv/AddTwoInts.c + Source: example_interfaces/srv/AddTwoInts.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#include "AddTwoInts.h" + +static const uint32_t example_interfaces_srv_AddTwoInts_Request_ops [] = +{ + /* AddTwoInts_Request */ + DDS_OP_ADR | DDS_OP_TYPE_8BY | DDS_OP_FLAG_SGN, offsetof (example_interfaces_srv_AddTwoInts_Request, a), + DDS_OP_ADR | DDS_OP_TYPE_8BY | DDS_OP_FLAG_SGN, offsetof (example_interfaces_srv_AddTwoInts_Request, b), + DDS_OP_RTS +}; + +/* Type Information: + [MINIMAL 0d2eecf8a24a1b9b0cdd18d529cd] (#deps: 0) + [COMPLETE 7497b44641821568bcaa98d7bdea] (#deps: 0) +*/ +#define TYPE_INFO_CDR_example_interfaces_srv_AddTwoInts_Request (unsigned char []){ \ + 0x60, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf1, 0x0d, 0x2e, 0xec, 0xf8, 0xa2, 0x4a, 0x1b, 0x9b, 0x0c, 0xdd, 0x18, \ + 0xd5, 0x29, 0xcd, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf2, 0x74, 0x97, 0xb4, 0x46, 0x41, 0x82, 0x15, 0x68, 0xbc, 0xaa, 0x98, \ + 0xd7, 0xbd, 0xea, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00\ +} +#define TYPE_INFO_CDR_SZ_example_interfaces_srv_AddTwoInts_Request 100u +#define TYPE_MAP_CDR_example_interfaces_srv_AddTwoInts_Request (unsigned char []){ \ + 0x4b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf1, 0x0d, 0x2e, 0xec, 0xf8, 0xa2, 0x4a, 0x1b, \ + 0x9b, 0x0c, 0xdd, 0x18, 0xd5, 0x29, 0xcd, 0x00, 0x33, 0x00, 0x00, 0x00, 0xf1, 0x51, 0x01, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x0c, 0xc1, 0x75, 0xb9, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x92, 0xeb, 0x5f, 0xfe, 0x00, \ + 0x84, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0x74, 0x97, 0xb4, 0x46, 0x41, 0x82, 0x15, \ + 0x68, 0xbc, 0xaa, 0x98, 0xd7, 0xbd, 0xea, 0x00, 0x6c, 0x00, 0x00, 0x00, 0xf2, 0x51, 0x01, 0x00, \ + 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x65, 0x78, 0x61, 0x6d, \ + 0x70, 0x6c, 0x65, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x3a, \ + 0x73, 0x72, 0x76, 0x3a, 0x3a, 0x41, 0x64, 0x64, 0x54, 0x77, 0x6f, 0x49, 0x6e, 0x74, 0x73, 0x5f, \ + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x61, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00, \ + 0x02, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \ + 0xf2, 0x74, 0x97, 0xb4, 0x46, 0x41, 0x82, 0x15, 0x68, 0xbc, 0xaa, 0x98, 0xd7, 0xbd, 0xea, 0xf1, \ + 0x0d, 0x2e, 0xec, 0xf8, 0xa2, 0x4a, 0x1b, 0x9b, 0x0c, 0xdd, 0x18, 0xd5, 0x29, 0xcd\ +} +#define TYPE_MAP_CDR_SZ_example_interfaces_srv_AddTwoInts_Request 254u +const dds_topic_descriptor_t example_interfaces_srv_AddTwoInts_Request_desc = +{ + .m_size = sizeof (example_interfaces_srv_AddTwoInts_Request), + .m_align = dds_alignof (example_interfaces_srv_AddTwoInts_Request), + .m_flagset = DDS_TOPIC_FIXED_SIZE | DDS_TOPIC_XTYPES_METADATA, + .m_nkeys = 0u, + .m_typename = "example_interfaces::srv::AddTwoInts_Request", + .m_keys = NULL, + .m_nops = 3, + .m_ops = example_interfaces_srv_AddTwoInts_Request_ops, + .m_meta = "", + .type_information = { .data = TYPE_INFO_CDR_example_interfaces_srv_AddTwoInts_Request, .sz = TYPE_INFO_CDR_SZ_example_interfaces_srv_AddTwoInts_Request }, + .type_mapping = { .data = TYPE_MAP_CDR_example_interfaces_srv_AddTwoInts_Request, .sz = TYPE_MAP_CDR_SZ_example_interfaces_srv_AddTwoInts_Request } +}; + +static const uint32_t example_interfaces_srv_AddTwoInts_Response_ops [] = +{ + /* AddTwoInts_Response */ + DDS_OP_ADR | DDS_OP_TYPE_8BY | DDS_OP_FLAG_SGN, offsetof (example_interfaces_srv_AddTwoInts_Response, sum), + DDS_OP_RTS +}; + +/* Type Information: + [MINIMAL a8819e9a441198929f6a0e0a54da] (#deps: 0) + [COMPLETE a3223aabc9fe3e105e7788bf5cbc] (#deps: 0) +*/ +#define TYPE_INFO_CDR_example_interfaces_srv_AddTwoInts_Response (unsigned char []){ \ + 0x60, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf1, 0xa8, 0x81, 0x9e, 0x9a, 0x44, 0x11, 0x98, 0x92, 0x9f, 0x6a, 0x0e, \ + 0x0a, 0x54, 0xda, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x40, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf2, 0xa3, 0x22, 0x3a, 0xab, 0xc9, 0xfe, 0x3e, 0x10, 0x5e, 0x77, 0x88, \ + 0xbf, 0x5c, 0xbc, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00\ +} +#define TYPE_INFO_CDR_SZ_example_interfaces_srv_AddTwoInts_Response 100u +#define TYPE_MAP_CDR_example_interfaces_srv_AddTwoInts_Response (unsigned char []){ \ + 0x3b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf1, 0xa8, 0x81, 0x9e, 0x9a, 0x44, 0x11, 0x98, \ + 0x92, 0x9f, 0x6a, 0x0e, 0x0a, 0x54, 0xda, 0x00, 0x23, 0x00, 0x00, 0x00, 0xf1, 0x51, 0x01, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x1d, 0x62, 0x3b, 0x89, 0x00, \ + 0x76, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0xa3, 0x22, 0x3a, 0xab, 0xc9, 0xfe, 0x3e, \ + 0x10, 0x5e, 0x77, 0x88, 0xbf, 0x5c, 0xbc, 0x00, 0x5e, 0x00, 0x00, 0x00, 0xf2, 0x51, 0x01, 0x00, \ + 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x65, 0x78, 0x61, 0x6d, \ + 0x70, 0x6c, 0x65, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x3a, \ + 0x73, 0x72, 0x76, 0x3a, 0x3a, 0x41, 0x64, 0x64, 0x54, 0x77, 0x6f, 0x49, 0x6e, 0x74, 0x73, 0x5f, \ + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00, \ + 0x04, 0x00, 0x00, 0x00, 0x73, 0x75, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0xf2, 0xa3, 0x22, 0x3a, 0xab, 0xc9, 0xfe, 0x3e, 0x10, 0x5e, 0x77, 0x88, \ + 0xbf, 0x5c, 0xbc, 0xf1, 0xa8, 0x81, 0x9e, 0x9a, 0x44, 0x11, 0x98, 0x92, 0x9f, 0x6a, 0x0e, 0x0a, \ + 0x54, 0xda\ +} +#define TYPE_MAP_CDR_SZ_example_interfaces_srv_AddTwoInts_Response 226u +const dds_topic_descriptor_t example_interfaces_srv_AddTwoInts_Response_desc = +{ + .m_size = sizeof (example_interfaces_srv_AddTwoInts_Response), + .m_align = dds_alignof (example_interfaces_srv_AddTwoInts_Response), + .m_flagset = DDS_TOPIC_FIXED_SIZE | DDS_TOPIC_XTYPES_METADATA, + .m_nkeys = 0u, + .m_typename = "example_interfaces::srv::AddTwoInts_Response", + .m_keys = NULL, + .m_nops = 2, + .m_ops = example_interfaces_srv_AddTwoInts_Response_ops, + .m_meta = "", + .type_information = { .data = TYPE_INFO_CDR_example_interfaces_srv_AddTwoInts_Response, .sz = TYPE_INFO_CDR_SZ_example_interfaces_srv_AddTwoInts_Response }, + .type_mapping = { .data = TYPE_MAP_CDR_example_interfaces_srv_AddTwoInts_Response, .sz = TYPE_MAP_CDR_SZ_example_interfaces_srv_AddTwoInts_Response } +}; + diff --git a/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.h b/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.h new file mode 100644 index 0000000..bd96fc7 --- /dev/null +++ b/examples/zenoh-pico/idlc/example_interfaces/srv/AddTwoInts.h @@ -0,0 +1,49 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: example_interfaces/srv/AddTwoInts.h + Source: example_interfaces/srv/AddTwoInts.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#ifndef DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_EXAMPLE_INTERFACES_SRV_ADDTWOINTS_H +#define DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_EXAMPLE_INTERFACES_SRV_ADDTWOINTS_H + +#include "dds/ddsc/dds_public_impl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct example_interfaces_srv_AddTwoInts_Request +{ + int64_t a; + int64_t b; +} example_interfaces_srv_AddTwoInts_Request; + +extern const dds_topic_descriptor_t example_interfaces_srv_AddTwoInts_Request_desc; + +#define example_interfaces_srv_AddTwoInts_Request__alloc() \ +((example_interfaces_srv_AddTwoInts_Request*) dds_alloc (sizeof (example_interfaces_srv_AddTwoInts_Request))); + +#define example_interfaces_srv_AddTwoInts_Request_free(d,o) \ +dds_sample_free ((d), &example_interfaces_srv_AddTwoInts_Request_desc, (o)) + +typedef struct example_interfaces_srv_AddTwoInts_Response +{ + int64_t sum; +} example_interfaces_srv_AddTwoInts_Response; + +extern const dds_topic_descriptor_t example_interfaces_srv_AddTwoInts_Response_desc; + +#define example_interfaces_srv_AddTwoInts_Response__alloc() \ +((example_interfaces_srv_AddTwoInts_Response*) dds_alloc (sizeof (example_interfaces_srv_AddTwoInts_Response))); + +#define example_interfaces_srv_AddTwoInts_Response_free(d,o) \ +dds_sample_free ((d), &example_interfaces_srv_AddTwoInts_Response_desc, (o)) + +#ifdef __cplusplus +} +#endif + +#endif /* DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_EXAMPLE_INTERFACES_SRV_ADDTWOINTS_H */ diff --git a/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.c b/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.c new file mode 100644 index 0000000..0cf1432 --- /dev/null +++ b/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.c @@ -0,0 +1,110 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: rcl_interfaces/msg/Log.c + Source: rcl_interfaces/msg/Log.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#include "Log.h" + +static const uint32_t rcl_interfaces_msg_Log_ops [] = +{ + /* Log */ + DDS_OP_ADR | DDS_OP_TYPE_EXT, offsetof (rcl_interfaces_msg_Log, stamp), (3u << 16u) + 16u /* Time */, + DDS_OP_ADR | DDS_OP_TYPE_1BY, offsetof (rcl_interfaces_msg_Log, level), + DDS_OP_ADR | DDS_OP_TYPE_STR, offsetof (rcl_interfaces_msg_Log, name), + DDS_OP_ADR | DDS_OP_TYPE_STR, offsetof (rcl_interfaces_msg_Log, msg), + DDS_OP_ADR | DDS_OP_TYPE_STR, offsetof (rcl_interfaces_msg_Log, file), + DDS_OP_ADR | DDS_OP_TYPE_STR, offsetof (rcl_interfaces_msg_Log, function), + DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (rcl_interfaces_msg_Log, line), + DDS_OP_RTS, + + /* Time */ + DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_SGN, offsetof (builtin_interfaces_msg_Time, sec), + DDS_OP_ADR | DDS_OP_TYPE_4BY, offsetof (builtin_interfaces_msg_Time, nanosec), + DDS_OP_RTS +}; + +/* Type Information: + [MINIMAL ea847fff605e3b008ad26813b68e] (#deps: 1) + - [MINIMAL 567c5a93541c3b1086a4ba46f98d] + [COMPLETE 8fb4a1390ccbf04409935bca9fac] (#deps: 1) + - [COMPLETE 8002f4258a57323b30e23d570ec1] +*/ +#define TYPE_INFO_CDR_rcl_interfaces_msg_Log (unsigned char []){ \ + 0x90, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0xf1, 0xea, 0x84, 0x7f, 0xff, 0x60, 0x5e, 0x3b, 0x00, 0x8a, 0xd2, 0x68, \ + 0x13, 0xb6, 0x8e, 0x00, 0x97, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xf1, 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, 0x3b, \ + 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d, 0x00, 0x37, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x40, \ + 0x40, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xf2, 0x8f, 0xb4, 0xa1, \ + 0x39, 0x0c, 0xcb, 0xf0, 0x44, 0x09, 0x93, 0x5b, 0xca, 0x9f, 0xac, 0x00, 0xf3, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, \ + 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, 0x57, 0x0e, 0xc1, 0x00, \ + 0x6e, 0x00, 0x00, 0x00\ +} +#define TYPE_INFO_CDR_SZ_rcl_interfaces_msg_Log 148u +#define TYPE_MAP_CDR_rcl_interfaces_msg_Log (unsigned char []){ \ + 0xf3, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xf1, 0xea, 0x84, 0x7f, 0xff, 0x60, 0x5e, 0x3b, \ + 0x00, 0x8a, 0xd2, 0x68, 0x13, 0xb6, 0x8e, 0x00, 0x93, 0x00, 0x00, 0x00, 0xf1, 0x51, 0x01, 0x00, \ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, \ + 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xf1, 0x56, 0x7c, 0x5a, 0x93, 0x54, \ + 0x1c, 0x3b, 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d, 0x96, 0xb8, 0xc7, 0x8d, 0x00, 0x00, 0x00, \ + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xc9, 0xe9, 0xa8, 0x48, 0x00, \ + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0xb0, 0x68, 0x93, 0x1c, \ + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0x6e, 0x2b, 0xaa, 0xf3, \ + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0x8c, 0x7d, 0xd9, 0x22, \ + 0x0c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0xc1, 0xc4, 0x25, 0x26, \ + 0x0b, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x64, 0x38, 0xc6, 0x69, 0xf1, \ + 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, 0x3b, 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d, 0x00, 0x00, \ + 0x33, 0x00, 0x00, 0x00, 0xf1, 0x51, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x04, 0x74, 0x45, 0x9c, 0xa3, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x07, 0xe2, 0x04, 0x64, 0xd5, 0x00, 0x86, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0xf2, 0x8f, 0xb4, 0xa1, 0x39, 0x0c, 0xcb, 0xf0, 0x44, 0x09, 0x93, 0x5b, 0xca, 0x9f, 0xac, 0x00, \ + 0xef, 0x00, 0x00, 0x00, 0xf2, 0x51, 0x01, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x19, 0x00, 0x00, 0x00, 0x72, 0x63, 0x6c, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, \ + 0x65, 0x73, 0x3a, 0x3a, 0x6d, 0x73, 0x67, 0x3a, 0x3a, 0x4c, 0x6f, 0x67, 0x00, 0x00, 0x00, 0x00, \ + 0xbf, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, 0x57, 0x0e, \ + 0xc1, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x00, 0x00, 0x00, \ + 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, \ + 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x70, 0x00, 0x05, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x00, 0x00, \ + 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x6d, 0x73, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x70, 0x00, 0x05, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, \ + 0x17, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x70, 0x00, 0x09, 0x00, 0x00, 0x00, \ + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, \ + 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x05, 0x00, 0x00, 0x00, 0x6c, 0x69, 0x6e, 0x65, \ + 0x00, 0x00, 0x00, 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, 0x57, \ + 0x0e, 0xc1, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0xf2, 0x51, 0x01, 0x00, 0x26, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, 0x6e, 0x5f, \ + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x3a, 0x3a, 0x6d, 0x73, 0x67, 0x3a, \ + 0x3a, 0x54, 0x69, 0x6d, 0x65, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, \ + 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, \ + 0x73, 0x65, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, \ + 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6e, 0x6f, 0x73, 0x65, 0x63, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xf2, 0x8f, 0xb4, 0xa1, \ + 0x39, 0x0c, 0xcb, 0xf0, 0x44, 0x09, 0x93, 0x5b, 0xca, 0x9f, 0xac, 0xf1, 0xea, 0x84, 0x7f, 0xff, \ + 0x60, 0x5e, 0x3b, 0x00, 0x8a, 0xd2, 0x68, 0x13, 0xb6, 0x8e, 0xf2, 0x80, 0x02, 0xf4, 0x25, 0x8a, \ + 0x57, 0x32, 0x3b, 0x30, 0xe2, 0x3d, 0x57, 0x0e, 0xc1, 0xf1, 0x56, 0x7c, 0x5a, 0x93, 0x54, 0x1c, \ + 0x3b, 0x10, 0x86, 0xa4, 0xba, 0x46, 0xf9, 0x8d\ +} +#define TYPE_MAP_CDR_SZ_rcl_interfaces_msg_Log 712u +const dds_topic_descriptor_t rcl_interfaces_msg_Log_desc = +{ + .m_size = sizeof (rcl_interfaces_msg_Log), + .m_align = dds_alignof (rcl_interfaces_msg_Log), + .m_flagset = DDS_TOPIC_XTYPES_METADATA, + .m_nkeys = 0u, + .m_typename = "rcl_interfaces::msg::Log", + .m_keys = NULL, + .m_nops = 11, + .m_ops = rcl_interfaces_msg_Log_ops, + .m_meta = "", + .type_information = { .data = TYPE_INFO_CDR_rcl_interfaces_msg_Log, .sz = TYPE_INFO_CDR_SZ_rcl_interfaces_msg_Log }, + .type_mapping = { .data = TYPE_MAP_CDR_rcl_interfaces_msg_Log, .sz = TYPE_MAP_CDR_SZ_rcl_interfaces_msg_Log } +}; + diff --git a/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.h b/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.h new file mode 100644 index 0000000..a7bdfb5 --- /dev/null +++ b/examples/zenoh-pico/idlc/rcl_interfaces/msg/Log.h @@ -0,0 +1,48 @@ +/**************************************************************** + + Generated by Eclipse Cyclone DDS IDL to C Translator + File name: rcl_interfaces/msg/Log.h + Source: rcl_interfaces/msg/Log.idl + Cyclone DDS: V0.10.4 + +*****************************************************************/ +#ifndef DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_RCL_INTERFACES_MSG_LOG_H +#define DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_RCL_INTERFACES_MSG_LOG_H + +#include "builtin_interfaces/msg/Time.h" + +#include "dds/ddsc/dds_public_impl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define rcl_interfaces_msg_Log_Constants_DEBUG 10 +#define rcl_interfaces_msg_Log_Constants_INFO 20 +#define rcl_interfaces_msg_Log_Constants_WARN 30 +#define rcl_interfaces_msg_Log_Constants_ERROR 40 +#define rcl_interfaces_msg_Log_Constants_FATAL 50 +typedef struct rcl_interfaces_msg_Log +{ + struct builtin_interfaces_msg_Time stamp; + uint8_t level; + char * name; + char * msg; + char * file; + char * function; + uint32_t line; +} rcl_interfaces_msg_Log; + +extern const dds_topic_descriptor_t rcl_interfaces_msg_Log_desc; + +#define rcl_interfaces_msg_Log__alloc() \ +((rcl_interfaces_msg_Log*) dds_alloc (sizeof (rcl_interfaces_msg_Log))); + +#define rcl_interfaces_msg_Log_free(d,o) \ +dds_sample_free ((d), &rcl_interfaces_msg_Log_desc, (o)) + +#ifdef __cplusplus +} +#endif + +#endif /* DDSC__HOME_R22052_WORKSPACE_CSDK_BUILD_AUTEL_MSGS_SRC_RCL_INTERFACES_MSG_LOG_H */ diff --git a/examples/zenoh-pico/listener.c b/examples/zenoh-pico/listener.c new file mode 100644 index 0000000..0b15ae7 --- /dev/null +++ b/examples/zenoh-pico/listener.c @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include + +#include +#include "rcl_interfaces/msg/Log.h" +// CycloneDDS CDR Deserializer +#include + +// CDR Xtypes header {0x00, 0x01} indicates it's Little Endian (CDR_LE representation) +const uint8_t ros2_header[4] = {0x00, 0x01, 0x00, 0x00}; + +static dds_cdrstream_allocator_t allocator = {.malloc = malloc, .realloc = realloc, .free = free}; + +static struct dds_cdrstream_desc desc_rd; + +void data_handler(const z_sample_t *sample, void *arg) { + (void)(arg); + + z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr); + printf(">> [Subscriber] Received ('%s' size '%d')\n", z_loan(keystr), (int)sample->payload.len); + z_drop(z_move(keystr)); + + dds_cdrstream_desc_init(&desc_rd, &allocator, + rcl_interfaces_msg_Log_desc.m_size, + rcl_interfaces_msg_Log_desc.m_align, + rcl_interfaces_msg_Log_desc.m_flagset, + rcl_interfaces_msg_Log_desc.m_ops, + rcl_interfaces_msg_Log_desc.m_keys, + rcl_interfaces_msg_Log_desc.m_nkeys); + + uint32_t actual_size; + const bool byteswap = (sample->payload.start[1] != DDSRT_LITTLE_ENDIAN); + const bool norm_ok = dds_stream_normalize( + sample->payload.start + 4, + sample->payload.len, + byteswap, + DDSI_RTPS_CDR_ENC_VERSION_2, &desc_rd, false, &actual_size); + + if (!norm_ok) { + printf("dds_stream_normalize failed\n"); + return; + } + + // Deserialize Msg + dds_istream_t is; + is.m_buffer = (char *)sample->payload.start + 4; + is.m_index = 0; + is.m_size = sample->payload.len; + is.m_xcdr_version = DDSI_RTPS_CDR_ENC_VERSION_2; + + rcl_interfaces_msg_Log msg; + + dds_stream_read_sample(&is, &msg, &allocator, &desc_rd); + /* print result */ + char buf[5000]; + is.m_index = 0; + dds_stream_print_sample (&is, &desc_rd, buf, 5000); + printf ("read sample: %s\n\n", buf); + + dds_cdrstream_desc_fini(&desc_rd, &allocator); +} + + +int main(int argc, char **argv) { + const char *keyexpr = "rosout"; + const char *mode = "client"; + const char *clocator = NULL; + const char *llocator = NULL; + + int opt; + while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) { + switch (opt) { + case 'k': + keyexpr = optarg; + break; + case 'e': + clocator = optarg; + break; + case 'm': + mode = optarg; + break; + case 'l': + llocator = optarg; + break; + case '?': + if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else { + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + } + return 1; + default: + return -1; + } + } + + z_owned_config_t config = z_config_default(); + zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + if (clocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_config_loan(&config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); + } + + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_config_move(&config)); + if (!z_session_check(&s)) { + printf("Unable to open session!\n"); + return -1; + } + + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); + return -1; + } + + z_keyexpr_t ke = z_keyexpr(keyexpr); + if (!z_keyexpr_is_initialized(&ke)) { + printf("%s is not a valid key expression", keyexpr); + return -1; + } + + z_owned_closure_sample_t callback = z_closure_sample(data_handler, NULL, NULL); + printf("Declaring Subscriber on '%s'...\n", keyexpr); + z_owned_subscriber_t sub = + z_declare_subscriber(z_session_loan(&s), z_keyexpr(keyexpr), z_closure_sample_move(&callback), NULL); + if (!z_subscriber_check(&sub)) { + printf("Unable to declare subscriber.\n"); + return -1; + } + + printf("Enter 'q' to quit...\n"); + char c = '\0'; + while (c != 'q') { + fflush(stdin); + scanf("%c", &c); + } + + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_session_loan(&s)); + zp_stop_lease_task(z_session_loan(&s)); + + z_close(z_session_move(&s)); + + return 0; +} diff --git a/examples/zenoh-pico/talker.c b/examples/zenoh-pico/talker.c new file mode 100644 index 0000000..a60915f --- /dev/null +++ b/examples/zenoh-pico/talker.c @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include + +#include +#include "rcl_interfaces/msg/Log.h" +// CycloneDDS CDR Deserializer +#include + +// CDR Xtypes header {0x00, 0x01} indicates it's Little Endian (CDR_LE representation) +const uint8_t ros2_header[4] = {0x00, 0x01, 0x00, 0x00}; + +static dds_cdrstream_allocator_t allocator = {.malloc = malloc, .realloc = realloc, .free = free}; + +const size_t alloc_size = 4096; // Abitrary size + +int main(int argc, char **argv) { + const char *keyexpr = "rosout"; + char *const default_value = "Pub from Pico!"; + char *value = default_value; + const char *mode = "client"; + char *clocator = NULL; + char *llocator = NULL; + int n = 2147483647; // max int value by default + + int opt; + while ((opt = getopt(argc, argv, "k:v:e:m:l:n:")) != -1) { + switch (opt) { + case 'k': + keyexpr = optarg; + break; + case 'v': + value = optarg; + break; + case 'e': + clocator = optarg; + break; + case 'm': + mode = optarg; + break; + case 'l': + llocator = optarg; + break; + case 'n': + n = atoi(optarg); + break; + case '?': + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l' || + optopt == 'n') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else { + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + } + return 1; + default: + return -1; + } + } + + z_owned_config_t config = z_config_default(); + zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); + if (clocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator)); + } + if (llocator != NULL) { + zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator)); + } + + printf("Opening session...\n"); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open session!\n"); + return -1; + } + + // Start read and lease tasks for zenoh-pico + if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); + return -1; + } + + printf("Declaring publisher for '%s'...\n", keyexpr); + z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL); + if (!z_check(pub)) { + printf("Unable to declare publisher for key expression!\n"); + return -1; + } + + // Set HelloWorld IDL message + rcl_interfaces_msg_Log msg; + msg.stamp.sec = 0; + msg.stamp.nanosec = 0; + msg.level = 20; + msg.name = "zenoh_log_test"; + msg.msg = "Hello from Zenoh to ROS2 encoded with CycloneDDS dds_cdrstream serializer"; + msg.function = "z_publisher_put"; + msg.file = "z_pub_ros2.c"; + msg.line = 140; + + dds_ostream_t os; + // Allocate buffer for ROS2 header + uint8_t *buf = malloc(alloc_size); + memcpy(buf, ros2_header, sizeof(ros2_header)); + + struct dds_cdrstream_desc desc_wr; + dds_cdrstream_desc_init(&desc_wr, &allocator, + rcl_interfaces_msg_Log_desc.m_size, + rcl_interfaces_msg_Log_desc.m_align, + rcl_interfaces_msg_Log_desc.m_flagset, + rcl_interfaces_msg_Log_desc.m_ops, + rcl_interfaces_msg_Log_desc.m_keys, + rcl_interfaces_msg_Log_desc.m_nkeys); + + printf("Press CTRL-C to quit...\n"); + for (int idx = 0; idx < n; ++idx) { + sleep(1); + printf("Putting Data ('%s')...\n", keyexpr); + + os.m_buffer = buf; + os.m_index = sizeof(ros2_header); // Offset for CDR Xtypes header + os.m_size = alloc_size; + os.m_xcdr_version = DDSI_RTPS_CDR_ENC_VERSION_2; + + struct timespec ts; + timespec_get(&ts, TIME_UTC); + msg.stamp.sec = ts.tv_sec; + msg.stamp.nanosec = ts.tv_nsec; + + // Do serialization + bool ret = dds_stream_write_sampleLE((dds_ostreamLE_t *)&os, &allocator, (void *)&msg, &desc_wr); + if (!ret) { + printf("dds_stream_write_sampleLE failed\n"); + continue; + } + + z_publisher_put_options_t options = z_publisher_put_options_default(); + z_publisher_put(z_loan(pub), (const uint8_t *)os.m_buffer, os.m_index, &options); + } + + z_undeclare_publisher(z_move(pub)); + + dds_cdrstream_desc_fini(&desc_wr, &allocator); + + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + + z_close(z_move(s)); + + return 0; +} \ No newline at end of file