Пример #1
0
        public FlightRadarData(FlightRadarData oldfd, PointLatLng point, DateTime time)
        {
            //copy from old data
            this.Id             = oldfd.Id;
            this.lastPoint      = oldfd.point;
            this.bearing        = oldfd.bearing;
            this.altitude       = oldfd.altitude;
            this.speed          = oldfd.speed;
            this.identification = oldfd.identification;

            /*
             * this.startTime = oldfd.startTime;
             * this.lastTime = oldfd.lastTime;
             * this.initialType = oldfd.initialType;
             * this.aircraftType = oldfd.aircraftType;
             * this.cumulativeRange = oldfd.cumulativeRange;
             * this.averageDirection = oldfd.averageDirection;
             * this.maxSpeed = oldfd.maxSpeed;
             * this.maxAltitude = oldfd.maxAltitude;
             * this.transactionId = oldfd.transactionId;
             */
            //function data
            this.auto = oldfd.auto;
            //set new data
            this.point = point;
            this.time  = time;
        }
Пример #2
0
 public static void InsertOrUpdate(Dictionary <int, FlightRadarData> map, int key, FlightRadarData value)
 {
     if (map.ContainsKey(key))
     {
         map[key] = value;
     }
     else
     {
         map.Add(key, value);
     }
 }
Пример #3
0
 public void ChangeFlightData(TrackType type, int index, FlightRadarData tempfd)
 {
     if (type == TrackType.Real)
     {
         realTrack[index] = tempfd;
     }
     else if (type == TrackType.Faker)
     {
         fakerTrack[index] = tempfd;
     }
 }
Пример #4
0
 public char getStatus(int id)
 {
     if (ContainsTrack(id))
     {
         FlightRadarData fd = GetAll(id);
         return(statusTracks.ContainsKey(id) ? statusTracks[id] : fd.identification);
     }
     else
     {
         return('\0');
     }
 }
Пример #5
0
        public void Load()
        {
            if (DataSettings.UseDatabase)
            {
                Dictionary <string, dynamic> connDat = DataSettings.Connection;
                string          connStr = string.Format("host={0};user={1};password={2};database={3};Convert Zero Datetime=True;", connDat["Host"], connDat["Username"], connDat["Password"], connDat["Database"]);
                MySqlConnection conn    = new MySqlConnection(connStr);
                conn.Open();
                using (MySqlCommand cmd = new MySqlCommand(null, conn))
                {
                    //faker
                    cmd.CommandText = "SELECT * FROM faker_track";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int    id    = reader.GetInt32("tk_id");
                            char   iff   = reader.GetChar("tk_iff");
                            double lat   = reader.GetDouble("tk_lat");
                            double lng   = reader.GetDouble("tk_lng");
                            double dir   = reader.GetDouble("tk_dir");
                            double speed = reader.GetDouble("tk_speed");
                            bool   auto  = reader.GetBoolean("tk_auto");

                            FlightRadarData fd = new FlightRadarData(TrackType.Faker);
                            fd.Id             = id;
                            fd.identification = iff;
                            fd.point          = new GMap.NET.PointLatLng(lat, lng);
                            fd.bearing        = dir;
                            fd.speed          = speed;
                            fd.altitude       = 0;
                            fd.auto           = auto;

                            /*
                             * fd.cumulativeRange = range_sum;
                             * fd.maxSpeed = speed_max;
                             * fd.maxAltitude = altitude_max;
                             * fd.startTime = ftime;
                             * fd.lastTime = ltime;
                             * fd.transactionId = transaction_id;
                             *
                             * fd.auto = type_srce == 1 ? true : false;
                             */
                            AddFaker(fd);
                        }
                    }
                }
                conn.Close();
            }
        }
