1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

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
This commit is contained in:
vassilis 2010-04-10 05:06:19 +00:00 committed by vassilis
parent 715592c832
commit bf792a8058
8 changed files with 326 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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();
}
}
}

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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();
}