Planner: Tidied up the implementation of the parser and added a parameter meta data repository for easy access to the parsed data.

This commit is contained in:
Adam M Rivera 2012-04-24 16:16:33 -05:00
parent 74789273b7
commit 8b636ee688
6 changed files with 73 additions and 12 deletions

View File

@ -208,6 +208,7 @@
<Reference Include="System.Xml">
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="ZedGraph, Version=5.1.2.878, Culture=neutral, PublicKeyToken=02a83cbd123fcd60, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
@ -225,6 +226,7 @@
<Compile Include="Attributes\DisplayTextAttribute.cs" />
<Compile Include="Attributes\PrivateAttribute.cs" />
<Compile Include="CodeGen.cs" />
<Compile Include="Constants\ParameterMetaDataConstants.cs" />
<Compile Include="Controls\BackstageView\BackstageView.cs">
<SubType>UserControl</SubType>
</Compile>
@ -552,7 +554,8 @@
<Compile Include="LangUtility.cs" />
<Compile Include="ThemeManager.cs" />
<Compile Include="Utilities\EnumTranslator.cs" />
<Compile Include="Utilities\ParameterInformationParser.cs" />
<Compile Include="Utilities\ParameterMetaDataParser.cs" />
<Compile Include="Utilities\ParameterMetaDataRepository.cs" />
<EmbeddedResource Include="Antenna\Tracker.resx">
<DependentUpon>Tracker.cs</DependentUpon>
</EmbeddedResource>
@ -1081,7 +1084,9 @@
<None Include="AeroSimRCAPMHil.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="app.config" />
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="arducopter-xplane.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@ -2,12 +2,16 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Windows.Forms;
using ArdupilotMega.Constants;
using ArdupilotMega.Utilities;
using log4net;
using ArdupilotMega.Controls.BackstageView;
using ArdupilotMega.Controls;
@ -19,6 +23,8 @@ namespace ArdupilotMega.GCSViews.ConfigurationView
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private readonly ParameterMetaDataRepository _parameterMetaDataRepository;
// Changes made to the params between writing to the copter
readonly Hashtable _changes = new Hashtable();
@ -41,6 +47,9 @@ namespace ArdupilotMega.GCSViews.ConfigurationView
public ConfigRawParams()
{
InitializeComponent();
// Init the accessor class for the parameter meta data
_parameterMetaDataRepository = new ParameterMetaDataRepository();
}
Hashtable loadParamFile(string Filename)
@ -397,7 +406,13 @@ namespace ArdupilotMega.GCSViews.ConfigurationView
Params.Rows[Params.RowCount - 1].Cells[Value.Index].Value = ((float)MainV2.comPort.param[value]).ToString("0.###");
try
{
if (tooltips[value] != null)
string metaDataDescription = _parameterMetaDataRepository.GetParameterMetaData(value, ParameterMetaDataConstants.Description);
if(!String.IsNullOrEmpty(metaDataDescription))
{
Params.Rows[Params.RowCount - 1].Cells[Command.Index].ToolTipText = metaDataDescription;
Params.Rows[Params.RowCount - 1].Cells[Value.Index].ToolTipText = metaDataDescription;
}
else if (tooltips[value] != null)
{
Params.Rows[Params.RowCount - 1].Cells[Command.Index].ToolTipText = ((paramsettings)tooltips[value]).desc;
//Params.Rows[Params.RowCount - 1].Cells[RawValue.Index].ToolTipText = ((paramsettings)tooltips[value]).desc;

View File

@ -1232,7 +1232,7 @@ namespace ArdupilotMega
}
// TODO: Move this to a more appropriate place, like right after CheckForUpdate();
ParameterInformationParser.GetParameterInformation();
ParameterMetaDataParser.GetParameterInformation();
}

View File

