From 4b770f45dd3b90753ed7c7b296b734dafb2ffda1 Mon Sep 17 00:00:00 2001 From: lljwork2021 Date: Wed, 9 Sep 2026 18:53:59 +0800 Subject: [PATCH] system/xrcedds: add eProsima Micro XRCE-DDS --- system/xrcedds/.gitignore | 3 + system/xrcedds/CMakeLists.txt | 101 +++++++++ system/xrcedds/HelloWorld.c | 70 +++++++ system/xrcedds/HelloWorld.h | 63 ++++++ system/xrcedds/HelloWorld.idl | 5 + system/xrcedds/Kconfig | 84 ++++++++ system/xrcedds/Make.defs | 35 ++++ system/xrcedds/Makefile | 103 ++++++++++ system/xrcedds/include/ucdr/config.h | 42 ++++ system/xrcedds/include/uxr/client/config.h | 61 ++++++ system/xrcedds/main.c | 228 +++++++++++++++++++++ 11 files changed, 795 insertions(+) create mode 100644 system/xrcedds/.gitignore create mode 100644 system/xrcedds/CMakeLists.txt create mode 100644 system/xrcedds/HelloWorld.c create mode 100644 system/xrcedds/HelloWorld.h create mode 100644 system/xrcedds/HelloWorld.idl create mode 100644 system/xrcedds/Kconfig create mode 100644 system/xrcedds/Make.defs create mode 100644 system/xrcedds/Makefile create mode 100644 system/xrcedds/include/ucdr/config.h create mode 100644 system/xrcedds/include/uxr/client/config.h create mode 100644 system/xrcedds/main.c diff --git a/system/xrcedds/.gitignore b/system/xrcedds/.gitignore new file mode 100644 index 00000000000..69fe2652f11 --- /dev/null +++ b/system/xrcedds/.gitignore @@ -0,0 +1,3 @@ +/xrcedds-client/ +/microcdr/ +/*.tar.gz diff --git a/system/xrcedds/CMakeLists.txt b/system/xrcedds/CMakeLists.txt new file mode 100644 index 00000000000..1e6d074d672 --- /dev/null +++ b/system/xrcedds/CMakeLists.txt @@ -0,0 +1,101 @@ +# ############################################################################## +# apps/system/xrcedds/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +if(CONFIG_SYSTEM_XRCEDDS) + set(XRCEDDS_VERSION 3.0.1) + set(MICROCDR_VERSION 2.0.2) + set(XRCEDDS_DIR ${CMAKE_CURRENT_LIST_DIR}/xrcedds-client) + set(MICROCDR_DIR ${CMAKE_CURRENT_LIST_DIR}/microcdr) + set(XRCEDDS_URL https://github.com/eProsima/Micro-XRCE-DDS-Client/archive) + set(MICROCDR_URL https://github.com/eProsima/Micro-CDR/archive) + + if(NOT EXISTS ${XRCEDDS_DIR}) + FetchContent_Declare( + xrcedds_fetch + URL ${XRCEDDS_URL}/refs/tags/v${XRCEDDS_VERSION}.tar.gz + SOURCE_DIR ${XRCEDDS_DIR} + BINARY_DIR ${NUTTX_APPS_BINDIR}/system/xrcedds/xrcedds-client + DOWNLOAD_NO_PROGRESS true + TIMEOUT 30) + FetchContent_GetProperties(xrcedds_fetch) + if(NOT xrcedds_fetch_POPULATED) + FetchContent_Populate(xrcedds_fetch) + endif() + endif() + + if(NOT EXISTS ${MICROCDR_DIR}) + FetchContent_Declare( + microcdr_fetch + URL ${MICROCDR_URL}/refs/tags/v${MICROCDR_VERSION}.tar.gz + SOURCE_DIR ${MICROCDR_DIR} + BINARY_DIR ${NUTTX_APPS_BINDIR}/system/xrcedds/microcdr + DOWNLOAD_NO_PROGRESS true + TIMEOUT 30) + FetchContent_GetProperties(microcdr_fetch) + if(NOT microcdr_fetch_POPULATED) + FetchContent_Populate(microcdr_fetch) + endif() + endif() + + file(GLOB XRCEDDS_SRCS + ${XRCEDDS_DIR}/src/c/core/serialization/*.c + ${XRCEDDS_DIR}/src/c/core/session/*.c + ${XRCEDDS_DIR}/src/c/core/session/stream/*.c + ${XRCEDDS_DIR}/src/c/util/*.c + ${XRCEDDS_DIR}/src/c/profile/transport/custom/*.c) + + if(CONFIG_SYSTEM_XRCEDDS_STREAM_FRAMING) + file(GLOB XRCEDDS_FRAMING_SRCS + ${XRCEDDS_DIR}/src/c/profile/transport/stream_framing/*.c) + list(APPEND XRCEDDS_SRCS ${XRCEDDS_FRAMING_SRCS}) + endif() + + file(GLOB MICROCDR_SRCS ${MICROCDR_DIR}/src/c/*.c + ${MICROCDR_DIR}/src/c/types/*.c) + + nuttx_add_library(xrcedds STATIC) + target_sources(xrcedds PRIVATE ${XRCEDDS_SRCS} ${MICROCDR_SRCS}) + target_include_directories( + xrcedds PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include ${XRCEDDS_DIR}/include + ${XRCEDDS_DIR}/src/c ${MICROCDR_DIR}/include) + + set_property( + TARGET nuttx + APPEND + PROPERTY NUTTX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include + ${XRCEDDS_DIR}/include ${MICROCDR_DIR}/include) + + if(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO) + nuttx_add_application( + NAME + ${CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_PROGNAME} + SRCS + main.c + HelloWorld.c + STACKSIZE + ${CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_STACKSIZE} + PRIORITY + ${CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_PRIORITY} + DEPENDS + xrcedds) + endif() +endif() diff --git a/system/xrcedds/HelloWorld.c b/system/xrcedds/HelloWorld.c new file mode 100644 index 00000000000..4c77e9aeb3f --- /dev/null +++ b/system/xrcedds/HelloWorld.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * apps/system/xrcedds/HelloWorld.c + * + * This source file contains the definition of the HelloWorld type described + * in the IDL file. It was generated from HelloWorld.idl by the Micro + * XRCE-DDS Gen tool (microxrceddsgen) and is committed to the tree so that + * it does not need to be regenerated at build time. DO NOT EDIT: to change + * the type, edit HelloWorld.idl and regenerate with microxrceddsgen. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "HelloWorld.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +bool HelloWorld_serialize_topic(struct ucdrBuffer *writer, + const HelloWorld *topic) +{ + (void)ucdr_serialize_uint32_t(writer, topic->index); + (void)ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool HelloWorld_deserialize_topic(struct ucdrBuffer *reader, + HelloWorld *topic) +{ + (void)ucdr_deserialize_uint32_t(reader, &topic->index); + (void)ucdr_deserialize_string(reader, topic->message, 255); + + return !reader->error; +} + +uint32_t HelloWorld_size_of_topic(const HelloWorld *topic, uint32_t size) +{ + uint32_t previous_size = size; + + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + + 1); + + return size - previous_size; +} diff --git a/system/xrcedds/HelloWorld.h b/system/xrcedds/HelloWorld.h new file mode 100644 index 00000000000..551c8ad9900 --- /dev/null +++ b/system/xrcedds/HelloWorld.h @@ -0,0 +1,63 @@ +/**************************************************************************** + * apps/system/xrcedds/HelloWorld.h + * + * This header declares the HelloWorld type. It was generated from + * HelloWorld.idl by the Micro XRCE-DDS Gen tool (microxrceddsgen) and is + * committed to the tree so that it does not need to be regenerated at build + * time. DO NOT EDIT: to change the type, edit HelloWorld.idl and regenerate + * with microxrceddsgen. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_XRCEDDS_HELLOWORLD_H +#define __APPS_SYSTEM_XRCEDDS_HELLOWORLD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This struct represents the HelloWorld structure defined in the IDL file. */ + +typedef struct HelloWorld +{ + uint32_t index; + char message[255]; +} HelloWorld; + +struct ucdrBuffer; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +bool HelloWorld_serialize_topic(struct ucdrBuffer *writer, + const HelloWorld *topic); +bool HelloWorld_deserialize_topic(struct ucdrBuffer *reader, + HelloWorld *topic); +uint32_t HelloWorld_size_of_topic(const HelloWorld *topic, uint32_t size); + +#endif /* __APPS_SYSTEM_XRCEDDS_HELLOWORLD_H */ diff --git a/system/xrcedds/HelloWorld.idl b/system/xrcedds/HelloWorld.idl new file mode 100644 index 00000000000..0fd2c355aee --- /dev/null +++ b/system/xrcedds/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/system/xrcedds/Kconfig b/system/xrcedds/Kconfig new file mode 100644 index 00000000000..df749b9221f --- /dev/null +++ b/system/xrcedds/Kconfig @@ -0,0 +1,84 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig SYSTEM_XRCEDDS + bool "eProsima Micro XRCE-DDS" + default n + ---help--- + Enable a lightweight build of Micro XRCE-DDS Client 3.0.1 and + Micro-CDR 2.0.2. Only the core client and the built-in UDP + transport are built; ROS 2, micro-ROS, discovery, and other + transports are not included. + +if SYSTEM_XRCEDDS + +config SYSTEM_XRCEDDS_STREAM_FRAMING + bool "Byte-stream transport framing" + default n + ---help--- + Enable HDLC framing for byte-stream transports such as UART. + The built-in UDP transport preserves packet boundaries, so this + is not needed for the UDP publisher demo. + +config SYSTEM_XRCEDDS_MTU + int "UDP transport MTU" + range 64 65535 + default 512 + +config SYSTEM_XRCEDDS_MAX_OUTPUT_BEST_EFFORT_STREAMS + int "Maximum output best-effort streams" + range 1 127 + default 1 + +config SYSTEM_XRCEDDS_MAX_OUTPUT_RELIABLE_STREAMS + int "Maximum output reliable streams" + range 1 127 + default 1 + +config SYSTEM_XRCEDDS_MAX_INPUT_BEST_EFFORT_STREAMS + int "Maximum input best-effort streams" + range 1 127 + default 1 + +config SYSTEM_XRCEDDS_MAX_INPUT_RELIABLE_STREAMS + int "Maximum input reliable streams" + range 1 127 + default 1 + +config SYSTEM_XRCEDDS_PUBLISH_DEMO + tristate "Micro XRCE-DDS UDP publisher demo" + default n + depends on NET_UDP && NET_IPv4 + ---help--- + Build the PublishHelloWorldClient command. It connects to a + Micro XRCE-DDS Agent through the built-in UDP transport and + publishes HelloWorld samples. + +if SYSTEM_XRCEDDS_PUBLISH_DEMO + +config SYSTEM_XRCEDDS_PUBLISH_DEMO_PROGNAME + string "Publisher command name" + default "PublishHelloWorldClient" + +config SYSTEM_XRCEDDS_PUBLISH_DEMO_PRIORITY + int "Publisher task priority" + default 100 + +config SYSTEM_XRCEDDS_PUBLISH_DEMO_STACKSIZE + int "Publisher task stack size" + default 4096 + +config SYSTEM_XRCEDDS_PUBLISH_DEMO_AGENT_IP + string "Agent IPv4 address" + default "127.0.0.1" + +config SYSTEM_XRCEDDS_PUBLISH_DEMO_AGENT_PORT + int "Agent UDP port" + range 1 65535 + default 8888 + +endif + +endif diff --git a/system/xrcedds/Make.defs b/system/xrcedds/Make.defs new file mode 100644 index 00000000000..dd7c7813a8e --- /dev/null +++ b/system/xrcedds/Make.defs @@ -0,0 +1,35 @@ +############################################################################ +# apps/system/xrcedds/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_SYSTEM_XRCEDDS),) +CONFIGURED_APPS += $(APPDIR)/system/xrcedds + +XRCEDDS_DIR := $(APPDIR)/system/xrcedds + +CFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/include" +CFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/xrcedds-client/include" +CFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/microcdr/include" + +CXXFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/include" +CXXFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/xrcedds-client/include" +CXXFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_DIR)/microcdr/include" +endif diff --git a/system/xrcedds/Makefile b/system/xrcedds/Makefile new file mode 100644 index 00000000000..a0c26c2081d --- /dev/null +++ b/system/xrcedds/Makefile @@ -0,0 +1,103 @@ +############################################################################ +# apps/system/xrcedds/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +XRCEDDS_VERSION := 3.0.1 +MICROCDR_VERSION := 2.0.2 +XRCEDDS_TARBALL := micro-xrce-dds-client-$(XRCEDDS_VERSION).tar.gz +MICROCDR_TARBALL := microcdr-$(MICROCDR_VERSION).tar.gz +XRCEDDS_UNPACK := xrcedds-client +MICROCDR_UNPACK := microcdr +XRCEDDS_CSRC := $(XRCEDDS_UNPACK)$(DELIM)src$(DELIM)c +XRCEDDS_URL := https://github.com/eProsima/Micro-XRCE-DDS-Client/archive +MICROCDR_URL := https://github.com/eProsima/Micro-CDR/archive + +CFLAGS += ${INCDIR_PREFIX}"$(XRCEDDS_CSRC)" + +XRCEDDS_SRC_DIRS := \ + $(XRCEDDS_CSRC)$(DELIM)core$(DELIM)serialization \ + $(XRCEDDS_CSRC)$(DELIM)core$(DELIM)session \ + $(XRCEDDS_CSRC)$(DELIM)core$(DELIM)session$(DELIM)stream \ + $(XRCEDDS_CSRC)$(DELIM)util + +# The UDP transport directory also contains windows/freertos/rtems platform +# implementations, so only the common and POSIX sources are selected below. +XRCEDDS_UDP_DIR := \ + $(XRCEDDS_CSRC)$(DELIM)profile$(DELIM)transport$(DELIM)ip$(DELIM)udp + +ifeq ($(CONFIG_SYSTEM_XRCEDDS_STREAM_FRAMING),y) +XRCEDDS_SRC_DIRS += \ + $(XRCEDDS_CSRC)$(DELIM)profile$(DELIM)transport$(DELIM)stream_framing +endif + +MICROCDR_SRC_DIRS := \ + $(MICROCDR_UNPACK)$(DELIM)src$(DELIM)c \ + $(MICROCDR_UNPACK)$(DELIM)src$(DELIM)c$(DELIM)types + +DEPPATH += $(foreach dir,$(XRCEDDS_SRC_DIRS),--dep-path $(dir)) +DEPPATH += --dep-path $(XRCEDDS_UDP_DIR) +DEPPATH += $(foreach dir,$(MICROCDR_SRC_DIRS),--dep-path $(dir)) +VPATH += $(foreach dir,$(XRCEDDS_SRC_DIRS),:$(dir)) +VPATH += :$(XRCEDDS_UDP_DIR) +VPATH += $(foreach dir,$(MICROCDR_SRC_DIRS),:$(dir)) + +CSRCS += $(foreach dir,$(XRCEDDS_SRC_DIRS),\ + $(notdir $(wildcard $(dir)$(DELIM)*.c))) +CSRCS += udp_transport.c udp_transport_posix.c +CSRCS += $(foreach dir,$(MICROCDR_SRC_DIRS),\ + $(notdir $(wildcard $(dir)$(DELIM)*.c))) + +ifneq ($(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO),) +PROGNAME = $(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_PROGNAME) +PRIORITY = $(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO_STACKSIZE) +MODULE = $(CONFIG_SYSTEM_XRCEDDS_PUBLISH_DEMO) +MAINSRC = main.c +CSRCS += HelloWorld.c +endif + +$(XRCEDDS_TARBALL): + $(Q) echo "Downloading Micro XRCE-DDS Client $(XRCEDDS_VERSION)" + $(Q) curl -L -o $@ $(XRCEDDS_URL)/refs/tags/v$(XRCEDDS_VERSION).tar.gz + +$(MICROCDR_TARBALL): + $(Q) echo "Downloading Micro-CDR $(MICROCDR_VERSION)" + $(Q) curl -L -o $@ $(MICROCDR_URL)/refs/tags/v$(MICROCDR_VERSION).tar.gz + +$(XRCEDDS_UNPACK): $(XRCEDDS_TARBALL) + $(Q) tar zxf $< + $(Q) mv Micro-XRCE-DDS-Client-$(XRCEDDS_VERSION) $@ + +$(MICROCDR_UNPACK): $(MICROCDR_TARBALL) + $(Q) tar zxf $< + $(Q) mv Micro-CDR-$(MICROCDR_VERSION) $@ + +context:: $(XRCEDDS_UNPACK) $(MICROCDR_UNPACK) + +distclean:: + $(call DELFILE,$(XRCEDDS_TARBALL)) + $(call DELFILE,$(MICROCDR_TARBALL)) + $(call DELDIR,$(XRCEDDS_UNPACK)) + $(call DELDIR,$(MICROCDR_UNPACK)) + +include $(APPDIR)/Application.mk diff --git a/system/xrcedds/include/ucdr/config.h b/system/xrcedds/include/ucdr/config.h new file mode 100644 index 00000000000..9e27b0a331d --- /dev/null +++ b/system/xrcedds/include/ucdr/config.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * apps/system/xrcedds/include/ucdr/config.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_XRCEDDS_INCLUDE_UCDR_CONFIG_H +#define __APPS_SYSTEM_XRCEDDS_INCLUDE_UCDR_CONFIG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#define MICROCDR_VERSION_MAJOR 2 +#define MICROCDR_VERSION_MINOR 0 +#define MICROCDR_VERSION_MICRO 2 +#define MICROCDR_VERSION_STR "2.0.2" + +#ifdef CONFIG_ENDIAN_BIG +# define UCDR_MACHINE_ENDIANNESS UCDR_BIG_ENDIANNESS +#else +# define UCDR_MACHINE_ENDIANNESS UCDR_LITTLE_ENDIANNESS +#endif + +#endif /* __APPS_SYSTEM_XRCEDDS_INCLUDE_UCDR_CONFIG_H */ diff --git a/system/xrcedds/include/uxr/client/config.h b/system/xrcedds/include/uxr/client/config.h new file mode 100644 index 00000000000..4bd89f7b951 --- /dev/null +++ b/system/xrcedds/include/uxr/client/config.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/system/xrcedds/include/uxr/client/config.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_XRCEDDS_INCLUDE_UXR_CLIENT_CONFIG_H +#define __APPS_SYSTEM_XRCEDDS_INCLUDE_UXR_CLIENT_CONFIG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#define UXR_CLIENT_VERSION_MAJOR 3 +#define UXR_CLIENT_VERSION_MINOR 0 +#define UXR_CLIENT_VERSION_MICRO 1 +#define UXR_CLIENT_VERSION_STR "3.0.1" + +#define UCLIENT_PROFILE_UDP +#define UCLIENT_PLATFORM_POSIX +#define UCLIENT_TWEAK_XRCE_WRITE_LIMIT + +#ifdef CONFIG_SYSTEM_XRCEDDS_STREAM_FRAMING +# define UCLIENT_PROFILE_STREAM_FRAMING +#endif + +#define UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS \ + CONFIG_SYSTEM_XRCEDDS_MAX_OUTPUT_BEST_EFFORT_STREAMS +#define UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS \ + CONFIG_SYSTEM_XRCEDDS_MAX_OUTPUT_RELIABLE_STREAMS +#define UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS \ + CONFIG_SYSTEM_XRCEDDS_MAX_INPUT_BEST_EFFORT_STREAMS +#define UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS \ + CONFIG_SYSTEM_XRCEDDS_MAX_INPUT_RELIABLE_STREAMS + +#define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS 10 +#define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL 1000 +#define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL 100 + +#ifdef UCLIENT_PROFILE_UDP +# define UXR_CONFIG_UDP_TRANSPORT_MTU CONFIG_SYSTEM_XRCEDDS_MTU +#endif + +#endif /* __APPS_SYSTEM_XRCEDDS_INCLUDE_UXR_CLIENT_CONFIG_H */ diff --git a/system/xrcedds/main.c b/system/xrcedds/main.c new file mode 100644 index 00000000000..a3710effadb --- /dev/null +++ b/system/xrcedds/main.c @@ -0,0 +1,228 @@ +/**************************************************************************** + * apps/system/xrcedds/main.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "HelloWorld.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define STREAM_HISTORY 8 +#define BUFFER_SIZE (UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + uxrUDPTransport transport; + uxrSession session; + uxrStreamId reliable_out; + uint8_t out_stream_buffer[BUFFER_SIZE]; + uint8_t in_stream_buffer[BUFFER_SIZE]; + uxrObjectId participant_id; + uxrObjectId topic_id; + uxrObjectId publisher_id; + uxrObjectId datawriter_id; + const char *participant_xml; + const char *topic_xml; + const char *publisher_xml; + const char *datawriter_xml; + uint16_t participant_req; + uint16_t topic_req; + uint16_t publisher_req; + uint16_t datawriter_req; + uint8_t status[4]; + uint16_t requests[4]; + bool connected; + uint32_t count; + char *ip; + char *port; + uint32_t max_topics; + + /* Parse the command line. */ + + if (argc < 3 || atoi(argv[2]) == 0) + { + printf("usage: program [-h | --help] | ip port []\n"); + return 0; + } + + ip = argv[1]; + port = argv[2]; + max_topics = (argc == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; + + /* Create the UDP transport. */ + + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + /* Create the session. */ + + uxr_init_session(&session, &transport.comm, 0xaaaabbbb); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + /* Create the reliable streams. */ + + reliable_out = uxr_create_output_reliable_stream(&session, + out_stream_buffer, + BUFFER_SIZE, + STREAM_HISTORY); + uxr_create_input_reliable_stream(&session, in_stream_buffer, + BUFFER_SIZE, STREAM_HISTORY); + + /* Create the DDS entities. */ + + participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, + participant_id, 0, + participant_xml, + UXR_REPLACE); + + topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + topic_xml = "" + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, + participant_id, topic_xml, + UXR_REPLACE); + + publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); + publisher_xml = ""; + publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, + publisher_id, + participant_id, + publisher_xml, + UXR_REPLACE); + + datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); + datawriter_xml = "" + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, + datawriter_id, + publisher_id, + datawriter_xml, + UXR_REPLACE); + + /* Send the create entities message and wait for its status. */ + + requests[0] = participant_req; + requests[1] = topic_req; + requests[2] = publisher_req; + requests[3] = datawriter_req; + + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %d topic: %d " + "publisher: %d datawriter: %d\n", + status[0], status[1], status[2], status[3]); + return 1; + } + + /* Give the Agent time to complete DataWriter/DataReader matching before + * sending the first sample. Otherwise the first sample is sent before + * discovery completes and is dropped by the Agent. + */ + + sleep(3); + + /* Publish samples until the requested number is reached or the session + * is disconnected. + */ + + connected = true; + count = 0; + + while (connected && count < max_topics) + { + HelloWorld topic; + ucdrBuffer ub; + uint32_t topic_size; + + topic.index = ++count; + strlcpy(topic.message, "Hello DDS world!", + sizeof(topic.message)); + + topic_size = HelloWorld_size_of_topic(&topic, 0); + + uxr_prepare_output_stream(&session, reliable_out, datawriter_id, &ub, + topic_size); + HelloWorld_serialize_topic(&ub, &topic); + + printf("Send topic: %s, id: %" PRIu32 "\n", topic.message, + topic.index); + connected = uxr_run_session_time(&session, 1000); + } + + /* Delete the session and close the transport. */ + + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +}