mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
uavobjectmanager: fixup indentation
No functional changes.
This commit is contained in:
parent
42041ef68c
commit
2a2eb47a2a
@ -1,20 +1,20 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup UAVObjects OpenPilot UAVObjects
|
||||
* @{
|
||||
* @addtogroup UAV Object Manager
|
||||
* @brief The core UAV Objects functions, most of which are wrappered by
|
||||
* autogenerated defines
|
||||
* @{
|
||||
*
|
||||
*
|
||||
* @file uavobjectmanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Object manager library. This library holds a collection of all objects.
|
||||
* It can be used by all modules/libraries to find an object reference.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
******************************************************************************
|
||||
* @addtogroup UAVObjects OpenPilot UAVObjects
|
||||
* @{
|
||||
* @addtogroup UAV Object Manager
|
||||
* @brief The core UAV Objects functions, most of which are wrappered by
|
||||
* autogenerated defines
|
||||
* @{
|
||||
*
|
||||
*
|
||||
* @file uavobjectmanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Object manager library. This library holds a collection of all objects.
|
||||
* It can be used by all modules/libraries to find an object reference.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
@ -50,10 +50,10 @@
|
||||
* List of event queues and the eventmask associated with the queue.
|
||||
*/
|
||||
struct ObjectEventListStruct {
|
||||
xQueueHandle queue;
|
||||
UAVObjEventCallback cb;
|
||||
uint8_t eventMask;
|
||||
struct ObjectEventListStruct *next;
|
||||
xQueueHandle queue;
|
||||
UAVObjEventCallback cb;
|
||||
uint8_t eventMask;
|
||||
struct ObjectEventListStruct *next;
|
||||
};
|
||||
typedef struct ObjectEventListStruct ObjectEventList;
|
||||
|
||||
@ -61,14 +61,14 @@ typedef struct ObjectEventListStruct ObjectEventList;
|
||||
* List of object instances, holds a pointer to the next instance and some UAVObjectData
|
||||
*/
|
||||
struct ObjectInstListStruct {
|
||||
struct ObjectInstListStruct *next;
|
||||
struct ObjectInstListStruct *next;
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectInstListStruct ObjectInstList;
|
||||
|
||||
/** fake structure for arbitrary sizes **/
|
||||
struct ObjectInstanceStruct {
|
||||
ObjectInstList header;
|
||||
uint32_t data;
|
||||
ObjectInstList header;
|
||||
uint32_t data;
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectInstanceStruct ObjectInstance;
|
||||
#define ObjectInstanceSize(numBytes) (offsetof(ObjectInstance,data)+(numBytes))
|
||||
@ -87,56 +87,56 @@ typedef enum {
|
||||
*/
|
||||
|
||||
struct GenericObjectStruct {
|
||||
ObjectFlags flags;
|
||||
/** The object list mode flags */
|
||||
const char *name;
|
||||
/** The object name */
|
||||
ObjectEventList *events;
|
||||
/** Event queues registered on the object */
|
||||
ObjectFlags flags;
|
||||
/** The object list mode flags */
|
||||
const char *name;
|
||||
/** The object name */
|
||||
ObjectEventList *events;
|
||||
/** Event queues registered on the object */
|
||||
} __attribute__((packed));
|
||||
typedef struct GenericObjectStruct GenericObject;
|
||||
|
||||
struct MetaObjectStruct {
|
||||
GenericObject header;
|
||||
UAVObjMetadata data;
|
||||
/** the actual metadata */
|
||||
GenericObject header;
|
||||
UAVObjMetadata data;
|
||||
/** the actual metadata */
|
||||
} __attribute__((packed));
|
||||
typedef struct MetaObjectStruct MetaObject;
|
||||
|
||||
struct ObjectListStruct {
|
||||
GenericObject header;
|
||||
uint32_t id;
|
||||
/** The object ID */
|
||||
uint16_t numBytes;
|
||||
/** Number of data bytes contained in the object (for a single instance) */
|
||||
MetaObject metaObj;
|
||||
/** Meta object of the UAVObject */
|
||||
struct ObjectListStruct *next;
|
||||
/** Needed by linked list library (utlist.h) */
|
||||
GenericObject header;
|
||||
uint32_t id;
|
||||
/** The object ID */
|
||||
uint16_t numBytes;
|
||||
/** Number of data bytes contained in the object (for a single instance) */
|
||||
MetaObject metaObj;
|
||||
/** Meta object of the UAVObject */
|
||||
struct ObjectListStruct *next;
|
||||
/** Needed by linked list library (utlist.h) */
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectListStruct ObjectList;
|
||||
|
||||
/** fake structure for arbitrary sizes **/
|
||||
struct ObjectListInstanceStruct {
|
||||
ObjectList header;
|
||||
uint32_t data;
|
||||
ObjectList header;
|
||||
uint32_t data;
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectListInstanceStruct ObjectListInstance;
|
||||
#define ObjectListInstanceSize(numBytes) (offsetof(ObjectListInstance,data)+(numBytes))
|
||||
|
||||
struct ObjectListMultiStruct {
|
||||
ObjectList header;
|
||||
uint16_t numInstances;
|
||||
/** Number of instances */
|
||||
ObjectInstList instances;
|
||||
/** List of object instances, instance 0 always exists */
|
||||
ObjectList header;
|
||||
uint16_t numInstances;
|
||||
/** Number of instances */
|
||||
ObjectInstList instances;
|
||||
/** List of object instances, instance 0 always exists */
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectListMultiStruct ObjectListMulti;
|
||||
|
||||
/** fake structure for arbitrary sizes **/
|
||||
struct ObjectListMultiInstanceStruct {
|
||||
ObjectListMulti header;
|
||||
uint32_t data;
|
||||
ObjectListMulti header;
|
||||
uint32_t data;
|
||||
} __attribute__((packed));
|
||||
typedef struct ObjectListMultiInstanceStruct ObjectListMultiInstance;
|
||||
#define ObjectListMultiInstanceSize(numBytes) (offsetof(ObjectListMultiInstance,data)+(numBytes))
|
||||
@ -158,13 +158,13 @@ typedef struct ObjectListMultiInstanceStruct ObjectListMultiInstance;
|
||||
|
||||
// Private functions
|
||||
static int32_t sendEvent(GenericObject * obj, uint16_t instId,
|
||||
UAVObjEventType event);
|
||||
UAVObjEventType event);
|
||||
static InstanceHandle createInstance(ObjectList * obj, uint16_t instId);
|
||||
static InstanceHandle getInstance(ObjectList * obj, uint16_t instId);
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb, uint8_t eventMask);
|
||||
UAVObjEventCallback cb, uint8_t eventMask);
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb);
|
||||
UAVObjEventCallback cb);
|
||||
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
static void objectFilename(UAVObjHandle obj, uint8_t * filename);
|
||||
@ -184,20 +184,20 @@ static UAVObjStats stats;
|
||||
*/
|
||||
int32_t UAVObjInitialize()
|
||||
{
|
||||
// Initialize variables
|
||||
objList = NULL;
|
||||
memset(&stats, 0, sizeof(UAVObjStats));
|
||||
// Initialize variables
|
||||
objList = NULL;
|
||||
memset(&stats, 0, sizeof(UAVObjStats));
|
||||
|
||||
// Create mutex
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
if (mutex == NULL)
|
||||
return -1;
|
||||
// Create mutex
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
if (mutex == NULL)
|
||||
return -1;
|
||||
|
||||
// Initialize default metadata structure (metadata of metaobjects)
|
||||
UAVObjMetadataInitialize(&defMetadata);
|
||||
// Initialize default metadata structure (metadata of metaobjects)
|
||||
UAVObjMetadataInitialize(&defMetadata);
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,9 +206,9 @@ int32_t UAVObjInitialize()
|
||||
*/
|
||||
void UAVObjGetStats(UAVObjStats * statsOut)
|
||||
{
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
memcpy(statsOut, &stats, sizeof(UAVObjStats));
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
memcpy(statsOut, &stats, sizeof(UAVObjStats));
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,9 +216,9 @@ void UAVObjGetStats(UAVObjStats * statsOut)
|
||||
*/
|
||||
void UAVObjClearStats()
|
||||
{
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
memset(&stats, 0, sizeof(UAVObjStats));
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
memset(&stats, 0, sizeof(UAVObjStats));
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,77 +235,77 @@ void UAVObjClearStats()
|
||||
* \return
|
||||
*/
|
||||
UAVObjHandle UAVObjRegister(uint32_t id, const char *name,
|
||||
const char *metaName,
|
||||
int32_t isSingleInstance, int32_t isSettings,
|
||||
uint32_t numBytes,
|
||||
UAVObjInitializeCallback initCb)
|
||||
const char *metaName,
|
||||
int32_t isSingleInstance, int32_t isSettings,
|
||||
uint32_t numBytes,
|
||||
UAVObjInitializeCallback initCb)
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Check that the object is not already registered
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Already registered, ignore
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// Check that the object is not already registered
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Already registered, ignore
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create and append entry
|
||||
if (isSingleInstance) {
|
||||
objEntry = (ObjectList *) pvPortMalloc( ObjectListInstanceSize(numBytes) );
|
||||
} else {
|
||||
objEntry = (ObjectList *) pvPortMalloc( ObjectListMultiInstanceSize(numBytes) );
|
||||
}
|
||||
if (objEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
( (GenericObject*)objEntry )->name = name;
|
||||
( (GenericObject*)objEntry )->events = NULL;
|
||||
OLSetIsMetaobject( (GenericObject*)objEntry, 0);
|
||||
OLSetIsSingleInstance( (GenericObject*)objEntry, isSingleInstance);
|
||||
OLSetIsSettings( (GenericObject*)objEntry, isSettings);
|
||||
objEntry->id = id;
|
||||
objEntry->numBytes = numBytes;
|
||||
// Create instance
|
||||
if (isSingleInstance) {
|
||||
memset(ObjSingleInstanceDataOffset(objEntry), 0, numBytes);
|
||||
} else {
|
||||
( (ObjectListMulti*)objEntry )->numInstances = 1;
|
||||
( (ObjectListMulti*)objEntry )->instances.next = NULL;
|
||||
memset(InstanceDataOffset(&(( (ObjectListMulti*)objEntry )->instances)), 0, numBytes);
|
||||
}
|
||||
// Create metaobject
|
||||
memset(LinkedMetaDataPtr(objEntry), 0, MetaNumBytes);
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->flags = OL_IS_METAOBJECT | OL_IS_SINGLE_INSTANCE;
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->name = metaName;
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->events = NULL;
|
||||
LL_APPEND(objList, objEntry);
|
||||
// Create and append entry
|
||||
if (isSingleInstance) {
|
||||
objEntry = (ObjectList *) pvPortMalloc( ObjectListInstanceSize(numBytes) );
|
||||
} else {
|
||||
objEntry = (ObjectList *) pvPortMalloc( ObjectListMultiInstanceSize(numBytes) );
|
||||
}
|
||||
if (objEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
( (GenericObject*)objEntry )->name = name;
|
||||
( (GenericObject*)objEntry )->events = NULL;
|
||||
OLSetIsMetaobject( (GenericObject*)objEntry, 0);
|
||||
OLSetIsSingleInstance( (GenericObject*)objEntry, isSingleInstance);
|
||||
OLSetIsSettings( (GenericObject*)objEntry, isSettings);
|
||||
objEntry->id = id;
|
||||
objEntry->numBytes = numBytes;
|
||||
// Create instance
|
||||
if (isSingleInstance) {
|
||||
memset(ObjSingleInstanceDataOffset(objEntry), 0, numBytes);
|
||||
} else {
|
||||
( (ObjectListMulti*)objEntry )->numInstances = 1;
|
||||
( (ObjectListMulti*)objEntry )->instances.next = NULL;
|
||||
memset(InstanceDataOffset(&(( (ObjectListMulti*)objEntry )->instances)), 0, numBytes);
|
||||
}
|
||||
// Create metaobject
|
||||
memset(LinkedMetaDataPtr(objEntry), 0, MetaNumBytes);
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->flags = OL_IS_METAOBJECT | OL_IS_SINGLE_INSTANCE;
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->name = metaName;
|
||||
( (GenericObject*)MetaObjectPtr(objEntry) )->events = NULL;
|
||||
LL_APPEND(objList, objEntry);
|
||||
|
||||
// fire events
|
||||
UAVObjInstanceUpdated((UAVObjHandle) objEntry, 0);
|
||||
// fire events
|
||||
UAVObjInstanceUpdated((UAVObjHandle) objEntry, 0);
|
||||
|
||||
UAVObjInstanceUpdated((UAVObjHandle) MetaObjectPtr(objEntry), 0);
|
||||
UAVObjInstanceUpdated((UAVObjHandle) MetaObjectPtr(objEntry), 0);
|
||||
|
||||
// Initialize object fields and metadata to default values
|
||||
if (initCb != NULL) {
|
||||
initCb((UAVObjHandle) objEntry, 0);
|
||||
}
|
||||
// Attempt to load object's metadata from the SD card (not done directly on the metaobject, but through the object)
|
||||
if (!OLGetIsMetaobject((GenericObject*)objEntry)) {
|
||||
UAVObjLoad((UAVObjHandle) MetaObjectPtr(objEntry), 0);
|
||||
}
|
||||
// If this is a settings object, attempt to load from SD card
|
||||
if (OLGetIsSettings((GenericObject*)objEntry)) {
|
||||
UAVObjLoad((UAVObjHandle) objEntry, 0);
|
||||
}
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return (UAVObjHandle) objEntry;
|
||||
// Initialize object fields and metadata to default values
|
||||
if (initCb != NULL) {
|
||||
initCb((UAVObjHandle) objEntry, 0);
|
||||
}
|
||||
// Attempt to load object's metadata from the SD card (not done directly on the metaobject, but through the object)
|
||||
if (!OLGetIsMetaobject((GenericObject*)objEntry)) {
|
||||
UAVObjLoad((UAVObjHandle) MetaObjectPtr(objEntry), 0);
|
||||
}
|
||||
// If this is a settings object, attempt to load from SD card
|
||||
if (OLGetIsSettings((GenericObject*)objEntry)) {
|
||||
UAVObjLoad((UAVObjHandle) objEntry, 0);
|
||||
}
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -315,30 +315,30 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char *name,
|
||||
*/
|
||||
UAVObjHandle UAVObjGetByID(uint32_t id)
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
if (MetaObjectId(objEntry->id) == id) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) MetaObjectPtr(objEntry);
|
||||
}
|
||||
}
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
if (MetaObjectId(objEntry->id) == id) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) MetaObjectPtr(objEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Object not found, release lock and return error
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
// Object not found, release lock and return error
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -348,32 +348,32 @@ UAVObjHandle UAVObjGetByID(uint32_t id)
|
||||
*/
|
||||
UAVObjHandle UAVObjGetByName(char *name)
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if ( ( (GenericObject*)objEntry )->name != NULL
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if ( ( (GenericObject*)objEntry )->name != NULL
|
||||
&& strcmp(( (GenericObject*)objEntry )->name, name) == 0) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
if ( ( (GenericObject*)MetaObjectPtr(objEntry) )->name != NULL
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
if ( ( (GenericObject*)MetaObjectPtr(objEntry) )->name != NULL
|
||||
&& strcmp(( (GenericObject*)MetaObjectPtr(objEntry) )->name, name) == 0) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) MetaObjectPtr(objEntry);
|
||||
}
|
||||
}
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle) MetaObjectPtr(objEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Object not found, release lock and return error
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
// Object not found, release lock and return error
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,12 +383,12 @@ UAVObjHandle UAVObjGetByName(char *name)
|
||||
*/
|
||||
uint32_t UAVObjGetID(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaObjectId( MetaBaseObjectPtr(obj)->id );
|
||||
} else {
|
||||
return ((ObjectList *) obj)->id;
|
||||
}
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaObjectId( MetaBaseObjectPtr(obj)->id );
|
||||
} else {
|
||||
return ((ObjectList *) obj)->id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,8 +398,8 @@ uint32_t UAVObjGetID(UAVObjHandle obj)
|
||||
*/
|
||||
const char *UAVObjGetName(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
return ((GenericObject *) obj)->name;
|
||||
PIOS_Assert(obj);
|
||||
return ((GenericObject *) obj)->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -409,12 +409,12 @@ const char *UAVObjGetName(UAVObjHandle obj)
|
||||
*/
|
||||
uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaNumBytes;
|
||||
} else {
|
||||
return ((ObjectList *) obj)->numBytes;
|
||||
}
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaNumBytes;
|
||||
} else {
|
||||
return ((ObjectList *) obj)->numBytes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -426,12 +426,12 @@ uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
|
||||
*/
|
||||
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return (UAVObjHandle) MetaBaseObjectPtr(obj);
|
||||
} else {
|
||||
return (UAVObjHandle) MetaObjectPtr( (ObjectList*) obj);
|
||||
}
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return (UAVObjHandle) MetaBaseObjectPtr(obj);
|
||||
} else {
|
||||
return (UAVObjHandle) MetaObjectPtr( (ObjectList*) obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,15 +441,15 @@ UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj)
|
||||
*/
|
||||
uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaNumInstances;
|
||||
}
|
||||
uint32_t numInstances;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
numInstances = ObjNumInstances(obj);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return numInstances;
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return MetaNumInstances;
|
||||
}
|
||||
uint32_t numInstances;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
numInstances = ObjNumInstances(obj);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return numInstances;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,33 +458,33 @@ uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
|
||||
* \return The instance ID or 0 if an error
|
||||
*/
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj,
|
||||
UAVObjInitializeCallback initCb)
|
||||
UAVObjInitializeCallback initCb)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return -1;
|
||||
}
|
||||
PIOS_Assert(obj);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
InstanceHandle instEntry;
|
||||
uint16_t instId;
|
||||
InstanceHandle instEntry;
|
||||
uint16_t instId;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Create new instance
|
||||
instId = ObjNumInstances(obj);
|
||||
instEntry = createInstance( (ObjectList*)obj, instId);
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Initialize instance data
|
||||
if (initCb != NULL) {
|
||||
initCb(obj, instId);
|
||||
}
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return instId;
|
||||
// Create new instance
|
||||
instId = ObjNumInstances(obj);
|
||||
instEntry = createInstance( (ObjectList*)obj, instId);
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Initialize instance data
|
||||
if (initCb != NULL) {
|
||||
initCb(obj, instId);
|
||||
}
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return instId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,8 +494,8 @@ uint16_t UAVObjCreateInstance(UAVObjHandle obj,
|
||||
*/
|
||||
int32_t UAVObjIsSingleInstance(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsSingleInstance((GenericObject *) obj);
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsSingleInstance((GenericObject *) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -505,8 +505,8 @@ int32_t UAVObjIsSingleInstance(UAVObjHandle obj)
|
||||
*/
|
||||
int32_t UAVObjIsMetaobject(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsMetaobject((GenericObject *) obj);
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsMetaobject((GenericObject *) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,8 +516,8 @@ int32_t UAVObjIsMetaobject(UAVObjHandle obj)
|
||||
*/
|
||||
int32_t UAVObjIsSettings(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsSettings((GenericObject *) obj);
|
||||
PIOS_Assert(obj);
|
||||
return OLGetIsSettings((GenericObject *) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -528,48 +528,48 @@ int32_t UAVObjIsSettings(UAVObjHandle obj)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId,
|
||||
const uint8_t * dataIn)
|
||||
const uint8_t * dataIn)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
memcpy(MetaDataPtr((MetaObject *)obj), dataIn, MetaNumBytes);
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
memcpy(MetaDataPtr((MetaObject *)obj), dataIn, MetaNumBytes);
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// Set the data
|
||||
memcpy(InstanceData(instEntry), dataIn, objEntry->numBytes);
|
||||
}
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// Set the data
|
||||
memcpy(InstanceData(instEntry), dataIn, objEntry->numBytes);
|
||||
}
|
||||
|
||||
// Fire event
|
||||
sendEvent((GenericObject*)obj, instId, EV_UNPACKED);
|
||||
// Fire event
|
||||
sendEvent((GenericObject*)obj, instId, EV_UNPACKED);
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -581,38 +581,38 @@ int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId,
|
||||
*/
|
||||
int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t * dataOut)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
memcpy(dataOut, MetaDataPtr((MetaObject *)obj), MetaNumBytes);
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
memcpy(dataOut, MetaDataPtr((MetaObject *)obj), MetaNumBytes);
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Pack data
|
||||
memcpy(dataOut, InstanceData(instEntry), objEntry->numBytes);
|
||||
}
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Pack data
|
||||
memcpy(dataOut, InstanceData(instEntry), objEntry->numBytes);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -625,70 +625,70 @@ int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t * dataOut)
|
||||
* @return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId,
|
||||
FILEINFO * file)
|
||||
FILEINFO * file)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(obj);
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
uint32_t bytesWritten;
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
uint32_t bytesWritten;
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
// Get the instance information
|
||||
if (instId != 0) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Write the object ID
|
||||
uint32_t objId = UAVObjGetID(obj);
|
||||
PIOS_FWRITE(file, &objId, sizeof(objId),
|
||||
&bytesWritten);
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
// Get the instance information
|
||||
if (instId != 0) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Write the object ID
|
||||
uint32_t objId = UAVObjGetID(obj);
|
||||
PIOS_FWRITE(file, &objId, sizeof(objId),
|
||||
&bytesWritten);
|
||||
|
||||
// Write the data and check that the write was successful
|
||||
PIOS_FWRITE(file, MetaDataPtr((MetaObject *)obj), MetaNumBytes,
|
||||
&bytesWritten);
|
||||
if (bytesWritten != MetaNumBytes) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
// Write the data and check that the write was successful
|
||||
PIOS_FWRITE(file, MetaDataPtr((MetaObject *)obj), MetaNumBytes,
|
||||
&bytesWritten);
|
||||
if (bytesWritten != MetaNumBytes) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
|
||||
// Cast to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
// Cast to object
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Write the object ID
|
||||
PIOS_FWRITE(file, &objEntry->id, sizeof(objEntry->id),
|
||||
&bytesWritten);
|
||||
// Get the instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Write the object ID
|
||||
PIOS_FWRITE(file, &objEntry->id, sizeof(objEntry->id),
|
||||
&bytesWritten);
|
||||
|
||||
// Write the instance ID
|
||||
if (!OLGetIsSingleInstance((GenericObject*)obj)) {
|
||||
PIOS_FWRITE(file, &instId,
|
||||
sizeof(instId), &bytesWritten);
|
||||
}
|
||||
// Write the data and check that the write was successful
|
||||
PIOS_FWRITE(file, InstanceData(instEntry), objEntry->numBytes,
|
||||
&bytesWritten);
|
||||
if (bytesWritten != objEntry->numBytes) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Write the instance ID
|
||||
if (!OLGetIsSingleInstance((GenericObject*)obj)) {
|
||||
PIOS_FWRITE(file, &instId,
|
||||
sizeof(instId), &bytesWritten);
|
||||
}
|
||||
// Write the data and check that the write was successful
|
||||
PIOS_FWRITE(file, InstanceData(instEntry), objEntry->numBytes,
|
||||
&bytesWritten);
|
||||
if (bytesWritten != objEntry->numBytes) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -703,57 +703,57 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId,
|
||||
*/
|
||||
int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(obj);
|
||||
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0)
|
||||
return -1;
|
||||
if (OLGetIsMetaobject( (GenericObject *) obj )) {
|
||||
if (instId != 0)
|
||||
return -1;
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(obj, instId, (uint8_t*) MetaDataPtr((MetaObject *)obj)) != 0)
|
||||
return -1;
|
||||
} else {
|
||||
InstanceHandle instEntry = getInstance( (ObjectList*)obj, instId);
|
||||
if (PIOS_FLASHFS_ObjSave(obj, instId, (uint8_t*) MetaDataPtr((MetaObject *)obj)) != 0)
|
||||
return -1;
|
||||
} else {
|
||||
InstanceHandle instEntry = getInstance( (ObjectList*)obj, instId);
|
||||
|
||||
if (instEntry == NULL)
|
||||
return -1;
|
||||
if (instEntry == NULL)
|
||||
return -1;
|
||||
|
||||
if (InstanceData(instEntry) == NULL)
|
||||
return -1;
|
||||
if (InstanceData(instEntry) == NULL)
|
||||
return -1;
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(obj, instId, InstanceData(instEntry)) != 0)
|
||||
return -1;
|
||||
}
|
||||
if (PIOS_FLASHFS_ObjSave(obj, instId, InstanceData(instEntry)) != 0)
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
FILEINFO file;
|
||||
uint8_t filename[14];
|
||||
FILEINFO file;
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
|
||||
// Open file
|
||||
if (PIOS_FOPEN_WRITE(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Append object
|
||||
if (UAVObjSaveToFile(obj, instId, &file) == -1) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Open file
|
||||
if (PIOS_FOPEN_WRITE(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Append object
|
||||
if (UAVObjSaveToFile(obj, instId, &file) == -1) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -764,87 +764,87 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
|
||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO * file)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
uint32_t bytesRead;
|
||||
GenericObject *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
uint32_t objId;
|
||||
uint16_t instId;
|
||||
UAVObjHandle obj;
|
||||
uint32_t bytesRead;
|
||||
GenericObject *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
uint32_t objId;
|
||||
uint16_t instId;
|
||||
UAVObjHandle obj;
|
||||
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return NULL;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return NULL;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Read the object ID
|
||||
if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
// Get the object
|
||||
obj = UAVObjGetByID(objId);
|
||||
if (obj == 0) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
objEntry = (GenericObject *) obj;
|
||||
// Read the object ID
|
||||
if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
// Get the object
|
||||
obj = UAVObjGetByID(objId);
|
||||
if (obj == 0) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
objEntry = (GenericObject *) obj;
|
||||
|
||||
// Get the instance ID
|
||||
instId = 0;
|
||||
if (!OLGetIsSingleInstance(objEntry)) {
|
||||
if (PIOS_FREAD
|
||||
// Get the instance ID
|
||||
instId = 0;
|
||||
if (!OLGetIsSingleInstance(objEntry)) {
|
||||
if (PIOS_FREAD
|
||||
(file, &instId, sizeof(instId), &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (OLGetIsMetaobject( objEntry )) {
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
// Read the instance data
|
||||
if (PIOS_FREAD
|
||||
(file, MetaDataPtr((MetaObject *)obj), MetaNumBytes, &bytesRead)) {
|
||||
if (OLGetIsMetaobject( objEntry )) {
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
// Read the instance data
|
||||
if (PIOS_FREAD
|
||||
(file, MetaDataPtr((MetaObject *)obj), MetaNumBytes, &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Get the instance information
|
||||
instEntry = getInstance((ObjectList *)objEntry, instId);
|
||||
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance((ObjectList *)objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
// Read the instance data
|
||||
if (PIOS_FREAD
|
||||
(file, InstanceData(instEntry), ((ObjectList *)objEntry)->numBytes, &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the instance information
|
||||
instEntry = getInstance((ObjectList *)objEntry, instId);
|
||||
}
|
||||
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance((ObjectList *)objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// Read the instance data
|
||||
if (PIOS_FREAD
|
||||
(file, InstanceData(instEntry), ((ObjectList *)objEntry)->numBytes, &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
// Fire event
|
||||
sendEvent(objEntry, instId, EV_UNPACKED);
|
||||
|
||||
}
|
||||
|
||||
// Fire event
|
||||
sendEvent(objEntry, instId, EV_UNPACKED);
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return obj;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return obj;
|
||||
#else /* PIOS_INCLUDE_SDCARD */
|
||||
return NULL;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -860,7 +860,7 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
|
||||
if (OLGetIsMetaobject( (GenericObject*) obj )) {
|
||||
if (OLGetIsMetaobject( (GenericObject*) obj )) {
|
||||
if (instId != 0)
|
||||
return -1;
|
||||
|
||||
@ -886,43 +886,43 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
FILEINFO file;
|
||||
UAVObjHandle loadedObj;
|
||||
uint8_t filename[14];
|
||||
FILEINFO file;
|
||||
UAVObjHandle loadedObj;
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
|
||||
// Open file
|
||||
if (PIOS_FOPEN_READ(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Load object
|
||||
loadedObj = UAVObjLoadFromFile(&file);
|
||||
if (loadedObj == 0) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Check that the IDs match
|
||||
if (UAVObjGetID(loadedObj) != UAVObjGetID(obj)) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Open file
|
||||
if (PIOS_FOPEN_READ(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Load object
|
||||
loadedObj = UAVObjLoadFromFile(&file);
|
||||
if (loadedObj == 0) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Check that the IDs match
|
||||
if (UAVObjGetID(loadedObj) != UAVObjGetID(obj)) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -933,30 +933,30 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
|
||||
*/
|
||||
int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(obj);
|
||||
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
|
||||
PIOS_FLASHFS_ObjDelete(obj, instId);
|
||||
PIOS_FLASHFS_ObjDelete(obj, instId);
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
uint8_t filename[14];
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Check for file system availability
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
// Get filename
|
||||
objectFilename(obj, filename);
|
||||
|
||||
// Delete file
|
||||
PIOS_FUNLINK(filename);
|
||||
// Delete file
|
||||
PIOS_FUNLINK(filename);
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -965,27 +965,27 @@ int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId)
|
||||
*/
|
||||
int32_t UAVObjSaveSettings()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject*)objEntry)) {
|
||||
// Save object
|
||||
if (UAVObjSave((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject*)objEntry)) {
|
||||
// Save object
|
||||
if (UAVObjSave((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -994,27 +994,27 @@ int32_t UAVObjSaveSettings()
|
||||
*/
|
||||
int32_t UAVObjLoadSettings()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject *)objEntry)) {
|
||||
// Load object
|
||||
if (UAVObjLoad((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject *)objEntry)) {
|
||||
// Load object
|
||||
if (UAVObjLoad((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1023,27 +1023,27 @@ int32_t UAVObjLoadSettings()
|
||||
*/
|
||||
int32_t UAVObjDeleteSettings()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject *)objEntry)) {
|
||||
// Save object
|
||||
if (UAVObjDelete((UAVObjHandle) objEntry, 0)
|
||||
== -1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if (OLGetIsSettings((GenericObject *)objEntry)) {
|
||||
// Save object
|
||||
if (UAVObjDelete((UAVObjHandle) objEntry, 0)
|
||||
== -1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1052,24 +1052,24 @@ int32_t UAVObjDeleteSettings()
|
||||
*/
|
||||
int32_t UAVObjSaveMetaobjects()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Save object
|
||||
if (UAVObjSave( (UAVObjHandle) MetaObjectPtr(objEntry), 0) ==
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Save object
|
||||
if (UAVObjSave( (UAVObjHandle) MetaObjectPtr(objEntry), 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1078,24 +1078,24 @@ int32_t UAVObjSaveMetaobjects()
|
||||
*/
|
||||
int32_t UAVObjLoadMetaobjects()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Load object
|
||||
if (UAVObjLoad((UAVObjHandle) MetaObjectPtr(objEntry), 0) ==
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Load object
|
||||
if (UAVObjLoad((UAVObjHandle) MetaObjectPtr(objEntry), 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1104,24 +1104,24 @@ int32_t UAVObjLoadMetaobjects()
|
||||
*/
|
||||
int32_t UAVObjDeleteMetaobjects()
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Load object
|
||||
if (UAVObjDelete((UAVObjHandle) MetaObjectPtr(objEntry), 0)
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Load object
|
||||
if (UAVObjDelete((UAVObjHandle) MetaObjectPtr(objEntry), 0)
|
||||
== -1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1132,7 +1132,7 @@ int32_t UAVObjDeleteMetaobjects()
|
||||
*/
|
||||
int32_t UAVObjSetData(UAVObjHandle obj, const void *dataIn)
|
||||
{
|
||||
return UAVObjSetInstanceData(obj, 0, dataIn);
|
||||
return UAVObjSetInstanceData(obj, 0, dataIn);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1154,7 +1154,7 @@ int32_t UAVObjSetDataField(UAVObjHandle obj, const void* dataIn, uint32_t offset
|
||||
*/
|
||||
int32_t UAVObjGetData(UAVObjHandle obj, void *dataOut)
|
||||
{
|
||||
return UAVObjGetInstanceData(obj, 0, dataOut);
|
||||
return UAVObjGetInstanceData(obj, 0, dataOut);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1176,50 +1176,50 @@ int32_t UAVObjGetDataField(UAVObjHandle obj, void* dataOut, uint32_t offset, uin
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSetInstanceData(UAVObjHandle obj, uint16_t instId,
|
||||
const void *dataIn)
|
||||
const void *dataIn)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Check access level
|
||||
if (!OLGetIsMetaobject((GenericObject *)obj)) {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
// Check access level
|
||||
if (!OLGetIsMetaobject((GenericObject *)obj)) {
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList *) obj;
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
if (UAVObjGetAccess( LinkedMetaDataPtr(objEntry) ) == ACCESS_READONLY) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(InstanceData(instEntry), dataIn, objEntry->numBytes);
|
||||
} else {
|
||||
// Get instance information
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(MetaDataPtr((MetaObject *)obj), dataIn, MetaNumBytes);
|
||||
}
|
||||
if (UAVObjGetAccess( LinkedMetaDataPtr(objEntry) ) == ACCESS_READONLY) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(InstanceData(instEntry), dataIn, objEntry->numBytes);
|
||||
} else {
|
||||
// Get instance information
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(MetaDataPtr((MetaObject *)obj), dataIn, MetaNumBytes);
|
||||
}
|
||||
|
||||
// Fire event
|
||||
sendEvent((GenericObject *)obj, instId, EV_UPDATED);
|
||||
// Fire event
|
||||
sendEvent((GenericObject *)obj, instId, EV_UPDATED);
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1305,43 +1305,43 @@ int32_t UAVObjSetInstanceDataField(UAVObjHandle obj, uint16_t instId, const void
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjGetInstanceData(UAVObjHandle obj, uint16_t instId,
|
||||
void *dataOut)
|
||||
void *dataOut)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
PIOS_Assert(obj);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
if ( !OLGetIsMetaobject( (GenericObject*) obj) )
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
if ( !OLGetIsMetaobject( (GenericObject*) obj) )
|
||||
{
|
||||
ObjectList *objEntry;
|
||||
InstanceHandle instEntry;
|
||||
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList *) obj;
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(dataOut, InstanceData(instEntry), objEntry->numBytes);
|
||||
} else {
|
||||
// Get instance information
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(dataOut, MetaDataPtr((MetaObject *)obj), MetaNumBytes);
|
||||
}
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(dataOut, InstanceData(instEntry), objEntry->numBytes);
|
||||
} else {
|
||||
// Get instance information
|
||||
if (instId != 0) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
// Set data
|
||||
memcpy(dataOut, MetaDataPtr((MetaObject *)obj), MetaNumBytes);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1418,22 +1418,22 @@ int32_t UAVObjGetInstanceDataField(UAVObjHandle obj, uint16_t instId, void* data
|
||||
*/
|
||||
int32_t UAVObjSetMetadata(UAVObjHandle obj, const UAVObjMetadata * dataIn)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(obj);
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Set metadata (metadata of metaobjects can not be modified)
|
||||
if (!OLGetIsMetaobject((GenericObject*)obj)) {
|
||||
UAVObjSetData((UAVObjHandle) MetaObjectPtr( (ObjectList*)obj ),
|
||||
dataIn);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
// Set metadata (metadata of metaobjects can not be modified)
|
||||
if (!OLGetIsMetaobject((GenericObject*)obj)) {
|
||||
UAVObjSetData((UAVObjHandle) MetaObjectPtr( (ObjectList*)obj ),
|
||||
dataIn);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1444,22 +1444,22 @@ int32_t UAVObjSetMetadata(UAVObjHandle obj, const UAVObjMetadata * dataIn)
|
||||
*/
|
||||
int32_t UAVObjGetMetadata(UAVObjHandle obj, UAVObjMetadata * dataOut)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(obj);
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Get metadata
|
||||
if (OLGetIsMetaobject((GenericObject*)obj)) {
|
||||
memcpy(dataOut, &defMetadata, sizeof(UAVObjMetadata));
|
||||
} else {
|
||||
UAVObjGetData((UAVObjHandle) MetaObjectPtr( (ObjectList*)obj ),
|
||||
dataOut);
|
||||
}
|
||||
// Get metadata
|
||||
if (OLGetIsMetaobject((GenericObject*)obj)) {
|
||||
memcpy(dataOut, &defMetadata, sizeof(UAVObjMetadata));
|
||||
} else {
|
||||
UAVObjGetData((UAVObjHandle) MetaObjectPtr( (ObjectList*)obj ),
|
||||
dataOut);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1615,11 +1615,11 @@ void UAVObjSetGcsTelemetryUpdateMode(UAVObjMetadata* metadata, UAVObjUpdateMode
|
||||
*/
|
||||
int8_t UAVObjReadOnly(UAVObjHandle obj)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
if (!OLGetIsMetaobject( (GenericObject *)obj)) {
|
||||
return UAVObjGetAccess( LinkedMetaDataPtr( (ObjectList*)obj ) ) == ACCESS_READONLY;
|
||||
}
|
||||
return -1;
|
||||
PIOS_Assert(obj);
|
||||
if (!OLGetIsMetaobject( (GenericObject *)obj)) {
|
||||
return UAVObjGetAccess( LinkedMetaDataPtr( (ObjectList*)obj ) ) == ACCESS_READONLY;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1631,15 +1631,15 @@ int8_t UAVObjReadOnly(UAVObjHandle obj)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjConnectQueue(UAVObjHandle obj, xQueueHandle queue,
|
||||
uint8_t eventMask)
|
||||
uint8_t eventMask)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(queue);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = connectObj(obj, queue, 0, eventMask);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(queue);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = connectObj(obj, queue, 0, eventMask);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1650,13 +1650,13 @@ int32_t UAVObjConnectQueue(UAVObjHandle obj, xQueueHandle queue,
|
||||
*/
|
||||
int32_t UAVObjDisconnectQueue(UAVObjHandle obj, xQueueHandle queue)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(queue);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = disconnectObj(obj, queue, 0);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
PIOS_Assert(obj);
|
||||
PIOS_Assert(queue);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = disconnectObj(obj, queue, 0);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1668,14 +1668,14 @@ int32_t UAVObjDisconnectQueue(UAVObjHandle obj, xQueueHandle queue)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjConnectCallback(UAVObjHandle obj, UAVObjEventCallback cb,
|
||||
uint8_t eventMask)
|
||||
uint8_t eventMask)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = connectObj(obj, 0, cb, eventMask);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
PIOS_Assert(obj);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = connectObj(obj, 0, cb, eventMask);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1686,12 +1686,12 @@ int32_t UAVObjConnectCallback(UAVObjHandle obj, UAVObjEventCallback cb,
|
||||
*/
|
||||
int32_t UAVObjDisconnectCallback(UAVObjHandle obj, UAVObjEventCallback cb)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = disconnectObj(obj, 0, cb);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
PIOS_Assert(obj);
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
res = disconnectObj(obj, 0, cb);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1701,7 +1701,7 @@ int32_t UAVObjDisconnectCallback(UAVObjHandle obj, UAVObjEventCallback cb)
|
||||
*/
|
||||
void UAVObjRequestUpdate(UAVObjHandle obj)
|
||||
{
|
||||
UAVObjRequestInstanceUpdate(obj, UAVOBJ_ALL_INSTANCES);
|
||||
UAVObjRequestInstanceUpdate(obj, UAVOBJ_ALL_INSTANCES);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1712,10 +1712,10 @@ void UAVObjRequestUpdate(UAVObjHandle obj)
|
||||
*/
|
||||
void UAVObjRequestInstanceUpdate(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((GenericObject *) obj, instId, EV_UPDATE_REQ);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
PIOS_Assert(obj);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((GenericObject *) obj, instId, EV_UPDATE_REQ);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1724,7 +1724,7 @@ void UAVObjRequestInstanceUpdate(UAVObjHandle obj, uint16_t instId)
|
||||
*/
|
||||
void UAVObjUpdated(UAVObjHandle obj)
|
||||
{
|
||||
UAVObjInstanceUpdated(obj, UAVOBJ_ALL_INSTANCES);
|
||||
UAVObjInstanceUpdated(obj, UAVOBJ_ALL_INSTANCES);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1734,10 +1734,10 @@ void UAVObjUpdated(UAVObjHandle obj)
|
||||
*/
|
||||
void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
PIOS_Assert(obj);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((GenericObject *) obj, instId, EV_UPDATED_MANUAL);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
PIOS_Assert(obj);
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((GenericObject *) obj, instId, EV_UPDATED_MANUAL);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1747,61 +1747,61 @@ void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId)
|
||||
*/
|
||||
void UAVObjIterate(void (*iterator) (UAVObjHandle obj))
|
||||
{
|
||||
PIOS_Assert(iterator);
|
||||
ObjectList *objEntry;
|
||||
PIOS_Assert(iterator);
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Iterate through the list and invoke iterator for each object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
(*iterator) ((UAVObjHandle) objEntry);
|
||||
(*iterator) ((UAVObjHandle) MetaObjectPtr(objEntry));
|
||||
}
|
||||
// Iterate through the list and invoke iterator for each object
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
(*iterator) ((UAVObjHandle) objEntry);
|
||||
(*iterator) ((UAVObjHandle) MetaObjectPtr(objEntry));
|
||||
}
|
||||
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an event to all event queues registered on the object.
|
||||
*/
|
||||
static int32_t sendEvent(GenericObject * obj, uint16_t instId,
|
||||
UAVObjEventType event)
|
||||
UAVObjEventType event)
|
||||
{
|
||||
ObjectEventList *eventEntry;
|
||||
UAVObjEvent msg;
|
||||
ObjectEventList *eventEntry;
|
||||
UAVObjEvent msg;
|
||||
|
||||
// Setup event
|
||||
msg.obj = (UAVObjHandle) obj;
|
||||
msg.event = event;
|
||||
msg.instId = instId;
|
||||
// Setup event
|
||||
msg.obj = (UAVObjHandle) obj;
|
||||
msg.event = event;
|
||||
msg.instId = instId;
|
||||
|
||||
// Go through each object and push the event message in the queue (if event is activated for the queue)
|
||||
LL_FOREACH(obj->events, eventEntry) {
|
||||
if (eventEntry->eventMask == 0
|
||||
// Go through each object and push the event message in the queue (if event is activated for the queue)
|
||||
LL_FOREACH(obj->events, eventEntry) {
|
||||
if (eventEntry->eventMask == 0
|
||||
|| (eventEntry->eventMask & event) != 0) {
|
||||
// Send to queue if a valid queue is registered
|
||||
if (eventEntry->queue != 0) {
|
||||
if (xQueueSend(eventEntry->queue, &msg, 0) != pdTRUE) // will not block
|
||||
{
|
||||
stats.lastQueueErrorID = UAVObjGetID(obj);
|
||||
++stats.eventQueueErrors;
|
||||
}
|
||||
}
|
||||
// Invoke callback (from event task) if a valid one is registered
|
||||
if (eventEntry->cb != 0) {
|
||||
if (EventCallbackDispatch(&msg, eventEntry->cb) != pdTRUE) // invoke callback from the event task, will not block
|
||||
{
|
||||
++stats.eventCallbackErrors;
|
||||
stats.lastCallbackErrorID = UAVObjGetID(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Send to queue if a valid queue is registered
|
||||
if (eventEntry->queue != 0) {
|
||||
if (xQueueSend(eventEntry->queue, &msg, 0) != pdTRUE) // will not block
|
||||
{
|
||||
stats.lastQueueErrorID = UAVObjGetID(obj);
|
||||
++stats.eventQueueErrors;
|
||||
}
|
||||
}
|
||||
// Invoke callback (from event task) if a valid one is registered
|
||||
if (eventEntry->cb != 0) {
|
||||
if (EventCallbackDispatch(&msg, eventEntry->cb) != pdTRUE) // invoke callback from the event task, will not block
|
||||
{
|
||||
++stats.eventCallbackErrors;
|
||||
stats.lastCallbackErrorID = UAVObjGetID(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1809,45 +1809,45 @@ static int32_t sendEvent(GenericObject * obj, uint16_t instId,
|
||||
*/
|
||||
static InstanceHandle createInstance(ObjectList * obj, uint16_t instId)
|
||||
{
|
||||
ObjectInstList *instEntry;
|
||||
int32_t n;
|
||||
ObjectInstList *instEntry;
|
||||
int32_t n;
|
||||
|
||||
// For single instance objects, only instance zero is allowed (and zero gets created in RegisterObject)
|
||||
if (OLGetIsSingleInstance((GenericObject*)obj)) {
|
||||
PIOS_Assert(0);
|
||||
return NULL;
|
||||
}
|
||||
// Make sure that the instance ID is within limits
|
||||
if (instId >= UAVOBJ_MAX_INSTANCES) {
|
||||
return NULL;
|
||||
}
|
||||
// Check if the instance already exists
|
||||
if ( instId< ObjNumInstances(obj) ) {
|
||||
return NULL;
|
||||
}
|
||||
// Create any missing instances (all instance IDs must be sequential)
|
||||
for (n = ObjNumInstances(obj); n < instId; ++n) {
|
||||
if (createInstance(obj, n) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// For single instance objects, only instance zero is allowed (and zero gets created in RegisterObject)
|
||||
if (OLGetIsSingleInstance((GenericObject*)obj)) {
|
||||
PIOS_Assert(0);
|
||||
return NULL;
|
||||
}
|
||||
// Make sure that the instance ID is within limits
|
||||
if (instId >= UAVOBJ_MAX_INSTANCES) {
|
||||
return NULL;
|
||||
}
|
||||
// Check if the instance already exists
|
||||
if ( instId< ObjNumInstances(obj) ) {
|
||||
return NULL;
|
||||
}
|
||||
// Create any missing instances (all instance IDs must be sequential)
|
||||
for (n = ObjNumInstances(obj); n < instId; ++n) {
|
||||
if (createInstance(obj, n) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the actual instance
|
||||
instEntry =
|
||||
(ObjectInstList *)
|
||||
pvPortMalloc(sizeof(ObjectInstList)+obj->numBytes);
|
||||
if (instEntry == NULL)
|
||||
return NULL;
|
||||
memset(InstanceDataOffset(instEntry), 0, obj->numBytes);
|
||||
LL_APPEND(( (ObjectListMulti*)obj )->instances.next, instEntry);
|
||||
// Create the actual instance
|
||||
instEntry =
|
||||
(ObjectInstList *)
|
||||
pvPortMalloc(sizeof(ObjectInstList)+obj->numBytes);
|
||||
if (instEntry == NULL)
|
||||
return NULL;
|
||||
memset(InstanceDataOffset(instEntry), 0, obj->numBytes);
|
||||
LL_APPEND(( (ObjectListMulti*)obj )->instances.next, instEntry);
|
||||
|
||||
( (ObjectListMulti*)obj )->numInstances++;
|
||||
( (ObjectListMulti*)obj )->numInstances++;
|
||||
|
||||
// Fire event
|
||||
UAVObjInstanceUpdated((UAVObjHandle) obj, instId);
|
||||
// Fire event
|
||||
UAVObjInstanceUpdated((UAVObjHandle) obj, instId);
|
||||
|
||||
// Done
|
||||
return InstanceDataOffset(instEntry);
|
||||
// Done
|
||||
return InstanceDataOffset(instEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1855,25 +1855,25 @@ static InstanceHandle createInstance(ObjectList * obj, uint16_t instId)
|
||||
*/
|
||||
static InstanceHandle getInstance(ObjectList * obj, uint16_t instId)
|
||||
{
|
||||
ObjectInstList *instEntry;
|
||||
// quick solutions
|
||||
if (OLGetIsSingleInstance((GenericObject*)(obj))) {
|
||||
if (instId!=0)
|
||||
return NULL;
|
||||
return ObjSingleInstanceDataOffset(obj);
|
||||
}
|
||||
if (instId>=ObjNumInstances(obj))
|
||||
return NULL;
|
||||
ObjectInstList *instEntry;
|
||||
// quick solutions
|
||||
if (OLGetIsSingleInstance((GenericObject*)(obj))) {
|
||||
if (instId!=0)
|
||||
return NULL;
|
||||
return ObjSingleInstanceDataOffset(obj);
|
||||
}
|
||||
if (instId>=ObjNumInstances(obj))
|
||||
return NULL;
|
||||
|
||||
// Look for specified instance ID
|
||||
uint16_t instance=0;
|
||||
LL_FOREACH(&(( (ObjectListMulti*)obj )->instances), instEntry) {
|
||||
if (instance++ == instId) {
|
||||
return InstanceDataOffset(instEntry);
|
||||
}
|
||||
}
|
||||
// If this point is reached then instance id was not found
|
||||
return NULL;
|
||||
// Look for specified instance ID
|
||||
uint16_t instance=0;
|
||||
LL_FOREACH(&(( (ObjectListMulti*)obj )->instances), instEntry) {
|
||||
if (instance++ == instId) {
|
||||
return InstanceDataOffset(instEntry);
|
||||
}
|
||||
}
|
||||
// If this point is reached then instance id was not found
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1885,34 +1885,34 @@ static InstanceHandle getInstance(ObjectList * obj, uint16_t instId)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb, uint8_t eventMask)
|
||||
UAVObjEventCallback cb, uint8_t eventMask)
|
||||
{
|
||||
ObjectEventList *eventEntry;
|
||||
GenericObject *objEntry;
|
||||
ObjectEventList *eventEntry;
|
||||
GenericObject *objEntry;
|
||||
|
||||
// Check that the queue is not already connected, if it is simply update event mask
|
||||
objEntry = (GenericObject *) obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry) {
|
||||
if (eventEntry->queue == queue && eventEntry->cb == cb) {
|
||||
// Already connected, update event mask and return
|
||||
eventEntry->eventMask = eventMask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// Check that the queue is not already connected, if it is simply update event mask
|
||||
objEntry = (GenericObject *) obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry) {
|
||||
if (eventEntry->queue == queue && eventEntry->cb == cb) {
|
||||
// Already connected, update event mask and return
|
||||
eventEntry->eventMask = eventMask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Add queue to list
|
||||
eventEntry =
|
||||
(ObjectEventList *) pvPortMalloc(sizeof(ObjectEventList));
|
||||
if (eventEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
eventEntry->queue = queue;
|
||||
eventEntry->cb = cb;
|
||||
eventEntry->eventMask = eventMask;
|
||||
LL_APPEND(objEntry->events, eventEntry);
|
||||
// Add queue to list
|
||||
eventEntry =
|
||||
(ObjectEventList *) pvPortMalloc(sizeof(ObjectEventList));
|
||||
if (eventEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
eventEntry->queue = queue;
|
||||
eventEntry->cb = cb;
|
||||
eventEntry->eventMask = eventMask;
|
||||
LL_APPEND(objEntry->events, eventEntry);
|
||||
|
||||
// Done
|
||||
return 0;
|
||||
// Done
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1923,24 +1923,24 @@ static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb)
|
||||
UAVObjEventCallback cb)
|
||||
{
|
||||
ObjectEventList *eventEntry;
|
||||
GenericObject *objEntry;
|
||||
ObjectEventList *eventEntry;
|
||||
GenericObject *objEntry;
|
||||
|
||||
// Find queue and remove it
|
||||
objEntry = (GenericObject *) obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry) {
|
||||
if ((eventEntry->queue == queue
|
||||
&& eventEntry->cb == cb)) {
|
||||
LL_DELETE(objEntry->events, eventEntry);
|
||||
vPortFree(eventEntry);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// Find queue and remove it
|
||||
objEntry = (GenericObject *) obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry) {
|
||||
if ((eventEntry->queue == queue
|
||||
&& eventEntry->cb == cb)) {
|
||||
LL_DELETE(objEntry->events, eventEntry);
|
||||
vPortFree(eventEntry);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If this point is reached the queue was not found
|
||||
return -1;
|
||||
// If this point is reached the queue was not found
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
@ -1949,9 +1949,9 @@ static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
*/
|
||||
static void customSPrintf(uint8_t * buffer, uint8_t * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf((char *)buffer, (char *)format, args);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf((char *)buffer, (char *)format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1959,6 +1959,6 @@ static void customSPrintf(uint8_t * buffer, uint8_t * format, ...)
|
||||
*/
|
||||
static void objectFilename(UAVObjHandle obj, uint8_t * filename)
|
||||
{
|
||||
customSPrintf(filename, (uint8_t *) "%X.obj", UAVObjGetID(obj));
|
||||
customSPrintf(filename, (uint8_t *) "%X.obj", UAVObjGetID(obj));
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
|
Loading…
x
Reference in New Issue
Block a user