mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Merge remote-tracking branch 'origin/naiiawah/OP-595' into next
This commit is contained in:
commit
686d5f2dcf
@ -492,6 +492,45 @@ QVariant UAVObjectField::getValue(quint32 index)
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool UAVObjectField::checkValue(const QVariant& value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Get metadata
|
||||
UAVObject::Metadata mdata = obj->getMetadata();
|
||||
// Update value if the access mode permits
|
||||
if ( mdata.gcsAccess == UAVObject::ACCESS_READWRITE )
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
case INT16:
|
||||
case INT32:
|
||||
case UINT8:
|
||||
case UINT16:
|
||||
case UINT32:
|
||||
case FLOAT32:
|
||||
case STRING:
|
||||
return true;
|
||||
break;
|
||||
case ENUM:
|
||||
{
|
||||
qint8 tmpenum = options.indexOf( value.toString() );
|
||||
return ((tmpenum < 0) ? false : true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qDebug() << "checkValue: other types" << type;
|
||||
Q_ASSERT(0); // To catch any programming errors where we tried to test invalid values
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectField::setValue(const QVariant& value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
QVariant getValue(quint32 index = 0);
|
||||
bool checkValue(const QVariant& data, quint32 index = 0);
|
||||
void setValue(const QVariant& data, quint32 index = 0);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
|
@ -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,24 @@ void UAVSettingsImportExportFactory::importUAVSettings()
|
||||
if (uavfield) {
|
||||
QStringList list = f.attribute("values").split(",");
|
||||
if (list.length() == 1) {
|
||||
uavfield->setValue(f.attribute("values"));
|
||||
if (false == uavfield->checkValue(f.attribute("values"))) {
|
||||
qDebug() << "checkValue returned false on: " << uavObjectName << f.attribute("values");
|
||||
setError = true;
|
||||
} else
|
||||
uavfield->setValue(f.attribute("values"));
|
||||
} 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->checkValue(element,i)) {
|
||||
qDebug() << "checkValue(list) returned false on: " << uavObjectName << list;
|
||||
setError = true;
|
||||
} else
|
||||
uavfield->setValue(element,i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
error = false;
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
@ -183,7 +192,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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user