1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

GCS\ObjectGenerator Minor change on the way named arrays are implemented

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@536 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-22 00:44:14 +00:00 committed by vassilis
parent b8b5bffe4d
commit 56f88a6a79
13 changed files with 62 additions and 61 deletions

View File

@ -352,7 +352,18 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
}
// Get numelements or elementnames attribute
elemAttr = elemAttributes.namedItem("elementnames");
if ( elemAttr.isNull() )
if ( !elemAttr.isNull() )
{
// Get element names
QStringList names = elemAttr.nodeValue().split(",", QString::SkipEmptyParts);
for (int n = 0; n < names.length(); ++n)
{
names[n] = names[n].trimmed();
}
field->elementNames = names;
field->numElements = names.length();
}
else
{
elemAttr = elemAttributes.namedItem("elements");
if ( elemAttr.isNull() )
@ -364,23 +375,10 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
field->numElements = elemAttr.nodeValue().toInt();
for (int n = 0; n < field->numElements; ++n)
{
field->elementNames.append(QString("[%1]").arg(n));
field->elementNames.append(QString("%1").arg(n));
}
field->defaultElementNames = true;
}
}
else
{
// Get element names
QStringList names = elemAttr.nodeValue().split(",", QString::SkipEmptyParts);
for (int n = 0; n < names.length(); ++n)
{
names[n] = names[n].trimmed();
}
field->elementNames = names;
field->numElements = names.length();
field->defaultElementNames = false;
}
// Get options attribute (only if an enum type)
if (field->type == FIELDTYPE_ENUM)
{
@ -598,7 +596,7 @@ bool UAVObjectParser::generateFlightObject(int objIndex, const QString& template
.arg( info->fields[n]->name ) );
}
// Generate element names (only if field has more than one element)
if (info->fields[n]->numElements > 1 && !info->fields[n]->defaultElementNames)
if (info->fields[n]->numElements > 1)
{
enums.append(QString("/* Array element names for field %1 */\n").arg(info->fields[n]->name));
enums.append("typedef enum { ");
@ -730,7 +728,7 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
.arg( info->fields[n]->name ) );
}
// Generate element names (only if field has more than one element)
if (info->fields[n]->numElements > 1 && !info->fields[n]->defaultElementNames)
if (info->fields[n]->numElements > 1)
{
enums.append(QString(" /* Array element names for field %1 */\n").arg(info->fields[n]->name));
enums.append(" typedef enum { ");

View File

@ -66,7 +66,6 @@ public:
int numElements;
QStringList elementNames;
QStringList options; // for enums only
bool defaultElementNames;
} FieldInfo;
typedef struct {

View File

@ -161,7 +161,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
if (field->getNumElements() == 1)
data.append(field->getName());
else
data.append((field->getElementNames())[index]);
data.append( QString("[%1]").arg((field->getElementNames())[index]) );
UAVObjectFieldEnum *enumField = dynamic_cast<UAVObjectFieldEnum*>(field);
UAVObjectFieldInt8 *int8Field = dynamic_cast<UAVObjectFieldInt8*>(field);
UAVObjectFieldInt16 *int16Field = dynamic_cast<UAVObjectFieldInt16*>(field);

View File

@ -38,31 +38,31 @@ ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
// Create fields
QList<UAVObjectField*> fields;
QStringList Field1ElemNames;
Field1ElemNames.append("[0]");
Field1ElemNames.append("0");
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
QStringList Field2ElemNames;
Field2ElemNames.append("[0]");
Field2ElemNames.append("0");
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
QStringList Field3ElemNames;
Field3ElemNames.append("[0]");
Field3ElemNames.append("0");
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), Field3ElemNames));
QStringList Field4ElemNames;
Field4ElemNames.append("[0]");
Field4ElemNames.append("[1]");
Field4ElemNames.append("[2]");
Field4ElemNames.append("[3]");
Field4ElemNames.append("0");
Field4ElemNames.append("1");
Field4ElemNames.append("2");
Field4ElemNames.append("3");
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
QStringList Field5ElemNames;
Field5ElemNames.append("[0]");
Field5ElemNames.append("0");
fields.append(new UAVObjectFieldUInt8(QString("Field5"), QString("unit5"), Field5ElemNames));
QStringList Field6ElemNames;
Field6ElemNames.append("[0]");
Field6ElemNames.append("0");
fields.append(new UAVObjectFieldUInt16(QString("Field6"), QString("unit6"), Field6ElemNames));
QStringList Field7ElemNames;
Field7ElemNames.append("[0]");
Field7ElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("Field7"), QString("unit7"), Field7ElemNames));
QStringList Field8ElemNames;
Field8ElemNames.append("[0]");
Field8ElemNames.append("0");
QStringList Field8EnumOptions;
Field8EnumOptions.append("Option1");
Field8EnumOptions.append("Option2");

