diff --git a/fsfw b/fsfw index 2d9216ba..0ccaf27f 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 2d9216ba19f1931225daa5b6b6f244a48c09f1b9 +Subproject commit 0ccaf27fcb0e7a0f2dd1ca7175a7051a0267c8ec diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 0f6a74e2..12b7d23f 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -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(uniqueId)], newValues); + handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast(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(&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 diff --git a/mission/devices/PayloadPcduHandler.h b/mission/devices/PayloadPcduHandler.h index 1ae43eb4..f9c16090 100644 --- a/mission/devices/PayloadPcduHandler.h +++ b/mission/devices/PayloadPcduHandler.h @@ -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_ */ diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index c9a393ae..28869f35 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.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; }; diff --git a/mission/memory/NVMParameterBase.cpp b/mission/memory/NVMParameterBase.cpp index c7ac7560..78f40525 100644 --- a/mission/memory/NVMParameterBase.cpp +++ b/mission/memory/NVMParameterBase.cpp @@ -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; } diff --git a/tmtc b/tmtc index a9a64687..9fff4a90 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a9a6468718e5ecde52a1092eb73ae79c2219a1a0 +Subproject commit 9fff4a90bcacb04eea64ac2d3456889c05a4b16d