diff --git a/CMakeLists.txt b/CMakeLists.txt index e7e0258e..c4ad2ba5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -418,6 +418,8 @@ if(UCLIENT_BUILD_EXAMPLES) add_subdirectory(examples/PublishHelloWorldBestEffort) add_subdirectory(examples/SubscribeHelloWorldBestEffort) add_subdirectory(examples/BinaryEntityCreation) + add_subdirectory(examples/PublishBigHelloWorld) + add_subdirectory(examples/SubscribeBigHelloWorld) if(UCLIENT_PLATFORM_LINUX) add_subdirectory(examples/CustomTransports) diff --git a/examples/PublishBigHelloWorld/BigHelloWorld.c b/examples/PublishBigHelloWorld/BigHelloWorld.c new file mode 100644 index 00000000..a21933a4 --- /dev/null +++ b/examples/PublishBigHelloWorld/BigHelloWorld.c @@ -0,0 +1,59 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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. + +/*! + * @file BigHelloWorld.c + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#include "BigHelloWorld.h" + +#include +#include + +bool BigHelloWorld_serialize_topic( + ucdrBuffer* writer, + const BigHelloWorld* topic) +{ + (void) ucdr_serialize_uint32_t(writer, topic->index); + + (void) ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool BigHelloWorld_deserialize_topic( + ucdrBuffer* reader, + BigHelloWorld* topic) +{ + (void) ucdr_deserialize_uint32_t(reader, &topic->index); + + (void) ucdr_deserialize_string(reader, topic->message, sizeof(topic->message)); + + return !reader->error; +} + +uint32_t BigHelloWorld_size_of_topic( + const BigHelloWorld* topic, + uint32_t size) +{ + uint32_t previousSize = size; + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + 1); + + return size - previousSize; +} diff --git a/examples/PublishBigHelloWorld/BigHelloWorld.h b/examples/PublishBigHelloWorld/BigHelloWorld.h new file mode 100644 index 00000000..88b309a0 --- /dev/null +++ b/examples/PublishBigHelloWorld/BigHelloWorld.h @@ -0,0 +1,63 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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. + +/*! + * @file BigHelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _BigHelloWorld_H_ +#define _BigHelloWorld_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include + +#define BIG_HELLO_WORLD_STRING_SIZE 50000 + +/*! + * @brief This struct represents the structure BigHelloWorld defined by the user in the IDL file. + * @ingroup BIGHELLOWORLD + */ +typedef struct BigHelloWorld +{ + uint32_t index; + char message[BIG_HELLO_WORLD_STRING_SIZE]; + +} BigHelloWorld; + +struct ucdrBuffer; + +bool BigHelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const BigHelloWorld* topic); +bool BigHelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + BigHelloWorld* topic); +uint32_t BigHelloWorld_size_of_topic( + const BigHelloWorld* topic, + uint32_t size); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // _BigHelloWorld_H_ diff --git a/examples/PublishBigHelloWorld/CMakeLists.txt b/examples/PublishBigHelloWorld/CMakeLists.txt new file mode 100644 index 00000000..c6993fec --- /dev/null +++ b/examples/PublishBigHelloWorld/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed 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. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(PublishBigHelloWorldClient C) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c BigHelloWorld.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/PublishBigHelloWorld/README.md b/examples/PublishBigHelloWorld/README.md new file mode 100644 index 00000000..f278b00c --- /dev/null +++ b/examples/PublishBigHelloWorld/README.md @@ -0,0 +1,20 @@ +# PublishBigHelloWorld example + +This example will show how to send big data (up to 64 kB) to the DDS World creating a client publisher. +In order to compile this example, the following profiles should be enabled: + +- `UCLIENT_PROFILE_UDP` + +## Usage +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. +2. Run the *SubscriberBigHelloWorld* example or some subscriber that can read the *BigHelloWorld* topic. +3. Run the *PublisherBigHelloWorld* example. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the number of topics that will be sent. + + If no number is given, the subscriber will listen indefinitely. + +## Considerations + +- Notice that `BUFFER_SIZE` shall be big enough to store the whole message. +- Notice that `STREAM_HISTORY` shall power of two. + diff --git a/examples/PublishBigHelloWorld/main.c b/examples/PublishBigHelloWorld/main.c new file mode 100644 index 00000000..ecef822e --- /dev/null +++ b/examples/PublishBigHelloWorld/main.c @@ -0,0 +1,146 @@ +// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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 "BigHelloWorld.h" + +#include +#include + +#include //printf +#include //strcmp +#include //atoi +#include //assert + +#define STREAM_HISTORY 128 +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY + +int main( + int args, + char** argv) +{ + assert(BUFFER_SIZE > BIG_HELLO_WORLD_STRING_SIZE); + + // CLI + if (3 > args || 0 == atoi(argv[2])) + { + printf("usage: program [-h | --help] | ip port []\n"); + return 0; + } + + char* ip = argv[1]; + char* port = argv[2]; + uint32_t max_topics = (args == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; + + // Transport + uxrUDPTransport transport; + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xAAAABBBB); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "BigHelloWorldTopic" + "BigHelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + + uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); + const char* publisher_xml = ""; + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); + + uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); + const char* datawriter_xml = "" + "" + "" + "NO_KEY" + "BigHelloWorldTopic" + "BigHelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); + + // Send create entities message and wait its status + uint8_t status[4]; + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %i topic: %i publisher: %i datawriter: %i\n", status[0], + status[1], status[2], status[3]); + return 1; + } + + // Write topics + bool connected = true; + uint32_t count = 0; + while (connected && count < max_topics) + { + BigHelloWorld topic; + topic.index = count++; + memset(topic.message, 'A', sizeof(topic.message) - 1); + topic.message[sizeof(topic.message) - 1] = '\0'; + + ucdrBuffer ub; + uint32_t topic_size = BigHelloWorld_size_of_topic(&topic, 0); + uxr_prepare_output_stream(&session, reliable_out, datawriter_id, &ub, topic_size); + BigHelloWorld_serialize_topic(&ub, &topic); + + printf("Send topic with size %d, id: %d\n", (uint32_t)strlen(topic.message), topic.index); + connected = uxr_run_session_time(&session, 1000); + } + + // Delete resources + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +} diff --git a/examples/SubscribeBigHelloWorld/BigHelloWorld.c b/examples/SubscribeBigHelloWorld/BigHelloWorld.c new file mode 100644 index 00000000..a21933a4 --- /dev/null +++ b/examples/SubscribeBigHelloWorld/BigHelloWorld.c @@ -0,0 +1,59 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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. + +/*! + * @file BigHelloWorld.c + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#include "BigHelloWorld.h" + +#include +#include + +bool BigHelloWorld_serialize_topic( + ucdrBuffer* writer, + const BigHelloWorld* topic) +{ + (void) ucdr_serialize_uint32_t(writer, topic->index); + + (void) ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool BigHelloWorld_deserialize_topic( + ucdrBuffer* reader, + BigHelloWorld* topic) +{ + (void) ucdr_deserialize_uint32_t(reader, &topic->index); + + (void) ucdr_deserialize_string(reader, topic->message, sizeof(topic->message)); + + return !reader->error; +} + +uint32_t BigHelloWorld_size_of_topic( + const BigHelloWorld* topic, + uint32_t size) +{ + uint32_t previousSize = size; + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + 1); + + return size - previousSize; +} diff --git a/examples/SubscribeBigHelloWorld/BigHelloWorld.h b/examples/SubscribeBigHelloWorld/BigHelloWorld.h new file mode 100644 index 00000000..88b309a0 --- /dev/null +++ b/examples/SubscribeBigHelloWorld/BigHelloWorld.h @@ -0,0 +1,63 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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. + +/*! + * @file BigHelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _BigHelloWorld_H_ +#define _BigHelloWorld_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include + +#define BIG_HELLO_WORLD_STRING_SIZE 50000 + +/*! + * @brief This struct represents the structure BigHelloWorld defined by the user in the IDL file. + * @ingroup BIGHELLOWORLD + */ +typedef struct BigHelloWorld +{ + uint32_t index; + char message[BIG_HELLO_WORLD_STRING_SIZE]; + +} BigHelloWorld; + +struct ucdrBuffer; + +bool BigHelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const BigHelloWorld* topic); +bool BigHelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + BigHelloWorld* topic); +uint32_t BigHelloWorld_size_of_topic( + const BigHelloWorld* topic, + uint32_t size); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // _BigHelloWorld_H_ diff --git a/examples/SubscribeBigHelloWorld/CMakeLists.txt b/examples/SubscribeBigHelloWorld/CMakeLists.txt new file mode 100644 index 00000000..1c013cf2 --- /dev/null +++ b/examples/SubscribeBigHelloWorld/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed 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. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(SubscribBigBigClient C) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c BigHelloWorld.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/SubscribeBigHelloWorld/README.md b/examples/SubscribeBigHelloWorld/README.md new file mode 100644 index 00000000..1062d3fe --- /dev/null +++ b/examples/SubscribeBigHelloWorld/README.md @@ -0,0 +1,19 @@ +# SubscribeBigHelloWorld example + +This example will show how to receive big data (up to 64 kB) to the DDS World creating a client publisher. +In order to compile this example, the following profiles should be enabled: + +- `UCLIENT_PROFILE_UDP` + +## Usage +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. +2. Run the *PublisherBigHelloWorld* example or some publisher that can send the *BigHelloWorld* topic. +3. Run the *SubscriberBigHelloWorld* example. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the amount of times that the topic will be listened. + If no number is given, the publisher will publish indefinitely. + +## Considerations + +- Notice that `BUFFER_SIZE` shall be big enough to store the whole message. +- Notice that `STREAM_HISTORY` shall power of two. + diff --git a/examples/SubscribeBigHelloWorld/main.c b/examples/SubscribeBigHelloWorld/main.c new file mode 100644 index 00000000..9c04233d --- /dev/null +++ b/examples/SubscribeBigHelloWorld/main.c @@ -0,0 +1,171 @@ +// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed 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 "BigHelloWorld.h" + +#include + +#include //printf +#include //strcmp +#include //atoi +#include //assert + +#define STREAM_HISTORY 128 +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY + +void on_topic( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) +{ + (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) length; + + BigHelloWorld topic; + BigHelloWorld_deserialize_topic(ub, &topic); + + printf("Received topic with size %d, id: %i\n", (uint32_t)strlen(topic.message), topic.index); + + // Print first 30 characters + char message[31]; + memcpy(message, topic.message, 30); + message[30] = '\0'; + printf("\tMessage: %s...\n", message); + + uint32_t* count_ptr = (uint32_t*) args; + (*count_ptr)++; +} + +int main( + int args, + char** argv) +{ + assert(BUFFER_SIZE > BIG_HELLO_WORLD_STRING_SIZE); + + // CLI + if (3 > args || 0 == atoi(argv[2])) + { + printf("usage: program [-h | --help] | ip port []\n"); + return 0; + } + + char* ip = argv[1]; + char* port = argv[2]; + uint32_t max_topics = (args == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; + + // State + uint32_t count = 0; + + // Transport + uxrUDPTransport transport; + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); + uxr_set_topic_callback(&session, on_topic, &count); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "BigHelloWorldTopic" + "BigHelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + + uxrObjectId subscriber_id = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); + const char* subscriber_xml = ""; + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, + subscriber_xml, UXR_REPLACE); + + uxrObjectId datareader_id = uxr_object_id(0x01, UXR_DATAREADER_ID); + const char* datareader_xml = "" + "" + "" + "NO_KEY" + "BigHelloWorldTopic" + "BigHelloWorld" + "" + "" + ""; + uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, + datareader_xml, UXR_REPLACE); + + // Send create entities message and wait its status + uint8_t status[4]; + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], + status[1], status[2], status[3]); + return 1; + } + + // Request topics + uxrDeliveryControl delivery_control = { + 0 + }; + delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; + uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, &delivery_control); + + // Read topics + bool connected = true; + while (connected && count < max_topics) + { + connected = uxr_run_session_time(&session, 1000); + } + + // Delete resources + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +} diff --git a/examples/SubscribeHelloWorld/main.c b/examples/SubscribeHelloWorld/main.c index d535d77d..b0e40d2a 100644 --- a/examples/SubscribeHelloWorld/main.c +++ b/examples/SubscribeHelloWorld/main.c @@ -37,7 +37,7 @@ void on_topic( HelloWorld topic; HelloWorld_deserialize_topic(ub, &topic); - printf("Received topic: %s, id: %i\n", topic.message, topic.index); + printf("Received topic: %s, id: %d\n", topic.message, topic.index); uint32_t* count_ptr = (uint32_t*) args; (*count_ptr)++;