View File

@ -52,6 +52,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
/* Array element names for field Field4 */
typedef enum { FIELD4_0=0, FIELD4_1=1, FIELD4_2=2, FIELD4_3=3, } Field4Elem;
/* Enumeration options for field Field8 */
typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } Field8Options;

View File

@ -38,19 +38,19 @@ ExampleObject2::ExampleObject2(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
// Create fields
QList<UAVObjectField*> fields;
QStringList Field1ElemNames;
Field1ElemNames.append("[0]");
Field1ElemNames.append("0");
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
QStringList Field2ElemNames;
Field2ElemNames.append("[0]");
Field2ElemNames.append("0");
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
QStringList Field3ElemNames;
Field3ElemNames.append("[0]");
Field3ElemNames.append("0");
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), Field3ElemNames));
QStringList Field4ElemNames;
Field4ElemNames.append("[0]");
Field4ElemNames.append("[1]");
Field4ElemNames.append("[2]");
Field4ElemNames.append("[3]");
Field4ElemNames.append("0");
Field4ElemNames.append("1");
Field4ElemNames.append("2");
Field4ElemNames.append("3");
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
// Initialize object

View File

@ -48,6 +48,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
/* Array element names for field Field4 */
typedef enum { FIELD4_0=0, FIELD4_1=1, FIELD4_2=2, FIELD4_3=3, } Field4Elem;
// Constants

View File

@ -38,13 +38,13 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
// Create fields
QList<UAVObjectField*> fields;
QStringList UpdatePeriodElemNames;
UpdatePeriodElemNames.append("[0]");
UpdatePeriodElemNames.append("0");
fields.append(new UAVObjectFieldInt32(QString("UpdatePeriod"), QString("ms"), UpdatePeriodElemNames));
QStringList StepSizeElemNames;
StepSizeElemNames.append("[0]");
StepSizeElemNames.append("0");
fields.append(new UAVObjectFieldInt32(QString("StepSize"), QString(""), StepSizeElemNames));
QStringList StepDirectionElemNames;
StepDirectionElemNames.append("[0]");
StepDirectionElemNames.append("0");
QStringList StepDirectionEnumOptions;
StepDirectionEnumOptions.append("up");
StepDirectionEnumOptions.append("down");

View File

@ -38,25 +38,25 @@ FlightTelemetryStats::FlightTelemetryStats(): UAVDataObject(OBJID, ISSINGLEINST,
// Create fields
QList<UAVObjectField*> fields;
QStringList ConnectedElemNames;
ConnectedElemNames.append("[0]");
ConnectedElemNames.append("0");
QStringList ConnectedEnumOptions;
ConnectedEnumOptions.append("True");
ConnectedEnumOptions.append("False");
fields.append(new UAVObjectFieldEnum(QString("Connected"), QString("bool"), ConnectedElemNames, ConnectedEnumOptions));
QStringList TxDataRateElemNames;
TxDataRateElemNames.append("[0]");
TxDataRateElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("TxDataRate"), QString("bytes/sec"), TxDataRateElemNames));
QStringList RxDataRateElemNames;
RxDataRateElemNames.append("[0]");
RxDataRateElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("RxDataRate"), QString("bytes/sec"), RxDataRateElemNames));
QStringList TxFailuresElemNames;
TxFailuresElemNames.append("[0]");
TxFailuresElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("TxFailures"), QString("count"), TxFailuresElemNames));
QStringList RxFailuresElemNames;
RxFailuresElemNames.append("[0]");
RxFailuresElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("RxFailures"), QString("count"), RxFailuresElemNames));
QStringList TxRetriesElemNames;
TxRetriesElemNames.append("[0]");
TxRetriesElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("TxRetries"), QString("count"), TxRetriesElemNames));
// Initialize object

