From 520b8d0700a54fc3525d481bf359efcc33700bd3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Apr 2024 14:43:32 +0200 Subject: [PATCH] separate store and stream file commands --- linux/payload/FreshMpsocHandler.cpp | 23 ++++++++++++++----- linux/payload/FreshMpsocHandler.h | 3 ++- linux/payload/plocMpsocHelpers.h | 34 +++++++++++++++++++++++++---- tmtc | 2 +- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/linux/payload/FreshMpsocHandler.cpp b/linux/payload/FreshMpsocHandler.cpp index ef293ae1..f1374697 100644 --- a/linux/payload/FreshMpsocHandler.cpp +++ b/linux/payload/FreshMpsocHandler.cpp @@ -516,7 +516,7 @@ ReturnValue_t FreshMpsocHandler::executeRegularCmd(ActionId_t actionId, break; } case (mpsoc::TC_SIMPLEX_STREAM_FILE): { - result = commandTcSimplexSendFile(commandData, commandDataLen); + result = commandTcSimplexStreamFile(commandData, commandDataLen); break; } case (mpsoc::TC_DOWNLINK_DATA_MODULATE): { @@ -669,14 +669,25 @@ ReturnValue_t FreshMpsocHandler::commandTcCamTakePic(const uint8_t* commandData, return returnvalue::OK; } -ReturnValue_t FreshMpsocHandler::commandTcSimplexSendFile(const uint8_t* commandData, - size_t commandDataLen) { - mpsoc::TcSimplexSendFile tcSimplexSendFile(spParams, commandSequenceCount); - ReturnValue_t result = tcSimplexSendFile.setPayload(commandData, commandDataLen); +ReturnValue_t FreshMpsocHandler::commandTcSimplexStreamFile(const uint8_t* commandData, + size_t commandDataLen) { + mpsoc::TcSimplexStreamFile tcSimplexStreamFile(spParams, commandSequenceCount); + ReturnValue_t result = tcSimplexStreamFile.setPayload(commandData, commandDataLen); if (result != returnvalue::OK) { return result; } - finishAndSendTc(mpsoc::TC_SIMPLEX_STREAM_FILE, tcSimplexSendFile); + finishAndSendTc(mpsoc::TC_SIMPLEX_STREAM_FILE, tcSimplexStreamFile); + return returnvalue::OK; +} + +ReturnValue_t FreshMpsocHandler::commandTcSimplexStoreFile(const uint8_t* commandData, + size_t commandDataLen) { + mpsoc::TcSimplexStoreFile tcSimplexStoreFile(spParams, commandSequenceCount); + ReturnValue_t result = tcSimplexStoreFile.setPayload(commandData, commandDataLen); + if (result != returnvalue::OK) { + return result; + } + finishAndSendTc(mpsoc::TC_SIMPLEX_STORE_FILE, tcSimplexStoreFile); return returnvalue::OK; } diff --git a/linux/payload/FreshMpsocHandler.h b/linux/payload/FreshMpsocHandler.h index 9d9ec1d6..e17a3d33 100644 --- a/linux/payload/FreshMpsocHandler.h +++ b/linux/payload/FreshMpsocHandler.h @@ -183,7 +183,8 @@ class FreshMpsocHandler : public FreshDeviceHandlerBase, public CommandsActionsI ReturnValue_t commandTcCamCmdSend(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcModeIdle(); ReturnValue_t commandTcCamTakePic(const uint8_t* commandData, size_t commandDataLen); - ReturnValue_t commandTcSimplexSendFile(const uint8_t* commandData, size_t commandDataLen); + ReturnValue_t commandTcSimplexStreamFile(const uint8_t* commandData, size_t commandDataLen); + ReturnValue_t commandTcSimplexStoreFile(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcDownlinkDataModulate(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t commandTcModeSnapshot(); diff --git a/linux/payload/plocMpsocHelpers.h b/linux/payload/plocMpsocHelpers.h index a06b2b1e..783a2fdc 100644 --- a/linux/payload/plocMpsocHelpers.h +++ b/linux/payload/plocMpsocHelpers.h @@ -81,7 +81,7 @@ enum FileAccessModes : uint8_t { static constexpr uint32_t HK_SET_ID = 0; static constexpr uint32_t DEADBEEF_ADDR = 0x40000004; -static constexpr uint32_t DEADBEEF_VALUE= 0xdeadbeef; +static constexpr uint32_t DEADBEEF_VALUE = 0xdeadbeef; namespace poolid { enum { @@ -157,7 +157,6 @@ static constexpr DeviceCommandId_t TC_FLASH_READ_FULL_FILE = 30; static const DeviceCommandId_t TC_SIMPLEX_STORE_FILE = 31; static const DeviceCommandId_t TC_VERIFY_BOOT = 32; - // Will reset the sequence count of the OBSW. Not required anymore after MPSoC update. static const DeviceCommandId_t OBSW_RESET_SEQ_COUNT_LEGACY = 50; @@ -901,9 +900,36 @@ class TcCamTakePic : public TcBase { /** * @brief Class to build simplex send file command */ -class TcSimplexSendFile : public TcBase { +class TcSimplexStreamFile : public TcBase { public: - TcSimplexSendFile(ploc::SpTcParams params, uint16_t sequenceCount) + TcSimplexStreamFile(ploc::SpTcParams params, uint16_t sequenceCount) + : TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {} + + ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) { + if (commandDataLen > MAX_DATA_LENGTH) { + return INVALID_LENGTH; + } + std::string fileName(reinterpret_cast(commandData)); + if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) { + return FILENAME_TOO_LONG; + } + + std::memcpy(payloadStart, fileName.data(), fileName.length()); + payloadStart[fileName.length()] = 0; + spParams.setFullPayloadLen(fileName.length() + 1); + return returnvalue::OK; + } + + private: + static constexpr size_t MAX_DATA_LENGTH = 256; +}; + +/** + * @brief Class to build simplex send file command + */ +class TcSimplexStoreFile : public TcBase { + public: + TcSimplexStoreFile(ploc::SpTcParams params, uint16_t sequenceCount) : TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {} ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) { diff --git a/tmtc b/tmtc index 18860ec2..05d59552 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 18860ec2c670230722f47a149a2486377a75da52 +Subproject commit 05d595523624e0388d74e5f09ac3e4d3657ebf91