1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

UAVObjects: Bugfixes to BITFIELD type

This commit is contained in:
Corvus Corax 2012-05-15 19:01:32 +02:00
parent 8fc471463d
commit aa7788d04c

View File

@ -136,14 +136,15 @@ void UAVObjectField::limitsInitialize(const QString &limits)
QString value=_value.trimmed(); QString value=_value.trimmed();
switch (type) switch (type)
{ {
case UINT8:
case UINT16:
case UINT32:
case BITFIELD:
lstruc.values.append((quint32)value.toULong());
break;
case INT8: case INT8:
case INT16: case INT16:
case INT32: case INT32:
case UINT8:
lstruc.values.append((quint32)value.toULong());
break;
case UINT16:
case UINT32:
lstruc.values.append((qint32)value.toLong()); lstruc.values.append((qint32)value.toLong());
break; break;
case FLOAT32: case FLOAT32:
@ -193,6 +194,7 @@ bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
case UINT8: case UINT8:
case UINT16: case UINT16:
case UINT32: case UINT32:
case BITFIELD:
foreach (QVariant vars, struc.values) { foreach (QVariant vars, struc.values) {
if(var.toUInt()==vars.toUInt()) if(var.toUInt()==vars.toUInt())
return true; return true;
@ -233,6 +235,7 @@ bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
case UINT8: case UINT8:
case UINT16: case UINT16:
case UINT32: case UINT32:
case BITFIELD:
foreach (QVariant vars, struc.values) { foreach (QVariant vars, struc.values) {
if(var.toUInt()==vars.toUInt()) if(var.toUInt()==vars.toUInt())
return false; return false;
@ -278,6 +281,7 @@ bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
case UINT8: case UINT8:
case UINT16: case UINT16:
case UINT32: case UINT32:
case BITFIELD:
if(!(var.toUInt()>=struc.values.at(0).toUInt() && var.toUInt()<=struc.values.at(1).toUInt())) if(!(var.toUInt()>=struc.values.at(0).toUInt() && var.toUInt()<=struc.values.at(1).toUInt()))
return false; return false;
return true; return true;
@ -319,6 +323,7 @@ bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
case UINT8: case UINT8:
case UINT16: case UINT16:
case UINT32: case UINT32:
case BITFIELD:
if(!(var.toUInt()>=struc.values.at(0).toUInt())) if(!(var.toUInt()>=struc.values.at(0).toUInt()))
return false; return false;
return true; return true;
@ -353,6 +358,7 @@ bool UAVObjectField::isWithinLimits(QVariant var,quint32 index)
case UINT8: case UINT8:
case UINT16: case UINT16:
case UINT32: case UINT32:
case BITFIELD:
if(!(var.toUInt()<=struc.values.at(0).toUInt())) if(!(var.toUInt()<=struc.values.at(0).toUInt()))
return false; return false;
return true; return true;
@ -460,6 +466,8 @@ QString UAVObjectField::getTypeAsString()
return "float32"; return "float32";
case UAVObjectField::ENUM: case UAVObjectField::ENUM:
return "enum"; return "enum";
case UAVObjectField::BITFIELD:
return "bitfield";
case UAVObjectField::STRING: case UAVObjectField::STRING:
return "string"; return "string";
default: default:
@ -721,7 +729,7 @@ bool UAVObjectField::isNumeric()
return false; return false;
break; break;
case BITFIELD: case BITFIELD:
return false; return true;
break; break;
case STRING: case STRING:
return false; return false;
@ -760,7 +768,7 @@ bool UAVObjectField::isText()
return true; return true;
break; break;
case BITFIELD: case BITFIELD:
return true; return false;
break; break;
case STRING: case STRING:
return true; return true;
@ -971,7 +979,7 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
{ {
quint8 tmpbitfield; quint8 tmpbitfield;
memcpy(&tmpbitfield, &data[offset + numBytesPerElement*((quint32)(index/8))], numBytesPerElement); memcpy(&tmpbitfield, &data[offset + numBytesPerElement*((quint32)(index/8))], numBytesPerElement);
tmpbitfield = tmpbitfield | ( (value.toUInt()!=0?1:0) << (index % 8) ); tmpbitfield = (tmpbitfield & ~(1 << (index % 8))) | ( (value.toUInt()!=0?1:0) << (index % 8) );
memcpy(&data[offset + numBytesPerElement*((quint32)(index/8))], &tmpbitfield, numBytesPerElement); memcpy(&data[offset + numBytesPerElement*((quint32)(index/8))], &tmpbitfield, numBytesPerElement);
break; break;
} }