Esempio n. 1
0
        public void Aircraft_UpdateCoordinates_Adds_Coordinate_To_Full_And_Short_Trails()
        {
            var now = DateTime.UtcNow;

            _Aircraft.DataVersion = now.Ticks + 1;
            _Aircraft.Latitude    = 10;
            _Aircraft.Longitude   = 20;
            _Aircraft.Track       = 30;
            _Aircraft.UpdateCoordinates(now, 30);

            Assert.AreEqual(1, _Aircraft.FullCoordinates.Count);
            Assert.AreEqual(1, _Aircraft.ShortCoordinates.Count);

            var fullCoordinate = _Aircraft.FullCoordinates[0];

            Assert.AreEqual(10f, fullCoordinate.Latitude);
            Assert.AreEqual(20f, fullCoordinate.Longitude);
            Assert.AreEqual(30f, fullCoordinate.Heading);
            Assert.AreEqual(now.Ticks + 1, fullCoordinate.DataVersion);
            Assert.AreEqual(now.Ticks, fullCoordinate.Tick);

            var shortCoordinate = _Aircraft.ShortCoordinates[0];

            Assert.AreEqual(10f, shortCoordinate.Latitude);
            Assert.AreEqual(20f, shortCoordinate.Longitude);
            Assert.AreEqual(30f, shortCoordinate.Heading);
            Assert.AreEqual(now.Ticks + 1, shortCoordinate.DataVersion);
            Assert.AreEqual(now.Ticks, shortCoordinate.Tick);
        }
        private void ApplyMessageToAircraft(BaseStationMessage message, IAircraft aircraft, bool isNewAircraft)
        {
            // We want to retrieve all of the lookups without writing anything to the aircraft. Then all of the values
            // that need changing on the aircraft will be set in one lock with one DataVersion so they're all consistent.

            CodeBlock codeBlock = null;
            Route route = null;

            if(isNewAircraft) codeBlock = StandingDataManager.FindCodeBlock(message.Icao24);

            bool callsignChanged;
            string operatorIcao;
            lock(aircraft) {  // <-- nothing should be changing Callsign, we're the only thread that writes it, but just in case...
                callsignChanged = !String.IsNullOrEmpty(message.Callsign) && message.Callsign != aircraft.Callsign;
                operatorIcao = aircraft.OperatorIcao;
            }
            if(callsignChanged) route = LookupRoute(message.Callsign, operatorIcao);

            var track = CalculateTrack(message, aircraft);

            lock(aircraft) {
                var now = Provider.UtcNow;
                GenerateDataVersion(aircraft);

                aircraft.LastUpdate = now;
                ++aircraft.CountMessagesReceived;
                if(isNewAircraft) aircraft.FirstSeen = now;
                if(aircraft.Icao24 == null) aircraft.Icao24 = message.Icao24;

                if(!String.IsNullOrEmpty(message.Callsign)) aircraft.Callsign = message.Callsign;
                if(message.Altitude != null) aircraft.Altitude = message.Altitude;
                if(message.GroundSpeed != null) aircraft.GroundSpeed = message.GroundSpeed;
                if(track != null) aircraft.Track = track;
                if(message.Track != null && message.Track != 0.0) aircraft.IsTransmittingTrack = true;
                if(message.Latitude != null) aircraft.Latitude = message.Latitude;
                if(message.Longitude != null) aircraft.Longitude = message.Longitude;
                if(message.VerticalRate != null) aircraft.VerticalRate = message.VerticalRate;
                if(message.OnGround != null) aircraft.OnGround = message.OnGround;
                if(message.Squawk != null) {
                    aircraft.Squawk = message.Squawk;
                    aircraft.Emergency = message.Squawk == 7500 || message.Squawk == 7600 || message.Squawk == 7700;
                }

                var supplementaryMessage = message != null && message.Supplementary != null ? message.Supplementary : null;
                if(supplementaryMessage != null) {
                    if(supplementaryMessage.SpeedType != null) aircraft.SpeedType = supplementaryMessage.SpeedType.Value;
                    if(supplementaryMessage.CallsignIsSuspect != null) aircraft.CallsignIsSuspect = supplementaryMessage.CallsignIsSuspect.Value;
                }

                ApplyCodeBlock(aircraft, codeBlock);
                ApplyRoute(aircraft, route);

                if(message.Latitude != null && message.Longitude != null) aircraft.UpdateCoordinates(now, _ShortTrailLengthSeconds);
            }

            if(isNewAircraft) _DatabaseLookupQueue.Enqueue(new DatabaseLookup(aircraft, true, true));
        }