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

OP-33 GCS/UAVObjects: Update example objects

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@419 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-02 03:17:51 +00:00 committed by vassilis
parent b51c29c2f9
commit 0faaa1e158
15 changed files with 267 additions and 101 deletions

View File

@ -1,12 +1,12 @@
/**
******************************************************************************
*
* @file exampleobject.cpp
* @file exampleobject1.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the ExampleObject object. This file has been
* @brief Implementation of the ExampleObject1 object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: exampleobject.xml.
* @note Object definition file: exampleobject1.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
@ -28,48 +28,48 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "exampleobject.h"
#include "exampleobject1.h"
const QString ExampleObject::NAME = QString("ExampleObject");
const QString ExampleObject1::NAME = QString("ExampleObject1");
ExampleObject::ExampleObject(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
{
// Create fields
QList<UAVObjectField*> fields;
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));
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);
}
UAVObject::Metadata ExampleObject::getDefaultMetadata()
UAVObject::Metadata ExampleObject1::getDefaultMetadata()
{
UAVObject::Metadata metadata;
metadata.gcsTelemetryAcked = 1;
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
metadata.gcsTelemetryUpdatePeriod = 200;
metadata.flightTelemetryAcked = 1;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.flightTelemetryUpdatePeriod = 100;
metadata.flightTelemetryUpdatePeriod = 0;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER;
metadata.loggingUpdatePeriod = 0;
return metadata;
}
ExampleObject::DataFields ExampleObject::getData()
ExampleObject1::DataFields ExampleObject1::getData()
{
QMutexLocker locker(mutex);
return data;
}
void ExampleObject::setData(DataFields& data)
void ExampleObject1::setData(DataFields& data)
{
QMutexLocker locker(mutex);
this->data = data;
@ -77,9 +77,9 @@ void ExampleObject::setData(DataFields& data)
emit objectUpdated(this);
}
UAVDataObject* ExampleObject::clone(quint32 instID)
UAVDataObject* ExampleObject1::clone(quint32 instID)
{
ExampleObject* obj = new ExampleObject();
ExampleObject1* obj = new ExampleObject1();
obj->initialize(instID, this->getMetaObject());
return obj;
}

View File

@ -1,12 +1,12 @@
/**
******************************************************************************
*
* @file exampleobject.h
* @file exampleobject1.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the ExampleObject object. This file has been
* @brief Implementation of the ExampleObject1 object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: exampleobject.xml.
* @note Object definition file: exampleobject1.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
@ -28,25 +28,25 @@
* 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
#ifndef EXAMPLEOBJECT1_H
#define EXAMPLEOBJECT1_H
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
class ExampleObject: public UAVDataObject
class ExampleObject1: public UAVDataObject
{
public:
// Field structure
typedef struct {
qint8 field1;
qint16 field2;
qint32 field3;
float field4[4];
quint8 field5;
quint16 field6;
quint32 field7;
quint8 field8;
qint8 Field1;
qint16 Field2;
qint32 Field3;
float Field4[4];
quint8 Field5;
quint16 Field6;
quint32 Field7;
quint8 Field8;
} __attribute__((packed)) DataFields;
@ -55,14 +55,14 @@ public:
// Constants
static const quint32 OBJID = 1785231914U;
static const quint32 OBJID = 3852936276U;
static const QString NAME;
static const bool ISSINGLEINST = 0;
static const bool ISSETTINGS = 0;
static const quint32 NUMBYTES = sizeof(DataFields);
// Functions
ExampleObject();
ExampleObject1();
DataFields getData();
void setData(DataFields& data);
@ -74,4 +74,4 @@ private:
};
#endif // EXAMPLEOBJECT_H
#endif // EXAMPLEOBJECT1_H

View File

@ -0,0 +1,81 @@
/**
******************************************************************************
*
* @file exampleobject2.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the ExampleObject2 object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: exampleobject2.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
* 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 "exampleobject2.h"
const QString ExampleObject2::NAME = QString("ExampleObject2");
ExampleObject2::ExampleObject2(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
{
// Create fields
QList<UAVObjectField*> fields;
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));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);
}
UAVObject::Metadata ExampleObject2::getDefaultMetadata()
{
UAVObject::Metadata metadata;
metadata.gcsTelemetryAcked = 1;
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.flightTelemetryAcked = 1;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
metadata.flightTelemetryUpdatePeriod = 100;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER;
metadata.loggingUpdatePeriod = 0;
return metadata;
}
ExampleObject2::DataFields ExampleObject2::getData()
{
QMutexLocker locker(mutex);
return data;
}
void ExampleObject2::setData(DataFields& data)
{
QMutexLocker locker(mutex);
this->data = data;
emit objectUpdatedAuto(this); // trigger object updated event
emit objectUpdated(this);
}
UAVDataObject* ExampleObject2::clone(quint32 instID)
{
ExampleObject2* obj = new ExampleObject2();
obj->initialize(instID, this->getMetaObject());
return obj;
}

View File

@ -0,0 +1,72 @@
/**
******************************************************************************
*
* @file exampleobject2.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the ExampleObject2 object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: exampleobject2.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
* 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 EXAMPLEOBJECT2_H
#define EXAMPLEOBJECT2_H
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
class ExampleObject2: public UAVDataObject
{
public:
// Field structure
typedef struct {
qint8 Field1;
qint16 Field2;
qint32 Field3;
float Field4[4];
} __attribute__((packed)) DataFields;
// Enumeration types
// Constants
static const quint32 OBJID = 2743296914U;
static const QString NAME;
static const bool ISSINGLEINST = 0;
static const bool ISSETTINGS = 0;
static const quint32 NUMBYTES = sizeof(DataFields);
// Functions
ExampleObject2();
DataFields getData();
void setData(DataFields& data);
Metadata getDefaultMetadata();
UAVDataObject* clone(quint32 instID);
private:
DataFields data;
};
#endif // EXAMPLEOBJECT2_H

View File

@ -36,10 +36,9 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
{
// Create fields
QList<UAVObjectField*> fields;
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));
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("UpdatePeriod"), QString("ms"), 1));
fields.append(new UAVObjectFieldPrimitives<qint32>(QString("StepSize"), QString(""), 1));
fields.append(new UAVObjectFieldPrimitives<quint8>(QString("StepDirection"), QString(""), 1));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -39,18 +39,18 @@ class ExampleSettings: public UAVDataObject
public:
// Field structure
typedef struct {
qint8 setting1;
qint16 setting2;
qint8 setting3;
qint32 setting4;
qint32 UpdatePeriod;
qint32 StepSize;
quint8 StepDirection;
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } STEPDIRECTIONEnum;
// Constants
static const quint32 OBJID = 3555345034U;
static const quint32 OBJID = 1640607828U;
static const QString NAME;
static const bool ISSINGLEINST = 1;
static const bool ISSETTINGS = 1;

View File

@ -8,7 +8,7 @@ UAVObjectsTest::UAVObjectsTest(): sout(stdout), done(false)
connect(objMngr, SIGNAL(newInstance(UAVObject*)), this, SLOT(newInstance(UAVObject*)));
// Create test objects
obj1 = new ExampleObject();
obj1 = new ExampleObject1();
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectUpdated(UAVObject*)));
connect(obj1, SIGNAL(objectUpdatedAuto(UAVObject*)), this, SLOT(objectUpdatedAuto(UAVObject*)));
connect(obj1, SIGNAL(objectUpdatedManual(UAVObject*)), this, SLOT(objectUpdatedManual(UAVObject*)));
@ -62,17 +62,17 @@ void UAVObjectsTest::runTest()
if (!done)
{
// Create a new instance
ExampleObject* obj2 = new ExampleObject();
ExampleObject1* obj2 = new ExampleObject1();
objMngr->registerObject(obj2);
// Set data
ExampleObject::DataFields data = obj1->getData();
data.field1 = 1;
data.field2 = 2;
data.field3 = 3;
data.field4[0] = 4.1;
data.field4[1] = 4.2;
data.field4[2] = 4.3;
ExampleObject1::DataFields data = obj1->getData();
data.Field1 = 1;
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
@ -92,28 +92,28 @@ void UAVObjectsTest::runTest()
// Pack, unpack testing
quint8* buf = new quint8[obj1->getNumBytes()];
obj1->pack(buf);
data.field1 = 10;
data.field2 = 20;
data.field3 = 30;
data.field4[0] = 40.1;
data.field4[1] = 40.2;
data.field4[2] = 40.3;
data.Field1 = 10;
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.field2 = 20;
data.field3 = 30;
data.field4[0] = 40.1;
data.field4[1] = 40.2;
data.field4[2] = 40.3;
data.Field1 = 10;
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();
// Get all instances
QList<UAVObject*> objs = objMngr->getObjectInstances(ExampleObject::OBJID);
QList<UAVObject*> objs = objMngr->getObjectInstances(ExampleObject1::OBJID);
for (int n = 0; n < objs.length(); ++n)
{
sout << "[Printing object instances]\n";

View File

@ -2,7 +2,7 @@
#define UAVOBJECTSTEST_H
#include "..\uavobjectmanager.h"
#include "..\exampleobject.h"
#include "..\exampleobject1.h"
#include <QTimer>
#include <QTextStream>
@ -26,7 +26,7 @@ private slots:
private:
UAVObjectManager* objMngr;
ExampleObject* obj1;
ExampleObject1* obj1;
QTimer* timer;
QTextStream sout;
bool done;

View File

@ -13,17 +13,17 @@ SOURCES += main.cpp \
../uavmetaobject.cpp \
../uavdataobject.cpp \
uavobjectstest.cpp \
../exampleobject.cpp \
../uavobjectfieldprimitives.cpp \
../uavobjectfieldenum.cpp \
../uavobjectfieldstring.cpp
../uavobjectfieldstring.cpp \
../exampleobject1.cpp
HEADERS += ../uavobjectmanager.h \
../uavobjectfield.h \
../uavobject.h \
../uavmetaobject.h \
../uavdataobject.h \
uavobjectstest.h \
../exampleobject.h \
../uavobjectfieldprimitives.h \
../uavobjectfieldenum.h \
../uavobjectfieldstring.h
../uavobjectfieldstring.h \
../exampleobject1.h

View File

@ -11,10 +11,11 @@ HEADERS += uavobjects_global.h \
uavobjectsinit.h \
uavobjectsplugin.h \
examplesettings.h \
exampleobject.h \
uavobjectfieldprimitives.h \
uavobjectfieldenum.h \
uavobjectfieldstring.h
uavobjectfieldstring.h \
exampleobject2.h \
exampleobject1.h
SOURCES += uavobject.cpp \
uavmetaobject.cpp \
uavobjectmanager.cpp \
@ -23,9 +24,10 @@ SOURCES += uavobject.cpp \
uavobjectsinit.cpp \
uavobjectsplugin.cpp \
examplesettings.cpp \
exampleobject.cpp \
uavobjectfieldprimitives.cpp \
uavobjectfieldenum.cpp \
uavobjectfieldstring.cpp
uavobjectfieldstring.cpp \
exampleobject2.cpp \
exampleobject1.cpp
DEFINES += UAVOBJECTS_LIBRARY
OTHER_FILES += UAVObjects.pluginspec

View File

@ -30,7 +30,8 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uavobjectsinit.h"
#include "exampleobject.h"
#include "exampleobject1.h"
#include "exampleobject2.h"
#include "examplesettings.h"
@ -40,7 +41,8 @@
*/
void UAVObjectsInitialize(UAVObjectManager* objMngr)
{
objMngr->registerObject( new ExampleObject() );
objMngr->registerObject( new ExampleObject1() );
objMngr->registerObject( new ExampleObject2() );
objMngr->registerObject( new ExampleSettings() );
}

