diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d5b030f..6dab4525 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -382,10 +382,8 @@ add_subdirectory(${TEST_PATH}) add_subdirectory(${UNITTEST_PATH}) # This should have already been downloaded by the FSFW Still include it to be -# safe -# find_package(etl ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET) -# Not installed, so use FetchContent to download and provide etl -# if(NOT etl_FOUND) +# safe find_package(etl ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET) Not +# installed, so use FetchContent to download and provide etl if(NOT etl_FOUND) message( STATUS "No ETL installation was found with find_package. Installing and providing " diff --git a/bsp_linux_board/CMakeLists.txt b/bsp_linux_board/CMakeLists.txt index 24e81b42..c1817ac1 100644 --- a/bsp_linux_board/CMakeLists.txt +++ b/bsp_linux_board/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(${OBSW_NAME} PUBLIC InitMission.cpp main.cpp gpioInit.cpp - ObjectFactory.cpp) + ObjectFactory.cpp RPiSdCardManager.cpp) add_subdirectory(boardconfig) add_subdirectory(boardtest) diff --git a/bsp_linux_board/InitMission.cpp b/bsp_linux_board/InitMission.cpp index ec77f668..21cc5c23 100644 --- a/bsp_linux_board/InitMission.cpp +++ b/bsp_linux_board/InitMission.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -78,34 +79,10 @@ void initmission::initTasks() { sif::error << "Add component TMTC Polling failed" << std::endl; } -#if OBSW_ADD_SCEX == 1 - PeriodicTaskIF* scexDevHandler = factory->createPeriodicTask( - "SCEX_DEV", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc); - result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_DEV", objects::SCEX); - } - result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_DEV", objects::SCEX); - } - result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_DEV", objects::SCEX); - } - result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_DEV", objects::SCEX); - } - result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ); - - result = HasReturnvaluesIF::RETURN_OK; - PeriodicTaskIF* scexReaderTask = factory->createPeriodicTask( - "SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); - result = scexReaderTask->addComponent(objects::SCEX_UART_READER); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); - } +#if OBSW_ADD_SCEX_DEVICE == 1 + PeriodicTaskIF* scexDevHandler; + PeriodicTaskIF* scexReaderTask; + scheduling::schedulingScex(*factory, scexDevHandler, scexReaderTask); #endif /* PUS Services */ @@ -140,7 +117,7 @@ void initmission::initTasks() { #endif /* OBSW_ADD_TEST_CODE == 1 */ taskStarter(pstTasks, "PST Tasks"); -#if OBSW_ADD_SCEX == 1 +#if OBSW_ADD_SCEX_DEVICE == 1 scexDevHandler->startTask(); scexReaderTask->startTask(); #endif @@ -229,9 +206,9 @@ void initmission::createPstTasks(TaskFactory& factory, FixedTimeslotTaskIF* spiPst = factory.createFixedTimeslotTask( "SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { if (result != FixedTimeslotTaskIF::SLOT_LIST_EMPTY) { - sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; + sif::error << "InitMission::createPstTasks: Creating PST failed!" << std::endl; } } else { taskVec.push_back(spiPst); @@ -269,7 +246,7 @@ void initmission::createTestTasks(TaskFactory& factory, PeriodicTaskIF* scexReaderTask = factory.createPeriodicTask( "SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); result = scexReaderTask->addComponent(objects::SCEX_UART_READER); - if (result != HasReturnvaluesIF::RETURN_OK) { + if (result != returnvalue::OK) { initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); } taskVec.push_back(scexReaderTask); diff --git a/bsp_linux_board/OBSWConfig.h.in b/bsp_linux_board/OBSWConfig.h.in index 398cf19e..f17c3d48 100644 --- a/bsp_linux_board/OBSWConfig.h.in +++ b/bsp_linux_board/OBSWConfig.h.in @@ -28,7 +28,7 @@ #define OBSW_ADD_RTD_DEVICES 0 #define OBSW_ADD_PL_PCDU 0 #define OBSW_ADD_TMP_DEVICES 0 -#define OBSW_ADD_SCEX 1 +#define OBSW_ADD_SCEX_DEVICE 1 #define OBSW_ADD_RAD_SENSORS 0 #define OBSW_ADD_SYRLINKS 0 #define OBSW_STAR_TRACKER_GROUND_CONFIG 1 diff --git a/bsp_linux_board/ObjectFactory.cpp b/bsp_linux_board/ObjectFactory.cpp index 19a00647..075d1af6 100644 --- a/bsp_linux_board/ObjectFactory.cpp +++ b/bsp_linux_board/ObjectFactory.cpp @@ -1,5 +1,6 @@ #include "ObjectFactory.h" +#include #include #include "OBSWConfig.h" @@ -47,8 +48,8 @@ #include "fsfw_hal/linux/spi/SpiCookie.h" void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; - PusServiceBase::packetDestination = objects::TM_FUNNEL; + PusServiceBase::PUS_DISTRIBUTOR = objects::PUS_PACKET_DISTRIBUTOR; + PusServiceBase::PACKET_DESTINATION = objects::TM_FUNNEL; CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR; CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; @@ -56,9 +57,6 @@ void Factory::setStaticFrameworkObjectIds() { TmFunnel::downlinkDestination = objects::TMTC_BRIDGE; // No storage object for now. TmFunnel::storageDestination = objects::NO_OBJECT; - - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - TmPacketBase::timeStamperId = objects::TIME_STAMPER; } void ObjectFactory::produce(void* args) { @@ -84,8 +82,9 @@ void ObjectFactory::produce(void* args) { #endif #endif -#if OBSW_ADD_SCEX == 1 - createScexComponents(uart::DEV, pwrSwitcher); +#if OBSW_ADD_SCEX_DEVICE == 1 + auto* sdcMan = new RPiSdCardManager("/tmp"); + createScexComponents(uart::DEV, pwrSwitcher, *sdcMan, true, std::nullopt); #endif #if OBSW_ADD_SUN_SENSORS == 1 @@ -202,8 +201,7 @@ void ObjectFactory::createTestTasks() { #endif #if OBSW_ADD_UART_TEST_CODE == 1 - auto scexReader = new ScexUartReader(objects::SCEX_UART_READER); - new UartTestClass(objects::UART_TEST, scexReader); + new UartTestClass(objects::UART_TEST); #else new UartComIF(objects::UART_COM_IF); #endif diff --git a/bsp_linux_board/RPiSdCardManager.cpp b/bsp_linux_board/RPiSdCardManager.cpp new file mode 100644 index 00000000..ccb4f3a9 --- /dev/null +++ b/bsp_linux_board/RPiSdCardManager.cpp @@ -0,0 +1,13 @@ +#include "RPiSdCardManager.h" + +RPiSdCardManager::RPiSdCardManager(std::string prefix) : prefix(std::move(prefix)) {} + +const std::string& RPiSdCardManager::getCurrentMountPrefix() const { return prefix; } + +bool RPiSdCardManager::isSdCardMounted(sd::SdCard sdCard) { return true; } + +std::optional RPiSdCardManager::getPreferredSdCard() const { return std::nullopt; } + +void RPiSdCardManager::setActiveSdCard(sd::SdCard sdCard) {} + +std::optional RPiSdCardManager::getActiveSdCard() const { return std::nullopt; } diff --git a/bsp_linux_board/RPiSdCardManager.h b/bsp_linux_board/RPiSdCardManager.h new file mode 100644 index 00000000..28413815 --- /dev/null +++ b/bsp_linux_board/RPiSdCardManager.h @@ -0,0 +1,18 @@ +#ifndef BSP_LINUX_BOARD_RPISDCARDMANAGER_H_ +#define BSP_LINUX_BOARD_RPISDCARDMANAGER_H_ +#include + +class RPiSdCardManager : public SdCardMountedIF { + public: + RPiSdCardManager(std::string prefix); + const std::string& getCurrentMountPrefix() const override; + bool isSdCardMounted(sd::SdCard sdCard) override; + std::optional getPreferredSdCard() const override; + void setActiveSdCard(sd::SdCard sdCard) override; + std::optional getActiveSdCard() const override; + + private: + std::string prefix; +}; + +#endif /* BSP_LINUX_BOARD_RPISDCARDMANAGER_H_ */ diff --git a/bsp_q7s/boardconfig/busConf.h b/bsp_q7s/boardconfig/busConf.h index 2402938f..3fb8d801 100644 --- a/bsp_q7s/boardconfig/busConf.h +++ b/bsp_q7s/boardconfig/busConf.h @@ -15,6 +15,7 @@ static constexpr char UART_PLOC_MPSOC_DEV[] = "/dev/ul-plmpsoc"; static constexpr char UART_PLOC_SUPERVSIOR_DEV[] = "/dev/ul-plsv"; static constexpr char UART_SYRLINKS_DEV[] = "/dev/ul-syrlinks"; static constexpr char UART_STAR_TRACKER_DEV[] = "/dev/ul-str"; +static constexpr char UART_SCEX_DEV[] = "/dev/ul-scex"; static constexpr char UIO_PDEC_REGISTERS[] = "/dev/uio0"; static constexpr char UIO_PTME[] = "/dev/uio1"; diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index de36b01a..e4a1fcbf 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -139,7 +139,11 @@ ReturnValue_t CoreController::initialize() { ReturnValue_t CoreController::initializeAfterTaskCreation() { ReturnValue_t result = returnvalue::OK; - sdInfo.pref = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if (not sdCard) { + return returnvalue::FAILED; + } + sdInfo.pref = sdCard.value(); sdcMan->setActiveSdCard(sdInfo.pref); currMntPrefix = sdcMan->getCurrentMountPrefix(); if (BLOCKING_SD_INIT) { @@ -337,7 +341,11 @@ ReturnValue_t CoreController::sdStateMachine() { if (sdInfo.state == SdStates::SET_STATE_SELF) { if (not sdInfo.commandExecuted) { result = sdcMan->getSdCardsStatus(sdInfo.currentState); - sdInfo.pref = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if (not sdCard) { + return returnvalue::FAILED; + } + sdInfo.pref = sdCard.value(); updateSdInfoOther(); if (sdInfo.pref != sd::SdCard::SLOT_0 and sdInfo.pref != sd::SdCard::SLOT_1) { sif::warning << "Preferred SD card invalid. Setting to card 0.." << std::endl; @@ -384,6 +392,7 @@ ReturnValue_t CoreController::sdStateMachine() { if (nonBlockingOpChecking(SdStates::DETERMINE_OTHER, 5, "Mounting SD card")) { sdInfo.prefState = sd::SdState::MOUNTED; currentStateSetter(sdInfo.pref, sd::SdState::MOUNTED); + sdcMan->setActiveSdCard(sdInfo.pref); } } } diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 6e0fce0c..725252a5 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -1,6 +1,7 @@ #include "bsp_q7s/core/InitMission.h" #include +#include #include #include @@ -242,6 +243,11 @@ void initmission::initTasks() { initmission::printAddObjectError("PTME_TEST", objects::CCSDS_IP_CORE_BRIDGE); } #endif +#if OBSW_ADD_SCEX_DEVICE == 1 + PeriodicTaskIF* scexDevHandler; + PeriodicTaskIF* scexReaderTask; + scheduling::schedulingScex(*factory, scexDevHandler, scexReaderTask); +#endif std::vector pusTasks; createPusTasks(*factory, missedDeadlineFunc, pusTasks); @@ -280,8 +286,9 @@ void initmission::initTasks() { taskStarter(pstTasks, "PST task vector"); taskStarter(pusTasks, "PUS task vector"); -#if OBSW_ADD_TEST_CODE == 1 - taskStarter(testTasks, "Test task vector"); +#if OBSW_ADD_SCEX_DEVICE == 1 + scexDevHandler->startTask(); + scexReaderTask->startTask(); #endif #if OBSW_TEST_CCSDS_BRIDGE == 1 @@ -304,6 +311,11 @@ void initmission::initTasks() { #if OBSW_ADD_PLOC_SUPERVISOR == 1 supvHelperTask->startTask(); #endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ + +#if OBSW_ADD_TEST_CODE == 1 + taskStarter(testTasks, "Test task vector"); +#endif + sif::info << "Tasks started.." << std::endl; } @@ -514,23 +526,23 @@ void initmission::createTestTasks(TaskFactory& factory, } /** - ▄ ▄ - ▌▒█ ▄▀▒▌ - ▌▒▒█ ▄▀▒▒▒▐ - ▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐ - ▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐ - ▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌ - ▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌ - ▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐ - ▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌ - ▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌ - ▌▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐ - ▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌ - ▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐ - ▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌ - ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐ - ▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌ - ▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀ - ▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀ - ▒▒▒▒▒▒▒▒▒▒▀▀ + â–„ â–„ + ▌▒█ ▄▀▒▌ + ▌▒▒█ ▄▀▒▒▒â–� + â–�▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒â–� + ▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒â–� + ▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌ + â–�▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌ + ▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒â–� + â–�░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌ + ▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌ + ▌▒▀â–�▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒â–� + â–�â–’â–’â–�â–€â–�▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌ + â–�▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒â–� + ▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌ + â–�â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–’â–‘â–’â–‘â–’â–‘â–’â–’â–„â–’â–’â–� + ▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌ + ▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀ + ▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀ + ▒▒▒▒▒▒▒▒▒▒▀▀ **/ diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 6627d90d..320c4fc9 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -1,5 +1,7 @@ #include "ObjectFactory.h" +#include + #include "OBSWConfig.h" #include "bsp_q7s/boardtest/Q7STestTask.h" #include "bsp_q7s/callbacks/gnssCallback.h" @@ -865,6 +867,7 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) { new I2cTestClass(objects::I2C_TEST, q7s::I2C_DEFAULT_DEV); #endif #if OBSW_ADD_UART_TEST_CODE == 1 + // auto* reader= new ScexUartReader(objects::SCEX_UART_READER); new UartTestClass(objects::UART_TEST); #endif } diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index acce5dfb..86fb8bd9 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -1,3 +1,5 @@ +#include + #include "OBSWConfig.h" #include "bsp_q7s/core/CoreController.h" #include "bsp_q7s/core/ObjectFactory.h" @@ -56,6 +58,11 @@ void ObjectFactory::produce(void* args) { #if OBSW_USE_CCSDS_IP_CORE == 1 createCcsdsComponents(gpioComIF); #endif /* OBSW_USE_CCSDS_IP_CORE == 1 */ + +#if OBSW_ADD_SCEX_DEVICE == 1 + createScexComponents(q7s::UART_GNSS_DEV, pwrSwitcher, *SdCardManager::instance(), false, + pcdu::Switches::PDU1_CH5_SOLAR_CELL_EXP_5V); +#endif /* Test Task */ #if OBSW_ADD_TEST_CODE == 1 createTestComponents(gpioComIF); diff --git a/bsp_q7s/memory/FileSystemHandler.cpp b/bsp_q7s/memory/FileSystemHandler.cpp index cb122383..a5bd68c6 100644 --- a/bsp_q7s/memory/FileSystemHandler.cpp +++ b/bsp_q7s/memory/FileSystemHandler.cpp @@ -71,8 +71,9 @@ void FileSystemHandler::fileSystemHandlerLoop() { void FileSystemHandler::fileSystemCheckup() { SdCardManager::SdStatePair statusPair; sdcMan->getSdCardsStatus(statusPair); - sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard(); - if ((preferredSdCard == sd::SdCard::SLOT_0) and (statusPair.first == sd::SdState::MOUNTED)) { + auto preferredSdCard = sdcMan->getPreferredSdCard(); + if (preferredSdCard and (preferredSdCard == sd::SdCard::SLOT_0) and + (statusPair.first == sd::SdState::MOUNTED)) { currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT; } else if ((preferredSdCard == sd::SdCard::SLOT_1) and (statusPair.second == sd::SdState::MOUNTED)) { @@ -90,7 +91,7 @@ void FileSystemHandler::fileSystemCheckup() { sif::warning << "Preferred SD card is " << sdString << " but does not appear to be mounted. Attempting fix.." << std::endl; // This function will appear to fix the inconsistent state - ReturnValue_t result = sdcMan->sanitizeState(&statusPair, preferredSdCard); + ReturnValue_t result = sdcMan->sanitizeState(&statusPair, preferredSdCard.value()); if (result != returnvalue::OK) { // Oh no. triggerEvent(SdCardManager::SANITIZATION_FAILED, 0, 0); @@ -108,7 +109,11 @@ ReturnValue_t FileSystemHandler::initialize() { << std::endl; } sdcMan = SdCardManager::instance(); - sd::SdCard preferredSdCard = sdcMan->getPreferredSdCard(); + auto sdCard = sdcMan->getPreferredSdCard(); + if (not sdCard) { + return returnvalue::FAILED; + } + sd::SdCard preferredSdCard = sdCard.value(); if (preferredSdCard == sd::SdCard::SLOT_0) { currentMountPrefix = SdCardManager::SD_0_MOUNT_POINT; } else if (preferredSdCard == sd::SdCard::SLOT_1) { diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index e2702771..d4b22e59 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -300,11 +300,6 @@ ReturnValue_t SdCardManager::sanitizeState(SdStatePair* statusPair, sd::SdCard p blocking = true; resetNonBlockingState = true; } - if (prefSdCard == sd::SdCard::NONE) { - result = getPreferredSdCard(); - if (result != returnvalue::OK) { - } - } if (statusPair == nullptr) { sdStatusPtr = std::make_unique(); statusPair = sdStatusPtr.get(); @@ -379,7 +374,7 @@ void SdCardManager::processSdStatusLine(std::pair& act idx++; } -sd::SdCard SdCardManager::getPreferredSdCard() const { +std::optional SdCardManager::getPreferredSdCard() const { MutexGuard mg(mutex); auto res = mg.getLockResult(); if (res != returnvalue::OK) { @@ -412,13 +407,9 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { return result; } -std::string SdCardManager::getCurrentMountPrefix() const { +const std::string& SdCardManager::getCurrentMountPrefix() const { MutexGuard mg(mutex); - if (sdInfo.active == sd::SdCard::SLOT_0) { - return SD_0_MOUNT_POINT; - } else { - return SD_1_MOUNT_POINT; - } + return currentPrefix; } SdCardManager::OpStatus SdCardManager::checkCurrentOp(Operations& currentOp) { @@ -552,6 +543,17 @@ ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, in return result; } -void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { sdInfo.active = sdCard; } +void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { + MutexGuard mg(mutex); + sdInfo.active = sdCard; + if (sdInfo.active == sd::SdCard::SLOT_0) { + currentPrefix = SD_0_MOUNT_POINT; + } else { + currentPrefix = SD_1_MOUNT_POINT; + } +} -sd::SdCard SdCardManager::getActiveSdCard() const { return sdInfo.active; } +std::optional SdCardManager::getActiveSdCard() const { + MutexGuard mg(mutex); + return sdInfo.active; +} diff --git a/bsp_q7s/memory/SdCardManager.h b/bsp_q7s/memory/SdCardManager.h index 87ed91d7..d8bafe25 100644 --- a/bsp_q7s/memory/SdCardManager.h +++ b/bsp_q7s/memory/SdCardManager.h @@ -92,7 +92,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * @param sdCard * @return */ - sd::SdCard getPreferredSdCard() const override; + std::optional getPreferredSdCard() const override; /** * Switch on the specified SD card. @@ -159,7 +159,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * mounted * @return */ - sd::SdCard getActiveSdCard() const override; + std::optional getActiveSdCard() const override; /** * Unmount the specified SD card. This is recommended before switching it off. The SD card @@ -188,7 +188,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * @param prefSdCardPtr * @return */ - std::string getCurrentMountPrefix() const override; + const std::string& getCurrentMountPrefix() const override; OpStatus checkCurrentOp(Operations& currentOp); diff --git a/generators/bsp_q7s_events.csv b/generators/bsp_q7s_events.csv index c7001a82..a38aa4e9 100644 --- a/generators/bsp_q7s_events.csv +++ b/generators/bsp_q7s_events.csv @@ -215,4 +215,6 @@ Event ID (dec); Event ID (hex); Name; Severity; Description; File Path 13701;0x3585;REBOOT_SW;MEDIUM; Software reboot occurred. Can also be a systemd reboot. P1: Current Chip, P2: Current Copy;bsp_q7s/core/CoreController.h 13702;0x3586;REBOOT_MECHANISM_TRIGGERED;MEDIUM;The reboot mechanism was triggered. P1: First 16 bits: Last Chip, Last 16 bits: Last Copy, P2: Each byte is the respective reboot count for the slots;bsp_q7s/core/CoreController.h 13703;0x3587;REBOOT_HW;MEDIUM;;bsp_q7s/core/CoreController.h -13800;0x35e8;EXPERIMENT_TIMEDOUT;LOW;;mission/devices/devicedefinitions/ScexDefinitions.h +13800;0x35e8;MISSING_PACKET;LOW;;mission/devices/devicedefinitions/ScexDefinitions.h +13801;0x35e9;EXPERIMENT_TIMEDOUT;LOW;;mission/devices/devicedefinitions/ScexDefinitions.h +13802;0x35ea;MULTI_PACKET_COMMAND_DONE;INFO;;mission/devices/devicedefinitions/ScexDefinitions.h diff --git a/generators/bsp_q7s_returnvalues.csv b/generators/bsp_q7s_returnvalues.csv index ab196298..7a1e52f8 100644 --- a/generators/bsp_q7s_returnvalues.csv +++ b/generators/bsp_q7s_returnvalues.csv @@ -1,6 +1,6 @@ Full ID (hex); Name; Description; Unique ID; Subsytem Name; File Path -0x0000;OK;System-wide code for ok.;0;HasReturnvaluesIF;fsfw/returnvalues/HasReturnvaluesIF.h -0x0001;Failed;Unspecified system-wide code for failed.;1;HasReturnvaluesIF;fsfw/returnvalues/HasReturnvaluesIF.h +0x0000;OK;System-wide code for ok.;0;HasReturnvaluesIF;fsfw/returnvalues/returnvalue.h +0x0001;Failed;Unspecified system-wide code for failed.;1;HasReturnvaluesIF;fsfw/returnvalues/returnvalue.h 0x63a0;NVMB_KeyNotExists;Specified key does not exist in json file;160;NVM_PARAM_BASE;mission/memory/NVMParameterBase.h 0x58a0;SUSS_ErrorUnlockMutex;;160;SUS_HANDLER;mission/devices/SusHandler.h 0x58a1;SUSS_ErrorLockMutex;;161;SUS_HANDLER;mission/devices/SusHandler.h @@ -361,8 +361,9 @@ Full ID (hex); Name; Description; Unique ID; Subsytem Name; File Path 0x2cd2;CCS_TooShortBlockedPacket;;210;CCSDS_HANDLER_IF;fsfw/src/fsfw/datalinklayer/CCSDSReturnValuesIF.h 0x2cd3;CCS_TooShortMapExtraction;;211;CCSDS_HANDLER_IF;fsfw/src/fsfw/datalinklayer/CCSDSReturnValuesIF.h 0x4201;PUS11_InvalidTypeTimeWindow;;1;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h -0x4202;PUS11_TimeshiftingNotPossible;;2;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h -0x4203;PUS11_InvalidRelativeTime;;3;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h +0x4202;PUS11_InvalidTimeWindow;;2;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h +0x4203;PUS11_TimeshiftingNotPossible;;3;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h +0x4204;PUS11_InvalidRelativeTime;;4;PUS_SERVICE_11;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h 0x3401;DC_NoReplyReceived;;1;DEVICE_COMMUNICATION_IF;fsfw/src/fsfw/devicehandlers/DeviceCommunicationIF.h 0x3402;DC_ProtocolError;;2;DEVICE_COMMUNICATION_IF;fsfw/src/fsfw/devicehandlers/DeviceCommunicationIF.h 0x3403;DC_Nullpointer;;3;DEVICE_COMMUNICATION_IF;fsfw/src/fsfw/devicehandlers/DeviceCommunicationIF.h diff --git a/generators/events/translateEvents.cpp b/generators/events/translateEvents.cpp index dda8b717..4448112c 100644 --- a/generators/events/translateEvents.cpp +++ b/generators/events/translateEvents.cpp @@ -1,7 +1,7 @@ /** - * @brief Auto-generated event translation file. Contains 217 translations. + * @brief Auto-generated event translation file. Contains 219 translations. * @details - * Generated on: 2022-08-24 16:53:50 + * Generated on: 2022-08-31 16:07:07 */ #include "translateEvents.h" @@ -217,7 +217,9 @@ const char *ALLOC_FAILURE_STRING = "ALLOC_FAILURE"; const char *REBOOT_SW_STRING = "REBOOT_SW"; const char *REBOOT_MECHANISM_TRIGGERED_STRING = "REBOOT_MECHANISM_TRIGGERED"; const char *REBOOT_HW_STRING = "REBOOT_HW"; +const char *MISSING_PACKET_STRING = "MISSING_PACKET"; const char *EXPERIMENT_TIMEDOUT_STRING = "EXPERIMENT_TIMEDOUT"; +const char *MULTI_PACKET_COMMAND_DONE_STRING = "MULTI_PACKET_COMMAND_DONE"; const char *translateEvents(Event event) { switch ((event & 0xFFFF)) { @@ -646,7 +648,11 @@ const char *translateEvents(Event event) { case (13703): return REBOOT_HW_STRING; case (13800): + return MISSING_PACKET_STRING; + case (13801): return EXPERIMENT_TIMEDOUT_STRING; + case (13802): + return MULTI_PACKET_COMMAND_DONE_STRING; default: return "UNKNOWN_EVENT"; } diff --git a/generators/objects/translateObjects.cpp b/generators/objects/translateObjects.cpp index 215d47d8..8f5c084f 100644 --- a/generators/objects/translateObjects.cpp +++ b/generators/objects/translateObjects.cpp @@ -2,7 +2,7 @@ * @brief Auto-generated object translation file. * @details * Contains 135 translations. - * Generated on: 2022-08-24 16:53:50 + * Generated on: 2022-08-31 16:07:07 */ #include "translateObjects.h" diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index e1d80966..861dfb5c 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -6,4 +6,4 @@ add_subdirectory(devices) add_subdirectory(fsfwconfig) add_subdirectory(obc) -target_sources(${OBSW_NAME} PUBLIC ObjectFactory.cpp) +target_sources(${OBSW_NAME} PUBLIC ObjectFactory.cpp InitMission.cpp) diff --git a/linux/InitMission.cpp b/linux/InitMission.cpp new file mode 100644 index 00000000..eb8f677a --- /dev/null +++ b/linux/InitMission.cpp @@ -0,0 +1,47 @@ +#include "InitMission.h" + +#include +#include +#include + +#include "OBSWConfig.h" +#include "ObjectFactory.h" + +void scheduling::schedulingScex(TaskFactory& factory, PeriodicTaskIF*& scexDevHandler, + PeriodicTaskIF*& scexReaderTask) { + using namespace initmission; + ReturnValue_t result = returnvalue::OK; +#if OBSW_PRINT_MISSED_DEADLINES == 1 + void (*missedDeadlineFunc)(void) = TaskFactory::printMissedDeadline; +#else + void (*missedDeadlineFunc)(void) = nullptr; +#endif + scexDevHandler = factory.createPeriodicTask( + "SCEX_DEV", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc); + + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION); + if (result != returnvalue::OK) { + printAddObjectError("SCEX_DEV", objects::SCEX); + } + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE); + if (result != returnvalue::OK) { + printAddObjectError("SCEX_DEV", objects::SCEX); + } + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE); + if (result != returnvalue::OK) { + printAddObjectError("SCEX_DEV", objects::SCEX); + } + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ); + if (result != returnvalue::OK) { + printAddObjectError("SCEX_DEV", objects::SCEX); + } + result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ); + + result = returnvalue::OK; + scexReaderTask = factory.createPeriodicTask( + "SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); + result = scexReaderTask->addComponent(objects::SCEX_UART_READER); + if (result != returnvalue::OK) { + printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER); + } +} diff --git a/linux/InitMission.h b/linux/InitMission.h new file mode 100644 index 00000000..e5a3afff --- /dev/null +++ b/linux/InitMission.h @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace scheduling { +void schedulingScex(TaskFactory& factory, PeriodicTaskIF*& scexDevHandler, + PeriodicTaskIF*& scexReaderTask); +} diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index 0398bd7e..43e4109a 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -323,14 +323,20 @@ void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF, #endif // OBSW_ADD_RTD_DEVICES == 1 } -void ObjectFactory::createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher) { +void ObjectFactory::createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher, + SdCardMountedIF& mountedIF, bool onImmediately, + std::optional switchId) { // objekte anlegen - SdCardMountedIF* sdcMan = nullptr; auto* cookie = new UartCookie(objects::SCEX, uartDev, uart::SCEX_BAUD, 4096); auto scexUartReader = new ScexUartReader(objects::SCEX_UART_READER); - auto scexHandler = new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, sdcMan); - scexHandler->setStartUpImmediately(); + auto scexHandler = new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, mountedIF); + if (onImmediately) { + scexHandler->setStartUpImmediately(); + } + if (switchId) { + scexHandler->setPowerSwitcher(*pwrSwitcher, switchId.value()); + } } void ObjectFactory::createThermalController() { diff --git a/linux/ObjectFactory.h b/linux/ObjectFactory.h index 99bef0e7..f4ecc6e3 100644 --- a/linux/ObjectFactory.h +++ b/linux/ObjectFactory.h @@ -1,8 +1,11 @@ #pragma once +#include #include #include +#include +#include #include class GpioIF; @@ -16,7 +19,9 @@ void createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiComIF, PowerSwitc void createRtdComponents(std::string spiDev, GpioIF* gpioComIF, PowerSwitchIF* pwrSwitcher, SpiComIF* comIF); -void createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher); +void createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher, + SdCardMountedIF& mountedIF, bool onImmediately, + std::optional switchId); void gpioChecker(ReturnValue_t result, std::string output); diff --git a/linux/boardtest/UartTestClass.cpp b/linux/boardtest/UartTestClass.cpp index 9843baa5..7f18957a 100644 --- a/linux/boardtest/UartTestClass.cpp +++ b/linux/boardtest/UartTestClass.cpp @@ -27,12 +27,11 @@ using namespace returnvalue; -UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader) - : TestTask(objectId), reader(reader) { +UartTestClass::UartTestClass(object_id_t objectId) : TestTask(objectId) { mode = TestModes::SCEX; - scexMode = ScexModes::READER_TASK; + scexMode = ScexModes::SIMPLE; // No one-cell and all-cell support implemented yet - currCmd = scex::Cmds::FRAM; + currCmd = scex::Cmds::PING; if (scexMode == ScexModes::SIMPLE) { auto encodingBuf = new std::array; DleParser::BufPair encodingBufPair{encodingBuf->data(), encodingBuf->size()}; @@ -40,6 +39,8 @@ UartTestClass::UartTestClass(object_id_t objectId, ScexUartReader* reader) DleParser::BufPair decodingBufPair{decodedBuf->data(), decodedBuf->size()}; dleParser = new ScexDleParser(*(new SimpleRingBuffer(4096, true)), dleEncoder, encodingBufPair, decodingBufPair, &foundDlePacketHandler, this); + } else { + reader = new ScexUartReader(objects::SCEX_UART_READER); } } @@ -150,13 +151,13 @@ void UartTestClass::gpsPeriodic() { } void UartTestClass::scexInit() { - if (reader == nullptr) { - sif::warning << "UartTestClass::scexInit: Reader invalid" << std::endl; - return; - } if (scexMode == ScexModes::SIMPLE) { scexSimpleInit(); } else { + if (reader == nullptr) { + sif::warning << "UartTestClass::scexInit: Reader invalid" << std::endl; + return; + } #if defined(RASPBERRY_PI) std::string devname = "/dev/serial0"; #else @@ -176,13 +177,13 @@ void UartTestClass::scexInit() { void UartTestClass::scexPeriodic() { using namespace std; using namespace scex; - if (reader == nullptr) { - return; - } if (scexMode == ScexModes::SIMPLE) { scexSimplePeriodic(); } else { + if (reader == nullptr) { + return; + } if (not cmdSent) { size_t len = 0; prepareScexCmd(currCmd, false, cmdBuf.data(), &len); @@ -375,6 +376,7 @@ int UartTestClass::prepareScexCmd(scex::Cmds cmd, bool tempCheck, uint8_t* cmdBu uint16_t crc = CRC::crc16ccitt(cmdBuf, 5); cmdBuf[5] = (crc >> 8) & 0xff; cmdBuf[6] = crc & 0xff; + *len = 7; return 0; } diff --git a/linux/boardtest/UartTestClass.h b/linux/boardtest/UartTestClass.h index 1c1b9988..14d74322 100644 --- a/linux/boardtest/UartTestClass.h +++ b/linux/boardtest/UartTestClass.h @@ -19,7 +19,7 @@ class ScexDleParser; class UartTestClass : public TestTask { public: - UartTestClass(object_id_t objectId, ScexUartReader* reader); + UartTestClass(object_id_t objectId); ReturnValue_t initialize() override; ReturnValue_t performOneShotAction() override; diff --git a/linux/csp/CspComIF.cpp b/linux/csp/CspComIF.cpp index 5d8c3fd6..ea508a31 100644 --- a/linux/csp/CspComIF.cpp +++ b/linux/csp/CspComIF.cpp @@ -166,23 +166,23 @@ ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s if (result != 0) { return returnvalue::FAILED; } - } else if(req == GOMSPACE::SpecialRequestTypes::SAVE_TABLE) { - if(sendLen < 2) { + } else if (req == GOMSPACE::SpecialRequestTypes::SAVE_TABLE) { + if (sendLen < 2) { return returnvalue::FAILED; } const TableInfo* tableInfo = reinterpret_cast(sendData); int result = gs_rparam_save(cspAddress, cspCookie->getTimeout(), tableInfo->sourceTable, - tableInfo->targetTable); + tableInfo->targetTable); if (result != 0) { return returnvalue::FAILED; } - } else if(req == GOMSPACE::SpecialRequestTypes::LOAD_TABLE) { - if(sendLen < 2) { + } else if (req == GOMSPACE::SpecialRequestTypes::LOAD_TABLE) { + if (sendLen < 2) { return returnvalue::FAILED; } const TableInfo* tableInfo = reinterpret_cast(sendData); int result = gs_rparam_load(cspAddress, cspCookie->getTimeout(), tableInfo->sourceTable, - tableInfo->targetTable); + tableInfo->targetTable); if (result != 0) { return returnvalue::FAILED; } diff --git a/linux/devices/ScexUartReader.cpp b/linux/devices/ScexUartReader.cpp index 38286a7a..ca7013c4 100644 --- a/linux/devices/ScexUartReader.cpp +++ b/linux/devices/ScexUartReader.cpp @@ -34,7 +34,6 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { lock->unlockMutex(); while (true) { semaphore->acquire(); - sif::info << "task was started" << std::endl; int bytesRead = 0; while (true) { bytesRead = read(serialPort, reinterpret_cast(recBuf.data()), @@ -42,7 +41,6 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { if (bytesRead == 0) { MutexGuard mg(lock); if (state == States::FINISH) { - sif::debug << "finish detected" << std::endl; state = States::IDLE; break; } @@ -66,8 +64,6 @@ ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) { } } }; - // task block comes here - sif::info << "task was stopped" << std::endl; } return OK; } @@ -135,7 +131,6 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl; return FAILED; } - arrayprinter::print(cmdbuf.data(), encodedLen); size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen); if (bytesWritten != encodedLen) { sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed" diff --git a/linux/fsfwconfig/events/translateEvents.cpp b/linux/fsfwconfig/events/translateEvents.cpp index dda8b717..4448112c 100644 --- a/linux/fsfwconfig/events/translateEvents.cpp +++ b/linux/fsfwconfig/events/translateEvents.cpp @@ -1,7 +1,7 @@ /** - * @brief Auto-generated event translation file. Contains 217 translations. + * @brief Auto-generated event translation file. Contains 219 translations. * @details - * Generated on: 2022-08-24 16:53:50 + * Generated on: 2022-08-31 16:07:07 */ #include "translateEvents.h" @@ -217,7 +217,9 @@ const char *ALLOC_FAILURE_STRING = "ALLOC_FAILURE"; const char *REBOOT_SW_STRING = "REBOOT_SW"; const char *REBOOT_MECHANISM_TRIGGERED_STRING = "REBOOT_MECHANISM_TRIGGERED"; const char *REBOOT_HW_STRING = "REBOOT_HW"; +const char *MISSING_PACKET_STRING = "MISSING_PACKET"; const char *EXPERIMENT_TIMEDOUT_STRING = "EXPERIMENT_TIMEDOUT"; +const char *MULTI_PACKET_COMMAND_DONE_STRING = "MULTI_PACKET_COMMAND_DONE"; const char *translateEvents(Event event) { switch ((event & 0xFFFF)) { @@ -646,7 +648,11 @@ const char *translateEvents(Event event) { case (13703): return REBOOT_HW_STRING; case (13800): + return MISSING_PACKET_STRING; + case (13801): return EXPERIMENT_TIMEDOUT_STRING; + case (13802): + return MULTI_PACKET_COMMAND_DONE_STRING; default: return "UNKNOWN_EVENT"; } diff --git a/linux/fsfwconfig/objects/translateObjects.cpp b/linux/fsfwconfig/objects/translateObjects.cpp index 215d47d8..8f5c084f 100644 --- a/linux/fsfwconfig/objects/translateObjects.cpp +++ b/linux/fsfwconfig/objects/translateObjects.cpp @@ -2,7 +2,7 @@ * @brief Auto-generated object translation file. * @details * Contains 135 translations. - * Generated on: 2022-08-24 16:53:50 + * Generated on: 2022-08-31 16:07:07 */ #include "translateObjects.h" diff --git a/mission/devices/GomspaceDeviceHandler.cpp b/mission/devices/GomspaceDeviceHandler.cpp index ebfcf2a9..412f2e46 100644 --- a/mission/devices/GomspaceDeviceHandler.cpp +++ b/mission/devices/GomspaceDeviceHandler.cpp @@ -87,7 +87,7 @@ ReturnValue_t GomspaceDeviceHandler::buildCommandFromCommand(DeviceCommandId_t d } case (GOMSPACE::REQUEST_HK_TABLE): { DeviceType devType; - if(getDevType(devType) != returnvalue::OK) { + if (getDevType(devType) != returnvalue::OK) { return returnvalue::FAILED; } result = @@ -99,11 +99,11 @@ ReturnValue_t GomspaceDeviceHandler::buildCommandFromCommand(DeviceCommandId_t d } case (GOMSPACE::REQUEST_CONFIG_TABLE): { DeviceType devType; - if(getDevType(devType) != returnvalue::OK) { + if (getDevType(devType) != returnvalue::OK) { return returnvalue::FAILED; } - result = generateRequestFullCfgTableCmd(devType, tableCfg.cfgTableSize, - deviceCommand, cspCookie); + result = + generateRequestFullCfgTableCmd(devType, tableCfg.cfgTableSize, deviceCommand, cspCookie); if (result != returnvalue::OK) { return result; } diff --git a/mission/devices/GomspaceDeviceHandler.h b/mission/devices/GomspaceDeviceHandler.h index 528cd2dd..af9d3411 100644 --- a/mission/devices/GomspaceDeviceHandler.h +++ b/mission/devices/GomspaceDeviceHandler.h @@ -93,10 +93,9 @@ class GomspaceDeviceHandler : public DeviceHandlerBase { * @param cspCookie * @return */ - ReturnValue_t generateRequestFullCfgTableCmd(GOMSPACE::DeviceType devType, - uint16_t tableSize, DeviceCommandId_t id, - CspCookie *cspCookie); - ReturnValue_t getDevType(GOMSPACE::DeviceType& type) const; + ReturnValue_t generateRequestFullCfgTableCmd(GOMSPACE::DeviceType devType, uint16_t tableSize, + DeviceCommandId_t id, CspCookie *cspCookie); + ReturnValue_t getDevType(GOMSPACE::DeviceType &type) const; /** * This command handles printing the HK table to the console. This is useful for debugging * purposes diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index e643a945..c811f5d3 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -491,8 +491,8 @@ void PayloadPcduHandler::checkAdcValues() { void PayloadPcduHandler::checkJsonFileInit() { if (not jsonFileInitComplete) { - sd::SdCard activeSd = sdcMan->getActiveSdCard(); - if (sdcMan->isSdCardMounted(activeSd)) { + auto activeSd = sdcMan->getActiveSdCard(); + if (activeSd and sdcMan->isSdCardMounted(activeSd.value())) { params.initialize(sdcMan->getCurrentMountPrefix()); jsonFileInitComplete = true; } diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index 15dd05cb..5dddec3e 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -14,25 +15,18 @@ using std::ofstream; using namespace returnvalue; ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie, - SdCardMountedIF* sdcMan) + SdCardMountedIF& sdcMan) : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) {} ScexDeviceHandler::~ScexDeviceHandler() {} -void ScexDeviceHandler::doStartUp() { - // mode on - setMode(MODE_ON); -} +void ScexDeviceHandler::doStartUp() { setMode(MODE_ON); } void ScexDeviceHandler::doShutDown() { setMode(_MODE_POWER_DOWN); } -ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { - return OK; -} +ReturnValue_t ScexDeviceHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { return OK; } -ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { - return OK; -} +ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { return OK; } ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, @@ -88,8 +82,17 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic finishCountdown.setTimeout(LONG_CD); // countdown starten finishCountdown.resetTimer(); + if (debugMode) { + uint32_t remainingMillis = finishCountdown.getRemainingMillis(); + + sif::info << "ScexDeviceHandler::buildCommandFromCommand: RemainingMillis: " + << remainingMillis << std::endl; + } + prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {commandData + 1, commandDataLen - 1}, tempCheck); + updatePeriodicReply(true, deviceCommand); + actionHelper.finish(true, getCommanderQueueId(deviceCommand), deviceCommand, OK); break; } case (ONE_CELL): { @@ -98,6 +101,8 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic finishCountdown.resetTimer(); prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {commandData + 1, commandDataLen - 1}, tempCheck); + updatePeriodicReply(true, deviceCommand); + actionHelper.finish(true, getCommanderQueueId(deviceCommand), deviceCommand, OK); break; } case (ALL_CELLS_CMD): { @@ -106,6 +111,8 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic finishCountdown.resetTimer(); prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {commandData + 1, commandDataLen - 1}, tempCheck); + actionHelper.finish(true, getCommanderQueueId(deviceCommand), deviceCommand, OK); + updatePeriodicReply(true, deviceCommand); break; } default: { @@ -123,12 +130,12 @@ void ScexDeviceHandler::fillCommandAndReplyMap() { insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3); insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3); - insertInCommandAndReplyMap(scex::Cmds::ALL_CELLS_CMD, 0, nullptr, 0, false, false, - scex::Cmds::ALL_CELLS_CMD, &finishCountdown); - insertInCommandAndReplyMap(scex::Cmds::ONE_CELL, 0, nullptr, 0, false, false, - scex::Cmds::ONE_CELL, &finishCountdown); - insertInCommandAndReplyMap(scex::Cmds::FRAM, 0, nullptr, 0, false, false, - scex::Cmds::FRAM, &finishCountdown); + insertInCommandAndReplyMap(scex::Cmds::ALL_CELLS_CMD, 0, nullptr, 0, true, false, + scex::Cmds::ALL_CELLS_CMD, &finishCountdown); + insertInCommandAndReplyMap(scex::Cmds::ONE_CELL, 0, nullptr, 0, true, false, scex::Cmds::ONE_CELL, + &finishCountdown); + insertInCommandAndReplyMap(scex::Cmds::FRAM, 0, nullptr, 0, true, false, scex::Cmds::FRAM, + &finishCountdown); insertInReplyMap(scex::Cmds::ERROR_REPLY, 3); } @@ -140,58 +147,93 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai if (result == ScexHelper::INVALID_CRC) { sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl; - return result; + *foundLen = remainingSize; + } else { + result = handleValidReply(remainingSize, foundId, foundLen); + } + return result; +} + +ReturnValue_t ScexDeviceHandler::handleValidReply(size_t remSize, DeviceCommandId_t* foundId, + size_t* foundLen) { + using namespace scex; + ReturnValue_t result = OK; + + switch (helper.getCmd()) { + case (FRAM): { + if (debugMode) { + uint32_t remainingMillis = finishCountdown.getRemainingMillis(); + + sif::info << "ScexDeviceHandler::handleValidReply: RemMillis: " << remainingMillis + << std::endl; + } + result = APERIODIC_REPLY; + break; + } + case (ONE_CELL): { + result = APERIODIC_REPLY; + break; + } + case (ALL_CELLS_CMD): { + result = APERIODIC_REPLY; + break; + } + default: { + break; + } } *foundId = helper.getCmd(); - *foundLen = remainingSize; - - return OK; + *foundLen = remSize; + return result; } ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) { - // cmd auswertung (in file reinschreiben) using namespace scex; ReturnValue_t status = OK; auto oneFileHandler = [&](std::string cmdName) { - fileId = random_string(6); - std::ostringstream oss("/tmp/scex-", std::ostringstream::ate); - oss << cmdName << fileId << ".bin"; + fileId = date_time_string(); + std::ostringstream oss; + auto prefix = sdcMan.getCurrentMountPrefix(); + oss << prefix << "/scex-" << cmdName << fileId << ".bin"; fileName = oss.str(); - std::cout << fileName << std::endl; + sif::info << "ScexDeviceHandler::interpretDeviceReply: FileName: " << fileName << std::endl; ofstream out(fileName, ofstream::binary); if (out.bad()) { sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName << std::endl; return FAILED; } - if (debugMode) { - out << helper; - } + out << helper; return OK; }; auto multiFileHandler = [&](std::string cmdName) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { - - fileId = random_string(6); - std::ostringstream oss("/tmp/scex-", std::ostringstream::ate); - oss << cmdName << fileId << ".bin"; + fileId = date_time_string(); + std::ostringstream oss; + auto prefix = sdcMan.getCurrentMountPrefix(); + oss << prefix << "/scex-" << cmdName << fileId << ".bin"; fileName = oss.str(); + sif::info << "ScexDeviceHandler::interpretDeviceReply: FileName: " << fileName + << std::endl; // TODO remove fileNameSet = true; ofstream out(fileName, ofstream::binary); if (out.bad()) { - sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName + sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName << std::endl; return FAILED; } + out << helper; } else { ofstream out(fileName, ofstream::binary | ofstream::app); // append - if (debugMode) { - out << helper; + if (out.bad()) { + sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName + << std::endl; + return FAILED; } + out << helper; } - return OK; }; switch (id) { @@ -220,7 +262,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons break; } case (ALL_CELLS_CMD): { - status = multiFileHandler("all_cell_"); + status = multiFileHandler("multi_cell_"); break; } default: @@ -231,29 +273,40 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons reader.finish(); commandActive = false; if (id != PING) { - sif::info << "Reader is finished" << std::endl; fileNameSet = false; } + if (id == FRAM or id == ALL_CELLS_CMD or id == ONE_CELL) { + triggerEvent(MULTI_PACKET_COMMAND_DONE, id); + updatePeriodicReply(false, id); + } + } + if (debugMode) { + uint32_t remainingMillis = finishCountdown.getRemainingMillis(); + sif::info << __FILE__ << __func__ << "(" << __LINE__ << ") RemMillis: " << remainingMillis + << std::endl; } - return status; } void ScexDeviceHandler::performOperationHook() { + uint32_t remainingMillis = finishCountdown.getRemainingMillis(); if (commandActive and finishCountdown.hasTimedOut()) { triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0); reader.finish(); - sif::warning << "ScexDeviceHandler::performOperationHook: Reader timeout" << std::endl; + sif::warning << "ScexDeviceHandler::scanForReply: Reader timeout; RemMillis: " + << remainingMillis << std::endl; fileNameSet = false; commandActive = false; } } -uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { - return OK; -} +uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return OK; } ReturnValue_t ScexDeviceHandler::getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) { + if (switchId) { + *numberOfSwitches = 1; + *switches = &switchId.value(); + } return OK; } @@ -262,23 +315,38 @@ ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& lo return OK; } -std::string ScexDeviceHandler::random_string(std::string::size_type length) { - static auto& chrs = - "0123456789" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +std::string ScexDeviceHandler::date_time_string() { + using namespace std; + string date_time; + Clock::TimeOfDay_t tod; + Clock::getDateAndTime(&tod); + ostringstream oss(std::ostringstream::ate); - thread_local static std::mt19937 rg{std::random_device{}()}; - thread_local static std::uniform_int_distribution pick(0, - sizeof(chrs) - 2); + if (tod.hour < 10) { + oss << tod.year << tod.month << tod.day << "_0" << tod.hour; + } else { + oss << tod.year << tod.month << tod.day << "_" << tod.hour; + } + if (tod.minute < 10) { + oss << 0 << tod.minute; - std::string s; + } else { + oss << tod.minute; + } + if (tod.second < 10) { + oss << 0 << tod.second; + } else { + oss << tod.second; + } - s.reserve(length); + date_time = oss.str(); - while (length--) s += chrs[pick(rg)]; - - return s; + return date_time; } void ScexDeviceHandler::modeChanged() {} + +void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) { + DeviceHandlerBase::setPowerSwitcher(&powerSwitcher); + this->switchId = switchId; +} diff --git a/mission/devices/ScexDeviceHandler.h b/mission/devices/ScexDeviceHandler.h index eeaac755..6cf2492b 100644 --- a/mission/devices/ScexDeviceHandler.h +++ b/mission/devices/ScexDeviceHandler.h @@ -5,12 +5,17 @@ #include #include +#include + +#include "commonSubsystemIds.h" + class SdCardMountedIF; class ScexDeviceHandler : public DeviceHandlerBase { public: ScexDeviceHandler(object_id_t objectId, ScexUartReader &reader, CookieIF *cookie, - SdCardMountedIF *sdcMan); + SdCardMountedIF &sdcMan); + void setPowerSwitcher(PowerSwitchIF &powerSwitcher, power::Switch_t switchId); virtual ~ScexDeviceHandler(); private: @@ -18,17 +23,18 @@ class ScexDeviceHandler : public DeviceHandlerBase { static constexpr uint32_t SHORT_CD = 7000; std::array cmdBuf = {}; + std::optional switchId; std::string fileId = ""; std::string fileName = ""; bool fileNameSet = false; bool commandActive = false; - bool debugMode = true; + bool debugMode = false; scex::Cmds currCmd = scex::Cmds::PING; - SdCardMountedIF *sdcMan = nullptr; + SdCardMountedIF &sdcMan; Countdown finishCountdown = Countdown(LONG_CD); - std::string random_string(std::string::size_type length); + std::string date_time_string(); // DeviceHandlerBase private function implementation void doStartUp() override; @@ -45,6 +51,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) override; ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; + ReturnValue_t handleValidReply(size_t remSize, DeviceCommandId_t *foundId, size_t *foundLen); uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) override; diff --git a/mission/devices/devicedefinitions/ScexDefinitions.h b/mission/devices/devicedefinitions/ScexDefinitions.h index 685f0cc0..4abe1249 100644 --- a/mission/devices/devicedefinitions/ScexDefinitions.h +++ b/mission/devices/devicedefinitions/ScexDefinitions.h @@ -14,8 +14,10 @@ namespace scex { static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SCEX_HANDLER; static constexpr Event MISSING_PACKET = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); - -static constexpr Event EXPERIMENT_TIMEDOUT = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); +static constexpr Event EXPERIMENT_TIMEDOUT = event::makeEvent(SUBSYSTEM_ID, 1, severity::LOW); +//! FRAM, One Cell or All cells command finished. P1: Command ID +static constexpr Event MULTI_PACKET_COMMAND_DONE = + event::makeEvent(SUBSYSTEM_ID, 2, severity::INFO); enum Cmds : DeviceCommandId_t { PING = 0b00111, diff --git a/mission/memory/SdCardMountedIF.h b/mission/memory/SdCardMountedIF.h index 853c7e8d..57e98919 100644 --- a/mission/memory/SdCardMountedIF.h +++ b/mission/memory/SdCardMountedIF.h @@ -1,6 +1,7 @@ #ifndef MISSION_MEMORY_SDCARDMOUNTERIF_H_ #define MISSION_MEMORY_SDCARDMOUNTERIF_H_ +#include #include #include "definitions.h" @@ -8,11 +9,11 @@ class SdCardMountedIF { public: virtual ~SdCardMountedIF(){}; - virtual std::string getCurrentMountPrefix() const = 0; + virtual const std::string& getCurrentMountPrefix() const = 0; virtual bool isSdCardMounted(sd::SdCard sdCard) = 0; - virtual sd::SdCard getPreferredSdCard() const = 0; + virtual std::optional getPreferredSdCard() const = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0; - virtual sd::SdCard getActiveSdCard() const = 0; + virtual std::optional getActiveSdCard() const = 0; private: }; diff --git a/mission/utility/InitMission.h b/mission/utility/InitMission.h index dc131981..5529f749 100644 --- a/mission/utility/InitMission.h +++ b/mission/utility/InitMission.h @@ -1,12 +1,11 @@ -#ifndef MISSION_UTILITY_INITMISSION_H_ -#define MISSION_UTILITY_INITMISSION_H_ +#pragma once #include #include namespace initmission { -void printAddObjectError(const char* name, object_id_t objectId) { +static void printAddObjectError(const char* name, object_id_t objectId) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "InitMission::printAddError: Adding object " << name << " with object ID 0x" << std::hex << std::setfill('0') << std::setw(8) << objectId << " failed!" << std::dec @@ -18,5 +17,3 @@ void printAddObjectError(const char* name, object_id_t objectId) { } } // namespace initmission - -#endif /* MISSION_UTILITY_INITMISSION_H_ */ diff --git a/tmtc b/tmtc index 603b7e85..a7714747 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 603b7e8574d74ba60692115133cde3cd8b8bd423 +Subproject commit a7714747bc45dfa6a9ccb41cc6eb890b21ca0481