Exemple #1
0
 // Update attribute values
 private void UpdateStationAttributes(CStationHlaObject station, double timestamp)
 {
     // Add Values
     station.AddAttributeValue(Som.StationOC.StationName, station.StationName);
     station.AddAttributeValue(Som.StationOC.Location, (uint)station.Location);
     UpdateAttributeValues(station, timestamp);
 }
Exemple #2
0
        public override void FdAmb_ObjectDiscoveredHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectDiscoveredHandler(sender, data);

            #region User Code
            // Check the class type of the discovered object
            if (data.ClassHandle == Som.ShipOC.Handle) // A ship
            {
                // Create and add a new ship to the list
                CShipHlaObject newShip = new CShipHlaObject(data.ObjectInstance);
                newShip.Type = Som.ShipOC;// if user forgets to set type of the object, then an exception generated
                manager.ShipObjects.Add(newShip);

                // Request Update Values of Attributes
                // (1) Request update values of all attributes for a specific object instance
                //RequestAttributeValueUpdate(newShip);


                // (2) Request an update for all attribute values of all object instances of a specific object class
                //RequestAttributeValueUpdate(Som.ShipOC);

                // (3) Request Update Values for specific attributes only
                List <HlaAttribute> attributes = new List <HlaAttribute>();
                attributes.Add(Som.ShipOC.Callsign);
                RequestAttributeValueUpdate(newShip, attributes);
            }
            else if (data.ClassHandle == Som.StationOC.Handle) // A station
            {
                // Create and add a new station to the list
                CStationHlaObject newStation = new CStationHlaObject(data.ObjectInstance);
                newStation.Type = Som.StationOC;
                manager.StationObjects.Add(newStation);

                // Request Update Values of Attributes
                RequestAttributeValueUpdate(newStation);
            }
            #endregion //User Code
        }
Exemple #3
0
        public override void FdAmb_ObjectDiscoveredHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectDiscoveredHandler(sender, data);

            #region User Code
            // Check the class type of the discovered object
            if (data.ClassHandle == Som.ShipOC.Handle) // A ship
            {
                // Create and add a new ship to the list
                CShipHlaObject newShip = new CShipHlaObject(data.ObjectInstance);
                newShip.Type = Som.ShipOC;
                Program.ShipObjects.Add(newShip);
                // Create a new track
                CTrackHlaObject track = new CTrackHlaObject(Som.TrackOC);
                track.TrackNo = data.ObjectInstance.Handle;
                Program.MyTracks.Add(track);
                // hook to track event
                track.OutOfZone += HandleTrackOutOfZone;
                // Request Update Values of Attributes
                RequestAttributeValueUpdate(newShip);
                // register the track object
                RegisterHlaObject(track);
            }
            else if (data.ClassHandle == Som.StationOC.Handle) // A station
            {
                // Create and add a new ship to the list
                CStationHlaObject newStation = new CStationHlaObject(data.ObjectInstance);
                newStation.Type = Som.StationOC;
                Program.StationObjects.Add(newStation);

                // Request Update Values of Attributes
                // (1) Request update values of all attributes for a specific object instance
                RequestAttributeValueUpdate(newStation);
            }
            #endregion //User Code
        }
