From bf792a805802f3181982e56cd45b64fe95b32136 Mon Sep 17 00:00:00 2001 From: vassilis Date: Sat, 10 Apr 2010 05:06:19 +0000 Subject: [PATCH] Flight/SystemMod: Creation of the system module, for now it only responds to a request to load/save the settings objects git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@468 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/OpenPilot/Makefile | 5 ++ .../OpenPilot/Modules/System/inc/systemmod.h | 34 +++++++++ flight/OpenPilot/Modules/System/systemmod.c | 76 +++++++++++++++++++ .../UAVObjects/inc/settingspersistence.h | 73 ++++++++++++++++++ .../UAVObjects/inc/uavobjectmanager.h | 2 + .../UAVObjects/settingspersistence.c | 73 ++++++++++++++++++ .../OpenPilot/UAVObjects/uavobjectmanager.c | 61 +++++++++++++++ flight/OpenPilot/UAVObjects/uavobjectsinit.c | 2 + 8 files changed, 326 insertions(+) create mode 100644 flight/OpenPilot/Modules/System/inc/systemmod.h create mode 100644 flight/OpenPilot/Modules/System/systemmod.c create mode 100644 flight/OpenPilot/UAVObjects/inc/settingspersistence.h create mode 100644 flight/OpenPilot/UAVObjects/settingspersistence.c diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 101701f84..a0804cc5f 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -75,6 +75,8 @@ OPTESTS = ./Tests OPMODULEDIR = ./Modules MODEXAMPLE = $(OPMODULEDIR)/Example MODEXAMPLEINC = $(MODEXAMPLE)/inc +MODSYSTEM = $(OPMODULEDIR)/System +MODSYSTEMINC = $(MODSYSTEM)/inc MODTELEMETRY = $(OPMODULEDIR)/Telemetry MODTELEMETRYINC = $(MODTELEMETRY)/inc MODGPS = $(OPMODULEDIR)/GPS @@ -106,6 +108,7 @@ DOXYGENDIR = ../Doc/Doxygen ## MODULES SRC = $(MODEXAMPLE)/examplemodevent.c $(MODEXAMPLE)/examplemodperiodic.c $(MODEXAMPLE)/examplemodthread.c +SRC = $(MODSYSTEM)/systemmod.c SRC += $(MODTELEMETRY)/telemetry.c SRC += $(MODGPS)/GPS.c $(MODGPS)/buffer.c @@ -130,6 +133,7 @@ SRC += $(OPUAVOBJ)/eventdispatcher.c SRC += $(OPUAVOBJ)/exampleobject1.c SRC += $(OPUAVOBJ)/exampleobject2.c SRC += $(OPUAVOBJ)/examplesettings.c +SRC += $(OPUAVOBJ)/settingspersistence.c ## PIOS Hardware (STM32F10x) SRC += $(PIOSSTM32F10X)/pios_sys.c @@ -245,6 +249,7 @@ EXTRAINCDIRS += $(OPUAVOBJ) EXTRAINCDIRS += $(OPUAVOBJINC) EXTRAINCDIRS += $(MODEXAMPLE) EXTRAINCDIRS += $(MODEXAMPLEINC) +EXTRAINCDIRS += $(MODSYSTEMINC) EXTRAINCDIRS += $(MODTELEMETRY) EXTRAINCDIRS += $(MODTELEMETRYINC) EXTRAINCDIRS += $(MODGPS) diff --git a/flight/OpenPilot/Modules/System/inc/systemmod.h b/flight/OpenPilot/Modules/System/inc/systemmod.h new file mode 100644 index 000000000..8a0dc8dfb --- /dev/null +++ b/flight/OpenPilot/Modules/System/inc/systemmod.h @@ -0,0 +1,34 @@ +/** + ****************************************************************************** + * + * @file systemmod.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief System module + * + * @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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef SYSTEM_H +#define SYSTEM_H + +#include "openpilot.h" + +int32_t SystemModInitialize(void); + +#endif // SYSTEM_H + diff --git a/flight/OpenPilot/Modules/System/systemmod.c b/flight/OpenPilot/Modules/System/systemmod.c new file mode 100644 index 000000000..96a1eb960 --- /dev/null +++ b/flight/OpenPilot/Modules/System/systemmod.c @@ -0,0 +1,76 @@ +/** + ****************************************************************************** + * + * @file systemmod.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief System module + * + * @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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "systemmod.h" +#include "settingspersistence.h" + +// Private constants + +// Private types + +// Private variables + +// Private functions +static void ObjectUpdatedCb(UAVObjEvent* ev); + +/** + * Initialise the module, called on startup. + * \returns 0 on success or -1 if initialisation failed + */ +int32_t SystemModInitialize(void) +{ + // Listen for ExampleObject1 updates, connect a callback function + SettingsPersistenceConnectCallback(&ObjectUpdatedCb); + + return 0; +} + +/** + * Function called in response to object updates + */ +static void ObjectUpdatedCb(UAVObjEvent* ev) +{ + SettingsPersistenceData setper; + + // If the object updated was the SettingsPersistence execute requested action + if ( ev->obj == SettingsPersistenceHandle() ) + { + // Get object data + SettingsPersistenceGet(&setper); + + // Execute action + if ( setper.Operation == SETTINGSPERSISTENCE_OPERATION_LOAD) + { + UAVObjLoadSettings(); + } + else if ( setper.Operation == SETTINGSPERSISTENCE_OPERATION_SAVE) + { + UAVObjSaveSettings(); + } + } +} + + diff --git a/flight/OpenPilot/UAVObjects/inc/settingspersistence.h b/flight/OpenPilot/UAVObjects/inc/settingspersistence.h new file mode 100644 index 000000000..b8f66573b --- /dev/null +++ b/flight/OpenPilot/UAVObjects/inc/settingspersistence.h @@ -0,0 +1,73 @@ +/** + ****************************************************************************** + * + * @file settingspersistence.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SettingsPersistence object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: settingspersistence.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SETTINGSPERSISTENCE_H +#define SETTINGSPERSISTENCE_H + +#include "openpilot.h" + +// Object constants +#define SETTINGSPERSISTENCE_OBJID 3652432370U +#define SETTINGSPERSISTENCE_NAME "SettingsPersistence" +#define SETTINGSPERSISTENCE_ISSINGLEINST 1 +#define SETTINGSPERSISTENCE_ISSETTINGS 0 +#define SETTINGSPERSISTENCE_NUMBYTES sizeof(SettingsPersistenceData) + +// Object access macros +#define SettingsPersistenceGet(dataOut) UAVObjGetData(SettingsPersistenceHandle(), dataOut) +#define SettingsPersistenceSet(dataIn) UAVObjSetData(SettingsPersistenceHandle(), dataIn) +#define SettingsPersistenceInstGet(instId, dataOut) UAVObjGetInstanceData(SettingsPersistenceHandle(), instId, dataOut) +#define SettingsPersistenceInstSet(instId, dataIn) UAVObjSetInstanceData(SettingsPersistenceHandle(), instId, dataIn) +#define SettingsPersistenceConnectQueue(queue) UAVObjConnectQueue(SettingsPersistenceHandle(), queue, EV_MASK_ALL_UPDATES) +#define SettingsPersistenceConnectCallback(cb) UAVObjConnectCallback(SettingsPersistenceHandle(), cb, EV_MASK_ALL_UPDATES) +#define SettingsPersistenceCreateInstance() UAVObjCreateInstance(SettingsPersistenceHandle()) +#define SettingsPersistenceRequestUpdate() UAVObjRequestUpdate(SettingsPersistenceHandle()) +#define SettingsPersistenceRequestInstUpdate(instId) UAVObjRequestInstanceUpdate(SettingsPersistenceHandle(), instId) +#define SettingsPersistenceUpdated() UAVObjUpdated(SettingsPersistenceHandle()) +#define SettingsPersistenceInstUpdated(instId) UAVObjUpdated(SettingsPersistenceHandle(), instId) +#define SettingsPersistenceGetMetadata(dataOut) UAVObjGetMetadata(SettingsPersistenceHandle(), dataOut) +#define SettingsPersistenceSetMetadata(dataIn) UAVObjSetMetadata(SettingsPersistenceHandle(), dataIn) + +// Object data +typedef struct { + uint8_t Operation; + +} __attribute__((packed)) SettingsPersistenceData; + +// Enumeration types +typedef enum { SETTINGSPERSISTENCE_OPERATION_LOAD=0, SETTINGSPERSISTENCE_OPERATION_SAVE=1, } SETTINGSPERSISTENCEOPERATIONEnum; + + +// Generic interface functions +int32_t SettingsPersistenceInitialize(); +UAVObjHandle SettingsPersistenceHandle(); + +#endif // SETTINGSPERSISTENCE_H diff --git a/flight/OpenPilot/UAVObjects/inc/uavobjectmanager.h b/flight/OpenPilot/UAVObjects/inc/uavobjectmanager.h index 36123d3e5..b05be0987 100644 --- a/flight/OpenPilot/UAVObjects/inc/uavobjectmanager.h +++ b/flight/OpenPilot/UAVObjects/inc/uavobjectmanager.h @@ -108,6 +108,8 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId); int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId); int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file); UAVObjHandle UAVObjLoadFromFile(FILEINFO* file); +int32_t UAVObjSaveSettings(); +int32_t UAVObjLoadSettings(); int32_t UAVObjSetData(UAVObjHandle obj, const void* dataIn); int32_t UAVObjGetData(UAVObjHandle obj, void* dataOut); int32_t UAVObjSetInstanceData(UAVObjHandle obj, uint16_t instId, const void* dataIn); diff --git a/flight/OpenPilot/UAVObjects/settingspersistence.c b/flight/OpenPilot/UAVObjects/settingspersistence.c new file mode 100644 index 000000000..11ac1fc22 --- /dev/null +++ b/flight/OpenPilot/UAVObjects/settingspersistence.c @@ -0,0 +1,73 @@ +/** + ****************************************************************************** + * + * @file settingspersistence.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SettingsPersistence object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: settingspersistence.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "settingspersistence.h" + +// Private variables +static UAVObjHandle handle; + +/** + * Initialize object. + * \return 0 Success + * \return -1 Failure + */ +int32_t SettingsPersistenceInitialize() +{ + UAVObjMetadata metadata; + + // Register object with the object manager + handle = UAVObjRegister(SETTINGSPERSISTENCE_OBJID, SETTINGSPERSISTENCE_NAME, 0, SETTINGSPERSISTENCE_ISSINGLEINST, SETTINGSPERSISTENCE_ISSETTINGS, SETTINGSPERSISTENCE_NUMBYTES); + if (handle == 0) return -1; + + // Initialize metadata + metadata.telemetryAcked = 1; + metadata.telemetryUpdateMode = UPDATEMODE_MANUAL; + metadata.telemetryUpdatePeriod = 0; + metadata.gcsTelemetryAcked = 1; + metadata.gcsTelemetryUpdateMode = UPDATEMODE_MANUAL; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.loggingUpdateMode = UPDATEMODE_NEVER; + metadata.loggingUpdatePeriod = 0; + UAVObjSetMetadata(handle, &metadata); + + // Done + return 0; +} + +/** + * Get object handle + */ +UAVObjHandle SettingsPersistenceHandle() +{ + return handle; +} + + diff --git a/flight/OpenPilot/UAVObjects/uavobjectmanager.c b/flight/OpenPilot/UAVObjects/uavobjectmanager.c index b7eb08aec..64cbcd44e 100644 --- a/flight/OpenPilot/UAVObjects/uavobjectmanager.c +++ b/flight/OpenPilot/UAVObjects/uavobjectmanager.c @@ -663,6 +663,67 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId) return 0; } +/** + * Save all settings objects to the SD card. + * @return 0 if success or -1 if failure + */ +int32_t UAVObjSaveSettings() +{ + ObjectList* objEntry; + + // Get lock + xSemaphoreTakeRecursive(mutex, portMAX_DELAY); + + // Save all settings objects + LL_FOREACH(objList, objEntry) + { + // Check if this is a settings object + if ( objEntry->isSettings ) + { + // Save object + if ( UAVObjSave( (UAVObjHandle)objEntry, 0 ) == -1 ) + { + xSemaphoreGiveRecursive(mutex); + return -1; + } + } + } + + // Done + xSemaphoreGiveRecursive(mutex); + return 0; +} + +/** + * Load all settings objects from the SD card. + * @return 0 if success or -1 if failure + */ +int32_t UAVObjLoadSettings() +{ + 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->isSettings ) + { + // Load object + if ( UAVObjLoad( (UAVObjHandle)objEntry, 0 ) == -1 ) + { + xSemaphoreGiveRecursive(mutex); + return -1; + } + } + } + + // Done + xSemaphoreGiveRecursive(mutex); + return 0; +} /** * Set the object data diff --git a/flight/OpenPilot/UAVObjects/uavobjectsinit.c b/flight/OpenPilot/UAVObjects/uavobjectsinit.c index 0e2574a65..f53bbd185 100644 --- a/flight/OpenPilot/UAVObjects/uavobjectsinit.c +++ b/flight/OpenPilot/UAVObjects/uavobjectsinit.c @@ -31,6 +31,7 @@ #include "exampleobject1.h" #include "exampleobject2.h" #include "examplesettings.h" +#include "settingspersistence.h" /** @@ -42,5 +43,6 @@ void UAVObjectsInitializeAll() ExampleObject1Initialize(); ExampleObject2Initialize(); ExampleSettingsInitialize(); + SettingsPersistenceInitialize(); }