From cc11e3afed54fcc708b5b1b740f51705ae2ac922 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 22 Oct 2012 16:06:55 +0200 Subject: [PATCH] Fixed param loading --- src/ui/QGCParamWidget.cc | 233 ++++++++++++++++++++++----------------- src/ui/UASInfo.ui | 4 +- 2 files changed, 135 insertions(+), 102 deletions(-) diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index 077425ef4..0b8b23ad9 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -25,7 +25,8 @@ This file is part of the QGROUNDCONTROL project * @brief Implementation of class QGCParamWidget * @author Lorenz Meier */ - +#include +#include #include #include #include @@ -38,6 +39,7 @@ This file is part of the QGROUNDCONTROL project #include "QGCParamWidget.h" #include "UASInterface.h" +#include "MainWindow.h" #include #include "QGC.h" @@ -364,7 +366,7 @@ void QGCParamWidget::addParameter(int uas, int component, int paramCount, int pa // There is only one transmission timeout for all components // since components do not manage their transmission, // the longest timeout is safe for all components. - quint64 thisTransmissionTimeout = QGC::groundTimeMilliseconds() + ((paramCount/retransmissionBurstRequestSize+5)*retransmissionTimeout); + quint64 thisTransmissionTimeout = QGC::groundTimeMilliseconds() + ((paramCount)*retransmissionTimeout); if (thisTransmissionTimeout > transmissionTimeout) { transmissionTimeout = thisTransmissionTimeout; @@ -490,19 +492,19 @@ void QGCParamWidget::addParameter(int uas, int component, QString parameterName, // Get component if (!components->contains(component)) { -// QString componentName; -// switch (component) -// { -// case MAV_COMP_ID_CAMERA: -// componentName = tr("Camera (#%1)").arg(component); -// break; -// case MAV_COMP_ID_IMU: -// componentName = tr("IMU (#%1)").arg(component); -// break; -// default: -// componentName = tr("Component #").arg(component); -// break; -// } + // QString componentName; + // switch (component) + // { + // case MAV_COMP_ID_CAMERA: + // componentName = tr("Camera (#%1)").arg(component); + // break; + // case MAV_COMP_ID_IMU: + // componentName = tr("IMU (#%1)").arg(component); + // break; + // default: + // componentName = tr("Component #").arg(component); + // break; + // } QString componentName = tr("Component #%1").arg(component); addComponent(uas, component, componentName); } @@ -680,22 +682,22 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* current, int column) switch (parameters.value(key)->value(str).type()) { case QVariant::Int: - { - QVariant fixedValue(value.toInt()); - parameters.value(key)->insert(str, fixedValue); - } + { + QVariant fixedValue(value.toInt()); + parameters.value(key)->insert(str, fixedValue); + } break; case QVariant::UInt: - { - QVariant fixedValue(value.toUInt()); - parameters.value(key)->insert(str, fixedValue); - } + { + QVariant fixedValue(value.toUInt()); + parameters.value(key)->insert(str, fixedValue); + } break; case QMetaType::Float: - { - QVariant fixedValue(value.toFloat()); - parameters.value(key)->insert(str, fixedValue); - } + { + QVariant fixedValue(value.toFloat()); + parameters.value(key)->insert(str, fixedValue); + } break; default: qCritical() << "ABORTED PARAM UPDATE, NO VALID QVARIANT TYPE"; @@ -766,8 +768,7 @@ void QGCParamWidget::loadParameters() if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; - // Clear list - clear(); + bool userWarned = false; QTextStream in(&file); while (!in.atEnd()) { @@ -776,49 +777,65 @@ void QGCParamWidget::loadParameters() QStringList wpParams = line.split("\t"); if (wpParams.size() == 5) { // Only load parameters for right mav - if (mav->getUASID() == wpParams.at(0).toInt()) { + if (!userWarned && (mav->getUASID() != wpParams.at(0).toInt())) { + MainWindow::instance()->showCriticalMessage(tr("Parameter loading warning"), tr("The parameters from the file %1 have been saved from system %2, but the currently selected system has the ID %3. If this is unintentional, please click on to revert to the parameters that are currently onboard").arg(fileName).arg(wpParams.at(0).toInt()).arg(mav->getUASID())); + userWarned = true; + } - bool changed = false; - int component = wpParams.at(1).toInt(); - QString parameterName = wpParams.at(2); - if (!parameters.contains(component) || parameters.value(component)->value(parameterName, wpParams.at(3).toDouble()-3.0f) != (float)wpParams.at(3).toDouble()) { - changed = true; - } + bool changed = false; + int component = wpParams.at(1).toInt(); + QString parameterName = wpParams.at(2); + if (!parameters.contains(component) || + fabs((static_cast(parameters.value(component)->value(parameterName, wpParams.at(3).toDouble()).toDouble())) - (wpParams.at(3).toDouble())) > 2.0f * FLT_EPSILON) { + changed = true; + qDebug() << "Changed" << parameterName << "VAL" << wpParams.at(3).toDouble(); + } - // Set parameter value - addParameter(wpParams.at(0).toInt(), wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toDouble()); + // Set parameter value - if (changed) { - // Create changed values data structure if necessary - if (!changedValues.contains(wpParams.at(1).toInt())) { - changedValues.insert(wpParams.at(1).toInt(), new QMap()); - } - - // Add to changed values - if (changedValues.value(wpParams.at(1).toInt())->contains(wpParams.at(2))) { - changedValues.value(wpParams.at(1).toInt())->remove(wpParams.at(2)); - } - - switch (wpParams.at(3).toUInt()) - { - case MAV_PARAM_TYPE_REAL32: - changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toFloat()); - break; - case MAV_PARAM_TYPE_UINT32: - changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toUInt()); - break; - case MAV_PARAM_TYPE_INT32: - changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toInt()); - break; - } - - //qDebug() << "MARKING COMP" << wpParams.at(1).toInt() << "PARAM" << wpParams.at(2) << "VALUE" << (float)wpParams.at(3).toDouble() << "AS CHANGED"; - - // Mark in UI + // Create changed values data structure if necessary + if (changed && !changedValues.contains(wpParams.at(1).toInt())) { + changedValues.insert(wpParams.at(1).toInt(), new QMap()); + } + // Add to changed values + if (changed && changedValues.value(wpParams.at(1).toInt())->contains(wpParams.at(2))) { + changedValues.value(wpParams.at(1).toInt())->remove(wpParams.at(2)); + } + switch (wpParams.at(4).toUInt()) + { + case (int)MAV_PARAM_TYPE_REAL32: + addParameter(wpParams.at(0).toInt(), wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toFloat()); + if (changed) { + changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toFloat()); + setParameter(wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toFloat()); + qDebug() << "FLOAT PARAM CHANGED"; } + break; + case (int)MAV_PARAM_TYPE_UINT32: + addParameter(wpParams.at(0).toInt(), wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toUInt()); + if (changed) { + changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toUInt()); + setParameter(wpParams.at(1).toInt(), wpParams.at(2), QVariant(wpParams.at(3).toUInt())); + } + break; + case (int)MAV_PARAM_TYPE_INT32: + addParameter(wpParams.at(0).toInt(), wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toInt()); + if (changed) { + changedValues.value(wpParams.at(1).toInt())->insert(wpParams.at(2), wpParams.at(3).toInt()); + setParameter(wpParams.at(1).toInt(), wpParams.at(2), QVariant(wpParams.at(3).toInt())); + } + break; + default: + qDebug() << "FAILED LOADING PARAM" << wpParams.at(2) << "NO KNOWN DATA TYPE"; } + + //qDebug() << "MARKING COMP" << wpParams.at(1).toInt() << "PARAM" << wpParams.at(2) << "VALUE" << (float)wpParams.at(3).toDouble() << "AS CHANGED"; + + // Mark in UI + + } } } @@ -909,22 +926,22 @@ void QGCParamWidget::retransmissionGuardTick() switch (parameters.value(component)->value(key).type()) { case QVariant::Int: - { - QVariant fixedValue(value.toInt()); - emit parameterChanged(component, key, fixedValue); - } + { + QVariant fixedValue(value.toInt()); + emit parameterChanged(component, key, fixedValue); + } break; case QVariant::UInt: - { - QVariant fixedValue(value.toUInt()); - emit parameterChanged(component, key, fixedValue); - } + { + QVariant fixedValue(value.toUInt()); + emit parameterChanged(component, key, fixedValue); + } break; case QMetaType::Float: - { - QVariant fixedValue(value.toFloat()); - emit parameterChanged(component, key, fixedValue); - } + { + QVariant fixedValue(value.toFloat()); + emit parameterChanged(component, key, fixedValue); + } break; default: //qCritical() << "ABORTED PARAM RETRANSMISSION, NO VALID QVARIANT TYPE"; @@ -974,25 +991,25 @@ void QGCParamWidget::setParameter(int component, QString parameterName, QVariant switch (parameters.value(component)->value(parameterName).type()) { case QVariant::Int: - { - QVariant fixedValue(value.toInt()); - emit parameterChanged(component, parameterName, fixedValue); - //qDebug() << "PARAM WIDGET SENT:" << fixedValue; - } + { + QVariant fixedValue(value.toInt()); + emit parameterChanged(component, parameterName, fixedValue); + //qDebug() << "PARAM WIDGET SENT:" << fixedValue; + } break; case QVariant::UInt: - { - QVariant fixedValue(value.toUInt()); - emit parameterChanged(component, parameterName, fixedValue); - //qDebug() << "PARAM WIDGET SENT:" << fixedValue; - } + { + QVariant fixedValue(value.toUInt()); + emit parameterChanged(component, parameterName, fixedValue); + //qDebug() << "PARAM WIDGET SENT:" << fixedValue; + } break; case QMetaType::Float: - { - QVariant fixedValue(value.toFloat()); - emit parameterChanged(component, parameterName, fixedValue); - //qDebug() << "PARAM WIDGET SENT:" << fixedValue; - } + { + QVariant fixedValue(value.toFloat()); + emit parameterChanged(component, parameterName, fixedValue); + //qDebug() << "PARAM WIDGET SENT:" << fixedValue; + } break; default: qCritical() << "ABORTED PARAM SEND, NO VALID QVARIANT TYPE"; @@ -1010,11 +1027,20 @@ void QGCParamWidget::setParameter(int component, QString parameterName, QVariant transmissionMissingWriteAckPackets.value(component)->insert(parameterName, value); // Set timeouts - transmissionActive = true; - quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + 5*rewriteTimeout; - if (newTransmissionTimeout > transmissionTimeout) { - transmissionTimeout = newTransmissionTimeout; + if (transmissionActive) + { + transmissionTimeout += rewriteTimeout; + } + else + { + quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + rewriteTimeout; + if (newTransmissionTimeout > transmissionTimeout) + { + transmissionTimeout = newTransmissionTimeout; + } + transmissionActive = true; } + // Enable guard / reset timeouts setRetransmissionGuardEnabled(true); } @@ -1046,10 +1072,17 @@ void QGCParamWidget::setParameters() } else { statusLabel->setText(tr("Transmitting %1 parameters.").arg(parametersSent)); // Set timeouts - transmissionActive = true; - quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + (parametersSent/retransmissionBurstRequestSize+5)*rewriteTimeout; - if (newTransmissionTimeout > transmissionTimeout) { - transmissionTimeout = newTransmissionTimeout; + if (transmissionActive) + { + transmissionTimeout += parametersSent*rewriteTimeout; + } + else + { + transmissionActive = true; + quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + parametersSent*rewriteTimeout; + if (newTransmissionTimeout > transmissionTimeout) { + transmissionTimeout = newTransmissionTimeout; + } } // Enable guard setRetransmissionGuardEnabled(true); diff --git a/src/ui/UASInfo.ui b/src/ui/UASInfo.ui index ee130441b..0912c7fa4 100644 --- a/src/ui/UASInfo.ui +++ b/src/ui/UASInfo.ui @@ -118,7 +118,7 @@ - Recv. Loss + MAV RX Loss @@ -204,7 +204,7 @@ - Send Loss + MAV TX Loss -- 2.22.0