Пример #1
0
        public PointLatLng FindPositionFor(RecievedTrackData track)
        {
            int    radarNumber = track.RadarNumber;
            string radarKey    = DataDecoder.GenerateId(RecievedType.Radar, radarNumber);
            Dictionary <string, RecievedRadarData> radars = Radars;
            RecievedRadarData radar;
            PointLatLng       point = new PointLatLng();

            if (radars.ContainsKey(radarKey))
            {
                radar     = radars[radarKey] as RecievedRadarData;
                point.Lat = radar.Lat + track.PositionY;
                point.Lng = radar.Lng + track.PositionX;
            }
            else if (_FirstRadar != null)
            {
                radar     = _FirstRadar;
                point.Lat = radar.Lat + track.PositionY;
                point.Lng = radar.Lng + track.PositionX;
            }
            return(point);
        }
Пример #2
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);
         }
     }
 }
Пример #3
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);
        }