vsTASKER 7 Tutorial
×
Menu
Index

Subscribe

  
 
Now, double-click on the subscribing FedItem to call its Property Window
 
 typedef struct {
    hlaPosition   position;
    hlaIdentifier ident;
    hlaState      state;
    bool _position, _ident, _state;
 } local;
 
 
 
Every time an Attribute of a subcribed Object is changed by one federate, the corresponding FedItem is called for the paired Attribute.
We then need to copy locally the data coming from the RTI.
 
Let's open the State Attribute and add the following code:
 
 local.state <- (hlaState);
 local._state = true;
 
 
This code means that the data coming from the RTI must be casted as hlaState (structure) and copied to the local.state variable we defined above in the Declaration part of the FedItem.
 
Let's do the same for the remaining two Attributes:
 
 local.position <- (hlaPosition);
 local._position = true;
 
 local.ident <- (hlaIdentifier);
 local._ident = true;
 
 
When the Object is first found on the RTI, the Discover part is called with the Object handle.
If the FedItem allows runtime entities () the Discover part will automatically try to create an Entity, set the entity pointer and pair it with the handle.
 
 entity = new Entity("default", objectInstanceName);
 add(entity); // in the used_by list
 store(entity); // associate it with the handle
 
We know that the Object code part will be called once all Attributes have been received.
This is the reason why we have raised the flag, because not all data structure might be changed and as several Entities do share the same FedItem, this way of working insure that data from different entities will not be mixed up.
 
 if (local._state) {
     entity->getDyn()->setHeading(local.state.Heading);
     entity->getDyn()->setSpeed(local.state.Speed);
 }
 
 if (local._position) {
     entity->pos.x = local.position.X;
     entity->pos.y = local.position.Y;
     entity->pos.z = local.position.Z;
 }
 
Now, let's run the application...