From 2431994180e1246d8d1761259cb6aff0c95bdffd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Apr 2024 12:10:41 +0200 Subject: [PATCH] various fixes, store file works now --- linux/payload/FreshMpsocHandler.cpp | 4 ++-- linux/payload/PlocMpsocSpecialComHelper.cpp | 2 ++ linux/payload/plocMpsocHelpers.cpp | 4 ++++ linux/payload/plocMpsocHelpers.h | 23 +++++++++++---------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/linux/payload/FreshMpsocHandler.cpp b/linux/payload/FreshMpsocHandler.cpp index 55860efa..15a5e318 100644 --- a/linux/payload/FreshMpsocHandler.cpp +++ b/linux/payload/FreshMpsocHandler.cpp @@ -265,7 +265,7 @@ ReturnValue_t FreshMpsocHandler::executeAction(ActionId_t actionId, MessageQueue return result; } result = specialComHelper.startFlashWrite(flashWritePusCmd.getObcFile(), - flashWritePusCmd.getMPSoCFile()); + flashWritePusCmd.getMpsocFile()); if (result != returnvalue::OK) { return result; } @@ -279,7 +279,7 @@ ReturnValue_t FreshMpsocHandler::executeAction(ActionId_t actionId, MessageQueue return result; } result = specialComHelper.startFlashRead(flashReadPusCmd.getObcFile(), - flashReadPusCmd.getMPSoCFile(), + flashReadPusCmd.getMpsocFile(), flashReadPusCmd.getReadSize()); if (result != returnvalue::OK) { return result; diff --git a/linux/payload/PlocMpsocSpecialComHelper.cpp b/linux/payload/PlocMpsocSpecialComHelper.cpp index 39407f87..ff997314 100644 --- a/linux/payload/PlocMpsocSpecialComHelper.cpp +++ b/linux/payload/PlocMpsocSpecialComHelper.cpp @@ -103,6 +103,8 @@ ReturnValue_t PlocMpsocSpecialComHelper::startFlashRead(std::string obcFile, std } flashReadAndWrite.totalReadSize = readFileSize; internalState = InternalState::FLASH_READ; + sif::info << "PLOC MPSoC: Reading " << mpsocFile << " with size " << readFileSize << " to " + << obcFile << std::endl; return semaphore.release(); } diff --git a/linux/payload/plocMpsocHelpers.cpp b/linux/payload/plocMpsocHelpers.cpp index 538d2cd9..90d07f30 100644 --- a/linux/payload/plocMpsocHelpers.cpp +++ b/linux/payload/plocMpsocHelpers.cpp @@ -13,6 +13,10 @@ std::string mpsoc::getStatusString(uint16_t status) { return "Incorrect length"; break; } + case (mpsoc::statusCode::FLASH_DRIVE_ERROR): { + return "flash drive error"; + break; + } case (mpsoc::statusCode::INCORRECT_CRC): { return "Incorrect crc"; break; diff --git a/linux/payload/plocMpsocHelpers.h b/linux/payload/plocMpsocHelpers.h index b3a1f23d..e1966dce 100644 --- a/linux/payload/plocMpsocHelpers.h +++ b/linux/payload/plocMpsocHelpers.h @@ -283,6 +283,7 @@ static const uint16_t TC_SIMPLEX_SEND_FILE_DELAY = 80; namespace statusCode { static const uint16_t DEFAULT_ERROR_CODE = 0x1; +static constexpr uint16_t FLASH_DRIVE_ERROR = 0xb; static const uint16_t UNKNOWN_APID = 0x5DD; static const uint16_t INCORRECT_LENGTH = 0x5DE; static const uint16_t INCORRECT_CRC = 0x5DF; @@ -843,11 +844,11 @@ class FlashBasePusCmd { const std::string& getObcFile() const { return obcFile; } - const std::string& getMPSoCFile() const { return mpsocFile; } + const std::string& getMpsocFile() const { return mpsocFile; } protected: size_t getParsedSize() const { - return getObcFile().size() + getMPSoCFile().size() + 2 * SIZE_NULL_TERMINATOR; + return getObcFile().size() + getMpsocFile().size() + 2 * SIZE_NULL_TERMINATOR; } static const size_t SIZE_NULL_TERMINATOR = 1; @@ -1034,7 +1035,7 @@ class TcSimplexStreamFile : public TcBase { : TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {} ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) { - if (commandDataLen > MAX_DATA_LENGTH) { + if (commandDataLen > MAX_FILENAME_SIZE) { return INVALID_LENGTH; } std::string fileName(reinterpret_cast(commandData)); @@ -1042,14 +1043,15 @@ class TcSimplexStreamFile : public TcBase { return FILENAME_TOO_LONG; } + std::memset(payloadStart, 0, FILENAME_FIELD_SIZE); std::memcpy(payloadStart, fileName.data(), fileName.length()); payloadStart[fileName.length()] = 0; - spParams.setFullPayloadLen(fileName.length() + 1); + spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE); + ; return returnvalue::OK; } private: - static constexpr size_t MAX_DATA_LENGTH = 256; }; /** @@ -1082,14 +1084,13 @@ class TcSimplexStoreFile : public TcBase { if (fileName.size() > MAX_FILENAME_SIZE) { return FILENAME_TOO_LONG; } - sif::debug << "file name: " << fileName << std::endl; char divStr[16]{}; sprintf(divStr, "DIV%03u", chunkParameter); - sif::debug << "div str: " << divStr << std::endl; std::memcpy(payloadStart, divStr, DIV_STR_LEN); - std::memset(payloadStart + DIV_STR_LEN, 0, FILENAME_FIELD_SIZE); - std::memcpy(payloadStart + DIV_STR_LEN, fileName.data(), fileName.length()); - spParams.setFullPayloadLen(DIV_STR_LEN + FILENAME_FIELD_SIZE + CRC_SIZE); + payloadStart[DIV_STR_LEN] = 0; + std::memset(payloadStart + DIV_STR_LEN + 1, 0, FILENAME_FIELD_SIZE - DIV_STR_LEN - 1); + std::memcpy(payloadStart + DIV_STR_LEN + 1, fileName.data(), fileName.length()); + spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE); return returnvalue::OK; } @@ -1097,7 +1098,7 @@ class TcSimplexStoreFile : public TcBase { uint32_t chunkParameter = 0; static constexpr size_t MIN_DATA_LENGTH = 4; static constexpr size_t DIV_STR_LEN = 6; - static constexpr size_t MAX_DATA_LENGTH = DIV_STR_LEN + FILENAME_FIELD_SIZE; + static constexpr size_t MAX_DATA_LENGTH = 4 + MAX_FILENAME_SIZE; }; /**