mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
Merge branch 'corvuscorax/uavobjmanagerfix' into next
This commit is contained in:
commit
e3fe62d964
@ -159,7 +159,7 @@ int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId);
|
|||||||
int32_t UAVObjDelete(UAVObjHandle obj_handle, uint16_t instId);
|
int32_t UAVObjDelete(UAVObjHandle obj_handle, uint16_t instId);
|
||||||
#if defined(PIOS_INCLUDE_SDCARD)
|
#if defined(PIOS_INCLUDE_SDCARD)
|
||||||
int32_t UAVObjSaveToFile(UAVObjHandle obj_handle, uint16_t instId, FILEINFO *file);
|
int32_t UAVObjSaveToFile(UAVObjHandle obj_handle, uint16_t instId, FILEINFO *file);
|
||||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO *file);
|
int32_t UAVObjLoadFromFile(UAVObjHandle obj_handle, FILEINFO *file);
|
||||||
#endif
|
#endif
|
||||||
int32_t UAVObjSaveSettings();
|
int32_t UAVObjSaveSettings();
|
||||||
int32_t UAVObjLoadSettings();
|
int32_t UAVObjLoadSettings();
|
||||||
|
@ -864,45 +864,50 @@ int32_t UAVObjSave(UAVObjHandle obj_handle, __attribute__((unused)) uint16_t ins
|
|||||||
#if defined(PIOS_USE_SETTINGS_ON_SDCARD)
|
#if defined(PIOS_USE_SETTINGS_ON_SDCARD)
|
||||||
/**
|
/**
|
||||||
* Load an object from the file system (SD card).
|
* Load an object from the file system (SD card).
|
||||||
|
* @param[in] obj The object handle.
|
||||||
* @param[in] file File to read from
|
* @param[in] file File to read from
|
||||||
* @return The handle of the object loaded or NULL if a failure
|
* @return 0 if success or -1 if failure
|
||||||
*/
|
*/
|
||||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO *file)
|
int32_t UAVObjLoadFromFile(UAVObjHandle obj_handle, FILEINFO *file)
|
||||||
{
|
{
|
||||||
uint32_t bytesRead;
|
uint32_t bytesRead;
|
||||||
struct UAVOBase *objEntry;
|
struct UAVOBase *objEntry;
|
||||||
InstanceHandle instEntry;
|
InstanceHandle instEntry;
|
||||||
uint32_t objId;
|
uint32_t objId;
|
||||||
uint16_t instId;
|
uint16_t instId;
|
||||||
UAVObjHandle obj_handle;
|
|
||||||
|
|
||||||
// Check for file system availability
|
// Check for file system availability
|
||||||
if (PIOS_SDCARD_IsMounted() == 0) {
|
if (PIOS_SDCARD_IsMounted() == 0) {
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// Get the object
|
||||||
|
if (obj_handle == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
objEntry = (struct UAVOBase *)obj_handle;
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
// Read the object ID
|
// Read the object ID
|
||||||
if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) {
|
if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) {
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
// Get the object
|
|
||||||
obj_handle = UAVObjGetByID(objId);
|
// Check that the IDs match
|
||||||
if (obj_handle == 0) {
|
if (objId != UAVObjGetID(obj_handle)) {
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
objEntry = (struct UAVOBase *)obj_handle;
|
|
||||||
|
|
||||||
// Get the instance ID
|
// Get the instance ID
|
||||||
instId = 0;
|
instId = 0;
|
||||||
if (!UAVObjIsSingleInstance(obj_handle)) {
|
if (!UAVObjIsSingleInstance(obj_handle)) {
|
||||||
if (PIOS_FREAD
|
if (PIOS_FREAD
|
||||||
(file, &instId, sizeof(instId), &bytesRead)) {
|
(file, &instId, sizeof(instId), &bytesRead)) {
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -911,13 +916,13 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO *file)
|
|||||||
if (instId != 0) {
|
if (instId != 0) {
|
||||||
// Error, unlock and return
|
// Error, unlock and return
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (PIOS_FREAD
|
if (PIOS_FREAD
|
||||||
(file, MetaDataPtr((struct UAVOMeta *)obj_handle), MetaNumBytes, &bytesRead)) {
|
(file, MetaDataPtr((struct UAVOMeta *)obj_handle), MetaNumBytes, &bytesRead)) {
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Get the instance information
|
// Get the instance information
|
||||||
@ -929,14 +934,14 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO *file)
|
|||||||
if (instEntry == NULL) {
|
if (instEntry == NULL) {
|
||||||
// Error, unlock and return
|
// Error, unlock and return
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Read the instance data
|
// Read the instance data
|
||||||
if (PIOS_FREAD
|
if (PIOS_FREAD
|
||||||
(file, InstanceData(instEntry), ((struct UAVOData *)objEntry)->instance_size, &bytesRead)) {
|
(file, InstanceData(instEntry), ((struct UAVOData *)objEntry)->instance_size, &bytesRead)) {
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,7 +950,7 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO *file)
|
|||||||
|
|
||||||
// Unlock
|
// Unlock
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return obj_handle;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* PIOS_USE_SETTINGS_ON_SDCARD */
|
#endif /* PIOS_USE_SETTINGS_ON_SDCARD */
|
||||||
|
|
||||||
@ -992,7 +997,6 @@ int32_t UAVObjLoad(UAVObjHandle obj_handle, __attribute__((unused)) uint16_t ins
|
|||||||
|
|
||||||
#if defined(PIOS_USE_SETTINGS_ON_SDCARD)
|
#if defined(PIOS_USE_SETTINGS_ON_SDCARD)
|
||||||
FILEINFO file;
|
FILEINFO file;
|
||||||
UAVObjHandle loadedObj;
|
|
||||||
uint8_t filename[14];
|
uint8_t filename[14];
|
||||||
|
|
||||||
// Check for file system availability
|
// Check for file system availability
|
||||||
@ -1011,14 +1015,7 @@ int32_t UAVObjLoad(UAVObjHandle obj_handle, __attribute__((unused)) uint16_t ins
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Load object
|
// Load object
|
||||||
loadedObj = UAVObjLoadFromFile(&file);
|
if (UAVObjLoadFromFile(obj_handle, &file) != 0) {
|
||||||
if (loadedObj == 0) {
|
|
||||||
PIOS_FCLOSE(file);
|
|
||||||
xSemaphoreGiveRecursive(mutex);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// Check that the IDs match
|
|
||||||
if (UAVObjGetID(loadedObj) != UAVObjGetID(obj_handle)) {
|
|
||||||
PIOS_FCLOSE(file);
|
PIOS_FCLOSE(file);
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user