diff --git a/linux/payload/plocMpsocHelpers.h b/linux/payload/plocMpsocHelpers.h index ffd077d9..ef03359d 100644 --- a/linux/payload/plocMpsocHelpers.h +++ b/linux/payload/plocMpsocHelpers.h @@ -6,10 +6,10 @@ #include #include -#include "OBSWConfig.h" #include "eive/definitions.h" -#include "fsfw/globalfunctions/CRC.h" +#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" namespace mpsoc { @@ -838,20 +838,45 @@ class TcSimplexSendFile : public TcBase { : TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {} ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) { + if (commandDataLen < MIN_DATA_LENGTH) { + return INVALID_LENGTH; + } if (commandDataLen > MAX_DATA_LENGTH) { return INVALID_LENGTH; } - std::string fileName(reinterpret_cast(commandData)); + const uint8_t** dataPtr = &commandData; + ReturnValue_t result = SerializeAdapter::deSerialize(&chunkParameter, dataPtr, &commandDataLen, + SerializeIF::Endianness::NETWORK); + if (result != returnvalue::OK) { + return result; + } + if (chunkParameter == 0) { + return INVALID_PARAMETER; + } + std::string fileName(reinterpret_cast(*dataPtr)); if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) { return FILENAME_TOO_LONG; } - spParams.setFullPayloadLen(commandDataLen + CRC_SIZE); - std::memcpy(payloadStart, commandData, commandDataLen); + size_t currentCopyIdx = 0; + size_t payloadLen = fileName.length() + sizeof(NULL_TERMINATOR) + CRC_SIZE; + if (chunkParameter > 1) { + char divStr[12]{}; + sprintf(divStr, "DIV%03d", chunkParameter); + std::memcpy(payloadStart, divStr, DIV_STR_LEN); + payloadLen += DIV_STR_LEN; + currentCopyIdx += DIV_STR_LEN; + } + + std::memcpy(payloadStart + currentCopyIdx, *dataPtr, fileName.length()); + spParams.setFullPayloadLen(payloadLen); return returnvalue::OK; } private: - static const size_t MAX_DATA_LENGTH = 256; + uint32_t chunkParameter = 0; + static constexpr size_t MAX_DATA_LENGTH = 256; + static constexpr size_t MIN_DATA_LENGTH = 4; + static constexpr size_t DIV_STR_LEN = 6; }; /**