mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
GCS/UAVObjects: Merged all UAVObjectFields into a single class using a QVariant for the data, updated UAVObjectBrowser and fixed a bug with array fields, added isNumeric() and isText() functions to UAVObjectField
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@598 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
0826af11e5
commit
23ed286883
@ -41,9 +41,9 @@ UAVObjectParser::UAVObjectParser()
|
||||
QString( "quint8") << QString("quint16") << QString("quint32") <<
|
||||
QString("float") << QString("quint8");
|
||||
|
||||
fieldTypeStrCPPClass << QString("Int8") << QString("Int16") << QString("Int32") <<
|
||||
QString( "UInt8") << QString("UInt16") << QString("UInt32") <<
|
||||
QString("Float") << QString("Enum");
|
||||
fieldTypeStrCPPClass << QString("INT8") << QString("INT16") << QString("INT32") <<
|
||||
QString( "UINT8") << QString("UINT16") << QString("UINT32") <<
|
||||
QString("FLOAT32") << QString("ENUM");
|
||||
|
||||
fieldTypeStrXML << QString("int8") << QString("int16") << QString("int32") <<
|
||||
QString("uint8") << QString("uint16") << QString("uint32") <<
|
||||
@ -742,7 +742,7 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
|
||||
.arg(varOptionName)
|
||||
.arg(options[m]) );
|
||||
}
|
||||
finit.append( QString(" fields.append(new UAVObjectFieldEnum(QString(\"%1\"), QString(\"%2\"), %3, %4));\n")
|
||||
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::ENUM, %3, %4) );\n")
|
||||
.arg(info->fields[n]->name)
|
||||
.arg(info->fields[n]->units)
|
||||
.arg(varElemName)
|
||||
@ -751,10 +751,10 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
|
||||
// For all other types
|
||||
else
|
||||
{
|
||||
finit.append( QString(" fields.append(new UAVObjectField%1(QString(\"%2\"), QString(\"%3\"), %4));\n")
|
||||
.arg(fieldTypeStrCPPClass[info->fields[n]->type])
|
||||
finit.append( QString(" fields.append( new UAVObjectField(QString(\"%1\"), QString(\"%2\"), UAVObjectField::%3, %4, QStringList()) );\n")
|
||||
.arg(info->fields[n]->name)
|
||||
.arg(info->fields[n]->units)
|
||||
.arg(fieldTypeStrCPPClass[info->fields[n]->type])
|
||||
.arg(varElemName) );
|
||||
}
|
||||
}
|
||||
|
@ -68,26 +68,32 @@ class EnumFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QList<QVariant> &data,
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
EnumFieldTreeItem(UAVObjectFieldEnum *field, int index, const QVariant &data,
|
||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
||||
TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getSelectedIndex(m_index) != value);
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant tmpValue = m_field->getValue(m_index);
|
||||
int tmpValIndex = options.indexOf(tmpValue.toString());
|
||||
setChanged(tmpValIndex != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
QString enumOptions(int index) { return m_enumOptions.at(index); }
|
||||
void apply() {
|
||||
int value = data(dataColumn).toInt();
|
||||
m_field->setSelectedIndex(value, m_index);
|
||||
QStringList options = m_field->getOptions();
|
||||
m_field->setValue(options[value], m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getSelectedIndex(m_index);
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
QStringList options = m_field->getOptions();
|
||||
QVariant value = m_field->getValue(m_index);
|
||||
int valIndex = options.indexOf(value.toString());
|
||||
if (data() != valIndex || changed()) {
|
||||
TreeItem::setData(valIndex);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
@ -109,7 +115,7 @@ public:
|
||||
}
|
||||
private:
|
||||
QStringList m_enumOptions;
|
||||
UAVObjectFieldEnum *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class IntFieldTreeItem : public FieldTreeItem
|
||||
@ -146,162 +152,162 @@ class Int8FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
Int8FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT8MIN, QINT8MAX, parent), m_field(field) { }
|
||||
Int8FieldTreeItem(UAVObjectFieldInt8 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
Int8FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT8MIN, QINT8MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt8 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class Int16FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
Int16FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT16MIN, QINT16MAX, parent), m_field(field) { }
|
||||
Int16FieldTreeItem(UAVObjectFieldInt16 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
Int16FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT16MIN, QINT16MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt16 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class Int32FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Int32FieldTreeItem(UAVObjectFieldInt32 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
Int32FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT32MIN, QINT32MAX, parent), m_field(field) { }
|
||||
Int32FieldTreeItem(UAVObjectFieldInt32 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
Int32FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QINT32MIN, QINT32MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldInt32 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class UInt8FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
UInt8FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT8MAX, parent), m_field(field) { }
|
||||
UInt8FieldTreeItem(UAVObjectFieldUInt8 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
UInt8FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT8MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt8 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class UInt16FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
UInt16FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT16MAX, parent), m_field(field) { }
|
||||
UInt16FieldTreeItem(UAVObjectFieldUInt16 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
UInt16FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT16MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt16 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
class UInt32FieldTreeItem : public IntFieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
UInt32FieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT32MAX, parent), m_field(field) { }
|
||||
UInt32FieldTreeItem(UAVObjectFieldUInt32 *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
UInt32FieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
IntFieldTreeItem(index, data, QUINTMIN, QUINT32MAX, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
TreeItem::setData(value, column);
|
||||
}
|
||||
void apply() {
|
||||
m_field->setValue(data(dataColumn).toInt());
|
||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
int value = m_field->getValue(m_index);
|
||||
int value = m_field->getValue(m_index).toInt();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldUInt32 *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
|
||||
@ -309,9 +315,9 @@ class FloatFieldTreeItem : public FieldTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FloatFieldTreeItem(UAVObjectFieldFloat *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
FloatFieldTreeItem(UAVObjectFieldFloat *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||
void setData(QVariant value, int column) {
|
||||
setChanged(m_field->getValue(m_index) != value);
|
||||
@ -322,7 +328,7 @@ public:
|
||||
setChanged(false);
|
||||
}
|
||||
void update() {
|
||||
double value = m_field->getValue(m_index);
|
||||
double value = m_field->getValue(m_index).toDouble();
|
||||
if (data() != value || changed()) {
|
||||
TreeItem::setData(value);
|
||||
setHighlight(true);
|
||||
@ -347,7 +353,7 @@ public:
|
||||
spinBox->setValue(value.toDouble());
|
||||
}
|
||||
private:
|
||||
UAVObjectFieldFloat *m_field;
|
||||
UAVObjectField *m_field;
|
||||
};
|
||||
|
||||
#endif // FIELDTREEITEM_H
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfields.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QTimer>
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavdataobject.h"
|
||||
#include "uavobjects/uavmetaobject.h"
|
||||
#include "uavobjects/uavobjectfields.h"
|
||||
#include "uavobjects/uavobjectfield.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <QtGui/QColor>
|
||||
//#include <QtGui/QIcon>
|
||||
@ -162,48 +162,43 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
|
||||
data.append(field->getName());
|
||||
else
|
||||
data.append( QString("[%1]").arg((field->getElementNames())[index]) );
|
||||
UAVObjectFieldEnum *enumField = dynamic_cast<UAVObjectFieldEnum*>(field);
|
||||
UAVObjectFieldInt8 *int8Field = dynamic_cast<UAVObjectFieldInt8*>(field);
|
||||
UAVObjectFieldInt16 *int16Field = dynamic_cast<UAVObjectFieldInt16*>(field);
|
||||
UAVObjectFieldInt32 *int32Field = dynamic_cast<UAVObjectFieldInt32*>(field);
|
||||
UAVObjectFieldUInt8 *uInt8Field = dynamic_cast<UAVObjectFieldUInt8*>(field);
|
||||
UAVObjectFieldUInt16 *uInt16Field = dynamic_cast<UAVObjectFieldUInt16*>(field);
|
||||
UAVObjectFieldUInt32 *uInt32Field = dynamic_cast<UAVObjectFieldUInt32*>(field);
|
||||
UAVObjectFieldFloat *floatField = dynamic_cast<UAVObjectFieldFloat*>(field);
|
||||
|
||||
FieldTreeItem *item;
|
||||
if (enumField) {
|
||||
data.append(enumField->getSelectedIndex(index));
|
||||
UAVObjectField::FieldType type = field->getType();
|
||||
if (type == UAVObjectField::ENUM) {
|
||||
QStringList options = field->getOptions();
|
||||
QVariant value = field->getValue();
|
||||
data.append( options.indexOf(value.toString()) );
|
||||
data.append(field->getUnits());
|
||||
item = new EnumFieldTreeItem(enumField, index, data);
|
||||
} else if (int8Field) {
|
||||
data.append(int8Field->getValue(index));
|
||||
item = new EnumFieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::INT8) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new Int8FieldTreeItem(int8Field, index, data);
|
||||
} else if (int16Field) {
|
||||
data.append(int16Field->getValue(index));
|
||||
item = new Int8FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::INT16) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new Int16FieldTreeItem(int16Field, index, data);
|
||||
} else if (int32Field) {
|
||||
data.append(int32Field->getValue(index));
|
||||
item = new Int16FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::INT32) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new Int32FieldTreeItem(int32Field, index, data);
|
||||
} else if (uInt8Field) {
|
||||
data.append(uInt8Field->getValue(index));
|
||||
item = new Int32FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::UINT8) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new UInt8FieldTreeItem(uInt8Field, index, data);
|
||||
} else if (uInt16Field) {
|
||||
data.append(uInt16Field->getValue(index));
|
||||
item = new UInt8FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::UINT16) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new UInt16FieldTreeItem(uInt16Field, index, data);
|
||||
} else if (uInt32Field) {
|
||||
data.append(uInt32Field->getValue(index));
|
||||
item = new UInt16FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::UINT32) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new UInt32FieldTreeItem(uInt32Field, index, data);
|
||||
} else if (floatField) {
|
||||
data.append(floatField->getValue(index));
|
||||
item = new UInt32FieldTreeItem(field, index, data);
|
||||
} else if (type == UAVObjectField::FLOAT32) {
|
||||
data.append(field->getValue(index));
|
||||
data.append(field->getUnits());
|
||||
item = new FloatFieldTreeItem(floatField, index, data);
|
||||
item = new FloatFieldTreeItem(field, index, data);
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "exampleobject1.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString ExampleObject1::NAME = QString("ExampleObject1");
|
||||
|
||||
@ -42,34 +42,34 @@ ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
|
||||
QList<UAVObjectField*> fields;
|
||||
QStringList Field1ElemNames;
|
||||
Field1ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field1"), QString("unit1"), UAVObjectField::INT8, Field1ElemNames, QStringList()) );
|
||||
QStringList Field2ElemNames;
|
||||
Field2ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field2"), QString("unit2"), UAVObjectField::INT16, Field2ElemNames, QStringList()) );
|
||||
QStringList Field3ElemNames;
|
||||
Field3ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), Field3ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field3"), QString("unit3"), UAVObjectField::INT32, Field3ElemNames, QStringList()) );
|
||||
QStringList Field4ElemNames;
|
||||
Field4ElemNames.append("0");
|
||||
Field4ElemNames.append("1");
|
||||
Field4ElemNames.append("2");
|
||||
Field4ElemNames.append("3");
|
||||
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field4"), QString("unit4"), UAVObjectField::FLOAT32, Field4ElemNames, QStringList()) );
|
||||
QStringList Field5ElemNames;
|
||||
Field5ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt8(QString("Field5"), QString("unit5"), Field5ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field5"), QString("unit5"), UAVObjectField::UINT8, Field5ElemNames, QStringList()) );
|
||||
QStringList Field6ElemNames;
|
||||
Field6ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt16(QString("Field6"), QString("unit6"), Field6ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field6"), QString("unit6"), UAVObjectField::UINT16, Field6ElemNames, QStringList()) );
|
||||
QStringList Field7ElemNames;
|
||||
Field7ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("Field7"), QString("unit7"), Field7ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field7"), QString("unit7"), UAVObjectField::UINT32, Field7ElemNames, QStringList()) );
|
||||
QStringList Field8ElemNames;
|
||||
Field8ElemNames.append("0");
|
||||
QStringList Field8EnumOptions;
|
||||
Field8EnumOptions.append("Option1");
|
||||
Field8EnumOptions.append("Option2");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Field8"), QString("unit8"), Field8ElemNames, Field8EnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Field8"), QString("unit8"), UAVObjectField::ENUM, Field8ElemNames, Field8EnumOptions) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "exampleobject2.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString ExampleObject2::NAME = QString("ExampleObject2");
|
||||
|
||||
@ -42,19 +42,19 @@ ExampleObject2::ExampleObject2(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
|
||||
QList<UAVObjectField*> fields;
|
||||
QStringList Field1ElemNames;
|
||||
Field1ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field1"), QString("unit1"), UAVObjectField::INT8, Field1ElemNames, QStringList()) );
|
||||
QStringList Field2ElemNames;
|
||||
Field2ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field2"), QString("unit2"), UAVObjectField::INT16, Field2ElemNames, QStringList()) );
|
||||
QStringList Field3ElemNames;
|
||||
Field3ElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), Field3ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field3"), QString("unit3"), UAVObjectField::INT32, Field3ElemNames, QStringList()) );
|
||||
QStringList Field4ElemNames;
|
||||
Field4ElemNames.append("0");
|
||||
Field4ElemNames.append("1");
|
||||
Field4ElemNames.append("2");
|
||||
Field4ElemNames.append("3");
|
||||
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
|
||||
fields.append( new UAVObjectField(QString("Field4"), QString("unit4"), UAVObjectField::FLOAT32, Field4ElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "examplesettings.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString ExampleSettings::NAME = QString("ExampleSettings");
|
||||
|
||||
@ -42,16 +42,16 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
|
||||
QList<UAVObjectField*> fields;
|
||||
QStringList UpdatePeriodElemNames;
|
||||
UpdatePeriodElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt32(QString("UpdatePeriod"), QString("ms"), UpdatePeriodElemNames));
|
||||
fields.append( new UAVObjectField(QString("UpdatePeriod"), QString("ms"), UAVObjectField::INT32, UpdatePeriodElemNames, QStringList()) );
|
||||
QStringList StepSizeElemNames;
|
||||
StepSizeElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt32(QString("StepSize"), QString(""), StepSizeElemNames));
|
||||
fields.append( new UAVObjectField(QString("StepSize"), QString(""), UAVObjectField::INT32, StepSizeElemNames, QStringList()) );
|
||||
QStringList StepDirectionElemNames;
|
||||
StepDirectionElemNames.append("0");
|
||||
QStringList StepDirectionEnumOptions;
|
||||
StepDirectionEnumOptions.append("up");
|
||||
StepDirectionEnumOptions.append("down");
|
||||
fields.append(new UAVObjectFieldEnum(QString("StepDirection"), QString(""), StepDirectionElemNames, StepDirectionEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("StepDirection"), QString(""), UAVObjectField::ENUM, StepDirectionElemNames, StepDirectionEnumOptions) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "flighttelemetrystats.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString FlightTelemetryStats::NAME = QString("FlightTelemetryStats");
|
||||
|
||||
@ -47,22 +47,22 @@ FlightTelemetryStats::FlightTelemetryStats(): UAVDataObject(OBJID, ISSINGLEINST,
|
||||
StatusEnumOptions.append("HandshakeReq");
|
||||
StatusEnumOptions.append("HandshakeAck");
|
||||
StatusEnumOptions.append("Connected");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Status"), QString(""), StatusElemNames, StatusEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Status"), QString(""), UAVObjectField::ENUM, StatusElemNames, StatusEnumOptions) );
|
||||
QStringList TxDataRateElemNames;
|
||||
TxDataRateElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("TxDataRate"), QString("bytes/sec"), TxDataRateElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxDataRate"), QString("bytes/sec"), UAVObjectField::FLOAT32, TxDataRateElemNames, QStringList()) );
|
||||
QStringList RxDataRateElemNames;
|
||||
RxDataRateElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("RxDataRate"), QString("bytes/sec"), RxDataRateElemNames));
|
||||
fields.append( new UAVObjectField(QString("RxDataRate"), QString("bytes/sec"), UAVObjectField::FLOAT32, RxDataRateElemNames, QStringList()) );
|
||||
QStringList TxFailuresElemNames;
|
||||
TxFailuresElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("TxFailures"), QString("count"), TxFailuresElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxFailures"), QString("count"), UAVObjectField::UINT32, TxFailuresElemNames, QStringList()) );
|
||||
QStringList RxFailuresElemNames;
|
||||
RxFailuresElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("RxFailures"), QString("count"), RxFailuresElemNames));
|
||||
fields.append( new UAVObjectField(QString("RxFailures"), QString("count"), UAVObjectField::UINT32, RxFailuresElemNames, QStringList()) );
|
||||
QStringList TxRetriesElemNames;
|
||||
TxRetriesElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("TxRetries"), QString("count"), TxRetriesElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxRetries"), QString("count"), UAVObjectField::UINT32, TxRetriesElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "gcstelemetrystats.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString GCSTelemetryStats::NAME = QString("GCSTelemetryStats");
|
||||
|
||||
@ -47,22 +47,22 @@ GCSTelemetryStats::GCSTelemetryStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSET
|
||||
StatusEnumOptions.append("HandshakeReq");
|
||||
StatusEnumOptions.append("HandshakeAck");
|
||||
StatusEnumOptions.append("Connected");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Status"), QString(""), StatusElemNames, StatusEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Status"), QString(""), UAVObjectField::ENUM, StatusElemNames, StatusEnumOptions) );
|
||||
QStringList TxDataRateElemNames;
|
||||
TxDataRateElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("TxDataRate"), QString("bytes/sec"), TxDataRateElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxDataRate"), QString("bytes/sec"), UAVObjectField::FLOAT32, TxDataRateElemNames, QStringList()) );
|
||||
QStringList RxDataRateElemNames;
|
||||
RxDataRateElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("RxDataRate"), QString("bytes/sec"), RxDataRateElemNames));
|
||||
fields.append( new UAVObjectField(QString("RxDataRate"), QString("bytes/sec"), UAVObjectField::FLOAT32, RxDataRateElemNames, QStringList()) );
|
||||
QStringList TxFailuresElemNames;
|
||||
TxFailuresElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("TxFailures"), QString("count"), TxFailuresElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxFailures"), QString("count"), UAVObjectField::UINT32, TxFailuresElemNames, QStringList()) );
|
||||
QStringList RxFailuresElemNames;
|
||||
RxFailuresElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("RxFailures"), QString("count"), RxFailuresElemNames));
|
||||
fields.append( new UAVObjectField(QString("RxFailures"), QString("count"), UAVObjectField::UINT32, RxFailuresElemNames, QStringList()) );
|
||||
QStringList TxRetriesElemNames;
|
||||
TxRetriesElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("TxRetries"), QString("count"), TxRetriesElemNames));
|
||||
fields.append( new UAVObjectField(QString("TxRetries"), QString("count"), UAVObjectField::UINT32, TxRetriesElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "gpsobject.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString GpsObject::NAME = QString("GpsObject");
|
||||
|
||||
@ -42,19 +42,19 @@ GpsObject::GpsObject(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
|
||||
QList<UAVObjectField*> fields;
|
||||
QStringList LatitudeElemNames;
|
||||
LatitudeElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("Latitude"), QString("degrees"), LatitudeElemNames));
|
||||
fields.append( new UAVObjectField(QString("Latitude"), QString("degrees"), UAVObjectField::FLOAT32, LatitudeElemNames, QStringList()) );
|
||||
QStringList LongitudeElemNames;
|
||||
LongitudeElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("Longitude"), QString("degrees"), LongitudeElemNames));
|
||||
fields.append( new UAVObjectField(QString("Longitude"), QString("degrees"), UAVObjectField::FLOAT32, LongitudeElemNames, QStringList()) );
|
||||
QStringList AltitudeElemNames;
|
||||
AltitudeElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldFloat(QString("Altitude"), QString("meters"), AltitudeElemNames));
|
||||
fields.append( new UAVObjectField(QString("Altitude"), QString("meters"), UAVObjectField::FLOAT32, AltitudeElemNames, QStringList()) );
|
||||
QStringList SatellitesElemNames;
|
||||
SatellitesElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldInt8(QString("Satellites"), QString(""), SatellitesElemNames));
|
||||
fields.append( new UAVObjectField(QString("Satellites"), QString(""), UAVObjectField::INT8, SatellitesElemNames, QStringList()) );
|
||||
QStringList UpdatesElemNames;
|
||||
UpdatesElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt16(QString("Updates"), QString(""), UpdatesElemNames));
|
||||
fields.append( new UAVObjectField(QString("Updates"), QString(""), UAVObjectField::UINT16, UpdatesElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "objectpersistence.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString ObjectPersistence::NAME = QString("ObjectPersistence");
|
||||
|
||||
@ -46,7 +46,7 @@ ObjectPersistence::ObjectPersistence(): UAVDataObject(OBJID, ISSINGLEINST, ISSET
|
||||
OperationEnumOptions.append("Load");
|
||||
OperationEnumOptions.append("Save");
|
||||
OperationEnumOptions.append("Delete");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Operation"), QString(""), OperationElemNames, OperationEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Operation"), QString(""), UAVObjectField::ENUM, OperationElemNames, OperationEnumOptions) );
|
||||
QStringList SelectionElemNames;
|
||||
SelectionElemNames.append("0");
|
||||
QStringList SelectionEnumOptions;
|
||||
@ -54,13 +54,13 @@ ObjectPersistence::ObjectPersistence(): UAVDataObject(OBJID, ISSINGLEINST, ISSET
|
||||
SelectionEnumOptions.append("AllSettings");
|
||||
SelectionEnumOptions.append("AllMetaObjects");
|
||||
SelectionEnumOptions.append("AllObjects");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Selection"), QString(""), SelectionElemNames, SelectionEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Selection"), QString(""), UAVObjectField::ENUM, SelectionElemNames, SelectionEnumOptions) );
|
||||
QStringList ObjectIDElemNames;
|
||||
ObjectIDElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("ObjectID"), QString(""), ObjectIDElemNames));
|
||||
fields.append( new UAVObjectField(QString("ObjectID"), QString(""), UAVObjectField::UINT32, ObjectIDElemNames, QStringList()) );
|
||||
QStringList InstanceIDElemNames;
|
||||
InstanceIDElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("InstanceID"), QString(""), InstanceIDElemNames));
|
||||
fields.append( new UAVObjectField(QString("InstanceID"), QString(""), UAVObjectField::UINT32, InstanceIDElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "systemalarms.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString SystemAlarms::NAME = QString("SystemAlarms");
|
||||
|
||||
@ -52,7 +52,7 @@ SystemAlarms::SystemAlarms(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAM
|
||||
AlarmEnumOptions.append("Warning");
|
||||
AlarmEnumOptions.append("Error");
|
||||
AlarmEnumOptions.append("Critical");
|
||||
fields.append(new UAVObjectFieldEnum(QString("Alarm"), QString(""), AlarmElemNames, AlarmEnumOptions));
|
||||
fields.append( new UAVObjectField(QString("Alarm"), QString(""), UAVObjectField::ENUM, AlarmElemNames, AlarmEnumOptions) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "systemstats.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString SystemStats::NAME = QString("SystemStats");
|
||||
|
||||
@ -42,13 +42,13 @@ SystemStats::SystemStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
|
||||
QList<UAVObjectField*> fields;
|
||||
QStringList FlightTimeElemNames;
|
||||
FlightTimeElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt32(QString("FlightTime"), QString("ms"), FlightTimeElemNames));
|
||||
fields.append( new UAVObjectField(QString("FlightTime"), QString("ms"), UAVObjectField::UINT32, FlightTimeElemNames, QStringList()) );
|
||||
QStringList HeapRemainingElemNames;
|
||||
HeapRemainingElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt16(QString("HeapRemaining"), QString("bytes"), HeapRemainingElemNames));
|
||||
fields.append( new UAVObjectField(QString("HeapRemaining"), QString("bytes"), UAVObjectField::UINT16, HeapRemainingElemNames, QStringList()) );
|
||||
QStringList CPULoadElemNames;
|
||||
CPULoadElemNames.append("0");
|
||||
fields.append(new UAVObjectFieldUInt8(QString("CPULoad"), QString("%"), CPULoadElemNames));
|
||||
fields.append( new UAVObjectField(QString("CPULoad"), QString("%"), UAVObjectField::UINT8, CPULoadElemNames, QStringList()) );
|
||||
|
||||
// Initialize object
|
||||
initializeFields(fields, (quint8*)&data, NUMBYTES);
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavmetaobject.h"
|
||||
#include <QList>
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavmetaobject.h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -50,14 +50,14 @@ UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* pare
|
||||
QStringList updateModeEnum;
|
||||
updateModeEnum << tr("Periodic") << tr("On Change") << tr("Manual") << tr("Never");
|
||||
QList<UAVObjectField*> fields;
|
||||
fields.append(new UAVObjectFieldEnum(tr("Flight Telemetry Acked"), QString(""), 1, boolEnum));
|
||||
fields.append(new UAVObjectFieldEnum(tr("Flight Telemetry Update Mode"), QString(""), 1, updateModeEnum));
|
||||
fields.append(new UAVObjectFieldInt32(tr("Flight Telemetry Update Period"), tr("ms"), 1));
|
||||
fields.append(new UAVObjectFieldEnum(tr("GCS Telemetry Acked"), QString(""), 1, boolEnum));
|
||||
fields.append(new UAVObjectFieldEnum(tr("GCS Telemetry Update Mode"), QString(""), 1, updateModeEnum));
|
||||
fields.append(new UAVObjectFieldInt32(tr("GCS Telemetry Update Period"), tr("ms"), 1));
|
||||
fields.append(new UAVObjectFieldEnum(tr("Logging Update Mode"), QString(""), 1, updateModeEnum));
|
||||
fields.append(new UAVObjectFieldUInt32(tr("Logging Update Period"), tr("ms"), 1));
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Flight Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Acked"), tr(""), UAVObjectField::ENUM, 1, boolEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("GCS Telemetry Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Mode"), tr(""), UAVObjectField::ENUM, 1, updateModeEnum) );
|
||||
fields.append( new UAVObjectField(tr("Logging Update Period"), tr(""), UAVObjectField::UINT32, 1, QStringList()) );
|
||||
// Initialize parent
|
||||
UAVObject::initialize(0);
|
||||
UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata));
|
||||
|
@ -28,32 +28,69 @@
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, quint32 numElements)
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
|
||||
{
|
||||
// Copy params
|
||||
this->name = name;
|
||||
this->units = units;
|
||||
this->numElements = numElements;
|
||||
this->offset = 0;
|
||||
this->data = NULL;
|
||||
this->obj = NULL;
|
||||
QStringList elementNames;
|
||||
// Set element names
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
elementNames.append(QString("[%1]").arg(n));
|
||||
elementNames.append(QString("%1").arg(n));
|
||||
}
|
||||
// Initialize
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
|
||||
}
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, const QStringList& elementNames)
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
constructorInitialize(name, units, type, elementNames, options);
|
||||
}
|
||||
|
||||
void UAVObjectField::constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options)
|
||||
{
|
||||
// Copy params
|
||||
this->name = name;
|
||||
this->units = units;
|
||||
this->type = type;
|
||||
this->options = options;
|
||||
this->numElements = elementNames.length();
|
||||
this->offset = 0;
|
||||
this->data = NULL;
|
||||
this->obj = NULL;
|
||||
this->elementNames = elementNames;
|
||||
// Set field size
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
numBytesPerElement = sizeof(qint8);
|
||||
break;
|
||||
case INT16:
|
||||
numBytesPerElement = sizeof(qint16);
|
||||
break;
|
||||
case INT32:
|
||||
numBytesPerElement = sizeof(qint32);
|
||||
break;
|
||||
case UINT8:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case UINT16:
|
||||
numBytesPerElement = sizeof(quint16);
|
||||
break;
|
||||
case UINT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case FLOAT32:
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
break;
|
||||
case ENUM:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
case STRING:
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
break;
|
||||
default:
|
||||
numBytesPerElement = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
|
||||
@ -62,7 +99,11 @@ void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj
|
||||
this->offset = dataOffset;
|
||||
this->obj = obj;
|
||||
clear();
|
||||
initializeValues();
|
||||
}
|
||||
|
||||
UAVObjectField::FieldType UAVObjectField::getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getElementNames()
|
||||
@ -77,14 +118,8 @@ UAVObject* UAVObjectField::getObject()
|
||||
|
||||
void UAVObjectField::clear()
|
||||
{
|
||||
if (data != NULL)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
for (unsigned int n = 0; n < getNumBytesElement()*numElements; ++n)
|
||||
{
|
||||
data[offset + n] = 0;
|
||||
}
|
||||
}
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
memset(&data[offset], 0, numBytesPerElement*numElements);
|
||||
}
|
||||
|
||||
QString UAVObjectField::getName()
|
||||
@ -97,6 +132,11 @@ QString UAVObjectField::getUnits()
|
||||
return units;
|
||||
}
|
||||
|
||||
QStringList UAVObjectField::getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumElements()
|
||||
{
|
||||
return numElements;
|
||||
@ -109,7 +149,7 @@ quint32 UAVObjectField::getDataOffset()
|
||||
|
||||
quint32 UAVObjectField::getNumBytes()
|
||||
{
|
||||
return getNumBytesElement() * numElements;
|
||||
return numBytesPerElement * numElements;
|
||||
}
|
||||
|
||||
QString UAVObjectField::toString()
|
||||
@ -125,4 +165,381 @@ QString UAVObjectField::toString()
|
||||
}
|
||||
|
||||
|
||||
qint32 UAVObjectField::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(dataOut, &data[offset], numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
qint32 UAVObjectField::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Unpack each element from input buffer
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
case INT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case INT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT8:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case UINT16:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case UINT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case FLOAT32:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
break;
|
||||
case ENUM:
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
memcpy(&data[offset], dataIn, numElements);
|
||||
break;
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
quint32 UAVObjectField::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
bool UAVObjectField::isNumeric()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return true;
|
||||
break;
|
||||
case INT16:
|
||||
return true;
|
||||
break;
|
||||
case INT32:
|
||||
return true;
|
||||
break;
|
||||
case UINT8:
|
||||
return true;
|
||||
break;
|
||||
case UINT16:
|
||||
return true;
|
||||
break;
|
||||
case UINT32:
|
||||
return true;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return true;
|
||||
break;
|
||||
case ENUM:
|
||||
return false;
|
||||
break;
|
||||
case STRING:
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool UAVObjectField::isText()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
return false;
|
||||
break;
|
||||
case INT16:
|
||||
return false;
|
||||
break;
|
||||
case INT32:
|
||||
return false;
|
||||
break;
|
||||
case UINT8:
|
||||
return false;
|
||||
break;
|
||||
case UINT16:
|
||||
return false;
|
||||
break;
|
||||
case UINT32:
|
||||
return false;
|
||||
break;
|
||||
case FLOAT32:
|
||||
return false;
|
||||
break;
|
||||
case ENUM:
|
||||
return true;
|
||||
break;
|
||||
case STRING:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant UAVObjectField::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
// Get value
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8;
|
||||
memcpy(&tmpint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint8);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16;
|
||||
memcpy(&tmpint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint16);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32;
|
||||
memcpy(&tmpint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpint32);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8;
|
||||
memcpy(&tmpuint8, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint8);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16;
|
||||
memcpy(&tmpuint16, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint16);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32;
|
||||
memcpy(&tmpuint32, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpuint32);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat;
|
||||
memcpy(&tmpfloat, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant(tmpfloat);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
quint8 tmpenum;
|
||||
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return QVariant( options[tmpenum] );
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
data[offset + numElements - 1] = '\0';
|
||||
QString str((char*)&data[offset]);
|
||||
return QVariant( str );
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If this point is reached then we got an invalid type
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void UAVObjectField::setValue(const QVariant& value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check that index is not out of bounds
|
||||
if ( index >= numElements )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Set value
|
||||
switch (type)
|
||||
{
|
||||
case INT8:
|
||||
{
|
||||
qint8 tmpint8 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT16:
|
||||
{
|
||||
qint16 tmpint16 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case INT32:
|
||||
{
|
||||
qint32 tmpint32 = value.toInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT8:
|
||||
{
|
||||
quint8 tmpuint8 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint8, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT16:
|
||||
{
|
||||
quint16 tmpuint16 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint16, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case UINT32:
|
||||
{
|
||||
quint32 tmpuint32 = value.toUInt();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpuint32, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case FLOAT32:
|
||||
{
|
||||
float tmpfloat = value.toFloat();
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpfloat, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
qint8 tmpenum = options.indexOf( value.toString() );
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
{
|
||||
QString str = value.toString();
|
||||
QByteArray barray = str.toAscii();
|
||||
quint32 index;
|
||||
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
|
||||
{
|
||||
data[offset+index] = barray[index];
|
||||
}
|
||||
barray[index] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double UAVObjectField::getDouble(quint32 index)
|
||||
{
|
||||
return getValue().toDouble();
|
||||
}
|
||||
|
||||
void UAVObjectField::setDouble(double value, quint32 index)
|
||||
{
|
||||
setValue(QVariant(value));
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobject.h"
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class UAVObject;
|
||||
|
||||
@ -39,22 +40,29 @@ class UAVOBJECTS_EXPORT UAVObjectField: public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectField(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectField(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
typedef enum { INT8 = 0, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING } FieldType;
|
||||
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options);
|
||||
UAVObjectField(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj);
|
||||
virtual void initializeValues() = 0;
|
||||
UAVObject* getObject();
|
||||
FieldType getType();
|
||||
QString getName();
|
||||
QString getUnits();
|
||||
quint32 getNumElements();
|
||||
QStringList getElementNames();
|
||||
virtual qint32 pack(quint8* dataOut) = 0;
|
||||
virtual qint32 unpack(const quint8* dataIn) = 0;
|
||||
virtual double getDouble(quint32 index = 0) = 0;
|
||||
virtual void setDouble(double value, quint32 index = 0) = 0;
|
||||
QStringList getOptions();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
QVariant getValue(quint32 index = 0);
|
||||
void setValue(const QVariant& data, quint32 index = 0);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getDataOffset();
|
||||
quint32 getNumBytes();
|
||||
virtual quint32 getNumBytesElement() = 0;
|
||||
quint32 getNumBytesElement();
|
||||
bool isNumeric();
|
||||
bool isText();
|
||||
QString toString();
|
||||
|
||||
signals:
|
||||
@ -63,13 +71,17 @@ signals:
|
||||
protected:
|
||||
QString name;
|
||||
QString units;
|
||||
FieldType type;
|
||||
QStringList elementNames;
|
||||
QStringList options;
|
||||
quint32 numElements;
|
||||
quint32 numBytesPerElement;
|
||||
quint32 offset;
|
||||
quint8* data;
|
||||
UAVObject* obj;
|
||||
|
||||
void clear();
|
||||
void constructorInitialize(const QString& name, const QString& units, FieldType type, const QStringList& elementNames, const QStringList& options);
|
||||
|
||||
|
||||
};
|
||||
|
@ -1,199 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldenum.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectfieldenum.h"
|
||||
#include <QtEndian>
|
||||
|
||||
UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, const QStringList& options):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
this->options = options;
|
||||
}
|
||||
|
||||
UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, const QStringList& elementNames, const QStringList& options):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
this->options = options;
|
||||
}
|
||||
|
||||
QStringList UAVObjectFieldEnum::getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
QString UAVObjectFieldEnum::getSelected(quint32 arrayIndex)
|
||||
{
|
||||
return options[getValue(arrayIndex)];
|
||||
}
|
||||
|
||||
void UAVObjectFieldEnum::setSelected(QString& val, quint32 arrayIndex)
|
||||
{
|
||||
// Find index of selected value
|
||||
int index = options.indexOf(val);
|
||||
if (index >= 0)
|
||||
{
|
||||
setValue(index, arrayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
quint8 UAVObjectFieldEnum::getSelectedIndex(quint32 arrayIndex)
|
||||
{
|
||||
return getValue(arrayIndex);
|
||||
}
|
||||
|
||||
void UAVObjectFieldEnum::setSelectedIndex(quint8 index, quint32 arrayIndex)
|
||||
{
|
||||
// Check that the index is valid
|
||||
if (index < options.length())
|
||||
{
|
||||
setValue(index, arrayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldEnum::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldEnum::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldEnum::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldEnum::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldEnum::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 tmpValue;
|
||||
tmpValue = (quint8)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldEnum::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
quint8 UAVObjectFieldEnum::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldEnum::setValue(quint8 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldenum.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDENUM_H
|
||||
#define UAVOBJECTFIELDENUM_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QStringList>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldEnum: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, const QStringList& options);
|
||||
UAVObjectFieldEnum(const QString& name, const QString& units, const QStringList& elementNames, const QStringList& options);
|
||||
QStringList getOptions();
|
||||
QString getSelected(quint32 arrayIndex);
|
||||
void setSelected(QString& val, quint32 arrayIndex);
|
||||
quint8 getSelectedIndex(quint32 arrayIndex);
|
||||
void setSelectedIndex(quint8 index, quint32 arrayIndex);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
QStringList options;
|
||||
|
||||
quint8 getValue(quint32 index = 0);
|
||||
void setValue(quint8 value, quint32 index = 0);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDENUM_H
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldfloat.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfieldfloat.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldFloat::UAVObjectFieldFloat(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(float);
|
||||
}
|
||||
|
||||
UAVObjectFieldFloat::UAVObjectFieldFloat(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(float);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldFloat::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldFloat::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldFloat::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldFloat::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
float value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldFloat::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
float tmpValue;
|
||||
tmpValue = (float)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldFloat::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
float UAVObjectFieldFloat::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
float value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldFloat::setValue(float value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldfloat.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDFLOAT_H
|
||||
#define UAVOBJECTFIELDFLOAT_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldFloat: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldFloat(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldFloat(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
float getValue(quint32 index = 0);
|
||||
void setValue(float value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDFLOAT_H
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint16.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfieldint16.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldInt16::UAVObjectFieldInt16(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint16);
|
||||
}
|
||||
|
||||
UAVObjectFieldInt16::UAVObjectFieldInt16(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldInt16::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt16::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt16::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint16 value;
|
||||
value = qFromLittleEndian<qint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldInt16::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldInt16::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint16 tmpValue;
|
||||
tmpValue = (qint16)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldInt16::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
qint16 UAVObjectFieldInt16::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldInt16::setValue(qint16 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint16.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDINT16_H
|
||||
#define UAVOBJECTFIELDINT16_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldInt16: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldInt16(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldInt16(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
qint16 getValue(quint32 index = 0);
|
||||
void setValue(qint16 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDINT16_H
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint32.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfieldint32.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldInt32::UAVObjectFieldInt32(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint32);
|
||||
}
|
||||
|
||||
UAVObjectFieldInt32::UAVObjectFieldInt32(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldInt32::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt32::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<qint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt32::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
qint32 value;
|
||||
value = qFromLittleEndian<qint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldInt32::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldInt32::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint32 tmpValue;
|
||||
tmpValue = (qint32)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldInt32::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt32::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldInt32::setValue(qint32 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint32.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDINT32_H
|
||||
#define UAVOBJECTFIELDINT32_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldInt32: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldInt32(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldInt32(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
qint32 getValue(quint32 index = 0);
|
||||
void setValue(qint32 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDINT32_H
|
@ -1,167 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint8.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfieldint8.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldInt8::UAVObjectFieldInt8(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint8);
|
||||
}
|
||||
|
||||
UAVObjectFieldInt8::UAVObjectFieldInt8(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(qint8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldInt8::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt8::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldInt8::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldInt8::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldInt8::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint8 tmpValue;
|
||||
tmpValue = (qint8)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldInt8::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
qint8 UAVObjectFieldInt8::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
qint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldInt8::setValue(qint8 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldint8.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDINT8_H
|
||||
#define UAVOBJECTFIELDINT8_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldInt8: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldInt8(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldInt8(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
qint8 getValue(quint32 index = 0);
|
||||
void setValue(qint8 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDINT8_H
|
@ -1,41 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfields.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDS_H
|
||||
#define UAVOBJECTFIELDS_H
|
||||
|
||||
#include "uavobjectfieldint8.h"
|
||||
#include "uavobjectfieldint16.h"
|
||||
#include "uavobjectfieldint32.h"
|
||||
#include "uavobjectfielduint8.h"
|
||||
#include "uavobjectfielduint16.h"
|
||||
#include "uavobjectfielduint32.h"
|
||||
#include "uavobjectfieldfloat.h"
|
||||
#include "uavobjectfieldenum.h"
|
||||
#include "uavobjectfieldstring.h"
|
||||
|
||||
#endif // UAVOBJECTFIELDS_H
|
@ -1,198 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldenum.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavobjectfieldstring.h"
|
||||
#include <QtEndian>
|
||||
|
||||
UAVObjectFieldString::UAVObjectFieldString(const QString& name, quint32 maxSize):
|
||||
UAVObjectField(name, QString(""), maxSize)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
}
|
||||
|
||||
QString UAVObjectFieldString::getString()
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Null terminate last element
|
||||
setValue('\0', numElements - 1);
|
||||
// Read characters into string until a null is received
|
||||
QString str;
|
||||
quint8 ch;
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
// Get character and check if end of string is received
|
||||
ch = getValue(index);
|
||||
if ( ch != '\0' )
|
||||
{
|
||||
str.append(ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
return str;
|
||||
}
|
||||
|
||||
void UAVObjectFieldString::setString(QString& str)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Copy string to data
|
||||
QByteArray barray = str.toAscii();
|
||||
quint32 index;
|
||||
for (index = 0; index < (quint32)barray.length() && index < (numElements-1); ++index)
|
||||
{
|
||||
setValue(barray[index], index);
|
||||
}
|
||||
// Null terminate
|
||||
setValue('\0', index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldString::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldString::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldString::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldString::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldString::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 tmpValue;
|
||||
tmpValue = (quint8)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldString::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
quint8 UAVObjectFieldString::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldString::setValue(quint8 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfieldstring.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDSTRING_H
|
||||
#define UAVOBJECTFIELDSTRING_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QStringList>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldString: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldString(const QString& name, quint32 maxSize);
|
||||
QString getString();
|
||||
void setString(QString& str);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
|
||||
quint8 getValue(quint32 index = 0);
|
||||
void setValue(quint8 value, quint32 index = 0);
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDSTRING_H
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint16.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfielduint16.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldUInt16::UAVObjectFieldUInt16(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint16);
|
||||
}
|
||||
|
||||
UAVObjectFieldUInt16::UAVObjectFieldUInt16(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldUInt16::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt16::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint16>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt16::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint16 value;
|
||||
value = qFromLittleEndian<quint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldUInt16::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldUInt16::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint16 tmpValue;
|
||||
tmpValue = (quint16)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldUInt16::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
quint16 UAVObjectFieldUInt16::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint16 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldUInt16::setValue(quint16 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint16.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDUINT16_H
|
||||
#define UAVOBJECTFIELDUINT16_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldUInt16: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldUInt16(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldUInt16(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
quint16 getValue(quint32 index = 0);
|
||||
void setValue(quint16 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDUINT16_H
|
@ -1,171 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint32.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfielduint32.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldUInt32::UAVObjectFieldUInt32(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
}
|
||||
|
||||
UAVObjectFieldUInt32::UAVObjectFieldUInt32(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldUInt32::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt32::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
qToLittleEndian<quint32>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt32::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
quint32 value;
|
||||
value = qFromLittleEndian<quint32>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldUInt32::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldUInt32::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint32 tmpValue;
|
||||
tmpValue = (quint32)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldUInt32::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
quint32 UAVObjectFieldUInt32::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint32 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldUInt32::setValue(quint32 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint32.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDUINT32_H
|
||||
#define UAVOBJECTFIELDUINT32_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldUInt32: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldUInt32(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldUInt32(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
quint32 getValue(quint32 index = 0);
|
||||
void setValue(quint32 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDUINT32_H
|
@ -1,167 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint8.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavobjectfielduint8.h"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
UAVObjectFieldUInt8::UAVObjectFieldUInt8(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
}
|
||||
|
||||
UAVObjectFieldUInt8::UAVObjectFieldUInt8(const QString& name, const QString& units, const QStringList& elementNames):
|
||||
UAVObjectField(name, units, elementNames)
|
||||
{
|
||||
numBytesPerElement = sizeof(quint8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all values
|
||||
*/
|
||||
void UAVObjectFieldUInt8::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt8::pack(quint8* dataOut)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
qint32 UAVObjectFieldUInt8::unpack(const quint8* dataIn)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Pack each element in output buffer
|
||||
for (quint32 index = 0; index < numElements; ++index)
|
||||
{
|
||||
data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index];
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
double UAVObjectFieldUInt8::getDouble(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
double ret = 0.0;
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
ret = (double)value;
|
||||
}
|
||||
// Done
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value from a double.
|
||||
*/
|
||||
void UAVObjectFieldUInt8::setDouble(double value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 tmpValue;
|
||||
tmpValue = (quint8)value;
|
||||
memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of bytes per field element.
|
||||
*/
|
||||
quint32 UAVObjectFieldUInt8::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
quint8 UAVObjectFieldUInt8::getValue(quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
quint8 value;
|
||||
memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field value.
|
||||
*/
|
||||
void UAVObjectFieldUInt8::setValue(quint8 value, quint32 index)
|
||||
{
|
||||
QMutexLocker locker(obj->getMutex());
|
||||
// Check if index is out of bounds or no data available
|
||||
if (index < numElements && data != NULL)
|
||||
{
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
|
||||
// Emit updated event
|
||||
emit fieldUpdated(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavobjectfielduint8.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup uavobjects_plugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef UAVOBJECTFIELDUINT8_H
|
||||
#define UAVOBJECTFIELDUINT8_H
|
||||
|
||||
#include "uavobjects_global.h"
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
// Note: This class could be implemented as a template but due to limitations of the Qt
|
||||
// plugins it not possible.
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldUInt8: public UAVObjectField
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAVObjectFieldUInt8(const QString& name, const QString& units, quint32 numElements);
|
||||
UAVObjectFieldUInt8(const QString& name, const QString& units, const QStringList& elementNames);
|
||||
void initializeValues();
|
||||
qint32 pack(quint8* dataOut);
|
||||
qint32 unpack(const quint8* dataIn);
|
||||
double getDouble(quint32 index = 0);
|
||||
void setDouble(double value, quint32 index = 0);
|
||||
quint32 getNumBytesElement();
|
||||
quint8 getValue(quint32 index = 0);
|
||||
void setValue(quint8 value, quint32 index = 0);
|
||||
|
||||
private:
|
||||
quint32 numBytesPerElement;
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDUINT8_H
|
@ -11,18 +11,8 @@ HEADERS += uavobjects_global.h \
|
||||
uavobjectsinit.h \
|
||||
uavobjectsplugin.h \
|
||||
examplesettings.h \
|
||||
uavobjectfieldenum.h \
|
||||
uavobjectfieldstring.h \
|
||||
exampleobject2.h \
|
||||
exampleobject1.h \
|
||||
uavobjectfieldint8.h \
|
||||
uavobjectfieldint16.h \
|
||||
uavobjectfieldint32.h \
|
||||
uavobjectfieldfloat.h \
|
||||
uavobjectfielduint8.h \
|
||||
uavobjectfielduint16.h \
|
||||
uavobjectfielduint32.h \
|
||||
uavobjectfields.h \
|
||||
gpsobject.h \
|
||||
gcstelemetrystats.h \
|
||||
flighttelemetrystats.h \
|
||||
@ -37,17 +27,8 @@ SOURCES += uavobject.cpp \
|
||||
uavobjectsinit.cpp \
|
||||
uavobjectsplugin.cpp \
|
||||
examplesettings.cpp \
|
||||
uavobjectfieldenum.cpp \
|
||||
uavobjectfieldstring.cpp \
|
||||
exampleobject2.cpp \
|
||||
exampleobject1.cpp \
|
||||
uavobjectfieldint8.cpp \
|
||||
uavobjectfieldint16.cpp \
|
||||
uavobjectfieldint32.cpp \
|
||||
uavobjectfieldfloat.cpp \
|
||||
uavobjectfielduint8.cpp \
|
||||
uavobjectfielduint16.cpp \
|
||||
uavobjectfielduint32.cpp \
|
||||
gpsobject.cpp \
|
||||
gcstelemetrystats.cpp \
|
||||
flighttelemetrystats.cpp \
|
||||
|
@ -29,7 +29,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "$(NAMELC).h"
|
||||
#include "uavobjectfields.h"
|
||||
#include "uavobjectfield.h"
|
||||
|
||||
const QString $(NAME)::NAME = QString("$(NAME)");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user