3.2. Generating Examples

The RTI Code Generator (also referred to as rtiddsgen) included with Connext Micro can generate DDS example applications with a type definition file as input.

Note

Before running rtiddsgen, you might need to add rti_connext_dds-<version>/rtiddsgen/scripts to your path environment variable folder.

3.2.1. Default example

To generate an example, run the following command:

rtiddsgen -example -language <C|C++> [-namespace] <file with type definition>

This generates an example using the default example template, which uses the Dynamic Participant Dynamic Endpoint (DPDE) discovery plugin.

rtiddsgen accepts the following options:

  • -example: Generates type files, example files, and CMakelists files.

  • -language <C|C++>: Generates C or C++ code.

  • -namespace: Enables C++ namespaces when the language option is C++.

The generated example can then be compiled using CMake and the CMakelists.txt file generated by Code Generator. Code Generator also creates a README.txt file with a description of the example and instructions for how to compile and run it.

3.2.2. Custom example

Code Generator can also generate examples using custom templates with the option -exampleTemplate <templateName>.

To generate an example using a custom template instead of the default one, run the following command:

rtiddsgen -example -exampleTemplate <template name> -language <C|C++> [-namespace] <file with type definition>

To see the list of the available templates for each language, run the following command:

rtiddsgen -showTemplates

As an example, the following command will generate an example in the C language, using the waitsets custom template instead of the default template:

List of example templates per language:
    - C:
        - cert
        - dpse
        - shared_memory
        - static_udp
        - waitsets
        - crc
        - zcv2
    - C++:
        - dpse
        - waitsets
    - C++ Namespace:
        - dpse
        - waitsets

The following command will generate an example in the C language, using the ‘waitsets’ custom template instead of the default template:

rtiddsgen -example -exampleTemplate waitsets -language C <file with type definition>

3.2.3. Descriptions of generated examples

Each example consists of a publication and subscription pair to send and receive the type specified by the user. When compiled, the example creates two applications: one to send samples (a publisher) and another to receive samples (a subscriber).

  • default example (no template specified)

    Discovery of endpoints is done with the dynamic-endpoint discovery (DPDE). Only the UDP and INTRA transports are enabled. The subscriber application creates a DataReader, which uses a listener to receive notifications about new samples and matched publishers. These notifications are received in the middleware thread (instead of the application thread).

  • cert

    An example that only uses APIs that are compatible with Connext Cert.

  • dpse

    Identical to the default template, except that the discovery of endpoints is done with static-endpoint discovery (DPSE). Static-endpoint discovery uses function calls to statically assert information about remote endpoints belonging to remote DomainParticipants.

  • secure

    Identical to the default template, except that this example uses secure communication.

  • shared_memory

    Identical to the default template, except that the only transport used is shared memory. Because the UDP transport is disabled and only the shared memory transport is enabled, both the publisher and subscriber applications need to run in the same OS.

  • static_udp

    Identical to the default template, except that this example uses a static UDP interface configuration. Using this API, the UDP transport is statically configured. This is useful in systems that are not able to return the installed UDP interfaces (name, IP address, mask…).

  • waitsets

    The only difference from the default template is that the Subscriber application creates a DataReader that uses a Waitset (instead of a listener) to receive notifications about new samples and matched publishers. These notifications are received in the middleware thread (instead of the application thread).

  • crc Identical to the default template, except that the configuration of the CRC settings. The CRC QoS enables the generation of a checksum value based on the data being transmitted. It also determines which checksums are allowed and whether they should be sent.

  • zcv2 Identical to the default template, with the added Zero Copy v2 interface. This example performs discovery over UDP. User traffic is handled using the Zero Copy v2 interface.

3.2.4. How to compile the generated examples

Before compiling, set the environment variable RTIMEHOME to the Connext Micro installation directory.

Depending on the number of network interfaces installed on the local machine, you might need to restrict which interfaces are used by Connext Micro. Use the option -udp_intf <interface name> when running the example.

