3.22. Example Applications

The RTI Code Generator (rtiddsgen) can generate example applications from an IDL file, as shown in Hello World with Publish/Subscribe. The last type in the IDL is used as the data-type to publish. Refer to Generating examples for instructions on how to build these examples.

Connext Micro also provides some buildable applications in the installation directory, as described in Provided examples.

3.22.1. Generating examples

Note

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

3.22.1.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.22.1.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
        - mag/shared_memory
        - mag/static_udp
        - mag/dpde
        - mag/dpse
        - psk
    - C++:
        - dpse
        - waitsets
        - mag/dpde
    - 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.22.1.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 Discovery Plugin (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

    Discovery of endpoints is done with the Static Discovery Plugin (DPSE). Static-endpoint discovery uses function calls to statically assert information about remote endpoints belonging to remote DomainParticipants.

  • shared_memory

    The only transport used is shared memory. Because the UDP Transport is disabled and only the Shared Memory Transport (SHMEM) is enabled, both the publisher and subscriber applications need to run in the same operating system.

  • static_udp

    This example uses a static UDP Transport 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, etc.).

  • waitsets

    In this example, 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

    This example includes configuration of the Message Integrity Checking settings. The CRC fields in the WireProtocolQosPolicy enable generating a checksum value based on the data being transmitted. They also determine which checksums are allowed and whether they should be sent.

  • zcv2

    This example uses the Zero Copy v2 Transport and handles discovery over the UDP Transport. User traffic is handled using the Zero Copy v2 interface.

  • psk

    This example uses pre-shared key (PSK) encryption to secure communications. You must have the Lightweight Security Plugin installed in order to compile this example.

3.22.1.4. How to compile the generated examples

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

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]

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] \ [-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>]

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’.

3.22.1.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>]

3.22.2. Provided examples

Connext Micro provides buildable example applications in the example/ directory of your installation. Each example demonstrates different features, as described below:

  • HelloWorld_transformations: A HelloWorld example that uses UDP transformations to send encrypted packets using OpenSSL.

  • HelloWorld_dgram: A HelloWorld example that uses an example DGRAM implementation.

Consult the README.txt file included with each example for instructions on how to build and run the application.