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

UABOBJECTS: Made GCS aware of new BITFIELD type in UAVObjects - so far not used by UAVObjectgenerator, but can be used (hardcoded) in metadata objects

This commit is contained in:
Corvus Corax 2012-05-15 18:22:36 +02:00
parent badf509d1d
commit 31fd30b108
3 changed files with 58 additions and 9 deletions

View File

@ -166,6 +166,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
FieldTreeItem *item; FieldTreeItem *item;
UAVObjectField::FieldType type = field->getType(); UAVObjectField::FieldType type = field->getType();
switch (type) { switch (type) {
case UAVObjectField::BITFIELD:
case UAVObjectField::ENUM: { case UAVObjectField::ENUM: {
QStringList options = field->getOptions(); QStringList options = field->getOptions();
QVariant value = field->getValue(); QVariant value = field->getValue();

View File

@ -86,6 +86,9 @@ void UAVObjectField::constructorInitialize(const QString& name, const QString& u
case ENUM: case ENUM:
numBytesPerElement = sizeof(quint8); numBytesPerElement = sizeof(quint8);
break; break;
case BITFIELD:
numBytesPerElement = sizeof(quint8);
break;
case STRING: case STRING:
numBytesPerElement = sizeof(quint8); numBytesPerElement = sizeof(quint8);
break; break;
@ -477,7 +480,15 @@ UAVObject* UAVObjectField::getObject()
void UAVObjectField::clear() void UAVObjectField::clear()
{ {
QMutexLocker locker(obj->getMutex()); QMutexLocker locker(obj->getMutex());
memset(&data[offset], 0, numBytesPerElement*numElements); switch (type)
{
case BITFIELD:
memset(&data[offset], 0, numBytesPerElement*((quint32)(numElements/8)));
break;
default:
memset(&data[offset], 0, numBytesPerElement*numElements);
break;
}
} }
QString UAVObjectField::getName() QString UAVObjectField::getName()
@ -507,7 +518,15 @@ quint32 UAVObjectField::getDataOffset()
quint32 UAVObjectField::getNumBytes() quint32 UAVObjectField::getNumBytes()
{ {
return numBytesPerElement * numElements; switch (type)
{
case BITFIELD:
return numBytesPerElement * ((quint32) (numElements/8));
break;
default:
return numBytesPerElement * numElements;
break;
}
} }
QString UAVObjectField::toString() QString UAVObjectField::toString()
@ -584,6 +603,12 @@ qint32 UAVObjectField::pack(quint8* dataOut)
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index]; dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
} }
break; break;
case BITFIELD:
for (quint32 index = 0; index < (quint32)(numElements/8); ++index)
{
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
}
break;
case STRING: case STRING:
memcpy(dataOut, &data[offset], numElements); memcpy(dataOut, &data[offset], numElements);
break; break;
@ -653,6 +678,12 @@ qint32 UAVObjectField::unpack(const quint8* dataIn)
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index]; data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
} }
break; break;
case BITFIELD:
for (quint32 index = 0; index < (quint32)(numElements/8); ++index)
{
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
}
break;
case STRING: case STRING:
memcpy(&data[offset], dataIn, numElements); memcpy(&data[offset], dataIn, numElements);
break; break;
@ -661,11 +692,6 @@ qint32 UAVObjectField::unpack(const quint8* dataIn)
return getNumBytes(); return getNumBytes();
} }
quint32 UAVObjectField::getNumBytesElement()
{
return numBytesPerElement;
}
bool UAVObjectField::isNumeric() bool UAVObjectField::isNumeric()
{ {
switch (type) switch (type)
@ -694,6 +720,9 @@ bool UAVObjectField::isNumeric()
case ENUM: case ENUM:
return false; return false;
break; break;
case BITFIELD:
return false;
break;
case STRING: case STRING:
return false; return false;
break; break;
@ -730,6 +759,9 @@ bool UAVObjectField::isText()
case ENUM: case ENUM:
return true; return true;
break; break;
case BITFIELD:
return true;
break;
case STRING: case STRING:
return true; return true;
break; break;
@ -810,6 +842,14 @@ QVariant UAVObjectField::getValue(quint32 index)
return QVariant( options[tmpenum] ); return QVariant( options[tmpenum] );
break; break;
} }
case BITFIELD:
{
quint8 tmpbitfield;
memcpy(&tmpbitfield, &data[offset + numBytesPerElement*((quint32)(index/8))], numBytesPerElement);
tmpbitfield = (tmpbitfield >> (index % 8)) & 1;
return QVariant( tmpbitfield );
break;
}
case STRING: case STRING:
{ {
data[offset + numElements - 1] = '\0'; data[offset + numElements - 1] = '\0';
@ -845,6 +885,7 @@ bool UAVObjectField::checkValue(const QVariant& value, quint32 index)
case UINT32: case UINT32:
case FLOAT32: case FLOAT32:
case STRING: case STRING:
case BITFIELD:
return true; return true;
break; break;
case ENUM: case ENUM:
@ -926,6 +967,14 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement); memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
break; break;
} }
case BITFIELD:
{
quint8 tmpbitfield;
memcpy(&tmpbitfield, &data[offset + numBytesPerElement*((quint32)(index/8))], numBytesPerElement);
tmpbitfield = tmpbitfield | ( (value.toUInt()!=0?1:0) << (index % 8) );
memcpy(&data[offset + numBytesPerElement*((quint32)(index/8))], &tmpbitfield, numBytesPerElement);
break;
}
case STRING: case STRING:
{ {
QString str = value.toString(); QString str = value.toString();

View File

@ -42,7 +42,7 @@ class UAVOBJECTS_EXPORT UAVObjectField: public QObject
Q_OBJECT Q_OBJECT
public: public:
typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType; typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, BITFIELD, STRING } FieldType;
typedef enum { EQUAL,NOT_EQUAL,BETWEEN,BIGGER,SMALLER } LimitType; typedef enum { EQUAL,NOT_EQUAL,BETWEEN,BIGGER,SMALLER } LimitType;
typedef struct typedef struct
{ {
@ -70,7 +70,6 @@ public:
void setDouble(double value, quint32 index = 0); void setDouble(double value, quint32 index = 0);
quint32 getDataOffset(); quint32 getDataOffset();
quint32 getNumBytes(); quint32 getNumBytes();
quint32 getNumBytesElement();
bool isNumeric(); bool isNumeric();
bool isText(); bool isText();
QString toString(); QString toString();