The Connext Micro source bundle includes rtime-make (on Linux® and macOS® systems) or rtime-make.bat (on Windows® systems) to simplify invocation of CMake. This script is a convenient way to invoke CMake with the correct options. For example:

cd <directory with generated example>

rtime-make --config <Debug|Release> --build --target armv8leElfgcc7.3.0-Linux4 --source-dir . \
     -G "Unix Makefiles" --delete [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true] \
     [-DRTIME_LINK_SHMEM_LIBS=true]
cd <directory with generated example>

rtime-make --config <Debug|Release> --build --target x86_64leMachOclang15.0-Darwin23 --source-dir . \
     -G "Unix Makefiles" --delete [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true] \
     [-DRTIME_LINK_SHMEM_LIBS=true]
cd <directory with generated example>

rtime-make.bat --config <Debug|Release> --build --target x86_64lePEvs2017-Win10 --source-dir . \
     -G "Visual Studio 15 2017" --delete [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE_eq_true] \
     [-DRTIME_LINK_SHMEM_LIBS_eq_true]

Warning

RTI recommends using the toolchain file that matches the target architecture to compile the generated examples.

For example, if the target architecture is --target armv8leElfgcc7.3.0-Linux4, then the example applications should be compiled with the armv8leElfgcc7.3.0-Linux4 toolchain file. Failing to do so may cause warnings.

The executable can be found in the directory ‘objs’.

It is also possible to compile using CMake, e.g., when the Connext Micro source bundle is not installed.

cmake [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true] [-DRTIME_LINK_SHMEM_LIBS=true] \
      [-DCMAKE_BUILD_TYPE=<Debug|Release>] -G "Unix Makefiles" -B./<your build directory> -H. -DRTIME_TARGET_NAME=armv8leElfgcc7.3.0-Linux4

cmake --build ./<your build directory> [--config <Debug|Release>]
cmake [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true] [-DRTIME_LINK_SHMEM_LIBS=true] \
      [-DCMAKE_BUILD_TYPE=<Debug|Release>] -G "Unix Makefiles" -B./<your build directory> -H. -DRTIME_TARGET_NAME=x86_64leMachOclang15.0-Darwin23

cmake --build ./<your build directory> [--config <Debug|Release>]
cmake [-DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true] [-DRTIME_LINK_SHMEM_LIBS=true] \
      [-DCMAKE_BUILD_TYPE=<Debug|Release>] -G "Visual Studio 15 2017" -B./<your build directory> -H. -DRTIME_TARGET_NAME=x86_64lePEvs2017-Win10

cmake --build .\<your build directory> [--config <Debug|Release>]

The executable can be found in the directory ‘objs’.

The following options are accepted:

  • -DRTIME_IDL_ADD_REGENERATE_TYPESUPPORT_RULE=true adds a rule to regenerate type support plugin source files if the input file with the type definition changes. Default value is ‘false’.

  • -DRTIME_LINK_SHMEM_LIBS=true adds a dependency to the shared memory transport libraries. This option shall be used only with the shared memory example. The default value is ‘false’.

3.2.5. How to run the generated examples

By default, the example uses all available interfaces to receive samples. This can cause communication problems if the number of available interfaces is greater than the maximum number of interfaces supported by Connext Micro. For this reason, it is recommended to restrict the number of interfaces used by the application. Use the option -udp_intf <interface name> when running the example.

For example, if the example has been compiled for Linux i86Linux2.6gcc4.4.5, run the subscriber with this command:

objs/armv8leElfgcc7.3.0-Linux4/<Type definition file name>_subscriber [-domain <Domain_ID>] [-peer <address>] \
             [-sleep <sleep_time>] [-count <seconds_to_run>] [-udp_intf <interface name>]

and run the publisher with this command:

objs/armv8leElfgcc7.3.0-Linux4/<Type definition file name>_publisher [-domain <Domain_ID> -peer <address>] \
             [-sleep <sleep_time>] [-count <seconds_to_run>] [-udp_intf <interface name>]

Note

Shared memory examples only accept the following options:

  • [-domain <Domain_ID>]

  • [-sleep <sleep_time>]

  • [-count <seconds_to_run>]