-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tutorials contain the code for the new Connext Guide.
- Loading branch information
1 parent
89a721e
commit 0e3e9b1
Showing
142 changed files
with
6,524 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# RTI Connext Tutorials | ||
|
||
The code included in this directory is the supporting material for the tutorials | ||
in the | ||
[Connext Developer](https://community.rti.com/static/documentation/developers/index.html) | ||
page. | ||
|
||
Please follow the instructions for each tutorial under *Learn*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
# | ||
# RTI grants Licensee a license to use, modify, compile, and create derivative | ||
# works of the Software. Licensee has the right to distribute object form | ||
# only for use with RTI products. The Software is provided "as is", with no | ||
# warranty of any type, including any warranty for fitness for any purpose. | ||
# RTI is under no obligation to maintain or support the Software. RTI shall | ||
# not be liable for any incidental or consequential damages arising out of the | ||
# use or inability to use the software. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.11) | ||
project(connext-tutorial-content-filtering) | ||
list(APPEND CMAKE_MODULE_PATH | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../../../resources/cmake/Modules" | ||
) | ||
include(ConnextDdsConfigureCmakeUtils) | ||
connextdds_configure_cmake_utils() | ||
|
||
# Include ConnextDdsAddExample.cmake from resources/cmake | ||
include(ConnextDdsAddExample) | ||
|
||
connextdds_call_codegen( | ||
IDL "home_automation" | ||
LANG "C++11" | ||
PREFIX "home_automation" | ||
) | ||
|
||
connextdds_add_application( | ||
TARGET "publisher" | ||
LANG "C++11" | ||
OUTPUT_NAME "home_automation_publisher" | ||
SOURCES | ||
$<TARGET_OBJECTS:home_automation_CXX11_obj> | ||
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_publisher.cxx" | ||
DEPENDENCIES | ||
${_CONNEXT_DEPENDENCIES} | ||
) | ||
|
||
connextdds_add_application( | ||
TARGET "subscriber" | ||
LANG "C++11" | ||
OUTPUT_NAME "home_automation_subscriber" | ||
SOURCES | ||
$<TARGET_OBJECTS:home_automation_CXX11_obj> | ||
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_subscriber.cxx" | ||
DEPENDENCIES | ||
${_CONNEXT_DEPENDENCIES} | ||
) | ||
|
||
connextdds_add_application( | ||
TARGET "subscriber_update_filter" | ||
LANG "C++11" | ||
OUTPUT_NAME "home_automation_subscriber_update_filter" | ||
SOURCES | ||
$<TARGET_OBJECTS:home_automation_CXX11_obj> | ||
"${CMAKE_CURRENT_SOURCE_DIR}/home_automation_subscriber_update_filter.cxx" | ||
DEPENDENCIES | ||
${_CONNEXT_DEPENDENCIES} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Tutorial: Content Filtering | ||
|
||
This code is part of the Connext | ||
[Content Filtering](https://community.rti.com/static/documentation/developers/learn/content-filtering.html) | ||
tutorial. | ||
|
||
## Building the Example :wrench: | ||
|
||
You can build the example following the instructions in the tutorial, or you can | ||
build it using CMake as follows. | ||
|
||
1. Generate the build files: | ||
|
||
```sh | ||
mkdir build | ||
cd build | ||
cmake .. | ||
``` | ||
|
||
This command will try to find the location of your Connext installation. If it | ||
can't find it, specify it with the ``-DCONNEXTDDS_DIR`` option, for example: | ||
|
||
```sh | ||
cmake -DCONNEXTDDS_DIR=/home/rti/rti_connext_dds-x.y.z .. | ||
``` | ||
|
||
If you are compiling for windows you may also need to specify the | ||
[generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html), | ||
and platform. | ||
|
||
```sh | ||
cmake .. -G "Visual Studio 17 2022" -A x64 | ||
``` | ||
|
||
2. Build the applications: | ||
|
||
```sh | ||
cmake --build . | ||
``` | ||
|
||
If you are using a multi-configuration generator, such as Visual Studio | ||
solutions, you can specify the configuration mode to build as follows: | ||
|
||
```sh | ||
cmake --build . --config Release|Debug | ||
``` | ||
|
||
## Running the Example :rocket: | ||
|
||
See the tutorial for instructions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
(c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
RTI grants Licensee a license to use, modify, compile, and create derivative | ||
works of the Software. Licensee has the right to distribute object form only | ||
for use with RTI products. The Software is provided "as is", with no warranty | ||
of any type, including any warranty for fitness for any purpose. RTI is under | ||
no obligation to maintain or support the Software. RTI shall not be liable for | ||
any incidental or consequential damages arising out of the use or inability to | ||
use the software. | ||
--> | ||
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd"> | ||
<qos_library name="MyLibrary"> | ||
<qos_profile name="MyProfile" is_default_qos="true"> | ||
<base_name> | ||
<element>BuiltinQosLib::Generic.StrictReliable</element> | ||
</base_name> | ||
</qos_profile> | ||
</qos_library> | ||
</dds> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
* | ||
* RTI grants Licensee a license to use, modify, compile, and create derivative | ||
* works of the Software. Licensee has the right to distribute object form | ||
* only for use with RTI products. The Software is provided "as is", with no | ||
* warranty of any type, including any warranty for fitness for any purpose. | ||
* RTI is under no obligation to maintain or support the Software. RTI shall | ||
* not be liable for any incidental or consequential damages arising out of the | ||
* use or inability to use the software. | ||
*/ | ||
|
||
struct DeviceStatus { | ||
@key string sensor_name; | ||
string room_name; | ||
boolean is_open; | ||
}; |
39 changes: 39 additions & 0 deletions
39
tutorials/content_filtering/c++11/home_automation_publisher.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
// | ||
// RTI grants Licensee a license to use, modify, compile, and create derivative | ||
// works of the Software. Licensee has the right to distribute object form | ||
// only for use with RTI products. The Software is provided "as is", with no | ||
// warranty of any type, including any warranty for fitness for any purpose. | ||
// RTI is under no obligation to maintain or support the Software. RTI shall | ||
// not be liable for any incidental or consequential damages arising out of the | ||
// use or inability to use the software. | ||
// | ||
|
||
#include <iostream> | ||
#include <thread> | ||
#include <rti/rti.hpp> | ||
#include "home_automation.hpp" | ||
|
||
void publish_sensor( | ||
const std::string &sensor_name, | ||
const std::string &room_name) | ||
{ | ||
dds::domain::DomainParticipant participant(0); | ||
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus"); | ||
dds::pub::DataWriter<DeviceStatus> writer(topic); | ||
|
||
DeviceStatus device_status { sensor_name, room_name, false }; | ||
for (int i = 0; i < 1000; i++) { | ||
device_status.is_open(!device_status.is_open()); | ||
writer.write(device_status); | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
std::string sensor_name = (argc > 1) ? argv[1] : "Window1"; | ||
std::string room_name = (argc > 2) ? argv[2] : "LivingRoom"; | ||
publish_sensor(sensor_name, room_name); | ||
} |
45 changes: 45 additions & 0 deletions
45
tutorials/content_filtering/c++11/home_automation_subscriber.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
// | ||
// RTI grants Licensee a license to use, modify, compile, and create derivative | ||
// works of the Software. Licensee has the right to distribute object form | ||
// only for use with RTI products. The Software is provided "as is", with no | ||
// warranty of any type, including any warranty for fitness for any purpose. | ||
// RTI is under no obligation to maintain or support the Software. RTI shall | ||
// not be liable for any incidental or consequential damages arising out of the | ||
// use or inability to use the software. | ||
// | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
#include "rti/rti.hpp" | ||
#include "rti/sub/SampleProcessor.hpp" | ||
#include "home_automation.hpp" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
dds::domain::DomainParticipant participant(0); | ||
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus"); | ||
dds::topic::ContentFilteredTopic<DeviceStatus> content_filtered_topic( | ||
topic, | ||
"FilterRoomAndOpenWindows", | ||
dds::topic::Filter("is_open = true and room_name = 'LivingRoom'")); | ||
dds::sub::DataReader<DeviceStatus> reader(content_filtered_topic); | ||
|
||
rti::sub::SampleProcessor sample_processor; | ||
sample_processor.attach_reader( | ||
reader, | ||
[](const rti::sub::LoanedSample<DeviceStatus> &sample) { | ||
if (sample.info().valid()) { // ignore samples with only | ||
// meta-data | ||
std::cout << "WARNING: " << sample.data().sensor_name() | ||
<< " in " << sample.data().room_name() | ||
<< " is open!" << std::endl; | ||
} | ||
}); | ||
|
||
while (true) { // wait in a loop | ||
std::this_thread::sleep_for(std::chrono::seconds(4)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tutorials/content_filtering/c++11/home_automation_subscriber_update_filter.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
// | ||
// RTI grants Licensee a license to use, modify, compile, and create derivative | ||
// works of the Software. Licensee has the right to distribute object form | ||
// only for use with RTI products. The Software is provided "as is", with no | ||
// warranty of any type, including any warranty for fitness for any purpose. | ||
// RTI is under no obligation to maintain or support the Software. RTI shall | ||
// not be liable for any incidental or consequential damages arising out of the | ||
// use or inability to use the software. | ||
// | ||
|
||
#include <iostream> | ||
#include <thread> | ||
|
||
#include "rti/rti.hpp" | ||
#include "rti/sub/SampleProcessor.hpp" | ||
#include "home_automation.hpp" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
dds::domain::DomainParticipant participant(0); | ||
dds::topic::Topic<DeviceStatus> topic(participant, "WindowStatus"); | ||
dds::core::StringSeq parameters(1, "'LivingRoom'"); | ||
dds::topic::ContentFilteredTopic<DeviceStatus> content_filtered_topic( | ||
topic, | ||
"FilterRoomAndOpenWindows", | ||
dds::topic::Filter( | ||
"is_open = true and room_name = %0", | ||
parameters)); | ||
dds::sub::DataReader<DeviceStatus> reader(content_filtered_topic); | ||
|
||
parameters[0] = "'Kitchen'"; | ||
content_filtered_topic.filter_parameters( | ||
parameters.begin(), | ||
parameters.end()); | ||
|
||
rti::sub::SampleProcessor sample_processor; | ||
sample_processor.attach_reader( | ||
reader, | ||
[](const rti::sub::LoanedSample<DeviceStatus> &sample) { | ||
if (sample.info().valid()) { // ignore samples with only | ||
// meta-data | ||
std::cout << "WARNING: " << sample.data().sensor_name() | ||
<< " in " << sample.data().room_name() | ||
<< " is open!" << std::endl; | ||
} | ||
}); | ||
|
||
while (true) { // wait in a loop | ||
std::this_thread::sleep_for(std::chrono::seconds(4)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Tutorial: Content Filtering | ||
|
||
This code is part of the Connext | ||
[Content Filtering](https://community.rti.com/static/documentation/developers/learn/content-filtering.html) | ||
tutorial and is included here in full for convenience. | ||
|
||
Please see the tutorial for instructions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
(c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved. | ||
RTI grants Licensee a license to use, modify, compile, and create derivative | ||
works of the Software. Licensee has the right to distribute object form only | ||
for use with RTI products. The Software is provided "as is", with no warranty | ||
of any type, including any warranty for fitness for any purpose. RTI is under | ||
no obligation to maintain or support the Software. RTI shall not be liable for | ||
any incidental or consequential damages arising out of the use or inability to | ||
use the software. | ||
--> | ||
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd"> | ||
<qos_library name="MyLibrary"> | ||
<qos_profile name="MyProfile" is_default_qos="true"> | ||
<base_name> | ||
<element>BuiltinQosLib::Generic.StrictReliable</element> | ||
</base_name> | ||
</qos_profile> | ||
</qos_library> | ||
</dds> |
Oops, something went wrong.