From afdaf88d4afba93c936f25438ae64d2ae25d608d Mon Sep 17 00:00:00 2001 From: corvus Date: Sat, 5 Feb 2011 22:17:40 +0000 Subject: [PATCH] UAVObjects: Allow Generation and Initialisation of individual UAVObjects per target as defined in Makefile (and/or Make include file) For OpenPilot this is flight/OpenPilot/UAVObjects.inc For sim_posix and sim_win32 needs rebuild of uavobjectgenerator and uavobjects! git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2736 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/OpenPilot/Makefile | 3 +- flight/OpenPilot/Makefile.posix | 5 +- flight/OpenPilot/Makefile.win32 | 5 +- flight/OpenPilot/UAVObjects.inc | 73 +++++++++++++++++++ flight/UAVObjects/Makefiletemplate.inc | 2 +- .../flight/uavobjectgeneratorflight.cpp | 36 ++++----- 6 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 flight/OpenPilot/UAVObjects.inc diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 637bf746e..b7c7840bd 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -170,7 +170,8 @@ endif ## UAVOBJECTS ifndef TESTAPP -include $(UAVOBJSYNTHDIR)/Makefile.inc +#include $(UAVOBJSYNTHDIR)/Makefile.inc +include ./UAVObjects.inc SRC += $(UAVOBJSRC) endif diff --git a/flight/OpenPilot/Makefile.posix b/flight/OpenPilot/Makefile.posix index 7a430a753..0673396d8 100644 --- a/flight/OpenPilot/Makefile.posix +++ b/flight/OpenPilot/Makefile.posix @@ -154,8 +154,10 @@ endif ## UAVOBJECTS ifndef TESTAPP -include $(UAVOBJSYNTHDIR)/Makefile.inc +#include $(UAVOBJSYNTHDIR)/Makefile.inc +include ./UAVObjects.inc SRC += $(UAVOBJSRC) +CFLAGS_UAVOBJECTS = $(UAVOBJDEFINE) endif ## PIOS Hardware (posix) @@ -298,6 +300,7 @@ ifeq ($(DEBUG),YES) CFLAGS = -g$(DEBUGF) -DDEBUG endif +CFLAGS += $(CFLAGS_UAVOBJECTS) CFLAGS += -DARCH_POSIX CFLAGS += -O$(OPT) CFLAGS += -mtune=$(MCU) diff --git a/flight/OpenPilot/Makefile.win32 b/flight/OpenPilot/Makefile.win32 index 729f954f1..05498866f 100644 --- a/flight/OpenPilot/Makefile.win32 +++ b/flight/OpenPilot/Makefile.win32 @@ -151,8 +151,10 @@ endif ## UAVOBJECTS ifndef TESTAPP -include $(UAVOBJSYNTHDIR)/Makefile.inc +#include $(UAVOBJSYNTHDIR)/Makefile.inc +include ./UAVObjects.inc SRC += $(UAVOBJSRC) +CFLAGS_UAVOBJECTS = $(UAVOBJDEFINE) endif ## PIOS Hardware (win32) @@ -288,6 +290,7 @@ ifeq ($(DEBUG),YES) CFLAGS = -g endif +CFLAGS += $(CFLAGS_UAVOBJECTS) CFLAGS += -DARCH_WIN32 CFLAGS += -O$(OPT) CFLAGS += -mtune=$(MCU) diff --git a/flight/OpenPilot/UAVObjects.inc b/flight/OpenPilot/UAVObjects.inc new file mode 100644 index 000000000..fa24d3f53 --- /dev/null +++ b/flight/OpenPilot/UAVObjects.inc @@ -0,0 +1,73 @@ +##### +# Project: OpenPilot +# +# Makefile for OpenPilot UAVObject code +# +# The OpenPilot Team, http://www.openpilot.org, Copyright (C) 2011. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +##### + +# These are the UAVObjects supposed to be build as part of the OpenPilot target +# (all architectures) + +UAVOBJSRCFILENAMES = +UAVOBJSRCFILENAMES += actuatorcommand +UAVOBJSRCFILENAMES += actuatordesired +UAVOBJSRCFILENAMES += actuatorsettings +UAVOBJSRCFILENAMES += ahrscalibration +UAVOBJSRCFILENAMES += ahrssettings +UAVOBJSRCFILENAMES += ahrsstatus +UAVOBJSRCFILENAMES += attitudeactual +UAVOBJSRCFILENAMES += attitudedesired +UAVOBJSRCFILENAMES += attituderaw +# UAVOBJSRCFILENAMES += attitudesettings CC only +UAVOBJSRCFILENAMES += baroaltitude +UAVOBJSRCFILENAMES += batterysettings +UAVOBJSRCFILENAMES += firmwareiapobj +UAVOBJSRCFILENAMES += flightbatterystate +UAVOBJSRCFILENAMES += flightplancontrol +UAVOBJSRCFILENAMES += flightplansettings +UAVOBJSRCFILENAMES += flightplanstatus +UAVOBJSRCFILENAMES += flighttelemetrystats +UAVOBJSRCFILENAMES += gcstelemetrystats +UAVOBJSRCFILENAMES += gpsposition +UAVOBJSRCFILENAMES += gpssatellites +UAVOBJSRCFILENAMES += gpstime +UAVOBJSRCFILENAMES += guidancesettings +UAVOBJSRCFILENAMES += homelocation +UAVOBJSRCFILENAMES += i2cstats +UAVOBJSRCFILENAMES += manualcontrolcommand +UAVOBJSRCFILENAMES += manualcontrolsettings +UAVOBJSRCFILENAMES += mixersettings +UAVOBJSRCFILENAMES += mixerstatus +UAVOBJSRCFILENAMES += nedaccel +UAVOBJSRCFILENAMES += objectpersistence +UAVOBJSRCFILENAMES += positionactual +UAVOBJSRCFILENAMES += positiondesired +UAVOBJSRCFILENAMES += ratedesired +UAVOBJSRCFILENAMES += sonaraltitude +UAVOBJSRCFILENAMES += stabilizationsettings +UAVOBJSRCFILENAMES += systemalarms +UAVOBJSRCFILENAMES += systemsettings +UAVOBJSRCFILENAMES += systemstats +UAVOBJSRCFILENAMES += taskinfo +UAVOBJSRCFILENAMES += telemetrysettings +UAVOBJSRCFILENAMES += velocityactual +UAVOBJSRCFILENAMES += velocitydesired +UAVOBJSRCFILENAMES += watchdogstatus + +UAVOBJSRC = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),$(UAVOBJSYNTHDIR)/$(UAVOBJSRCFILE).c ) +UAVOBJDEFINE = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),-DUAVOBJ_INIT_$(UAVOBJSRCFILE) ) diff --git a/flight/UAVObjects/Makefiletemplate.inc b/flight/UAVObjects/Makefiletemplate.inc index 9dcfabd8b..76907bb84 100644 --- a/flight/UAVObjects/Makefiletemplate.inc +++ b/flight/UAVObjects/Makefiletemplate.inc @@ -38,4 +38,4 @@ UAVOBJSRCFILENAMES = $(UAVOBJFILENAMES) UAVOBJSRC = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),$(UAVOBJSYNTHDIR)/$(UAVOBJSRCFILE).c ) - +UAVOBJDEFINE = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),-DUAVOBJ_INIT_$(UAVOBJSRCFILE) ) diff --git a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp index 03f9ffaff..400a8fa00 100644 --- a/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp +++ b/ground/uavobjgenerator/generators/flight/uavobjectgeneratorflight.cpp @@ -51,8 +51,10 @@ bool UAVObjectGeneratorFlight::generate(UAVObjectParser* parser,QString template for (int objidx = 0; objidx < parser->getNumObjects(); ++objidx) { ObjectInfo* info=parser->getObjectByIndex(objidx); process_object(info); - flightObjInit.append(" " + info->name + "Initialize();\n"); - objInc.append("#include \"" + info->namelc + ".h\"\n"); + flightObjInit.append("#ifdef UAVOBJ_INIT_" + info->namelc +"\r\n"); + flightObjInit.append(" " + info->name + "Initialize();\r\n"); + flightObjInit.append("#endif\r\n"); + objInc.append("#include \"" + info->namelc + ".h\"\r\n"); objFileNames.append(" " + info->namelc); objNames.append(" " + info->name); } @@ -107,12 +109,12 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) // Append field if ( info->fields[n]->numElements > 1 ) { - fields.append( QString(" %1 %2[%3];\n").arg(type) + fields.append( QString(" %1 %2[%3];\r\n").arg(type) .arg(info->fields[n]->name).arg(info->fields[n]->numElements) ); } else { - fields.append( QString(" %1 %2;\n").arg(type).arg(info->fields[n]->name) ); + fields.append( QString(" %1 %2;\r\n").arg(type).arg(info->fields[n]->name) ); } } outInclude.replace(QString("$(DATAFIELDS)"), fields); @@ -121,11 +123,11 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) QString enums; for (int n = 0; n < info->fields.length(); ++n) { - enums.append(QString("// Field %1 information\n").arg(info->fields[n]->name)); + enums.append(QString("// Field %1 information\r\n").arg(info->fields[n]->name)); // 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(QString("/* Enumeration options for field %1 */\r\n").arg(info->fields[n]->name)); enums.append("typedef enum { "); // Go through each option QStringList options = info->fields[n]->options; @@ -138,14 +140,14 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) .arg(m) ); } - enums.append( QString(" } %1%2Options;\n") + enums.append( QString(" } %1%2Options;\r\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(QString("/* Array element names for field %1 */\r\n").arg(info->fields[n]->name)); enums.append("typedef enum { "); // Go through the element names QStringList elemNames = info->fields[n]->elementNames; @@ -159,15 +161,15 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) .arg(m) ); } - enums.append( QString(" } %1%2Elem;\n") + enums.append( QString(" } %1%2Elem;\r\n") .arg( info->name ) .arg( info->fields[n]->name ) ); } // Generate array information if (info->fields[n]->numElements > 1) { - enums.append(QString("/* Number of elements for field %1 */\n").arg(info->fields[n]->name)); - enums.append( QString("#define %1_%2_NUMELEM %3\n") + enums.append(QString("/* Number of elements for field %1 */\r\n").arg(info->fields[n]->name)); + enums.append( QString("#define %1_%2_NUMELEM %3\r\n") .arg( info->name.toUpper() ) .arg( info->fields[n]->name.toUpper() ) .arg( info->fields[n]->numElements ) ); @@ -186,19 +188,19 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) { if ( info->fields[n]->type == FIELDTYPE_ENUM ) { - initfields.append( QString("\tdata.%1 = %2;\n") + initfields.append( QString("\tdata.%1 = %2;\r\n") .arg( info->fields[n]->name ) .arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[0] ) ) ); } else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 ) { - initfields.append( QString("\tdata.%1 = %2;\n") + initfields.append( QString("\tdata.%1 = %2;\r\n") .arg( info->fields[n]->name ) .arg( info->fields[n]->defaultValues[0].toFloat() ) ); } else { - initfields.append( QString("\tdata.%1 = %2;\n") + initfields.append( QString("\tdata.%1 = %2;\r\n") .arg( info->fields[n]->name ) .arg( info->fields[n]->defaultValues[0].toInt() ) ); } @@ -210,21 +212,21 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info) { if ( info->fields[n]->type == FIELDTYPE_ENUM ) { - initfields.append( QString("\tdata.%1[%2] = %3;\n") + initfields.append( QString("\tdata.%1[%2] = %3;\r\n") .arg( info->fields[n]->name ) .arg( idx ) .arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[idx] ) ) ); } else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 ) { - initfields.append( QString("\tdata.%1[%2] = %3;\n") + initfields.append( QString("\tdata.%1[%2] = %3;\r\n") .arg( info->fields[n]->name ) .arg( idx ) .arg( info->fields[n]->defaultValues[idx].toFloat() ) ); } else { - initfields.append( QString("\tdata.%1[%2] = %3;\n") + initfields.append( QString("\tdata.%1[%2] = %3;\r\n") .arg( info->fields[n]->name ) .arg( idx ) .arg( info->fields[n]->defaultValues[idx].toInt() ) );