From 2016d3bf16e2d92d276520ae06b23f768496926e Mon Sep 17 00:00:00 2001 From: Michael Oborne Date: Mon, 18 Nov 2024 14:19:40 +1100 Subject: [PATCH] ParameterMetaDataRepositoryAPMpdef: add version specific pdefs --- .../ParameterMetaDataRepositoryAPMpdef.cs | 45 ++++++++++++++++++- MainV2.cs | 11 +++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/ExtLibs/Utilities/ParameterMetaDataRepositoryAPMpdef.cs b/ExtLibs/Utilities/ParameterMetaDataRepositoryAPMpdef.cs index edffe4747a..b70a254cc8 100644 --- a/ExtLibs/Utilities/ParameterMetaDataRepositoryAPMpdef.cs +++ b/ExtLibs/Utilities/ParameterMetaDataRepositoryAPMpdef.cs @@ -23,11 +23,18 @@ public static class ParameterMetaDataRepositoryAPMpdef private static string[] vehicles = new[] { "SITL", "AP_Periph", "ArduSub", "Rover", "ArduCopter", - "ArduPlane", "AntennaTracker", "Blimp", "Heli" + "ArduPlane", "AntennaTracker", "Blimp", "Heli" + }; + + private static string[] vehicles_versioned = new[] + { + "Copter", "Plane", "Rover", "Sub", "Tracker" }; static string url = "https://autotest.ardupilot.org/Parameters/{0}/apm.pdef.xml.gz"; + static string urlversioned = "https://autotest.ardupilot.org/Parameters/versioned/{0}/stable-{1}/apm.pdef.xml"; + static ParameterMetaDataRepositoryAPMpdef() { GetMetaData(); @@ -42,6 +49,42 @@ public static void CheckLoad(string vehicle = "") Reload(vehicle); } + public static async Task GetMetaDataVersioned(Version version) + { + List tlist = new List(); + + vehicles_versioned.ForEach(a => + { + try + { + var newurl = String.Format(urlversioned, a, version.ToString()); + var file = Path.Combine(Settings.GetDataDirectory(), a + version.ToString() + ".apm.pdef.xml"); + if (File.Exists(file)) + if (new FileInfo(file).LastWriteTime.AddDays(7) > DateTime.Now) + return; + var dltask = Download.getFilefromNetAsync(newurl, file); + tlist.Add(dltask); + } + catch (Exception ex) { log.Error(ex); } + }); + + await Task.WhenAll(tlist); + + vehicles_versioned.ForEach(a => + { + try + { + Reload(a + version.ToString()); + + var veh = vehicles.First(b => b.Contains(a)); + + if(_parameterMetaDataXML.ContainsKey(a + version.ToString())) + _parameterMetaDataXML[veh] = _parameterMetaDataXML[a + version.ToString()]; + } + catch (Exception ex) { log.Error(ex); } + }); + } + public static async Task GetMetaData(bool force = false) { List tlist = new List(); diff --git a/MainV2.cs b/MainV2.cs index 74fae22d68..4caab691b6 100644 --- a/MainV2.cs +++ b/MainV2.cs @@ -1677,8 +1677,8 @@ public void doConnect(MAVLinkInterface comPort, string portname, string baud, bo foreach (var item in softwares) { - // check primare firmware type. ie arudplane, arducopter - if (fields1[0].ToLower().Contains(item.VehicleType.ToLower())) + // check primare firmware type. ie arudplane, arducopter + if (fields1[0].ToLower().Contains(item.VehicleType.ToLower())) { Version ver1 = VersionDetection.GetVersion(comPort.MAV.VersionString); Version ver2 = item.MavFirmwareVersion; @@ -1691,10 +1691,13 @@ public void doConnect(MAVLinkInterface comPort, string portname, string baud, bo break; } - // check the first hit only - break; + // check the first hit only + break; } } + + // load version specific config + ParameterMetaDataRepositoryAPMpdef.GetMetaDataVersioned(VersionDetection.GetVersion(comPort.MAV.VersionString)); } catch (Exception ex) {