From 3be9cae8a5aaae8e3d57fe94685283516881f55d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 16 Nov 2023 16:57:36 +0100 Subject: [PATCH 1/7] variable cfg path --- bsp_q7s/CMakeLists.txt | 1 + bsp_q7s/acs/CMakeLists.txt | 1 + bsp_q7s/acs/StrConfigPathGetter.h | 23 +++++++++++++++++++++++ bsp_q7s/em/emObjectFactory.cpp | 2 +- bsp_q7s/fmObjectFactory.cpp | 2 +- bsp_q7s/objectFactory.cpp | 6 ++++-- bsp_q7s/objectFactory.h | 4 +++- mission/acs/str/ArcsecJsonParamBase.cpp | 2 +- mission/acs/str/ArcsecJsonParamBase.h | 2 +- mission/acs/str/StarTrackerHandler.cpp | 18 ++++++++++++------ mission/acs/str/StarTrackerHandler.h | 8 +++++--- mission/acs/str/strHelpers.h | 6 ++++++ 12 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 bsp_q7s/acs/CMakeLists.txt create mode 100644 bsp_q7s/acs/StrConfigPathGetter.h diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index e3232363..0a1a9434 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -25,3 +25,4 @@ add_subdirectory(memory) add_subdirectory(callbacks) add_subdirectory(xadc) add_subdirectory(fs) +add_subdirectory(acs) diff --git a/bsp_q7s/acs/CMakeLists.txt b/bsp_q7s/acs/CMakeLists.txt new file mode 100644 index 00000000..87bf46f2 --- /dev/null +++ b/bsp_q7s/acs/CMakeLists.txt @@ -0,0 +1 @@ +# target_sources(${OBSW_NAME} PUBLIC ) diff --git a/bsp_q7s/acs/StrConfigPathGetter.h b/bsp_q7s/acs/StrConfigPathGetter.h new file mode 100644 index 00000000..58d6964c --- /dev/null +++ b/bsp_q7s/acs/StrConfigPathGetter.h @@ -0,0 +1,23 @@ +#include + +#include "bsp_q7s/fs/SdCardManager.h" +#include "mission/acs/str/strHelpers.h" + +class StrConfigPathGetter : public startracker::SdCardConfigPathGetter { + public: + StrConfigPathGetter(SdCardManager& sdcMan) : sdcMan(sdcMan) {} + + std::optional getCfgPath() override { + if (!sdcMan.isSdCardUsable(std::nullopt)) { + return std::nullopt; + } + if (sdcMan.getActiveSdCard() == sd::SdCard::SLOT_1) { + return std::string("/mnt/sd1/startracker/flight-config.json"); + } else { + return std::string("/mnt/sd0/startracker/flight-config.json"); + } + } + + private: + SdCardManager& sdcMan; +}; diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 41dab3e6..65456d1e 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -152,7 +152,7 @@ void ObjectFactory::produce(void* args) { #endif #if OBSW_ADD_STAR_TRACKER == 1 - createStrComponents(pwrSwitcher); + createStrComponents(pwrSwitcher, *SdCardManager::instance()); #endif /* OBSW_ADD_STAR_TRACKER == 1 */ #if OBSW_ADD_PL_PCDU == 1 diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index b154ac52..05704abf 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -109,7 +109,7 @@ void ObjectFactory::produce(void* args) { createPayloadComponents(gpioComIF, *pwrSwitcher); #if OBSW_ADD_STAR_TRACKER == 1 - createStrComponents(pwrSwitcher); + createStrComponents(pwrSwitcher, *SdCardManager::instance()); #endif /* OBSW_ADD_STAR_TRACKER == 1 */ #if OBSW_ADD_CCSDS_IP_CORES == 1 diff --git a/bsp_q7s/objectFactory.cpp b/bsp_q7s/objectFactory.cpp index eadf70c6..f561e0f5 100644 --- a/bsp_q7s/objectFactory.cpp +++ b/bsp_q7s/objectFactory.cpp @@ -37,6 +37,7 @@ #include #include "OBSWConfig.h" +#include "bsp_q7s/acs/StrConfigPathGetter.h" #include "bsp_q7s/boardtest/Q7STestTask.h" #include "bsp_q7s/callbacks/gnssCallback.h" #include "bsp_q7s/callbacks/pcduSwitchCb.h" @@ -935,7 +936,7 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) { #endif } -void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher) { +void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher, SdCardManager& sdcMan) { auto* strAssy = new StrAssembly(objects::STR_ASSY); strAssy->connectModeTreeParent(satsystem::acs::ACS_SUBSYSTEM); auto* starTrackerCookie = @@ -949,9 +950,10 @@ void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher) { sif::error << "No valid Star Tracker parameter JSON file" << std::endl; } auto strFdir = new StrFdir(objects::STAR_TRACKER); + auto cfgGetter = new StrConfigPathGetter(sdcMan); auto starTracker = new StarTrackerHandler(objects::STAR_TRACKER, objects::STR_COM_IF, starTrackerCookie, - paramJsonFile, strComIF, power::PDU1_CH2_STAR_TRACKER_5V); + strComIF, power::PDU1_CH2_STAR_TRACKER_5V, *cfgGetter); starTracker->setPowerSwitcher(pwrSwitcher); starTracker->connectModeTreeParent(*strAssy); starTracker->setCustomFdir(strFdir); diff --git a/bsp_q7s/objectFactory.h b/bsp_q7s/objectFactory.h index b3dfa83b..2e10dd71 100644 --- a/bsp_q7s/objectFactory.h +++ b/bsp_q7s/objectFactory.h @@ -15,6 +15,8 @@ #include #include +#include "bsp_q7s/fs/SdCardManager.h" + class LinuxLibgpioIF; class SerialComIF; class SpiComIF; @@ -75,7 +77,7 @@ void createHeaterComponents(GpioIF* gpioIF, PowerSwitchIF* pwrSwitcher, HealthTa HeaterHandler*& heaterHandler); void createImtqComponents(PowerSwitchIF* pwrSwitcher, bool enableHkSets, const char* i2cDev); void createBpxBatteryComponent(bool enableHkSets, const char* i2cDev); -void createStrComponents(PowerSwitchIF* pwrSwitcher); +void createStrComponents(PowerSwitchIF* pwrSwitcher, SdCardManager& sdcMan); void createSolarArrayDeploymentComponents(PowerSwitchIF& pwrSwitcher, GpioIF& gpioIF); void createSyrlinksComponents(PowerSwitchIF* pwrSwitcher); void createPayloadComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF& pwrSwitcher); diff --git a/mission/acs/str/ArcsecJsonParamBase.cpp b/mission/acs/str/ArcsecJsonParamBase.cpp index 58c54d30..704c23af 100644 --- a/mission/acs/str/ArcsecJsonParamBase.cpp +++ b/mission/acs/str/ArcsecJsonParamBase.cpp @@ -65,7 +65,7 @@ void ArcsecJsonParamBase::addSetParamHeader(uint8_t* buffer, uint8_t setId) { *(buffer + 1) = setId; } -ReturnValue_t ArcsecJsonParamBase::init(const std::string filename) { +ReturnValue_t ArcsecJsonParamBase::init(const std::string& filename) { ReturnValue_t result = returnvalue::OK; if (not std::filesystem::exists(filename)) { sif::warning << "ArcsecJsonParamBase::init: JSON file " << filename << " does not exist" diff --git a/mission/acs/str/ArcsecJsonParamBase.h b/mission/acs/str/ArcsecJsonParamBase.h index 4c4a7a90..b855a322 100644 --- a/mission/acs/str/ArcsecJsonParamBase.h +++ b/mission/acs/str/ArcsecJsonParamBase.h @@ -46,7 +46,7 @@ class ArcsecJsonParamBase { * @param return JSON_FILE_NOT_EXISTS if specified file does not exist, otherwise * returnvalue::OK */ - ReturnValue_t init(const std::string filename); + ReturnValue_t init(const std::string& filename); /** * @brief Fills a buffer with a parameter set diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 541301f1..4ca85d56 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -24,8 +24,8 @@ extern "C" { std::atomic_bool JCFG_DONE(false); StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, - const char* jsonFileStr, StrComHandler* strHelper, - power::Switch_t powerSwitch) + StrComHandler* strHelper, power::Switch_t powerSwitch, + startracker::SdCardConfigPathGetter& cfgPathGetter) : DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this), versionSet(this), @@ -57,8 +57,8 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, centroidsSet(this), contrastSet(this), strHelper(strHelper), - paramJsonFile(jsonFileStr), - powerSwitch(powerSwitch) { + powerSwitch(powerSwitch), + cfgPathGetter(cfgPathGetter) { if (comCookie == nullptr) { sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl; } @@ -140,7 +140,13 @@ ReturnValue_t StarTrackerHandler::initialize() { // Spin up a thread to do the JSON initialization, takes 200-250 ms which would // delay whole satellite boot process. jcfgCountdown.resetTimer(); - jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), paramJsonFile.c_str()}; + auto strCfgPath = cfgPathGetter.getCfgPath(); + if (strCfgPath.has_value()) { + jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()}; + } else { + // Simplified FDIR: Just continue as usual.. + JCFG_DONE = true; + } EventManagerIF* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); if (manager == nullptr) { @@ -928,7 +934,7 @@ void StarTrackerHandler::bootFirmware(Mode_t toMode) { } } -void StarTrackerHandler::setUpJsonCfgs(JsonConfigs& cfgs, const char* paramJsonFile) { +void StarTrackerHandler::setUpJsonCfgs(JsonConfigs& cfgs, std::string paramJsonFile) { cfgs.tracking.init(paramJsonFile); cfgs.logLevel.init(paramJsonFile); cfgs.logSubscription.init(paramJsonFile); diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index 3bfdc8fd..9a446065 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -42,8 +42,8 @@ class StarTrackerHandler : public DeviceHandlerBase { * to high to enable the device. */ StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, - const char* jsonFileStr, StrComHandler* strHelper, - power::Switch_t powerSwitch); + StrComHandler* strHelper, power::Switch_t powerSwitch, + startracker::SdCardConfigPathGetter& cfgPathGetter); virtual ~StarTrackerHandler(); ReturnValue_t initialize() override; @@ -244,7 +244,7 @@ class StarTrackerHandler : public DeviceHandlerBase { Countdown jcfgCountdown = Countdown(250); bool commandExecuted = false; std::thread jsonCfgTask; - static void setUpJsonCfgs(JsonConfigs& cfgs, const char* paramJsonFile); + static void setUpJsonCfgs(JsonConfigs& cfgs, std::string paramJsonFile); std::string paramJsonFile; @@ -311,6 +311,8 @@ class StarTrackerHandler : public DeviceHandlerBase { std::set additionalRequestedTm{}; std::set::iterator currentSecondaryTmIter; + startracker::SdCardConfigPathGetter& cfgPathGetter; + /** * @brief Handles internal state */ diff --git a/mission/acs/str/strHelpers.h b/mission/acs/str/strHelpers.h index 808d6060..5337859f 100644 --- a/mission/acs/str/strHelpers.h +++ b/mission/acs/str/strHelpers.h @@ -14,6 +14,12 @@ namespace startracker { static const Submode_t SUBMODE_BOOTLOADER = 1; static const Submode_t SUBMODE_FIRMWARE = 2; +class SdCardConfigPathGetter { + public: + virtual ~SdCardConfigPathGetter() = default; + virtual std::optional getCfgPath() = 0; +}; + /** * @brief Returns the frame type field of a decoded frame. */ From 9010d1d2028b81aa69174848389d87a2351ea62e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 16 Nov 2023 17:07:47 +0100 Subject: [PATCH 2/7] add new command to reload the JSON file --- CHANGELOG.md | 18 +++++++++++++--- mission/acs/str/StarTrackerHandler.cpp | 30 +++++++++++++++++++------- mission/acs/str/StarTrackerHandler.h | 1 + mission/acs/str/strHelpers.h | 1 + 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74bd77e3..7ab784df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,18 @@ will consitute of a breaking change warranting a new major release: # [unreleased] +## Fixed + +- STR config path was previously hardcoded to `/mnt/sd0/startracker/flight-config.json`. + A new abstraction was introduces which now uses the active SD card to build the correct + config path when initializing the star tracker. + +## Added + +- Introduced a new `RELOAD_JSON_CFG_FILE` command for the STR to reload the JSON configuration + data based on the current output of the config file path getter function. A reboot of the + device is still necessary to load the configuration to the STR. + # [v7.3.0] 2023-11-07 ## Changed @@ -696,7 +708,7 @@ This is the version which will fly on the satellite for the initial launch phase This gives other tasks some time to register the SD cards being unusable, and therefore provides a way for them to perform any re-initialization tasks necessary after SD card switches. - TCS controller now only has an OFF mode and an ON mode -- The TCS controller pauses operations related to the TCS board assembly (reading sensors and +- The TCS controller pauses operations related to the TCS board assembly (reading sensors and the primary control loop) while a TCS board recovery is on-going. - Allow specifying custom OBSW update filename. This allowed keeping a cleaner file structure where each update has a name including the version @@ -1761,8 +1773,8 @@ Syrlinks PR: PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/353 - Syrlinks Handler: Read RX frequency shift as 24 bit signed number now. Also include validity handling for datasets. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/350 -- `GyroADIS1650XHandler`: Changed calculation of angular rate to be sensitivity based instead of - max. range based, as previous fix still left an margin of error between ADIS16505 sensors +- `GyroADIS1650XHandler`: Changed calculation of angular rate to be sensitivity based instead of + max. range based, as previous fix still left an margin of error between ADIS16505 sensors and L3GD20 sensors. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/346 diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 4ca85d56..98529b29 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -139,14 +139,7 @@ ReturnValue_t StarTrackerHandler::initialize() { // Spin up a thread to do the JSON initialization, takes 200-250 ms which would // delay whole satellite boot process. - jcfgCountdown.resetTimer(); - auto strCfgPath = cfgPathGetter.getCfgPath(); - if (strCfgPath.has_value()) { - jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()}; - } else { - // Simplified FDIR: Just continue as usual.. - JCFG_DONE = true; - } + reloadJsonCfgFile(); EventManagerIF* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); if (manager == nullptr) { @@ -175,6 +168,18 @@ ReturnValue_t StarTrackerHandler::initialize() { return returnvalue::OK; } +bool StarTrackerHandler::reloadJsonCfgFile() { + jcfgCountdown.resetTimer(); + auto strCfgPath = cfgPathGetter.getCfgPath(); + if (strCfgPath.has_value()) { + jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()}; + return true; + } + // Simplified FDIR: Just continue as usual.. + JCFG_DONE = true; + return false; +} + ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, size_t size) { ReturnValue_t result = returnvalue::OK; @@ -193,6 +198,15 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu addSecondaryTmForNormalMode(idToAdd); return EXECUTION_FINISHED; } + case (startracker::RELOAD_JSON_CFG_FILE): { + // It should be noted that this just reloads the JSON config structure in memory from the + // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve + // this is to simply reboot the device after a reload. + if (reloadJsonCfgFile()) { + return HasActionsIF::EXECUTION_FINISHED; + } + return returnvalue::FAILED; + } case (startracker::RESET_SECONDARY_TM_SET): { resetSecondaryTmSet(); return EXECUTION_FINISHED; diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index 9a446065..24ea55bc 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -544,6 +544,7 @@ class StarTrackerHandler : public DeviceHandlerBase { void doNormalTransition(Mode_t modeFrom, Submode_t subModeFrom); void bootFirmware(Mode_t toMode); void bootBootloader(); + bool reloadJsonCfgFile(); }; #endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */ diff --git a/mission/acs/str/strHelpers.h b/mission/acs/str/strHelpers.h index 5337859f..8f83331d 100644 --- a/mission/acs/str/strHelpers.h +++ b/mission/acs/str/strHelpers.h @@ -387,6 +387,7 @@ static constexpr DeviceCommandId_t REQ_CENTROIDS = 94; static constexpr DeviceCommandId_t ADD_SECONDARY_TM_TO_NORMAL_MODE = 95; static constexpr DeviceCommandId_t RESET_SECONDARY_TM_SET = 96; static constexpr DeviceCommandId_t READ_SECONDARY_TM_SET = 97; +static constexpr DeviceCommandId_t RELOAD_JSON_CFG_FILE = 100; static const DeviceCommandId_t NONE = 0xFFFFFFFF; static const uint32_t VERSION_SET_ID = REQ_VERSION; From 8c51f53a269083bb62bb33cb8490968170ac750f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 12:55:05 +0100 Subject: [PATCH 3/7] bump fsfw --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index cc3e64e7..41d67bff 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit cc3e64e70d90f6a2b5c59215b2569c1771e890f0 +Subproject commit 41d67bff639192afa2e18a23db6801c75b4fea88 From a648b4be37422b82d8a3a89c57ec191fdd5f6fc9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 14:17:19 +0100 Subject: [PATCH 4/7] better thread and startup handling --- mission/acs/str/StarTrackerHandler.cpp | 34 +++++++++++++++++++------- mission/acs/str/StarTrackerHandler.h | 3 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 98529b29..9e7d3b5e 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -82,17 +82,13 @@ void StarTrackerHandler::doStartUp() { // the device handler's submode to the star tracker's mode return; case StartupState::DONE: - if (jcfgCountdown.isBusy()) { + if (!JCFG_DONE) { startupState = StartupState::WAIT_JCFG; return; } startupState = StartupState::IDLE; break; case StartupState::WAIT_JCFG: { - if (jcfgCountdown.hasTimedOut()) { - startupState = StartupState::IDLE; - break; - } return; } default: @@ -172,6 +168,7 @@ bool StarTrackerHandler::reloadJsonCfgFile() { jcfgCountdown.resetTimer(); auto strCfgPath = cfgPathGetter.getCfgPath(); if (strCfgPath.has_value()) { + jcfgPending = true; jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()}; return true; } @@ -199,13 +196,14 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu return EXECUTION_FINISHED; } case (startracker::RELOAD_JSON_CFG_FILE): { + if (jcfgPending) { + return HasActionsIF::IS_BUSY; + } // It should be noted that this just reloads the JSON config structure in memory from the // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve // this is to simply reboot the device after a reload. - if (reloadJsonCfgFile()) { - return HasActionsIF::EXECUTION_FINISHED; - } - return returnvalue::FAILED; + reloadJsonCfgFile(); + return returnvalue::OK; } case (startracker::RESET_SECONDARY_TM_SET): { resetSecondaryTmSet(); @@ -355,6 +353,24 @@ void StarTrackerHandler::performOperationHook() { break; } } + if (jcfgPending) { + if (JCFG_DONE) { + auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); + if (iter != deviceCommandMap.end()) { + if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { + actionHelper.finish(true, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE); + } + } + jsonCfgTask.join(); + jcfgPending = false; + } else if (jcfgCountdown.hasTimedOut()) { + auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); + if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { + actionHelper.finish(false, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE, + returnvalue::FAILED); + } + } + } } Submode_t StarTrackerHandler::getInitialSubmode() { return startracker::SUBMODE_BOOTLOADER; } diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index 24ea55bc..ad37557d 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -240,8 +240,9 @@ class StarTrackerHandler : public DeviceHandlerBase { Subscription subscription; AutoThreshold autoThreshold; }; + bool jcfgPending = false; JsonConfigs jcfgs; - Countdown jcfgCountdown = Countdown(250); + Countdown jcfgCountdown = Countdown(1000); bool commandExecuted = false; std::thread jsonCfgTask; static void setUpJsonCfgs(JsonConfigs& cfgs, std::string paramJsonFile); From f9d2d35f86cd27adccb634ca36f4c2231cc28211 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 14:34:15 +0100 Subject: [PATCH 5/7] this is stupid --- mission/acs/str/StarTrackerHandler.cpp | 41 +++++++++++++------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 9e7d3b5e..0b58d61e 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -169,6 +169,7 @@ bool StarTrackerHandler::reloadJsonCfgFile() { auto strCfgPath = cfgPathGetter.getCfgPath(); if (strCfgPath.has_value()) { jcfgPending = true; + JCFG_DONE = false; jsonCfgTask = std::thread{setUpJsonCfgs, std::ref(jcfgs), strCfgPath.value()}; return true; } @@ -182,6 +183,21 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu ReturnValue_t result = returnvalue::OK; switch (actionId) { + case (startracker::RELOAD_JSON_CFG_FILE): { + if (jcfgPending) { + return HasActionsIF::IS_BUSY; + } + // It should be noted that this just reloads the JSON config structure in memory from the + // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve + // this is to simply reboot the device after a reload. + if(reloadJsonCfgFile()) { + // Could trigger this after the thread has finished, but the base class does not accept + // commands for buildCommandForCommand when it is OFF. I am sure there is way to solve + // this, but I don't care anymore. This is fine. + return HasActionsIF::EXECUTION_FINISHED; + }; + return returnvalue::OK; + } case (startracker::ADD_SECONDARY_TM_TO_NORMAL_MODE): { if (size < 4) { return HasActionsIF::INVALID_PARAMETERS; @@ -195,16 +211,6 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu addSecondaryTmForNormalMode(idToAdd); return EXECUTION_FINISHED; } - case (startracker::RELOAD_JSON_CFG_FILE): { - if (jcfgPending) { - return HasActionsIF::IS_BUSY; - } - // It should be noted that this just reloads the JSON config structure in memory from the - // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve - // this is to simply reboot the device after a reload. - reloadJsonCfgFile(); - return returnvalue::OK; - } case (startracker::RESET_SECONDARY_TM_SET): { resetSecondaryTmSet(); return EXECUTION_FINISHED; @@ -355,20 +361,11 @@ void StarTrackerHandler::performOperationHook() { } if (jcfgPending) { if (JCFG_DONE) { - auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); - if (iter != deviceCommandMap.end()) { - if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { - actionHelper.finish(true, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE); - } - } jsonCfgTask.join(); jcfgPending = false; + JCFG_DONE = false; } else if (jcfgCountdown.hasTimedOut()) { - auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); - if (iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { - actionHelper.finish(false, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE, - returnvalue::FAILED); - } + JCFG_DONE = false; } } } @@ -549,6 +546,7 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi rawPacket = commandBuffer; return returnvalue::OK; } + case (startracker::REQ_TIME): { prepareTimeRequest(); return returnvalue::OK; @@ -762,6 +760,7 @@ void StarTrackerHandler::fillCommandAndReplyMap() { startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandMap(startracker::UPLOAD_IMAGE); this->insertInCommandMap(startracker::DOWNLOAD_IMAGE); + this->insertInCommandMap(startracker::RELOAD_JSON_CFG_FILE); this->insertInCommandAndReplyMap(startracker::REQ_POWER, 3, &powerSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_INTERFACE, 3, &interfaceSet, From cdad099f32e14771209e70204b096b7987d1fc67 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 14:54:21 +0100 Subject: [PATCH 6/7] PLEASE WORK --- mission/acs/str/StarTrackerHandler.cpp | 39 ++++++++++++++++---------- mission/acs/str/StarTrackerHandler.h | 5 +++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 0b58d61e..79f29a7f 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -5,6 +5,8 @@ #include #include +#include "fsfw/ipc/MessageQueueIF.h" + extern "C" { #include #include @@ -183,21 +185,6 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu ReturnValue_t result = returnvalue::OK; switch (actionId) { - case (startracker::RELOAD_JSON_CFG_FILE): { - if (jcfgPending) { - return HasActionsIF::IS_BUSY; - } - // It should be noted that this just reloads the JSON config structure in memory from the - // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve - // this is to simply reboot the device after a reload. - if(reloadJsonCfgFile()) { - // Could trigger this after the thread has finished, but the base class does not accept - // commands for buildCommandForCommand when it is OFF. I am sure there is way to solve - // this, but I don't care anymore. This is fine. - return HasActionsIF::EXECUTION_FINISHED; - }; - return returnvalue::OK; - } case (startracker::ADD_SECONDARY_TM_TO_NORMAL_MODE): { if (size < 4) { return HasActionsIF::INVALID_PARAMETERS; @@ -361,11 +348,21 @@ void StarTrackerHandler::performOperationHook() { } if (jcfgPending) { if (JCFG_DONE) { + sif::debug << "jcfg fucking done" << std::endl; jsonCfgTask.join(); jcfgPending = false; JCFG_DONE = false; + auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); + if (iter != deviceCommandMap.end() and iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { + sif::debug << "jcfg sending finished" << std::endl; + actionHelper.finish(true, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE); + } } else if (jcfgCountdown.hasTimedOut()) { JCFG_DONE = false; + auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); + if (iter != deviceCommandMap.end() and iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { + actionHelper.finish(false, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE); + } } } } @@ -532,6 +529,16 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi preparePingRequest(); return returnvalue::OK; } + case (startracker::RELOAD_JSON_CFG_FILE): { + if (jcfgPending) { + return HasActionsIF::IS_BUSY; + } + // It should be noted that this just reloads the JSON config structure in memory from the + // JSON file. The configuration still needs to be sent to the STR. The easiest way to achieve + // this is to simply reboot the device after a reload. + reloadJsonCfgFile(); + return returnvalue::OK; + } case (startracker::SET_TIME_FROM_SYS_TIME): { SetTimeActionRequest setTimeRequest{}; timeval tv; @@ -2846,3 +2853,5 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { } return returnvalue::OK; } + +ReturnValue_t StarTrackerHandler::acceptExternalDeviceCommands() { return returnvalue::OK; } diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index ad37557d..6bc1ff09 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -27,7 +27,9 @@ extern "C" { * @details Datasheet: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/ * Arbeitsdaten/08_Used%20Components/ArcSec_KULeuven_Startracker/ * Sagitta%201.0%20Datapack&fileid=659181 - * @author J. Meier + * @note The STR code is a chaotic inconsistent mess and should be re-written with a simpler base + * class. DO NOT USE THIS AS REFERENCE. Stay away from it. + * @author J. Meier, R. Mueller */ class StarTrackerHandler : public DeviceHandlerBase { public: @@ -546,6 +548,7 @@ class StarTrackerHandler : public DeviceHandlerBase { void bootFirmware(Mode_t toMode); void bootBootloader(); bool reloadJsonCfgFile(); + ReturnValue_t acceptExternalDeviceCommands() override; }; #endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */ From 518b265b4afacbe73d5750cad071f5cc0f19825b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 21 Nov 2023 15:22:24 +0100 Subject: [PATCH 7/7] remove the printouts, done --- mission/acs/str/StarTrackerHandler.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 79f29a7f..9ad70d41 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -88,7 +88,6 @@ void StarTrackerHandler::doStartUp() { startupState = StartupState::WAIT_JCFG; return; } - startupState = StartupState::IDLE; break; case StartupState::WAIT_JCFG: { return; @@ -348,17 +347,16 @@ void StarTrackerHandler::performOperationHook() { } if (jcfgPending) { if (JCFG_DONE) { - sif::debug << "jcfg fucking done" << std::endl; + if(startupState == StartupState::WAIT_JCFG) { + startupState = StartupState::DONE; + } jsonCfgTask.join(); jcfgPending = false; - JCFG_DONE = false; auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); if (iter != deviceCommandMap.end() and iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { - sif::debug << "jcfg sending finished" << std::endl; actionHelper.finish(true, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE); } } else if (jcfgCountdown.hasTimedOut()) { - JCFG_DONE = false; auto iter = deviceCommandMap.find(startracker::RELOAD_JSON_CFG_FILE); if (iter != deviceCommandMap.end() and iter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) { actionHelper.finish(false, iter->second.sendReplyTo, startracker::RELOAD_JSON_CFG_FILE);