Added parameter interface to config file handler
EIVE/eive-obsw/pipeline/head There was a failure building this commit Details

This commit is contained in:
petriVM18 2022-06-08 11:08:19 +02:00
parent 7cd048b03f
commit 8b6992df6d
2 changed files with 143 additions and 4 deletions

View File

@ -8,9 +8,16 @@
#include "GlobalConfigHandler.h"
#include <fsfw/ipc/MutexFactory.h>
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <fsfw/ipc/MessageQueueIF.h>
#include <fsfw/ipc/QueueFactory.h>
MutexIF* GlobalConfigHandler::configLock = nullptr;
GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): SystemObject(objectId), NVMParameterBase(configFilePath){
GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath):
SystemObject(objectId),
NVMParameterBase(configFilePath),
parameterHelper(this),
commandQueue(QueueFactory::instance()->createMessageQueue(20)),
actionHelper(this, commandQueue){
if (configLock == nullptr) {
configLock = MutexFactory::instance()->createMutex();
}
@ -22,6 +29,12 @@ ReturnValue_t GlobalConfigHandler::initialize(){
if (result != RETURN_OK) {
return result;
}
result = actionHelper.initialize(commandQueue);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = ReadConfigFile();
if(result!=RETURN_OK){
#if OBSW_VERBOSE_LEVEL >= 1
@ -32,6 +45,15 @@ ReturnValue_t GlobalConfigHandler::initialize(){
return result;
}
}
result = parameterHelper.initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::initialize: parameterHelper init failed with " << result << std::endl;
#endif
return result;
}
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::initialize success " << std::endl;
#endif
@ -44,9 +66,23 @@ GlobalConfigHandler::~GlobalConfigHandler() {
ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) {
ReturnValue_t result = RETURN_OK;
sif::debug<<"GlobalConfigHandler::performOperation"<<std::endl;
readCommandQueue();
return result;
}
void GlobalConfigHandler::readCommandQueue(){
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result != RETURN_OK) {
return;
}
result = parameterHelper.handleParameterMessage(&command);
if (result == RETURN_OK) {
return;
}
}
ReturnValue_t GlobalConfigHandler::lockConfigFile(){
ReturnValue_t result = RETURN_OK;
result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 0);
@ -244,3 +280,78 @@ std::string GlobalConfigHandler::getConfigFileName(){
return getFullName();
}
ReturnValue_t GlobalConfigHandler::getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues,
uint16_t startAtIndex) {
ReturnValue_t result = RETURN_OK;
switch(uniqueId){
case(ParamIds::PARAM0):{
result=handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast<ParamIds>(uniqueId)],
parameterWrapper, newValues);
break;
}
case(ParamIds::PARAM1):{
result=handleIntParamUpdate(PARAM_KEY_MAP[static_cast<ParamIds>(uniqueId)],
parameterWrapper, newValues);
break;
}
default:{
result=RETURN_FAILED;
break;
}
}
return result;
}
//Taken from payloadPCDU Handler Definition
ReturnValue_t GlobalConfigHandler::handleDoubleParamUpdate(std::string key,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues) {
double newValue = 0.0;
ReturnValue_t result = newValues->getElement<double>(&newValue, 0, 0);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result=setConfigFileValue(key, newValue);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// Do this so the dumping and loading with the framework works as well
doubleDummy = newValue;
parameterWrapper->set(doubleDummy);
return WriteConfigFile();
}
ReturnValue_t GlobalConfigHandler::handleIntParamUpdate(std::string key,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues) {
int newValue = 0;
ReturnValue_t result = newValues->getElement<int>(&newValue, 0, 0);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result=setConfigFileValue(key, newValue);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// Do this so the dumping and loading with the framework works as well
intDummy = newValue;
parameterWrapper->set(intDummy);
return WriteConfigFile();
}
MessageQueueId_t GlobalConfigHandler::getCommandQueue() const{
return commandQueue->getId();
}
ReturnValue_t GlobalConfigHandler::executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data,
size_t size) {
return RETURN_FAILED;
}

View File

@ -16,9 +16,13 @@
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include "mission/memory/NVMParameterBase.h"
#include "OBSWConfig.h"
#include "fsfw/parameters/HasParametersIF.h"
#include "fsfw/parameters/ParameterHelper.h"
#include <fsfw/action/ActionHelper.h>
#include <fsfw/action/HasActionsIF.h>
static constexpr double PARAM0_DEFAULT = 5.0;
static constexpr double PARAM1_DEFAULT = 905.0;
static constexpr int PARAM1_DEFAULT = 905;
enum ParamIds : uint8_t {
PARAM0 = 0,
@ -35,7 +39,11 @@ static std::map<ParamIds, std::string> PARAM_KEY_MAP = {
* 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{
class GlobalConfigHandler: public SystemObject,
public ExecutableObjectIF,
public NVMParameterBase,
public ReceivesParameterMessagesIF,
public HasActionsIF{
public:
GlobalConfigHandler(object_id_t objectId, std::string configFilePath);
virtual ~GlobalConfigHandler();
@ -49,6 +57,7 @@ public:
static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM);
ReturnValue_t performOperation(uint8_t operationCode);
void readCommandQueue();
ReturnValue_t initialize();
ReturnValue_t lockConfigFile();
@ -64,11 +73,30 @@ public:
ReturnValue_t setConfigFileName(std::string configFileName);
std::string getConfigFileName();
ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues,
uint16_t startAtIndex);
ReturnValue_t handleDoubleParamUpdate(std::string key,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues);
ReturnValue_t handleIntParamUpdate(std::string key,
ParameterWrapper* parameterWrapper,
const ParameterWrapper* newValues) ;
MessageQueueId_t getCommandQueue() const override;
ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data,
size_t size) override;
private:
static MutexIF* configLock ;
ParameterHelper parameterHelper;
MessageQueueIF* commandQueue;
ActionHelper actionHelper;
double doubleDummy = 0.0;
int intDummy = 0;
};
#endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */