Beispiel #1
0
        public void ReceiverOnTransponderDataReady(object sender, RawTransponderDataEventArgs e)
        {
            foreach (var data in e.TransponderData)
            {
                List <string> TrackList = data.Split(';').ToList <string>();

                TrackData t = new TrackData(TrackList[0], double.Parse(TrackList[1]), double.Parse(TrackList[2]),
                                            double.Parse(TrackList[3]), TrackList[4], 0, 0, _output);

                foreach (IObserver observer in _observers)
                {
                    observer.Update(t);
                }
            }
        }
Beispiel #2
0
        public void HandleNewTrackData(TrackData trackdata)
        {
            TrackData trackToEdit = _currentTracks.Find(x => x._Tag == trackdata._Tag);

            trackToEdit._CurrentXcord   = trackdata._CurrentXcord;
            trackToEdit._CurrentYcord   = trackdata._CurrentYcord;
            trackToEdit._CurrentZcord   = trackdata._CurrentZcord;
            trackToEdit._CurrentCourse  = trackdata._CurrentCourse;
            trackToEdit._CurrentHorzVel = trackToEdit._CurrentHorzVel;

            if (_currentTracks.Exists(x => x._Tag == trackdata._Tag))
            {
                AddTrack(trackdata);
            }
        }
Beispiel #3
0
 public void AddTrack(TrackData trackData)
 {
     //Check if TrackData with given tag already exists.
     if (_currentTracks.Exists(x => x._Tag == trackData._Tag))
     {
         //Find index of existing data.
         int index = _currentTracks.FindIndex(x => x._Tag == trackData._Tag);
         //replace existing data with new data.
         _currentTracks[index] = trackData;
     }
     else
     {
         //Add trackData.
         _currentTracks.Add(trackData);
     }
 }
Beispiel #4
0
        public void LogInactiveSeparationEvent(SeperationEvent seperationEvent)
        {
            string    timeOfOccurence = seperationEvent._OccurrenceTime.ToString();
            TrackData track1          = seperationEvent._InvolvedTracks[0];
            TrackData track2          = seperationEvent._InvolvedTracks[1];

            //Creating instance of StreamWriter
            System.IO.StreamWriter streamWriter = System.IO.File.AppendText(startupPath + fileName);

            string lineToLog = "Timestamp: " + timeOfOccurence + "  " + "Flight 1: " + track1._Tag + " | " + "Flight 2: " + track2._Tag + " | " + "SeperationEvent status: " + seperationEventInactive;

            //Perhaps it should be WriteLineAsync in order to keep up with the system
            streamWriter.Write(lineToLog);

            //Closing streamWriter instance and file
            streamWriter.Close();
        }
Beispiel #5
0
        public void HandleNewTrackData(TrackData trackdata)
        {
            //Check if no track data with given tag exists.
            if (_currentTracks.Exists(x => x._Tag == trackdata._Tag) == false)
            {
                // Add the new track if coordinates are inside the given boundaries of the airspace.
                if (_airspace.CheckIfInMonitoredArea(trackdata._CurrentXcord, trackdata._CurrentYcord,
                                                     trackdata._CurrentZcord))
                {
                    AddTrack(trackdata);
                }
            }
            else
            {
                // Update trackdata
                TrackData trackToEdit = _currentTracks.Find(x => x._Tag == trackdata._Tag);
                trackToEdit._CurrentXcord   = trackdata._CurrentXcord;
                trackToEdit._CurrentYcord   = trackdata._CurrentYcord;
                trackToEdit._CurrentZcord   = trackdata._CurrentZcord;
                trackToEdit._CurrentCourse  = trackdata._CurrentCourse;
                trackToEdit._CurrentHorzVel = trackToEdit._CurrentHorzVel;

                // Remove tracks if out of airspace

                if (!(_airspace.CheckIfInMonitoredArea(trackToEdit._CurrentXcord, trackToEdit._CurrentYcord,
                                                       trackToEdit._CurrentZcord)))
                {
                    RemoveTrack(trackToEdit._Tag);
                }
                // Check for potential seperation events
                CheckForSeperationEvents(trackToEdit);
            }

            // Check for potential seperation events
            CheckForSeperationEvents(trackdata);


            // Remove separations event after update
            RemoveSeparationEvents();

            // Render updated tracks to console
            RenderTracks();

            // Render seperation events
            RenderSeperationEvents();
        }
        public double CalculateTrackSpeed(TrackData newData, TrackData oldData)
        {
            //Check that the tags for the supplied data match
            if (!(newData.Tag.Equals(oldData.Tag)))
            {
                throw new System.ArgumentException("Tags for the supplied TrackData-objects do not match.");
            }

            //Get X, Y and Z for old data and new data
            double old_x = oldData.CurrentXcord;
            double new_x = newData.CurrentXcord;

            double old_y = oldData.CurrentYcord;
            double new_y = newData.CurrentYcord;

            //Get difference in X, Y and Z
            double dx = Math.Abs(old_x - new_x);
            double dy = Math.Abs(old_y - new_y);

            //Calculate distance traveled
            double Distance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
            //Get the timestamps as strings
            string oldTime = oldData.TimeStamp;
            string newTime = newData.TimeStamp;

            //Format timestamps to DateTime
            string   formatString = "yyyyMMddHHmmssfff";
            DateTime oldDateTime  = DateTime.ParseExact(oldTime, formatString, null);
            DateTime newDateTime  = DateTime.ParseExact(newTime, formatString, null);

            //Check that the new data is actually newer than the old data
            if (oldDateTime > newDateTime)
            {
                throw new System.ArgumentException("Timestamp of new data is older than Timestamp of old data");
            }

            //Get difference in DateTimes
            TimeSpan dt_TimeSpan = newDateTime - oldDateTime;
            int      dt_ms       = Math.Abs(dt_TimeSpan.Minutes * 1000 * 60) + Math.Abs(dt_TimeSpan.Seconds * 1000) + Math.Abs(dt_TimeSpan.Milliseconds);


            //Calculate speed in m/s
            double speed = Distance / dt_ms * 1000;

            return(speed);
        }
