mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Whitespace and line endings
This commit is contained in:
parent
934addfdcc
commit
d883c8af9f
@ -44,7 +44,7 @@ struct ObjectEventListStruct {
|
||||
xQueueHandle queue;
|
||||
UAVObjEventCallback cb;
|
||||
int32_t eventMask;
|
||||
struct ObjectEventListStruct* next;
|
||||
struct ObjectEventListStruct *next;
|
||||
};
|
||||
typedef struct ObjectEventListStruct ObjectEventList;
|
||||
|
||||
@ -52,9 +52,9 @@ typedef struct ObjectEventListStruct ObjectEventList;
|
||||
* List of object instances, holds the actual data structure and instance ID
|
||||
*/
|
||||
struct ObjectInstListStruct {
|
||||
void* data;
|
||||
void *data;
|
||||
uint16_t instId;
|
||||
struct ObjectInstListStruct* next;
|
||||
struct ObjectInstListStruct *next;
|
||||
};
|
||||
typedef struct ObjectInstListStruct ObjectInstList;
|
||||
|
||||
@ -62,34 +62,48 @@ typedef struct ObjectInstListStruct ObjectInstList;
|
||||
* List of objects registered in the object manager
|
||||
*/
|
||||
struct ObjectListStruct {
|
||||
uint32_t id; /** The object ID */
|
||||
const char* name; /** The object name */
|
||||
int8_t isMetaobject; /** Set to 1 if this is a metaobject */
|
||||
int8_t isSingleInstance; /** Set to 1 if this object has a single instance */
|
||||
int8_t isSettings; /** Set to 1 if this object is a settings object */
|
||||
uint16_t numBytes; /** Number of data bytes contained in the object (for a single instance) */
|
||||
uint16_t numInstances; /** Number of instances */
|
||||
struct ObjectListStruct* linkedObj; /** Linked object, for regular objects this is the metaobject and for metaobjects it is the parent object */
|
||||
ObjectInstList instances; /** List of object instances, instance 0 always exists */
|
||||
ObjectEventList* events; /** Event queues registered on the object */
|
||||
struct ObjectListStruct* next; /** Needed by linked list library (utlist.h) */
|
||||
uint32_t id;
|
||||
/** The object ID */
|
||||
const char *name;
|
||||
/** The object name */
|
||||
int8_t isMetaobject;
|
||||
/** Set to 1 if this is a metaobject */
|
||||
int8_t isSingleInstance;
|
||||
/** Set to 1 if this object has a single instance */
|
||||
int8_t isSettings;
|
||||
/** Set to 1 if this object is a settings object */
|
||||
uint16_t numBytes;
|
||||
/** Number of data bytes contained in the object (for a single instance) */
|
||||
uint16_t numInstances;
|
||||
/** Number of instances */
|
||||
struct ObjectListStruct *linkedObj;
|
||||
/** Linked object, for regular objects this is the metaobject and for metaobjects it is the parent object */
|
||||
ObjectInstList instances;
|
||||
/** List of object instances, instance 0 always exists */
|
||||
ObjectEventList *events;
|
||||
/** Event queues registered on the object */
|
||||
struct ObjectListStruct *next;
|
||||
/** Needed by linked list library (utlist.h) */
|
||||
};
|
||||
typedef struct ObjectListStruct ObjectList;
|
||||
|
||||
// Private functions
|
||||
static int32_t sendEvent(ObjectList* obj, uint16_t instId, UAVObjEventType event);
|
||||
static ObjectInstList* createInstance(ObjectList* obj, uint16_t instId);
|
||||
static ObjectInstList* getInstance(ObjectList* obj, uint16_t instId);
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback cb, int32_t eventMask);
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback cb);
|
||||
static int32_t sendEvent(ObjectList * obj, uint16_t instId,
|
||||
UAVObjEventType event);
|
||||
static ObjectInstList *createInstance(ObjectList * obj, uint16_t instId);
|
||||
static ObjectInstList *getInstance(ObjectList * obj, uint16_t instId);
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb, int32_t eventMask);
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb);
|
||||
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
static void objectFilename(ObjectList* obj, uint8_t* filename);
|
||||
static void customSPrintf(uint8_t* buffer, uint8_t* format, ...);
|
||||
static void objectFilename(ObjectList * obj, uint8_t * filename);
|
||||
static void customSPrintf(uint8_t * buffer, uint8_t * format, ...);
|
||||
#endif
|
||||
|
||||
// Private variables
|
||||
static ObjectList* objList;
|
||||
static ObjectList *objList;
|
||||
static xSemaphoreHandle mutex;
|
||||
static UAVObjMetadata defMetadata;
|
||||
static UAVObjStats stats;
|
||||
@ -130,7 +144,7 @@ int32_t UAVObjInitialize()
|
||||
* Get the statistics counters
|
||||
* @param[out] statsOut The statistics counters will be copied there
|
||||
*/
|
||||
void UAVObjGetStats(UAVObjStats* statsOut)
|
||||
void UAVObjGetStats(UAVObjStats * statsOut)
|
||||
{
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
memcpy(statsOut, &stats, sizeof(UAVObjStats));
|
||||
@ -160,21 +174,22 @@ void UAVObjClearStats()
|
||||
* \return Object handle, or NULL if failure.
|
||||
* \return
|
||||
*/
|
||||
UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName, int32_t isMetaobject,
|
||||
int32_t isSingleInstance, int32_t isSettings, uint32_t numBytes, UAVObjInitializeCallback initCb)
|
||||
UAVObjHandle UAVObjRegister(uint32_t id, const char *name,
|
||||
const char *metaName, int32_t isMetaobject,
|
||||
int32_t isSingleInstance, int32_t isSettings,
|
||||
uint32_t numBytes,
|
||||
UAVObjInitializeCallback initCb)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList* metaObj;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
ObjectList *metaObj;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Check that the object is not already registered
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
if (objEntry->id == id)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Already registered, ignore
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
@ -182,17 +197,16 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
||||
}
|
||||
|
||||
// Create and append entry
|
||||
objEntry = (ObjectList*)pvPortMalloc(sizeof(ObjectList));
|
||||
if (objEntry == NULL)
|
||||
{
|
||||
objEntry = (ObjectList *) pvPortMalloc(sizeof(ObjectList));
|
||||
if (objEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
objEntry->id = id;
|
||||
objEntry->name = name;
|
||||
objEntry->isMetaobject = (int8_t)isMetaobject;
|
||||
objEntry->isSingleInstance = (int8_t)isSingleInstance;
|
||||
objEntry->isSettings = (int8_t)isSettings;
|
||||
objEntry->isMetaobject = (int8_t) isMetaobject;
|
||||
objEntry->isSingleInstance = (int8_t) isSingleInstance;
|
||||
objEntry->isSettings = (int8_t) isSettings;
|
||||
objEntry->numBytes = numBytes;
|
||||
objEntry->events = NULL;
|
||||
objEntry->numInstances = 0;
|
||||
@ -204,47 +218,41 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
||||
|
||||
// Create instance zero
|
||||
instEntry = createInstance(objEntry, 0);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create metaobject and update linkedObj
|
||||
if (isMetaobject)
|
||||
{
|
||||
if (isMetaobject) {
|
||||
objEntry->linkedObj = NULL; // will be set later
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Create metaobject
|
||||
metaObj = (ObjectList*)UAVObjRegister(id+1, metaName, NULL, 1, 1, 0, sizeof(UAVObjMetadata), NULL);
|
||||
metaObj =
|
||||
(ObjectList *) UAVObjRegister(id + 1, metaName,
|
||||
NULL, 1, 1, 0,
|
||||
sizeof
|
||||
(UAVObjMetadata),
|
||||
NULL);
|
||||
// Link two objects
|
||||
objEntry->linkedObj = metaObj;
|
||||
metaObj->linkedObj = objEntry;
|
||||
}
|
||||
|
||||
// Initialize object fields and metadata to default values
|
||||
if ( initCb != NULL )
|
||||
{
|
||||
initCb((UAVObjHandle)objEntry, 0);
|
||||
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 ( !objEntry->isMetaobject )
|
||||
{
|
||||
UAVObjLoad( (UAVObjHandle)objEntry->linkedObj, 0 );
|
||||
if (!objEntry->isMetaobject) {
|
||||
UAVObjLoad((UAVObjHandle) objEntry->linkedObj, 0);
|
||||
}
|
||||
|
||||
// If this is a settings object, attempt to load from SD card
|
||||
if ( objEntry->isSettings )
|
||||
{
|
||||
UAVObjLoad( (UAVObjHandle)objEntry, 0 );
|
||||
if (objEntry->isSettings) {
|
||||
UAVObjLoad((UAVObjHandle) objEntry, 0);
|
||||
}
|
||||
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return (UAVObjHandle)objEntry;
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,20 +262,18 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
||||
*/
|
||||
UAVObjHandle UAVObjGetByID(uint32_t id)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
if (objEntry->id == id)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->id == id) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle)objEntry;
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,22 +287,21 @@ UAVObjHandle UAVObjGetByID(uint32_t id)
|
||||
* \param[in] name The name of the object
|
||||
* \return The object or NULL if not found.
|
||||
*/
|
||||
UAVObjHandle UAVObjGetByName(char* name)
|
||||
UAVObjHandle UAVObjGetByName(char *name)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Look for object
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
if (objEntry->name != NULL && strcmp(objEntry->name, name) == 0)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
if (objEntry->name != NULL
|
||||
&& strcmp(objEntry->name, name) == 0) {
|
||||
// Release lock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
// Done, object found
|
||||
return (UAVObjHandle)objEntry;
|
||||
return (UAVObjHandle) objEntry;
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +317,7 @@ UAVObjHandle UAVObjGetByName(char* name)
|
||||
*/
|
||||
uint32_t UAVObjGetID(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->id;
|
||||
return ((ObjectList *) obj)->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,9 +325,9 @@ uint32_t UAVObjGetID(UAVObjHandle obj)
|
||||
* \param[in] obj The object handle
|
||||
* \return The object's name
|
||||
*/
|
||||
const char* UAVObjGetName(UAVObjHandle obj)
|
||||
const char *UAVObjGetName(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->name;
|
||||
return ((ObjectList *) obj)->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -332,7 +337,7 @@ const char* UAVObjGetName(UAVObjHandle obj)
|
||||
*/
|
||||
uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->numBytes;
|
||||
return ((ObjectList *) obj)->numBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -344,7 +349,7 @@ uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
|
||||
*/
|
||||
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj)
|
||||
{
|
||||
return (UAVObjHandle)(((ObjectList*)obj)->linkedObj);
|
||||
return (UAVObjHandle) (((ObjectList *) obj)->linkedObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -356,7 +361,7 @@ uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
|
||||
{
|
||||
uint32_t numInstances;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
numInstances = ((ObjectList*)obj)->numInstances;
|
||||
numInstances = ((ObjectList *) obj)->numInstances;
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return numInstances;
|
||||
}
|
||||
@ -366,29 +371,26 @@ uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
|
||||
* \param[in] obj The object handle
|
||||
* \return The instance ID or 0 if an error
|
||||
*/
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj, UAVObjInitializeCallback initCb)
|
||||
uint16_t UAVObjCreateInstance(UAVObjHandle obj,
|
||||
UAVObjInitializeCallback initCb)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Create new instance
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
instEntry = createInstance(objEntry, objEntry->numInstances);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize instance data
|
||||
if ( initCb != NULL )
|
||||
{
|
||||
if (initCb != NULL) {
|
||||
initCb(obj, instEntry->instId);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return instEntry->instId;
|
||||
@ -401,7 +403,7 @@ uint16_t UAVObjCreateInstance(UAVObjHandle obj, UAVObjInitializeCallback initCb)
|
||||
*/
|
||||
int32_t UAVObjIsSingleInstance(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->isSingleInstance;
|
||||
return ((ObjectList *) obj)->isSingleInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -411,7 +413,7 @@ int32_t UAVObjIsSingleInstance(UAVObjHandle obj)
|
||||
*/
|
||||
int32_t UAVObjIsMetaobject(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->isMetaobject;
|
||||
return ((ObjectList *) obj)->isMetaobject;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,7 +423,7 @@ int32_t UAVObjIsMetaobject(UAVObjHandle obj)
|
||||
*/
|
||||
int32_t UAVObjIsSettings(UAVObjHandle obj)
|
||||
{
|
||||
return ((ObjectList*)obj)->isSettings;
|
||||
return ((ObjectList *) obj)->isSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -431,32 +433,30 @@ int32_t UAVObjIsSettings(UAVObjHandle obj)
|
||||
* \param[in] dataIn The byte array
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId, const uint8_t* dataIn)
|
||||
int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId,
|
||||
const uint8_t * dataIn)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the data
|
||||
memcpy(instEntry->data, dataIn, objEntry->numBytes);
|
||||
|
||||
@ -475,26 +475,24 @@ int32_t UAVObjUnpack(UAVObjHandle obj, uint16_t instId, const uint8_t* dataIn)
|
||||
* \param[out] dataOut The byte array
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t* dataOut)
|
||||
int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t * dataOut)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast handle to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Pack data
|
||||
memcpy(dataOut, instEntry->data, objEntry->numBytes);
|
||||
|
||||
@ -512,50 +510,46 @@ int32_t UAVObjPack(UAVObjHandle obj, uint16_t instId, uint8_t* dataOut)
|
||||
* @param[in] file File to append to
|
||||
* @return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file)
|
||||
int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId,
|
||||
FILEINFO * file)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
uint32_t bytesWritten;
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Check for file system availability
|
||||
if ( PIOS_SDCARD_IsMounted() == 0 )
|
||||
{
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Write the object ID
|
||||
PIOS_FWRITE(file,&objEntry->id,sizeof(objEntry->id),&bytesWritten);
|
||||
PIOS_FWRITE(file, &objEntry->id, sizeof(objEntry->id),
|
||||
&bytesWritten);
|
||||
|
||||
// Write the instance ID
|
||||
if (!objEntry->isSingleInstance)
|
||||
{
|
||||
PIOS_FWRITE(file,&instEntry->instId,sizeof(instEntry->instId),&bytesWritten);
|
||||
if (!objEntry->isSingleInstance) {
|
||||
PIOS_FWRITE(file, &instEntry->instId,
|
||||
sizeof(instEntry->instId), &bytesWritten);
|
||||
}
|
||||
|
||||
// Write the data and check that the write was successful
|
||||
PIOS_FWRITE(file,instEntry->data,objEntry->numBytes,&bytesWritten);
|
||||
if ( bytesWritten != objEntry->numBytes )
|
||||
{
|
||||
PIOS_FWRITE(file, instEntry->data, objEntry->numBytes,
|
||||
&bytesWritten);
|
||||
if (bytesWritten != objEntry->numBytes) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Done
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
@ -575,57 +569,51 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file)
|
||||
int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
|
||||
ObjectList* objEntry = (ObjectList*)obj;
|
||||
ObjectList *objEntry = (ObjectList *) obj;
|
||||
|
||||
if(objEntry == NULL)
|
||||
if (objEntry == NULL)
|
||||
return -1;
|
||||
|
||||
ObjectInstList* instEntry = getInstance(objEntry, instId);
|
||||
ObjectInstList *instEntry = getInstance(objEntry, instId);
|
||||
|
||||
if(instEntry == NULL)
|
||||
if (instEntry == NULL)
|
||||
return -1;
|
||||
|
||||
if(instEntry->data == NULL)
|
||||
if (instEntry->data == NULL)
|
||||
return -1;
|
||||
|
||||
if(PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) != 0)
|
||||
if (PIOS_FLASHFS_ObjSave(obj, instId, instEntry->data) != 0)
|
||||
return -1;
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
FILEINFO file;
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if ( PIOS_SDCARD_IsMounted() == 0 )
|
||||
{
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get filename
|
||||
objectFilename(objEntry, filename);
|
||||
|
||||
// Open file
|
||||
if ( PIOS_FOPEN_WRITE(filename,file) )
|
||||
{
|
||||
if (PIOS_FOPEN_WRITE(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Append object
|
||||
if ( UAVObjSaveToFile(obj, instId, &file) == -1 )
|
||||
{
|
||||
if (UAVObjSaveToFile(obj, instId, &file) == -1) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
@ -638,74 +626,63 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
|
||||
* @param[in] file File to read from
|
||||
* @return The handle of the object loaded or NULL if a failure
|
||||
*/
|
||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO * file)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
uint32_t bytesRead;
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
uint32_t objId;
|
||||
uint16_t instId;
|
||||
UAVObjHandle obj;
|
||||
|
||||
// Check for file system availability
|
||||
if ( PIOS_SDCARD_IsMounted() == 0 )
|
||||
{
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Read the object ID
|
||||
if ( PIOS_FREAD(file,&objId,sizeof(objId),&bytesRead) )
|
||||
{
|
||||
if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the object
|
||||
obj = UAVObjGetByID(objId);
|
||||
if ( obj == 0 )
|
||||
{
|
||||
if (obj == 0) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get the instance ID
|
||||
instId = 0;
|
||||
if ( !objEntry->isSingleInstance )
|
||||
{
|
||||
if ( PIOS_FREAD(file,&instId,sizeof(instId),&bytesRead) )
|
||||
{
|
||||
if (!objEntry->isSingleInstance) {
|
||||
if (PIOS_FREAD
|
||||
(file, &instId, sizeof(instId), &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
|
||||
// If the instance does not exist create it and any other instances before it
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
instEntry = createInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Read the instance data
|
||||
if ( PIOS_FREAD(file,instEntry->data,objEntry->numBytes,&bytesRead) )
|
||||
{
|
||||
if (PIOS_FREAD
|
||||
(file, instEntry->data, objEntry->numBytes, &bytesRead)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Fire event
|
||||
sendEvent(objEntry, instId, EV_UNPACKED);
|
||||
|
||||
@ -728,21 +705,21 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
||||
int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS)
|
||||
ObjectList* objEntry = (ObjectList*)obj;
|
||||
ObjectList *objEntry = (ObjectList *) obj;
|
||||
|
||||
if(objEntry == NULL)
|
||||
if (objEntry == NULL)
|
||||
return -1;
|
||||
|
||||
ObjectInstList* instEntry = getInstance(objEntry, instId);
|
||||
ObjectInstList *instEntry = getInstance(objEntry, instId);
|
||||
|
||||
if(instEntry == NULL)
|
||||
if (instEntry == NULL)
|
||||
return -1;
|
||||
|
||||
if(instEntry->data == NULL)
|
||||
if (instEntry->data == NULL)
|
||||
return -1;
|
||||
|
||||
// Fire event on success
|
||||
if(PIOS_FLASHFS_ObjLoad(obj, instId, instEntry->data) == 0)
|
||||
if (PIOS_FLASHFS_ObjLoad(obj, instId, instEntry->data) == 0)
|
||||
sendEvent(objEntry, instId, EV_UNPACKED);
|
||||
else
|
||||
return -1;
|
||||
@ -750,51 +727,43 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
|
||||
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
FILEINFO file;
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
UAVObjHandle loadedObj;
|
||||
ObjectList* loadedObjEntry;
|
||||
ObjectList *loadedObjEntry;
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if ( PIOS_SDCARD_IsMounted() == 0 )
|
||||
{
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get filename
|
||||
objectFilename(objEntry, filename);
|
||||
|
||||
// Open file
|
||||
if ( PIOS_FOPEN_READ(filename,file) )
|
||||
{
|
||||
if (PIOS_FOPEN_READ(filename, file)) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Load object
|
||||
loadedObj = UAVObjLoadFromFile(&file);
|
||||
if (loadedObj == 0)
|
||||
{
|
||||
if (loadedObj == 0) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that the IDs match
|
||||
loadedObjEntry = (ObjectList*)loadedObj;
|
||||
if ( loadedObjEntry->id != objEntry->id )
|
||||
{
|
||||
loadedObjEntry = (ObjectList *) loadedObj;
|
||||
if (loadedObjEntry->id != objEntry->id) {
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Done, close file and unlock
|
||||
PIOS_FCLOSE(file);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
@ -814,20 +783,18 @@ int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId)
|
||||
PIOS_FLASHFS_ObjDelete(obj, instId);
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SDCARD)
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
uint8_t filename[14];
|
||||
|
||||
// Check for file system availability
|
||||
if ( PIOS_SDCARD_IsMounted() == 0 )
|
||||
{
|
||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get filename
|
||||
objectFilename(objEntry, filename);
|
||||
@ -847,20 +814,18 @@ int32_t UAVObjDelete(UAVObjHandle obj, uint16_t instId)
|
||||
*/
|
||||
int32_t UAVObjSaveSettings()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isSettings )
|
||||
{
|
||||
if (objEntry->isSettings) {
|
||||
// Save object
|
||||
if ( UAVObjSave( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjSave((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -878,20 +843,18 @@ int32_t UAVObjSaveSettings()
|
||||
*/
|
||||
int32_t UAVObjLoadSettings()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isSettings )
|
||||
{
|
||||
if (objEntry->isSettings) {
|
||||
// Load object
|
||||
if ( UAVObjLoad( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjLoad((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -909,20 +872,18 @@ int32_t UAVObjLoadSettings()
|
||||
*/
|
||||
int32_t UAVObjDeleteSettings()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isSettings )
|
||||
{
|
||||
if (objEntry->isSettings) {
|
||||
// Save object
|
||||
if ( UAVObjDelete( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjDelete((UAVObjHandle) objEntry, 0)
|
||||
== -1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -940,20 +901,18 @@ int32_t UAVObjDeleteSettings()
|
||||
*/
|
||||
int32_t UAVObjSaveMetaobjects()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Save all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isMetaobject )
|
||||
{
|
||||
if (objEntry->isMetaobject) {
|
||||
// Save object
|
||||
if ( UAVObjSave( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjSave((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -971,20 +930,18 @@ int32_t UAVObjSaveMetaobjects()
|
||||
*/
|
||||
int32_t UAVObjLoadMetaobjects()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isMetaobject )
|
||||
{
|
||||
if (objEntry->isMetaobject) {
|
||||
// Load object
|
||||
if ( UAVObjLoad( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjLoad((UAVObjHandle) objEntry, 0) ==
|
||||
-1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -1002,20 +959,18 @@ int32_t UAVObjLoadMetaobjects()
|
||||
*/
|
||||
int32_t UAVObjDeleteMetaobjects()
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Load all settings objects
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
// Check if this is a settings object
|
||||
if ( objEntry->isMetaobject )
|
||||
{
|
||||
if (objEntry->isMetaobject) {
|
||||
// Load object
|
||||
if ( UAVObjDelete( (UAVObjHandle)objEntry, 0 ) == -1 )
|
||||
{
|
||||
if (UAVObjDelete((UAVObjHandle) objEntry, 0)
|
||||
== -1) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
@ -1033,7 +988,7 @@ int32_t UAVObjDeleteMetaobjects()
|
||||
* \param[in] dataIn The object's data structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSetData(UAVObjHandle obj, const void* dataIn)
|
||||
int32_t UAVObjSetData(UAVObjHandle obj, const void *dataIn)
|
||||
{
|
||||
return UAVObjSetInstanceData(obj, 0, dataIn);
|
||||
}
|
||||
@ -1044,7 +999,7 @@ int32_t UAVObjSetData(UAVObjHandle obj, const void* dataIn)
|
||||
* \param[out] dataOut The object's data structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjGetData(UAVObjHandle obj, void* dataOut)
|
||||
int32_t UAVObjGetData(UAVObjHandle obj, void *dataOut)
|
||||
{
|
||||
return UAVObjGetInstanceData(obj, 0, dataOut);
|
||||
}
|
||||
@ -1056,38 +1011,36 @@ int32_t UAVObjGetData(UAVObjHandle obj, void* dataOut)
|
||||
* \param[in] dataIn The object's data structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSetInstanceData(UAVObjHandle obj, uint16_t instId, const void* dataIn)
|
||||
int32_t UAVObjSetInstanceData(UAVObjHandle obj, uint16_t instId,
|
||||
const void *dataIn)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
UAVObjMetadata* mdata;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
UAVObjMetadata *mdata;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Check access level
|
||||
if ( !objEntry->isMetaobject )
|
||||
{
|
||||
mdata = (UAVObjMetadata*)(objEntry->linkedObj->instances.data);
|
||||
if ( mdata->access == ACCESS_READONLY )
|
||||
{
|
||||
if (!objEntry->isMetaobject) {
|
||||
mdata =
|
||||
(UAVObjMetadata *) (objEntry->linkedObj->instances.
|
||||
data);
|
||||
if (mdata->access == ACCESS_READONLY) {
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set data
|
||||
memcpy(instEntry->data, dataIn, objEntry->numBytes);
|
||||
|
||||
@ -1106,26 +1059,25 @@ int32_t UAVObjSetInstanceData(UAVObjHandle obj, uint16_t instId, const void* dat
|
||||
* \param[out] dataOut The object's data structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjGetInstanceData(UAVObjHandle obj, uint16_t instId, void* dataOut)
|
||||
int32_t UAVObjGetInstanceData(UAVObjHandle obj, uint16_t instId,
|
||||
void *dataOut)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectInstList* instEntry;
|
||||
ObjectList *objEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Get instance information
|
||||
instEntry = getInstance(objEntry, instId);
|
||||
if ( instEntry == NULL )
|
||||
{
|
||||
if (instEntry == NULL) {
|
||||
// Error, unlock and return
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set data
|
||||
memcpy(dataOut, instEntry->data, objEntry->numBytes);
|
||||
|
||||
@ -1140,21 +1092,19 @@ int32_t UAVObjGetInstanceData(UAVObjHandle obj, uint16_t instId, void* dataOut)
|
||||
* \param[in] dataIn The object's metadata structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjSetMetadata(UAVObjHandle obj, const UAVObjMetadata* dataIn)
|
||||
int32_t UAVObjSetMetadata(UAVObjHandle obj, const UAVObjMetadata * dataIn)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Set metadata (metadata of metaobjects can not be modified)
|
||||
objEntry = (ObjectList*)obj;
|
||||
if (!objEntry->isMetaobject)
|
||||
{
|
||||
UAVObjSetData((UAVObjHandle)objEntry->linkedObj, dataIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
objEntry = (ObjectList *) obj;
|
||||
if (!objEntry->isMetaobject) {
|
||||
UAVObjSetData((UAVObjHandle) objEntry->linkedObj,
|
||||
dataIn);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1169,22 +1119,20 @@ int32_t UAVObjSetMetadata(UAVObjHandle obj, const UAVObjMetadata* dataIn)
|
||||
* \param[out] dataOut The object's metadata structure
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjGetMetadata(UAVObjHandle obj, UAVObjMetadata* dataOut)
|
||||
int32_t UAVObjGetMetadata(UAVObjHandle obj, UAVObjMetadata * dataOut)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Get metadata
|
||||
objEntry = (ObjectList*)obj;
|
||||
if (objEntry->isMetaobject)
|
||||
{
|
||||
objEntry = (ObjectList *) obj;
|
||||
if (objEntry->isMetaobject) {
|
||||
memcpy(dataOut, &defMetadata, sizeof(UAVObjMetadata));
|
||||
}
|
||||
else
|
||||
{
|
||||
UAVObjGetData((UAVObjHandle)objEntry->linkedObj, dataOut);
|
||||
} else {
|
||||
UAVObjGetData((UAVObjHandle) objEntry->linkedObj,
|
||||
dataOut);
|
||||
}
|
||||
|
||||
// Unlock
|
||||
@ -1202,16 +1150,17 @@ int32_t UAVObjGetMetadata(UAVObjHandle obj, UAVObjMetadata* dataOut)
|
||||
*/
|
||||
int8_t UAVObjReadOnly(UAVObjHandle obj)
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
UAVObjMetadata* mdata;
|
||||
ObjectList *objEntry;
|
||||
UAVObjMetadata *mdata;
|
||||
|
||||
// Cast to object info
|
||||
objEntry = (ObjectList*)obj;
|
||||
objEntry = (ObjectList *) obj;
|
||||
|
||||
// Check access level
|
||||
if ( !objEntry->isMetaobject )
|
||||
{
|
||||
mdata = (UAVObjMetadata*)(objEntry->linkedObj->instances.data);
|
||||
if (!objEntry->isMetaobject) {
|
||||
mdata =
|
||||
(UAVObjMetadata *) (objEntry->linkedObj->instances.
|
||||
data);
|
||||
return mdata->access == ACCESS_READONLY;
|
||||
}
|
||||
return -1;
|
||||
@ -1225,7 +1174,8 @@ int8_t UAVObjReadOnly(UAVObjHandle obj)
|
||||
* \param[in] eventMask The event mask, if EV_MASK_ALL then all events are enabled (e.g. EV_UPDATED | EV_UPDATED_MANUAL)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjConnectQueue(UAVObjHandle obj, xQueueHandle queue, int32_t eventMask)
|
||||
int32_t UAVObjConnectQueue(UAVObjHandle obj, xQueueHandle queue,
|
||||
int32_t eventMask)
|
||||
{
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
@ -1257,7 +1207,8 @@ int32_t UAVObjDisconnectQueue(UAVObjHandle obj, xQueueHandle queue)
|
||||
* \param[in] eventMask The event mask, if EV_MASK_ALL then all events are enabled (e.g. EV_UPDATED | EV_UPDATED_MANUAL)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
int32_t UAVObjConnectCallback(UAVObjHandle obj, UAVObjEventCallback cb, int32_t eventMask)
|
||||
int32_t UAVObjConnectCallback(UAVObjHandle obj, UAVObjEventCallback cb,
|
||||
int32_t eventMask)
|
||||
{
|
||||
int32_t res;
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
@ -1281,7 +1232,6 @@ int32_t UAVObjDisconnectCallback(UAVObjHandle obj, UAVObjEventCallback cb)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request an update of the object's data from the GCS. The call will not wait for the response, a EV_UPDATED event
|
||||
* will be generated as soon as the object is updated.
|
||||
@ -1301,7 +1251,7 @@ void UAVObjRequestUpdate(UAVObjHandle obj)
|
||||
void UAVObjRequestInstanceUpdate(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((ObjectList*)obj, instId, EV_UPDATE_REQ);
|
||||
sendEvent((ObjectList *) obj, instId, EV_UPDATE_REQ);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
@ -1322,7 +1272,7 @@ void UAVObjUpdated(UAVObjHandle obj)
|
||||
void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId)
|
||||
{
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
sendEvent((ObjectList*)obj, instId, EV_UPDATED_MANUAL);
|
||||
sendEvent((ObjectList *) obj, instId, EV_UPDATED_MANUAL);
|
||||
xSemaphoreGiveRecursive(mutex);
|
||||
}
|
||||
|
||||
@ -1331,17 +1281,16 @@ void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId)
|
||||
* \param iterator This function will be called once for each object,
|
||||
* the object will be passed as a parameter
|
||||
*/
|
||||
void UAVObjIterate(void (*iterator)(UAVObjHandle obj))
|
||||
void UAVObjIterate(void (*iterator) (UAVObjHandle obj))
|
||||
{
|
||||
ObjectList* objEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Get lock
|
||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||
|
||||
// Iterate through the list and invoke iterator for each object
|
||||
LL_FOREACH(objList, objEntry)
|
||||
{
|
||||
(*iterator)((UAVObjHandle)objEntry);
|
||||
LL_FOREACH(objList, objEntry) {
|
||||
(*iterator) ((UAVObjHandle) objEntry);
|
||||
}
|
||||
|
||||
// Release lock
|
||||
@ -1351,33 +1300,31 @@ void UAVObjIterate(void (*iterator)(UAVObjHandle obj))
|
||||
/**
|
||||
* Send an event to all event queues registered on the object.
|
||||
*/
|
||||
static int32_t sendEvent(ObjectList* obj, uint16_t instId, UAVObjEventType event)
|
||||
static int32_t sendEvent(ObjectList * obj, uint16_t instId,
|
||||
UAVObjEventType event)
|
||||
{
|
||||
ObjectEventList* eventEntry;
|
||||
ObjectEventList *eventEntry;
|
||||
UAVObjEvent msg;
|
||||
|
||||
// Setup event
|
||||
msg.obj = (UAVObjHandle)obj;
|
||||
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 || (eventEntry->eventMask & event) != 0 )
|
||||
{
|
||||
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
|
||||
if (eventEntry->queue != 0) {
|
||||
if (xQueueSend(eventEntry->queue, &msg, 0) != pdTRUE) // will not block
|
||||
{
|
||||
++stats.eventErrors;
|
||||
}
|
||||
}
|
||||
// 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
|
||||
if (eventEntry->cb != 0) {
|
||||
if (EventCallbackDispatch(&msg, eventEntry->cb) != pdTRUE) // invoke callback from the event task, will not block
|
||||
{
|
||||
++stats.eventErrors;
|
||||
}
|
||||
@ -1392,52 +1339,47 @@ static int32_t sendEvent(ObjectList* obj, uint16_t instId, UAVObjEventType event
|
||||
/**
|
||||
* Create a new object instance, return the instance info or NULL if failure.
|
||||
*/
|
||||
static ObjectInstList* createInstance(ObjectList* obj, uint16_t instId)
|
||||
static ObjectInstList *createInstance(ObjectList * obj, uint16_t instId)
|
||||
{
|
||||
ObjectInstList* instEntry;
|
||||
ObjectInstList *instEntry;
|
||||
int32_t n;
|
||||
|
||||
// For single instance objects, only instance zero is allowed
|
||||
if (obj->isSingleInstance && instId != 0)
|
||||
{
|
||||
if (obj->isSingleInstance && instId != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Make sure that the instance ID is within limits
|
||||
if (instId >= UAVOBJ_MAX_INSTANCES)
|
||||
{
|
||||
if (instId >= UAVOBJ_MAX_INSTANCES) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if the instance already exists
|
||||
if ( getInstance(obj, instId) != NULL )
|
||||
{
|
||||
if (getInstance(obj, instId) != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create any missing instances (all instance IDs must be sequential)
|
||||
for (n = obj->numInstances; n < instId; ++n)
|
||||
{
|
||||
if ( createInstance(obj, n) == NULL )
|
||||
{
|
||||
for (n = obj->numInstances; n < instId; ++n) {
|
||||
if (createInstance(obj, n) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(instId == 0) /* Instance 0 ObjectInstList allocated with ObjectList element */
|
||||
{
|
||||
if (instId == 0) { /* Instance 0 ObjectInstList allocated with ObjectList element */
|
||||
instEntry = &obj->instances;
|
||||
instEntry->data = pvPortMalloc(obj->numBytes);
|
||||
if (instEntry->data == NULL) return NULL;
|
||||
if (instEntry->data == NULL)
|
||||
return NULL;
|
||||
memset(instEntry->data, 0, obj->numBytes);
|
||||
instEntry->instId = instId;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
// Create the actual instance
|
||||
instEntry = (ObjectInstList*)pvPortMalloc(sizeof(ObjectInstList));
|
||||
if (instEntry == NULL) return NULL;
|
||||
instEntry =
|
||||
(ObjectInstList *)
|
||||
pvPortMalloc(sizeof(ObjectInstList));
|
||||
if (instEntry == NULL)
|
||||
return NULL;
|
||||
instEntry->data = pvPortMalloc(obj->numBytes);
|
||||
if (instEntry->data == NULL) return NULL;
|
||||
if (instEntry->data == NULL)
|
||||
return NULL;
|
||||
memset(instEntry->data, 0, obj->numBytes);
|
||||
instEntry->instId = instId;
|
||||
LL_APPEND(obj->instances.next, instEntry);
|
||||
@ -1445,7 +1387,7 @@ static ObjectInstList* createInstance(ObjectList* obj, uint16_t instId)
|
||||
++obj->numInstances;
|
||||
|
||||
// Fire event
|
||||
UAVObjInstanceUpdated((UAVObjHandle)obj, instId);
|
||||
UAVObjInstanceUpdated((UAVObjHandle) obj, instId);
|
||||
|
||||
// Done
|
||||
return instEntry;
|
||||
@ -1454,15 +1396,13 @@ static ObjectInstList* createInstance(ObjectList* obj, uint16_t instId)
|
||||
/**
|
||||
* Get the instance information or NULL if the instance does not exist
|
||||
*/
|
||||
static ObjectInstList* getInstance(ObjectList* obj, uint16_t instId)
|
||||
static ObjectInstList *getInstance(ObjectList * obj, uint16_t instId)
|
||||
{
|
||||
ObjectInstList* instEntry;
|
||||
ObjectInstList *instEntry;
|
||||
|
||||
// Look for specified instance ID
|
||||
LL_FOREACH(&(obj->instances), instEntry)
|
||||
{
|
||||
if (instEntry->instId == instId)
|
||||
{
|
||||
LL_FOREACH(&(obj->instances), instEntry) {
|
||||
if (instEntry->instId == instId) {
|
||||
return instEntry;
|
||||
}
|
||||
}
|
||||
@ -1478,17 +1418,16 @@ static ObjectInstList* getInstance(ObjectList* obj, uint16_t instId)
|
||||
* \param[in] eventMask The event mask, if EV_MASK_ALL then all events are enabled (e.g. EV_UPDATED | EV_UPDATED_MANUAL)
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback cb, int32_t eventMask)
|
||||
static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb, int32_t eventMask)
|
||||
{
|
||||
ObjectEventList* eventEntry;
|
||||
ObjectList* objEntry;
|
||||
ObjectEventList *eventEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Check that the queue is not already connected, if it is simply update event mask
|
||||
objEntry = (ObjectList*)obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry)
|
||||
{
|
||||
if ( eventEntry->queue == queue && eventEntry->cb == cb )
|
||||
{
|
||||
objEntry = (ObjectList *) 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;
|
||||
@ -1496,9 +1435,9 @@ static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallb
|
||||
}
|
||||
|
||||
// Add queue to list
|
||||
eventEntry = (ObjectEventList*)pvPortMalloc(sizeof(ObjectEventList));
|
||||
if (eventEntry == NULL)
|
||||
{
|
||||
eventEntry =
|
||||
(ObjectEventList *) pvPortMalloc(sizeof(ObjectEventList));
|
||||
if (eventEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
eventEntry->queue = queue;
|
||||
@ -1517,17 +1456,17 @@ static int32_t connectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallb
|
||||
* \param[in] cb The event callback
|
||||
* \return 0 if success or -1 if failure
|
||||
*/
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback cb)
|
||||
static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue,
|
||||
UAVObjEventCallback cb)
|
||||
{
|
||||
ObjectEventList* eventEntry;
|
||||
ObjectList* objEntry;
|
||||
ObjectEventList *eventEntry;
|
||||
ObjectList *objEntry;
|
||||
|
||||
// Find queue and remove it
|
||||
objEntry = (ObjectList*)obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry)
|
||||
{
|
||||
if ( ( eventEntry->queue == queue && eventEntry->cb == cb ) )
|
||||
{
|
||||
objEntry = (ObjectList *) obj;
|
||||
LL_FOREACH(objEntry->events, eventEntry) {
|
||||
if ((eventEntry->queue == queue
|
||||
&& eventEntry->cb == cb)) {
|
||||
LL_DELETE(objEntry->events, eventEntry);
|
||||
vPortFree(eventEntry);
|
||||
return 0;
|
||||
@ -1542,7 +1481,7 @@ static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCa
|
||||
/**
|
||||
* Wrapper for the sprintf function
|
||||
*/
|
||||
static void customSPrintf(uint8_t* buffer, uint8_t* format, ...)
|
||||
static void customSPrintf(uint8_t * buffer, uint8_t * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@ -1552,24 +1491,8 @@ static void customSPrintf(uint8_t* buffer, uint8_t* format, ...)
|
||||
/**
|
||||
* Get an 8 character (plus extension) filename for the object.
|
||||
*/
|
||||
static void objectFilename(ObjectList* obj, uint8_t* filename)
|
||||
static void objectFilename(ObjectList * obj, uint8_t * filename)
|
||||
{
|
||||
customSPrintf(filename, (uint8_t*)"%X.obj", obj->id);
|
||||
customSPrintf(filename, (uint8_t *) "%X.obj", obj->id);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_SDCARD */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user