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 a Flex Package

  1. Go to FlexLang in the top navigation bar
  2. Click on Package Manager and then the blue New button
  3. Enter a name for your package using the Namespace::PackageName format (e.g. Tutorial::Package), and choose an owner
  4. Click Create Package and wait for the Flex environment to load
  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;
}
  1. Save the file by pressing the hot-key Ctrl + S / Cmd + S
  2. 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: Use Messages in a Design

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

  1. Create a new project
  2. Add three components and update their names to be:
    • LocationReporter
    • Autonomy
    • Controller
  3. Add a ZeroMQ transport
  4. Draw a connection from LocationReporter to Controller
  5. Click on the connection and choose your custom Flex package and message WhereAmINow
  6. Draw a connection from Autonomy to Controller
  7. Click on the connection and choose your custom Flex package and message WhereShouldIGo

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 and update a component interface to use the new version. See how the changes you made to Flex affect the resulting interface code.

Cheers!

By completing this tutorial you learned how to:

  • Use Tangram Pro™ to define and use custom message definitions to build component-based systems.