View File

@ -1,15 +0,0 @@
<xml>
<object name="ExampleObject" singleinstance="false" settings="false">
<field name="field1" units="unit1" type="int8" elements="1"/>
<field name="field2" units="unit2" type="int16" elements="1"/>
<field name="field3" units="unit3" type="int32" elements="1"/>
<field name="field4" units="unit4" type="float" elements="4"/>
<field name="field5" units="unit5" type="uint8" elements="1"/>
<field name="field6" units="unit6" type="uint16" elements="1"/>
<field name="field7" units="unit7" type="uint32" elements="1"/>
<field name="field8" units="unit8" type="enum" elements="1" options="option1, option2"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="onchange" period="100"/>
<logging updatemode="never" period="0"/>
</object>
</xml>

View File

@ -0,0 +1,15 @@
<xml>
<object name="ExampleObject1" singleinstance="false" settings="false">
<field name="Field1" units="unit1" type="int8" elements="1"/>
<field name="Field2" units="unit2" type="int16" elements="1"/>
<field name="Field3" units="unit3" type="int32" elements="1"/>
<field name="Field4" units="unit4" type="float" elements="4"/>
<field name="Field5" units="unit5" type="uint8" elements="1"/>
<field name="Field6" units="unit6" type="uint16" elements="1"/>
<field name="Field7" units="unit7" type="uint32" elements="1"/>
<field name="Field8" units="unit8" type="enum" elements="1" options="Option1, Option2"/>
<telemetrygcs acked="true" updatemode="periodic" period="200"/>
<telemetryflight acked="true" updatemode="onchange" period="0"/>
<logging updatemode="never" period="0"/>
</object>
</xml>

View File

@ -0,0 +1,11 @@
<xml>
<object name="ExampleObject2" singleinstance="false" settings="false">
<field name="Field1" units="unit1" type="int8" elements="1"/>
<field name="Field2" units="unit2" type="int16" elements="1"/>
<field name="Field3" units="unit3" type="int32" elements="1"/>
<field name="Field4" units="unit4" type="float" elements="4"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="periodic" period="100"/>
<logging updatemode="never" period="0"/>
</object>
</xml>

View File

@ -1,9 +1,8 @@
<xml>
<object name="ExampleSettings" singleinstance="true" settings="true">
<field name="setting1" units="unit1" type="int8" elements="1"/>
<field name="setting2" units="unit2" type="int16" elements="1"/>
<field name="setting3" units="unit3" type="int8" elements="1"/>
<field name="setting4" units="unit4" type="int32" elements="1"/>
<field name="UpdatePeriod" units="ms" type="int32" elements="1"/>
<field name="StepSize" units="" type="int32" elements="1"/>
<field name="StepDirection" units="" type="enum" elements="1" options="up,down"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="onchange" period="0"/>
<logging updatemode="never" period="0"/>