Пример #1
0
        private string DecodeVelocityOverGroundMsg(ModeSReply msg, DateTime timestamp)
        {
            VelocityOverGroundMsg velocity = (VelocityOverGroundMsg)msg;

            if (msg.ICAO24 == null)
            {
                return("VelocityOverGroundMsg: No ICAO24 found.");
            }
            string icao24 = BitConverter.ToString(msg.ICAO24).Replace("-", String.Empty);
            // check if ICAO is already stored in lookup table
            ADSBInfo info = null;

            if (!adsbinfos.TryGetValue(icao24, out info))
            {
                // no --> add new entry
                info        = new ADSBInfo();
                info.ICAO24 = icao24;
                adsbinfos.Add(icao24, info);
            }
            // add information
            if (velocity.HasValidVelocity)
            {
                info.Speed = velocity.Velocity;
            }
            if (velocity.HasValidHeading)
            {
                info.Heading = velocity.Heading;
            }
            return("[" + info.ICAO24 + "] VelocityOverGroundMsg: Speed=" + info.Speed.ToString() + ", Heading= " + info.Heading.ToString());
        }
Пример #2
0
        private string DecodeIdentificationMsg(ModeSReply msg, DateTime timestamp)
        {
            IdentificationMsg ident = (IdentificationMsg)msg;

            if (msg.ICAO24 == null)
            {
                return("IdentifyMsg: No ICAO24 found.");
            }
            string icao24 = BitConverter.ToString(msg.ICAO24).Replace("-", String.Empty);
            // check if ICAO is already stored in lookup table
            ADSBInfo info = null;

            if (!adsbinfos.TryGetValue(icao24, out info))
            {
                // no --> add new entry
                info        = new ADSBInfo();
                info.ICAO24 = icao24;
                adsbinfos.Add(icao24, info);
            }
            // add call sign
            info.Call = ident.getIdentity();
            return("[" + info.ICAO24 + "] IdentificationMsg: Call=" + info.Call);
        }
Пример #3
0
        private string DecodeAirbornePositionMsg(ModeSReply msg, DateTime timestamp)
        {
            // Airborne position message --> we need subsequent messages to decode
            AirbornePositionMsg pos = (AirbornePositionMsg)msg;

            if (msg.ICAO24 == null)
            {
                return("AirbornePositionMsg: No ICAO24 found.");
            }
            string icao24 = BitConverter.ToString(msg.ICAO24).Replace("-", String.Empty);
            // check if ICAO is already stored in lookup table
            ADSBInfo info = null;

            if (!adsbinfos.TryGetValue(icao24, out info))
            {
                // no --> add new entry
                info        = new ADSBInfo();
                info.ICAO24 = icao24;
                adsbinfos.Add(icao24, info);
            }
            // adsbinfo found --> update information and calculate position
            // contains valid position?
            if (!pos.HasValidPosition)
            {
                // no --> return error meesage
                return("[" + info.ICAO24 + "] AirbornePositionMsg: No valid position found.");
            }
            info.ICAO24         = icao24;
            info.NICSupplementA = pos.NICSupplementA;
            // position calculated before
            if (!double.IsNaN(info.Lat) & !double.IsNaN(info.Lon))
            {
                try
                {
                    // use local CPR
                    double[] localpos = pos.getLocalPosition(info.Lat, info.Lon);
                    // we have a pos --> store in info and update timestamp
                    info.Lat = localpos[0];
                    info.Lon = localpos[1];
                    if (pos.HasValidAltitude)
                    {
                        info.Alt = pos.Altitude;
                    }
                    info.Timestamp = timestamp;
                    return("[" + info.ICAO24 + "] AirbornePositionMsg: Lat= " + info.Lat.ToString("F8") + ", Lon=" + info.Lon.ToString("F8") + ", Alt= " + info.Alt.ToString() + ", Time= " + info.Timestamp.ToString("HH:mm:ss.fff"));
                }
                catch (Exception ex)
                {
                }
            }
            // no position calculated before
            if (pos.IsOddFormat)
            {
                try
                {
                    // odd message
                    info.LastOddAirborne  = pos;
                    info.LastOddTimestamp = DateTime.UtcNow;
                    // check if even message was received before and not older than 10secs--> calculate global CPR
                    if ((info.LastEvenAirborne != null) && ((info.LastOddTimestamp - info.LastOddTimestamp).TotalSeconds <= 10))
                    {
                        try
                        {
                            double[] globalpos = pos.getGlobalPosition(info.LastEvenAirborne);
                            // we have a position --> store in info and update timestamp
                            info.Lat = globalpos[0];
                            info.Lon = globalpos[1];
                            if (pos.HasValidAltitude)
                            {
                                info.Alt = pos.Altitude;
                            }
                            //                        info.Timestamp = timestamp;
                            return("[" + info.ICAO24 + "] AirbornePositionMsg: Lat= " + info.Lat.ToString("F8") + ", Lon=" + info.Lon.ToString("F8") + ", Alt= " + info.Alt.ToString() + ", Time= " + info.Timestamp.ToString("HH:mm:ss.fff"));
                        }
                        catch
                        {
                            return("[" + info.ICAO24 + "] AirbornePositionMsg: Error while decoding position");
                        }
                    }
                    return("[" + info.ICAO24 + "] AirbornePositionMsg: No decoding possible yet");
                }
                catch (Exception ex)
                {
                }
            }
            // even message
            info.LastEvenAirborne  = pos;
            info.LastEvenTimestamp = DateTime.UtcNow;
            // check if odd message was received before and not older than 10secs --> calculate global CPR
            if ((info.LastOddAirborne != null) && ((info.LastEvenTimestamp - info.LastOddTimestamp).TotalSeconds <= 10))
            {
                try
                {
                    double[] globalpos = pos.getGlobalPosition(info.LastOddAirborne);
                    // we have a position --> store in info and update timestamp
                    info.Lat = globalpos[0];
                    info.Lon = globalpos[1];
                    if (pos.HasValidAltitude)
                    {
                        info.Alt = pos.Altitude;
                    }
//                    info.Timestamp = timestamp;
                    return("[" + info.ICAO24 + "] AirbornePositionMsg: Lat= " + info.Lat.ToString("F8") + ", Lon=" + info.Lon.ToString("F8") + ", Alt= " + info.Alt.ToString() + ", Time= " + info.Timestamp.ToString("HH:mm:ss.fff"));
                }
                catch
                {
                    return("[" + info.ICAO24 + "] AirbornePositionMsg: Error while decoding position");
                }
            }
            else
            {
                return("[" + info.ICAO24 + "] AirbornePositionMsg:No decoding possible yet");
            }
        }