View File

@ -38,25 +38,25 @@ GCSTelemetryStats::GCSTelemetryStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSET
// Create fields
QList<UAVObjectField*> fields;
QStringList ConnectedElemNames;
ConnectedElemNames.append("[0]");
ConnectedElemNames.append("0");
QStringList ConnectedEnumOptions;
ConnectedEnumOptions.append("True");
ConnectedEnumOptions.append("False");
fields.append(new UAVObjectFieldEnum(QString("Connected"), QString("bool"), ConnectedElemNames, ConnectedEnumOptions));
QStringList TxDataRateElemNames;
TxDataRateElemNames.append("[0]");
TxDataRateElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("TxDataRate"), QString("bytes/sec"), TxDataRateElemNames));
QStringList RxDataRateElemNames;
RxDataRateElemNames.append("[0]");
RxDataRateElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("RxDataRate"), QString("bytes/sec"), RxDataRateElemNames));
QStringList TxFailuresElemNames;
TxFailuresElemNames.append("[0]");
TxFailuresElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("TxFailures"), QString("count"), TxFailuresElemNames));
QStringList RxFailuresElemNames;
RxFailuresElemNames.append("[0]");
RxFailuresElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("RxFailures"), QString("count"), RxFailuresElemNames));
QStringList TxRetriesElemNames;
TxRetriesElemNames.append("[0]");
TxRetriesElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("TxRetries"), QString("count"), TxRetriesElemNames));
// Initialize object

View File

@ -38,19 +38,19 @@ GpsObject::GpsObject(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
// Create fields
QList<UAVObjectField*> fields;
QStringList LatitudeElemNames;
LatitudeElemNames.append("[0]");
LatitudeElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("Latitude"), QString("degrees"), LatitudeElemNames));
QStringList LongitudeElemNames;
LongitudeElemNames.append("[0]");
LongitudeElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("Longitude"), QString("degrees"), LongitudeElemNames));
QStringList AltitudeElemNames;
AltitudeElemNames.append("[0]");
AltitudeElemNames.append("0");
fields.append(new UAVObjectFieldFloat(QString("Altitude"), QString("meters"), AltitudeElemNames));
QStringList SatellitesElemNames;
SatellitesElemNames.append("[0]");
SatellitesElemNames.append("0");
fields.append(new UAVObjectFieldInt8(QString("Satellites"), QString(""), SatellitesElemNames));
QStringList UpdatesElemNames;
UpdatesElemNames.append("[0]");
UpdatesElemNames.append("0");
fields.append(new UAVObjectFieldUInt16(QString("Updates"), QString(""), UpdatesElemNames));
// Initialize object

View File

@ -38,7 +38,7 @@ SettingsPersistence::SettingsPersistence(): UAVDataObject(OBJID, ISSINGLEINST, I
// Create fields
QList<UAVObjectField*> fields;
QStringList OperationElemNames;
OperationElemNames.append("[0]");
OperationElemNames.append("0");
QStringList OperationEnumOptions;
OperationEnumOptions.append("Load");
OperationEnumOptions.append("Save");

View File

@ -38,13 +38,13 @@ SystemStats::SystemStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
// Create fields
QList<UAVObjectField*> fields;
QStringList FlightTimeElemNames;
FlightTimeElemNames.append("[0]");
FlightTimeElemNames.append("0");
fields.append(new UAVObjectFieldUInt32(QString("FlightTime"), QString("ms"), FlightTimeElemNames));
QStringList HeapRemainingElemNames;
HeapRemainingElemNames.append("[0]");
HeapRemainingElemNames.append("0");
fields.append(new UAVObjectFieldUInt16(QString("HeapRemaining"), QString("bytes"), HeapRemainingElemNames));
QStringList CPULoadElemNames;
CPULoadElemNames.append("[0]");
CPULoadElemNames.append("0");
fields.append(new UAVObjectFieldUInt8(QString("CPULoad"), QString("%"), CPULoadElemNames));
// Initialize object