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
* @brief Implementation of class QGCParamWidget
* @author Lorenz Meier <mail@qgroundcontrol.org>
*/
#include <cmath>
#include <float.h>
#include <QGridLayout>
#include <QPushButton>
#include <QFileDialog>
......@@ -38,6 +39,7 @@ This file is part of the QGROUNDCONTROL project
#include "QGCParamWidget.h"
#include "UASInterface.h"
#include "MainWindow.h"
#include <QDebug>
#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);
}
......@@ -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,40 +777,58 @@ 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 <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;
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()) {
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;
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());
if (changed) {
// 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>());
}
// 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));
}
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());
setParameter(wpParams.at(1).toInt(), wpParams.at(2), wpParams.at(3).toFloat());
qDebug() << "FLOAT PARAM CHANGED";
}
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());
setParameter(wpParams.at(1).toInt(), wpParams.at(2), QVariant(wpParams.at(3).toUInt()));
}
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());
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";
......@@ -820,8 +839,6 @@ void QGCParamWidget::loadParameters()
}
}
}
}
}
file.close();
}
......@@ -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) {
if (transmissionActive)
{
transmissionTimeout += rewriteTimeout;
}
else
{
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + rewriteTimeout;
if (newTransmissionTimeout > transmissionTimeout)
{
transmissionTimeout = newTransmissionTimeout;
}
transmissionActive = true;
}
// Enable guard / reset timeouts
setRetransmissionGuardEnabled(true);
}
......@@ -1046,11 +1072,18 @@ void QGCParamWidget::setParameters()
} else {
statusLabel->setText(tr("Transmitting %1 parameters.").arg(parametersSent));
// Set timeouts
if (transmissionActive)
{
transmissionTimeout += parametersSent*rewriteTimeout;
}
else
{
transmissionActive = true;
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + (parametersSent/retransmissionBurstRequestSize+5)*rewriteTimeout;
quint64 newTransmissionTimeout = QGC::groundTimeMilliseconds() + parametersSent*rewriteTimeout;
if (newTransmissionTimeout > transmissionTimeout) {
transmissionTimeout = newTransmissionTimeout;
}
}
// Enable guard
setRetransmissionGuardEnabled(true);
}
......
......@@ -118,7 +118,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Recv. Loss</string>
<string>MAV RX Loss</string>
</property>
</widget>
</item>
......@@ -204,7 +204,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Send Loss</string>
<string>MAV TX Loss</string>
</property>
</widget>
</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