1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

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
This commit is contained in:
vassilis 2010-12-23 16:01:31 +00:00 committed by vassilis
parent be4df7b757
commit 6799f75aeb
3 changed files with 34 additions and 3 deletions

View File

@ -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;
}

View File

@ -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
{

View File

@ -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<ObjectInfo*> 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<int> fieldTypeNumBytes;
QStringList updateModeStr;
QStringList updateModeStrXML;
QStringList accessModeStr;