Worked on config file handler, added all functions
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
petriVM18 2022-06-07 09:54:52 +02:00
parent c413d90b88
commit 74b38a6d06
8 changed files with 236 additions and 0 deletions

View File

@ -2,6 +2,7 @@ target_sources(${OBSW_NAME} PUBLIC
InitMission.cpp
main.cpp
ObjectFactory.cpp
GlobalConfigHandler.cpp
)
add_subdirectory(fsfwconfig)

View File

@ -0,0 +1,156 @@
/*
* GlobalConfigHandler.cpp
*
* Created on: May 3, 2022
* Author: metobs
*/
#include "GlobalConfigHandler.h"
#include <fsfw/ipc/MutexFactory.h>
#include "fsfw/serviceinterface/ServiceInterface.h"
MutexIF* GlobalConfigHandler::configLock = nullptr;
GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): SystemObject(objectId), NVMParameterBase(configFilePath){
if (configLock == nullptr) {
configLock = MutexFactory::instance()->createMutex();
}
}
ReturnValue_t GlobalConfigHandler::initialize(){
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
result = ReadConfigFile();
if(result!=RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl;
#endif
result=ResetConfigFile();
if (result != RETURN_OK) {
return result;
}
}
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::initialize success " << std::endl;
#endif
return result;
}
GlobalConfigHandler::~GlobalConfigHandler() {
}
ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) {
ReturnValue_t result = RETURN_OK;
sif::debug<<"GlobalConfigHandler::performOperation"<<std::endl;
return result;
}
ReturnValue_t GlobalConfigHandler::lockConfigFile(){
ReturnValue_t result = RETURN_OK;
result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 0);
return result;
}
ReturnValue_t GlobalConfigHandler::unlockConfigFile(){
ReturnValue_t result = RETURN_OK;
result=configLock->unlockMutex();
return result;
}
//TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock
//Use template functions for different data types
ReturnValue_t GlobalConfigHandler::setConfigFileValue(){
ReturnValue_t result = RETURN_OK;
return result;
}
ReturnValue_t GlobalConfigHandler::getConfigFileValue(){
ReturnValue_t result = RETURN_OK;
return result;
}
ReturnValue_t GlobalConfigHandler::insertConfigFileValue(){
ReturnValue_t result = RETURN_OK;
return result;
}
ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){
ReturnValue_t result = RETURN_OK;
result=lockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::resetConfigFileValues lock mutex failed with " << result << std::endl;
#endif
return result;
}
insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT);
insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT);
result=unlockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::resetConfigFileValues unlock mutex failed with " << result << std::endl;
#endif
return result;
}
return result;
}
ReturnValue_t GlobalConfigHandler::WriteConfigFile(){
ReturnValue_t result = RETURN_OK;
ReturnValue_t resultWrite = RETURN_OK;
result=lockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::WriteConfigFile lock mutex failed with " << result << std::endl;
#endif
return result;
}
resultWrite =writeJsonFile();
if(resultWrite!=RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << result << std::endl;
#endif
}
result=unlockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::WriteConfigFile unlock mutex failed with " << result << std::endl;
#endif
return result;
}
return resultWrite;
}
ReturnValue_t GlobalConfigHandler::ReadConfigFile(){
ReturnValue_t result = RETURN_OK;
ReturnValue_t resultRead = RETURN_OK;
result=lockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::ReadConfigFile lock mutex failed with " << result << std::endl;
#endif
return result;
}
resultRead=readJsonFile();
if(resultRead!=RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << result << std::endl;
#endif
}
result=unlockConfigFile();
if (result!= RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::ReadConfigFile unlock mutex failed with " << result << std::endl;
#endif
return result;
}
return resultRead;
}
ReturnValue_t GlobalConfigHandler::ResetConfigFile(){
ReturnValue_t result = RETURN_OK;
resetConfigFileValues();
result =writeJsonFile();
return result;
}

View File

@ -0,0 +1,63 @@
/*
* GlobalConfigHandler.h
*
* Created on: May 3, 2022
* Author: metobs
*/
#ifndef BSP_LINUX_GLOBALCONFIGHANDLER_H_
#define BSP_LINUX_GLOBALCONFIGHANDLER_H_
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/storagemanager/StorageManagerIF.h>
#include <fsfw/tasks/ExecutableObjectIF.h>
#include <sstream>
#include <string>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include "mission/memory/NVMParameterBase.h"
#include "OBSWConfig.h"
static constexpr double PARAM0_DEFAULT = 5.0;
static constexpr double PARAM1_DEFAULT = 905.0;
enum ParamIds : uint8_t {
PARAM0 = 0,
PARAM1 = 1,
};
static std::map<ParamIds, std::string> PARAM_KEY_MAP = {
{PARAM0, "Parameter0"},
{PARAM1, "Parameter1"},
};
/*
* Idea: This class is intended to be used as a subclass for the Core Controller.
* Its tasks is managing a configuration JSON file containing config values important for various object.
* If some function to read or write a config value is called, a mutex should be used so only one call is done at a time.
*/
class GlobalConfigHandler: public SystemObject, public ExecutableObjectIF, public NVMParameterBase{
public:
GlobalConfigHandler(object_id_t objectId, std::string configFilePath);
virtual ~GlobalConfigHandler();
ReturnValue_t performOperation(uint8_t operationCode);
ReturnValue_t initialize();
ReturnValue_t lockConfigFile();
ReturnValue_t unlockConfigFile();
ReturnValue_t setConfigFileValue();
ReturnValue_t getConfigFileValue();
ReturnValue_t insertConfigFileValue();
ReturnValue_t resetConfigFileValues();
ReturnValue_t WriteConfigFile();
ReturnValue_t ReadConfigFile();
ReturnValue_t ResetConfigFile();
private:
std::string configFilePath;
static MutexIF* configLock ;
};
#endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */

View File

@ -138,6 +138,15 @@ void initmission::initTasks() {
}
#endif /* OBSW_ADD_TEST_CODE == 1 */
PeriodicTaskIF* configTask = factory->createPeriodicTask(
"CONFIG_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = configTask->addComponent(objects::CONFIG_TEST);
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("CONFIG_TASK", objects::CONFIG_TEST);
}
sif::info << "Starting tasks.." << std::endl;
tmTcDistributor->startTask();
tmtcBridgeTask->startTask();
@ -148,6 +157,7 @@ void initmission::initTasks() {
pusHighPrio->startTask();
pusMedPrio->startTask();
pusLowPrio->startTask();
configTask->startTask();
#if OBSW_ADD_TEST_CODE == 1
testTask->startTask();

View File

@ -24,6 +24,8 @@
#include <test/testtasks/TestTask.h>
#endif
#include "GlobalConfigHandler.h"
void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR;
PusServiceBase::packetDestination = objects::TM_FUNNEL;
@ -44,4 +46,5 @@ void ObjectFactory::produce(void* args) {
ObjectFactory::produceGenericObjects();
new TestTask(objects::TEST_TASK);
new GlobalConfigHandler(objects::CONFIG_TEST,"/path/to/JSON.config");
}

View File

@ -21,6 +21,7 @@ enum sourceObjects : uint32_t {
/* Test Task */
TEST_TASK = 0x42694269,
CONFIG_TEST = 0x42694270,
DUMMY_INTERFACE = 0xCAFECAFE,
DUMMY_HANDLER = 0x4400AFFE,

View File

@ -23,6 +23,7 @@ int main(void) {
<< " v" << common::OBSW_VERSION << " | FSFW v" << fsfw::FSFW_VERSION << " --"
<< std::endl;
std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl;
std::cout << "-- " <<" BSP HOSTED"<< " --" << std::endl;
initmission::initMission();

View File

@ -59,6 +59,7 @@ enum sourceObjects : uint32_t {
/* 0x54 ('T') for test handlers */
TEST_TASK = 0x54694269,
CONFIG_TEST = 0x54694270,
LIBGPIOD_TEST = 0x54123456,
SPI_TEST = 0x54000010,
UART_TEST = 0x54000020,