Skip to main content

Author Messages with Flex

The previous tutorials leveraged messages from existing packages in Tangram Pro™. But, if a component software interface needs messages that are currently not included in existing packages, you can define your own messages with Flex – our specification language.

Flex Language Documentation is available at Flex Docs. For this tutorial, example Flex code is provided.

You'll learn how to:

  • Add support for your own messages using the Flex Code Editor

Step 1: Create Your Own Message Set

  1. Go to FlexLang in the upper left corner

  2. Click on Package Manager

  3. Create a new Flex package by clicking the New button in the upper right of the popup. Choose a name for your package using the Namespace::PackageName format. Ensure you select your team from the dropdown menu

  4. Click Create Package

  5. Create a new file by hovering over your package in the left side file viewer, clicking the File icon (the left icon next to your package)

  6. Enter the name "Messages.flex" and hit enter

  7. Paste the following code below the module name:

    struct LocationLLA {
    latitude : float64;
    longitude : float64;
    altitude : float64;
    message struct WhereAmINow {
    location: LocationLLA;
    message struct WhereShouldIGo {
    waypoint: LocationLLA;
  8. Save the file by pressing the hot-key Ctrl + S / Cmd + S

  9. Create a release of your new package by clicking the Create Release checkmark button above your package name in the left panel and then choosing Create Release r1 at the bottom right

Step 2: Build a Component-Based Design Using the New Messages

For a refresher on building a component-based design, go to Visualize a Project Design.

  1. Go to Projects and create a new Project
  2. Add a ZeroMQ Transport to the project
  3. Add three components and update their names to be:
    • LocationReporter
    • Autonomy
    • Controller
  4. Import your package in the project under the Flex Packages tab
  5. Connect LocationReporter to Controller. Select your Flex package, and message WhereAmINow.
  6. Connect Autonomy to Controller. Select your Flex package, and message WhereShouldIGo.

Step 3: Generate a CSI

For a refresher in generating a Component Software Interface, go to Generate Code with Builds.

  1. Click Build in your project
  2. Select the LocationReporter component in the list
  3. Enable Generate Interface Code and select C++ for the Output Language
  4. Click Build
  5. Download the generated code. Extract and open the package.
  6. Navigate to the code-gen/include folder. You should see a file called WhereAmINow.hpp. This file was generated as a result of your defining it as a message in your .flex file and including that message in the interface for LocationReporter. Note that WhereShouldIGo is NOT included because even though you defined it in your .flex file, it was not in the interface specification of the LocationReporter component.
  7. Open WhereAmINow.hpp. Take a look at the file and see that there are C++ functions in there to getLocation() and setLocation() that use the type LocationLLA. Note that these were defined from your the WhereAmINow message struct in your Flex file.
  8. Open LocationLLA.hpp. Take a look at the file and see that there are private class variables for latitude, longitude, and altitude. Note that these were defined in your LocationLLA struct in your Flex file.

Further Exploration

  • Enter a syntactic error in the Flex editor, and see that it identifies the error.
  • Make a change to your Flex file, such as adding a field to a message. Create a release for the changed Flex specification, update a component interface to use the new version, and generate a CSI. See how the changes you made to Flex affect the resulting interface code.


By completing this tutorial you learned how to:

  • Use Tangram Pro™ to define and use custom message definitions to build component-based systems.
  • Generate code with these user-defined Flex packages.