QGCUASParamManager.cc 2.9 KB
Newer Older
1 2
#include "QGCUASParamManager.h"

tstellanova's avatar
tstellanova committed
3 4 5 6
#include <QApplication>>
#include <QDir>

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

9 10
QGCUASParamManager::QGCUASParamManager(UASInterface* uas, QWidget *parent) :
    QWidget(parent),
tstellanova's avatar
tstellanova committed
11 12 13
    mav(uas),
    paramDataModel(NULL),
    paramCommsMgr(NULL)
14
{
15
    paramDataModel = uas->getParamDataModel();
tstellanova's avatar
tstellanova committed
16 17 18 19 20
    paramCommsMgr = uas->getParamCommsMgr();
    mav->setParamManager(this);

    // Load default values and tooltips
    loadParamMetaInfoCSV();
21 22 23
}


24 25
bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
26
    return paramDataModel->getOnboardParamValue(component,parameter,value);
tstellanova's avatar
tstellanova committed
27
}
28

tstellanova's avatar
tstellanova committed
29

30 31 32
void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter)
{
    if (mav) {
tstellanova's avatar
tstellanova committed
33
        paramCommsMgr->requestParameterUpdate(component,parameter);
34 35 36
    }
}

tstellanova's avatar
tstellanova committed
37 38


tstellanova's avatar
tstellanova committed
39 40 41 42 43 44 45 46 47
/**
 * Send a request to deliver the list of onboard parameters
 * to the MAV.
 */
void QGCUASParamManager::requestParameterList()
{
    if (!mav) {
        return;
    }
tstellanova's avatar
tstellanova committed
48
    //paramDataModel->forgetAllOnboardParameters(); //TODO really??
tstellanova's avatar
tstellanova committed
49
    setParameterStatusMsg(tr("Requested param list.. waiting"));
tstellanova's avatar
tstellanova committed
50
    paramCommsMgr->requestParameterList();
tstellanova's avatar
tstellanova committed
51
}
52 53 54 55 56 57 58 59 60 61 62 63 64


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

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


65
void QGCUASParamManager::setParameter(int compId, QString paramName, QVariant value)
tstellanova's avatar
tstellanova committed
66
{
67 68
    //paramCommsMgr->setParameter(compId,paramName,value);
    paramDataModel->updatePendingParamWithValue(compId,paramName,value);
tstellanova's avatar
tstellanova committed
69
}
tstellanova's avatar
tstellanova committed
70

tstellanova's avatar
tstellanova committed
71 72 73 74 75
void QGCUASParamManager::sendPendingParameters()
{
    paramCommsMgr->sendPendingParameters();
}

76 77
void QGCUASParamManager::setPendingParam(int compId,  QString& paramName,  const QVariant& value)
{
78
    paramDataModel->updatePendingParamWithValue(compId,paramName,value);
79 80
}

tstellanova's avatar
tstellanova committed
81

tstellanova's avatar
tstellanova committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

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;
}