Skip to content

Commit

Permalink
Log: LogBrowse: allow ploting bit mask feilds individualy
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and meee1 committed Feb 15, 2023
1 parent c9fbd45 commit 53fb15b
Showing 1 changed file with 138 additions and 51 deletions.
189 changes: 138 additions & 51 deletions Log/LogBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class DataModifer
public double offset = 0;
public double scalar = 1;
public bool doOffsetFirst = false;
public bool isMask = false;
public uint mask = 0;

public DataModifer()
{
Expand All @@ -81,10 +83,18 @@ public DataModifer()

public DataModifer(string _commandString)
{
this.commandString = _commandString;
this.commandString = _commandString.Trim();
this.isValid = ParseCommandString(_commandString);
}

public DataModifer(uint _mask)
{
this.commandString = "";
this.isValid = true;
this.isMask = true;
this.mask = _mask;
}

private bool ParseCommandString(string _commandString)
{
if (_commandString == null)
Expand Down Expand Up @@ -140,6 +150,15 @@ private bool ParseCommandString(string _commandString)
this.offset = -value;
break;

case '&':
if (value < 0)
{
return false;
}
this.isMask = true;
this.mask = (uint)value;
break;

default:
return false;
} // switch
Expand Down Expand Up @@ -619,6 +638,23 @@ private string get_instance_info(string LogMSG, string instance, string VehicleT
return "";
}

private void add_field_node(ref TreeNode root_node, string LogMSG, string instance, string VehicleType)
{
var new_node = root_node.Nodes.Add(instance);
new_node.ToolTipText = get_extra_info(LogMSG, instance, VehicleType);

// if bitmask add sub nodes, look up in metadata
if (LogMetaData.MetaData.ContainsKey(LogMSG) && LogMetaData.MetaData[LogMSG].ContainsKey(instance) && LogMetaData.MetaData[LogMSG][instance].bitmask != null)
{
foreach(var bit in LogMetaData.MetaData[LogMSG][instance].bitmask)
{
var new_bit_node = new_node.Nodes.Add(bit.name);
new_bit_node.ToolTipText = bit.description;
new_bit_node.Tag = "bitmask";
}
}
}

private void ResetTreeView(List<string> seenmessagetypes, string VehicleType)
{
treeView1.Nodes.Clear();
Expand Down Expand Up @@ -649,8 +685,7 @@ private void ResetTreeView(List<string> seenmessagetypes, string VehicleType)
instNode.ToolTipText = get_instance_info(item.Name, instanceinfo, VehicleType);
foreach (var item1 in item.FieldNames)
{
var new_node = instNode.Nodes.Add(item1);
new_node.ToolTipText = get_extra_info(item.Name, item1, VehicleType);
add_field_node(ref instNode, item.Name, item1, VehicleType);
}
}
}
Expand All @@ -659,8 +694,7 @@ private void ResetTreeView(List<string> seenmessagetypes, string VehicleType)
// no instance add the fields
foreach (var item1 in item.FieldNames)
{
var new_node = msgNode.Nodes.Add(item1);
new_node.ToolTipText = get_extra_info(item.Name, item1, VehicleType);
add_field_node(ref msgNode, item.Name, item1, VehicleType);
}
}
treeView1.Nodes.Add(msgNode);
Expand Down Expand Up @@ -1032,7 +1066,7 @@ void graphit_clickprocess(bool left = true)
}

void GraphItem(string type, string fieldname, bool left = true, bool displayerror = true,
bool isexpression = false, string instance = "")
bool isexpression = false, string instance = "", string bitmask = null)
{
log.InfoFormat("GraphItem: {0} {1} {2}", type, fieldname, instance);
DataModifer dataModifier = new DataModifer();
Expand All @@ -1050,7 +1084,7 @@ void GraphItem(string type, string fieldname, bool left = true, bool displayerro
return;
}

if (dataModifierHash.ContainsKey(nodeName))
if (dataModifierHash.ContainsKey(nodeName) && (bitmask == null))
{
dataModifier = (DataModifer)dataModifierHash[nodeName];
}
Expand All @@ -1071,32 +1105,86 @@ void GraphItem(string type, string fieldname, bool left = true, bool displayerro
{
if (subsubnode.Text == fieldname)
{
if (subsubnode.Checked != true)
if (bitmask == null)
{
subsubnode.Checked = true;
if (subsubnode.Checked != true)
{
subsubnode.Checked = true;
}
extra_label = " " + subsubnode.ToolTipText;
break;
}
else
{
foreach (TreeNode subsubsubnode in subsubnode.Nodes)
{
if (subsubsubnode.Text == bitmask)
{
if (subsubsubnode.Checked != true)
{
subsubsubnode.Checked = true;
}
extra_label = " " + subsubsubnode.ToolTipText;
break;
}
}
}
extra_label = " " + subsubnode.ToolTipText;
break;
}
}
}
}
else
{
if (subnode.Text == fieldname)
if (bitmask == null)
{
if (subnode.Checked != true)
if (subnode.Text == fieldname)
{
subnode.Checked = true;
if (subnode.Checked != true)
{
subnode.Checked = true;
}
extra_label = " " + subnode.ToolTipText;
break;
}
}
else
{
foreach (TreeNode subsubnode in subnode.Nodes)
{
if (subsubnode.Text == bitmask)
{
if (subsubnode.Checked != true)
{
subsubnode.Checked = true;
}
extra_label = " " + subsubnode.ToolTipText;
break;
}
}
extra_label = " " + subnode.ToolTipText;
break;
}
}
}
}
}

