mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
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
This commit is contained in:
parent
26377a8418
commit
fe212a22e7
@ -36,10 +36,14 @@ ExampleObject::ExampleObject(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, N
|
||||
{
|
||||
// Create fields
|
||||
QList<UAVObjectField*> 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<qint8>(QString("field1"), QString("unit1"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint16>(QString("field2"), QString("unit2"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("field3"), QString("unit3"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<float>(QString("field4"), QString("unit4"), 4));
|
||||
fields.append(new UAVObjectFieldPrimitives<quint8>(QString("field5"), QString("unit5"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<quint16>(QString("field6"), QString("unit6"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<quint32>(QString("field7"), QString("unit7"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<quint8>(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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -36,10 +36,10 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
|
||||
{
|
||||
// Create fields
|
||||
QList<UAVObjectField*> 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<qint8>(QString("setting1"), QString("unit1"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint16>(QString("setting2"), QString("unit2"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint8>(QString("setting3"), QString("unit3"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint32>(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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,52 +0,0 @@
|
||||
#include "testobject1.h"
|
||||
|
||||
const QString TestObject1::NAME = QString("TestObject1");
|
||||
|
||||
TestObject1::TestObject1(): UAVDataObject(OBJID, SINGLEINST, NAME)
|
||||
{
|
||||
// Create fields
|
||||
QList<UAVObjectField*> 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;
|
||||
}
|
@ -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
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<UAVObjectField*> 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<qint8>(QString("FlightTelemetryAcked"), QString(""), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint8>(QString("FlightTelemetryUpdateMode"), QString(""), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("FlightTelemetryUpdatePeriod"), QString("ms"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint8>(QString("GCSTelemetryAcked"), QString(""), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint8>(QString("GCSTelemetryUpdateMode"), QString(""), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("GCSTelemetryUpdatePeriod"), QString("ms"), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint8>(QString("LoggingUpdateMode"), QString(""), 1));
|
||||
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("LoggingUpdatePeriod"), QString("ms"), 1));
|
||||
// Initialize parent
|
||||
UAVObject::initialize(0);
|
||||
UAVObject::initializeFields(fields, (quint8*)&parentMetadata, sizeof(Metadata));
|
||||
|
@ -28,32 +28,15 @@
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
|
||||
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<qint16>(value16, &dataOut[numBytesPerElement*index]);
|
||||
break;
|
||||
case FIELDTYPE_INT32:
|
||||
case FIELDTYPE_FLOAT32:
|
||||
qint32 value32;
|
||||
memcpy(&value32, &data[offset + numBytesPerElement*index], 4);
|
||||
qToBigEndian<qint32>(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<qint16>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value16, 2);
|
||||
break;
|
||||
case FIELDTYPE_INT32:
|
||||
case FIELDTYPE_FLOAT32:
|
||||
qint32 value32;
|
||||
value32 = qFromBigEndian<qint32>(&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;
|
||||
|
@ -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;
|
||||
|
69
ground/src/plugins/uavobjects/uavobjectfieldenum.cpp
Normal file
69
ground/src/plugins/uavobjects/uavobjectfieldenum.cpp
Normal file
@ -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<quint8>(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);
|
||||
}
|
||||
}
|
49
ground/src/plugins/uavobjects/uavobjectfieldenum.h
Normal file
49
ground/src/plugins/uavobjects/uavobjectfieldenum.h
Normal file
@ -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 <QStringList>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldEnum: public UAVObjectFieldPrimitives<quint8>
|
||||
{
|
||||
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
|
181
ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp
Normal file
181
ground/src/plugins/uavobjects/uavobjectfieldprimitives.cpp
Normal file
@ -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 <typename FType>
|
||||
UAVObjectFieldPrimitives<FType>::UAVObjectFieldPrimitives(const QString& name, const QString& units, quint32 numElements):
|
||||
UAVObjectField(name, units, numElements)
|
||||
{
|
||||
numBytesPerElement = sizeof(FType);
|
||||
}
|
||||
|
||||
template <typename FType>
|
||||
void UAVObjectFieldPrimitives<FType>::initializeValues()
|
||||
{
|
||||
for (quint32 n = 0; n < numElements; ++n)
|
||||
{
|
||||
setValue(0, n);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pack the field in to an array of bytes.
|
||||
*/
|
||||
template <typename FType>
|
||||
qint32 UAVObjectFieldPrimitives<FType>::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<FType>(value, &dataOut[numBytesPerElement*index]);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack the field from an array of bytes.
|
||||
*/
|
||||
template <typename FType>
|
||||
qint32 UAVObjectFieldPrimitives<FType>::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<FType>(&dataIn[numBytesPerElement*index]);
|
||||
memcpy(&data[offset + numBytesPerElement*index], &value, numBytesPerElement);
|
||||
}
|
||||
// Done
|
||||
return getNumBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value as a double.
|
||||
*/
|
||||
template <typename FType>
|
||||
double UAVObjectFieldPrimitives<FType>::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 <typename FType>
|
||||
void UAVObjectFieldPrimitives<FType>::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 <typename FType>
|
||||
quint32 UAVObjectFieldPrimitives<FType>::getNumBytesElement()
|
||||
{
|
||||
return numBytesPerElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field value.
|
||||
*/
|
||||
template <typename FType>
|
||||
FType UAVObjectFieldPrimitives<FType>::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 <typename FType>
|
||||
void UAVObjectFieldPrimitives<FType>::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<qint8>;
|
||||
template class UAVObjectFieldPrimitives<qint16>;
|
||||
template class UAVObjectFieldPrimitives<qint32>;
|
||||
template class UAVObjectFieldPrimitives<quint8>;
|
||||
template class UAVObjectFieldPrimitives<quint16>;
|
||||
template class UAVObjectFieldPrimitives<quint32>;
|
||||
template class UAVObjectFieldPrimitives<float>;
|
||||
|
||||
|
||||
|
94
ground/src/plugins/uavobjects/uavobjectfieldprimitives.h
Normal file
94
ground/src/plugins/uavobjects/uavobjectfieldprimitives.h
Normal file
@ -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 <QtEndian>
|
||||
|
||||
template <typename FType>
|
||||
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<qint8>(const uchar *src)
|
||||
{
|
||||
return *src;
|
||||
}
|
||||
|
||||
template <> inline void qToBigEndian<qint8>(qint8 src, uchar *dest)
|
||||
{
|
||||
*dest = src;
|
||||
}
|
||||
|
||||
template<> inline quint8 qFromBigEndian<quint8>(const uchar *src)
|
||||
{
|
||||
return *src;
|
||||
}
|
||||
|
||||
template <> inline void qToBigEndian<quint8>(quint8 src, uchar *dest)
|
||||
{
|
||||
*dest = src;
|
||||
}
|
||||
|
||||
template<> inline float qFromBigEndian<float>(const uchar *src)
|
||||
{
|
||||
quint32 tmpint;
|
||||
float tmpfloat;
|
||||
tmpint = qFromBigEndian<quint32>(src);
|
||||
memcpy(&tmpfloat, &tmpint, sizeof(quint32));
|
||||
return tmpfloat;
|
||||
}
|
||||
|
||||
template <> inline void qToBigEndian<float>(float src, uchar *dest)
|
||||
{
|
||||
quint32 tmpint;
|
||||
memcpy(&tmpint, &src, sizeof(quint32));
|
||||
qToBigEndian<quint32>(tmpint, dest);
|
||||
}
|
||||
|
||||
|
||||
#endif // UAVOBJECTFIELDPRIMITIVES_H
|
75
ground/src/plugins/uavobjects/uavobjectfieldstring.cpp
Normal file
75
ground/src/plugins/uavobjects/uavobjectfieldstring.cpp
Normal file
@ -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<quint8>(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);
|
||||
}
|
||||
|
||||
|
44
ground/src/plugins/uavobjects/uavobjectfieldstring.h
Normal file
44
ground/src/plugins/uavobjects/uavobjectfieldstring.h
Normal file
@ -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 <QStringList>
|
||||
|
||||
class UAVOBJECTS_EXPORT UAVObjectFieldString: public UAVObjectFieldPrimitives<quint8>
|
||||
{
|
||||
public:
|
||||
UAVObjectFieldString(const QString& name, quint32 maxSize);
|
||||
QString getString();
|
||||
void setString(QString& str);
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // UAVOBJECTFIELDSTRING_H
|
@ -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
|
||||
|
@ -57,7 +57,7 @@ UAVObject::Metadata $(NAME)::getDefaultMetadata()
|
||||
|
||||
$(NAME)::DataFields $(NAME)::getData()
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
QMutexLocker locker(mutex);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user