From 2139dee574209dddda7d01eea98dd4a013723a28 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sun, 24 Jun 2012 23:30:51 -0400 Subject: [PATCH] uavobjectmanager: remove uavo name field and related functions Saves a further 8 bytes of RAM per object. Saves 1.5KB of flash by removing all of the const strings for all of the object names and the corresponding meta object names. This leaves room for more code. --- flight/Modules/FlightPlan/lib/uavobject.py | 6 +- .../Modules/RadioComBridge/RadioComBridge.c | 6 +- flight/UAVObjects/inc/uavobjectmanager.h | 4 +- flight/UAVObjects/inc/uavobjecttemplate.h | 2 - flight/UAVObjects/uavobjectmanager.c | 68 ++----------------- flight/UAVObjects/uavobjecttemplate.c | 2 +- 6 files changed, 16 insertions(+), 72 deletions(-) diff --git a/flight/Modules/FlightPlan/lib/uavobject.py b/flight/Modules/FlightPlan/lib/uavobject.py index aafe76a43..bf2d622e8 100644 --- a/flight/Modules/FlightPlan/lib/uavobject.py +++ b/flight/Modules/FlightPlan/lib/uavobject.py @@ -109,7 +109,10 @@ class UAVObject: def addField(self, field): append(self.fields, field) - + ''' + # + # Support for getName was removed from embedded UAVO database to save RAM + Flash + # def getName(self): """__NATIVE__ UAVObjHandle objHandle; @@ -143,6 +146,7 @@ class UAVObject: return PM_RET_OK; """ pass + ''' def read(self): """__NATIVE__ diff --git a/flight/Modules/RadioComBridge/RadioComBridge.c b/flight/Modules/RadioComBridge/RadioComBridge.c index ceb547fd1..a321b4bfa 100644 --- a/flight/Modules/RadioComBridge/RadioComBridge.c +++ b/flight/Modules/RadioComBridge/RadioComBridge.c @@ -255,9 +255,9 @@ static int32_t RadioComBridgeInitialize(void) PipXSettingsPairIDGet(&(data->pairStats[0].pairID)); // Configure our UAVObjects for updates. - UAVObjConnectQueue(UAVObjGetByName("PipXStatus"), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); - UAVObjConnectQueue(UAVObjGetByName("GCSReceiver"), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); - UAVObjConnectQueue(UAVObjGetByName("ObjectPersistence"), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL); + UAVObjConnectQueue(UAVObjGetByID(PIPXSTATUS_OBJID), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); + UAVObjConnectQueue(UAVObjGetByID(GCSRECEIVER_OBJID), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); + UAVObjConnectQueue(UAVObjGetByID(OBJECTPERSISTENCE_OBJID), data->objEventQueue, EV_UPDATED | EV_UPDATED_MANUAL); return 0; } diff --git a/flight/UAVObjects/inc/uavobjectmanager.h b/flight/UAVObjects/inc/uavobjectmanager.h index 8bd8febb0..62aff543d 100644 --- a/flight/UAVObjects/inc/uavobjectmanager.h +++ b/flight/UAVObjects/inc/uavobjectmanager.h @@ -148,12 +148,10 @@ typedef struct { int32_t UAVObjInitialize(); void UAVObjGetStats(UAVObjStats* statsOut); void UAVObjClearStats(); -UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName, +UAVObjHandle UAVObjRegister(uint32_t id, int32_t isSingleInstance, int32_t isSettings, uint32_t numBytes, UAVObjInitializeCallback initCb); UAVObjHandle UAVObjGetByID(uint32_t id); -UAVObjHandle UAVObjGetByName(char* name); uint32_t UAVObjGetID(UAVObjHandle obj); -const char* UAVObjGetName(UAVObjHandle obj); uint32_t UAVObjGetNumBytes(UAVObjHandle obj); uint16_t UAVObjGetNumInstances(UAVObjHandle obj); UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj); diff --git a/flight/UAVObjects/inc/uavobjecttemplate.h b/flight/UAVObjects/inc/uavobjecttemplate.h index f106dd8ba..2938c218f 100644 --- a/flight/UAVObjects/inc/uavobjecttemplate.h +++ b/flight/UAVObjects/inc/uavobjecttemplate.h @@ -42,8 +42,6 @@ // Object constants #define $(NAMEUC)_OBJID $(OBJIDHEX) -#define $(NAMEUC)_NAME "$(NAME)" -#define $(NAMEUC)_METANAME "$(NAME)Meta" #define $(NAMEUC)_ISSINGLEINST $(ISSINGLEINST) #define $(NAMEUC)_ISSETTINGS $(ISSETTINGS) #define $(NAMEUC)_NUMBYTES sizeof($(NAME)Data) diff --git a/flight/UAVObjects/uavobjectmanager.c b/flight/UAVObjects/uavobjectmanager.c index 9d8efb2b6..2b2b69018 100644 --- a/flight/UAVObjects/uavobjectmanager.c +++ b/flight/UAVObjects/uavobjectmanager.c @@ -81,7 +81,6 @@ struct UAVOBase { bool isSettings : 1; } flags; - const char * name; } __attribute__((packed)); /* Augmented type for Meta UAVO */ @@ -237,14 +236,13 @@ static void UAVObjInitMetaData (struct UAVOMeta * obj_meta) memset(uavo_base, 0, sizeof(*uavo_base)); uavo_base->flags.isMeta = true; uavo_base->flags.isSingle = true; - uavo_base->name = name; uavo_base->next_event = NULL; /* Clear the instance data carried in the UAVO */ memset(&(obj_meta->instance0), 0, sizeof(obj_meta->instance0)); } -static struct UAVOData * UAVObjAllocSingle(uint32_t num_bytes, const char * name) +static struct UAVOData * UAVObjAllocSingle(uint32_t num_bytes) { /* Compute the complete size of the object, including the data for a single embedded instance */ uint32_t object_size = sizeof(struct UAVOSingle) + num_bytes; @@ -258,7 +256,6 @@ static struct UAVOData * UAVObjAllocSingle(uint32_t num_bytes, const char * name struct UAVOBase * uavo_base = &(uavo_single->uavo.base); memset(uavo_base, 0, sizeof(*uavo_base)); uavo_base->flags.isSingle = true; - uavo_base->name = name; uavo_base->next_event = NULL; /* Clear the instance data carried in the UAVO */ @@ -268,7 +265,7 @@ static struct UAVOData * UAVObjAllocSingle(uint32_t num_bytes, const char * name return (&(uavo_single->uavo)); } -static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes, const char * name) +static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes) { /* Compute the complete size of the object, including the data for a single embedded instance */ uint32_t object_size = sizeof(struct UAVOMulti) + num_bytes; @@ -282,7 +279,6 @@ static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes, const char * name) struct UAVOBase * uavo_base = &(uavo_multi->uavo.base); memset(uavo_base, 0, sizeof(*uavo_base)); uavo_base->flags.isSingle = false; - uavo_base->name = name; uavo_base->next_event = NULL; /* Set up the type-specific part of the UAVO */ @@ -302,8 +298,6 @@ static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes, const char * name) /** * Register and new object in the object manager. * \param[in] id Unique object ID - * \param[in] name Object name - * \param[in] nameName Metaobject name * \param[in] isSingleInstance Is this a single instance or multi-instance object * \param[in] isSettings Is this a settings object * \param[in] numBytes Number of bytes of object data (for one instance) @@ -311,8 +305,7 @@ static struct UAVOData * UAVObjAllocMulti(uint32_t num_bytes, const char * name) * \return Object handle, or NULL if failure. * \return */ -UAVObjHandle UAVObjRegister(uint32_t id, const char *name, - const char *metaName, +UAVObjHandle UAVObjRegister(uint32_t id, int32_t isSingleInstance, int32_t isSettings, uint32_t num_bytes, UAVObjInitializeCallback initCb) @@ -327,9 +320,9 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char *name, /* Map the various flags to one of the UAVO types we understand */ if (isSingleInstance) { - uavo_data = UAVObjAllocSingle (num_bytes, name); + uavo_data = UAVObjAllocSingle (num_bytes); } else { - uavo_data = UAVObjAllocMulti (num_bytes, name); + uavo_data = UAVObjAllocMulti (num_bytes); } if (!uavo_data) @@ -343,7 +336,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char *name, } /* Initialize the embedded meta UAVO */ - UAVObjInitMetaData (&uavo_data->metaObj, metaName); + UAVObjInitMetaData (&uavo_data->metaObj); /* Add the newly created object to the global list of objects */ LL_APPEND(uavo_list, uavo_data); @@ -398,40 +391,6 @@ unlock_exit: return found_obj; } -/** - * Retrieve an object from the list given its name - * \param[in] name The name of the object - * \return The object or NULL if not found. - */ -UAVObjHandle UAVObjGetByName(char *name) -{ - UAVObjHandle * found_obj = (UAVObjHandle *) NULL; - - // Get lock - xSemaphoreTakeRecursive(mutex, portMAX_DELAY); - - // Look for object - struct UAVO * tmp_obj; - LL_FOREACH(uavo_list, tmp_obj) { - if ((tmp_obj->common.name) && - strcmp(tmp_obj->common.name, name) == 0) { - - found_obj = (UAVObjHandle) tmp_obj; - goto unlock_exit; - } - if ((tmp_obj->metaObj.common.name) && - strcmp(tmp_obj->metaObj.common.name, name) == 0) { - - found_obj = (UAVObjHandle) &(tmp_obj->metaObj); - goto unlock_exit; - } - } - -unlock_exit: - xSemaphoreGiveRecursive(mutex); - return found_obj; -} - /** * Get the object's ID * \param[in] obj The object handle @@ -457,21 +416,6 @@ uint32_t UAVObjGetID(UAVObjHandle obj_handle) } } -/** - * Get the object's name - * \param[in] obj The object handle - * \return The object's name - */ -const char *UAVObjGetName(UAVObjHandle obj) -{ - PIOS_Assert(obj); - - /* Recover the common object header */ - struct UAVObjectCommon * uavo_common = (struct UAVObjectCommon *) obj; - - return (uavo_common->name); -} - /** * Get the number of bytes of the object's data (for one instance) * \param[in] obj The object handle diff --git a/flight/UAVObjects/uavobjecttemplate.c b/flight/UAVObjects/uavobjecttemplate.c index e515cc8d7..f8db8a024 100644 --- a/flight/UAVObjects/uavobjecttemplate.c +++ b/flight/UAVObjects/uavobjecttemplate.c @@ -54,7 +54,7 @@ int32_t $(NAME)Initialize(void) return -2; // Register object with the object manager - handle = UAVObjRegister($(NAMEUC)_OBJID, $(NAMEUC)_NAME, $(NAMEUC)_METANAME, + handle = UAVObjRegister($(NAMEUC)_OBJID, $(NAMEUC)_ISSINGLEINST, $(NAMEUC)_ISSETTINGS, $(NAMEUC)_NUMBYTES, &$(NAME)SetDefaults); // Done