diff --git a/bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h b/bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h index a57b3c26..1ed6e298 100644 --- a/bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h +++ b/bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h @@ -71,7 +71,7 @@ public: static const uint8_t INTERFACE_ID = CLASS_ID::MPSOC_CMD; //! [EXPORT] : [COMMENT] Received command with invalid length - static const ReturnValue_t INVALID_LENGTH = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t INVALID_LENGTH = MAKE_RETURN_CODE(0xC0); /** * @brief Constructor @@ -212,7 +212,6 @@ public: * @brief Constructor */ TcMemWrite(uint16_t sequenceCount) : TcBase(apid::TC_MEM_WRITE, sequenceCount) { - this->setPacketDataLength(PACKET_LENGTH); } protected: @@ -223,21 +222,22 @@ protected: if (result != RETURN_OK) { return result; } - std::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE); - std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE, - commandData + MEM_ADDRESS_SIZE, MEM_DATA_SIZE); + std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); + uint16_t memLen = *(commandData + MEM_ADDRESS_SIZE) << 8 + | *(commandData + MEM_ADDRESS_SIZE + 1); + this->setPacketDataLength(memLen * 4 + FIX_LENGTH - 1); return result; } private: - static const size_t COMMAND_LENGTH = 8; - static const uint16_t PACKET_LENGTH = 9; + // Min length consists of 4 byte address, 2 byte mem length field, 4 byte data (1 word) + static const size_t MIN_COMMAND_DATA_LENGTH = 10; static const size_t MEM_ADDRESS_SIZE = 4; - static const size_t MEM_DATA_SIZE = 4; + static const size_t FIX_LENGTH = 8; ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen != COMMAND_LENGTH) { + if (commandDataLen < MIN_COMMAND_DATA_LENGTH) { return INVALID_LENGTH; } return RETURN_OK; diff --git a/bsp_q7s/devices/ploc/CMakeLists.txt b/bsp_q7s/devices/ploc/CMakeLists.txt index 2a80d64c..0babd089 100644 --- a/bsp_q7s/devices/ploc/CMakeLists.txt +++ b/bsp_q7s/devices/ploc/CMakeLists.txt @@ -4,5 +4,4 @@ target_sources(${TARGET_NAME} PRIVATE PlocMemoryDumper.cpp PlocMPSoCHandler.cpp PlocMPSoCHelper.cpp - MPSoCSequenceCount.cpp ) diff --git a/bsp_q7s/devices/ploc/MPSoCSequenceCount.cpp b/bsp_q7s/devices/ploc/MPSoCSequenceCount.cpp deleted file mode 100644 index 450900d4..00000000 --- a/bsp_q7s/devices/ploc/MPSoCSequenceCount.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "fsfw/serviceInterface/ServiceInterfaceStream.h" -#include "MPSoCSequenceCount.h" - -MPSoCSequenceCount::MPSoCSequenceCount() : SourceSequenceCounter() { -} - -ReturnValue_t MPSoCSequenceCount::compare(uint16_t recvSeqCount) { - if (recvSeqCount != *this) { - sif::warning << "MPSoCSequenceCount::compare: Packet sequence count mismatch. Received: " - << recvSeqCount << ", Expected: " << *this << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - -MPSoCSequenceCount::~MPSoCSequenceCount() { -} - diff --git a/bsp_q7s/devices/ploc/MPSoCSequenceCount.h b/bsp_q7s/devices/ploc/MPSoCSequenceCount.h deleted file mode 100644 index 9495f6a2..00000000 --- a/bsp_q7s/devices/ploc/MPSoCSequenceCount.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef BSP_Q7S_DEVICES_PLOC_MPSOCSEQUENCECOUNT_H_ -#define BSP_Q7S_DEVICES_PLOC_MPSOCSEQUENCECOUNT_H_ - -#include "fsfw/tmtcservices/SourceSequenceCounter.h" -#include "fsfw/returnvalues/HasReturnvaluesIF.h" - -/** - * @brief Class to manage the sequence count of the space packets exchanged with the MPSoC of the - * PLOC. - * - * @author J. Meier - */ -class MPSoCSequenceCount : public SourceSequenceCounter { -public: - MPSoCSequenceCount(); - virtual ~MPSoCSequenceCount(); - - ReturnValue_t compare(uint16_t recvSeqCount); -}; - -#endif /* BSP_Q7S_DEVICES_PLOC_MPSOCSEQUENCECOUNT_H_ */ diff --git a/bsp_q7s/devices/ploc/PlocMPSoCHandler.cpp b/bsp_q7s/devices/ploc/PlocMPSoCHandler.cpp index b9d17a8a..0fa4eb04 100644 --- a/bsp_q7s/devices/ploc/PlocMPSoCHandler.cpp +++ b/bsp_q7s/devices/ploc/PlocMPSoCHandler.cpp @@ -207,10 +207,10 @@ ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t *start, } } uint16_t recvSeqCnt = (*(start + 2) << 8 | *(start + 3)) & PACKET_SEQUENCE_COUNT_MASK; - result = sequenceCount.compare(recvSeqCnt); - if (result != RETURN_OK) { + if (recvSeqCnt != sequenceCount) { triggerEvent(SEQ_CNT_MISMATCH, sequenceCount, recvSeqCnt); - sequenceCount = recvSeqCnt; + sequenceCount = recvSeqCnt; + return result; } return result; } diff --git a/bsp_q7s/devices/ploc/PlocMPSoCHandler.h b/bsp_q7s/devices/ploc/PlocMPSoCHandler.h index a85bf432..63eaa17b 100644 --- a/bsp_q7s/devices/ploc/PlocMPSoCHandler.h +++ b/bsp_q7s/devices/ploc/PlocMPSoCHandler.h @@ -5,8 +5,8 @@ #include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw_hal/linux/uart/UartComIF.h" #include "fsfw/ipc/QueueFactory.h" +#include "fsfw/tmtcservices/SourceSequenceCounter.h" #include "bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h" -#include "MPSoCSequenceCount.h" #include "PlocMPSoCHelper.h" /** @@ -93,7 +93,7 @@ private: MessageQueueIF* eventQueue = nullptr; - MPSoCSequenceCount sequenceCount; + SourceSequenceCounter sequenceCount; uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; diff --git a/bsp_q7s/devices/ploc/PlocMPSoCHelper.cpp b/bsp_q7s/devices/ploc/PlocMPSoCHelper.cpp index b922a44d..cc20036c 100644 --- a/bsp_q7s/devices/ploc/PlocMPSoCHelper.cpp +++ b/bsp_q7s/devices/ploc/PlocMPSoCHelper.cpp @@ -60,7 +60,7 @@ void PlocMPSoCHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; } -void PlocMPSoCHelper::setSequenceCount(MPSoCSequenceCount* sequenceCount_) { +void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) { sequenceCount = sequenceCount_; } @@ -214,8 +214,7 @@ ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size return result; } uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount(); - result = sequenceCount->compare(recvSeqCnt); - if (result != RETURN_OK) { + if (recvSeqCnt != *sequenceCount) { triggerEvent(SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt); *sequenceCount = recvSeqCnt; return result; diff --git a/bsp_q7s/devices/ploc/PlocMPSoCHelper.h b/bsp_q7s/devices/ploc/PlocMPSoCHelper.h index 8cd77e74..82e98dd7 100644 --- a/bsp_q7s/devices/ploc/PlocMPSoCHelper.h +++ b/bsp_q7s/devices/ploc/PlocMPSoCHelper.h @@ -9,8 +9,8 @@ #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw_hal/linux/uart/UartComIF.h" #include "fsfw/devicehandlers/CookieIF.h" +#include "fsfw/tmtcservices/SourceSequenceCounter.h" #include "bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h" -#include "MPSoCSequenceCount.h" /** * @brief Helper class for MPSoC of PLOC intended to accelerate large data transfers between @@ -91,7 +91,7 @@ public: /** * @brief Sets the sequence count object responsible for the sequence count handling */ - void setSequenceCount(MPSoCSequenceCount* sequenceCount_); + void setSequenceCount(SourceSequenceCounter* sequenceCount_); private: @@ -132,7 +132,7 @@ private: // Communication cookie. Must be set by the MPSoC Handler CookieIF* comCookie = nullptr; // Sequence count, must be set by Ploc MPSoC Handler - MPSoCSequenceCount* sequenceCount; + SourceSequenceCounter* sequenceCount; ReturnValue_t performFlashWrite(); ReturnValue_t sendCommand(mpsoc::TcBase* tc);