diff --git a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp index 34850458c..63805ba8f 100644 --- a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp +++ b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp @@ -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); diff --git a/ground/src/plugins/uavobjects/exampleobject1.cpp b/ground/src/plugins/uavobjects/exampleobject1.cpp index ff1e68091..6a0be143f 100644 --- a/ground/src/plugins/uavobjects/exampleobject1.cpp +++ b/ground/src/plugins/uavobjects/exampleobject1.cpp @@ -43,7 +43,10 @@ ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, 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)); + 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); diff --git a/ground/src/plugins/uavobjects/exampleobject1.h b/ground/src/plugins/uavobjects/exampleobject1.h index dad24ee11..9bf963b20 100644 --- a/ground/src/plugins/uavobjects/exampleobject1.h +++ b/ground/src/plugins/uavobjects/exampleobject1.h @@ -33,6 +33,7 @@ #include "uavdataobject.h" #include "uavobjectfieldprimitives.h" +#include "uavobjectfieldenum.h" class ExampleObject1: public UAVDataObject { diff --git a/ground/src/plugins/uavobjects/exampleobject2.h b/ground/src/plugins/uavobjects/exampleobject2.h index 06f45de29..2aad7b494 100644 --- a/ground/src/plugins/uavobjects/exampleobject2.h +++ b/ground/src/plugins/uavobjects/exampleobject2.h @@ -33,6 +33,7 @@ #include "uavdataobject.h" #include "uavobjectfieldprimitives.h" +#include "uavobjectfieldenum.h" class ExampleObject2: public UAVDataObject { diff --git a/ground/src/plugins/uavobjects/examplesettings.cpp b/ground/src/plugins/uavobjects/examplesettings.cpp index 281aa2cd5..dcf8cabb1 100644 --- a/ground/src/plugins/uavobjects/examplesettings.cpp +++ b/ground/src/plugins/uavobjects/examplesettings.cpp @@ -38,7 +38,10 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING QList fields; fields.append(new UAVObjectFieldPrimitives(QString("UpdatePeriod"), QString("ms"), 1)); fields.append(new UAVObjectFieldPrimitives(QString("StepSize"), QString(""), 1)); - fields.append(new UAVObjectFieldPrimitives(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); diff --git a/ground/src/plugins/uavobjects/examplesettings.h b/ground/src/plugins/uavobjects/examplesettings.h index 43551b45b..3d4c50841 100644 --- a/ground/src/plugins/uavobjects/examplesettings.h +++ b/ground/src/plugins/uavobjects/examplesettings.h @@ -33,6 +33,7 @@ #include "uavdataobject.h" #include "uavobjectfieldprimitives.h" +#include "uavobjectfieldenum.h" class ExampleSettings: public UAVDataObject { diff --git a/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp b/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp index 59a894056..65b5adc7d 100644 --- a/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp +++ b/ground/src/plugins/uavobjects/tests/uavobjectstest.cpp @@ -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 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 fields = obj->getFields(); + // qint8 + UAVObjectFieldPrimitives* fieldint8 = dynamic_cast< UAVObjectFieldPrimitives* >(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; } diff --git a/ground/src/plugins/uavobjects/uavobjecttemplate.h b/ground/src/plugins/uavobjects/uavobjecttemplate.h index 37fa388c3..547843bd6 100644 --- a/ground/src/plugins/uavobjects/uavobjecttemplate.h +++ b/ground/src/plugins/uavobjects/uavobjecttemplate.h @@ -33,6 +33,7 @@ #include "uavdataobject.h" #include "uavobjectfieldprimitives.h" +#include "uavobjectfieldenum.h" class $(NAME): public UAVDataObject {