diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 69fa9399..63124dc8 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1604,12 +1604,12 @@ const HasModesIF& DeviceHandlerBase::getModeIF() const { return *this; } ModeTreeChildIF& DeviceHandlerBase::getModeTreeChildIF() { return *this; } ReturnValue_t DeviceHandlerBase::finishAction(bool success, DeviceCommandId_t action, - ReturnValue_t result) { - auto commandIter = deviceCommandMap.find(action); - if (commandIter == deviceCommandMap.end()) { - return MessageQueueIF::NO_QUEUE; - } - commandIter->second.isExecuting = false; - actionHelper.finish(success, commandIter->second.sendReplyTo, action, result); - return returnvalue::OK; + ReturnValue_t result) { + auto commandIter = deviceCommandMap.find(action); + if (commandIter == deviceCommandMap.end()) { + return MessageQueueIF::NO_QUEUE; + } + commandIter->second.isExecuting = false; + actionHelper.finish(success, commandIter->second.sendReplyTo, action, result); + return returnvalue::OK; } diff --git a/src/fsfw/globalfunctions/DleParser.cpp b/src/fsfw/globalfunctions/DleParser.cpp index 90adfa7a..cc695bab 100644 --- a/src/fsfw/globalfunctions/DleParser.cpp +++ b/src/fsfw/globalfunctions/DleParser.cpp @@ -11,8 +11,7 @@ DleParser::DleParser(SimpleRingBuffer& decodeRingBuf, DleEncoder& decoder, BufPa : decodeRingBuf(decodeRingBuf), decoder(decoder), encodedBuf(encodedBuf), - decodedBuf(decodedBuf) { -} + decodedBuf(decodedBuf) {} ReturnValue_t DleParser::passData(const uint8_t* data, size_t len) { if (data == nullptr or len == 0) { @@ -24,7 +23,7 @@ ReturnValue_t DleParser::passData(const uint8_t* data, size_t len) { ReturnValue_t DleParser::parseRingBuf(size_t& readSize) { ctx.setType(DleParser::ContextType::NONE); size_t availableData = decodeRingBuf.getAvailableReadData(); - if(availableData == 0) { + if (availableData == 0) { return NO_PACKET_FOUND; } if (availableData > encodedBuf.second) { @@ -106,7 +105,7 @@ void DleParser::defaultFoundPacketHandler(uint8_t* packet, size_t len, void* arg } void DleParser::defaultErrorHandler() { - if(ctx.getType() != DleParser::ContextType::ERROR) { + if (ctx.getType() != DleParser::ContextType::ERROR) { errorPrinter("No error"); return; } @@ -126,7 +125,8 @@ void DleParser::defaultErrorHandler() { case (ErrorTypes::ENCODED_BUF_TOO_SMALL): case (ErrorTypes::DECODING_BUF_TOO_SMALL): { char opt[64]; - snprintf(opt, sizeof(opt), ": Too small for packet with length %zu", ctx.decodedPacket.second); + snprintf(opt, sizeof(opt), ": Too small for packet with length %zu", + ctx.decodedPacket.second); if (ctx.error.first == ErrorTypes::ENCODED_BUF_TOO_SMALL) { errorPrinter("Encoded buf too small", opt); } else { @@ -168,10 +168,6 @@ ReturnValue_t DleParser::confirmBytesRead(size_t bytesRead) { return decodeRingBuf.deleteData(bytesRead); } -const DleParser::Context& DleParser::getContext() { - return ctx; -} +const DleParser::Context& DleParser::getContext() { return ctx; } -void DleParser::reset() { - decodeRingBuf.clear(); -} +void DleParser::reset() { decodeRingBuf.clear(); } diff --git a/src/fsfw/modes/ModeMessage.cpp b/src/fsfw/modes/ModeMessage.cpp index ecc52c94..efe6d534 100644 --- a/src/fsfw/modes/ModeMessage.cpp +++ b/src/fsfw/modes/ModeMessage.cpp @@ -24,3 +24,13 @@ void ModeMessage::setCantReachMode(CommandMessage* message, ReturnValue_t reason message->setParameter(reason); message->setParameter2(0); } + +void ModeMessage::setModeAnnounceMessage(CommandMessage& message, bool recursive) { + Command_t cmd; + if (recursive) { + cmd = CMD_MODE_ANNOUNCE_RECURSIVELY; + } else { + cmd = CMD_MODE_ANNOUNCE; + } + message.setCommand(cmd); +} diff --git a/src/fsfw/modes/ModeMessage.h b/src/fsfw/modes/ModeMessage.h index 84429e84..1582ccd4 100644 --- a/src/fsfw/modes/ModeMessage.h +++ b/src/fsfw/modes/ModeMessage.h @@ -1,43 +1,42 @@ #ifndef FSFW_MODES_MODEMESSAGE_H_ #define FSFW_MODES_MODEMESSAGE_H_ -#include "../ipc/CommandMessage.h" +#include "fsfw/ipc/CommandMessage.h" typedef uint32_t Mode_t; typedef uint8_t Submode_t; class ModeMessage { - private: - ModeMessage(); - public: static const uint8_t MESSAGE_ID = messagetypes::MODE_COMMAND; - static const Command_t CMD_MODE_COMMAND = - MAKE_COMMAND_ID(0x01); //!> Command to set the specified Mode, replies are: REPLY_MODE_REPLY, - //! REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, - //! as this will break the subsystem mode machine!! - static const Command_t CMD_MODE_COMMAND_FORCED = MAKE_COMMAND_ID( - 0xF1); //!> Command to set the specified Mode, regardless of external control flag, replies - //! are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any - //! replies, as this will break the subsystem mode machine!! - static const Command_t REPLY_MODE_REPLY = - MAKE_COMMAND_ID(0x02); //!> Reply to a CMD_MODE_COMMAND or CMD_MODE_READ - static const Command_t REPLY_MODE_INFO = - MAKE_COMMAND_ID(0x03); //!> Unrequested info about the current mode (used for composites to - //! inform their container of a changed mode) - static const Command_t REPLY_CANT_REACH_MODE = MAKE_COMMAND_ID( - 0x04); //!> Reply in case a mode command can't be executed. Par1: returnCode, Par2: 0 - static const Command_t REPLY_WRONG_MODE_REPLY = - MAKE_COMMAND_ID(0x05); //!> Reply to a CMD_MODE_COMMAND, indicating that a mode was commanded - //! and a transition started but was aborted; the parameters contain - //! the mode that was reached - static const Command_t CMD_MODE_READ = MAKE_COMMAND_ID( - 0x06); //!> Command to read the current mode and reply with a REPLY_MODE_REPLY - static const Command_t CMD_MODE_ANNOUNCE = MAKE_COMMAND_ID( - 0x07); //!> Command to trigger an ModeInfo Event. This command does NOT have a reply. - static const Command_t CMD_MODE_ANNOUNCE_RECURSIVELY = - MAKE_COMMAND_ID(0x08); //!> Command to trigger an ModeInfo Event and to send this command to - //! every child. This command does NOT have a reply. + //!> Command to set the specified Mode, replies are: REPLY_MODE_REPLY, + //! REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, + //! as this will break the subsystem mode machine!! + static const Command_t CMD_MODE_COMMAND = MAKE_COMMAND_ID(0x01); + //!> Command to set the specified Mode, regardless of external control flag, replies + //! are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any + //! replies, as this will break the subsystem mode machine!! + static const Command_t CMD_MODE_COMMAND_FORCED = MAKE_COMMAND_ID(0xF1); + //!> Reply to a CMD_MODE_COMMAND or CMD_MODE_READ + static const Command_t REPLY_MODE_REPLY = MAKE_COMMAND_ID(0x02); + //!> Unrequested info about the current mode (used for composites to + //! inform their container of a changed mode) + static const Command_t REPLY_MODE_INFO = MAKE_COMMAND_ID(0x03); + //!> Reply in case a mode command can't be executed. Par1: returnCode, Par2: 0 + static const Command_t REPLY_CANT_REACH_MODE = MAKE_COMMAND_ID(0x04); + //!> Reply to a CMD_MODE_COMMAND, indicating that a mode was commanded + //! and a transition started but was aborted; the parameters contain + //! the mode that was reached + static const Command_t REPLY_WRONG_MODE_REPLY = MAKE_COMMAND_ID(0x05); + //!> Command to read the current mode and reply with a REPLY_MODE_REPLY + static const Command_t CMD_MODE_READ = MAKE_COMMAND_ID(0x06); + //!> Command to trigger an ModeInfo Event. This command does NOT have a reply. + static const Command_t CMD_MODE_ANNOUNCE = MAKE_COMMAND_ID(0x07); + //!> Command to trigger an ModeInfo Event and to send this command to + //! every child. This command does NOT have a reply. + static const Command_t CMD_MODE_ANNOUNCE_RECURSIVELY = MAKE_COMMAND_ID(0x08); + + ModeMessage() = delete; static Mode_t getMode(const CommandMessage* message); static Submode_t getSubmode(const CommandMessage* message); @@ -45,6 +44,7 @@ class ModeMessage { static void setModeMessage(CommandMessage* message, Command_t command, Mode_t mode, Submode_t submode); + static void setModeAnnounceMessage(CommandMessage& message, bool recursive); static void setCantReachMode(CommandMessage* message, ReturnValue_t reason); static void clear(CommandMessage* message); }; diff --git a/src/fsfw/pus/CService200ModeCommanding.cpp b/src/fsfw/pus/CService200ModeCommanding.cpp index 809fb02b..f5928be7 100644 --- a/src/fsfw/pus/CService200ModeCommanding.cpp +++ b/src/fsfw/pus/CService200ModeCommanding.cpp @@ -54,15 +54,26 @@ ReturnValue_t CService200ModeCommanding::checkInterfaceAndAcquireMessageQueue( ReturnValue_t CService200ModeCommanding::prepareCommand(CommandMessage *message, uint8_t subservice, const uint8_t *tcData, size_t tcDataLen, uint32_t *state, object_id_t objectId) { - ModePacket modeCommandPacket; - ReturnValue_t result = - modeCommandPacket.deSerialize(&tcData, &tcDataLen, SerializeIF::Endianness::BIG); - if (result != returnvalue::OK) { - return result; + ReturnValue_t result = returnvalue::OK; + if (subservice == Subservice::COMMAND_MODE_ANNCOUNCE or + subservice == Subservice::COMMAND_MODE_ANNOUNCE_RECURSIVELY) { + bool recursive = true; + if (subservice == Subservice::COMMAND_MODE_ANNCOUNCE) { + recursive = false; + } + ModeMessage::setModeAnnounceMessage(*message, recursive); + } else { + ModePacket modeCommandPacket; + ReturnValue_t result = + modeCommandPacket.deSerialize(&tcData, &tcDataLen, SerializeIF::Endianness::BIG); + if (result != returnvalue::OK) { + return result; + } + + ModeMessage::setModeMessage(message, ModeMessage::CMD_MODE_COMMAND, modeCommandPacket.getMode(), + modeCommandPacket.getSubmode()); } - ModeMessage::setModeMessage(message, ModeMessage::CMD_MODE_COMMAND, modeCommandPacket.getMode(), - modeCommandPacket.getSubmode()); return result; } diff --git a/src/fsfw/pus/servicepackets/Service200Packets.h b/src/fsfw/pus/servicepackets/Service200Packets.h index 701e3f09..3e1df55a 100644 --- a/src/fsfw/pus/servicepackets/Service200Packets.h +++ b/src/fsfw/pus/servicepackets/Service200Packets.h @@ -1,9 +1,9 @@ #ifndef FSFW_PUS_SERVICEPACKETS_SERVICE200PACKETS_H_ #define FSFW_PUS_SERVICEPACKETS_SERVICE200PACKETS_H_ -#include "../../modes/ModeMessage.h" -#include "../../serialize/SerialLinkedListAdapter.h" -#include "../../serialize/SerializeIF.h" +#include "fsfw/modes/ModeMessage.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/serialize/SerializeIF.h" /** * @brief Subservice 1, 2, 3, 4, 5 diff --git a/src/fsfw_hal/linux/uart/UartComIF.cpp b/src/fsfw_hal/linux/uart/UartComIF.cpp index df21da64..0880dec6 100644 --- a/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -1,4 +1,5 @@ #include "UartComIF.h" + #include #include #include @@ -458,5 +459,3 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) { } return returnvalue::FAILED; } - - diff --git a/src/fsfw_hal/linux/uart/UartComIF.h b/src/fsfw_hal/linux/uart/UartComIF.h index 940938d9..657e0123 100644 --- a/src/fsfw_hal/linux/uart/UartComIF.h +++ b/src/fsfw_hal/linux/uart/UartComIF.h @@ -1,15 +1,14 @@ #ifndef BSP_Q7S_COMIF_UARTCOMIF_H_ #define BSP_Q7S_COMIF_UARTCOMIF_H_ -#include "UartCookie.h" -#include "helper.h" - #include #include #include #include +#include "UartCookie.h" +#include "helper.h" /** * @brief This is the communication interface to access serial ports on linux based operating diff --git a/src/fsfw_hal/linux/uart/UartCookie.h b/src/fsfw_hal/linux/uart/UartCookie.h index 6fa2bd1b..670ef72f 100644 --- a/src/fsfw_hal/linux/uart/UartCookie.h +++ b/src/fsfw_hal/linux/uart/UartCookie.h @@ -1,14 +1,12 @@ #ifndef SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ #define SAM9G20_COMIF_COOKIES_UART_COOKIE_H_ -#include "helper.h" - #include #include #include - +#include "helper.h" /** * @brief Cookie for the UartComIF. There are many options available to configure the UART driver. diff --git a/src/fsfw_hal/linux/uart/helper.cpp b/src/fsfw_hal/linux/uart/helper.cpp index b451f457..df4b7aa8 100644 --- a/src/fsfw_hal/linux/uart/helper.cpp +++ b/src/fsfw_hal/linux/uart/helper.cpp @@ -1,8 +1,9 @@ #include "helper.h" -#include "fsfw/serviceinterface.h" #include +#include "fsfw/serviceinterface.h" + void uart::setMode(struct termios& options, UartModes mode) { if (mode == UartModes::NON_CANONICAL) { /* Disable canonical mode */ @@ -145,6 +146,5 @@ void uart::setBaudrate(struct termios& options, UartBaudRate baud) { } int uart::readCountersAndErrors(int serialPort, serial_icounter_struct& icounter) { - return ioctl(serialPort, TIOCGICOUNT, &icounter); + return ioctl(serialPort, TIOCGICOUNT, &icounter); } - diff --git a/src/fsfw_hal/linux/uart/helper.h b/src/fsfw_hal/linux/uart/helper.h index b6a524d6..515f815b 100644 --- a/src/fsfw_hal/linux/uart/helper.h +++ b/src/fsfw_hal/linux/uart/helper.h @@ -1,8 +1,8 @@ #ifndef FSFW_HAL_LINUX_UART_HELPER_H_ #define FSFW_HAL_LINUX_UART_HELPER_H_ -#include #include +#include enum class Parity { NONE, EVEN, ODD }; @@ -56,7 +56,6 @@ void setBaudrate(struct termios& options, UartBaudRate baud); int readCountersAndErrors(int serialPort, serial_icounter_struct& icounter); -} - +} // namespace uart #endif /* FSFW_HAL_LINUX_UART_HELPER_H_ */