/// <summary>
        /// Call when new aircraft beacon detected.
        /// </summary>
        /// <param name="beacon">detected beacon</param>
        public void AddAircraftBeacon(AircraftBeacon beacon)
        {
            if (!aircraftBuffer.ContainsKey(beacon.AircraftAddress))
                aircraftBuffer.Add(beacon.AircraftAddress, new CircularFifoBuffer<AircraftBeaconSpeedAndTrack>(aircraftBuffersCapacity));

            aircraftBuffer[beacon.AircraftAddress].Enqueue(new AircraftBeaconSpeedAndTrack(beacon));
        }
Exemple #2
0
        public static Beacon ParseBeacon(string receivedLine)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(receivedLine))
                    throw new BeaconParserException("Received line empty!", receivedLine);

                Beacon beacon;

                receivedLine = receivedLine.Trim();

                if (!receivedLine.StartsWith("#"))
                {
                    var aprsMatches = matcherAPRSBaseRegex.Matches(receivedLine);

                    if (aprsMatches.Count != 2)
                        throw new BeaconParserException("APRS Base matcher failed.", receivedLine);
                    
                    string beaconType = aprsMatches[0].Groups[3].Value;

                    switch (beaconType)
                    {
                        case "qAS":
                            beacon = new AircraftBeacon();
                            break;

                        case "qAC":
                            beacon = new ReceiverBeacon();
                            break;

                        default:
                            throw new BeaconParserException($"Unknown package type {beaconType}", receivedLine);
                    }

                    ((IBaseAPRSBeacon)beacon).parseAPRSBaseData(aprsMatches[0].Groups);
                    ((IGeographicPositionAndDateTime)beacon).parseCoords(aprsMatches[1].Groups);
                    ((ConcreteBeacon)beacon).parseOgnConcreteBeacon(receivedLine);
                }
                else
                {
                    var comment = new InformationalComment();
                    comment.InformationalData = receivedLine;
                    beacon = comment;
                }

                beacon.ParsedDateTime = DateTimeOffset.Now;
                return beacon;
            }
            catch(BeaconParserException e)
            {
                throw e;
            }
            catch(Exception e)
            {
                throw new BeaconParserException("Unknown exception while parsing beacon.", receivedLine, e);
            }
        }
Exemple #3
0
 [InlineData(0x05DDE626, AircraftBeacon.AddressTypes.ICAO, AircraftBeacon.AircraftTypes.Glider, 0xDDE626, false, false)] // icao other address
 public void AircraftParserAddressDecoder(ulong id, AircraftBeacon.AddressTypes expectedAddressType, AircraftBeacon.AircraftTypes expectedAircraftType, uint expectedAddressValue, bool expectedStealthFlag, bool expectedNoTrackFlag)
 {
     var beacon = new AircraftBeacon { AircraftId = id };
     Assert.Equal(expectedAddressType, beacon.AddressType);
     Assert.Equal(expectedAircraftType, beacon.AircraftType);
     Assert.Equal(expectedAddressValue, beacon.AircraftAddress);
     Assert.Equal(expectedStealthFlag, beacon.StealthMode);
     Assert.Equal(expectedNoTrackFlag, beacon.NoTrackingFlag);
 }