From 40cff93f65f90c4e89b35945a08cbbf242db3f32 Mon Sep 17 00:00:00 2001 From: Bryan Godbolt Date: Mon, 13 Sep 2010 15:45:29 -0600 Subject: [PATCH] Parameter List for Opal-RT is now read from an XML file --- qgroundcontrol.pro | 4 +- settings/ParameterList.xml | 76 ++++++++++++++ src/comm/OpalRT.h | 6 +- src/comm/Parameter.cc | 12 ++- src/comm/Parameter.h | 9 +- src/comm/ParameterList.cc | 198 ++++++++++++++++++++++++++++--------- src/comm/ParameterList.h | 19 +++- src/comm/ParameterList.xml | 25 ----- src/ui/MainWindow.ui | 44 ++++----- 9 files changed, 288 insertions(+), 105 deletions(-) create mode 100644 settings/ParameterList.xml delete mode 100644 src/comm/ParameterList.xml diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 4c409bd9e..edb59b6b4 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -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 diff --git a/settings/ParameterList.xml b/settings/ParameterList.xml new file mode 100644 index 000000000..3894080f4 --- /dev/null +++ b/settings/ParameterList.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/comm/OpalRT.h b/src/comm/OpalRT.h index e2c64a7ff..678c44f17 100644 --- a/src/comm/OpalRT.h +++ b/src/comm/OpalRT.h @@ -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 diff --git a/src/comm/Parameter.cc b/src/comm/Parameter.cc index 6f97f0c53..512982e01 100644 --- a/src/comm/Parameter.cc +++ b/src/comm/Parameter.cc @@ -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)), diff --git a/src/comm/Parameter.h b/src/comm/Parameter.h index 48abc6d6a..695cd8a79 100644 --- a/src/comm/Parameter.h +++ b/src/comm/Parameter.h @@ -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); diff --git a/src/comm/ParameterList.cc b/src/comm/ParameterList.cc index 7ffc66d68..0b1d37624 100644 --- a/src/comm/ParameterList.cc +++ b/src/comm/ParameterList.cc @@ -34,9 +34,16 @@ ParameterList::ParameterList() :params(new QMap >), paramList(new QList >()) { -// params = new QMap >; - /* 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 *opalParams = new QMap; - getParameterList(opalParams); - - /* Iterate over the parameters we want to use in qgc and populate their ids */ - QMap >::iterator componentIter; - QMap::iterator paramIter; - QString s; - for (componentIter = params->begin(); componentIter != params->end(); ++componentIter) - { - paramList->append(QList()); - 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 *opalParams = new QMap; + getParameterList(opalParams); + + /* Iterate over the parameters we want to use in qgc and populate their ids */ + QMap >::iterator componentIter; + QMap::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()); + 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(¶mFile); + + 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(id), + QGCParamID(e.attribute("QGCParamID"))); + (*params)[id].insert(p->getParamID(), *p); + delete p; + } + else + { + qDebug() << __FILE__ << ":" << __LINE__ << ": error in xml doc"; + } + } + +} diff --git a/src/comm/ParameterList.h b/src/comm/ParameterList.h index a674f8ce9..f93ffac77 100644 --- a/src/comm/ParameterList.h +++ b/src/comm/ParameterList.h @@ -26,6 +26,11 @@ This file is part of the QGROUNDCONTROL project #include #include +#include +#include +#include +#include +#include #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* 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 diff --git a/src/comm/ParameterList.xml b/src/comm/ParameterList.xml deleted file mode 100644 index 78d3b5af8..000000000 --- a/src/comm/ParameterList.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - avionics_src/sm_ampro/NAV_FILT_INIT/ - Value - NAV_FILT_INIT - - - - - - - - - - - - - - - - - - diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 49c27902d..7a936e1e7 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -38,7 +38,7 @@ 0 0 1000 - 22 + 23 @@ -113,7 +113,7 @@ - + :/images/actions/system-log-out.svg:/images/actions/system-log-out.svg @@ -125,7 +125,7 @@ - + :/images/categories/preferences-system.svg :/images/categories/preferences-system.svg:/images/categories/preferences-system.svg @@ -138,7 +138,7 @@ - + :/images/control/launch.svg :/images/control/launch.svg:/images/control/launch.svg @@ -148,7 +148,7 @@ - + :/images/control/land.svg:/images/control/land.svg @@ -173,7 +173,7 @@ - + :/images/actions/list-add.svg:/images/actions/list-add.svg @@ -182,7 +182,7 @@ - + :/images/categories/applications-system.svg:/images/categories/applications-system.svg @@ -194,7 +194,7 @@ - + :/images/apps/utilities-system-monitor.svg:/images/apps/utilities-system-monitor.svg @@ -203,7 +203,7 @@ - + :/images/status/weather-overcast.svg:/images/status/weather-overcast.svg @@ -212,7 +212,7 @@ - + :/images/categories/applications-internet.svg:/images/categories/applications-internet.svg @@ -221,7 +221,7 @@ - + :/images/devices/input-gaming.svg:/images/devices/input-gaming.svg @@ -230,7 +230,7 @@ - + :/images/status/network-wireless-encrypted.svg:/images/status/network-wireless-encrypted.svg @@ -242,7 +242,7 @@ - + :/images/categories/preferences-system.svg:/images/categories/preferences-system.svg @@ -257,7 +257,7 @@ true - + :/images/control/launch.svg:/images/control/launch.svg @@ -269,7 +269,7 @@ - + :/images/status/network-transmit-receive.svg:/images/status/network-transmit-receive.svg @@ -278,7 +278,7 @@ - + :/images/devices/network-wired.svg:/images/devices/network-wired.svg @@ -287,7 +287,7 @@ - + :/images/categories/applications-internet.svg:/images/categories/applications-internet.svg @@ -296,7 +296,7 @@ - + :/images/apps/utilities-system-monitor.svg:/images/apps/utilities-system-monitor.svg @@ -305,7 +305,7 @@ - + :/images/status/software-update-available.svg:/images/status/software-update-available.svg @@ -314,7 +314,7 @@ - + :/images/categories/preferences-system.svg:/images/categories/preferences-system.svg @@ -323,9 +323,7 @@ - - - + actionExit -- 2.22.0