Skip to content

Commit

Permalink
Extlibs: ArduPilot: LogMetaData: Parse bitmasks
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and meee1 committed Feb 15, 2023
1 parent 7850bd8 commit c9fbd45
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions ExtLibs/ArduPilot/LogMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ public class LogMetaData

static string url = "https://autotest.ardupilot.org/LogMessages/{0}/LogMessages.xml.xz";

public static Dictionary<string, Dictionary<string, string>> MetaData { get; } = new Dictionary<string, Dictionary<string, string>>();
public struct LogItemFeild
{
public string description;
public struct LogItemFeildBitmask
{
public string name;
public uint mask;
public string description;
}
public List<LogItemFeildBitmask> bitmask;
};

public static Dictionary<string, Dictionary<string, LogItemFeild>> MetaData { get; } = new Dictionary<string, Dictionary<string, LogItemFeild>>();

public static async Task GetMetaData()
{
Expand Down Expand Up @@ -107,16 +119,38 @@ public static void ParseMetaData()
var typedesc = b.Descendants("description").FirstOrDefault();

if (!MetaData.ContainsKey(type.Value))
MetaData[type.Value] = new Dictionary<string, string>();
MetaData[type.Value] = new Dictionary<string, LogItemFeild>();

MetaData[type.Value]["description"] = typedesc.Value;
LogItemFeild log_type = new LogItemFeild();
log_type.description = typedesc.Value;
MetaData[type.Value]["description"] = log_type;

b.Descendants("fields").Descendants("field").ForEach(c =>
{
var name = c.Attribute("name");
var desc = c.Descendants("description").FirstOrDefault();
var bits = c.Descendants("bitmask").FirstOrDefault();

LogItemFeild log_feild = new LogItemFeild();
log_feild.description = desc.Value;

if (bits != null)
{
if (log_feild.bitmask == null)
{
log_feild.bitmask = new List<LogItemFeild.LogItemFeildBitmask>();
}

MetaData[type.Value][name.Value] = desc.Value;
bits.Descendants("bit").ForEach(d =>
{
LogItemFeild.LogItemFeildBitmask log_mask = new LogItemFeild.LogItemFeildBitmask();
log_mask.name = (string)d.Attribute("name");
log_mask.mask = (uint)d.Descendants("value").FirstOrDefault();
log_mask.description = (string)d.Descendants("description").FirstOrDefault();
log_feild.bitmask.Add(log_mask);
});
}
MetaData[type.Value][name.Value] = log_feild;
});
});
}
Expand Down

0 comments on commit c9fbd45

Please sign in to comment.