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

GCS/UAVObjectGenerator Added support for named arrays (i.e. each array element can have a name - needed for alarms), updated object browser to display names instead of just array index.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@532 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-21 02:50:51 +00:00 committed by vassilis
parent f999028753
commit 8622b7323d
39 changed files with 325 additions and 94 deletions

View File

@ -350,7 +350,10 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
return QString("Object:field:type attribute value is invalid");
}
}
// Get numelements attribute
// Get numelements or elementnames attribute
elemAttr = elemAttributes.namedItem("elementnames");
if ( elemAttr.isNull() )
{
elemAttr = elemAttributes.namedItem("elements");
if ( elemAttr.isNull() )
{
@ -359,6 +362,24 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
else
{
field->numElements = elemAttr.nodeValue().toInt();
for (int n = 0; n < field->numElements; ++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)
@ -559,6 +580,7 @@ bool UAVObjectParser::generateFlightObject(int objIndex, const QString& template
// Only for enum types
if (info->fields[n]->type == FIELDTYPE_ENUM)
{
enums.append(QString("/* Enumeration options for field %1 */\n").arg(info->fields[n]->name));
enums.append("typedef enum { ");
// Go through each option
QStringList options = info->fields[n]->options;
@ -571,9 +593,29 @@ bool UAVObjectParser::generateFlightObject(int objIndex, const QString& template
.arg(m) );
}
enums.append( QString(" } %1%2Enum;\n")
enums.append( QString(" } %1%2Options;\n")
.arg( info->name )
.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)
{
enums.append(QString("/* Array element names for field %1 */\n").arg(info->fields[n]->name));
enums.append("typedef enum { ");
// Go through the element names
QStringList elemNames = info->fields[n]->elementNames;
for (int m = 0; m < elemNames.length(); ++m)
{
enums.append( QString("%1_%2_%3=%4, ")
.arg( info->name.toUpper() )
.arg( info->fields[n]->name.toUpper() ) );
.arg( info->fields[n]->name.toUpper() )
.arg( elemNames[m].toUpper() )
.arg(m) );
}
enums.append( QString(" } %1%2Elem;\n")
.arg( info->name )
.arg( info->fields[n]->name ) );
}
}
outInclude.replace(QString("$(DATAENUM)"), enums);
@ -624,31 +666,42 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
QString finit;
for (int n = 0; n < info->fields.length(); ++n)
{
// Setup element names
QString varElemName = info->fields[n]->name + "ElemNames";
finit.append( QString(" QStringList %1;\n").arg(varElemName) );
QStringList elemNames = info->fields[n]->elementNames;
for (int m = 0; m < elemNames.length(); ++m)
{
finit.append( QString(" %1.append(\"%2\");\n")
.arg(varElemName)
.arg(elemNames[m]) );
}
// 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) );
QString varOptionName = info->fields[n]->name + "EnumOptions";
finit.append( QString(" QStringList %1;\n").arg(varOptionName) );
QStringList options = info->fields[n]->options;
for (int m = 0; m < options.length(); ++m)
{
finit.append( QString(" %1.append(\"%2\");\n")
.arg(optionName)
.arg(varOptionName)
.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) );
.arg(varElemName)
.arg(varOptionName) );
}
// For all other types
else
{
finit.append( QString(" fields.append(new UAVObjectField%1(QString(\"%2\"), QString(\"%3\"), %4));\n")
.arg(fieldTypeStrCPPClass[info->fields[n]->type])
.arg(info->fields[n]->name)
.arg(info->fields[n]->units)
.arg(info->fields[n]->numElements) );
.arg(varElemName) );
}
}
outCode.replace(QString("$(FIELDSINIT)"), finit);
@ -661,6 +714,7 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
// Only for enum types
if (info->fields[n]->type == FIELDTYPE_ENUM)
{
enums.append(QString(" /* Enumeration options for field %1 */\n").arg(info->fields[n]->name));
enums.append(" typedef enum { ");
// Go through each option
QStringList options = info->fields[n]->options;
@ -672,7 +726,25 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc
.arg(m) );
}
enums.append( QString(" } %1Enum;\n")
enums.append( QString(" } %1Options;\n")
.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)
{
enums.append(QString(" /* Array element names for field %1 */\n").arg(info->fields[n]->name));
enums.append(" typedef enum { ");
// Go through the element names
QStringList elemNames = info->fields[n]->elementNames;
for (int m = 0; m < elemNames.length(); ++m)
{
enums.append( QString("%1_%2=%3, ")
.arg( info->fields[n]->name.toUpper() )
.arg( elemNames[m].toUpper() )
.arg(m) );
}
enums.append( QString(" } %1Elem;\n")
.arg( info->fields[n]->name ) );
}
}

View File

@ -64,7 +64,9 @@ public:
QString units;
FieldType type;
int numElements;
QStringList elementNames;
QStringList options; // for enums only
bool defaultElementNames;
} FieldInfo;
typedef struct {

View File

@ -121,7 +121,7 @@ void UAVObjectBrowserWidget::readSettings()
updateSettings(SettingsPersistence::OPERATION_LOAD);
}
void UAVObjectBrowserWidget::updateSettings(SettingsPersistence::OperationEnum op)
void UAVObjectBrowserWidget::updateSettings(SettingsPersistence::OperationOptions op)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();

View File

@ -65,7 +65,7 @@ private:
Ui_UAVObjectBrowser *m_browser;
UAVObjectTreeModel *m_model;
void updateSettings(SettingsPersistence::OperationEnum op);
void updateSettings(SettingsPersistence::OperationOptions op);
void enableSendRequest(bool enable);
ObjectTreeItem *findCurrentObjectTreeItem();
};

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(QString("[%1]").arg(index));
data.append((field->getElementNames())[index]);
UAVObjectFieldEnum *enumField = dynamic_cast<UAVObjectFieldEnum*>(field);
UAVObjectFieldInt8 *int8Field = dynamic_cast<UAVObjectFieldInt8*>(field);
UAVObjectFieldInt16 *int16Field = dynamic_cast<UAVObjectFieldInt16*>(field);

View File

@ -37,17 +37,36 @@ ExampleObject1::ExampleObject1(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
{
// Create fields
QList<UAVObjectField*> fields;
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), 1));
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), 1));
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), 1));
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), 4));
fields.append(new UAVObjectFieldUInt8(QString("Field5"), QString("unit5"), 1));
fields.append(new UAVObjectFieldUInt16(QString("Field6"), QString("unit6"), 1));
fields.append(new UAVObjectFieldUInt32(QString("Field7"), QString("unit7"), 1));
QStringList Field1ElemNames;
Field1ElemNames.append("[0]");
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
QStringList Field2ElemNames;
Field2ElemNames.append("[0]");
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
QStringList Field3ElemNames;
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]");
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
QStringList Field5ElemNames;
Field5ElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt8(QString("Field5"), QString("unit5"), Field5ElemNames));
QStringList Field6ElemNames;
Field6ElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt16(QString("Field6"), QString("unit6"), Field6ElemNames));
QStringList Field7ElemNames;
Field7ElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt32(QString("Field7"), QString("unit7"), Field7ElemNames));
QStringList Field8ElemNames;
Field8ElemNames.append("[0]");
QStringList Field8EnumOptions;
Field8EnumOptions.append("Option1");
Field8EnumOptions.append("Option2");
fields.append(new UAVObjectFieldEnum(QString("Field8"), QString("unit8"), 1, Field8EnumOptions));
fields.append(new UAVObjectFieldEnum(QString("Field8"), QString("unit8"), Field8ElemNames, Field8EnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -52,7 +52,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } Field8Enum;
/* Enumeration options for field Field8 */
typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } Field8Options;
// Constants

View File

