Commit cc11e3af authored by Lorenz Meier's avatar Lorenz Meier

Fixed param loading

parent d79828ac
...@@ -25,7 +25,8 @@ This file is part of the QGROUNDCONTROL project ...@@ -25,7 +25,8 @@ This file is part of the QGROUNDCONTROL project
* @brief Implementation of class QGCParamWidget * @brief Implementation of class QGCParamWidget
* @author Lorenz Meier <mail@qgroundcontrol.org> * @author Lorenz Meier <mail@qgroundcontrol.org>
*/ */
#include <cmath>
#include <float.h>
#include <QGridLayout> #include <QGridLayout>
#include <QPushButton> #include <QPushButton>
#include <QFileDialog> #include <QFileDialog>
...@@ -38,6 +39,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -38,6 +39,7 @@ This file is part of the QGROUNDCONTROL project
#include "QGCParamWidget.h" #include "QGCParamWidget.h"
#include "UASInterface.h" #include "UASInterface.h"
#include "MainWindow.h"
#include <QDebug> #include <QDebug>
#include "QGC.h" #include "QGC.h"
...@@ -364,7 +366,7 @@ void QGCParamWidget::addParameter(int uas, int component, int paramCount, int pa ...@@ -364,7 +366,7 @@ void QGCParamWidget::addParameter(int uas, int component, int paramCount, int pa
// There is only one transmission timeout for all components // There is only one transmission timeout for all components
// since components do not manage their transmission, // since components do not manage their transmission,
// the longest timeout is safe for all components. // 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) if (thisTransmissionTimeout > transmissionTimeout)
{ {
transmissionTimeout = thisTransmissionTimeout; transmissionTimeout = thisTransmissionTimeout;
...@@ -490,19 +492,19 @@ void QGCParamWidget::addParameter(int uas, int component, QString parameterName, ...@@ -490,19 +492,19 @@ void QGCParamWidget::addParameter(int uas, int component, QString parameterName,
// Get component // Get component
if (!components->contains(component)) if (!components->contains(component))
{ {
// QString componentName; // QString componentName;
// switch (component) // switch (component)
// { // {
// case MAV_COMP_ID_CAMERA: // case MAV_COMP_ID_CAMERA:
// componentName = tr("Camera (#%1)").arg(component); // componentName = tr("Camera (#%1)").arg(component);
// break; // break;
// case MAV_COMP_ID_IMU: // case MAV_COMP_ID_IMU:
// componentName = tr("IMU (#%1)").arg(component); // componentName = tr("IMU (#%1)").arg(component);
// break; // break;
// default: // default:
// componentName = tr("Component #").arg(component); // componentName = tr("Component #").arg(component);
// break; // break;
// } // }
QString componentName = tr("Component #%1").arg(component); QString componentName = tr("Component #%1").arg(component);
addComponent(uas, component, componentName); addComponent(uas, component, componentName);
} }
...@@ -766,8 +768,7 @@ void QGCParamWidget::loadParameters() ...@@ -766,8 +768,7 @@ void QGCParamWidget::loadParameters()
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return; return;
// Clear list bool userWarned = false;
clear();
QTextStream in(&file); QTextStream in(&file);
while (!in.atEnd()) { while (!in.atEnd()) {
...@@ -776,40 +777,58 @@ void QGCParamWidget::loadParameters() ...@@ -776,40 +777,58 @@ void QGCParamWidget::loadParameters()
QStringList wpParams = line.split("\t"); QStringList wpParams = line.split("\t");
if (wpParams.size() == 5) { if (wpParams.size() == 5) {
// Only load parameters for right mav // 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 <READ> to revert to the parameters that are currently onboard").arg(fileName).arg(wpParams.at(0).toInt()).arg(mav->getUASID()));
userWarned = true;
}
bool changed = false; bool changed = false;
int component = wpParams.at(1).toInt(); int component = wpParams.at(1).toInt();
QString parameterName = wpParams.at(2); 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()) { if (!parameters.contains(component) ||
fabs((static_cast<float>(parameters.value(component)->value(parameterName, wpParams.at(3).toDouble()).toDouble())) - (wpParams.at(3).toDouble())) > 2.0f * FLT_EPSILON) {
changed = true; changed = true;
qDebug() << "Changed" << parameterName << "VAL" << wpParams.at(3).toDouble();
} }
// Set parameter value // Set parameter value
addParameter(wpParams.at(0).toInt(), wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toDouble());
if (changed) {
// Create changed values data structure if necessary // Create changed values data structure if necessary
if (!changedValues.contains(wpParams.at(1).toInt())) { if (changed && !changedValues.contains(wpParams.at(1).toInt())) {
changedValues.insert(wpParams.at(1).toInt(), new QMap<QString, QVariant>()); changedValues.insert(wpParams.at(1).toInt(), new QMap<QString, QVariant>());
} }
// Add to changed values // Add to changed values
if (changedValues.value(wpParams.at(1).toInt())->contains(wpParams.at(2))) { if (changed && changedValues.value(wpParams.at(1).toInt())->contains(wpParams.at(2))) {
changedValues.value(wpParams.at(1).toInt())->remove(wpParams.at(2)); changedValues.value(wpParams.at(1).toInt())->remove(wpParams.at(2));
} }
switch (wpParams.at(3).toUInt()) switch (wpParams.at(4).toUInt())
{ {
case MAV_PARAM_TYPE_REAL32: 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()); 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; break;
case MAV_PARAM_TYPE_UINT32: 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()); 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; break;
case MAV_PARAM_TYPE_INT32: 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()); 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; 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"; //qDebug() << "MARKING COMP" << wpParams.at(1).toInt() << "PARAM" << wpParams.at(2) << "VALUE" << (float)wpParams.at(3).toDouble() << "AS CHANGED";
...@@ -820,8 +839,6 @@ void QGCParamWidget::loadParameters() ...@@ -820,8 +839,6 @@ void QGCParamWidget::loadParameters()
} }
} }
} }
}
}
file.close(); file.close();
} }
...@@ -1010,11 +1027,20 @@ void QGCParamWidget::setParameter(int component, QString parameterName, QVariant ...@@ -1010,11 +1027,20 @@ void QGCParamWidget::setParameter(int component, QString parameterName, QVariant
transmissionMissingWriteAckPackets.value(component)->insert(parameterName, value); transmissionMissingWriteAckPackets.value(component)->insert(parameterName, value);
// Set timeouts // Set timeouts
transmissionActive = true; if (transmissionActive)
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + 5*rewriteTimeout; {
if (newTransmissionTimeout > transmissionTimeout) { transmissionTimeout += rewriteTimeout;
}
else
{
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + rewriteTimeout;
if (newTransmissionTimeout > transmissionTimeout)
{
transmissionTimeout = newTransmissionTimeout; transmissionTimeout = newTransmissionTimeout;
} }
transmissionActive = true;
}
// Enable guard / reset timeouts // Enable guard / reset timeouts
setRetransmissionGuardEnabled(true); setRetransmissionGuardEnabled(true);
} }
...@@ -1046,11 +1072,18 @@ void QGCParamWidget::setParameters() ...@@ -1046,11 +1072,18 @@ void QGCParamWidget::setParameters()
} else { } else {
statusLabel->setText(tr("Transmitting %1 parameters.").arg(parametersSent)); statusLabel->setText(tr("Transmitting %1 parameters.").arg(parametersSent));
// Set timeouts // Set timeouts
if (transmissionActive)
{
transmissionTimeout += parametersSent*rewriteTimeout;
}
else
{
transmissionActive = true; transmissionActive = true;
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + (parametersSent/retransmissionBurstRequestSize+5)*rewriteTimeout; quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + parametersSent*rewriteTimeout;
if (newTransmissionTimeout > transmissionTimeout) { if (newTransmissionTimeout > transmissionTimeout) {
transmissionTimeout = newTransmissionTimeout; transmissionTimeout = newTransmissionTimeout;
} }
}
// Enable guard // Enable guard
setRetransmissionGuardEnabled(true); setRetransmissionGuardEnabled(true);
} }
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Recv. Loss</string> <string>MAV RX Loss</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -204,7 +204,7 @@ ...@@ -204,7 +204,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Send Loss</string> <string>MAV TX Loss</string>
</property> </property>
</widget> </widget>
</item> </item>
......
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