if (dataModifier.IsValid())
{
extra_label = dataModifier.commandString + extra_label;
}

if (bitmask != null)
{
foreach (var bitmask_item in LogMetaData.MetaData[type][fieldname].bitmask)
{
if (bitmask_item.name == bitmask)
{
extra_label = "." + bitmask + extra_label;
dataModifier = new DataModifer(bitmask_item.mask);
break;
}
}
}

// clear the filter on add
logdatafilter.Clear();

Expand Down Expand Up @@ -1354,7 +1442,6 @@ void GraphItem_GetList(string fieldname, string type, DFLog dflog, DataModifer d
double a = 0; // row counter
double b = 0;
DateTime screenupdate = DateTime.MinValue;
double value_prev = 0;

foreach (var item in logdata.GetEnumeratorType(type))
{
Expand All @@ -1374,24 +1461,20 @@ void GraphItem_GetList(string fieldname, string type, DFLog dflog, DataModifer d
double value = double.Parse(item.items[col],
System.Globalization.CultureInfo.InvariantCulture);

// abandon realy bad data
if (Math.Abs(value) > 9.15e8)
{
a++;
continue;
}

if (dataModifier.IsValid())
{
if ((a != 0) && Math.Abs(value - value_prev) > 1e5)
if (dataModifier.isMask)
{
// there is a glitch in the data, reject it by replacing it with the previous value
value = value_prev;
int shift;
for (shift = 0; shift < 32; shift++)
{
if (((dataModifier.mask >> shift) & 1) != 0) {
break;
}
}
value = ((uint)value & dataModifier.mask) >> shift;
}

value_prev = value;

if (dataModifier.doOffsetFirst)
else if (dataModifier.doOffsetFirst)
{
value += dataModifier.offset;
value *= dataModifier.scalar;
Expand Down Expand Up @@ -2942,28 +3025,32 @@ private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)

if (e.Node.Checked)
{
if (wasrightclick)
{
if (parts.Length == 3)
GraphItem(parts[0], parts[2], false, true, false, parts[1]);
else
GraphItem(parts[0], parts[1], false);
}
else
{
if (parts.Length == 3)
GraphItem(parts[0], parts[2], true, true, false, parts[1]);
if (parts.Length == 4)
GraphItem(parts[0], parts[2], !wasrightclick, true, false, parts[1], parts[3]);

else if (parts.Length == 3)
if ((e.Node.Tag != null) && (e.Node.Tag.ToString() == "bitmask"))
GraphItem(parts[0], parts[1], !wasrightclick, true, false, "", parts[2]);
else
GraphItem(parts[0], parts[1], true);
}
GraphItem(parts[0], parts[2], !wasrightclick, true, false, parts[1]);
else
GraphItem(parts[0], parts[1], !wasrightclick, true, false, "");
}
else
{
List<CurveItem> removeitems = new List<CurveItem>();

var name = parts.Length == 3
? parts[0] + "[" + parts[1] + "]." + parts[2]
: parts[0] + "." + parts[1];
string name;
if (parts.Length == 4)
name = parts[0] + "[" + parts[1] + "]." + parts[2] + "." + parts[3];

else if (parts.Length == 3)
if ((e.Node.Tag != null) && (e.Node.Tag.ToString() == "bitmask"))
name = parts[0] + "." + parts[1] + "." + parts[2];
else
name = parts[0] + "[" + parts[1] + "]." + parts[2];
else
name = parts[0] + "." + parts[1];

foreach (var item in zg1.GraphPane.CurveList)
{
Expand Down Expand Up @@ -3626,18 +3713,18 @@ private void treeView1_TreeNodeMouseHover(object sender, TreeNodeMouseHoverEvent
if (items.Length >= 2 && LogMetaData.MetaData.ContainsKey(items[0]) &&
LogMetaData.MetaData[items[0]].ContainsKey(items[items.Length - 1]))
{
var desc = LogMetaData.MetaData[items[0]][items[items.Length - 1]];
var feild = LogMetaData.MetaData[items[0]][items[items.Length - 1]];
pos.Y -= 30;
pos.X += 30;
txt_info.Text = desc;
txt_info.Text = feild.description;
//toolTip1.Show(desc, treeView1, pos, 2000);
} else if (items.Length == 1 && LogMetaData.MetaData.ContainsKey(items[0]) &&
LogMetaData.MetaData[items[0]].ContainsKey("description"))
{
var desc = LogMetaData.MetaData[items[0]]["description"];
var feild = LogMetaData.MetaData[items[0]]["description"];
pos.Y -= 30;
pos.X += 30;
txt_info.Text = desc;
txt_info.Text = feild.description;
//toolTip1.Show(desc, treeView1, pos, 2000);
}
}
Expand Down

0 comments on commit 53fb15b

Please sign in to comment.