Beispiel #7
0
        public bool CheckIfSeperationEventExistsFor(TrackData trackData1, TrackData trackData2)
        {
            if (_currentSeperationEvents.Exists(x => x._InvolvedTracks[1]._Tag == trackData1._Tag &&
                                                x._InvolvedTracks[0]._Tag == trackData2._Tag))
            {
                return(true);
            }

            else if (_currentSeperationEvents.Exists(x => x._InvolvedTracks[1]._Tag == trackData2._Tag &&
                                                     x._InvolvedTracks[0]._Tag == trackData1._Tag))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public void CheckForSeperationEvents(TrackData trackData)
 {
     foreach (var track in CurrentTracks)
     {
         if (trackData != null && track.Tag != trackData.Tag)
         {
             if (CheckForSeperationEventConditions(trackData, track) == true)
             {
                 //If seperation event does not exist yet, create it and add it to currentSeperationEvents
                 //Check if separation event already exists
                 if (!CurrentEvents.CheckIfSeperationEventExistsFor(trackData, track))
                 {
                     // Add new separation event
                     CurrentEvents.AddSeperationEventFor(trackData, track, _outputFile);
                 }
             }
         }
     }
 }
        public void UpdateTrackData(TrackData trackData)
        {
            // Update trackdata
            TrackData trackToEdit = CurrentTracks.Find(x => x.Tag == trackData.Tag);

            trackToEdit.CurrentHorzVel = CalculateTrackSpeed(trackData, trackToEdit);
            trackToEdit.CurrentCourse  = CalculateTrackCourse(trackData, trackToEdit);
            trackToEdit.CurrentXcord   = trackData.CurrentXcord;
            trackToEdit.CurrentYcord   = trackData.CurrentYcord;
            trackToEdit.CurrentZcord   = trackData.CurrentZcord;
            trackToEdit.CurrentHorzVel = trackToEdit.CurrentHorzVel;
            trackToEdit.TimeStamp      = trackData.TimeStamp;

            //Replace old object with new object
            int index = CurrentTracks.FindIndex(x => x.Tag == trackData.Tag);

            CurrentTracks.RemoveAt(index);
            CurrentTracks.Insert(index, trackToEdit);
        }
Beispiel #10
0
        public TrackData ConvertData(string data) //parsing
        {
            TrackData track = new TrackData();


            var words = data.Split(';');

            track.Tag       = words[0];
            track.X         = int.Parse(words[1]);
            track.Y         = int.Parse(words[2]);
            track.Altitude  = int.Parse(words[3]);
            track.TimeStamp = DateTime.ParseExact(words[4], "yyyyMMddHHmmssfff",
                                                  System.Globalization.CultureInfo.InvariantCulture);
            track.Course   = 0;
            track.Velocity = 0;



            return(track);
        }
        public bool CheckIfSeperationEventExistsFor(TrackData trackData1, TrackData trackData2)
        {
            foreach (FlightEvent e in events)
            {
                if (e is SeperationEvent)
                {
                    if ((e.InvolvedTracks[0].Tag == trackData1.Tag) && (e.InvolvedTracks[1].Tag == trackData2.Tag))
                    {
                        return(true);
                    }
                    if ((e.InvolvedTracks[1].Tag == trackData1.Tag) && (e.InvolvedTracks[0].Tag == trackData2.Tag))
                    {
                        return(true);
                    }
                }
            }

            return(false);

            /*
             * if (events == null)
             * {
             *  return false;
             * }
             * if (events.Exists(x => x is SeperationEvent && x._InvolvedTracks[1]._Tag == trackData1._Tag &&
             *                                       x._InvolvedTracks[0]._Tag == trackData2._Tag))
             * {
             *  return true;
             * }
             *
             * else if (events.Exists(x => x is SeperationEvent && x._InvolvedTracks[1]._Tag == trackData2._Tag &&
             *                                            x._InvolvedTracks[0]._Tag == trackData1._Tag))
             * {
             *  return true;
             * }
             * else
             * {
             *  return false;
             * }*/
        }
        public double CalculateTrackCourse(TrackData newData, TrackData oldData)
        {
            //Check that the tags for the supplied data match
            if (!(newData.Tag.Equals(oldData.Tag)))
            {
                throw new System.ArgumentException("Tags for the supplied TrackData-objects do not match.");
            }

            //Check that the new data is actually newer than the old data
            //Get the timestamps as strings
            string oldTime = oldData.TimeStamp;
            string newTime = newData.TimeStamp;

            //Format timestamps to DateTime
            string   formatString = "yyyyMMddHHmmssfff";
            DateTime oldDateTime  = DateTime.ParseExact(oldTime, formatString, null);
            DateTime newDateTime  = DateTime.ParseExact(newTime, formatString, null);


            if (oldDateTime > newDateTime)
            {
                throw new System.ArgumentException("Timestamp of new data is older than Timestamp of old data");
            }

            //Get X and Y for old data and new data
            double old_x = oldData.CurrentXcord;
            double new_x = newData.CurrentXcord;

            double old_y = oldData.CurrentYcord;
            double new_y = newData.CurrentYcord;

            //Get difference in X and Y
            double dx = new_x - old_x;
            double dy = new_y - old_y;

            //Calculate angle in degrees
            double Angle = Math.Atan2(dy, dx) * (180 / Math.PI);

            return(Angle);
        }
Beispiel #13
0
        public bool CheckForSeperationEvent(TrackData trackData1, TrackData trackData2)
        {
            //Check if both tracks are the same
            if (trackData1._Tag == trackData2._Tag)
            {
                throw new Exception("Provided TrackDatas have the same Tag");
            }
            else
            {
                if (Math.Abs(trackData1._CurrentXcord - trackData2._CurrentXcord) < 5000 &&
                    Math.Abs(trackData1._CurrentYcord - trackData2._CurrentYcord) < 5000 &&
                    Math.Abs(trackData1._CurrentZcord - trackData2._CurrentZcord) < 300)
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }
        }
Beispiel #14
0
        public bool CheckForSeperationEvent(TrackData trackData1, TrackData trackData2)
        {
            //Check if both tracks are the same
            if (trackData1._Tag == trackData2._Tag)
            {
                throw new Exception("Provided TrackDatas have the same Tag");
            }
            else
            {
                //Check if conditions are met with the given TrackData-objects
                if (Math.Abs(trackData1._CurrentXcord - trackData2._CurrentXcord) < MIN_X_DISTANCE &&
                    Math.Abs(trackData1._CurrentYcord - trackData2._CurrentYcord) < MIN_Y_DISTANCE &&
                    Math.Abs(trackData1._CurrentZcord - trackData2._CurrentZcord) < MIN_Z_DISTANCE)
                {
                    //If seperation event does not exist yet, create it and add it to currentSeperationEvents
                    //Check if separation event already exists
                    if (!CheckIfSeperationEventExistsFor(trackData1, trackData2))
                    {
                        // Add new separation event
                        //string time = DateTime.Now.ToString();
                        string           time = trackData1._TimeStamp;
                        List <TrackData> trackDataInSeperationEvent = new List <TrackData>();
                        trackDataInSeperationEvent.Add(trackData1);
                        trackDataInSeperationEvent.Add(trackData2);

                        SeperationEvent SeperationEvent = new SeperationEvent(time, trackDataInSeperationEvent, true);
                        _currentSeperationEvents.Add(SeperationEvent);
                        _logger.LogActiveSeparationEvent(SeperationEvent);
                    }

                    return(true);
                }

                else
                {
                    return(false);
                }
            }
        }
        public bool CheckForSeperationEventConditions(TrackData trackData1, TrackData trackData2)
        {
            //Check if both tracks are the same
            if (trackData1.Tag == trackData2.Tag)
            {
                throw new Exception("Provided TrackDatas have the same Tag");
            }
            else
            {
                //Check if conditions are met with the given TrackData-objects
                if (Math.Abs(trackData1.CurrentXcord - trackData2.CurrentXcord) < MIN_X_DISTANCE &&
                    Math.Abs(trackData1.CurrentYcord - trackData2.CurrentYcord) < MIN_Y_DISTANCE &&
                    Math.Abs(trackData1.CurrentZcord - trackData2.CurrentZcord) < MIN_Z_DISTANCE)
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }
        }
Beispiel #16
0
        private TrackData decodeTrack(string trackString)
        {
            var parameters = trackString.Split(';');

            string tag             = parameters[0];
            int    x               = Int32.Parse(parameters[1]);
            int    y               = Int32.Parse(parameters[2]);
            int    altitude        = Int32.Parse(parameters[3]);
            string timestampString = parameters[4];


            DateTime timestamp = new DateTime(
                year: Int32.Parse(timestampString.Substring(0, 4)),
                month: Int32.Parse(timestampString.Substring(4, 2)),
                day: Int32.Parse(timestampString.Substring(6, 2)),
                hour: Int32.Parse(timestampString.Substring(8, 2)),
                minute: Int32.Parse(timestampString.Substring(10, 2)),
                second: Int32.Parse(timestampString.Substring(12, 2)),
                millisecond: Int32.Parse(timestampString.Substring(14, 3)));

            TrackData trackData = new TrackData(tag, x, y, altitude, timestamp);

            return(trackData);
        }
        public void HandleNewTrackData(TrackData trackdata)
        {
            //Check if no track data with given tag exists.
            if (CurrentTracks.Exists(x => x.Tag == trackdata.Tag) == false)
            {
                // Add the new track if coordinates are inside the given boundaries of the airspace.
                if (_airspace.CheckIfInMonitoredArea(trackdata.CurrentXcord, trackdata.CurrentYcord,
                                                     trackdata.CurrentZcord))
                {
                    AddTrack(trackdata);
                    //string time = trackdata._TimeStamp;
                    //TrackEnteredEvent TrackEnteredEvent = new TrackEnteredEvent(time, trackdata, true, _outputConsole, _outputFile);
                    CurrentEvents.AddTrackEnteredEventFor(trackdata, _outputFile);
                }
            }
            else
            {
                //Update trackdata
                UpdateTrackData(trackdata);

                // Remove tracks if out of airspace
                CheckIfTrackdataIsStillInAirspace(trackdata);

                // Check for potential seperation events
                CheckForSeperationEvents(trackdata);
            }

            //Remove all events that are not relevant anymore
            CurrentEvents.cleanUpEvents();

            // Check for potential seperation events
            CheckForSeperationEvents(trackdata);

            // Update status of flightEvents' _isRaised-attribute.
            UpdateSeperationEventStatus();
        }
Beispiel #18
0
 public IEnumerable <SeperationEvent> GetSeperationEventInvolvedIn(TrackData trackData)
 {
     return(_currentSeperationEvents.Where(x => x._InvolvedTracks[0]._Tag == trackData._Tag ||
                                           x._InvolvedTracks[1]._Tag == trackData._Tag));
 }
        private String GenerateCollisionString(TrackData track1, TrackData track2)
        {
            string appendText = "Time of occurrence: " + track1.Timestamp + ", Tags: " + track1.Tag + ", " + track2.Tag + Environment.NewLine;

            return(appendText);
        }
Beispiel #20
0
 public void Update(TrackData trackdata)
 {
     HandleNewTrackData(trackdata);
 }
Beispiel #21
0
 public FlightData(TrackData trackData)
 {
     CurrentTrackData = trackData;
     CollisionFlag    = false;
 }
Beispiel #22
0
        public double CalculateDirection(TrackData prevData, TrackData currData)
        {
            double directionInRadians = Math.Atan2(currData.X - prevData.X, currData.Y - prevData.Y);

            return(RadiansToDegrees(directionInRadians));
        }