Skip to content

Commit

Permalink
LogBrowse: improve parameter handling
Browse files Browse the repository at this point in the history
1. Detect firmware type for loading correct metadata
2. Display default values if applicable
  • Loading branch information
robertlong13 authored and meee1 committed Nov 17, 2023
1 parent 60209b8 commit 977c741
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ExtLibs/Mavlink/MAVLinkParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ private MAVLinkParam()
/// <param name="name"></param>
/// <param name="value"></param>
/// <param name="wiretype"></param>
public MAVLinkParam(string name, double value, MAV_PARAM_TYPE wiretype)
public MAVLinkParam(string name, double value, MAV_PARAM_TYPE wiretype, decimal? _default_value = null)
{
Name = name;
Type = wiretype;
Value = value;
default_value = _default_value;
}

/// <summary>
Expand Down
55 changes: 38 additions & 17 deletions Log/LogBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,26 @@ private void ResetTreeView(List<string> seenmessagetypes, string VehicleType)
MainV2.comPort.MAV.param.Clear();
MainV2.comPort.MAV.param.AddRange(parmdata);

// If we are not currently connected to a vehicle, then use VehicleType to set CurrentState firmware
// (we probably aren't connected to a vehicle when reviewing a log, but if we are, we don't want to override this)
if (!MainV2.comPort.BaseStream.IsOpen)
{
var firmware_lookup = new Dictionary<string, Firmwares>()
{
{"ArduPlane", Firmwares.ArduPlane},
{"ArduCopter", Firmwares.ArduCopter2},
{"Blimp", Firmwares.ArduCopter2},
{"ArduRover",Firmwares.ArduRover},
{"ArduSub",Firmwares.ArduSub},
{"AntennaTracker", Firmwares.ArduTracker}
};
var match = firmware_lookup.Where(d => VehicleType.StartsWith(d.Key)).ToArray();
if (match.Count() == 1)
{
MainV2.comPort.MAV.cs.firmware = match[0].Value;
}
}

var sorted = new SortedList(dflog.logformat);
// go through all fmt's
foreach (DFLog.Label item in sorted.Values)
Expand Down Expand Up @@ -3738,32 +3758,33 @@ private void chk_params_CheckedChanged(object sender, EventArgs e)

chk_params.Checked = false;

var parmdata = logdata.GetEnumeratorType("PARM").Select(a =>
new MAVLink.MAVLinkParam(a["Name"], double.Parse(a["Value"], CultureInfo.InvariantCulture),
MAVLink.MAV_PARAM_TYPE.REAL32));

//Check the list for duplicates and use the latest occurence for value
MAVLink.MAVLinkParamList newparamdata = new MAVLink.MAVLinkParamList();
foreach (MAVLink.MAVLinkParam sourceItem in parmdata)
MAVLink.MAVLinkParamList paramdata = new MAVLink.MAVLinkParamList();
bool has_defaults = logdata.dflog.logformat["PARM"].FieldNames.Contains("Default");
foreach (var msg in logdata.GetEnumeratorType("PARM"))
{
//Lookup the next item in the target list
for (var idx_target = 0; idx_target < newparamdata.Count(); idx_target++)
double value = double.Parse(msg["Value"], CultureInfo.InvariantCulture);
decimal tmp;
decimal? default_value = has_defaults && decimal.TryParse(msg["Default"], out tmp) ? (decimal?)tmp : null;
MAVLink.MAVLinkParam sourceItem = new MAVLink.MAVLinkParam(msg["Name"], value, MAVLink.MAV_PARAM_TYPE.REAL32, default_value);

// Lookup the next item in the target list
for (var idx_target = 0; idx_target < paramdata.Count(); idx_target++)
{
if (sourceItem.Name == newparamdata[idx_target].Name)
if (sourceItem.Name == paramdata[idx_target].Name)
{
//This item is already in the parameters, since source is in time order, it means the value changed
//We can replace the item in the output with this new value
Console.WriteLine("Duplicated item Name:{0} Prev:{1} New:{2}", sourceItem.Name, newparamdata[idx_target].Value, sourceItem.Value);
newparamdata[idx_target] = sourceItem;
// This item is already in the parameters, since source is in time order, it means the value changed.
// We can replace the item in the output with this new value
Console.WriteLine("Duplicated item Name:{0} Prev:{1} New:{2}", sourceItem.Name, paramdata[idx_target].Value, sourceItem.Value);
paramdata[idx_target] = sourceItem;
break;
}
}
//item is not in target list, we can add it
newparamdata.Add(sourceItem);
// The item is not in target list, we can add it
paramdata.Add(sourceItem);
}

MainV2.comPort.MAV.param.Clear();
MainV2.comPort.MAV.param.AddRange(newparamdata);
MainV2.comPort.MAV.param.AddRange(paramdata);

var frm = new ConfigRawParams().ShowUserControl();
}
Expand Down

0 comments on commit 977c741

Please sign in to comment.