From 11f476878d311850c4360eec0b5e4a7cad597dcc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 28 Feb 2023 19:14:15 +0100 Subject: [PATCH] rework SUS polling --- bsp_q7s/memory/LocalParameterHandler.h | 4 +- common/config/eive/resultClassIds.h | 4 +- dummies/CoreControllerDummy.h | 2 +- dummies/SusDummy.cpp | 5 +- dummies/SusDummy.h | 5 +- linux/ObjectFactory.cpp | 27 ++--- linux/devices/AcsBoardPolling.h | 1 - linux/devices/CMakeLists.txt | 1 + linux/devices/SusPolling.cpp | 109 ++++++++++++++++++ linux/devices/SusPolling.h | 50 ++++++++ linux/fsfwconfig/returnvalues/classIds.h | 4 +- linux/ipcore/PdecHandler.cpp | 22 ++-- linux/ipcore/PdecHandler.h | 3 +- mission/controller/AcsController.h | 2 +- mission/controller/ThermalController.h | 26 ++--- mission/controller/acs/SensorValues.h | 28 ++--- mission/devices/SusHandler.cpp | 60 +++++----- mission/devices/SusHandler.h | 6 +- .../devices/devicedefinitions/acsPolling.h | 10 ++ .../{SusDefinitions.h => susMax1227Helpers.h} | 4 +- mission/system/objects/ComSubsystem.cpp | 2 +- mission/system/objects/ComSubsystem.h | 18 +-- 22 files changed, 281 insertions(+), 112 deletions(-) create mode 100644 linux/devices/SusPolling.cpp create mode 100644 linux/devices/SusPolling.h rename mission/devices/devicedefinitions/{SusDefinitions.h => susMax1227Helpers.h} (98%) diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index a8b96950..cdbcff06 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -19,8 +19,8 @@ class LocalParameterHandler : public NVMParameterBase { * @brief Constructor * * @param sdRelativeName Absolute name of json file relative to mount - * directory of SD card. - * E.g. conf/example.json + * directory + * of SD card. E.g. conf/example.json * @param sdcMan Pointer to SD card manager */ LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan); diff --git a/common/config/eive/resultClassIds.h b/common/config/eive/resultClassIds.h index f7bf26c1..df47d935 100644 --- a/common/config/eive/resultClassIds.h +++ b/common/config/eive/resultClassIds.h @@ -40,8 +40,8 @@ enum commonClassIds : uint8_t { ACS_SAFE, // ACSSAF ACS_PTG, // ACSPTG ACS_DETUMBLE, // ACSDTB - SD_CARD_MANAGER, // SDMA - LOCAL_PARAM_HANDLER, // LPH + SD_CARD_MANAGER, // SDMA + LOCAL_PARAM_HANDLER, // LPH COMMON_CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/dummies/CoreControllerDummy.h b/dummies/CoreControllerDummy.h index 1b4eeaf8..37d88081 100644 --- a/dummies/CoreControllerDummy.h +++ b/dummies/CoreControllerDummy.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include class CoreControllerDummy : public ExtendedControllerBase { public: diff --git a/dummies/SusDummy.cpp b/dummies/SusDummy.cpp index 7c271b21..d1129a49 100644 --- a/dummies/SusDummy.cpp +++ b/dummies/SusDummy.cpp @@ -35,8 +35,9 @@ uint32_t SusDummy::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return ReturnValue_t SusDummy::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(SUS::SusPoolIds::TEMPERATURE_C, new PoolEntry({0}, 1, true)); - localDataPoolMap.emplace(SUS::SusPoolIds::CHANNEL_VEC, + localDataPoolMap.emplace(susMax1227::SusPoolIds::TEMPERATURE_C, + new PoolEntry({0}, 1, true)); + localDataPoolMap.emplace(susMax1227::SusPoolIds::CHANNEL_VEC, new PoolEntry({2603, 781, 2760, 2048, 4056, 0}, true)); return returnvalue::OK; diff --git a/dummies/SusDummy.h b/dummies/SusDummy.h index a229bd87..9a49a591 100644 --- a/dummies/SusDummy.h +++ b/dummies/SusDummy.h @@ -2,8 +2,7 @@ #define DUMMIES_SUSDUMMY_H_ #include - -#include "mission/devices/devicedefinitions/SusDefinitions.h" +#include class SusDummy : public DeviceHandlerBase { public: @@ -17,7 +16,7 @@ class SusDummy : public DeviceHandlerBase { virtual ~SusDummy(); protected: - SUS::SusDataset susSet; + susMax1227::SusDataset susSet; void doStartUp() override; void doShutDown() override; ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index e3162a07..bf7f343f 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -78,15 +78,16 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo #if OBSW_ADD_SUN_SENSORS == 1 SusFdir* fdir = nullptr; std::array susHandlers = {}; - SpiCookie* spiCookie = new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, SUS::MAX_CMD_SIZE, - spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); + SpiCookie* spiCookie = + new SpiCookie(addresses::SUS_0, gpioIds::CS_SUS_0, susMax1227::MAX_CMD_SIZE, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[0] = new SusHandler(objects::SUS_0_N_LOC_XFYFZM_PT_XF, 0, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_0_N_LOC_XFYFZM_PT_XF); susHandlers[0]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[1] = @@ -94,7 +95,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_1_N_LOC_XBYFZM_PT_XB); susHandlers[1]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[2] = @@ -102,7 +103,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_2_N_LOC_XFYBZB_PT_YB); susHandlers[2]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[3] = @@ -110,7 +111,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_3_N_LOC_XFYBZF_PT_YF); susHandlers[3]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[4] = @@ -118,7 +119,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_4_N_LOC_XMYFZF_PT_ZF); susHandlers[4]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[5] = @@ -126,7 +127,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_5_N_LOC_XFYMZB_PT_ZB); susHandlers[5]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[6] = @@ -134,7 +135,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_6_R_LOC_XFYBZM_PT_XF); susHandlers[6]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[7] = @@ -142,7 +143,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_7_R_LOC_XBYBZM_PT_XB); susHandlers[7]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[8] = @@ -150,7 +151,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_8_R_LOC_XBYBZB_PT_YB); susHandlers[8]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[9] = @@ -158,7 +159,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_9_R_LOC_XBYBZB_PT_YF); susHandlers[9]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[10] = @@ -166,7 +167,7 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_10_N_LOC_XMYBZF_PT_ZF); susHandlers[10]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, SUS::MAX_CMD_SIZE, + spiCookie = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, susMax1227::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); spiCookie->setMutexParams(MutexIF::TimeoutType::WAITING, spi::SUS_CS_TIMEOUT); susHandlers[11] = diff --git a/linux/devices/AcsBoardPolling.h b/linux/devices/AcsBoardPolling.h index 58c35786..9d642dc8 100644 --- a/linux/devices/AcsBoardPolling.h +++ b/linux/devices/AcsBoardPolling.h @@ -24,7 +24,6 @@ class AcsBoardPolling : public SystemObject, MutexIF* ipcLock; SemaphoreIF* semaphore; std::array cmdBuf; - std::array replyBuf; struct DevBase { SpiCookie* cookie = nullptr; diff --git a/linux/devices/CMakeLists.txt b/linux/devices/CMakeLists.txt index ad4e8efe..8b23566b 100644 --- a/linux/devices/CMakeLists.txt +++ b/linux/devices/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources( PRIVATE Max31865RtdPolling.cpp ScexUartReader.cpp ImtqPollingTask.cpp + SusPolling.cpp ScexDleParser.cpp ScexHelper.cpp RwPollingTask.cpp diff --git a/linux/devices/SusPolling.cpp b/linux/devices/SusPolling.cpp new file mode 100644 index 00000000..1b7d3605 --- /dev/null +++ b/linux/devices/SusPolling.cpp @@ -0,0 +1,109 @@ +#include "SusPolling.h" + +#include +#include + +using namespace returnvalue; + +SusPolling::SusPolling(object_id_t objectId, SpiComIF& spiComIF, GpioIF& gpioIF) + : SystemObject(objectId), spiComIF(spiComIF), gpioIF(gpioIF) { + semaphore = SemaphoreFactory::instance()->createBinarySemaphore(); + semaphore->acquire(); + ipcLock = MutexFactory::instance()->createMutex(); +} + +ReturnValue_t SusPolling::performOperation(uint8_t operationCode) { + while (true) { + ipcLock->lockMutex(); + state = InternalState::IDLE; + ipcLock->unlockMutex(); + semaphore->acquire(); + // TODO: Perform SUS polling here. + } + return OK; +} + +ReturnValue_t SusPolling::initialize() { return OK; } + +ReturnValue_t SusPolling::initializeInterface(CookieIF* cookie) { + auto* spiCookie = dynamic_cast(cookie); + if (spiCookie == nullptr) { + return FAILED; + } + int susIdx = addressToIndex(spiCookie->getSpiAddress()); + if (susIdx < 0) { + return FAILED; + } + susDevs[susIdx].cookie = spiCookie; + return spiComIF.initializeInterface(cookie); +} + +ReturnValue_t SusPolling::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) { + auto* spiCookie = dynamic_cast(cookie); + if (spiCookie == nullptr) { + return FAILED; + } + int susIdx = addressToIndex(spiCookie->getSpiAddress()); + if (susIdx < 0) { + return FAILED; + } + if (sendLen != sizeof(acs::SusRequest)) { + return FAILED; + } + const auto* susReq = reinterpret_cast(sendData); + if (susDevs[susIdx].mode != susReq->mode) { + } + return OK; +} + +ReturnValue_t SusPolling::getSendSuccess(CookieIF* cookie) { return OK; } + +ReturnValue_t SusPolling::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { return OK; } + +ReturnValue_t SusPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { + return OK; +} + +int SusPolling::addressToIndex(address_t addr) { + switch (addr) { + case (addresses::SUS_0): + return 0; + break; + case (addresses::SUS_1): + return 1; + break; + case (addresses::SUS_2): + return 2; + break; + case (addresses::SUS_3): + return 3; + break; + case (addresses::SUS_4): + return 4; + break; + case (addresses::SUS_5): + return 5; + break; + case (addresses::SUS_6): + return 6; + break; + case (addresses::SUS_7): + return 7; + break; + case (addresses::SUS_8): + return 8; + break; + case (addresses::SUS_9): + return 9; + break; + case (addresses::SUS_10): + return 10; + break; + case (addresses::SUS_11): + return 11; + break; + default: { + return -1; + } + } +} diff --git a/linux/devices/SusPolling.h b/linux/devices/SusPolling.h new file mode 100644 index 00000000..dcaecfe7 --- /dev/null +++ b/linux/devices/SusPolling.h @@ -0,0 +1,50 @@ +#ifndef LINUX_DEVICES_SUSPOLLING_H_ +#define LINUX_DEVICES_SUSPOLLING_H_ + +#include +#include +#include +#include +#include + +#include "devices/addresses.h" +#include "mission/devices/devicedefinitions/acsPolling.h" + +class SusPolling : public SystemObject, public ExecutableObjectIF, public DeviceCommunicationIF { + public: + SusPolling(object_id_t objectId, SpiComIF& spiComIF, GpioIF& gpioIF); + + ReturnValue_t performOperation(uint8_t operationCode) override; + ReturnValue_t initialize() override; + + private: + enum class InternalState { IDLE, BUSY } state = InternalState::IDLE; + + struct SusDev { + SpiCookie* cookie = nullptr; + bool performStartup = false; + acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF; + ReturnValue_t replyResult = returnvalue::OK; + acs::SusReply ownReply{}; + acs::SusReply readerReply{}; + }; + + MutexIF* ipcLock; + SemaphoreIF* semaphore; + uint8_t* rawReply = nullptr; + size_t dummy = 0; + SpiComIF& spiComIF; + GpioIF& gpioIF; + + std::array susDevs; + + ReturnValue_t initializeInterface(CookieIF* cookie) override; + ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override; + ReturnValue_t getSendSuccess(CookieIF* cookie) override; + ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override; + ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override; + + static int addressToIndex(address_t addr); +}; + +#endif /* LINUX_DEVICES_SUSPOLLING_H_ */ diff --git a/linux/fsfwconfig/returnvalues/classIds.h b/linux/fsfwconfig/returnvalues/classIds.h index 0a71a8b6..f4db7ffa 100644 --- a/linux/fsfwconfig/returnvalues/classIds.h +++ b/linux/fsfwconfig/returnvalues/classIds.h @@ -13,8 +13,8 @@ namespace CLASS_ID { enum { CLASS_ID_START = COMMON_CLASS_ID_END, - SCRATCH_BUFFER, // SCBU - CLASS_ID_END // [EXPORT] : [END] + SCRATCH_BUFFER, // SCBU + CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 80327c94..d5e5c0c8 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -164,8 +164,8 @@ ReturnValue_t PdecHandler::polledOperation() { // See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information. ReturnValue_t PdecHandler::irqOperation() { - ReturnValue_t result = returnvalue::OK; - int fd = -1; + ReturnValue_t result = returnvalue::OK; + int fd = -1; // Used to unmask IRQ uint32_t info = 1; @@ -183,7 +183,7 @@ ReturnValue_t PdecHandler::irqOperation() { case State::INIT: { result = handleInitState(); if (result == returnvalue::OK) { - openIrqFile(&fd); + openIrqFile(&fd); } break; } @@ -196,7 +196,7 @@ ReturnValue_t PdecHandler::irqOperation() { break; } case State::RUNNING: { - checkLocks(); + checkLocks(); checkAndHandleIrqs(fd, info); break; } @@ -238,13 +238,13 @@ ReturnValue_t PdecHandler::handleInitState() { } void PdecHandler::openIrqFile(int* fd) { - *fd = open(uioNames.irq, O_RDWR); - if (*fd < 0) { - sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" - << std::endl; - triggerEvent(OPEN_IRQ_FILE_FAILED); - state = State::WAIT_FOR_RECOVERY; - } + *fd = open(uioNames.irq, O_RDWR); + if (*fd < 0) { + sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" + << std::endl; + triggerEvent(OPEN_IRQ_FILE_FAILED); + state = State::WAIT_FOR_RECOVERY; + } } ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index e98e939c..2f0bcca2 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -105,8 +105,7 @@ class PdecHandler : public SystemObject, //! [EXPORT] : [COMMENT] Failed to pull PDEC reset to low static constexpr Event PDEC_RESET_FAILED = event::makeEvent(SUBSYSTEM_ID, 10, severity::HIGH); //! [EXPORT] : [COMMENT] Failed to open the IRQ uio file - static constexpr Event OPEN_IRQ_FILE_FAILED = - event::makeEvent(SUBSYSTEM_ID, 11, severity::HIGH); + static constexpr Event OPEN_IRQ_FILE_FAILED = event::makeEvent(SUBSYSTEM_ID, 11, severity::HIGH); private: static const uint8_t INTERFACE_ID = CLASS_ID::PDEC_HANDLER; diff --git a/mission/controller/AcsController.h b/mission/controller/AcsController.h index 6d31ae49..f59a4605 100644 --- a/mission/controller/AcsController.h +++ b/mission/controller/AcsController.h @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include "acs/ActuatorCmd.h" diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index a161b0eb..e1371aa2 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include @@ -112,18 +112,18 @@ class ThermalController : public ExtendedControllerBase { TMP1075::Tmp1075Dataset tmp1075SetIfBoard; // SUS - SUS::SusDataset susSet0; - SUS::SusDataset susSet1; - SUS::SusDataset susSet2; - SUS::SusDataset susSet3; - SUS::SusDataset susSet4; - SUS::SusDataset susSet5; - SUS::SusDataset susSet6; - SUS::SusDataset susSet7; - SUS::SusDataset susSet8; - SUS::SusDataset susSet9; - SUS::SusDataset susSet10; - SUS::SusDataset susSet11; + susMax1227::SusDataset susSet0; + susMax1227::SusDataset susSet1; + susMax1227::SusDataset susSet2; + susMax1227::SusDataset susSet3; + susMax1227::SusDataset susSet4; + susMax1227::SusDataset susSet5; + susMax1227::SusDataset susSet6; + susMax1227::SusDataset susSet7; + susMax1227::SusDataset susSet8; + susMax1227::SusDataset susSet9; + susMax1227::SusDataset susSet10; + susMax1227::SusDataset susSet11; // TempLimits TempLimits acsBoardLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0); diff --git a/mission/controller/acs/SensorValues.h b/mission/controller/acs/SensorValues.h index 6323b326..79c3dfe1 100644 --- a/mission/controller/acs/SensorValues.h +++ b/mission/controller/acs/SensorValues.h @@ -4,13 +4,13 @@ #include #include #include +#include #include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h" #include "fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h" #include "fsfw_hal/devicehandlers/MgmRM3100Handler.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" #include "mission/devices/devicedefinitions/GPSDefinitions.h" -#include "mission/devices/devicedefinitions/SusDefinitions.h" namespace ACS { @@ -36,19 +36,19 @@ class SensorValues { imtq::RawMtmMeasurementNoTorque imtqMgmSet = imtq::RawMtmMeasurementNoTorque(objects::IMTQ_HANDLER); - std::array susSets{ - SUS::SusDataset(objects::SUS_0_N_LOC_XFYFZM_PT_XF), - SUS::SusDataset(objects::SUS_1_N_LOC_XBYFZM_PT_XB), - SUS::SusDataset(objects::SUS_2_N_LOC_XFYBZB_PT_YB), - SUS::SusDataset(objects::SUS_3_N_LOC_XFYBZF_PT_YF), - SUS::SusDataset(objects::SUS_4_N_LOC_XMYFZF_PT_ZF), - SUS::SusDataset(objects::SUS_5_N_LOC_XFYMZB_PT_ZB), - SUS::SusDataset(objects::SUS_6_R_LOC_XFYBZM_PT_XF), - SUS::SusDataset(objects::SUS_7_R_LOC_XBYBZM_PT_XB), - SUS::SusDataset(objects::SUS_8_R_LOC_XBYBZB_PT_YB), - SUS::SusDataset(objects::SUS_9_R_LOC_XBYBZB_PT_YF), - SUS::SusDataset(objects::SUS_10_N_LOC_XMYBZF_PT_ZF), - SUS::SusDataset(objects::SUS_11_R_LOC_XBYMZB_PT_ZB), + std::array susSets{ + susMax1227::SusDataset(objects::SUS_0_N_LOC_XFYFZM_PT_XF), + susMax1227::SusDataset(objects::SUS_1_N_LOC_XBYFZM_PT_XB), + susMax1227::SusDataset(objects::SUS_2_N_LOC_XFYBZB_PT_YB), + susMax1227::SusDataset(objects::SUS_3_N_LOC_XFYBZF_PT_YF), + susMax1227::SusDataset(objects::SUS_4_N_LOC_XMYFZF_PT_ZF), + susMax1227::SusDataset(objects::SUS_5_N_LOC_XFYMZB_PT_ZB), + susMax1227::SusDataset(objects::SUS_6_R_LOC_XFYBZM_PT_XF), + susMax1227::SusDataset(objects::SUS_7_R_LOC_XBYBZM_PT_XB), + susMax1227::SusDataset(objects::SUS_8_R_LOC_XBYBZB_PT_YB), + susMax1227::SusDataset(objects::SUS_9_R_LOC_XBYBZB_PT_YF), + susMax1227::SusDataset(objects::SUS_10_N_LOC_XMYBZF_PT_ZF), + susMax1227::SusDataset(objects::SUS_11_R_LOC_XBYMZB_PT_ZB), }; AdisGyroPrimaryDataset gyr0AdisSet = AdisGyroPrimaryDataset(objects::GYRO_0_ADIS_HANDLER); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 0b053e99..50ffa0cb 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -43,25 +43,25 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { break; } case (ComStates::WRITE_SETUP): { - *id = SUS::WRITE_SETUP; + *id = susMax1227::WRITE_SETUP; return buildCommandFromCommand(*id, nullptr, 0); } case (ComStates::EXT_CLOCKED_CONVERSIONS): { - *id = SUS::READ_EXT_TIMED_CONVERSIONS; + *id = susMax1227::READ_EXT_TIMED_CONVERSIONS; return buildCommandFromCommand(*id, nullptr, 0); } case (ComStates::START_INT_CLOCKED_CONVERSIONS): { - *id = SUS::START_INT_TIMED_CONVERSIONS; + *id = susMax1227::START_INT_TIMED_CONVERSIONS; comState = ComStates::READ_INT_CLOCKED_CONVERSIONS; return buildCommandFromCommand(*id, nullptr, 0); } case (ComStates::READ_INT_CLOCKED_CONVERSIONS): { - *id = SUS::READ_INT_TIMED_CONVERSIONS; + *id = susMax1227::READ_INT_TIMED_CONVERSIONS; comState = ComStates::START_INT_CLOCKED_CONVERSIONS; return buildCommandFromCommand(*id, nullptr, 0); } case (ComStates::EXT_CLOCKED_TEMP): { - *id = SUS::READ_EXT_TIMED_TEMPS; + *id = susMax1227::READ_EXT_TIMED_TEMPS; return buildCommandFromCommand(*id, nullptr, 0); } } @@ -70,7 +70,7 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) { ReturnValue_t SusHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) { if (comState == ComStates::WRITE_SETUP) { - *id = SUS::WRITE_SETUP; + *id = susMax1227::WRITE_SETUP; return buildCommandFromCommand(*id, nullptr, 0); } return NOTHING_TO_SEND; @@ -81,32 +81,32 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman size_t commandDataLen) { using namespace max1227; switch (deviceCommand) { - case (SUS::WRITE_SETUP): { + case (susMax1227::WRITE_SETUP): { if (clkMode == ClkModes::INT_CLOCKED) { - cmdBuffer[0] = SUS::SETUP_INT_CLOKED; + cmdBuffer[0] = susMax1227::SETUP_INT_CLOKED; } else { - cmdBuffer[0] = SUS::SETUP_EXT_CLOCKED; + cmdBuffer[0] = susMax1227::SETUP_EXT_CLOCKED; } rawPacket = cmdBuffer; rawPacketLen = 1; break; } - case (SUS::START_INT_TIMED_CONVERSIONS): { + case (susMax1227::START_INT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); cmdBuffer[0] = max1227::buildResetByte(true); - cmdBuffer[1] = SUS::CONVERSION; + cmdBuffer[1] = susMax1227::CONVERSION; rawPacket = cmdBuffer; rawPacketLen = 2; break; } - case (SUS::READ_INT_TIMED_CONVERSIONS): { + case (susMax1227::READ_INT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - rawPacketLen = SUS::SIZE_READ_INT_CONVERSIONS; + rawPacketLen = susMax1227::SIZE_READ_INT_CONVERSIONS; break; } - case (SUS::READ_EXT_TIMED_CONVERSIONS): { + case (susMax1227::READ_EXT_TIMED_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; for (uint8_t idx = 0; idx < 6; idx++) { @@ -114,10 +114,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman cmdBuffer[idx * 2 + 1] = 0; } cmdBuffer[12] = 0x00; - rawPacketLen = SUS::SIZE_READ_EXT_CONVERSIONS; + rawPacketLen = susMax1227::SIZE_READ_EXT_CONVERSIONS; break; } - case (SUS::READ_EXT_TIMED_TEMPS): { + case (susMax1227::READ_EXT_TIMED_TEMPS): { cmdBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, true); std::memset(cmdBuffer + 1, 0, 24); rawPacket = cmdBuffer; @@ -131,13 +131,13 @@ ReturnValue_t SusHandler::buildCommandFromCommand(DeviceCommandId_t deviceComman } void SusHandler::fillCommandAndReplyMap() { - insertInCommandAndReplyMap(SUS::WRITE_SETUP, 1); - insertInCommandAndReplyMap(SUS::START_INT_TIMED_CONVERSIONS, 1); - insertInCommandAndReplyMap(SUS::READ_INT_TIMED_CONVERSIONS, 1, &dataset, - SUS::SIZE_READ_INT_CONVERSIONS); - insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_CONVERSIONS, 1, &dataset, - SUS::SIZE_READ_EXT_CONVERSIONS); - insertInCommandAndReplyMap(SUS::READ_EXT_TIMED_TEMPS, 1); + insertInCommandAndReplyMap(susMax1227::WRITE_SETUP, 1); + insertInCommandAndReplyMap(susMax1227::START_INT_TIMED_CONVERSIONS, 1); + insertInCommandAndReplyMap(susMax1227::READ_INT_TIMED_CONVERSIONS, 1, &dataset, + susMax1227::SIZE_READ_INT_CONVERSIONS); + insertInCommandAndReplyMap(susMax1227::READ_EXT_TIMED_CONVERSIONS, 1, &dataset, + susMax1227::SIZE_READ_EXT_CONVERSIONS); + insertInCommandAndReplyMap(susMax1227::READ_EXT_TIMED_TEMPS, 1); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSize, @@ -149,16 +149,16 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, size_t remainingSiz ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::WRITE_SETUP: { + case susMax1227::WRITE_SETUP: { if (getMode() == _MODE_START_UP) { commandExecuted = true; } return returnvalue::OK; } - case SUS::START_INT_TIMED_CONVERSIONS: { + case susMax1227::START_INT_TIMED_CONVERSIONS: { return returnvalue::OK; } - case SUS::READ_INT_TIMED_CONVERSIONS: { + case susMax1227::READ_INT_TIMED_CONVERSIONS: { PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = max1227::getTemperature(((packet[0] & 0x0f) << 8) | packet[1]); for (uint8_t idx = 0; idx < 6; idx++) { @@ -168,7 +168,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8 printDataset(); break; } - case (SUS::READ_EXT_TIMED_CONVERSIONS): { + case (susMax1227::READ_EXT_TIMED_CONVERSIONS): { PoolReadGuard readSet(&dataset); for (uint8_t idx = 0; idx < 6; idx++) { dataset.channels[idx] = packet[idx * 2 + 1] << 8 | packet[idx * 2 + 2]; @@ -181,7 +181,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8 printDataset(); break; } - case (SUS::READ_EXT_TIMED_TEMPS): { + case (susMax1227::READ_EXT_TIMED_TEMPS): { PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = max1227::getTemperature(((packet[23] & 0x0f) << 8) | packet[24]); dataset.temperatureCelcius.setValid(true); @@ -200,8 +200,8 @@ uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { retu ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(SUS::TEMPERATURE_C, &tempC); - localDataPoolMap.emplace(SUS::CHANNEL_VEC, &channelVec); + localDataPoolMap.emplace(susMax1227::TEMPERATURE_C, &tempC); + localDataPoolMap.emplace(susMax1227::CHANNEL_VEC, &channelVec); poolManager.subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams(dataset.getSid(), false, 5.0)); return returnvalue::OK; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 5645c47d..37aa2bb7 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -2,8 +2,8 @@ #define MISSION_DEVICES_SUSHANDLER_H_ #include +#include -#include "devicedefinitions/SusDefinitions.h" #include "events/subsystemIdRanges.h" #include "fsfw/globalfunctions/PeriodicOperationDivider.h" #include "mission/devices/max1227.h" @@ -71,7 +71,7 @@ class SusHandler : public DeviceHandlerBase { bool goToNormalModeImmediately = false; bool commandExecuted = false; - SUS::SusDataset dataset; + susMax1227::SusDataset dataset; // Read temperature in each alternating communication step when using // externally clocked mode ClkModes clkMode = ClkModes::INT_CLOCKED; @@ -79,7 +79,7 @@ class SusHandler : public DeviceHandlerBase { PoolEntry channelVec = PoolEntry({0, 0, 0, 0, 0, 0}); uint8_t susIdx = 0; - uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; + uint8_t cmdBuffer[susMax1227::MAX_CMD_SIZE]; ComStates comState = ComStates::IDLE; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; diff --git a/mission/devices/devicedefinitions/acsPolling.h b/mission/devices/devicedefinitions/acsPolling.h index 7398c199..eb4a7344 100644 --- a/mission/devices/devicedefinitions/acsPolling.h +++ b/mission/devices/devicedefinitions/acsPolling.h @@ -76,6 +76,16 @@ struct MgmLis3Reply { int16_t temperatureRaw = thermal::INVALID_TEMPERATURE; }; +struct SusRequest { + SimpleSensorMode mode = SimpleSensorMode::OFF; +}; + +struct SusReply { + bool dataWasSet = false; + uint16_t tempRaw = 0; + uint16_t channelsRaw[6]{}; +}; + } // namespace acs #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_ACSPOLLING_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/susMax1227Helpers.h similarity index 98% rename from mission/devices/devicedefinitions/SusDefinitions.h rename to mission/devices/devicedefinitions/susMax1227Helpers.h index 59ff5d24..a75547ec 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/susMax1227Helpers.h @@ -6,7 +6,7 @@ #include -namespace SUS { +namespace susMax1227 { static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending @@ -72,6 +72,6 @@ class SusDataset : public StaticLocalDataSet { lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); lp_vec_t channels = lp_vec_t(sid.objectId, CHANNEL_VEC, this); }; -} // namespace SUS +} // namespace susMax1227 #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ */ diff --git a/mission/system/objects/ComSubsystem.cpp b/mission/system/objects/ComSubsystem.cpp index 9df7e72b..c495729c 100644 --- a/mission/system/objects/ComSubsystem.cpp +++ b/mission/system/objects/ComSubsystem.cpp @@ -184,7 +184,7 @@ void ComSubsystem::startRxAndTxLowRateSeq() { void ComSubsystem::checkTransmitterCountdown() { if (transmitterCountdown.hasTimedOut()) { - triggerEvent(TX_TIMER_EXPIRED, transmitterTimeout); + triggerEvent(TX_TIMER_EXPIRED, transmitterTimeout); startTransition(com::Submode::RX_ONLY, SUBMODE_NONE); countdownActive = false; } diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index 831b4cec..854a877b 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -1,24 +1,23 @@ #ifndef MISSION_SYSTEM_COMSUBSYSTEM_H_ #define MISSION_SYSTEM_COMSUBSYSTEM_H_ +#include #include #include #include #include -#include #include "mission/comDefs.h" class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { public: + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::COM_SUBSYSTEM; - static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::COM_SUBSYSTEM; - - //! [EXPORT] : [COMMENT] The transmit timer to protect the Syrlinks expired - //! P1: The current timer value - static const Event TX_TIMER_EXPIRED = MAKE_EVENT(1, severity::INFO); - //! [EXPORT] : [COMMENT] Transmitter will be turned on due to detection of bitlock - static const Event BIT_LOCK_TX_ON = MAKE_EVENT(2, severity::INFO); + //! [EXPORT] : [COMMENT] The transmit timer to protect the Syrlinks expired + //! P1: The current timer value + static const Event TX_TIMER_EXPIRED = MAKE_EVENT(1, severity::INFO); + //! [EXPORT] : [COMMENT] Transmitter will be turned on due to detection of bitlock + static const Event BIT_LOCK_TX_ON = MAKE_EVENT(2, severity::INFO); /** * @brief Constructor @@ -27,7 +26,8 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { * @param maxNumberOfSequences * @param maxNumberOfTables * @param transmitterTimeout Maximum time the transmitter of the syrlinks - * will be enabled + * will + * be enabled */ ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables, uint32_t transmitterTimeout);