Пример #6
0
 public void Save()
 {
     if (DataSettings.UseDatabase)
     {
         int             mission_id = Mission.GetMissionId();
         MySqlConnection conn       = DataSettings.GetConnection();
         using (MySqlCommand cmd = new MySqlCommand(null, conn)) {
             //Store real data
             Dictionary <int, FlightRadarData> CloneReal = new Dictionary <int, FlightRadarData>(realTrack);
             foreach (int id in CloneReal.Keys)
             {
                 FlightRadarData fd = CloneReal[id];
                 cmd.CommandText = "INSERT INTO real_track VALUES (@id, @name, @iff, @lat, @lng, @dir, @speed, @mission) " +
                                   "ON DUPLICATE KEY UPDATE tk_name = @name, tk_iff = @iff, tk_lat = @lat, tk_lng = @lng, tk_dir = @dir, tk_speed = @speed";
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("id", fd.Id);
                 cmd.Parameters.AddWithValue("name", fd.name);
                 cmd.Parameters.AddWithValue("iff", fd.identification);
                 cmd.Parameters.AddWithValue("lat", fd.point.Lat);
                 cmd.Parameters.AddWithValue("lng", fd.point.Lng);
                 cmd.Parameters.AddWithValue("dir", fd.bearing);
                 cmd.Parameters.AddWithValue("speed", fd.speed);
                 cmd.Parameters.AddWithValue("mission", mission_id);
                 cmd.ExecuteNonQuery();
             }
             //Store faker data
             Dictionary <int, FlightRadarData> CloneFaker = new Dictionary <int, FlightRadarData>(fakerTrack);
             foreach (int id in CloneFaker.Keys)
             {
                 FlightRadarData fd = CloneFaker[id];
                 cmd.CommandText = "INSERT INTO faker_track VALUES (@id, @name, @iff, @lat, @lng, @dir, @speed, @auto, @mission) " +
                                   "ON DUPLICATE KEY UPDATE tk_name = @name, tk_iff = @iff, tk_lat = @lat, tk_lng = @lng, tk_dir = @dir, tk_speed = @speed, tk_auto = @auto";
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("id", fd.Id);
                 cmd.Parameters.AddWithValue("name", fd.name);
                 cmd.Parameters.AddWithValue("iff", fd.identification);
                 cmd.Parameters.AddWithValue("lat", fd.point.Lat);
                 cmd.Parameters.AddWithValue("lng", fd.point.Lng);
                 cmd.Parameters.AddWithValue("dir", fd.bearing);
                 cmd.Parameters.AddWithValue("speed", fd.speed);
                 cmd.Parameters.AddWithValue("auto", fd.auto);
                 cmd.Parameters.AddWithValue("mission", mission_id);
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
        public static void testDoWork()
        {
            /*
             * for (int i = 0; i < flightSimulation.Count; i++)
             * {
             *  FlightRadarData fd = flightSimulation[i];
             *  if (fd.auto)
             *  {
             *      DateTime now = DateTime.Now;
             *      double intervalSecond = (fd.time != null) ? now.Subtract(fd.time.Value).TotalMilliseconds / 1000 : 0;
             *      double distance = getDistanceFrom(ScaleConverter.ConvertSpeed(fd.speed, "kts", "km/h"), intervalSecond);
             *      PointLatLng p = FindPointAtDistanceFrom(fd.point, DegreesToRadians(fd.bearing), distance);
             *      FlightRadarData tempfd = new FlightRadarData(fd, p, now);
             *      flightSimulation[i] = tempfd;
             *  }
             * }
             */
            Track track = Track.GetInstance();

            foreach (int faker in track.Fakers)
            {
                FlightRadarData fd = track.GetFaker(faker);
                if (fd.auto)
                {
                    DateTime    now            = DateTime.Now;
                    double      intervalSecond = (fd.time != null) ? now.Subtract(fd.time.Value).TotalMilliseconds / 1000 : 0;
                    double      distance       = getDistanceFrom(ScaleConverter.ConvertSpeed(fd.speed, "kts", "km/h"), intervalSecond);
                    PointLatLng p = FindPointAtDistanceFrom(fd.point, DegreesToRadians(fd.bearing), distance);
                    fd.lastPoint = fd.point;
                    fd.point     = p;
                    fd.time      = now;
                    if (DataSettings.UseDatabase)
                    {
                        MySqlConnection conn = DataSettings.GetConnection();
                        using (MySqlCommand cmd = new MySqlCommand(null, conn))
                        {
                            cmd.CommandText = "INSERT INTO faker_track_point (point_lat, point_lng, faker_id) VALUES (@lat, @lng, @id)";
                            cmd.Parameters.AddWithValue("lat", fd.lastPoint.Lat);
                            cmd.Parameters.AddWithValue("lng", fd.lastPoint.Lng);
                            cmd.Parameters.AddWithValue("id", fd.Id);
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
Пример #8
0
 public void CompareDict(Dictionary <int, RecievedTrackData> prev, Dictionary <int, RecievedTrackData> curr)
 {
     if (DataSettings.UseDatabase)
     {
         MySqlConnection conn = DataSettings.GetConnection();
         List <int>      keys = new List <int>(curr.Keys);
         using (MySqlCommand cmd = new MySqlCommand(null, conn))
         {
             foreach (int id in curr.Keys)
             {
                 RecievedTrackData track = curr[id];
                 FlightRadarData   fd    = GetReal(track.TrackNumber);
                 cmd.CommandText = "INSERT INTO real_track_point (point_lat, point_lng, real_id) VALUES (@lat, @lng, @id)";
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("lat", fd.point.Lat);
                 cmd.Parameters.AddWithValue("lng", fd.point.Lng);
                 cmd.Parameters.AddWithValue("id", fd.Id);
                 cmd.ExecuteNonQuery();
             }
             if (keys.Count > 0)
             {
                 cmd.CommandText = "DELETE FROM real_track WHERE tk_id NOT IN (" + string.Join(",", keys) + ")";
             }
             else
             {
                 cmd.CommandText = "DELETE FROM real_track";
             }
             cmd.ExecuteNonQuery();
         }
     }
     foreach (int id in prev.Keys)
     {
         if (!curr.ContainsKey(id))
         {
             RecievedTrackData data = prev[id];
             RemoveReal(data.TrackNumber);
         }
     }
 }
Пример #9
0
 public void AddFaker(FlightRadarData fd, MySqlConnection conn)
 {
     AddFaker(fd);
     if (DataSettings.UseDatabase)
     {
         using (MySqlCommand cmd = new MySqlCommand(null, conn))
         {
             cmd.CommandText = "INSERT INTO faker_track VALUES (@id, @name, @iff, @lat, @lng, @dir, @speed, @auto, @mission) " +
                               "ON DUPLICATE KEY UPDATE tk_name = @name, tk_iff = @iff, tk_lat = @lat, tk_lng = @lng, tk_dir = @dir, tk_speed = @speed, tk_auto = @auto";
             cmd.Parameters.Clear();
             cmd.Parameters.AddWithValue("id", fd.Id);
             cmd.Parameters.AddWithValue("name", fd.name);
             cmd.Parameters.AddWithValue("iff", fd.identification);
             cmd.Parameters.AddWithValue("lat", fd.point.Lat);
             cmd.Parameters.AddWithValue("lng", fd.point.Lng);
             cmd.Parameters.AddWithValue("dir", fd.bearing);
             cmd.Parameters.AddWithValue("speed", fd.speed);
             cmd.Parameters.AddWithValue("auto", fd.auto);
             cmd.Parameters.AddWithValue("mission", mission_id);
             cmd.ExecuteNonQuery();
         }
     }
 }
Пример #10
0
        public bool Decode()
        {
            /*
             * _Encoded = _Encoded.Replace("\n", ""); //clear escape string
             * string[] delimiters = { "0202" };
             * foreach (string code in _Encoded.Split(delimiters, StringSplitOptions.RemoveEmptyEntries))
             * {
             *  if (code.Length < 6)
             *  {
             *      return false;
             *  }
             *  string result = "0202" + code;
             *  try
             *  {
             *      int blockLength = Convert.ToInt32(result.Substring(4, 4), 16);
             *      string dataType = result.Substring(8, 2);
             *      string excess = "";
             *      if (dataType.Equals("01"))
             *      {
             *          //decode data : radar use 20 bytes
             *          int no = Convert.ToInt32(result.Substring(20, 2));
             *          string latPath = result.Substring(24, 8);
             *          string lngPath = result.Substring(32, 8);
             *          if (result.Length > 40)
             *          {
             *              excess = result.Substring(40);
             *          }
             *          //set radar data
             *          RecievedRadarData data = new RecievedRadarData();
             *          data.BlockLength = blockLength;
             *          data.Type = RecievedType.Radar;
             *          data.Number = no;
             *          data.Lat = FindPositionInDegree(latPath);
             *          data.Lng = FindPositionInDegree(lngPath);
             *          data.Excess = excess;
             *          string key = GenerateId(data.Type, data.Number);
             *          //result message
             *          string message = "RADAR, ";
             *          message += data.Number.ToString("00") + ", ";
             *          message += data.Lat.ToString("0.####") + ", ";
             *          message += data.Lng.ToString("0.####");
             *          //radar marker
             *          PointLatLng point = new PointLatLng(data.Lat, data.Lng);
             *          Bitmap pic = (Bitmap)Image.FromFile("Img/point/RS.png");
             *          GMapMarker marker = new GMarkerGoogle(point, pic);
             *          marker.Tag = "Radar";
             *          //store value
             *          if (!_Keys.Contains(key))
             *          {
             *              _Keys.Add(key);
             *              _Decoded.Add(key, data);
             *              _Result.Add(key, message);
             *              _Markers.Add(key, marker);
             *          }
             *          else
             *          {
             *              _Decoded[key] = data;
             *              _Result[key] = message;
             *              _Markers[key] = marker;
             *          }
             *      }
             *      else if (dataType.Equals("02"))
             *      {
             *          //decode data : track use 18 bytes
             *          double xPos = (double)Convert.ToInt16(result.Substring(12, 4), 16) / 480;
             *          double yPos = (double)Convert.ToInt16(result.Substring(16, 4), 16) / 480;
             *          double xSpeed = (double)Convert.ToInt16(result.Substring(20, 4), 16) / 8;
             *          double ySpeed = (double)Convert.ToInt16(result.Substring(24, 4), 16) / 8;
             *          int trackNo = Convert.ToInt32(result.Substring(28, 4));
             *          //TODO dont change if edited by user
             *          char status = (char)Convert.ToInt32(result.Substring(32, 2), 16);
             *          int radarNo = Convert.ToInt32(result.Substring(34, 2));
             *          MessageBox.Show("dataType = " + dataType + "\nblockLength = " + blockLength + "\n" + "result.Length = " + result.Length);
             *          if (result.Length > 36)
             *          {
             *              excess = result.Substring(36);
             *              Regex regex = new Regex(@"(02)(.{26})");
             *              MatchCollection matches = regex.Matches(excess);
             *              foreach (Match match in matches)
             *              {
             *                  MessageBox.Show(match.Groups[0].Value);
             *              }
             *          }
             *          //set track data
             *          RecievedTrackData data = new RecievedTrackData();
             *          data.BlockLength = blockLength;
             *          data.Type = RecievedType.Track;
             *          data.PositionX = xPos;
             *          data.PositionY = yPos;
             *          data.SpeedX = xSpeed;
             *          data.SpeedY = ySpeed;
             *          data.TrackNumber = trackNo;
             *          data.TrackType = ParseStatus(status);
             *          data.RadarNumber = radarNo;
             *          data.Excess = excess;
             *          string key = GenerateId(data.Type, data.TrackNumber);
             *          if (_Status.ContainsKey(key))
             *          {
             *              data.Identification = _Status[key];
             *          }
             *          else
             *          {
             *              data.Identification = status;
             *          }
             *          PointLatLng point = FindPositionFor(data);
             *          double kmph = ScaleConverter.ConvertSpeed(data.Speed, "mph", "km/h");
             *          //result message
             *          string message = "TRACK, ";
             *          message += data.TrackNumber.ToString("0000") + ", ";
             *          message += data.Identification + ", ";
             *          message += point.Lat.ToString("0.####") + ", ";
             *          message += point.Lng.ToString("0.####") + ", ";
             *          message += kmph.ToString("0.####") + ", ";
             *          message += data.RadarNumber.ToString("00");
             *          //track marker
             *          GMapMarker marker = new GMarkerArrow(point)
             *          {
             *              ToolTipText = message,
             *              ToolTipMode = MarkerTooltipMode.OnMouseOver
             *          };
             *          (marker as GMarkerArrow).Bearing = (float)data.Bearing;
             *          marker.setFill(data.Identification.ToString());
             *          marker.Tag = "Track";
             *          //flight tail
             *          FlightTail tail = new FlightTail(point, data.Speed, data.Bearing);
             *          //store value
             *          if (!_Keys.Contains(key))
             *          {
             *              _Keys.Add(key);
             *              _Decoded.Add(key, data);
             *              _Result.Add(key, message);
             *              _Markers.Add(key, marker);
             *              _Tails.Add(key, tail);
             *          }
             *          else
             *          {
             *              _Decoded[key] = data;
             *              _Result[key] = message;
             *              _Markers[key] = marker;
             *              _Tails[key] = tail;
             *          }
             *      }
             *  }
             *  catch (Exception ex)
             *  {
             *      Debug.WriteLine("Error: " + ex.Message);
             *      return false;
             *  }
             * }
             * return true;
             */
            _Encoded = _Encoded.Replace("\n", ""); //clear escape string
            _Encoded = _Encoded.Replace("\r", ""); //clear escape string
            _Encoded = _Encoded.Replace("\t", ""); //clear escape string
            string code = _Encoded;

            if (IsTrackDecode == 0)
            {
                //normal data
                while (code.StartsWith("0202", StringComparison.OrdinalIgnoreCase) && IsTrackDecode == 0)
                {
                    string result      = code;
                    int    blockLength = Convert.ToInt32(result.Substring(4, 4), 16);
                    int    dataType    = Convert.ToInt32(result.Substring(8, 2), 16);
                    string excess      = "";
                    if (dataType == 1)
                    {
                        //decode data : radar use 20 bytes
                        int    no      = Convert.ToInt32(result.Substring(20, 2), 16);
                        string latPath = result.Substring(24, 8);
                        string lngPath = result.Substring(32, 8);
                        //set radar data
                        RecievedRadarData data = new RecievedRadarData();
                        data.BlockLength = blockLength;
                        data.Type        = RecievedType.Radar;
                        data.Number      = no;
                        data.Lat         = FindPositionInDegree(latPath);
                        data.Lng         = FindPositionInDegree(lngPath);
                        data.Excess      = excess;
                        string key = GenerateId(data.Type, data.Number);
                        //result message
                        string message = "RADAR, ";
                        message += data.Number.ToString("00") + ", ";
                        message += data.Lat.ToString("0.####") + ", ";
                        message += data.Lng.ToString("0.####");
                        //radar marker

                        /*
                         * PointLatLng point = new PointLatLng(data.Lat, data.Lng);
                         * Bitmap pic = (Bitmap)Image.FromFile("Img/point/RS.png");
                         * GMapMarker marker = new GMarkerGoogle(point, pic);
                         * /
                         *  ToolTipText = message,
                         *  ToolTipMode = MarkerTooltipMode.OnMouseOver
                         * };
                         * marker.Tag = "Radar";
                         */
                        RE_radar = new PointLatLng(data.Lat, data.Lng);
                        mainForm main = mainForm.GetInstance();
                        if (main.radarP.Position != RE_radar)
                        {
                            main.radarP.Position = RE_radar;
                        }
                        //store value
                        if (!_DecodedRadar.ContainsKey(key))
                        {
                            _DecodedRadar.Add(key, data);
                        }
                        else
                        {
                            _DecodedRadar[key] = data;
                        }
                        if (_FirstRadar == null)
                        {
                            _FirstRadar = data;
                        }

                        track.ClearReal();
                        CurrentTrack.Clear();
                    }
                    else if (dataType == 2)
                    {
                        //decode data : track use 18 bytes
                        double xPos    = (double)Convert.ToInt16(result.Substring(12, 4), 16) / 480;
                        double yPos    = (double)Convert.ToInt16(result.Substring(16, 4), 16) / 480;
                        double xSpeed  = (double)Convert.ToInt16(result.Substring(20, 4), 16);
                        double ySpeed  = (double)Convert.ToInt16(result.Substring(24, 4), 16);
                        int    trackNo = Convert.ToInt32(result.Substring(28, 4), 16);
                        char   status  = (char)Convert.ToInt32(result.Substring(32, 2), 16);
                        int    radarNo = Convert.ToInt32(result.Substring(34, 2), 16);

                        track.CompareDict(PreviousTrack, CurrentTrack);
                        IsTrackDecode = blockLength - 18;
                        PreviousTrack = new Dictionary <int, RecievedTrackData>(CurrentTrack);
                        CurrentTrack.Clear();

                        RecievedTrackData data = new RecievedTrackData();
                        data.BlockLength = 14;
                        data.Type        = RecievedType.Track;
                        data.PositionX   = xPos;
                        data.PositionY   = yPos;
                        data.SpeedX      = xSpeed;
                        data.SpeedY      = ySpeed;
                        data.TrackNumber = trackNo;
                        data.TrackType   = ParseStatus(status);
                        data.RadarNumber = radarNo;
                        string key = GenerateId(data.Type, data.TrackNumber);
                        if (_Status.ContainsKey(key))
                        {
                            data.Identification = _Status[key];
                        }
                        else
                        {
                            data.Identification = status;
                        }
                        PointLatLng point = FindPositionFor(data);
                        double      kmph  = ScaleConverter.ConvertSpeed(data.Speed, "mph", "km/h");
                        //result message
                        string message = "TRACK, ";
                        message += data.TrackNumber.ToString("0000") + ", ";
                        message += data.Identification + ", ";
                        message += point.Lat.ToString("0.####") + ", ";
                        message += point.Lng.ToString("0.####") + ", ";
                        message += kmph.ToString("0.####") + ", ";
                        message += data.RadarNumber.ToString("00");

                        FlightRadarData fd = new FlightRadarData(TrackType.Real); //todo change
                        fd.Id             = data.TrackNumber;
                        fd.point          = point;
                        fd.speed          = data.Speed;
                        fd.bearing        = data.Bearing;
                        fd.identification = data.Identification;
                        //fd.lastTime = DateTime.Now;
                        track.AddReal(fd);

                        //store value
                        CurrentTrack.Add(fd.Id, data);
                    }
                    code = code.Substring(result.Length);
                }
            }
            else
            {
                //track data
                while (code.Length >= 28 && IsTrackDecode > 0)
                {
                    string result  = code;
                    double xPos    = (double)Convert.ToInt16(result.Substring(4, 4), 16) / 480;
                    double yPos    = (double)Convert.ToInt16(result.Substring(8, 4), 16) / 480;
                    double xSpeed  = (double)Convert.ToInt16(result.Substring(12, 4), 16);
                    double ySpeed  = (double)Convert.ToInt16(result.Substring(16, 4), 16);
                    int    trackNo = Convert.ToInt32(result.Substring(20, 4), 16);
                    char   status  = (char)Convert.ToInt32(result.Substring(24, 2), 16);
                    int    radarNo = Convert.ToInt32(result.Substring(26, 2), 16);

                    IsTrackDecode -= 14;

                    RecievedTrackData data = new RecievedTrackData();
                    data.BlockLength = 14;
                    data.Type        = RecievedType.Track;
                    data.PositionX   = xPos;
                    data.PositionY   = yPos;
                    data.SpeedX      = xSpeed;
                    data.SpeedY      = ySpeed;
                    data.TrackNumber = trackNo;
                    data.TrackType   = ParseStatus(status);
                    data.RadarNumber = radarNo;
                    string key = GenerateId(data.Type, data.TrackNumber);
                    if (_Status.ContainsKey(key))
                    {
                        data.Identification = _Status[key];
                    }
                    else
                    {
                        data.Identification = status;
                    }
                    PointLatLng point = FindPositionFor(data);
                    double      kmph  = ScaleConverter.ConvertSpeed(data.Speed, "mph", "km/h");
                    //result message
                    string message = "TRACK, ";
                    message += data.TrackNumber.ToString("0000") + ", ";
                    message += data.Identification + ", ";
                    message += point.Lat.ToString("0.####") + ", ";
                    message += point.Lng.ToString("0.####") + ", ";
                    message += kmph.ToString("0.####") + ", ";
                    message += data.RadarNumber.ToString("00");

                    FlightRadarData fd = new FlightRadarData(TrackType.Real); //todo change
                    fd.Id             = data.TrackNumber;
                    fd.point          = point;
                    fd.speed          = data.Speed;
                    fd.bearing        = data.Bearing;
                    fd.identification = data.Identification;
                    //fd.lastTime = DateTime.Now;
                    track.AddReal(fd);

                    //store value
                    CurrentTrack.Add(fd.Id, data);
                    code = code.Substring(28);
                }
            }
            return(true);
        }
Пример #11
0
        public static IntersectionResult Intersection(FlightRadarData fd1, FlightRadarData fd2, out PointLatLng intersectPoint, out double s, out double b, out double t)
        {
            IntersectionResult result       = IntersectionResult.Empty;
            PointLatLng        point1       = fd1.point;
            PointLatLng        point2       = fd2.point;
            double             initDistance = GetDistance(point1, point2);
            float bearing = (float)fd1.bearing;

            intersectPoint = new PointLatLng();
            int attempt = 0;

            s = 0;
            b = 0;
            t = 0;
            while (result != IntersectionResult.Success && attempt < 360)
            {
                var φ1  = DegreesToRadians(point1.Lat);
                var φ2  = DegreesToRadians(point2.Lat);
                var λ1  = DegreesToRadians(point1.Lng);
                var λ2  = DegreesToRadians(point2.Lng);
                var Δφ  = φ2 - φ1;
                var Δλ  = λ2 - λ1;
                var θ13 = DegreesToRadians(bearing);
                var θ23 = DegreesToRadians(fd2.bearing);

                var δ12 = 2 * Math.Asin(Math.Sqrt(Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) + Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2)));

                var cosθa = (Math.Sin(φ2) - Math.Sin(φ1) * Math.Cos(δ12)) / (Math.Sin(δ12) * Math.Cos(φ1));
                var cosθb = (Math.Sin(φ1) - Math.Sin(φ2) * Math.Cos(δ12)) / (Math.Sin(δ12) * Math.Cos(φ2));
                var θa    = Math.Acos(Math.Min(Math.Max(cosθa, -1), 1)); // protect against rounding errors
                var θb    = Math.Acos(Math.Min(Math.Max(cosθb, -1), 1)); // protect against rounding errors

                var θ12 = Math.Sin(λ2 - λ1) > 0 ? θa : 2 * Math.PI - θa;
                var θ21 = Math.Sin(λ2 - λ1) > 0 ? 2 * Math.PI - θb : θb;

                var α1 = θ13 - θ12; // angle 2-1-3
                var α2 = θ21 - θ23; // angle 1-2-3

                if (Math.Sin(α1) == 0 && Math.Sin(α2) == 0)
                {
                    bearing = Rotate(bearing, fd1, fd2);
                    result  = IntersectionResult.Infinity;
                }
                else if (Math.Sin(α1) * Math.Sin(α2) < 0)
                {
                    bearing = Rotate(bearing, fd1, fd2);
                    result  = IntersectionResult.Ambiguous;
                }
                else
                {
                    var cosα3 = -Math.Cos(α1) * Math.Cos(α2) + Math.Sin(α1) * Math.Sin(α2) * Math.Cos(δ12);

                    var δ13 = Math.Atan2(Math.Sin(δ12) * Math.Sin(α1) * Math.Sin(α2), Math.Cos(α2) + Math.Cos(α1) * cosα3);

                    var φ3 = Math.Asin(Math.Sin(φ1) * Math.Cos(δ13) + Math.Cos(φ1) * Math.Sin(δ13) * Math.Cos(θ13));

                    var Δλ13 = Math.Atan2(Math.Sin(θ13) * Math.Sin(δ13) * Math.Cos(φ1), Math.Cos(δ13) - Math.Sin(φ1) * Math.Sin(φ3));
                    var λ3   = λ1 + Δλ13;

                    var lat = RadiansToDegrees(φ3);
                    var lng = RadiansToDegrees(λ3);
                    intersectPoint = new PointLatLng(lat, lng);

                    var speed2InKm = ScaleConverter.ConvertSpeed(fd2.speed, "kts", "km/h");
                    var distance2  = GetDistance(fd2.point, intersectPoint);
                    var time       = distance2 / speed2InKm;

                    var distance1 = GetDistance(fd1.point, intersectPoint);
                    var speed1    = distance1 / time;
                    if (distance1 > initDistance * 2.5)
                    {
                        bearing = Rotate(bearing, fd1, fd2);
                        result  = IntersectionResult.Ambiguous;
                    }
                    else if (speed1 > DataSettings.Track["MaxSpeed"])
                    {
                        bearing = Rotate(bearing, fd1, fd2);
                        attempt++;
                        result = IntersectionResult.Impossible;
                    }
                    else
                    {
                        s      = speed1;
                        b      = bearing;
                        t      = time;
                        result = IntersectionResult.Success;
                    }
                }
            }
            return(result);
        }
Пример #12
0
 public static float Rotate(float bearing, FlightRadarData fd1, FlightRadarData fd2)
 {
     bearing = (bearing + 1) % 360;
     return(bearing);
 }
Пример #13
0
 public void AddFaker(FlightRadarData fd)
 {
     DataDecoder.InsertOrUpdate(fakerTrack, fd.Id, fd);
     DataDecoder.InsertOrUpdate(AllTrack, fd.Id, fd);
 }
Пример #14
0
 public void AddReal(FlightRadarData fd)
 {
     DataDecoder.InsertOrUpdate(realTrack, fd.Id, fd);
     DataDecoder.InsertOrUpdate(AllTrack, fd.Id, fd);
 }