diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.cpp b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.cpp index 8841429fa..9dcd43208 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.cpp @@ -492,13 +492,13 @@ QVariant UAVObjectField::getValue(quint32 index) return QVariant(); } -void UAVObjectField::setValue(const QVariant& value, quint32 index) +bool UAVObjectField::setValue(const QVariant& value, quint32 index) { QMutexLocker locker(obj->getMutex()); // Check that index is not out of bounds if ( index >= numElements ) { - return; + return false; } // Get metadata UAVObject::Metadata mdata = obj->getMetadata(); @@ -552,8 +552,11 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index) case ENUM: { qint8 tmpenum = options.indexOf( value.toString() ); - Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values - memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement); +// Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values + if(tmpenum < 0) + return false; + else + memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement); break; } case STRING: @@ -570,6 +573,7 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index) } } } + return true; } double UAVObjectField::getDouble(quint32 index) diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.h b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.h index 9ae9d0d72..93c86c6fe 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.h +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectfield.h @@ -56,7 +56,7 @@ public: qint32 pack(quint8* dataOut); qint32 unpack(const quint8* dataIn); QVariant getValue(quint32 index = 0); - void setValue(const QVariant& data, quint32 index = 0); + bool setValue(const QVariant& data, quint32 index = 0); double getDouble(quint32 index = 0); void setDouble(double value, quint32 index = 0); quint32 getDataOffset(); diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp index 285bc7cbf..3733864c2 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexportfactory.cpp @@ -153,6 +153,7 @@ void UAVSettingsImportExportFactory::importUAVSettings() // - Update each field // - Issue and "updated" command bool error=false; + bool setError=false; QDomNode field = node.firstChild(); while(!field.isNull()) { QDomElement f = field.toElement(); @@ -161,16 +162,21 @@ void UAVSettingsImportExportFactory::importUAVSettings() if (uavfield) { QStringList list = f.attribute("values").split(","); if (list.length() == 1) { - uavfield->setValue(f.attribute("values")); + if (false == uavfield->setValue(f.attribute("values"))) { + qDebug() << "setValue returned false on: " << uavObjectName << f.attribute("values"); + setError = true; + } } else { // This is an enum: int i=0; QStringList list = f.attribute("values").split(","); foreach (QString element, list) { - uavfield->setValue(element,i++); + if (false == uavfield->setValue(element,i++)) { + qDebug() << "setValue returned false on: " << uavObjectName << list; + setError = true; + } } } - error = false; } else { error = true; } @@ -183,7 +189,9 @@ void UAVSettingsImportExportFactory::importUAVSettings() } else if (uavObjectID != obj->getObjID()) { qDebug() << "Mismatch for Object " << uavObjectName << uavObjectID << " - " << obj->getObjID(); swui.addLine(uavObjectName, "Warning (ObjectID mismatch)", true); - } else + } else if (setError) { + swui.addLine(uavObjectName, "Warning (Objects field value(s) invalid)", false); + } else swui.addLine(uavObjectName, "OK", true); } }