Beispiel #1
0
        private void EvalTrack(object o, TracksFilteredEventArgs args)
        {
            if (args.FilteredTracks.Count != 0 && UpdatedTracksList.Count == 0)
            {
                foreach (var track in args.FilteredTracks)
                {
                    UpdatedTracksList.Add(track);
                    TrackEntered?.Invoke(this, new TrackEnteredAirspaceEventArgs(new Event(EventsList, "Track Entered Airspace", track, DateTime.Now)));
                }
            }

            else if (args.FilteredTracks.Count != 0 && UpdatedTracksList.Count != 0)
            {
                foreach (var filteredTrack in args.FilteredTracks)
                {
                    var updatedTrack = UpdatedTracksList.Find(i => i.Tag == filteredTrack.Tag);

                    if (updatedTrack == null)
                    {
                        UpdatedTracksList.Add(filteredTrack);
                        TrackEntered?.Invoke(this, new TrackEnteredAirspaceEventArgs(new Event(EventsList, "Track Entered Airspace", filteredTrack, DateTime.Now)));
                    }
                    else
                    {
                        var newCalEvent = new TrackStartCalEventArgs(
                            UpdatedTracksList[UpdatedTracksList.IndexOf(updatedTrack)],
                            filteredTrack);
                        TrackStartCal?.Invoke(this, newCalEvent);
                        if (newCalEvent.CalculatedTrack != null)
                        {
                            filteredTrack.Course   = newCalEvent.CalculatedTrack.Course;
                            filteredTrack.Velocity = newCalEvent.CalculatedTrack.Velocity;
                            UpdatedTracksList[UpdatedTracksList.IndexOf(updatedTrack)] = filteredTrack;
                        }

                        SeperationChecker?.Invoke(this, new SeperationCheckerEventArgs(EventsList, UpdatedTracksList, filteredTrack));
                    }
                }
            }
            args.UpdatedTracks = UpdatedTracksList;
            TracksUpdated?.Invoke(this, new TracksUpdatedEventArgs(UpdatedTracksList, EventsList));
        }
Beispiel #2
0
        public void DecodeTransData(object sender, RawTransponderDataEventArgs e)
        {
            OldTracks = new List <ITrack>(Tracks);
            Tracks.Clear();

            foreach (var transData in e.TransponderData)
            {
                string[] trackData = transData.Split(';');

                Track.Tag       = trackData[0];
                Track.X         = int.Parse(trackData[1]);
                Track.Y         = int.Parse(trackData[2]);
                Track.Altitude  = int.Parse(trackData[3]);
                Track.TimeStamp = Convert.ToDateTime(MakeDateTimeString(trackData[4]));
                Track.Velocity  = 0;
                Track.Course    = 0;


                if (IsInAirspace(Track))
                {
                    // If same track is registered from next TransponderReceiver data, Course and Velocity are calculated
                    if (OldTracks.Any(x => x.Tag == Track.Tag))
                    {
                        ITrack oldTrack = OldTracks.FirstOrDefault(x => x.Tag == Track.Tag);
                        Track.CalculateCourse(oldTrack, Track);
                        Track.CalculateVelocity(oldTrack, Track);
                    }

                    ITrack insertTrack = new Track()
                    {
                        Altitude  = Track.Altitude, Course = Track.Course, Tag = Track.Tag,
                        TimeStamp = Track.TimeStamp, Velocity = Track.Velocity, X = Track.X, Y = Track.Y
                    };

                    // Insert track in newest list of tracks
                    Tracks.Add(insertTrack);
                }
            }
            foreach (var track in Tracks)
            {
                if (!OldTracks.Any(x => x.Tag == track.Tag))
                {
                    TrackEntered?.Invoke(track);
                    Writer.Write("Track entered airspace! Time: " + DateTime.Now.ToShortTimeString() + " Tag: " + track.Tag);
                }
            }

            foreach (var track in OldTracks)
            {
                if (!Tracks.Any(x => x.Tag == track.Tag))
                {
                    TrackLeaving?.Invoke(track);
                    Writer.Write("Track leaving airspace! Time: " + DateTime.Now.ToShortTimeString() + " Tag: " + track.Tag);
                }
            }
            //PrintToConsole(Tracks);

            // Print to GUI
            OnTracksReady?.Invoke(Tracks);

            // Check if any two tracks are colliding form list of tracks
            CollisionDetector.DetectCollision(Tracks);
        }