Commit 40cff93f authored by Bryan Godbolt's avatar Bryan Godbolt

Parameter List for Opal-RT is now read from an XML file

parent 6435a4ee
......@@ -18,8 +18,8 @@ TARGET = qgroundcontrol
BASEDIR = .
BUILDDIR = build
LANGUAGE = C++
CONFIG += release #debug_and_release \
#console
CONFIG += debug_and_release \
console
OBJECTS_DIR = $$BUILDDIR/obj
MOC_DIR = $$BUILDDIR/moc
UI_HEADERS_DIR = src/ui/generated
......
<ParameterList version="0.1">
<!-- Parameters in the top level block -->
<Block name="TopLevel">
<Parameter>
</Parameter>
</Block>
<!--Parameters related to the navigation block -->
<Block name="Navigation">
<Parameter
SimulinkPath="avionics_src/sm_avionics/Navigation_Filter/NAV_FILT_INIT/"
SimulinkParameterName="Value"
QGCParamID="NAV_FILT_INIT"
/>
</Block>
<!--Parameters related to the controller block -->
<Block name="Controller">
</Block>
<!-- Paremters for the Pilot Input/Raw RC block -->
<Block name="ServoInputs">
</Block>
<!-- Parameters for the servo output block -->
<Block name="ServoOutputs">
<!-- Settings for Aileron Servo -->
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/AileronOutput/"
SimulinkParameterName="Low"
QGCParamID="AIL_LOW_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/AileronOutput/"
SimulinkParameterName="Center"
QGCParamID="AIL_CENTER_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/AileronOutput/"
SimulinkParameterName="High"
QGCParamID="AIL_HIGH_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/AileronOutput/"
SimulinkParameterName="Reverse"
QGCParamID="AIL_REV_OUT"
/>
<!-- Settings for Elevator Servo -->
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/ElevatorOutput/"
SimulinkParameterName="Low"
QGCParamID="ELE_LOW_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/ElevatorOutput/"
SimulinkParameterName="Center"
QGCParamID="ELE_CENTER_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/ElevatorOutput/"
SimulinkParameterName="High"
QGCParamID="ELE_HIGH_OUT"
/>
<Parameter
SimulinkPath="avionics_src/sm_avionics/Servo_Outputs/ElevatorOutput/"
SimulinkParameterName="Reverse"
QGCParamID="ELE_REV_OUT"
/>
</Block>
</ParameterList>
......@@ -95,8 +95,10 @@ namespace OpalRT
enum SubsystemIds
{
NAV_ID = 1,
LOG_ID = 1,
CONTROLLER_ID = 1
LOG_ID,
CONTROLLER_ID,
SERVO_OUTPUTS,
SERVO_INPUTS
};
class OpalErrorMsg
......
......@@ -29,7 +29,17 @@ This file is part of the QGROUNDCONTROL project
#include "Parameter.h"
using namespace OpalRT;
Parameter::Parameter(char *simulinkPath, char *simulinkName, uint8_t componentID,
//Parameter::Parameter(char *simulinkPath, char *simulinkName, uint8_t componentID,
// QGCParamID paramID, unsigned short opalID)
// : simulinkPath(new QString(simulinkPath)),
// simulinkName(new QString(simulinkName)),
// componentID(componentID),
// paramID(new QGCParamID(paramID)),
// opalID(opalID)
//
//{
//}
Parameter::Parameter(QString simulinkPath, QString simulinkName, uint8_t componentID,
QGCParamID paramID, unsigned short opalID)
: simulinkPath(new QString(simulinkPath)),
simulinkName(new QString(simulinkName)),
......
......@@ -46,8 +46,13 @@ namespace OpalRT
class Parameter
{
public:
Parameter(char *simulinkPath = "",
char *simulinkName = "",
// Parameter(char *simulinkPath = "",
// char *simulinkName = "",
// uint8_t componentID = 0,
// QGCParamID paramID = QGCParamID(),
// unsigned short opalID = 0);
Parameter(QString simulinkPath = QString(),
QString simulinkName = QString(),
uint8_t componentID = 0,
QGCParamID paramID = QGCParamID(),
unsigned short opalID = 0);
......
......@@ -34,9 +34,16 @@ ParameterList::ParameterList()
:params(new QMap<int, QMap<QGCParamID, Parameter> >),
paramList(new QList<QList<Parameter*> >())
{
// params = new QMap<int, QMap<QGCParamID, Parameter> >;
/* Populate the map with parameter names. There is no elegant way of doing this so all
QDir settingsDir = QDir(qApp->applicationDirPath());
if (settingsDir.dirName() == "bin")
settingsDir.cdUp();
settingsDir.cd("settings");
QString filename(settingsDir.path() + "/ParameterList.xml");
if ((QFile::exists(filename)) && open(filename))
{
/* Populate the map with parameter names. There is no elegant way of doing this so all
parameter paths and names must be known at compile time and defined here.
Note: This function is written in a way that calls a lot of copy constructors and is
therefore not particularly efficient. However since it is only called once memory
......@@ -44,58 +51,58 @@ ParameterList::ParameterList()
parameters.
When defining the path, the trailing slash is necessary
*/
Parameter *p;
/* Component: Navigation Filter */
p = new Parameter("avionics_src/sm_ampro/NAV_FILT_INIT/",
"Value",
OpalRT::NAV_ID,
QGCParamID("NAV_FILT_INIT"));
(*params)[OpalRT::NAV_ID].insert(p->getParamID(), *p);
delete p;
p = new Parameter("avionics_src/sm_ampro/Gain/",
"Gain",
OpalRT::NAV_ID,
QGCParamID("TEST_OUTP_GAIN"));
(*params)[OpalRT::NAV_ID].insert(p->getParamID(), *p);
delete p;
/* Component: Log Facility */
p = new Parameter("avionics_src/sm_ampro/LOG_FILE_ON/",
"Value",
OpalRT::LOG_ID,
QGCParamID("LOG_FILE_ON"));
(*params)[OpalRT::LOG_ID].insert(p->getParamID(), *p);
delete p;
/* Get a list of the available parameters from opal-rt */
QMap<QString, unsigned short> *opalParams = new QMap<QString, unsigned short>;
getParameterList(opalParams);
/* Iterate over the parameters we want to use in qgc and populate their ids */
QMap<int, QMap<QGCParamID, Parameter> >::iterator componentIter;
QMap<QGCParamID, Parameter>::iterator paramIter;
QString s;
for (componentIter = params->begin(); componentIter != params->end(); ++componentIter)
{
paramList->append(QList<Parameter*>());
for (paramIter = (*componentIter).begin(); paramIter != (*componentIter).end(); ++paramIter)
// Parameter *p;
// /* Component: Navigation Filter */
// p = new Parameter("avionics_src/sm_ampro/NAV_FILT_INIT/",
// "Value",
// OpalRT::NAV_ID,
// QGCParamID("NAV_FILT_INIT"));
// (*params)[OpalRT::NAV_ID].insert(p->getParamID(), *p);
// delete p;
//
// p = new Parameter("avionics_src/sm_ampro/Gain/",
// "Gain",
// OpalRT::NAV_ID,
// QGCParamID("TEST_OUTP_GAIN"));
// (*params)[OpalRT::NAV_ID].insert(p->getParamID(), *p);
// delete p;
//
// /* Component: Log Facility */
// p = new Parameter("avionics_src/sm_ampro/LOG_FILE_ON/",
// "Value",
// OpalRT::LOG_ID,
// QGCParamID("LOG_FILE_ON"));
// (*params)[OpalRT::LOG_ID].insert(p->getParamID(), *p);
// delete p;
/* Get a list of the available parameters from opal-rt */
QMap<QString, unsigned short> *opalParams = new QMap<QString, unsigned short>;
getParameterList(opalParams);
/* Iterate over the parameters we want to use in qgc and populate their ids */
QMap<int, QMap<QGCParamID, Parameter> >::iterator componentIter;
QMap<QGCParamID, Parameter>::iterator paramIter;
QString s;
for (componentIter = params->begin(); componentIter != params->end(); ++componentIter)
{
paramList->last().append(paramIter.operator ->());
s = (*paramIter).getSimulinkPath() + (*paramIter).getSimulinkName();
if (opalParams->contains(s))
{
(*paramIter).setOpalID(opalParams->value(s));
// qDebug() << __FILE__ << " Line:" << __LINE__ << ": Successfully added " << s;
}
else
paramList->append(QList<Parameter*>());
for (paramIter = (*componentIter).begin(); paramIter != (*componentIter).end(); ++paramIter)
{
qWarning() << __FILE__ << " Line:" << __LINE__ << ": " << s << " was not found in param list";
paramList->last().append(paramIter.operator ->());
s = (*paramIter).getSimulinkPath() + (*paramIter).getSimulinkName();
if (opalParams->contains(s))
{
(*paramIter).setOpalID(opalParams->value(s));
// qDebug() << __FILE__ << " Line:" << __LINE__ << ": Successfully added " << s;
}
else
{
qWarning() << __FILE__ << " Line:" << __LINE__ << ": " << s << " was not found in param list";
}
}
}
delete opalParams;
}
delete opalParams;
}
ParameterList::~ParameterList()
......@@ -245,3 +252,96 @@ int ParameterList::count()
count += (*iter).count();
return count;
}
/* Functions related to reading the xml config file */
bool ParameterList::open(QString filename)
{
QFile paramFile(filename);
if (!paramFile.exists())
{
/// \todo open dialog box (maybe: that could also go in comm config window)
return false;
}
if (!paramFile.open(QIODevice::ReadOnly))
{
return false;
}
read(&paramFile);
return true;
}
bool ParameterList::read(QIODevice *device)
{
QDomDocument *paramConfig = new QDomDocument();
QString errorStr;
int errorLine;
int errorColumn;
if (!paramConfig->setContent(device, true, &errorStr, &errorLine,
&errorColumn))
{
qDebug() << "Error reading XML Parameter File on line: " << errorLine << errorStr;
return false;
}
QDomElement root = paramConfig->documentElement();
if (root.tagName() != "ParameterList") {
qDebug() << __FILE__ << __LINE__ << "This is not a parameter list xml file";
return false;
}
QDomElement child = root.firstChildElement("Block");
while (!child.isNull())
{
parseBlock(child);
child = child.nextSiblingElement("Block");
}
delete paramConfig;
return true;
}
void ParameterList::parseBlock(const QDomElement &block)
{
QDomNodeList paramList;
QDomElement e;
Parameter *p;
SubsystemIds id;
if (block.attribute("name") == "Navigation")
id = OpalRT::NAV_ID;
else if (block.attribute("name") == "Controller")
id = OpalRT::CONTROLLER_ID;
else if (block.attribute("name") == "ServoOutputs")
id = OpalRT::SERVO_OUTPUTS;
else if (block.attribute("name") == "ServoInputs")
id = OpalRT::SERVO_INPUTS;
paramList = block.elementsByTagName("Parameter");
for (int i=0; i < paramList.size(); ++i)
{
e = paramList.item(i).toElement();
if (e.hasAttribute("SimulinkPath") &&
e.hasAttribute("SimulinkParameterName") &&
e.hasAttribute("QGCParamID"))
{
p = new Parameter(e.attribute("SimulinkPath"),
e.attribute("SimulinkParameterName"),
static_cast<uint8_t>(id),
QGCParamID(e.attribute("QGCParamID")));
(*params)[id].insert(p->getParamID(), *p);
delete p;
}
else
{
qDebug() << __FILE__ << ":" << __LINE__ << ": error in xml doc";
}
}
}
......@@ -26,6 +26,11 @@ This file is part of the QGROUNDCONTROL project
#include <QMap>
#include <QVector>
#include <QIODevice>
#include <QFile>
#include <QDir>
#include <QApplication>
#include <QtXml>
#include "mavlink_types.h"
#include "QGCParamID.h"
......@@ -83,7 +88,6 @@ namespace OpalRT
qDebug() << "PID_GAIN is at index " << index;
\endcode
*/
int indexOf(const Parameter& p);
bool contains(int compid, QGCParamID paramid) const {return (*params)[compid].contains(paramid);}
......@@ -120,6 +124,19 @@ namespace OpalRT
\param[out] opalParams Map of parameter paths/names to ids which are valid in Opal-RT
*/
void getParameterList(QMap<QString, unsigned short>* opalParams);
/**
Open a file for reading in the xml config data
*/
bool open(QString filename=QString());
/**
Attempt to read XML configuration data from device
\param[in] the device to read the xml data from
\return true if the configuration was read successfully, false otherwise
*/
bool read(QIODevice *device);
void parseBlock(const QDomElement &block);
};
}
#endif // PARAMETERLIST_H
<ParameterList version="0.1">
<!--Parameters related to the navigation block -->
<Navigation>
<Parameter>
<SimulinkPath>avionics_src/sm_ampro/NAV_FILT_INIT/</SimulinkPath>
<SimulinkParameterName>Value</SimulinkParameterName>
<QGCParamID>NAV_FILT_INIT</QGCParamID>
</Parameter>
</Navigation>
<!--Parameters related to the controller block -->
<Controller>
</Controller>
<!-- Paremters for the Pilot Input/Raw RC block -->
<ServoInputs>
</ServoInputs>
<!-- Parameters for the servo output block -->
<ServoOutputs>
</ServoOutputs>
</ParameterList>
......@@ -38,7 +38,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuMGround">
......@@ -113,7 +113,7 @@
<widget class="QStatusBar" name="statusBar"/>
<action name="actionExit">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/actions/system-log-out.svg</normaloff>:/images/actions/system-log-out.svg</iconset>
</property>
<property name="text">
......@@ -125,7 +125,7 @@
</action>
<action name="actionSettings">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/preferences-system.svg</normaloff>
<normalon>:/images/categories/preferences-system.svg</normalon>:/images/categories/preferences-system.svg</iconset>
</property>
......@@ -138,7 +138,7 @@
</action>
<action name="actionLiftoff">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/control/launch.svg</normaloff>
<normalon>:/images/control/launch.svg</normalon>:/images/control/launch.svg</iconset>
</property>
......@@ -148,7 +148,7 @@
</action>
<action name="actionLand">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/control/land.svg</normaloff>:/images/control/land.svg</iconset>
</property>
<property name="text">
......@@ -173,7 +173,7 @@
</action>
<action name="actionAdd_Link">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/actions/list-add.svg</normaloff>:/images/actions/list-add.svg</iconset>
</property>
<property name="text">
......@@ -182,7 +182,7 @@
</action>
<action name="actionConfiguration">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/applications-system.svg</normaloff>:/images/categories/applications-system.svg</iconset>
</property>
<property name="text">
......@@ -194,7 +194,7 @@
</action>
<action name="actionEngineerView">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/apps/utilities-system-monitor.svg</normaloff>:/images/apps/utilities-system-monitor.svg</iconset>
</property>
<property name="text">
......@@ -203,7 +203,7 @@
</action>
<action name="actionPilotView">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/status/weather-overcast.svg</normaloff>:/images/status/weather-overcast.svg</iconset>
</property>
<property name="text">
......@@ -212,7 +212,7 @@
</action>
<action name="actionStyleConfig">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/applications-internet.svg</normaloff>:/images/categories/applications-internet.svg</iconset>
</property>
<property name="text">
......@@ -221,7 +221,7 @@
</action>
<action name="actionJoystickSettings">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/devices/input-gaming.svg</normaloff>:/images/devices/input-gaming.svg</iconset>
</property>
<property name="text">
......@@ -230,7 +230,7 @@
</action>
<action name="actionOperatorView">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/status/network-wireless-encrypted.svg</normaloff>:/images/status/network-wireless-encrypted.svg</iconset>
</property>
<property name="text">
......@@ -242,7 +242,7 @@
</action>
<action name="action3DView">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/preferences-system.svg</normaloff>:/images/categories/preferences-system.svg</iconset>
</property>
<property name="text">
......@@ -257,7 +257,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/control/launch.svg</normaloff>:/images/control/launch.svg</iconset>
</property>
<property name="text">
......@@ -269,7 +269,7 @@
</action>
<action name="actionShow_full_view">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/status/network-transmit-receive.svg</normaloff>:/images/status/network-transmit-receive.svg</iconset>
</property>
<property name="text">
......@@ -278,7 +278,7 @@
</action>
<action name="actionShow_MAVLink_view">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/devices/network-wired.svg</normaloff>:/images/devices/network-wired.svg</iconset>
</property>
<property name="text">
......@@ -287,7 +287,7 @@
</action>
<action name="actionOnline_documentation">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/applications-internet.svg</normaloff>:/images/categories/applications-internet.svg</iconset>
</property>
<property name="text">
......@@ -296,7 +296,7 @@
</action>
<action name="actionShow_data_analysis_view">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/apps/utilities-system-monitor.svg</normaloff>:/images/apps/utilities-system-monitor.svg</iconset>
</property>
<property name="text">
......@@ -305,7 +305,7 @@
</action>
<action name="actionProject_Roadmap">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/status/software-update-available.svg</normaloff>:/images/status/software-update-available.svg</iconset>
</property>
<property name="text">
......@@ -314,7 +314,7 @@
</action>
<action name="actionCredits_Developers">
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset>
<normaloff>:/images/categories/preferences-system.svg</normaloff>:/images/categories/preferences-system.svg</iconset>
</property>
<property name="text">
......@@ -323,9 +323,7 @@
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="../../mavground.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>actionExit</sender>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment