From 6799f75aebec92bed133fc30994e15c5f0d2f114 Mon Sep 17 00:00:00 2001 From: vassilis Date: Thu, 23 Dec 2010 16:01:31 +0000 Subject: [PATCH] GCS/UAVObjectGenerator: Calculate and report number of bytes used by the object fields. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2276 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../uavobjgenerator/uavobjectgenerator.cpp | 8 +++--- .../libs/uavobjgenerator/uavobjectparser.cpp | 26 +++++++++++++++++++ .../libs/uavobjgenerator/uavobjectparser.h | 3 +++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ground/src/libs/uavobjgenerator/uavobjectgenerator.cpp b/ground/src/libs/uavobjgenerator/uavobjectgenerator.cpp index 2473f6ded..85612ed8f 100644 --- a/ground/src/libs/uavobjgenerator/uavobjectgenerator.cpp +++ b/ground/src/libs/uavobjgenerator/uavobjectgenerator.cpp @@ -115,7 +115,7 @@ bool UAVObjectGenerator::processAll() QString flightObjInit; QString gcsObjInit; QString pythonObjInit; - + int numBytesTotal = 0; QString matlabAllocationCode; QString matlabSwithCode; @@ -130,7 +130,9 @@ bool UAVObjectGenerator::processAll() { QString name = parser->getObjectName(objidx); QString namelc = name.toLower(); - sout << "Generating code for object: " << name << endl; + int numBytes = parser->getNumBytes(objidx); + numBytesTotal += numBytes; + sout << "Generating code for object: " << name << " (" << numBytes << " bytes)" << endl; // Check for object ID conflicts quint32 id = parser->getObjectID(objidx); if ( objIDList.contains(id) || id == 0 ) @@ -256,7 +258,7 @@ bool UAVObjectGenerator::processAll() // Done sout << "Done: processed " << xmlList.length() << " XML files and generated " - << objIDList.length() << " objects with no ID collisions." << endl; + << objIDList.length() << " objects with no ID collisions. Total size of the data fields is " << numBytesTotal << " bytes." << endl; return true; } diff --git a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp index 5c0b8954d..689768ecf 100644 --- a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp +++ b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp @@ -57,6 +57,10 @@ UAVObjectParser::UAVObjectParser() QString("uint8") << QString("uint16") << QString("uint32") << QString("float") << QString("enum"); + fieldTypeNumBytes << int(1) << int(2) << int(4) << + int(1) << int(2) << int(4) << + int(4) << int(1); + updateModeStr << QString("UPDATEMODE_PERIODIC") << QString("UPDATEMODE_ONCHANGE") << QString("UPDATEMODE_MANUAL") << QString("UPDATEMODE_NEVER"); @@ -116,6 +120,27 @@ quint32 UAVObjectParser::getObjectID(int objIndex) } } +/** + * Get the number of bytes in the data fields of this object + */ +int UAVObjectParser::getNumBytes(int objIndex) +{ + ObjectInfo* info = objInfo[objIndex]; + if (info == NULL) + { + return 0; + } + else + { + int numBytes = 0; + for (int n = 0; n < info->fields.length(); ++n) + { + numBytes += info->fields[n]->numBytes * info->fields[n]->numElements; + } + return numBytes; + } +} + /** * Parse supplied XML file * @param xml The xml text @@ -454,6 +479,7 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in if (index >= 0) { field->type = (FieldType)index; + field->numBytes = fieldTypeNumBytes[index]; } else { diff --git a/ground/src/libs/uavobjgenerator/uavobjectparser.h b/ground/src/libs/uavobjgenerator/uavobjectparser.h index 0e07e7257..bbeabb393 100644 --- a/ground/src/libs/uavobjgenerator/uavobjectparser.h +++ b/ground/src/libs/uavobjgenerator/uavobjectparser.h @@ -69,6 +69,7 @@ public: QString units; FieldType type; int numElements; + int numBytes; QStringList elementNames; QStringList options; // for enums only bool defaultElementNames; @@ -101,6 +102,7 @@ public: QList getObjectInfo(); QString getObjectName(int objIndex); quint32 getObjectID(int objIndex); + int getNumBytes(int objIndex); bool generateFlightObject(int objIndex, const QString& templateInclude, const QString& templateCode, QString& outInclude, QString& outCode); bool generateGCSObject(int objIndex, const QString& templateInclude, const QString& templateCode, @@ -119,6 +121,7 @@ private: QStringList fieldTypeStrCPPClass; QStringList fieldTypeStrMatlab; QStringList fieldTypeStrXML; + QList fieldTypeNumBytes; QStringList updateModeStr; QStringList updateModeStrXML; QStringList accessModeStr;