1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/UAVObjectGenerator Fix bug with enumeration types

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@424 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-04 20:32:59 +00:00 committed by vassilis
parent e2871a24e7
commit 89749b06e4
8 changed files with 61 additions and 8 deletions

View File

@ -620,11 +620,32 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
QString finit;
for (int n = 0; n < info->fields.length(); ++n)
{
finit.append( QString(" fields.append(new UAVObjectFieldPrimitives<%1>(QString(\"%2\"), QString(\"%3\"), %4));\n")
.arg(fieldTypeStrCPP[info->fields[n]->type])
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(info->fields[n]->numElements) );
// Only for enum types
if (info->fields[n]->type == FIELDTYPE_ENUM)
{
QString optionName = info->fields[n]->name + "EnumOptions";
finit.append( QString(" QStringList %1;\n").arg(optionName) );
QStringList options = info->fields[n]->options;
for (int m = 0; m < options.length(); ++m)
{
finit.append( QString(" %1.append(\"%2\");\n")
.arg(optionName)
.arg(options[m]) );
}
finit.append( QString(" fields.append(new UAVObjectFieldEnum(QString(\"%1\"), QString(\"%2\"), %3, %4));\n")
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(info->fields[n]->numElements)
.arg(optionName) );
}
else
{
finit.append( QString(" fields.append(new UAVObjectFieldPrimitives<%1>(QString(\"%2\"), QString(\"%3\"), %4));\n")
.arg(fieldTypeStrCPP[info->fields[n]->type])
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(info->fields[n]->numElements) );
}
}
outCode.replace(QString("$(FIELDSINIT)"), finit);

View File

@ -43,7 +43,10 @@ ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
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));
QStringList Field8EnumOptions;
Field8EnumOptions.append("Option1");
Field8EnumOptions.append("Option2");
fields.append(new UAVObjectFieldEnum(QString("Field8"), QString("unit8"), 1, Field8EnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -33,6 +33,7 @@
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
#include "uavobjectfieldenum.h"
class ExampleObject1: public UAVDataObject
{

View File

@ -33,6 +33,7 @@
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
#include "uavobjectfieldenum.h"
class ExampleObject2: public UAVDataObject
{

View File

@ -38,7 +38,10 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
QList<UAVObjectField*> fields;
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));
QStringList StepDirectionEnumOptions;
StepDirectionEnumOptions.append("up");
StepDirectionEnumOptions.append("down");
fields.append(new UAVObjectFieldEnum(QString("StepDirection"), QString(""), 1, StepDirectionEnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -33,6 +33,7 @@
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
#include "uavobjectfieldenum.h"
class ExampleSettings: public UAVDataObject
{

View File

@ -110,7 +110,7 @@ void UAVObjectsTest::runTest()
data.Field4[1] = 40.2;
data.Field4[2] = 40.3;
obj1->setData(data);
obj1->load();
obj1->load();
// Get all instances
QList<UAVObject*> objs = objMngr->getObjectInstances(ExampleObject1::OBJID);
@ -120,6 +120,28 @@ void UAVObjectsTest::runTest()
sout << objs[n]->toString();
}
// Get object fields
QString objname("ExampleObject1");
UAVObject* obj = objMngr->getObject(objname);
QList<UAVObjectField*> fields = obj->getFields();
// qint8
UAVObjectFieldPrimitives<qint8>* fieldint8 = dynamic_cast< UAVObjectFieldPrimitives<qint8>* >(fields[0]);
if (fieldint8 != NULL)
{
fieldint8->setValue(10);
qint8 value = fieldint8->getValue();
sout << value;
}
// enum
UAVObjectFieldEnum* fieldenum = dynamic_cast< UAVObjectFieldEnum* >(fields[7]);
if (fieldenum != NULL)
{
QStringList options = fieldenum->getOptions();
fieldenum->setSelected(options[1]);
QString selected = fieldenum->getSelected();
sout << selected;
}
// Done
done = true;
}

View File

@ -33,6 +33,7 @@
#include "uavdataobject.h"
#include "uavobjectfieldprimitives.h"
#include "uavobjectfieldenum.h"
class $(NAME): public UAVDataObject
{