diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 41dab3e6..bcba1331 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -175,7 +175,7 @@ void ObjectFactory::produce(void* args) { createScexComponents(q7s::UART_SCEX_DEV, pwrSwitcher, *SdCardManager::instance(), false, power::Switches::PDU1_CH5_SOLAR_CELL_EXP_5V); #endif - createAcsController(true, enableHkSets); + createAcsController(true, enableHkSets, *SdCardManager::instance()); HeaterHandler* heaterHandler; createHeaterComponents(gpioComIF, pwrSwitcher, healthTable, heaterHandler); createThermalController(*heaterHandler, true); diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index b154ac52..118b583e 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -130,6 +130,6 @@ void ObjectFactory::produce(void* args) { createMiscComponents(); createThermalController(*heaterHandler, false); - createAcsController(true, enableHkSets); + createAcsController(true, enableHkSets, *SdCardManager::instance()); satsystem::init(false); } diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index 756dc0af..4956c1d6 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -335,8 +335,9 @@ void ObjectFactory::createScexComponents(std::string uartDev, PowerSwitchIF* pwr scexHandler->connectModeTreeParent(satsystem::payload::SUBSYSTEM); } -AcsController* ObjectFactory::createAcsController(bool connectSubsystem, bool enableHkSets) { - auto acsCtrl = new AcsController(objects::ACS_CONTROLLER, enableHkSets); +AcsController* ObjectFactory::createAcsController(bool connectSubsystem, bool enableHkSets, + SdCardMountedIF& mountedIF) { + auto acsCtrl = new AcsController(objects::ACS_CONTROLLER, enableHkSets, mountedIF); if (connectSubsystem) { acsCtrl->connectModeTreeParent(satsystem::acs::ACS_SUBSYSTEM); } diff --git a/linux/ObjectFactory.h b/linux/ObjectFactory.h index 46baa685..b813d823 100644 --- a/linux/ObjectFactory.h +++ b/linux/ObjectFactory.h @@ -31,7 +31,8 @@ void createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher, void gpioChecker(ReturnValue_t result, std::string output); -AcsController* createAcsController(bool connectSubsystem, bool enableHkSets); +AcsController* createAcsController(bool connectSubsystem, bool enableHkSets, + SdCardMountedIF& mountedIF); PowerController* createPowerController(bool connectSubsystem, bool enableHkSets); } // namespace ObjectFactory diff --git a/mission/acs/defs.h b/mission/acs/defs.h index baed276d..ce308f7c 100644 --- a/mission/acs/defs.h +++ b/mission/acs/defs.h @@ -73,6 +73,8 @@ static constexpr Event MEKF_INVALID_MODE_VIOLATION = MAKE_EVENT(6, severity::HIG static constexpr Event SAFE_MODE_CONTROLLER_FAILURE = MAKE_EVENT(7, severity::HIGH); //! [EXPORT] : [COMMENT] The TLE for the SGP4 Propagator has become too old. static constexpr Event TLE_TOO_OLD = MAKE_EVENT(8, severity::INFO); +//! [EXPORT] : [COMMENT] The TLE for the SGP4 Propagator has become too old. +static constexpr Event TLE_FILE_READ_FAILED = MAKE_EVENT(9, severity::LOW); extern const char* getModeStr(AcsMode mode); diff --git a/mission/controller/AcsController.cpp b/mission/controller/AcsController.cpp index de226515..7dce604e 100644 --- a/mission/controller/AcsController.cpp +++ b/mission/controller/AcsController.cpp @@ -1,12 +1,9 @@ #include "AcsController.h" -#include -#include -#include - -AcsController::AcsController(object_id_t objectId, bool enableHkSets) +AcsController::AcsController(object_id_t objectId, bool enableHkSets, SdCardMountedIF &sdcMan) : ExtendedControllerBase(objectId), enableHkSets(enableHkSets), + sdcMan(sdcMan), fusedRotationEstimation(&acsParameters), guidance(&acsParameters), safeCtrl(&acsParameters), @@ -1040,8 +1037,11 @@ ReturnValue_t AcsController::updateTle(const uint8_t *line1, const uint8_t *line } ReturnValue_t AcsController::writeTleToFs(const uint8_t *tle) { - // ToDo: check which SD card is active via sdcMan - std::string path = SD_0 + TLE_FILE; + auto mntPrefix = sdcMan.getCurrentMountPrefix(); + if (mntPrefix == nullptr or !sdcMan.isSdCardUsable(std::nullopt)) { + return returnvalue::FAILED; + } + std::string path = mntPrefix + TLE_FILE; // Clear existing TLE from file std::ofstream tleFile(path.c_str(), std::ofstream::out | std::ofstream::trunc); if (tleFile.is_open()) { @@ -1049,27 +1049,34 @@ ReturnValue_t AcsController::writeTleToFs(const uint8_t *tle) { tleFile << "\n"; tleFile.write(reinterpret_cast(tle + 69), 69); } else { - // return error + return WRITE_FILE_FAILED; } tleFile.close(); return returnvalue::OK; } ReturnValue_t AcsController::readTleFromFs(uint8_t *line1, uint8_t *line2) { - // ToDo: check which SD card is active via sdcMan - std::string path = SD_0 + TLE_FILE; - // Read existing TLE from file - std::fstream tleFile = std::fstream(path.c_str(), std::fstream::in); - if (tleFile.is_open()) { - std::string tleLine1, tleLine2; - getline(tleFile, tleLine1); - std::memcpy(line1, tleLine1.c_str(), 69); - getline(tleFile, tleLine2); - std::memcpy(line2, tleLine2.c_str(), 69); - } else { - // return error + auto mntPrefix = sdcMan.getCurrentMountPrefix(); + if (mntPrefix == nullptr or !sdcMan.isSdCardUsable(std::nullopt)) { + return returnvalue::FAILED; + } + std::string path = mntPrefix + TLE_FILE; + std::error_code e; + if (std::filesystem::exists(path, e)) { + // Read existing TLE from file + std::fstream tleFile = std::fstream(path.c_str(), std::fstream::in); + if (tleFile.is_open()) { + std::string tleLine1, tleLine2; + getline(tleFile, tleLine1); + std::memcpy(line1, tleLine1.c_str(), 69); + getline(tleFile, tleLine2); + std::memcpy(line2, tleLine2.c_str(), 69); + } else { + triggerEvent(acs::TLE_FILE_READ_FAILED); + return returnvalue::FAILED; + } + tleFile.close(); } - tleFile.close(); return returnvalue::OK; } diff --git a/mission/controller/AcsController.h b/mission/controller/AcsController.h index 9d91ae10..c2e4790f 100644 --- a/mission/controller/AcsController.h +++ b/mission/controller/AcsController.h @@ -4,15 +4,18 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include +#include #include #include #include @@ -23,15 +26,18 @@ #include #include #include +#include #include +#include #include +#include class AcsController : public ExtendedControllerBase, public ReceivesParameterMessagesIF { public: static constexpr dur_millis_t INIT_DELAY = 500; - AcsController(object_id_t objectId, bool enableHkSets); + AcsController(object_id_t objectId, bool enableHkSets, SdCardMountedIF& sdcMan); MessageQueueId_t getCommandQueue() const; ReturnValue_t getParameter(uint8_t domainId, uint8_t parameterId, @@ -51,6 +57,8 @@ class AcsController : public ExtendedControllerBase, public ReceivesParameterMes bool enableHkSets = false; + SdCardMountedIF& sdcMan; + AcsParameters acsParameters; SensorProcessing sensorProcessing; FusedRotationEstimation fusedRotationEstimation; @@ -93,6 +101,8 @@ class AcsController : public ExtendedControllerBase, public ReceivesParameterMes static const uint8_t INTERFACE_ID = CLASS_ID::ACS_CTRL; //! [EXPORT] : [COMMENT] File deletion failed and at least one file is still existent. static constexpr ReturnValue_t FILE_DELETION_FAILED = MAKE_RETURN_CODE(0); + //! [EXPORT] : [COMMENT] Writing the TLE to the file has failed. + static constexpr ReturnValue_t WRITE_FILE_FAILED = MAKE_RETURN_CODE(1); ReturnValue_t initialize() override; ReturnValue_t handleCommandMessage(CommandMessage* message) override; @@ -131,9 +141,7 @@ class AcsController : public ExtendedControllerBase, public ReceivesParameterMes ReturnValue_t writeTleToFs(const uint8_t* tle); ReturnValue_t readTleFromFs(uint8_t* line1, uint8_t* line2); - const std::string SD_0 = "/mnt/sd0/"; - const std::string SD_1 = "/mnt/sd1/"; - const std::string TLE_FILE = "conf/tle.txt"; + const std::string TLE_FILE = "/conf/tle.txt"; /* ACS Sensor Values */ ACS::SensorValues sensorValues;