コード例 #1
0
ファイル: StationFdApp.cs プロジェクト: otopcu/STMS
        // Reflect Object Attributes
        public override void FdAmb_ObjectAttributesReflectedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectAttributesReflectedHandler(sender, data);

            #region User Code
            foreach (var item in Program.StationObjects)
            {
                // Update station
                if (data.ObjectInstance.Handle == item.Handle)
                {
                    // Get parameter values - 2nd method
                    foreach (var pair in data.ObjectInstance.Attributes)
                    {
                        if (pair.Handle == Som.StationOC.StationName.Handle)
                        {
                            item.StationName = pair.GetValue <string>();
                        }
                        else if (pair.Handle == Som.StationOC.Location.Handle)
                        {
                            item.Location = pair.GetValue <LocationEnum>();
                        }
                    }
                }
            }
            foreach (var item in Program.MyTracks)
            {
                // Update track
                if (data.ObjectInstance.Handle == item.TrackNo)
                {
                    // Get parameter values - 1st method
                    // First check whether  the attr is updated or not. Result returns 0/null if the updated attribute set does not contain the attr and its value
                    if (data.IsValueUpdated(Som.ShipOC.Callsign))
                    {
                        item.TrackName = data.GetAttributeValue <string>(Som.ShipOC.Callsign);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Position))
                    {
                        item.TrackPosition = data.GetAttributeValue <PositionType>(Som.ShipOC.Position);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Heading))
                    {
                        item.TrackHeading = data.GetAttributeValue <LocationEnum>(Som.ShipOC.Heading);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Speed))
                    {
                        item.TrackSpeed = data.GetAttributeValue <SpeedEnum>(Som.ShipOC.Speed);
                    }
                }
            }
            foreach (var item in Program.OtherTracks)
            {
                // Find the Object
                if (data.ObjectInstance.Handle == item.Handle)
                {
                }
            }
            #endregion //User Code
        }
コード例 #2
0
        // FdAmb_ObjectAttributesReflectedHandler
        public override void FdAmb_ObjectAttributesReflectedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectAttributesReflectedHandler(sender, data);

            #region User Code
            throw new NotImplementedException("FdAmb_ObjectAttributesReflectedHandler");
            #endregion //User Code
        }
コード例 #3
0
 public override void FdAmb_ObjectDiscoveredHandler(object sender, HlaObjectEventArgs data)
 {
     // Call the base class handler
     base.FdAmb_ObjectDiscoveredHandler(sender, data);
     if (data.ClassHandle == Som.SensorOC.Handle)
     {
         CSensorHlaObject datacollection = new CSensorHlaObject(data.ObjectInstance);
         datacollection.Type = Som.SensorOC;
         manager.obj_list.Add(datacollection);
         RegisterHlaObject(datacollection);
         Console.WriteLine("A new object joined");
     }
     #region User Code
     //throw new NotImplementedException("FdAmb_ObjectDiscoveredHandler");
     #endregion //User Code
 }
コード例 #4
0
ファイル: StationFdApp.cs プロジェクト: otopcu/STMS
        // An Object is Removed
        public override void FdAmb_ObjectRemovedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectRemovedHandler(sender, data);

            #region User Code
            // Lock while taking a snapshot - to avoid foreach loop enumeration exception
            object[] stations, otracks, mytracks;
            lock (thisLock)
            {
                stations = Program.StationObjects.ToArray();
                mytracks = Program.MyTracks.ToArray();
                otracks  = Program.OtherTracks.ToArray();
            }
            foreach (CStationHlaObject station in stations)
            {
                if (data.ObjectInstance.Handle == station.Handle)// Find the Object
                {
                    Program.StationObjects.Remove(station);
                    Report($"Station: {station.StationName} left." + Environment.NewLine);
                }
            }
            foreach (CTrackHlaObject track in mytracks)
            {
                if (data.ObjectInstance.Handle == track.TrackNo)// Find the Object
                {
                    Program.MyTracks.Remove(track);
                    Report($"Ship: {track.TrackName} left." + Environment.NewLine);
                }
            }
            foreach (CTrackHlaObject track in otracks)
            {
                if (data.ObjectInstance.Handle == track.Handle)// Find the Object
                {
                    Program.OtherTracks.Remove(track);
                    Report($"Track: {track.TrackName} deleted." + Environment.NewLine);
                }
            }
            #endregion //User Code
        }
コード例 #5
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        // An Object is Removed
        public override void FdAmb_ObjectRemovedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectRemovedHandler(sender, data);

            #region User Code
            // Lock while taking a snapshot - to avoid foreach loop enumeration exception
            object[] snap;
            lock (thisLock)
            {
                snap = manager.ShipObjects.ToArray();
            }
            foreach (CShipHlaObject ship in snap)
            {
                if (data.ObjectInstance.Handle == ship.Handle)// Find the Object
                {
                    manager.ShipObjects.Remove(ship);
                    Report($"Ship: {ship.Ship.Callsign} left. Number of Ships Now: {manager.ShipObjects.Count}" + Environment.NewLine);
                }
            }
            #endregion //User Code
        }
コード例 #6
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        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
        }
コード例 #7
0
ファイル: StationFdApp.cs プロジェクト: otopcu/STMS
        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
        }
コード例 #8
0
ファイル: StationFdApp.cs プロジェクト: otopcu/STMS
        public override void FdAmb_TurnUpdatesOffForObjectInstanceAdvisedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_TurnUpdatesOffForObjectInstanceAdvisedHandler(sender, data);

            #region User Code
            #endregion //User Code
        }
コード例 #9
0
ファイル: StationFdApp.cs プロジェクト: otopcu/STMS
        // Attribute Value Update is Requested
        public override void FdAmb_AttributeValueUpdateRequestedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_AttributeValueUpdateRequestedHandler(sender, data);

            #region User Code
            // !!! If this federate is created only one object instance, then it is sufficient to check the handle of that object, otherwise we need to check all the collection
            if (data.ObjectInstance.Handle == Program.StationObjects[0].Handle)
            {
                // We can update all attributes if we dont want to check every attribute.
                var timestamp = Time + Lookahead;
                UpdateStationAttributes(Program.StationObjects[0], timestamp);
            }
            #endregion //User Code
        }
コード例 #10
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        public override void FdAmb_TurnUpdatesOffForObjectInstanceAdvisedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_TurnUpdatesOffForObjectInstanceAdvisedHandler(sender, data);

            #region User Code
            // Stop to update the position
            manager.timer.Stop();
            #endregion //User Code
        }
コード例 #11
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        public override void FdAmb_TurnUpdatesOnForObjectInstanceAdvisedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_TurnUpdatesOnForObjectInstanceAdvisedHandler(sender, data);

            #region User Code
            // Start to update the position periodically
            manager.timer.Start(); // OpenRti does not support this callback
            #endregion             //User Code
        }
コード例 #12
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        // Reflect Object Attributes
        public override void FdAmb_ObjectAttributesReflectedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectAttributesReflectedHandler(sender, data);

            #region User Code
            foreach (var item in manager.StationObjects)
            {
                // Update station
                if (data.ObjectInstance.Handle == item.Handle)
                {
                    // Get parameter values - 2nd method
                    foreach (var pair in data.ObjectInstance.Attributes)
                    {
                        if (pair.Handle == Som.StationOC.StationName.Handle)
                        {
                            item.StationName = pair.GetValue <string>();
                        }
                        else if (pair.Handle == Som.StationOC.Location.Handle)
                        {
                            item.Location = pair.GetValue <LocationEnum>();
                        }
                    }
                }
            }
            foreach (var item in manager.ShipObjects)
            {
                // Update ship
                if (data.ObjectInstance.Handle == item.Handle)
                {
                    // Get parameter values - 1st method
                    // First check whether  the attr is updated or not. Result returns 0/null if the updated attribute set does not contain the attr and its value
                    if (data.IsValueUpdated(Som.ShipOC.Callsign))
                    {
                        item.Ship.Callsign = data.GetAttributeValue <string>(Som.ShipOC.Callsign);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Heading))
                    {
                        item.Ship.Heading = (LocationEnum)data.GetAttributeValue <uint>(Som.ShipOC.Heading);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Position))
                    {
                        item.Ship.Position = data.GetAttributeValue <PositionType>(Som.ShipOC.Position);
                    }
                    if (data.IsValueUpdated(Som.ShipOC.Speed))
                    {
                        item.Ship.Speed = (SpeedEnum)data.GetAttributeValue <uint>(Som.ShipOC.Speed);
                    }

                    // Get parameter values - 2nd method
                    //foreach (var pair in data.ObjectInstance.Attributes)
                    //{
                    //  if (pair.Handle == Som.ShipOC.Callsign.Handle) item.Local.Callsign = pair.GetValue<string>();
                    //  else if (pair.Handle == Som.ShipOC.Position.Handle) item.Local.Position = pair.GetValue<PositionType>();
                    //}

                    // report to the user
                    //Report($"Callsign: {item.Local.Callsign}, Heading: {item.Local.Heading.ToString()}, Position: ({item.Local.Position.X}, {item.Local.Position.Y}), Speed: {item.Local.Speed.ToString()}" + Environment.NewLine);
                }
            }
            #endregion //User Code
        }
コード例 #13
0
ファイル: ShipFdApp.cs プロジェクト: otopcu/STMS
        // Attribute Value Update is Requested
        public override void FdAmb_AttributeValueUpdateRequestedHandler(object sender, HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_AttributeValueUpdateRequestedHandler(sender, data);

            #region User Code
            // !!! If this federate is created only one object instance, then it is sufficient to check the handle of that object, otherwise we need to check all the collection
            if (data.ObjectInstance.Handle == manager.ShipObjects[0].Handle)
            {
                // We can further try to figure out the attributes for which update is requested.
                //foreach (var item in data.ObjectInstance.Attributes)
                //{
                //  if (item.Handle == Som.ShipOC.Callsign.Handle) UpdateName(manager.Ships[0]);
                //  else if (item.Handle == Som.ShipOC.Heading.Handle) UpdateHeading(manager.Ships[0]);
                //  else if (item.Handle == Som.ShipOC.Position.Handle) UpdatePosition(manager.Ships[0]);
                //  else if (item.Handle == Som.ShipOC.Speed.Handle) UpdateSpeed(manager.Ships[0]);
                //}

                // We can update all attributes if we dont want to check every attribute.
                UpdateAll(manager.ShipObjects[0]);
                //UpdateName(manager.Ships[0]);
                //UpdatePosition(manager.Ships[0]);
                //UpdateHeading(manager.Ships[0]);
                //UpdateSpeed(manager.Ships[0]);
            }
            #endregion //User Code
        }