Exemple #4
0
        static public BindingList <CStationHlaObject> StationObjects; // Keeps the stations in the environment

        // Main Entrance for Application
        static void Main(string[] args)
        {
            // *************************************************
            // Initialization
            // *************************************************
            // Instantiation
            federate = new CStationFdApp();                                 // Initialize the application-specific federate
            // Local data
            station        = new CStationHlaObject(federate.Som.StationOC); // local object
            StationObjects = new BindingList <CStationHlaObject>();
            ShipObjects    = new BindingList <CShipHlaObject>();
            MyTracks       = new BindingList <CTrackHlaObject>();
            OtherTracks    = new BindingList <CTrackHlaObject>();

            // UI initialization
            PrintVersion();
            Thread ConsoleKeyListener = new Thread(new ThreadStart(ProcessKeyboard));

            ConsoleKeyListener.Name = "KeyListener";

            // Racon Initialization
            // Getting the information/debugging messages from RACoN
            federate.StatusMessageChanged += Federate_StatusMessageChanged;
            federate.LogLevel              = LogLevel.ALL;

            // initialization of station Properties
            Console.ForegroundColor = ConsoleColor.Yellow;
            setStationConfiguration();                              // get user input
            Console.Title = "StationFdApp: " + station.StationName; // set console title
            printConfiguration();                                   // report to user
            ConsoleKeyListener.Start();                             // start keyboard event listener

            // *************************************************
            // RTI Initialization
            // *************************************************
            // Initialize the federation execution
            federate.FederationExecution.FederateName       = station.StationName; // set federate name
            federate.FederationExecution.Name               = "Dardanelles";
            federate.FederationExecution.FederateType       = "StationFederate";
            federate.FederationExecution.ConnectionSettings = "rti://127.0.0.1";
            federate.FederationExecution.FDD = @".\StmsFom.xml";
            // Connect
            federate.Connect(CallbackModel.EVOKED, federate.FederationExecution.ConnectionSettings);
            // Create federation execution
            federate.CreateFederationExecution(federate.FederationExecution.Name, federate.FederationExecution.FomModules);
            // Join federation execution
            federate.JoinFederationExecution(federate.FederationExecution.FederateName, federate.FederationExecution.FederateType, federate.FederationExecution.Name, federate.FederationExecution.FomModules);

            // Declare Capability
            federate.DeclareCapability();

            //// Initialize the second federation execution
            //CStationFdApp federateForBosporus = new CStationFdApp();
            //federateForBosporus.StatusMessageChanged += Federate_StatusMessageChanged;
            //federateForBosporus.LogLevel = LogLevel.ALL;
            //federateForBosporus.FederationExecution.Name = "Bosporus";
            //federateForBosporus.FederationExecution.FederateType = "StationFederate";
            //federateForBosporus.FederationExecution.ConnectionSettings = "rti://127.0.0.1";
            //federateForBosporus.FederationExecution.FDD = @".\StmsFom.xml";
            //// Connect
            //federateForBosporus.Connect(CallbackModel.EVOKED, federateForBosporus.FederationExecution.ConnectionSettings);
            //// Create federation execution
            //federateForBosporus.CreateFederationExecution(federateForBosporus.FederationExecution.Name, federateForBosporus.FederationExecution.FomModules);
            //// Join federation execution
            //federateForBosporus.JoinFederationExecution(federateForBosporus.FederationExecution.FederateName, federateForBosporus.FederationExecution.FederateType, federateForBosporus.FederationExecution.Name, federateForBosporus.FederationExecution.FomModules);
            //// Declare Capability
            //federateForBosporus.DeclareCapability();

            // TM Initialization
            federate.EnableAsynchronousDelivery();
            //federate.EnableTimeRegulation(federate.Lookahead); // Lookahead is where this federate guarantees that it won't send any TSO message during this period
            federate.EnableTimeConstrained();

            // DDM Initialization
            //if (station.Location == LocationEnum.West)// create region according to the location
            //  federate.CreateWestRegion();
            //else
            //  federate.CreateEastRegion();

            // Various RTI Service Tests
            // DDM tests
            // Create a list of attribute set and region set pairs
            AttributeHandleSetRegionHandleSetPairVector pairs = new AttributeHandleSetRegionHandleSetPairVector();
            // Construct the region set
            List <HlaRegion> regions = new List <HlaRegion>();

            regions.Add(federate.aor1);
            // Populate the pairs. Here we use all the attributes of the object
            pairs.Pairs.Add(new KeyValuePair <List <HlaAttribute>, List <HlaRegion> >(federate.Som.ShipOC.Attributes, regions));
            federate.subscribeObjectClassAttributesWithRegions(federate.Som.ShipOC, pairs);
            federate.RequestAttributeValueUpdateWithRegions(federate.Som.ShipOC, pairs, "user-supplied tag");
            federate.UnsubscribeObjectClassWithRegions(federate.Som.ShipOC, pairs);
            //// FM tests
            //// Federate Save and Restore
            //federate.RequestFederationSave("Save_BeforeLunch");
            //federate.FederateSaveBegun();
            //// Operations for Application Specific Saving of Federate State
            //federate.FederateSaveComplete(true);
            //federate.QueryFederationSaveStatus();
            //federate.QueryFederationRestoreStatus();
            //// Support services
            //federate.Som.AreaOfResponsibility.Handle = federate.GetDimensionHandle(federate.Som.AreaOfResponsibility.Name);
            //federate.GetDimensionName(federate.Som.AreaOfResponsibility.Handle);

            // *************************************************
            // Main Simulation Loop - loops until ESC is pressed
            // *************************************************
            do
            {
                // process rti events (callbacks) and tick
                if (federate.FederateState.HasFlag(FederateStates.JOINED))
                {
                    federate.Run();
                }

                // Track Manager
                for (int i = MyTracks.Count - 1; i >= 0; i--)
                {
                    MyTracks[i].ProcessTrack(station.Location); // safe way to remove an element
                }
            } while (!Terminate);

            // Test OwM
            federate.QueryAttributeOwnership(station, federate.Som.StationOC.PrivilegeToDelete);
            bool res = federate.IsAttributeOwnedByFederate(station, federate.Som.StationOC.PrivilegeToDelete);

            //// Test for changing attribute order
            //List<Racon.RtiLayer.HlaAttribute> attributes = new List<Racon.RtiLayer.HlaAttribute>();
            //attributes.Add(federate.Som.StationOC.StationName);
            //federate.ChangeAttributeOrderType(station, attributes, Racon.OrderType.TimeStamp);// change the order type of attributes as TSO message

            //// Test for changing interaction order
            //federate.ChangeInteractionOrderType(federate.Som.RadioMessageIC, Racon.OrderType.Receive);

            // TM Tests
            federate.nextMessageRequest(federate.Time + 10);
            double time      = federate.QueryLogicalTime();
            double lookahead = federate.QueryLookahead();
            double galt;
            bool   res1 = federate.queryGALT(out galt);
            bool   res2 = federate.queryGALT();
            double list;
            bool   res4 = federate.QueryLITS(out list);
            bool   res3 = federate.QueryLITS();

            //// HLA13 calls
            //time = federate.QueryFederateTime();
            //galt = federate.QueryLBTS();
            //list = federate.QueryMinNextEventTime();

            //Console.WriteLine("Lookahead: " + federate.QueryLookahead()); // intial lookahead
            //federate.ModifyLookahead(3); // modify lookahead
            //Console.WriteLine("Lookahead: " + federate.QueryLookahead()); // modified lookahead

            //federate.FlushQueueRequest(time + lookahead);
            // *************************************************
            // Shutdown
            // *************************************************
            // Finalize user interface
            ConsoleKeyListener.Abort();
            // Finalize Federation Execution
            // Remove objects
            federate.DeleteObjectInstance(StationObjects[0]);
            // Disable time management
            federate.DisableTimeRegulation();
            //federate.DisableTimeConstrained();
            federate.DisableAsynchronousDelivery();
            // Leave and destroy federation execution
            bool result2 = federate.FinalizeFederation(federate.FederationExecution, ResignAction.NO_ACTION);

            // Dumb trace log
            System.IO.StreamWriter file = new System.IO.StreamWriter(@".\TraceLog.txt");
            file.WriteLine(federate.TraceLog);
            file.Close();
            //Console.WriteLine(federate.TraceLog.ToString());

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }