From fe212a22e7a3c642751042facf6182a15bba1465 Mon Sep 17 00:00:00 2001 From: vassilis Date: Thu, 1 Apr 2010 02:00:19 +0000 Subject: [PATCH] OP-54: GCS\UAVObjects added new field types (unsigned, enum and string) and refactored UAVObjectFields to use templates git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@416 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/uavobjects/exampleobject.cpp | 20 +- ground/src/plugins/uavobjects/exampleobject.h | 104 +++++---- .../plugins/uavobjects/examplesettings.cpp | 10 +- .../src/plugins/uavobjects/examplesettings.h | 95 ++++---- .../plugins/uavobjects/tests/testobject1.cpp | 52 ----- .../plugins/uavobjects/tests/testobject1.h | 33 --- .../uavobjects/tests/uavobjectstest.cpp | 30 +-- .../uavobjects/tests/uavobjectstest.pro | 10 +- .../src/plugins/uavobjects/uavmetaobject.cpp | 17 +- .../src/plugins/uavobjects/uavobjectfield.cpp | 208 +----------------- .../src/plugins/uavobjects/uavobjectfield.h | 33 +-- .../plugins/uavobjects/uavobjectfieldenum.cpp | 69 ++++++ .../plugins/uavobjects/uavobjectfieldenum.h | 49 +++++ .../uavobjects/uavobjectfieldprimitives.cpp | 181 +++++++++++++++ .../uavobjects/uavobjectfieldprimitives.h | 94 ++++++++ .../uavobjects/uavobjectfieldstring.cpp | 75 +++++++ .../plugins/uavobjects/uavobjectfieldstring.h | 44 ++++ ground/src/plugins/uavobjects/uavobjects.pro | 10 +- .../plugins/uavobjects/uavobjecttemplate.cpp | 2 +- .../plugins/uavobjects/uavobjecttemplate.h | 95 ++++---- 20 files changed, 743 insertions(+), 488 deletions(-) delete mode 100644 ground/src/plugins/uavobjects/tests/testobject1.cpp delete mode 100644 ground/src/plugins/uavobjects/tests/testobject1.h create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldenum.cpp create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldenum.h create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldprimitives.h create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldstring.cpp create mode 100644 ground/src/plugins/uavobjects/uavobjectfieldstring.h diff --git a/ground/src/plugins/uavobjects/exampleobject.cpp b/ground/src/plugins/uavobjects/exampleobject.cpp index 8e8e8836a..fdf3e0d73 100644 --- a/ground/src/plugins/uavobjects/exampleobject.cpp +++ b/ground/src/plugins/uavobjects/exampleobject.cpp @@ -36,10 +36,14 @@ ExampleObject::ExampleObject(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, N { // Create fields QList fields; - fields.append(new UAVObjectField(QString("field1"), QString("unit1"), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("field2"), QString("unit2"), UAVObjectField::FIELDTYPE_INT16, 1)); - fields.append(new UAVObjectField(QString("field3"), QString("unit3"), UAVObjectField::FIELDTYPE_FLOAT32, 4)); - fields.append(new UAVObjectField(QString("field4"), QString("unit4"), UAVObjectField::FIELDTYPE_INT32, 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field1"), QString("unit1"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field2"), QString("unit2"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field3"), QString("unit3"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field4"), QString("unit4"), 4)); + fields.append(new UAVObjectFieldPrimitives(QString("field5"), QString("unit5"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field6"), QString("unit6"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field7"), QString("unit7"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("field8"), QString("unit8"), 1)); // Initialize object initializeFields(fields, (quint8*)&data, NUMBYTES); @@ -49,11 +53,11 @@ UAVObject::Metadata ExampleObject::getDefaultMetadata() { UAVObject::Metadata metadata; metadata.gcsTelemetryAcked = 1; - metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; - metadata.gcsTelemetryUpdatePeriod = 100; + metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; + metadata.gcsTelemetryUpdatePeriod = 0; metadata.flightTelemetryAcked = 1; metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE; - metadata.flightTelemetryUpdatePeriod = 0; + metadata.flightTelemetryUpdatePeriod = 100; metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER; metadata.loggingUpdatePeriod = 0; return metadata; @@ -61,7 +65,7 @@ UAVObject::Metadata ExampleObject::getDefaultMetadata() ExampleObject::DataFields ExampleObject::getData() { - QMutexLocker locker(mutex); + QMutexLocker locker(mutex); return data; } diff --git a/ground/src/plugins/uavobjects/exampleobject.h b/ground/src/plugins/uavobjects/exampleobject.h index 9a68d5f3c..e4bc94b1c 100644 --- a/ground/src/plugins/uavobjects/exampleobject.h +++ b/ground/src/plugins/uavobjects/exampleobject.h @@ -1,17 +1,17 @@ /** - ****************************************************************************** - * - * @file exampleobject.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Implementation of the ExampleObject object. This file has been - * automatically generated by the UAVObjectGenerator. - * - * @note Object definition file: exampleobject.xml. - * This is an automatically generated file. - * DO NOT modify manually. - * - * @see The GNU Public License (GPL) Version 3 - * + ****************************************************************************** + * + * @file exampleobject.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the ExampleObject object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: exampleobject.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -28,38 +28,50 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef EXAMPLEOBJECT_H -#define EXAMPLEOBJECT_H - -#include "uavdataobject.h" - -class ExampleObject: public UAVDataObject -{ -public: - typedef struct { +#ifndef EXAMPLEOBJECT_H +#define EXAMPLEOBJECT_H + +#include "uavdataobject.h" +#include "uavobjectfieldprimitives.h" + +class ExampleObject: public UAVDataObject +{ +public: + // Field structure + typedef struct { qint8 field1; qint16 field2; - float field3[4]; - qint32 field4; - - } __attribute__((packed)) DataFields; - - static const quint32 OBJID = 3048370380U; - static const QString NAME; - static const bool ISSINGLEINST = 0; - static const bool ISSETTINGS = 0; - static const quint32 NUMBYTES = sizeof(DataFields); - - ExampleObject(); - - DataFields getData(); - void setData(DataFields& data); - Metadata getDefaultMetadata(); - UAVDataObject* clone(quint32 instID); - -private: - DataFields data; - -}; - -#endif // EXAMPLEOBJECT_H + qint32 field3; + float field4[4]; + quint8 field5; + quint16 field6; + quint32 field7; + quint8 field8; + + } __attribute__((packed)) DataFields; + + // Enumeration types + typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } FIELD8Enum; + + + // Constants + static const quint32 OBJID = 1785231914U; + static const QString NAME; + static const bool ISSINGLEINST = 0; + static const bool ISSETTINGS = 0; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + ExampleObject(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // EXAMPLEOBJECT_H diff --git a/ground/src/plugins/uavobjects/examplesettings.cpp b/ground/src/plugins/uavobjects/examplesettings.cpp index 8df139a3a..abb2e5257 100644 --- a/ground/src/plugins/uavobjects/examplesettings.cpp +++ b/ground/src/plugins/uavobjects/examplesettings.cpp @@ -36,10 +36,10 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING { // Create fields QList fields; - fields.append(new UAVObjectField(QString("setting1"), QString("unit1"), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("setting2"), QString("unit2"), UAVObjectField::FIELDTYPE_INT16, 1)); - fields.append(new UAVObjectField(QString("setting3"), QString("unit3"), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("setting4"), QString("unit4"), UAVObjectField::FIELDTYPE_INT32, 1)); + fields.append(new UAVObjectFieldPrimitives(QString("setting1"), QString("unit1"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("setting2"), QString("unit2"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("setting3"), QString("unit3"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("setting4"), QString("unit4"), 1)); // Initialize object initializeFields(fields, (quint8*)&data, NUMBYTES); @@ -61,7 +61,7 @@ UAVObject::Metadata ExampleSettings::getDefaultMetadata() ExampleSettings::DataFields ExampleSettings::getData() { - QMutexLocker locker(mutex); + QMutexLocker locker(mutex); return data; } diff --git a/ground/src/plugins/uavobjects/examplesettings.h b/ground/src/plugins/uavobjects/examplesettings.h index aaf6e4bb4..e233ab6e4 100644 --- a/ground/src/plugins/uavobjects/examplesettings.h +++ b/ground/src/plugins/uavobjects/examplesettings.h @@ -1,17 +1,17 @@ /** - ****************************************************************************** - * - * @file examplesettings.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Implementation of the ExampleSettings object. This file has been - * automatically generated by the UAVObjectGenerator. - * - * @note Object definition file: examplesettings.xml. - * This is an automatically generated file. - * DO NOT modify manually. - * - * @see The GNU Public License (GPL) Version 3 - * + ****************************************************************************** + * + * @file examplesettings.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the ExampleSettings object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: examplesettings.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -28,38 +28,45 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef EXAMPLESETTINGS_H -#define EXAMPLESETTINGS_H - -#include "uavdataobject.h" - -class ExampleSettings: public UAVDataObject -{ -public: - typedef struct { +#ifndef EXAMPLESETTINGS_H +#define EXAMPLESETTINGS_H + +#include "uavdataobject.h" +#include "uavobjectfieldprimitives.h" + +class ExampleSettings: public UAVDataObject +{ +public: + // Field structure + typedef struct { qint8 setting1; qint16 setting2; qint8 setting3; qint32 setting4; - - } __attribute__((packed)) DataFields; - - static const quint32 OBJID = 3555345034U; - static const QString NAME; - static const bool ISSINGLEINST = 1; - static const bool ISSETTINGS = 1; - static const quint32 NUMBYTES = sizeof(DataFields); - - ExampleSettings(); - - DataFields getData(); - void setData(DataFields& data); - Metadata getDefaultMetadata(); - UAVDataObject* clone(quint32 instID); - -private: - DataFields data; - -}; - -#endif // EXAMPLESETTINGS_H + + } __attribute__((packed)) DataFields; + + // Enumeration types + + + // Constants + static const quint32 OBJID = 3555345034U; + static const QString NAME; + static const bool ISSINGLEINST = 1; + static const bool ISSETTINGS = 1; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + ExampleSettings(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // EXAMPLESETTINGS_H diff --git a/ground/src/plugins/uavobjects/tests/testobject1.cpp b/ground/src/plugins/uavobjects/tests/testobject1.cpp deleted file mode 100644 index 01750f6af..000000000 --- a/ground/src/plugins/uavobjects/tests/testobject1.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "testobject1.h" - -const QString TestObject1::NAME = QString("TestObject1"); - -TestObject1::TestObject1(): UAVDataObject(OBJID, SINGLEINST, NAME) -{ - // Create fields - QList fields; - fields.append(new UAVObjectField(QString("Field1"), QString("unit1"), UAVObjectField::FIELDTYPE_INT16, 1)); - fields.append(new UAVObjectField(QString("Field2"), QString("unit2"), UAVObjectField::FIELDTYPE_FLOAT32, 3)); - fields.append(new UAVObjectField(QString("Field3"), QString("unit3"), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("Field4"), QString("unit4"), UAVObjectField::FIELDTYPE_INT32, 1)); - - // Initialize object - initializeFields(fields, (quint8*)&data, NUMBYTES); -} - -UAVObject::Metadata TestObject1::getDefaultMetadata() -{ - // Create metadata - UAVObject::Metadata metadata; - metadata.gcsTelemetryAcked = true; - metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; - metadata.gcsTelemetryUpdatePeriod = 200; - metadata.flightTelemetryAcked = true; - metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_NEVER; - metadata.flightTelemetryUpdatePeriod = 0; - metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER; - metadata.loggingUpdatePeriod = 0; - return metadata; -} - -TestObject1::DataFields TestObject1::getData() -{ - QMutexLocker locker(mutex); - return data; -} - -void TestObject1::setData(DataFields& data) -{ - QMutexLocker locker(mutex); - this->data = data; - emit objectUpdatedAuto(this); // trigger object updated event - emit objectUpdated(this); -} - -UAVDataObject* TestObject1::clone(quint32 instID) -{ - TestObject1* obj = new TestObject1(); - obj->initialize(instID, this->getMetaObject()); - return obj; -} diff --git a/ground/src/plugins/uavobjects/tests/testobject1.h b/ground/src/plugins/uavobjects/tests/testobject1.h deleted file mode 100644 index 57ace76c1..000000000 --- a/ground/src/plugins/uavobjects/tests/testobject1.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef TESTOBJECT1_H -#define TESTOBJECT1_H - -#include "..\uavdataobject.h" - -class TestObject1: public UAVDataObject -{ -public: - typedef struct { - qint16 field1; - float field2[3]; - qint8 field3; - qint32 field4; - } __attribute__((packed)) DataFields; - - static const quint32 OBJID = 0x0005; - static const QString NAME; - static const bool SINGLEINST = false; - static const quint32 NUMBYTES = sizeof(DataFields); - - TestObject1(); - - DataFields getData(); - void setData(DataFields& data); - Metadata getDefaultMetadata(); - UAVDataObject* clone(quint32 instID); - -private: - DataFields data; - -}; - -#endif // TESTOBJECT1_H diff --git a/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp b/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp index aed22e9e8..0119ee866 100644 --- a/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp +++ b/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp @@ -68,11 +68,11 @@ void UAVObjectsTest::runTest() // Set data ExampleObject::DataFields data = obj1->getData(); data.field1 = 1; - data.field3[0] = 2.1; - data.field3[1] = 2.2; - data.field3[2] = 2.3; - data.field2 = 3; - data.field4 = 4; + data.field2 = 2; + data.field3 = 3; + data.field4[0] = 4.1; + data.field4[1] = 4.2; + data.field4[2] = 4.3; obj1->setData(data); // Set metadata @@ -93,22 +93,22 @@ void UAVObjectsTest::runTest() quint8* buf = new quint8[obj1->getNumBytes()]; obj1->pack(buf); data.field1 = 10; - data.field3[0] = 20.1; - data.field3[1] = 20.2; - data.field3[2] = 20.3; - data.field2 = 30; - data.field4 = 40; + data.field2 = 20; + data.field3 = 30; + data.field4[0] = 40.1; + data.field4[1] = 40.2; + data.field4[2] = 40.3; obj1->setData(data); obj1->unpack(buf); // Save, load testing obj1->save(); data.field1 = 10; - data.field3[0] = 20.1; - data.field3[1] = 20.2; - data.field3[2] = 20.3; - data.field2 = 30; - data.field4 = 40; + data.field2 = 20; + data.field3 = 30; + data.field4[0] = 40.1; + data.field4[1] = 40.2; + data.field4[2] = 40.3; obj1->setData(data); obj1->load(); diff --git a/ground/src/plugins/uavobjects/tests/uavobjectstest.pro b/ground/src/plugins/uavobjects/tests/uavobjectstest.pro index 4e9fadcfc..370332ba8 100644 --- a/ground/src/plugins/uavobjects/tests/uavobjectstest.pro +++ b/ground/src/plugins/uavobjects/tests/uavobjectstest.pro @@ -13,11 +13,17 @@ SOURCES += main.cpp \ ../uavmetaobject.cpp \ ../uavdataobject.cpp \ uavobjectstest.cpp \ - ../exampleobject.cpp + ../exampleobject.cpp \ + ../uavobjectfieldprimitives.cpp \ + ../uavobjectfieldenum.cpp \ + ../uavobjectfieldstring.cpp HEADERS += ../uavobjectmanager.h \ ../uavobjectfield.h \ ../uavobject.h \ ../uavmetaobject.h \ ../uavdataobject.h \ uavobjectstest.h \ - ../exampleobject.h + ../exampleobject.h \ + ../uavobjectfieldprimitives.h \ + ../uavobjectfieldenum.h \ + ../uavobjectfieldstring.h diff --git a/ground/src/plugins/uavobjects/uavmetaobject.cpp b/ground/src/plugins/uavobjects/uavmetaobject.cpp index 4581956ea..ca5c9a281 100644 --- a/ground/src/plugins/uavobjects/uavmetaobject.cpp +++ b/ground/src/plugins/uavobjects/uavmetaobject.cpp @@ -26,6 +26,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "uavmetaobject.h" +#include "uavobjectfieldprimitives.h" /** * Constructor @@ -45,14 +46,14 @@ UAVMetaObject::UAVMetaObject(quint32 objID, const QString& name, UAVObject* pare ownMetadata.loggingUpdatePeriod = 0; // Setup fields QList fields; - fields.append(new UAVObjectField(QString("FlightTelemetryAcked"), QString(""), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("FlightTelemetryUpdateMode"), QString(""), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("FlightTelemetryUpdatePeriod"), QString("ms"), UAVObjectField::FIELDTYPE_INT32, 1)); - fields.append(new UAVObjectField(QString("GCSTelemetryAcked"), QString(""), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("GCSTelemetryUpdateMode"), QString(""), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("GCSTelemetryUpdatePeriod"), QString("ms"), UAVObjectField::FIELDTYPE_INT32, 1)); - fields.append(new UAVObjectField(QString("LoggingUpdateMode"), QString(""), UAVObjectField::FIELDTYPE_INT8, 1)); - fields.append(new UAVObjectField(QString("LoggingUpdatePeriod"), QString("ms"), UAVObjectField::FIELDTYPE_INT32, 1)); + fields.append(new UAVObjectFieldPrimitives(QString("FlightTelemetryAcked"), QString(""), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("FlightTelemetryUpdateMode"), QString(""), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("FlightTelemetryUpdatePeriod"), QString("ms"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("GCSTelemetryAcked"), QString(""), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("GCSTelemetryUpdateMode"), QString(""), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("GCSTelemetryUpdatePeriod"), QString("ms"), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("LoggingUpdateMode"), QString(""), 1)); + fields.append(new UAVObjectFieldPrimitives(QString("LoggingUpdatePeriod"), QString("ms"), 1)); // Initialize parent UAVObject::initialize(0); UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata)); diff --git a/ground/src/plugins/uavobjects/uavobjectfield.cpp b/ground/src/plugins/uavobjects/uavobjectfield.cpp index f967ef6e8..0ec3dd4fa 100644 --- a/ground/src/plugins/uavobjects/uavobjectfield.cpp +++ b/ground/src/plugins/uavobjects/uavobjectfield.cpp @@ -28,32 +28,15 @@ #include "uavobjectfield.h" #include -UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements) +UAVObjectField::UAVObjectField(const QString& name, const QString& units, quint32 numElements) { // Copy params this->name = name; this->units = units; - this->type = type; this->numElements = numElements; this->offset = 0; this->data = NULL; this->obj = NULL; - // Calculate the number of bytes per element based on the type - switch (type) { - case FIELDTYPE_CHAR: - case FIELDTYPE_INT8: - this->numBytesPerElement = 1; - break; - case FIELDTYPE_INT16: - this->numBytesPerElement = 2; - break; - case FIELDTYPE_INT32: - case FIELDTYPE_FLOAT32: - this->numBytesPerElement = 4; - break; - default: - this->numBytesPerElement = 0; - } } void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj) @@ -62,6 +45,7 @@ void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj this->offset = dataOffset; this->obj = obj; clear(); + initializeValues(); } UAVObject* UAVObjectField::getObject() @@ -74,7 +58,7 @@ void UAVObjectField::clear() if (data != NULL) { QMutexLocker locker(obj->getMutex()); - for (unsigned int n = 0; n < numBytesPerElement*numElements; ++n) + for (unsigned int n = 0; n < getNumBytesElement()*numElements; ++n) { data[offset + n] = 0; } @@ -91,188 +75,11 @@ QString UAVObjectField::getUnits() return units; } -UAVObjectField::FieldType UAVObjectField::getType() -{ - return type; -} - quint32 UAVObjectField::getNumElements() { return numElements; } -qint32 UAVObjectField::pack(quint8* dataOut) -{ - QMutexLocker locker(obj->getMutex()); - // Pack each element in output buffer - for (quint32 index = 0; index < numElements; ++index) - { - switch (type) { - case FIELDTYPE_CHAR: - case FIELDTYPE_INT8: - dataOut[numBytesPerElement*index] = data[offset + numBytesPerElement*index]; - break; - case FIELDTYPE_INT16: - qint16 value16; - memcpy(&value16, &data[offset + numBytesPerElement*index], 2); - qToBigEndian(value16, &dataOut[numBytesPerElement*index]); - break; - case FIELDTYPE_INT32: - case FIELDTYPE_FLOAT32: - qint32 value32; - memcpy(&value32, &data[offset + numBytesPerElement*index], 4); - qToBigEndian(value32, &dataOut[numBytesPerElement*index]); - break; - default: - return 0; - } - } - // Done - return getNumBytes(); -} - -qint32 UAVObjectField::unpack(const quint8* dataIn) -{ - QMutexLocker locker(obj->getMutex()); - // Pack each element in output buffer - for (quint32 index = 0; index < numElements; ++index) - { - switch (type) { - case FIELDTYPE_CHAR: - case FIELDTYPE_INT8: - data[offset + numBytesPerElement*index] = dataIn[numBytesPerElement*index]; - break; - case FIELDTYPE_INT16: - qint16 value16; - value16 = qFromBigEndian(&dataIn[numBytesPerElement*index]); - memcpy(&data[offset + numBytesPerElement*index], &value16, 2); - break; - case FIELDTYPE_INT32: - case FIELDTYPE_FLOAT32: - qint32 value32; - value32 = qFromBigEndian(&dataIn[numBytesPerElement*index]); - memcpy(&data[offset + numBytesPerElement*index], &value32, 4); - break; - default: - return 0; - } - } - // Done - return getNumBytes(); -} - -double UAVObjectField::getValue(quint32 index) -{ - double ret = 0.0; - - // Check if index is out of bounds or no data available - if (index < numElements && data != NULL) - { - // Get value from data - QMutexLocker locker(obj->getMutex()); - switch (type) { - case FIELDTYPE_CHAR: - case FIELDTYPE_INT8: - qint8 value8; - value8 = data[offset + numBytesPerElement*index]; - ret = (double)value8; - break; - case FIELDTYPE_INT16: - qint16 value16; - memcpy(&value16, &data[offset + numBytesPerElement*index], 2); - ret = (double)value16; - break; - case FIELDTYPE_INT32: - qint32 value32; - memcpy(&value32, &data[offset + numBytesPerElement*index], 4); - ret = (double)value32; - break; - case FIELDTYPE_FLOAT32: - float valuef; - memcpy(&valuef, &data[offset + numBytesPerElement*index], 4); - ret = (double)valuef; - break; - default: - ret = 0.0; - } - } - return ret; -} - -void UAVObjectField::setValue(double value, quint32 index) -{ - // Check if index is out of bounds or no data available - if (index < numElements && data != NULL) - { - // Set value - QMutexLocker locker(obj->getMutex()); - switch (type) { - case FIELDTYPE_CHAR: - case FIELDTYPE_INT8: - data[offset + numBytesPerElement*index] = (qint8)value; - break; - case FIELDTYPE_INT16: - qint16 value16; - value16 = (qint16)value; - memcpy(&data[offset + numBytesPerElement*index], &value16, 2); - break; - case FIELDTYPE_INT32: - qint32 value32; - value32 = (qint32)value; - memcpy(&data[offset + numBytesPerElement*index], &value32, 4); - break; - case FIELDTYPE_FLOAT32: - float valuef; - valuef = (float)value; - memcpy(&data[offset + numBytesPerElement*index], &valuef, 4); - break; - } - } - - // Emit updated event - emit fieldUpdated(this); -} - -double UAVObjectField::getValue() -{ - return getValue(0); -} - -void UAVObjectField::setValue(double value) -{ - setValue(value, 0); -} - - -QString UAVObjectField::getString() -{ - QString str; - if (data != NULL) - { - QMutexLocker locker(obj->getMutex()); - data[offset + numElements - 1] = '\0'; // null terminate - if (type == FIELDTYPE_CHAR) - { - str.append((char*)&data[offset]); - } - } - return str; -} - -void UAVObjectField::setString(QString& str) -{ - QByteArray barray = str.toAscii(); - if (data != NULL) - { - QMutexLocker locker(obj->getMutex()); - for (int n = 0; n < barray.length() && n < (int)numElements; ++n) - { - data[offset+n] = barray[n]; - } - data[offset + numElements - 1] = '\0'; // null terminate - } -} - quint32 UAVObjectField::getDataOffset() { return offset; @@ -280,12 +87,7 @@ quint32 UAVObjectField::getDataOffset() quint32 UAVObjectField::getNumBytes() { - return numBytesPerElement * numElements; -} - -quint32 UAVObjectField::getNumBytesElement() -{ - return numBytesPerElement; + return getNumBytesElement() * numElements; } QString UAVObjectField::toString() @@ -294,7 +96,7 @@ QString UAVObjectField::toString() sout.append ( QString("%1: [ ").arg(name) ); for (unsigned int n = 0; n < numElements; ++n) { - sout.append( QString("%1 ").arg(getValue(n)) ); + sout.append( QString("%1 ").arg(getDouble(n)) ); } sout.append( QString("] %1\n").arg(units) ); return sout; diff --git a/ground/src/plugins/uavobjects/uavobjectfield.h b/ground/src/plugins/uavobjects/uavobjectfield.h index bd85bdae6..a3a800038 100644 --- a/ground/src/plugins/uavobjects/uavobjectfield.h +++ b/ground/src/plugins/uavobjects/uavobjectfield.h @@ -38,46 +38,29 @@ class UAVOBJECTS_EXPORT UAVObjectField: public QObject Q_OBJECT public: - /** - * Recognized field types - */ - typedef enum { - FIELDTYPE_INT8 = 0, - FIELDTYPE_INT16, - FIELDTYPE_INT32, - FIELDTYPE_FLOAT32, - FIELDTYPE_CHAR - } FieldType; - - UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements); + UAVObjectField(const QString& name, const QString& units, quint32 numElements); void initialize(quint8* data, quint32 dataOffset, UAVObject* obj); + virtual void initializeValues() = 0; UAVObject* getObject(); QString getName(); QString getUnits(); - FieldType getType(); quint32 getNumElements(); - qint32 pack(quint8* dataOut); - qint32 unpack(const quint8* dataIn); - double getValue(); - void setValue(double value); - double getValue(quint32 index); - void setValue(double value, quint32 index); - QString getString(); - void setString(QString& str); + 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; quint32 getDataOffset(); quint32 getNumBytes(); - quint32 getNumBytesElement(); + virtual quint32 getNumBytesElement() = 0; QString toString(); signals: void fieldUpdated(UAVObjectField* field); -private: +protected: QString name; QString units; - FieldType type; quint32 numElements; - quint32 numBytesPerElement; quint32 offset; quint8* data; UAVObject* obj; diff --git a/ground/src/plugins/uavobjects/uavobjectfieldenum.cpp b/ground/src/plugins/uavobjects/uavobjectfieldenum.cpp new file mode 100644 index 000000000..b9738d6b7 --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldenum.cpp @@ -0,0 +1,69 @@ +/** + ****************************************************************************** + * + * @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" + +UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, QStringList& options): + UAVObjectFieldPrimitives(name, units, numElements) +{ + this->options = options; +} + +QStringList UAVObjectFieldEnum::getOptions() +{ + return options; +} + +QString UAVObjectFieldEnum::getSelected() +{ + return options[getValue()]; +} + +void UAVObjectFieldEnum::setSelected(QString& val) +{ + // Find index of selected value + int index = options.indexOf(val); + if (index >= 0) + { + setValue(index); + } +} + +quint8 UAVObjectFieldEnum::getSelectedIndex() +{ + return getValue(); +} + +void UAVObjectFieldEnum::setSelectedIndex(quint8 index) +{ + // Check that the index is valid + if (index < options.length()) + { + setValue(index); + } +} diff --git a/ground/src/plugins/uavobjects/uavobjectfieldenum.h b/ground/src/plugins/uavobjects/uavobjectfieldenum.h new file mode 100644 index 000000000..89302822c --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldenum.h @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @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 "uavobjectfieldprimitives.h" +#include + +class UAVOBJECTS_EXPORT UAVObjectFieldEnum: public UAVObjectFieldPrimitives +{ +public: + UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, QStringList& options); + QStringList getOptions(); + QString getSelected(); + void setSelected(QString& val); + quint8 getSelectedIndex(); + void setSelectedIndex(quint8 index); + +private: + QStringList options; +}; + +#endif // UAVOBJECTFIELDENUM_H diff --git a/ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp b/ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp new file mode 100644 index 000000000..4ea33d753 --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp @@ -0,0 +1,181 @@ +/** + ****************************************************************************** + * + * @file uavobjectfield.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 "uavobjectfieldprimitives.h" + +/** + * Constructor + */ +template +UAVObjectFieldPrimitives::UAVObjectFieldPrimitives(const QString& name, const QString& units, quint32 numElements): + UAVObjectField(name, units, numElements) +{ + numBytesPerElement = sizeof(FType); +} + +template +void UAVObjectFieldPrimitives::initializeValues() +{ + for (quint32 n = 0; n < numElements; ++n) + { + setValue(0, n); + } +} + +/** + * Pack the field in to an array of bytes. + */ +template +qint32 UAVObjectFieldPrimitives::pack(quint8* dataOut) +{ + QMutexLocker locker(obj->getMutex()); + // Pack each element in output buffer + for (quint32 index = 0; index < numElements; ++index) + { + FType value; + memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); + qToBigEndian(value, &dataOut[numBytesPerElement*index]); + } + // Done + return getNumBytes(); +} + +/** + * Unpack the field from an array of bytes. + */ +template +qint32 UAVObjectFieldPrimitives::unpack(const quint8* dataIn) +{ + QMutexLocker locker(obj->getMutex()); + // Pack each element in output buffer + for (quint32 index = 0; index < numElements; ++index) + { + FType value; + value = qFromBigEndian(&dataIn[numBytesPerElement*index]); + memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement); + } + // Done + return getNumBytes(); +} + +/** + * Get the field value as a double. + */ +template +double UAVObjectFieldPrimitives::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) + { + FType value; + memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); + ret = (double)value; + } + // Done + return ret; +} + +/** + * Set the field value from a double. + */ +template +void UAVObjectFieldPrimitives::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) + { + FType tmpValue; + tmpValue = (FType)value; + memcpy(&data[offset + numBytesPerElement*index], &tmpValue, numBytesPerElement); + } + + // Emit updated event + emit fieldUpdated(this); +} + +/** + * Get the number of bytes per field element. + */ +template +quint32 UAVObjectFieldPrimitives::getNumBytesElement() +{ + return numBytesPerElement; +} + +/** + * Get the field value. + */ +template +FType UAVObjectFieldPrimitives::getValue(quint32 index) +{ + QMutexLocker locker(obj->getMutex()); + // Check if index is out of bounds or no data available + if (index < numElements && data != NULL) + { + FType value; + memcpy(&value, &data[offset + numBytesPerElement*index], numBytesPerElement); + return value; + } + else + { + return 0; + } +} + +/** + * Set the field value. + */ +template +void UAVObjectFieldPrimitives::setValue(FType 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); +} + +/** + * Pre-define valid templates + */ +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; +template class UAVObjectFieldPrimitives; + + + diff --git a/ground/src/plugins/uavobjects/uavobjectfieldprimitives.h b/ground/src/plugins/uavobjects/uavobjectfieldprimitives.h new file mode 100644 index 000000000..425e2de04 --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldprimitives.h @@ -0,0 +1,94 @@ +/** + ****************************************************************************** + * + * @file uavobjectfieldprimitives.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 UAVOBJECTFIELDPRIMITIVES_H +#define UAVOBJECTFIELDPRIMITIVES_H + +#include "uavobjects_global.h" +#include "uavobjectfield.h" +#include + +template +class UAVOBJECTS_EXPORT UAVObjectFieldPrimitives: public UAVObjectField +{ +public: + UAVObjectFieldPrimitives(const QString& name, const QString& units, quint32 numElements); + 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(); + FType getValue(quint32 index = 0); + void setValue(FType value, quint32 index = 0); + +private: + quint32 numBytesPerElement; +}; + + +/** + * Implementation of missing QtEndian templates + */ +template<> inline qint8 qFromBigEndian(const uchar *src) +{ + return *src; +} + +template <> inline void qToBigEndian(qint8 src, uchar *dest) +{ + *dest = src; +} + +template<> inline quint8 qFromBigEndian(const uchar *src) +{ + return *src; +} + +template <> inline void qToBigEndian(quint8 src, uchar *dest) +{ + *dest = src; +} + +template<> inline float qFromBigEndian(const uchar *src) +{ + quint32 tmpint; + float tmpfloat; + tmpint = qFromBigEndian(src); + memcpy(&tmpfloat, &tmpint, sizeof(quint32)); + return tmpfloat; +} + +template <> inline void qToBigEndian(float src, uchar *dest) +{ + quint32 tmpint; + memcpy(&tmpint, &src, sizeof(quint32)); + qToBigEndian(tmpint, dest); +} + + +#endif // UAVOBJECTFIELDPRIMITIVES_H diff --git a/ground/src/plugins/uavobjects/uavobjectfieldstring.cpp b/ground/src/plugins/uavobjects/uavobjectfieldstring.cpp new file mode 100644 index 000000000..4c2f8a19a --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldstring.cpp @@ -0,0 +1,75 @@ +/** + ****************************************************************************** + * + * @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" + +UAVObjectFieldString::UAVObjectFieldString(const QString& name, quint32 maxSize): + UAVObjectFieldPrimitives(name, QString(""), maxSize) +{ +} + +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); +} + + diff --git a/ground/src/plugins/uavobjects/uavobjectfieldstring.h b/ground/src/plugins/uavobjects/uavobjectfieldstring.h new file mode 100644 index 000000000..e51bafde4 --- /dev/null +++ b/ground/src/plugins/uavobjects/uavobjectfieldstring.h @@ -0,0 +1,44 @@ +/** + ****************************************************************************** + * + * @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 "uavobjectfieldprimitives.h" +#include + +class UAVOBJECTS_EXPORT UAVObjectFieldString: public UAVObjectFieldPrimitives +{ +public: + UAVObjectFieldString(const QString& name, quint32 maxSize); + QString getString(); + void setString(QString& str); +private: +}; + +#endif // UAVOBJECTFIELDSTRING_H diff --git a/ground/src/plugins/uavobjects/uavobjects.pro b/ground/src/plugins/uavobjects/uavobjects.pro index ac642c78e..8f82ecaeb 100644 --- a/ground/src/plugins/uavobjects/uavobjects.pro +++ b/ground/src/plugins/uavobjects/uavobjects.pro @@ -11,7 +11,10 @@ HEADERS += uavobjects_global.h \ uavobjectsinit.h \ uavobjectsplugin.h \ examplesettings.h \ - exampleobject.h + exampleobject.h \ + uavobjectfieldprimitives.h \ + uavobjectfieldenum.h \ + uavobjectfieldstring.h SOURCES += uavobject.cpp \ uavmetaobject.cpp \ uavobjectmanager.cpp \ @@ -20,6 +23,9 @@ SOURCES += uavobject.cpp \ uavobjectsinit.cpp \ uavobjectsplugin.cpp \ examplesettings.cpp \ - exampleobject.cpp + exampleobject.cpp \ + uavobjectfieldprimitives.cpp \ + uavobjectfieldenum.cpp \ + uavobjectfieldstring.cpp DEFINES += UAVOBJECTS_LIBRARY OTHER_FILES += UAVObjects.pluginspec diff --git a/ground/src/plugins/uavobjects/uavobjecttemplate.cpp b/ground/src/plugins/uavobjects/uavobjecttemplate.cpp index 358456a3e..701a84827 100644 --- a/ground/src/plugins/uavobjects/uavobjecttemplate.cpp +++ b/ground/src/plugins/uavobjects/uavobjecttemplate.cpp @@ -57,7 +57,7 @@ UAVObject::Metadata $(NAME)::getDefaultMetadata() $(NAME)::DataFields $(NAME)::getData() { - QMutexLocker locker(mutex); + QMutexLocker locker(mutex); return data; } diff --git a/ground/src/plugins/uavobjects/uavobjecttemplate.h b/ground/src/plugins/uavobjects/uavobjecttemplate.h index 085637cf0..37fa388c3 100644 --- a/ground/src/plugins/uavobjects/uavobjecttemplate.h +++ b/ground/src/plugins/uavobjects/uavobjecttemplate.h @@ -1,17 +1,17 @@ /** - ****************************************************************************** - * - * @file $(NAMELC).h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Implementation of the $(NAME) object. This file has been - * automatically generated by the UAVObjectGenerator. - * - * @note Object definition file: $(XMLFILE). - * This is an automatically generated file. - * DO NOT modify manually. - * - * @see The GNU Public License (GPL) Version 3 - * + ****************************************************************************** + * + * @file $(NAMELC).h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the $(NAME) object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: $(XMLFILE). + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -28,34 +28,41 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef $(NAMEUC)_H -#define $(NAMEUC)_H - -#include "uavdataobject.h" - -class $(NAME): public UAVDataObject -{ -public: - typedef struct { -$(DATAFIELDS) - } __attribute__((packed)) DataFields; - - static const quint32 OBJID = $(OBJID)U; - static const QString NAME; - static const bool ISSINGLEINST = $(ISSINGLEINST); - static const bool ISSETTINGS = $(ISSETTINGS); - static const quint32 NUMBYTES = sizeof(DataFields); - - $(NAME)(); - - DataFields getData(); - void setData(DataFields& data); - Metadata getDefaultMetadata(); - UAVDataObject* clone(quint32 instID); - -private: - DataFields data; - -}; - -#endif // $(NAMEUC)_H +#ifndef $(NAMEUC)_H +#define $(NAMEUC)_H + +#include "uavdataobject.h" +#include "uavobjectfieldprimitives.h" + +class $(NAME): public UAVDataObject +{ +public: + // Field structure + typedef struct { +$(DATAFIELDS) + } __attribute__((packed)) DataFields; + + // Enumeration types +$(DATAENUM) + + // Constants + static const quint32 OBJID = $(OBJID)U; + static const QString NAME; + static const bool ISSINGLEINST = $(ISSINGLEINST); + static const bool ISSETTINGS = $(ISSETTINGS); + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + $(NAME)(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // $(NAMEUC)_H