@ -7,15 +7,14 @@ using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using ArdupilotMega.Constants;
using log4net;
namespace ArdupilotMega.Utilities
{
public static class ParameterInformationParser
public static class ParameterMetaDataParser
{
private const string META_DELIMETER = "@";
private const string PARAM_KEY = "Param";
private static readonly Regex _paramMetaRegex = new Regex(String.Format("{0}(?<MetaKey>[^:]+):(?<MetaValue>.+)", META_DELIMETER));
private static readonly Regex _paramMetaRegex = new Regex(String.Format("{0}(?<MetaKey>[^:]+):(?<MetaValue>.+)", ParameterMetaDataConstants.Delimeter));
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@ -29,7 +28,7 @@ namespace ArdupilotMega.Utilities
parameterLocations.RemoveAll(String.IsNullOrEmpty);
string sStartupPath = Application.StartupPath;
using(var objXmlTextWriter = new XmlTextWriter(String.Format("{0}\\ParameterMetaData.xml", sStartupPath), null))
using (var objXmlTextWriter = new XmlTextWriter(String.Format("{0}\\{1}", sStartupPath, ConfigurationManager.AppSettings["ParameterMetaDataXMLFileName"]), null))
{
objXmlTextWriter.Formatting = Formatting.Indented;
objXmlTextWriter.WriteStartDocument();
@ -100,7 +99,7 @@ namespace ArdupilotMega.Utilities
private static void ParseParameterInformation(string fileContents, XmlTextWriter objXmlTextWriter)
{
var indicies = new List<int>();
GetIndexOfMarkers(ref indicies, fileContents, META_DELIMETER + PARAM_KEY, 0);
GetIndexOfMarkers(ref indicies, fileContents, ParameterMetaDataConstants.Delimeter + ParameterMetaDataConstants.Param, 0);
if(indicies.Count > 0)
{
@ -115,7 +114,7 @@ namespace ArdupilotMega.Utilities
if(!String.IsNullOrEmpty(subStringToSearch))
{
var metaIndicies = new List<int>();
GetIndexOfMarkers(ref metaIndicies, subStringToSearch, META_DELIMETER, 0);
GetIndexOfMarkers(ref metaIndicies, subStringToSearch, ParameterMetaDataConstants.Delimeter, 0);
if(metaIndicies.Count > 0)
{
@ -125,7 +124,7 @@ namespace ArdupilotMega.Utilities
// Match based on the regex defined at the top of this class
Match paramNameKeyMatch = _paramMetaRegex.Match(paramNameKey);
if (paramNameKeyMatch.Success && paramNameKeyMatch.Groups["MetaKey"].Value == PARAM_KEY)
if (paramNameKeyMatch.Success && paramNameKeyMatch.Groups["MetaKey"].Value == ParameterMetaDataConstants.Param)
{
objXmlTextWriter.WriteStartElement(paramNameKeyMatch.Groups["MetaValue"].Value.Trim(new char[] { ' ' }));

View File

@ -0,0 +1,40 @@
using System;
using System.Configuration;
using System.IO;
using System.Windows.Forms;
using System.Xml.Linq;
namespace ArdupilotMega.Utilities
{
public class ParameterMetaDataRepository
{
private static XDocument _parameterMetaDataXML;
/// <summary>
/// Initializes a new instance of the <see cref="ParameterMetaDataRepository"/> class.
/// </summary>
public ParameterMetaDataRepository()
{
string paramMetaDataXMLFileName = String.Format("{0}\\{1}", Application.StartupPath, ConfigurationManager.AppSettings["ParameterMetaDataXMLFileName"]);
if (File.Exists(paramMetaDataXMLFileName))
_parameterMetaDataXML = XDocument.Load(paramMetaDataXMLFileName);
}
/// <summary>
/// Gets the parameter meta data.
/// </summary>
/// <param name="nodeKey">The node key.</param>
/// <param name="metaKey">The meta key.</param>
/// <returns></returns>
public string GetParameterMetaData(string nodeKey, string metaKey)
{
if(_parameterMetaDataXML != null)
{
// Use this to find the endpoint node we are looking for
// Either it will be pulled from a file in the ArduPlane hierarchy or the ArduCopter hierarchy
string endpointSearchString = (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane) ? "arduplane" : "arducopter";
}
return string.Empty;
}
}
}

View File

@ -10,6 +10,8 @@
value="http://ardupilot-mega.googlecode.com/git/Tools/ArdupilotMegaPlanner/bin/Release/"/>
<add key="ParameterLocations"
value="http://a432511-wip.googlecode.com/git-history/param-suffix/ArduCopter/Parameters.pde"/>
<add key="ParameterMetaDataXMLFileName"
value="ParameterMetaData.xml"/>
</appSettings>
<log4net>
<appender name="Console" type="log4net.Appender.ConsoleAppender">