![]() |
MAK RTIspy API Documentation for HLA 1516
|
The rtisimple example is a simple C++ code example of how to use the RTI API. The simple federate tries to create a federation and join it. It publishes and subscribes to the BaseEntity object class and registers an object of that class. Then it begins to update the object attributes and periodically sends an interaction. The attribute and parameter values will contain the string names of the attributes and parameters. If two or more simple federates are executed, each federate will discover the other's objects, reflect the other's updated attributes, and receive the other's interactions.
The simple13 and simple1516 federates can interoperate using the MAK RTI. Both federates use a narrow string format for the attribute values and tags. The default federation file format matches the respective federate (that is, simple13 uses MAKsimple.fed and simple1516 uses MAKsimple.xml). The MAK RTI supports both formats for each of the HLA RTI APIs. However, the MOM specification is different in the two files. If the MOM is enabled in the RID file, then the appropriate federation file must be used.
The rtisimple example code is written in a simple procedural style and does not use any object oriented concepts other than those inherent in the RTI API. The example consists of a few simple functions that perform the basic RTI operations, including create/destroy federation execution, join/resign federation execution, publish/subscribe object class attributes, publish/subscribe interaction class, update object attribute values, and send interaction. It displays output to a console window.
All federate interactions with the RTI are performed through an RTI Ambassador instance and a Federate Ambassador instance. The RTI library provides the implementation of the RTI Ambassador class and the federate must first instantiate an instance of this class. It then uses the RTI Ambassador instance to invoke service calls on the RTI.
The federate code must provide the implementation of a Federate Ambassador (an abstract class). The simple federate derives from the MAK RTI NullFederateAmbassador class, which is a concrete class definition that has an empty body for each Federate Ambassador method. The MyFederateAmbassador class implemented by the rtisimple example federate only overrides those Federate Ambassador member functions that are necessary for this example, specifically discoverObjectInstance(), removeObjectInstance(), reflectAttributeValues(), and receiveInteraction().
The main routine of the rtisimple example starts out by collecting command line arguments that specify the federation name, the federation execution data file (.fed, or for 1516 .fdd or .xml), and the federation type. The code then instantiates instances of the RTI Ambassador and Federate Ambassador. Before entering the main execution loop the code performs the following steps.
The code then enters an execution loop in which it invokes an attribute value update and periodically invokes a send interaction. Each execution cycle includes a sleep to pace the updates and to yield the processor. A check of keyboard input allows you to escape the execution cycle. After the execution loop, the code invokes a function that resigns the federate and attempts to destroy the federation execution.
The example includes project and workspace files for Windows and makefiles for UNIX.
The project solution is in ./examples/rtisimple/mkwin32/simple.sln. The format of the solution file and project files (.vcproj) corresponds to the compiler version of the installed RTI package. Open simple.sln in your development environment and build the targets. The executables simple13(d).exe and simple1516(d).exe are in ./examples/rtisimple/bin (where "d" is appended to the base name to designate the debug version.)
The source code files are in ./examples/rtisimple/src.
The makefile and source files are in ./examples/rtisimple/src. Change directory to ./examples/rtisimple/src and run "make install" to build all the targets (or "make install targetName" to make a specific target). The executables simple13 and simple1516 are in ./examples/rtisimple/bin.
After you build the rtisimple example, the executables will be in the example's bin directory. Also in that directory will be the FED and FDD file needed to create the federation execution.
The rtisimple example uses the default RID settings (lightweight mode) unless you copy a RID file into the bin directory or otherwise specify the RID file.
When you run the example, you can specify the federation name, FED file, and federate type, as follows:
rtisimple13 [federationName [federationFile [federateType]]]
You can run any number of the rtisimple example federates. Each federate registers an object and updates its attributes, and periodically sends an interaction. If two or more rtisimple federates are executed, each federate discovers the other's objects, reflects the other's updated attributes, and receives the other's interactions.
To exit the example, in the console, q or Q.
The rtisimple code: