catch exception in NVM param base
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
This commit is contained in:
parent
e1b8debb27
commit
d8240881cc
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit 2d9216ba19f1931225daa5b6b6f244a48c09f1b9
|
||||
Subproject commit 0ccaf27fcb0e7a0f2dd1ca7175a7051a0267c8ec
|
@ -608,7 +608,8 @@ ReturnValue_t PayloadPcduHandler::getParameter(uint8_t domainId, uint8_t uniqueI
|
||||
case (PlPcduParamIds::X8_TO_TX_WAIT_TIME):
|
||||
case (PlPcduParamIds::TX_TO_MPA_WAIT_TIME):
|
||||
case (PlPcduParamIds::MPA_TO_HPA_WAIT_TIME): {
|
||||
handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast<PlPcduParamIds>(uniqueId)], newValues);
|
||||
handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast<PlPcduParamIds>(uniqueId)],
|
||||
parameterWrapper, newValues);
|
||||
break;
|
||||
}
|
||||
case (PlPcduParamIds::INJECT_SSR_TO_DRO_FAILURE): {
|
||||
@ -655,6 +656,7 @@ void PayloadPcduHandler::handleFailureInjection(std::string output, Event event)
|
||||
}
|
||||
|
||||
ReturnValue_t PayloadPcduHandler::handleDoubleParamUpdate(std::string key,
|
||||
ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues) {
|
||||
double newValue = 0.0;
|
||||
ReturnValue_t result = newValues->getElement<double>(&newValue, 0, 0);
|
||||
@ -662,7 +664,10 @@ ReturnValue_t PayloadPcduHandler::handleDoubleParamUpdate(std::string key,
|
||||
return result;
|
||||
}
|
||||
params.setValue(key, newValue);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
// Do this so the dumping and loading with the framework works as well
|
||||
doubleDummy = newValue;
|
||||
parameterWrapper->set(doubleDummy);
|
||||
return params.writeJsonFile();
|
||||
}
|
||||
|
||||
#ifdef FSFW_OSAL_LINUX
|
||||
|
@ -111,6 +111,7 @@ class PayloadPcduHandler : public DeviceHandlerBase {
|
||||
bool adcCmdExecuted = false;
|
||||
bool periodicPrintout = false;
|
||||
bool jsonFileInitComplete = false;
|
||||
double doubleDummy = 0.0;
|
||||
|
||||
bool ssrToDroInjectionRequested = false;
|
||||
bool droToX8InjectionRequested = false;
|
||||
@ -161,7 +162,8 @@ class PayloadPcduHandler : public DeviceHandlerBase {
|
||||
bool checkCurrent(float val, float upperBound, Event event);
|
||||
void handleFailureInjection(std::string output, Event event);
|
||||
ReturnValue_t serializeFloat(uint32_t& param, float val);
|
||||
ReturnValue_t handleDoubleParamUpdate(std::string key, const ParameterWrapper* newValues);
|
||||
ReturnValue_t handleDoubleParamUpdate(std::string key, ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues);
|
||||
};
|
||||
|
||||
#endif /* LINUX_DEVICES_PLPCDUHANDLER_H_ */
|
||||
|
@ -180,6 +180,23 @@ class PlPcduParameter : public NVMParameterBase {
|
||||
PlPcduParameter() : NVMParameterBase(""), mountPrefix("") {
|
||||
using namespace plpcdu;
|
||||
// Initialize with default values
|
||||
resetValues();
|
||||
}
|
||||
|
||||
ReturnValue_t initialize(std::string mountPrefix) {
|
||||
setFullName(mountPrefix + "/conf/plpcdu.json");
|
||||
ReturnValue_t result = readJsonFile();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// File does not exist or reading JSON failed for various reason. Rewrite the JSON file
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "Creating PL PCDU JSON file at " << getFullName() << std::endl;
|
||||
#endif
|
||||
resetValues();
|
||||
writeJsonFile();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
void resetValues() {
|
||||
insertValue(PARAM_KEY_MAP[SSR_TO_DRO_WAIT_TIME], DFT_SSR_TO_DRO_WAIT_TIME);
|
||||
insertValue(PARAM_KEY_MAP[DRO_TO_X8_WAIT_TIME], DFT_DRO_TO_X8_WAIT_TIME);
|
||||
insertValue(PARAM_KEY_MAP[X8_TO_TX_WAIT_TIME], DFT_X8_TO_TX_WAIT_TIME);
|
||||
@ -204,20 +221,6 @@ class PlPcduParameter : public NVMParameterBase {
|
||||
insertValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], DFT_HPA_I_UPPER_BOUND);
|
||||
}
|
||||
|
||||
ReturnValue_t initialize(std::string mountPrefix) {
|
||||
setFullName(mountPrefix + "/conf/plpcdu.json");
|
||||
ReturnValue_t result = readJsonFile();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// File does not exist. Create it. Keys and appropriate init values were
|
||||
// specified in constructor
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "Creating PL PCDU JSON file at " << getFullName() << std::endl;
|
||||
#endif
|
||||
writeJsonFile();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mountPrefix;
|
||||
};
|
||||
|
@ -11,7 +11,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
|
||||
if (std::filesystem::exists(fullName)) {
|
||||
// Read JSON file content into object
|
||||
std::ifstream i(fullName);
|
||||
i >> json;
|
||||
try {
|
||||
i >> json;
|
||||
} catch (nlohmann::json::exception& e) {
|
||||
sif::warning << "Reading JSON file failed with error " << e.what() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
@ -19,7 +24,12 @@ ReturnValue_t NVMParameterBase::readJsonFile() {
|
||||
|
||||
ReturnValue_t NVMParameterBase::writeJsonFile() {
|
||||
std::ofstream o(fullName);
|
||||
o << std::setw(4) << json << std::endl;
|
||||
try {
|
||||
o << std::setw(4) << json << std::endl;
|
||||
} catch (nlohmann::json::exception& e) {
|
||||
sif::warning << "Writing JSON file failed with error " << e.what() << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
2
tmtc
2
tmtc
@ -1 +1 @@
|
||||
Subproject commit a9a6468718e5ecde52a1092eb73ae79c2219a1a0
|
||||
Subproject commit 9fff4a90bcacb04eea64ac2d3456889c05a4b16d
|
Loading…
Reference in New Issue
Block a user