From 590fe6ca391719d743d49cd41f4acc5012367667 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 5 May 2022 12:48:56 +0200 Subject: [PATCH] Some RW improvements - Moved Events to definitions file - Added new event if reset occurs - Deliver state if there is an error (going to be 0, still deliver it) --- fsfw | 2 +- mission/devices/RwHandler.cpp | 31 +++++++++---------- mission/devices/RwHandler.h | 6 +--- .../devices/devicedefinitions/RwDefinitions.h | 13 ++++++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/fsfw b/fsfw index f59b05c8..71f704c9 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit f59b05c86cd54390d2a259eda770ee7935587112 +Subproject commit 71f704c980ec8847bdd0bb1bf354c8de30d3524b diff --git a/mission/devices/RwHandler.cpp b/mission/devices/RwHandler.cpp index fa8aa808..aeac93a0 100644 --- a/mission/devices/RwHandler.cpp +++ b/mission/devices/RwHandler.cpp @@ -47,11 +47,6 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { *id = RwDefinitions::GET_LAST_RESET_STATUS; internalState = InternalState::READ_TEMPERATURE; break; - case InternalState::CLEAR_RESET_STATUS: - *id = RwDefinitions::CLEAR_LAST_RESET_STATUS; - /** After reset status is cleared, reset status will be polled again for verification */ - internalState = InternalState::GET_RESET_STATUS; - break; case InternalState::READ_TEMPERATURE: *id = RwDefinitions::GET_TEMPERATURE; internalState = InternalState::GET_RW_SATUS; @@ -60,6 +55,11 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { *id = RwDefinitions::GET_RW_STATUS; internalState = InternalState::GET_RESET_STATUS; break; + case InternalState::CLEAR_RESET_STATUS: + *id = RwDefinitions::CLEAR_LAST_RESET_STATUS; + /** After reset status is cleared, reset status will be polled again for verification */ + internalState = InternalState::GET_RESET_STATUS; + break; default: sif::debug << "RwHandler::buildNormalDeviceCommand: Invalid internal step" << std::endl; break; @@ -240,8 +240,6 @@ ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_ return RETURN_OK; } -void RwHandler::setNormalDatapoolEntriesInvalid() {} - uint32_t RwHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 5000; } ReturnValue_t RwHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, @@ -336,18 +334,19 @@ void RwHandler::prepareSetSpeedCmd(const uint8_t* commandData, size_t commandDat void RwHandler::handleResetStatusReply(const uint8_t* packet) { PoolReadGuard rg(&lastResetStatusSet); uint8_t offset = 2; - uint8_t resetStatus = *(packet + offset); + uint8_t resetStatus = packet[offset]; if (resetStatus != RwDefinitions::CLEARED) { internalState = InternalState::CLEAR_RESET_STATUS; - lastResetStatusSet.lastResetStatus = resetStatus; + lastResetStatusSet.lastNonClearedResetStatus = resetStatus; + triggerEvent(RwDefinitions::RESET_OCCURED, resetStatus, 0); } - lastResetStatusSet.currentResetStatus = resetStatus; + lastResetStatusSet.lastResetStatus = resetStatus; if (debugMode) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "RwHandler::handleResetStatusReply: Last reset status: " - << static_cast(lastResetStatusSet.lastResetStatus.value) << std::endl; + << static_cast(lastResetStatusSet.lastNonClearedResetStatus.value) << std::endl; sif::info << "RwHandler::handleResetStatusReply: Current reset status: " - << static_cast(lastResetStatusSet.currentResetStatus.value) + << static_cast(lastResetStatusSet.lastResetStatus.value) << std::endl; #endif } @@ -367,11 +366,9 @@ void RwHandler::handleGetRwStatusReply(const uint8_t* packet) { statusSet.clcMode = *(packet + offset); if (statusSet.state == RwDefinitions::STATE_ERROR) { - /** - * This requires the commanding of the init reaction wheel controller command to recover - * form error state which must be handled by the FDIR instance. - */ - triggerEvent(ERROR_STATE); + // This requires the commanding of the init reaction wheel controller command to recover + // from error state which must be handled by the FDIR instance. + triggerEvent(RwDefinitions::ERROR_STATE, statusSet.state.value, 0); sif::error << "RwHandler::handleGetRwStatusReply: Reaction wheel in error state" << std::endl; } diff --git a/mission/devices/RwHandler.h b/mission/devices/RwHandler.h index 01101be8..29f71ac6 100644 --- a/mission/devices/RwHandler.h +++ b/mission/devices/RwHandler.h @@ -66,13 +66,12 @@ class RwHandler : 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; - void setNormalDatapoolEntriesInvalid() override; uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; private: - static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::RW_HANDLER; + //! [EXPORT] : [COMMENT] Action Message with invalid speed was received. Valid speeds must be in //! the range of [-65000; 1000] or [1000; 65000] @@ -86,9 +85,6 @@ class RwHandler : public DeviceHandlerBase { //! [EXPORT] : [COMMENT] Reaction wheel reply has invalid crc static const ReturnValue_t CRC_ERROR = MAKE_RETURN_CODE(0xA4); - //! [EXPORT] : [COMMENT] Reaction wheel signals an error state - static const Event ERROR_STATE = MAKE_EVENT(1, severity::HIGH); - GpioIF* gpioComIF = nullptr; gpioId_t enableGpio = gpio::NO_GPIO; bool debugMode = false; diff --git a/mission/devices/devicedefinitions/RwDefinitions.h b/mission/devices/devicedefinitions/RwDefinitions.h index c25e3f09..07f74e8e 100644 --- a/mission/devices/devicedefinitions/RwDefinitions.h +++ b/mission/devices/devicedefinitions/RwDefinitions.h @@ -9,6 +9,13 @@ namespace RwDefinitions { +static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::RW_HANDLER; + +//! [EXPORT] : [COMMENT] Reaction wheel signals an error state +static constexpr Event ERROR_STATE = MAKE_EVENT(1, severity::HIGH); + +static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::HIGH); + static const uint32_t SPI_REPLY_DELAY = 70000; // us enum PoolIds : lp_id_t { @@ -133,9 +140,11 @@ class LastResetSatus : public StaticLocalDataSet { LastResetSatus(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, LAST_RESET_ID)) {} - lp_var_t lastResetStatus = + // If a reset occurs, the status code will be cached into this variable + lp_var_t lastNonClearedResetStatus = lp_var_t(sid.objectId, PoolIds::LAST_RESET_STATUS, this); - lp_var_t currentResetStatus = + // This will always contain the last polled reset status + lp_var_t lastResetStatus = lp_var_t(sid.objectId, PoolIds::CURRRENT_RESET_STATUS, this); };