@ -37,10 +37,21 @@ ExampleObject2::ExampleObject2(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS,
{
// Create fields
QList<UAVObjectField*> fields;
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), 1));
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), 1));
fields.append(new UAVObjectFieldInt32(QString("Field3"), QString("unit3"), 1));
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), 4));
QStringList Field1ElemNames;
Field1ElemNames.append("[0]");
fields.append(new UAVObjectFieldInt8(QString("Field1"), QString("unit1"), Field1ElemNames));
QStringList Field2ElemNames;
Field2ElemNames.append("[0]");
fields.append(new UAVObjectFieldInt16(QString("Field2"), QString("unit2"), Field2ElemNames));
QStringList Field3ElemNames;
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]");
fields.append(new UAVObjectFieldFloat(QString("Field4"), QString("unit4"), Field4ElemNames));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -37,12 +37,18 @@ ExampleSettings::ExampleSettings(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTING
{
// Create fields
QList<UAVObjectField*> fields;
fields.append(new UAVObjectFieldInt32(QString("UpdatePeriod"), QString("ms"), 1));
fields.append(new UAVObjectFieldInt32(QString("StepSize"), QString(""), 1));
QStringList UpdatePeriodElemNames;
UpdatePeriodElemNames.append("[0]");
fields.append(new UAVObjectFieldInt32(QString("UpdatePeriod"), QString("ms"), UpdatePeriodElemNames));
QStringList StepSizeElemNames;
StepSizeElemNames.append("[0]");
fields.append(new UAVObjectFieldInt32(QString("StepSize"), QString(""), StepSizeElemNames));
QStringList StepDirectionElemNames;
StepDirectionElemNames.append("[0]");
QStringList StepDirectionEnumOptions;
StepDirectionEnumOptions.append("up");
StepDirectionEnumOptions.append("down");
fields.append(new UAVObjectFieldEnum(QString("StepDirection"), QString(""), 1, StepDirectionEnumOptions));
fields.append(new UAVObjectFieldEnum(QString("StepDirection"), QString(""), StepDirectionElemNames, StepDirectionEnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -47,7 +47,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } StepDirectionEnum;
/* Enumeration options for field StepDirection */
typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } StepDirectionOptions;
// Constants

View File

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

View File

@ -50,7 +50,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { CONNECTED_TRUE=0, CONNECTED_FALSE=1, } ConnectedEnum;
/* Enumeration options for field Connected */
typedef enum { CONNECTED_TRUE=0, CONNECTED_FALSE=1, } ConnectedOptions;
// Constants

View File

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

View File

@ -50,7 +50,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { CONNECTED_TRUE=0, CONNECTED_FALSE=1, } ConnectedEnum;
/* Enumeration options for field Connected */
typedef enum { CONNECTED_TRUE=0, CONNECTED_FALSE=1, } ConnectedOptions;
// Constants

View File

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

View File

@ -37,10 +37,12 @@ SettingsPersistence::SettingsPersistence(): UAVDataObject(OBJID, ISSINGLEINST, I
{
// Create fields
QList<UAVObjectField*> fields;
QStringList OperationElemNames;
OperationElemNames.append("[0]");
QStringList OperationEnumOptions;
OperationEnumOptions.append("Load");
OperationEnumOptions.append("Save");
fields.append(new UAVObjectFieldEnum(QString("Operation"), QString(""), 1, OperationEnumOptions));
fields.append(new UAVObjectFieldEnum(QString("Operation"), QString(""), OperationElemNames, OperationEnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -45,7 +45,8 @@ public:
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { OPERATION_LOAD=0, OPERATION_SAVE=1, } OperationEnum;
/* Enumeration options for field Operation */
typedef enum { OPERATION_LOAD=0, OPERATION_SAVE=1, } OperationOptions;
// Constants

View File

@ -37,22 +37,17 @@ SystemAlarms::SystemAlarms(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAM
{
// Create fields
QList<UAVObjectField*> fields;
QStringList TypeEnumOptions;
TypeEnumOptions.append("None");
TypeEnumOptions.append("StackOverflow");
TypeEnumOptions.append("OutOfMemory");
fields.append(new UAVObjectFieldEnum(QString("Type"), QString(""), 1, TypeEnumOptions));
QStringList SeverityEnumOptions;
SeverityEnumOptions.append("Info");
SeverityEnumOptions.append("Warning");
SeverityEnumOptions.append("Error");
SeverityEnumOptions.append("Critical");
fields.append(new UAVObjectFieldEnum(QString("Severity"), QString(""), 1, SeverityEnumOptions));
QStringList ActiveEnumOptions;
ActiveEnumOptions.append("True");
ActiveEnumOptions.append("False");
fields.append(new UAVObjectFieldEnum(QString("Active"), QString("bool"), 1, ActiveEnumOptions));
fields.append(new UAVObjectFieldUInt32(QString("Info"), QString(""), 1));
QStringList AlarmElemNames;
AlarmElemNames.append("OutOfMemory");
AlarmElemNames.append("StackOverflow");
AlarmElemNames.append("CPUOverload");
AlarmElemNames.append("EventSystem");
QStringList AlarmEnumOptions;
AlarmEnumOptions.append("None");
AlarmEnumOptions.append("Warning");
AlarmEnumOptions.append("Error");
AlarmEnumOptions.append("Critical");
fields.append(new UAVObjectFieldEnum(QString("Alarm"), QString(""), AlarmElemNames, AlarmEnumOptions));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);
@ -65,10 +60,10 @@ UAVObject::Metadata SystemAlarms::getDefaultMetadata()
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.flightTelemetryAcked = 1;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.flightTelemetryUpdatePeriod = 0;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
metadata.loggingUpdatePeriod = 0;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
metadata.flightTelemetryUpdatePeriod = 4000;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
metadata.loggingUpdatePeriod = 1000;
return metadata;
}

View File

@ -40,21 +40,19 @@ class UAVOBJECTS_EXPORT SystemAlarms: public UAVDataObject
public:
// Field structure
typedef struct {
quint8 Type;
quint8 Severity;
quint8 Active;
quint32 Info;
quint8 Alarm[4];
} __attribute__((packed)) DataFields;
// Enumeration types
typedef enum { TYPE_NONE=0, TYPE_STACKOVERFLOW=1, TYPE_OUTOFMEMORY=2, } TypeEnum;
typedef enum { SEVERITY_INFO=0, SEVERITY_WARNING=1, SEVERITY_ERROR=2, SEVERITY_CRITICAL=3, } SeverityEnum;
typedef enum { ACTIVE_TRUE=0, ACTIVE_FALSE=1, } ActiveEnum;
/* Enumeration options for field Alarm */
typedef enum { ALARM_NONE=0, ALARM_WARNING=1, ALARM_ERROR=2, ALARM_CRITICAL=3, } AlarmOptions;
/* Array element names for field Alarm */
typedef enum { ALARM_OUTOFMEMORY=0, ALARM_STACKOVERFLOW=1, ALARM_CPUOVERLOAD=2, ALARM_EVENTSYSTEM=3, } AlarmElem;
// Constants
static const quint32 OBJID = 1784134234U;
static const quint32 OBJID = 2311311912U;
static const QString NAME;
static const bool ISSINGLEINST = 1;
static const bool ISSETTINGS = 0;

View File

@ -37,9 +37,15 @@ SystemStats::SystemStats(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
{
// Create fields
QList<UAVObjectField*> fields;
fields.append(new UAVObjectFieldUInt32(QString("FlightTime"), QString("ms"), 1));
fields.append(new UAVObjectFieldUInt16(QString("HeapRemaining"), QString("bytes"), 1));
fields.append(new UAVObjectFieldUInt8(QString("CPULoad"), QString("%"), 1));
QStringList FlightTimeElemNames;
FlightTimeElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt32(QString("FlightTime"), QString("ms"), FlightTimeElemNames));
QStringList HeapRemainingElemNames;
HeapRemainingElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt16(QString("HeapRemaining"), QString("bytes"), HeapRemainingElemNames));
QStringList CPULoadElemNames;
CPULoadElemNames.append("[0]");
fields.append(new UAVObjectFieldUInt8(QString("CPULoad"), QString("%"), CPULoadElemNames));
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);

View File

@ -37,6 +37,23 @@ UAVObjectField::UAVObjectField(const QString& name, const QString& units, quint3
this->offset = 0;
this->data = NULL;
this->obj = NULL;
// Set element names
for (quint32 n = 0; n < numElements; ++n)
{
elementNames.append(QString("[%1]").arg(n));
}
}
UAVObjectField::UAVObjectField(const QString& name, const QString& units, const QStringList& elementNames)
{
// Copy params
this->name = name;
this->units = units;
this->numElements = elementNames.length();
this->offset = 0;
this->data = NULL;
this->obj = NULL;
this->elementNames = elementNames;
}
void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj)
@ -48,6 +65,11 @@ void UAVObjectField::initialize(quint8* data, quint32 dataOffset, UAVObject* obj
initializeValues();
}
QStringList UAVObjectField::getElementNames()
{
return elementNames;
}
UAVObject* UAVObjectField::getObject()
{
return obj;

View File

@ -30,6 +30,7 @@
#include "uavobjects_global.h"
#include "uavobject.h"
#include <QStringList>
class UAVObject;
@ -39,12 +40,14 @@ class UAVOBJECTS_EXPORT UAVObjectField: public QObject
public:
UAVObjectField(const QString& name, const QString& units, quint32 numElements);
UAVObjectField(const QString& name, const QString& units, const QStringList& elementNames);
void initialize(quint8* data, quint32 dataOffset, UAVObject* obj);
virtual void initializeValues() = 0;
UAVObject* getObject();
QString getName();
QString getUnits();
quint32 getNumElements();
QStringList getElementNames();
virtual qint32 pack(quint8* dataOut) = 0;
virtual qint32 unpack(const quint8* dataIn) = 0;
virtual double getDouble(quint32 index = 0) = 0;
@ -60,6 +63,7 @@ signals:
protected:
QString name;
QString units;
QStringList elementNames;
quint32 numElements;
quint32 offset;
quint8* data;

View File

@ -29,13 +29,20 @@
#include "uavobjectfieldenum.h"
#include <QtEndian>
UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, QStringList& options):
UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, const QStringList& options):
UAVObjectField(name, units, numElements)
{
numBytesPerElement = sizeof(quint8);
this->options = options;
}
UAVObjectFieldEnum::UAVObjectFieldEnum(const QString& name, const QString& units, const QStringList& elementNames, const QStringList& options):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(quint8);
this->options = options;
}
QStringList UAVObjectFieldEnum::getOptions()
{
return options;

View File

@ -40,7 +40,8 @@ class UAVOBJECTS_EXPORT UAVObjectFieldEnum: public UAVObjectField
Q_OBJECT
public:
UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, QStringList& options);
UAVObjectFieldEnum(const QString& name, const QString& units, quint32 numElements, const QStringList& options);
UAVObjectFieldEnum(const QString& name, const QString& units, const QStringList& elementNames, const QStringList& options);
QStringList getOptions();
QString getSelected(quint32 arrayIndex);
void setSelected(QString& val, quint32 arrayIndex);

View File

@ -36,6 +36,12 @@ UAVObjectFieldFloat::UAVObjectFieldFloat(const QString& name, const QString& uni
numBytesPerElement = sizeof(float);
}
UAVObjectFieldFloat::UAVObjectFieldFloat(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(float);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldFloat: public UAVObjectField
public:
UAVObjectFieldFloat(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldFloat(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldInt16::UAVObjectFieldInt16(const QString& name, const QString& uni
numBytesPerElement = sizeof(qint16);
}
UAVObjectFieldInt16::UAVObjectFieldInt16(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(qint16);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldInt16: public UAVObjectField
public:
UAVObjectFieldInt16(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldInt16(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldInt32::UAVObjectFieldInt32(const QString& name, const QString& uni
numBytesPerElement = sizeof(qint32);
}
UAVObjectFieldInt32::UAVObjectFieldInt32(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(qint32);
}
/**
* Initialize all values
*/

View File

@ -39,6 +39,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldInt32: public UAVObjectField
public:
UAVObjectFieldInt32(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldInt32(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldInt8::UAVObjectFieldInt8(const QString& name, const QString& units
numBytesPerElement = sizeof(qint8);
}
UAVObjectFieldInt8::UAVObjectFieldInt8(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(qint8);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldInt8: public UAVObjectField
public:
UAVObjectFieldInt8(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldInt8(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldUInt16::UAVObjectFieldUInt16(const QString& name, const QString& u
numBytesPerElement = sizeof(quint16);
}
UAVObjectFieldUInt16::UAVObjectFieldUInt16(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(quint16);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldUInt16: public UAVObjectField
public:
UAVObjectFieldUInt16(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldUInt16(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldUInt32::UAVObjectFieldUInt32(const QString& name, const QString& u
numBytesPerElement = sizeof(quint32);
}
UAVObjectFieldUInt32::UAVObjectFieldUInt32(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(quint32);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldUInt32: public UAVObjectField
public:
UAVObjectFieldUInt32(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldUInt32(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -36,6 +36,12 @@ UAVObjectFieldUInt8::UAVObjectFieldUInt8(const QString& name, const QString& uni
numBytesPerElement = sizeof(quint8);
}
UAVObjectFieldUInt8::UAVObjectFieldUInt8(const QString& name, const QString& units, const QStringList& elementNames):
UAVObjectField(name, units, elementNames)
{
numBytesPerElement = sizeof(quint8);
}
/**
* Initialize all values
*/

View File

@ -41,6 +41,7 @@ class UAVOBJECTS_EXPORT UAVObjectFieldUInt8: public UAVObjectField
public:
UAVObjectFieldUInt8(const QString& name, const QString& units, quint32 numElements);
UAVObjectFieldUInt8(const QString& name, const QString& units, const QStringList& elementNames);
void initializeValues();
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);

View File

@ -1,11 +1,9 @@
<xml>
<object name="SystemAlarms" singleinstance="true" settings="false">
<field name="Type" units="" type="enum" elements="1" options="None,StackOverflow,OutOfMemory"/>
<field name="Severity" units="" type="enum" elements="1" options="Info,Warning,Error,Critical"/>
<field name="Active" units="bool" type="enum" elements="1" options="True,False"/>
<field name="Info" units="" type="uint32" elements="1"/>
<field name="Alarm" units="" type="enum" options="None,Warning,Error,Critical"
elementnames="OutOfMemory,StackOverflow,CPUOverload,EventSystem"/>
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="onchange" period="0"/>
<logging updatemode="onchange" period="0"/>
<telemetryflight acked="true" updatemode="periodic" period="4000"/>
<logging updatemode="periodic" period="1000"/>
</object>
</xml>