public PlaneFeedPluginPlaneInfoList GetPlanes(PlaneFeedPluginArgs args) { PlaneFeedPluginPlaneInfoList planes = new PlaneFeedPluginPlaneInfoList(); // time to report planes ArrayList list = Decoder.GetPlanes(); if (list.Count > 0) { // convert to plane info list foreach (ADSBInfo info in list) { PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); plane.Time = info.Timestamp; plane.Hex = info.ICAO24; // mark call with "@" if option is enabled plane.Call = (Settings.MarkLocal) ? "@" + info.Call : info.Call; plane.Lat = info.Lat; plane.Lon = info.Lon; plane.Alt = info.Alt; plane.Speed = info.Speed; plane.Track = info.Heading; plane.Reg = "[unknown]"; plane.Type = "[unknown]"; plane.Manufacturer = "[unknown]"; plane.Model = "[unknown]"; plane.Category = 0; planes.Add(plane); } // save raw data to file if enabled if (Settings.SaveToFile) { JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(planes); using (StreamWriter sw = new StreamWriter(args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json")) { sw.WriteLine(json); } } } Console.WriteLine("[" + this.GetType().Name + "]: Returning " + planes.Count + " planes"); return(planes); }
public PlaneFeedPluginPlaneInfoList GetPlanes(PlaneFeedPluginArgs args) { // intialize variables VarConverter VC = new VarConverter(); VC.AddVar("APPDIR", args.AppDirectory); VC.AddVar("DATADIR", args.AppDataDirectory); VC.AddVar("LOGDIR", args.LogDirectory); VC.AddVar("DATABASEDIR", args.DatabaseDirectory); VC.AddVar("MINLAT", args.MinLat); VC.AddVar("MAXLAT", args.MaxLat); VC.AddVar("MINLON", args.MinLon); VC.AddVar("MAXLON", args.MaxLon); VC.AddVar("MINALTM", args.MinAlt); VC.AddVar("MAXALTM", args.MaxAlt); VC.AddVar("MINALTFT", (int)UnitConverter.m_ft((double)args.MinAlt)); VC.AddVar("MAXALTFT", (int)UnitConverter.m_ft((double)args.MaxAlt)); // initialize plane info list PlaneFeedPluginPlaneInfoList planes = new PlaneFeedPluginPlaneInfoList(); string json = ""; // calculate url and get json String url = VC.ReplaceAllVars(Settings.URL); Console.WriteLine("[" + this.GetType().Name + "]: Creating web request: " + url); // this will only run on .NET 4.0 if you have installed .NET 4.5 or later frameworks on your machine! // ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); // webrequest.Timeout = Settings.Timeout * 1000; // webrequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0"; // webrequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; // Console.WriteLine("[" + this.GetType().Name + "]: Getting web response"); // HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); // Console.WriteLine("[" + this.GetType().Name + "]: Reading stream"); // using (StreamReader sr = new StreamReader(webresponse.GetResponseStream())) // { // json = sr.ReadToEnd(); // } json = OSNTlsClient.DownloadFile(url, Settings.Timeout * 1000); // save raw data to file if enabled if (Settings.SaveToFile) { using (StreamWriter sw = new StreamWriter(args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json")) { sw.WriteLine(json); } } Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); // JavaScriptSerializer js = new JavaScriptSerializer(); // dynamic root = js.Deserialize<dynamic>(json); dynamic root = JsonConvert.DeserializeObject(json); try { // analyze json string for planes data // get the planes position list var aclist = root["states"]; foreach (var ac in aclist) { try { // different handling of reading JSON between Windows (Array) & Linux (ArrayList) // access to data values itself is the same int len = 0; len = ac.Count; // skip if too few fields in record if (len < 17) { continue; } PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first plane.Hex = ReadPropertyString(ac, 0).ToUpper(); // get callsign plane.Call = ReadPropertyString(ac, 1); // get position plane.Lon = ReadPropertyDouble(ac, 5); plane.Lat = ReadPropertyDouble(ac, 6); // get altitude (provided in m --> convert to ft) plane.Alt = UnitConverter.m_ft(ReadPropertyDouble(ac, 13)); // get track plane.Track = ReadPropertyDouble(ac, 10); // get speed (provided in m/s --> convert to kts) plane.Speed = UnitConverter.ms_kts(ReadPropertyDouble(ac, 9)); // registration is not provided plane.Reg = ""; // get position timestamp in sec int l = ReadPropertyInt(ac, 3); if (l != int.MinValue) { DateTime timestamp = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); timestamp = timestamp.AddSeconds(l); plane.Time = timestamp; } else { // skip plane if no valid timestamp found continue; } // get type info plane.Type = ReadPropertyString(ac, 5); planes.Add(plane); } catch (Exception ex) { Console.WriteLine("[" + System.Reflection.MethodBase.GetCurrentMethod().Name + "]" + ex.Message); } } } catch (Exception ex) { Console.WriteLine("[" + System.Reflection.MethodBase.GetCurrentMethod().Name + "]" + ex.Message); } Console.WriteLine("[" + this.GetType().Name + "]: Returning " + planes.Count + " planes"); return(planes); }
public PlaneFeedPluginPlaneInfoList GetPlanes(PlaneFeedPluginArgs args) { // intialize variables VarConverter VC = new VarConverter(); VC.AddVar("APPDIR", args.AppDirectory); VC.AddVar("DATADIR", args.AppDataDirectory); VC.AddVar("LOGDIR", args.LogDirectory); VC.AddVar("DATABASEDIR", args.DatabaseDirectory); VC.AddVar("MINLAT", args.MinLat); VC.AddVar("MAXLAT", args.MaxLat); VC.AddVar("MINLON", args.MinLon); VC.AddVar("MAXLON", args.MaxLon); VC.AddVar("MINALTM", args.MinAlt); VC.AddVar("MAXALTM", args.MaxAlt); VC.AddVar("MINALTFT", (int)UnitConverter.m_ft((double)args.MinAlt)); VC.AddVar("MAXALTFT", (int)UnitConverter.m_ft((double)args.MaxAlt)); // initialize plane info list PlaneFeedPluginPlaneInfoList planes = new PlaneFeedPluginPlaneInfoList(); string json = ""; // calculate url and get json String url = VC.ReplaceAllVars(Settings.URL); Console.WriteLine("[" + this.GetType().Name + "]: Creating web request: " + url); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.Timeout = Settings.Timeout * 1000; webrequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0"; Console.WriteLine("[" + this.GetType().Name + "]: Getting web response"); HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); Console.WriteLine("[" + this.GetType().Name + "]: Reading stream"); using (StreamReader sr = new StreamReader(webresponse.GetResponseStream())) { json = sr.ReadToEnd(); } // save raw data to file if enabled if (Settings.SaveToFile) { using (StreamWriter sw = new StreamWriter(args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json")) { sw.WriteLine(json); } } Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); try { Console.WriteLine("[" + this.GetType().Name + "]: Deserializing data from JSON"); // JavaScriptSerializer js = new JavaScriptSerializer(); // dynamic root = js.Deserialize<dynamic>(json); dynamic root = JsonConvert.DeserializeObject(json); Console.WriteLine("[" + this.GetType().Name + "]: Created object from JSON is " + root.GetType().ToString()); // analyze json string for planes data // get the planes position list Console.WriteLine("[" + this.GetType().Name + "]: Getting root of planes list"); var aclist = root["planes"]; Console.WriteLine("[" + this.GetType().Name + "]: Created root object is " + aclist.GetType().ToString()); foreach (var ac in aclist) { try { // different handling of reading JSON between Windows (Array) & Linux (ArrayList) // access to data values itself is the same int len = 0; len = ac.Value.Count; // skip if too few fields in record if (len < 13) { continue; } PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first plane.Hex = ac.Name.Trim().Replace("\"", ""); // get position plane.Lat = ReadPropertyDouble(ac, 4); plane.Lon = ReadPropertyDouble(ac, 5); // get altitude plane.Alt = ReadPropertyDouble(ac, 6); // get callsign plane.Call = ReadPropertyString(ac, 5); // get registration plane.Reg = ReadPropertyString(ac, 2); // get track plane.Track = ReadPropertyDouble(ac, 7); // get speed plane.Speed = ReadPropertyDouble(ac, 8); // get position timestamp long l = ReadPropertyLong(ac, 9); if (l != long.MinValue) { DateTime timestamp = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); timestamp = timestamp.AddSeconds(l); plane.Time = timestamp; } else { // skip plane if no valid timestamp found continue; } // get type info plane.Type = ReadPropertyString(ac, 0); planes.Add(plane); } catch (Exception ex) { Console.WriteLine("[" + this.GetType().Name + "]: " + ex.Message); } } } catch (Exception ex) { string filename = args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json"; Console.WriteLine("[" + this.GetType().Name + "]: " + ex.Message + "\n\nJSON response saved as: " + filename); // save the JSON file try { using (StreamWriter sw = new StreamWriter(filename)) { sw.WriteLine(json); } } catch { // do nothing if saving fails } // forward exception to parent thread throw new Exception(ex.Message, ex.InnerException); } Console.WriteLine("[" + this.GetType().Name + "]: Returning " + planes.Count + " planes"); return(planes); }
public PlaneFeedPluginPlaneInfoList GetPlanes(PlaneFeedPluginArgs args) { // intialize variables VarConverter VC = new VarConverter(); VC.AddVar("APPDIR", args.AppDirectory); VC.AddVar("DATADIR", args.AppDataDirectory); VC.AddVar("LOGDIR", args.LogDirectory); VC.AddVar("DATABASEDIR", args.DatabaseDirectory); VC.AddVar("MINLAT", args.MinLat); VC.AddVar("MAXLAT", args.MaxLat); VC.AddVar("MINLON", args.MinLon); VC.AddVar("MAXLON", args.MaxLon); VC.AddVar("MINALTM", args.MinAlt); VC.AddVar("MAXALTM", args.MaxAlt); VC.AddVar("MINALTFT", (int)UnitConverter.m_ft((double)args.MinAlt)); VC.AddVar("MAXALTFT", (int)UnitConverter.m_ft((double)args.MaxAlt)); // initialize plane info list PlaneFeedPluginPlaneInfoList planes = new PlaneFeedPluginPlaneInfoList(); string json = ""; // calculate url and get json String url = VC.ReplaceAllVars(Settings.URL); Console.WriteLine("[" + this.GetType().Name + "]: Creating web request: " + url); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.Referer = "http://www.radarbox24.com/"; webrequest.Timeout = Settings.Timeout * 1000; webrequest.UserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130807 Firefox/17.0"; Console.WriteLine("[" + this.GetType().Name + "]: Getting web response"); HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); Console.WriteLine("[" + this.GetType().Name + "]: Reading stream"); using (StreamReader sr = new StreamReader(webresponse.GetResponseStream())) { json = sr.ReadToEnd(); } // save raw data to file if enabled if (Settings.SaveToFile) { using (StreamWriter sw = new StreamWriter(args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json")) { sw.WriteLine(json); } } Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); JavaScriptSerializer js = new JavaScriptSerializer(); dynamic root = js.Deserialize <dynamic>(json); try { // analyze json string for planes data // get the planes position list var aclist = root[0]; foreach (var ac in aclist) { try { // different handling of reading JSON between Windows (Array) & Linux (ArrayList) // access to data values itself is the same int len = 0; if (ac.Value.GetType() == typeof(ArrayList)) { len = ac.Value.Count; } else if (ac.Value.GetType() == typeof(Object[])) { len = ac.Value.Length; } // skip if too few fields in record if (len < 14) { continue; } PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first // Radarbox24 does not provide a HEX info // leave it empty and let it fill by Reg in planefeed main thread plane.Hex = ""; // get position plane.Lat = ReadPropertyDouble(ac, 1); plane.Lon = ReadPropertyDouble(ac, 2); // get altitude plane.Alt = ReadPropertyDouble(ac, 4); // get callsign plane.Call = ReadPropertyString(ac, 0); // get registration plane.Reg = ReadPropertyString(ac, 9); // get track plane.Track = ReadPropertyDouble(ac, 7); // get speed plane.Speed = ReadPropertyDouble(ac, 6); // get position timestamp in msec long l = ReadPropertyLong(ac, 3); if (l != long.MinValue) { DateTime timestamp = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); timestamp = timestamp.AddMilliseconds(l); plane.Time = timestamp; } else { // skip plane if no valid timestamp found continue; } // get type info plane.Type = ReadPropertyString(ac, 5); planes.Add(plane); } catch (Exception ex) { Console.WriteLine("[" + System.Reflection.MethodBase.GetCurrentMethod().Name + "]" + ex.Message); } } } catch (Exception ex) { // do nothing if property is not found } Console.WriteLine("[" + this.GetType().Name + "]: Returning " + planes.Count + " planes"); return(planes); }
public PlaneFeedPluginPlaneInfoList GetPlanes(PlaneFeedPluginArgs args) { // intialize variables VarConverter VC = new VarConverter(); VC.AddVar("APPDIR", args.AppDirectory); VC.AddVar("DATADIR", args.AppDataDirectory); VC.AddVar("LOGDIR", args.LogDirectory); VC.AddVar("DATABASEDIR", args.DatabaseDirectory); VC.AddVar("MINLAT", args.MinLat); VC.AddVar("MAXLAT", args.MaxLat); VC.AddVar("MINLON", args.MinLon); VC.AddVar("MAXLON", args.MaxLon); VC.AddVar("MINALTM", args.MinAlt); VC.AddVar("MAXALTM", args.MaxAlt); VC.AddVar("MINALTFT", (int)UnitConverter.m_ft((double)args.MinAlt)); VC.AddVar("MAXALTFT", (int)UnitConverter.m_ft((double)args.MaxAlt)); // initialize plane info list PlaneFeedPluginPlaneInfoList planes = new PlaneFeedPluginPlaneInfoList(); string json = ""; // calculate url and get json String url = VC.ReplaceAllVars(Settings.URL); Console.WriteLine("[" + this.GetType().Name + "]: Creating web request: " + url); // HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); // webrequest.Referer = "http://www.vrs-world.com/"; // webrequest.Timeout = Settings.Timeout * 1000; // webrequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"; // webrequest.Accept = "application/json, text/javascript, */*;q=0.01"; // webrequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip; // webrequest.Headers.Add("api-auth:" + APIKey); // Console.WriteLine("[" + this.GetType().Name + "]: Getting web response"); // HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); // Console.WriteLine("[" + this.GetType().Name + "]: Reading stream"); // // using (StreamReader sr = new StreamReader(webresponse.GetResponseStream())) // { // json = sr.ReadToEnd(); // } // */ json = VRSTlsClient.DownloadFile(url, Settings.Timeout * 1000, APIKey); // save raw data to file if enabled if (Settings.SaveToFile) { using (StreamWriter sw = new StreamWriter(args.TmpDirectory + Path.DirectorySeparatorChar + this.GetType().Name + "_" + DateTime.UtcNow.ToString("yyyy-MM-dd HH_mm_ss") + ".json")) { sw.WriteLine(json); } } Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); // JavaScriptSerializer js = new JavaScriptSerializer(); // dynamic root = js.Deserialize<dynamic>(json); dynamic root = JsonConvert.DeserializeObject(json); // 2017-07-23: workaround for "jumping planes" due to incorrect time stamps // try to get the server time to adjust the time stamps in plane positions // --> compare server time with local time and calculate offset // default offset is 0 long toffset = 0; try { // get local time of request in milliseconds DateTime lt = DateTime.UtcNow; long ltime = (long)(lt - new DateTime(1970, 1, 1)).TotalMilliseconds; // get server time in milliseconds long stime = ReadPropertyLong(root, "stm"); DateTime sti = new System.DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(stime); // calculate offset in milliseconds toffset = ltime - stime; // check value string message = "Server timestamp difference (server <> local): " + sti.ToString("yyyy-MM-dd HH:mm:ss,fffZ") + " <> " + lt.ToString("yyyy-MM-dd HH:mm:ss,fffZ"); // server time is more than 10.000 ms in the future --> keep offset for correction and log an error message // else --> set offset to 0 to work with real timestamps of entries without correction if (toffset <= -10000) { message += " --> timestamp correction applied!"; // Log.WriteMessage(message); } else { // clear offset toffset = 0; } // analyze json string for planes data // get the planes position list var aclist = root["acList"]; foreach (var ac in aclist) { try { PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first plane.Hex = ReadPropertyString(ac, "Icao").Trim().Replace("\"", ""); // get position plane.Lat = ReadPropertyDouble(ac, "Lat"); plane.Lon = ReadPropertyDouble(ac, "Long"); // get altitude // 2017-07-23: take "GAlt" (corrected altitude by air pressure) rather than "Alt" plane.Alt = ReadPropertyInt(ac, "GAlt"); // get callsign plane.Call = ReadPropertyString(ac, "Call"); // get registration plane.Reg = ReadPropertyString(ac, "Reg"); // get track plane.Track = ReadPropertyInt(ac, "Trak"); // get speed plane.Speed = ReadPropertyInt(ac, "Spd"); // get position timestamp // CAUTION!! time is UNIX time in milliseconds long l = ReadPropertyLong(ac, "PosTime"); if (l != long.MinValue) { // 2017-07-23: correct timestamp with offset l = l + toffset; DateTime timestamp = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); timestamp = timestamp.AddMilliseconds(l); plane.Time = timestamp; } else { // skip plane if no valid timestamp found continue; } // get type info plane.Type = ReadPropertyString(ac, "Type"); // get extended plane type info plane.Manufacturer = ReadPropertyString(ac, "Man"); plane.Model = ReadPropertyString(ac, "Mdl"); long cat = ReadPropertyLong(ac, "WTC"); switch (cat) { case 1: plane.Category = 1; break; case 2: plane.Category = 2; break; case 3: plane.Category = 3; break; case 4: plane.Category = 4; break; default: plane.Category = 0; break; } // do correction of A380 as "SuperHeavy" is not supported if (plane.Type == "A388") { plane.Category = 4; } // get country plane.Country = ReadPropertyString(ac, "Cou"); // get departure airport plane.From = ReadPropertyString(ac, "From"); // get destination airport plane.To = ReadPropertyString(ac, "To"); // get vertical speed plane.VSpeed = ReadPropertyInt(ac, "Vsi"); // add plane to list planes.Add(plane); } catch (Exception ex) { Console.WriteLine("[" + System.Reflection.MethodBase.GetCurrentMethod().Name + "]" + ex.Message); } } } catch (Exception ex) { // do nothing if property is not found } Console.WriteLine("[" + this.GetType().Name + "]: Returning " + planes.Count + " planes"); return(planes); }