From 30b6ae90f35aed3c93ef01860c049c1421b38145 Mon Sep 17 00:00:00 2001 From: LM Date: Mon, 14 Nov 2011 08:39:45 +0100 Subject: [PATCH] Added UAVObject sorting to make UAVObj structs align to word-boundaries. Else copying to / from UAVObjects will fail on Cortex M4 with an alignment error, since the proper alignment is not visible to the compiler in a line like this: float* data = UAVObj.Roll; data[2] = yaw; --- .gitignore | 2 ++ ground/uavobjgenerator/uavobjectparser.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index 6c4d8b39f..03797f84f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Exclude temporary and system files +.DS_Store # /flight/ /flight/*.pnproj diff --git a/ground/uavobjgenerator/uavobjectparser.cpp b/ground/uavobjgenerator/uavobjectparser.cpp index cba02f8ee..414712658 100644 --- a/ground/uavobjgenerator/uavobjectparser.cpp +++ b/ground/uavobjgenerator/uavobjectparser.cpp @@ -111,6 +111,11 @@ int UAVObjectParser::getNumBytes(int objIndex) } } +bool fieldTypeLessThan(const FieldInfo* f1, const FieldInfo* f2) +{ + return f1->numBytes > f2->numBytes; +} + /** * Parse supplied XML file * @param xml The xml text @@ -200,6 +205,9 @@ QString UAVObjectParser::parseXML(QString& xml, QString& filename) // Get next element childNode = childNode.nextSibling(); } + + // Sort all fields according to size + qStableSort(info->fields.begin(), info->fields.end(), fieldTypeLessThan); // Make sure that required elements were found if ( !accessFound )