xiaoxiang781216 commented on code in PR #3777: URL: https://github.com/apache/nuttx-apps/pull/3777#discussion_r3972387574
########## 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 <string.h> + +#include <ucdr/microcdr.h> + +#include "HelloWorld.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +bool HelloWorld_serialize_topic(struct ucdrBuffer *writer, + const HelloWorld *topic) +{ + (void)ucdr_serialize_uint32_t(writer, topic->index); Review Comment: remove all `(void)` ########## system/xrcedds/HelloWorld.h: ########## @@ -0,0 +1,63 @@ +/**************************************************************************** + * apps/system/xrcedds/HelloWorld.h Review Comment: it's better to move the demo app to apps/examples folder ########## 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 <nuttx/config.h> + +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <uxr/client/client.h> +#include <ucdr/microcdr.h> + +#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 [<max_topics>]\n"); Review Comment: program->argv[0] ########## 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 Review Comment: should we keep unpack name same as the project name ########## 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)) Review Comment: why not remove VPATH and use the full source file name ########## 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 <string.h> + +#include <ucdr/microcdr.h> + +#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) + Review Comment: remove all (uint32_t) ########## 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" Review Comment: do we need expose config.h to other project ########## 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 <nuttx/config.h> + +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <uxr/client/client.h> +#include <ucdr/microcdr.h> + +#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 [<max_topics>]\n"); + return 0; + } + + ip = argv[1]; + port = argv[2]; + max_topics = (argc == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; Review Comment: ```suggestion max_topics = argc == 4 ? atoi(argv[3]) : UINT32_MAX; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
