Пример #1
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);
            }
        }
Пример #2
0
 private static void parseReceiverBeaconBody(ReceiverBeacon beacon, string body)
 {
     try
     {
         //beacon.SystemInfo = body.Substring(body.IndexOf(' ') + 1);
     }
     catch (Exception e)
     {
         throw new BeaconParserException("Error while parsing system info from receiver beacon packet.", body, e);
     }
 }