Skip to content
QGCUASParamManager.cc 2.83 KiB
Newer Older
#include "QGCUASParamManager.h"

tstellanova's avatar
tstellanova committed
#include <QApplication>>
#include <QDir>

#include "UASInterface.h"
tstellanova's avatar
tstellanova committed
#include "UASParameterCommsMgr.h"

QGCUASParamManager::QGCUASParamManager(UASInterface* uas, QWidget *parent) :
    QWidget(parent),
tstellanova's avatar
tstellanova committed
    mav(uas),
    paramDataModel(NULL),
    paramCommsMgr(NULL)
    paramDataModel = uas->getParamDataModel();
tstellanova's avatar
tstellanova committed
    paramCommsMgr = uas->getParamCommsMgr();
    mav->setParamManager(this);

    // Load default values and tooltips
    loadParamMetaInfoCSV();
bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
    return paramDataModel->getOnboardParamValue(component,parameter,value);
tstellanova's avatar
tstellanova committed
}
tstellanova's avatar
tstellanova committed

void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter)
{
    if (mav) {
tstellanova's avatar
tstellanova committed
        paramCommsMgr->requestParameterUpdate(component,parameter);
tstellanova's avatar
tstellanova committed
/**
 * Send a request to deliver the list of onboard parameters
 * to the MAV.
 */
void QGCUASParamManager::requestParameterList()
{
    if (!mav) {
        return;
    }
    setParameterStatusMsg(tr("Requested param list.. waiting"));
tstellanova's avatar
tstellanova committed
    paramCommsMgr->requestParameterList();
tstellanova's avatar
tstellanova committed
}


void QGCUASParamManager::setParameterStatusMsg(const QString& msg)
{
    qDebug() << "parameterStatusMsg: " << msg;
    parameterStatusMsg = msg;
}

void QGCUASParamManager::setParamDescriptions(const QMap<QString,QString>& paramInfo) {
    paramDataModel->setParamDescriptions(paramInfo);
}


void QGCUASParamManager::setParameter(int compId, QString paramName, QVariant value)
tstellanova's avatar
tstellanova committed
{
    //paramCommsMgr->setParameter(compId,paramName,value);
    paramDataModel->updatePendingParamWithValue(compId,paramName,value);
tstellanova's avatar
tstellanova committed
}
tstellanova's avatar
tstellanova committed
void QGCUASParamManager::sendPendingParameters()
{
    paramCommsMgr->sendPendingParameters();
}

void QGCUASParamManager::setPendingParam(int compId,  QString& paramName,  const QVariant& value)
{
    paramDataModel->updatePendingParamWithValue(compId,paramName,value);
tstellanova's avatar
tstellanova committed

tstellanova's avatar
tstellanova committed

void QGCUASParamManager::loadParamMetaInfoCSV()
{
    // Load default values and tooltips
    QString autopilot(mav->getAutopilotTypeName());

    QDir appDir = QApplication::applicationDirPath();
    appDir.cd("files");
    QString fileName = QString("%1/%2/parameter_tooltips/tooltips.txt").arg(appDir.canonicalPath()).arg(autopilot.toLower());
    QFile paramMetaFile(fileName);

    qDebug() << "loadParamMetaInfoCSV for autopilot: " << autopilot << " from file: " << fileName;

    if (!paramMetaFile.open(QIODevice::ReadOnly | QIODevice::Text))  {
        qWarning() << "loadParamMetaInfoCSV couldn't open:" << fileName;
        return;
    }

    QTextStream in(&paramMetaFile);
    paramDataModel->loadParamMetaInfoFromStream(in);
    paramMetaFile.close();

}

/**
 * @return The MAV of this mgr. Unless the MAV object has been destroyed, this
 *         pointer is never zero.
 */
UASInterface* QGCUASParamManager::getUAS()
{
    return mav;
}