From cc863503acee06641220ff63c85101ac22ee5694 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 26 Apr 2024 14:36:25 +0200 Subject: [PATCH] bugfixes and improvements --- linux/payload/FreshMpsocHandler.cpp | 26 ++++++++- linux/payload/PlocMpsocSpecialComHelper.cpp | 4 +- linux/payload/plocMpsocHelpers.h | 65 ++++++++++----------- tmtc | 2 +- 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/linux/payload/FreshMpsocHandler.cpp b/linux/payload/FreshMpsocHandler.cpp index 610a7c5c..55860efa 100644 --- a/linux/payload/FreshMpsocHandler.cpp +++ b/linux/payload/FreshMpsocHandler.cpp @@ -359,7 +359,7 @@ void FreshMpsocHandler::handleTransitionToOn() { void FreshMpsocHandler::handleTransitionToOff() { if (handleHwShutdown()) { hkReport.setReportingEnabled(false); - setMode(MODE_OFF); + setMode(MODE_OFF, 0); transitionState = TransitionState::NONE; activeCmdInfo.reset(); powerState = PowerState::IDLE; @@ -476,6 +476,23 @@ ReturnValue_t FreshMpsocHandler::executeRegularCmd(ActionId_t actionId, result = commandTcMemRead(commandData, commandDataLen); break; } + case (mpsoc::TC_FLASHFOPEN): { + mpsoc::TcFlashFopen cmd(spParams, commandSequenceCount); + // C string constructor. + std::string filename = std::string(reinterpret_cast(commandData)); + if (filename.size() > mpsoc::MAX_FILENAME_SIZE) { + return mpsoc::NAME_TOO_LONG; + } + uint8_t mode = commandData[filename.size() + 2]; + cmd.setPayload(filename, mode); + result = finishAndSendTc(actionId, cmd); + break; + } + case (mpsoc::TC_FLASHFCLOSE): { + mpsoc::TcFlashFclose cmd(spParams, commandSequenceCount); + result = finishAndSendTc(actionId, cmd); + break; + } case (mpsoc::TC_FLASHDELETE): { result = commandTcFlashDelete(commandData, commandDataLen); break; @@ -518,6 +535,7 @@ ReturnValue_t FreshMpsocHandler::executeRegularCmd(ActionId_t actionId, } mpsoc::TcFlashMkfs cmd(spParams, commandSequenceCount, static_cast(commandData[0])); + sif::info << "PLOC MPSoC: Formatting Flash " << (int)commandData[0] << std::endl; result = finishAndSendTc(actionId, cmd, mpsoc::CMD_TIMEOUT_MKFS); break; } @@ -541,6 +559,10 @@ ReturnValue_t FreshMpsocHandler::executeRegularCmd(ActionId_t actionId, result = commandTcSimplexStreamFile(commandData, commandDataLen); break; } + case (mpsoc::TC_SIMPLEX_STORE_FILE): { + result = commandTcSimplexStoreFile(commandData, commandDataLen); + break; + } case (mpsoc::TC_DOWNLINK_DATA_MODULATE): { result = commandTcDownlinkDataModulate(commandData, commandDataLen); break; @@ -590,7 +612,7 @@ ReturnValue_t FreshMpsocHandler::commandTcMemRead(const uint8_t* commandData, ReturnValue_t FreshMpsocHandler::commandTcFlashDelete(const uint8_t* commandData, size_t commandDataLen) { - if (commandDataLen > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) { + if (commandDataLen > mpsoc::FILENAME_FIELD_SIZE) { return mpsoc::NAME_TOO_LONG; } ReturnValue_t result = returnvalue::OK; diff --git a/linux/payload/PlocMpsocSpecialComHelper.cpp b/linux/payload/PlocMpsocSpecialComHelper.cpp index aa97ee68..39407f87 100644 --- a/linux/payload/PlocMpsocSpecialComHelper.cpp +++ b/linux/payload/PlocMpsocSpecialComHelper.cpp @@ -224,7 +224,7 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() { ReturnValue_t PlocMpsocSpecialComHelper::flashfopen(uint8_t mode) { spParams.buf = commandBuffer; - mpsoc::FlashFopen flashFopen(spParams, *sequenceCount); + mpsoc::TcFlashFopen flashFopen(spParams, *sequenceCount); ReturnValue_t result = flashFopen.setPayload(flashReadAndWrite.mpsocFile, mode); if (result != returnvalue::OK) { return result; @@ -243,7 +243,7 @@ ReturnValue_t PlocMpsocSpecialComHelper::flashfopen(uint8_t mode) { ReturnValue_t PlocMpsocSpecialComHelper::flashfclose() { spParams.buf = commandBuffer; - mpsoc::FlashFclose flashFclose(spParams, *sequenceCount); + mpsoc::TcFlashFclose flashFclose(spParams, *sequenceCount); ReturnValue_t result = flashFclose.finishPacket(); if (result != returnvalue::OK) { return result; diff --git a/linux/payload/plocMpsocHelpers.h b/linux/payload/plocMpsocHelpers.h index dda86329..f2b4c48d 100644 --- a/linux/payload/plocMpsocHelpers.h +++ b/linux/payload/plocMpsocHelpers.h @@ -5,7 +5,6 @@ #include #include -#include "eive/definitions.h" #include "eive/eventSubsystemIds.h" #include "eive/resultClassIds.h" #include "fsfw/action/HasActionsIF.h" @@ -245,7 +244,9 @@ static constexpr size_t CRC_SIZE = 2; */ static const uint8_t SIZE_MEM_READ_RPT_FIX = 6; -static const size_t MAX_FILENAME_SIZE = 256; +static const size_t FILENAME_FIELD_SIZE = 256; +// Subtract size of NULL terminator. +static const size_t MAX_FILENAME_SIZE = FILENAME_FIELD_SIZE - 1; /** * PLOC space packet length for fixed size packets. This is the size of the whole packet data @@ -448,23 +449,21 @@ class TcMemWrite : public TcBase { /** * @brief Class to help creation of flash fopen command. */ -class FlashFopen : public TcBase { +class TcFlashFopen : public TcBase { public: - FlashFopen(ploc::SpTcParams params, uint16_t sequenceCount) + TcFlashFopen(ploc::SpTcParams params, uint16_t sequenceCount) : TcBase(params, apid::TC_FLASHFOPEN, sequenceCount) {} ReturnValue_t setPayload(std::string filename, uint8_t mode) { accessMode = mode; size_t nameSize = filename.size(); - spParams.setFullPayloadLen(256 + sizeof(uint8_t) + CRC_SIZE); + spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE); ReturnValue_t result = checkPayloadLen(); if (result != returnvalue::OK) { return result; } + std::memset(payloadStart, 0, FILENAME_FIELD_SIZE); std::memcpy(payloadStart, filename.c_str(), nameSize); - // payloadStart[nameSize] = NULL_TERMINATOR; - std::memset(payloadStart + nameSize, 0, 256 - nameSize); - // payloadStart[255] = NULL_TERMINATOR; payloadStart[256] = accessMode; return returnvalue::OK; } @@ -476,9 +475,9 @@ class FlashFopen : public TcBase { /** * @brief Class to help creation of flash fclose command. */ -class FlashFclose : public TcBase { +class TcFlashFclose : public TcBase { public: - FlashFclose(ploc::SpTcParams params, uint16_t sequenceCount) + TcFlashFclose(ploc::SpTcParams params, uint16_t sequenceCount) : TcBase(params, apid::TC_FLASHFCLOSE, sequenceCount) { spParams.setFullPayloadLen(CRC_SIZE); } @@ -506,7 +505,13 @@ class TcFlashMkfs : public TcBase { TcFlashMkfs(ploc::SpTcParams params, uint16_t sequenceCount, FlashId flashId) : TcBase(params, apid::TC_FLASH_MKFS, sequenceCount) { spParams.setFullPayloadLen(1 + CRC_SIZE); - payloadStart[0] = flashId; + const char* flashIdStr = "0:/"; + if (flashId == FlashId::FLASH_1) { + flashIdStr = "1:/"; + } + std::memcpy(payloadStart, flashIdStr, 3); + // Null terminator + payloadStart[3] = 0; } }; @@ -595,20 +600,14 @@ class TcFlashDelete : public TcBase { ReturnValue_t setPayload(std::string filename) { size_t nameSize = filename.size(); - spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE); + spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE); auto res = checkPayloadLen(); if (res != returnvalue::OK) { return res; } std::memcpy(payloadStart, filename.c_str(), nameSize); *(payloadStart + nameSize) = NULL_TERMINATOR; - - updateSpFields(); - res = checkSizeAndSerializeHeader(); - if (res != returnvalue::OK) { - return res; - } - return calcAndSetCrc(); + return returnvalue::OK; } }; @@ -760,8 +759,9 @@ class TcGetDirContent : public TcBase { if (result != returnvalue::OK) { return result; } + std::memset(payloadStart, 0, 256); std::memcpy(payloadStart, commandData, commandDataLen); - payloadStart[255] = '\0'; + payloadStart[255] = 0; return result; } }; @@ -802,7 +802,7 @@ class TcReplayWriteSeq : public TcBase { static const size_t USE_DECODING_LENGTH = 1; ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen > USE_DECODING_LENGTH + MAX_FILENAME_SIZE or + if (commandDataLen > USE_DECODING_LENGTH + FILENAME_FIELD_SIZE or checkPayloadLen() != returnvalue::OK) { sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen << std::endl; @@ -821,18 +821,18 @@ class FlashBasePusCmd { virtual ~FlashBasePusCmd() = default; virtual ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) { - if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) { + if (commandDataLen > FILENAME_FIELD_SIZE) { return INVALID_LENGTH; } size_t fileLen = strnlen(reinterpret_cast(commandData), commandDataLen); - if (fileLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) { + if (fileLen > MAX_FILENAME_SIZE) { return FILENAME_TOO_LONG; } obcFile = std::string(reinterpret_cast(commandData), fileLen); fileLen = strnlen(reinterpret_cast(commandData + obcFile.size() + SIZE_NULL_TERMINATOR), commandDataLen - obcFile.size() - 1); - if (fileLen > MAX_FILENAME_SIZE) { + if (fileLen > FILENAME_FIELD_SIZE) { return MPSOC_FILENAME_TOO_LONG; } mpsocFile = std::string( @@ -921,15 +921,15 @@ class TcCamTakePic : public TcBase { size_t deserLen = commandDataLen; size_t serLen = 0; fileName = reinterpret_cast(commandData); - if (fileName.size() + sizeof(NULL_TERMINATOR) > FILENAME_LEN) { + if (fileName.size() > MAX_FILENAME_SIZE) { return FILENAME_TOO_LONG; } - deserLen -= FILENAME_LEN; - *dataPtr += FILENAME_LEN; + deserLen -= fileName.length() + 1; + *dataPtr += fileName.length() + 1; uint8_t** payloadPtr = &payloadStart; memcpy(payloadStart, fileName.data(), fileName.size()); - *payloadStart += FILENAME_LEN; - serLen += FILENAME_LEN; + *payloadPtr += FILENAME_FIELD_SIZE; + serLen += FILENAME_FIELD_SIZE; ReturnValue_t result = SerializeAdapter::deSerialize(&encoderSettingY, dataPtr, &deserLen, SerializeIF::Endianness::NETWORK); if (result != returnvalue::OK) { @@ -1022,8 +1022,7 @@ class TcCamTakePic : public TcBase { private: static const size_t PARAMETER_SIZE = 28; - static constexpr size_t FILENAME_LEN = 64; - static constexpr size_t FULL_PAYLOAD_SIZE = FILENAME_LEN + PARAMETER_SIZE; + static constexpr size_t FULL_PAYLOAD_SIZE = FILENAME_FIELD_SIZE + PARAMETER_SIZE; }; /** @@ -1039,7 +1038,7 @@ class TcSimplexStreamFile : public TcBase { return INVALID_LENGTH; } std::string fileName(reinterpret_cast(commandData)); - if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) { + if (fileName.size() > MAX_FILENAME_SIZE) { return FILENAME_TOO_LONG; } @@ -1080,7 +1079,7 @@ class TcSimplexStoreFile : public TcBase { return INVALID_PARAMETER; } std::string fileName(reinterpret_cast(*dataPtr)); - if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) { + if (fileName.size() + sizeof(NULL_TERMINATOR) > FILENAME_FIELD_SIZE) { return FILENAME_TOO_LONG; } size_t currentCopyIdx = 0; diff --git a/tmtc b/tmtc index dfa45dbd..a59aceda 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit dfa45dbdba16d2190616eca6ba1dc13e94692b63 +Subproject commit a59aceda751bd1594b91c632fe0ae85b844707df