/** * Delete all metaobjects from the SD card. * @return 0 if success or -1 if failure */ int32_t UAVObjDeleteMetaobjects() { ObjectList *objEntry; // Get lock xSemaphoreTakeRecursive(mutex, portMAX_DELAY); // Load all settings objects LL_FOREACH(objList, objEntry) { // Check if this is a settings object if (objEntry->isMetaobject) { // Load object if (UAVObjDelete((UAVObjHandle) objEntry, 0) == -1) { xSemaphoreGiveRecursive(mutex); return -1; } } } // Done xSemaphoreGiveRecursive(mutex); return 0; }
/** * Function called in response to object updates */ static void objectUpdatedCb(UAVObjEvent * ev) { ObjectPersistenceData objper; UAVObjHandle obj; // If the object updated was the ObjectPersistence execute requested action if (ev->obj == ObjectPersistenceHandle()) { // Get object data ObjectPersistenceGet(&objper); int retval = -1; // Execute action if (objper.Operation == OBJECTPERSISTENCE_OPERATION_LOAD) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Load selected instance retval = UAVObjLoad(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_SAVE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Save selected instance retval = UAVObjSave(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_DELETE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Delete selected instance retval = UAVObjDelete(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteMetaobjects(); } } if(retval == 0) { objper.Operation = OBJECTPERSISTENCE_OPERATION_COMPLETED; ObjectPersistenceSet(&objper); } } }
/** * Function called in response to object updates */ static void objectUpdatedCb(UAVObjEvent * ev) { ObjectPersistenceData objper; UAVObjHandle obj; // // DEBUG // if (ev->obj == SystemAlarmsHandle()) { // SystemAlarmsData alarm; // SystemAlarmsGet(&alarm); // PIOS_COM_SendFormattedString(PIOS_COM_DEBUG, "ALARM: %d\r\n", alarm.Alarm); // } // If the object updated was the ObjectPersistence execute requested action if (ev->obj == ObjectPersistenceHandle()) { // Get object data ObjectPersistenceGet(&objper); int retval = -1; // Execute action if (objper.Operation == OBJECTPERSISTENCE_OPERATION_LOAD) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Load selected instance retval = UAVObjLoad(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_SAVE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Save selected instance retval = UAVObjSave(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_DELETE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Delete selected instance retval = UAVObjDelete(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_FULLERASE) { retval = -1; #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) retval = PIOS_FLASHFS_Format(); #endif } if(retval == 0) { objper.Operation = OBJECTPERSISTENCE_OPERATION_COMPLETED; ObjectPersistenceSet(&objper); } } }
/** * Function called in response to object updates */ static void objectUpdatedCb(UAVObjEvent * ev) { ObjectPersistenceData objper; UAVObjHandle obj; // If the object updated was the ObjectPersistence execute requested action if (ev->obj == ObjectPersistenceHandle()) { // Get object data ObjectPersistenceGet(&objper); int retval = 1; // Execute action if (objper.Operation == OBJECTPERSISTENCE_OPERATION_LOAD) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Load selected instance retval = UAVObjLoad(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjLoadMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_SAVE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Save selected instance retval = UAVObjSave(obj, objper.InstanceID); // Not sure why this is needed vTaskDelay(10); // Verify saving worked if (retval == 0) retval = UAVObjLoad(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjSaveMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_DELETE) { if (objper.Selection == OBJECTPERSISTENCE_SELECTION_SINGLEOBJECT) { // Get selected object obj = UAVObjGetByID(objper.ObjectID); if (obj == 0) { return; } // Delete selected instance retval = UAVObjDelete(obj, objper.InstanceID); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLSETTINGS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteSettings(); } else if (objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLMETAOBJECTS || objper.Selection == OBJECTPERSISTENCE_SELECTION_ALLOBJECTS) { retval = UAVObjDeleteMetaobjects(); } } else if (objper.Operation == OBJECTPERSISTENCE_OPERATION_FULLERASE) { retval = -1; #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) retval = PIOS_FLASHFS_Format(); #elif defined(PIOS_INCLUDE_FLASH_COMPACT_SETTINGS) retval = PIOS_FLASHFS_Compact_Format(); #endif } switch(retval) { case 0: objper.Operation = OBJECTPERSISTENCE_OPERATION_COMPLETED; ObjectPersistenceSet(&objper); break; case -1: objper.Operation = OBJECTPERSISTENCE_OPERATION_ERROR; ObjectPersistenceSet(&objper); break; default: break; } } }