From e561805f3aa45e73360725631eb5507f94b4c574 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 24 Aug 2022 12:02:16 +0200 Subject: [PATCH] update ploc supv helper --- .../PlocSupervisorDefinitions.h | 28 +++- linux/devices/ploc/PlocSupervisorHandler.cpp | 15 +- linux/devices/ploc/PlocSupervisorHandler.h | 13 +- linux/devices/ploc/PlocSupvHelper.cpp | 131 +++++++++++------- linux/devices/ploc/PlocSupvHelper.h | 9 +- tmtc | 2 +- 6 files changed, 126 insertions(+), 72 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index d36e4c0c..bfe23488 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -160,6 +160,15 @@ static const size_t MAX_PACKET_SIZE = 1024; static const uint8_t SPACE_PACKET_HEADER_LENGTH = 6; +struct UpdateParams { + std::string file; + uint8_t memId; + uint32_t startAddr; + uint32_t bytesWritten; + uint16_t seqCount; + bool deleteMemory; +}; + enum PoolIds : lp_id_t { NUM_TMS, TEMP_PS, @@ -1247,11 +1256,14 @@ class DisableAutoTm : public ploc::SpTcBase { */ class RequestLoggingData : public ploc::SpTcBase { public: + /** + * Subapid + */ enum class Sa : uint8_t { - REQUEST_COUNTERS = 1, - REQUEST_EVENT_BUFFERS = 2, - CLEAR_COUNTERS = 3, - SET_LOGGING_TOPIC = 4 + REQUEST_COUNTERS = 1, /**< REQUEST_COUNTERS */ + REQUEST_EVENT_BUFFERS = 2, /**< REQUEST_EVENT_BUFFERS */ + CLEAR_COUNTERS = 3, /**< CLEAR_COUNTERS */ + SET_LOGGING_TOPIC = 4 /**< SET_LOGGING_TOPIC */ }; RequestLoggingData(ploc::SpTcParams params) : ploc::SpTcBase(params) { @@ -1260,6 +1272,11 @@ class RequestLoggingData : public ploc::SpTcBase { spParams.creator.setSeqCount(DEFAULT_SEQUENCE_COUNT); } + /** + * @param sa + * @param tpc Topic + * @return + */ ReturnValue_t buildPacket(Sa sa, uint8_t tpc = 0) { auto res = checkSizeAndSerializeHeader(); if (res != result::OK) { @@ -1659,7 +1676,8 @@ class ExecutionReport : public VerificationReport { } default: sif::warning << "ExecutionReport::printStatusInformation: Invalid status code: 0x" - << std::hex << static_cast(statusCode) << std::endl; + << std::hex << std::setfill('0') << std::setw(4) + << static_cast(statusCode) << std::dec << std::endl; break; } } diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index b90fa721..a5d3f3e2 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -121,8 +121,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (result != RETURN_OK) { return result; } - result = supvHelper->performUpdate(params.file, params.memId, params.startAddr, - params.bytesWritten, params.seqCount); + result = supvHelper->performUpdate(params); if (result != RETURN_OK) { return result; } @@ -1992,7 +1991,7 @@ ReturnValue_t PlocSupervisorHandler::getTimeStampString(std::string& timeStamp) } ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size, - UpdateParams& params) { + supv::UpdateParams& params) { size_t remSize = size; if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(params.memId)) + sizeof(params.startAddr) + sizeof(params.bytesWritten) + sizeof(params.seqCount)) { @@ -2017,11 +2016,19 @@ ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* command << std::endl; return result; } + result = SerializeAdapter::deSerialize(¶ms.deleteMemory, &commandData, &remSize, + SerializeIF::Endianness::BIG); + if (result != RETURN_OK) { + sif::warning + << "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize whether to delete " + "memory" << std::endl; + return result; + } return RETURN_OK; } ReturnValue_t PlocSupervisorHandler::extractBaseParams(const uint8_t** commandData, size_t& remSize, - UpdateParams& params) { + supv::UpdateParams& params) { bool nullTermFound = false; for (size_t idx = 0; idx < remSize; idx++) { if ((*commandData)[idx] == '\0') { diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index e410340f..bd4b0b9c 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -367,17 +367,10 @@ class PlocSupervisorHandler : public DeviceHandlerBase { ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData); - struct UpdateParams { - std::string file; - uint8_t memId; - uint32_t startAddr; - uint32_t bytesWritten; - uint16_t seqCount; - }; - - ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, UpdateParams& params); + ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, + supv::UpdateParams& params); ReturnValue_t extractBaseParams(const uint8_t** commandData, size_t& remSize, - UpdateParams& params); + supv::UpdateParams& params); ReturnValue_t eventSubscription(); ReturnValue_t handleExecutionSuccessReport(const uint8_t* data); diff --git a/linux/devices/ploc/PlocSupvHelper.cpp b/linux/devices/ploc/PlocSupvHelper.cpp index 836e7fc0..a33765b5 100644 --- a/linux/devices/ploc/PlocSupvHelper.cpp +++ b/linux/devices/ploc/PlocSupvHelper.cpp @@ -46,7 +46,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) { break; } case InternalState::UPDATE: { - result = performUpdate(); + result = executeUpdate(); if (result == RETURN_OK) { triggerEvent(SUPV_UPDATE_SUCCESSFUL, result); } else if (result == PROCESS_TERMINATED) { @@ -107,22 +107,28 @@ void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress) { - return performUpdate(file, memoryId, startAddress, 0, 1); + supv::UpdateParams params; + params.file = file; + params.memId = memoryId; + params.startAddr = startAddress; + params.bytesWritten = 0; + params.seqCount = 1; + params.deleteMemory = true; + return performUpdate(params); } -ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId, - uint32_t startAddress, size_t startBytesWritten, - uint16_t initSeqCount) { +ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) { ReturnValue_t result = RETURN_OK; #ifdef XIPHOS_Q7S - result = FilesystemHelper::checkPath(file); + result = FilesystemHelper::checkPath(params.file); if (result != RETURN_OK) { - sif::warning << "PlocSupvHelper::startUpdate: File " << file << " does not exist" << std::endl; + sif::warning << "PlocSupvHelper::startUpdate: File " << params.file << " does not exist" + << std::endl; return result; } - result = FilesystemHelper::fileExists(file); + result = FilesystemHelper::fileExists(params.file); if (result != RETURN_OK) { - sif::warning << "PlocSupvHelper::startUpdate: The file " << file << " does not exist" + sif::warning << "PlocSupvHelper::startUpdate: The file " << params.file << " does not exist" << std::endl; return result; } @@ -134,21 +140,22 @@ ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId, return RETURN_FAILED; } #endif - update.file = file; + update.file = params.file; update.fullFileSize = getFileSize(update.file); - if (startBytesWritten > update.fullFileSize) { - sif::warning << "Invalid start bytes counter " << startBytesWritten + if (params.bytesWritten > update.fullFileSize) { + sif::warning << "Invalid start bytes counter " << params.bytesWritten << ", smaller than full file length" << update.fullFileSize << std::endl; return HasReturnvaluesIF::RETURN_FAILED; } - update.length = update.fullFileSize - startBytesWritten; - update.memoryId = memoryId; - update.startAddress = startAddress; + update.length = update.fullFileSize - params.bytesWritten; + update.memoryId = params.memId; + update.startAddress = params.startAddr; update.progressPercent = 0; - update.bytesWritten = startBytesWritten; + update.bytesWritten = params.bytesWritten; update.crcShouldBeChecked = true; update.packetNum = 1; - update.sequenceCount = initSeqCount; + update.deleteMemory = params.deleteMemory; + update.sequenceCount = params.seqCount; internalState = InternalState::UPDATE; uartComIF->flushUartTxAndRxBuf(comCookie); semaphore.release(); @@ -229,7 +236,7 @@ void PlocSupvHelper::executeFullCheckMemoryCommand() { } } -ReturnValue_t PlocSupvHelper::performUpdate() { +ReturnValue_t PlocSupvHelper::executeUpdate() { ReturnValue_t result = RETURN_OK; sif::info << "PLOC SUPV Update MPSoC: Calculating Image CRC" << std::endl; result = calcImageCrc(); @@ -246,10 +253,12 @@ ReturnValue_t PlocSupvHelper::performUpdate() { if (result != RETURN_OK) { return result; } - sif::info << "PLOC SUPV Update MPSoC: Erasing Memory" << std::endl; - result = eraseMemory(); - if (result != RETURN_OK) { - return result; + if(update.deleteMemory) { + sif::info << "PLOC SUPV Update MPSoC: Erasing Memory" << std::endl; + result = eraseMemory(); + if (result != RETURN_OK) { + return result; + } } return updateOperation(); } @@ -372,13 +381,38 @@ ReturnValue_t PlocSupvHelper::performEventBufferRequest() { if (result != RETURN_OK) { return result; } - result = handleEventBufferReception(); + result = + handleTmReception(ccsds::HEADER_LEN, tmBuf.data(), supv::recv_timeout::UPDATE_STATUS_REPORT); if (result != RETURN_OK) { return result; } - result = handleExe(); - if (result != RETURN_OK) { - return result; + ploc::SpTmReader spReader(tmBuf.data(), tmBuf.size()); + bool exeAlreadyReceived = false; + if (spReader.getApid() == supv::APID_EXE_FAILURE) { + exeAlreadyReceived = true; + result = handleRemainingExeReport(spReader); + } else if (spReader.getApid() == supv::APID_MRAM_DUMP_TM) { + result = handleEventBufferReception(spReader); + } + + if (not exeAlreadyReceived) { + result = handleExe(); + if (result != RETURN_OK) { + return result; + } + } + return result; +} + +ReturnValue_t PlocSupvHelper::handleRemainingExeReport(ploc::SpTmReader& reader) { + size_t remBytes = reader.getPacketDataLen() + 1; + ReturnValue_t result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "Reading exe failure report failed" << std::endl; + } + result = exeReportHandling(); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "Handling exe report failed" << std::endl; } return result; } @@ -652,22 +686,17 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() { return result; } - result = - handleTmReception(ccsds::HEADER_LEN, tmBuf.data(), supv::recv_timeout::UPDATE_STATUS_REPORT); - SpacePacketReader spReader(tmBuf.data(), tmBuf.size()); + bool exeAlreadyHandled = false; + uint32_t timeout = std::max(CRC_EXECUTION_TIMEOUT, supv::recv_timeout::UPDATE_STATUS_REPORT); + result = handleTmReception(ccsds::HEADER_LEN, tmBuf.data(), timeout); + ploc::SpTmReader spReader(tmBuf.data(), tmBuf.size()); if (spReader.getApid() == supv::APID_EXE_FAILURE) { - size_t remBytes = spReader.getPacketDataLen() + 1; - result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::warning << "Reading exe failure report failed" << std::endl; - } - result = exeReportHandling(); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::warning << "Handling exe report failed" << std::endl; - } + exeAlreadyHandled = true; + result = handleRemainingExeReport(spReader); } else if (spReader.getApid() == supv::APID_UPDATE_STATUS_REPORT) { size_t remBytes = spReader.getPacketDataLen() + 1; - result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN); + result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN, + supv::recv_timeout::UPDATE_STATUS_REPORT); if (result != RETURN_OK) { sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: Failed to receive update status report" @@ -683,9 +712,11 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() { std::memcpy(statusReportBuf.data(), tmBuf.data(), updateStatusReport.getNominalSize()); } - result = handleExe(CRC_EXECUTION_TIMEOUT); - if (result != RETURN_OK) { - return result; + if (not exeAlreadyHandled) { + result = handleExe(CRC_EXECUTION_TIMEOUT); + if (result != RETURN_OK) { + return result; + } } // Now process the status report @@ -715,14 +746,14 @@ uint32_t PlocSupvHelper::getFileSize(std::string filename) { return size; } -ReturnValue_t PlocSupvHelper::handleEventBufferReception() { +ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reader) { ReturnValue_t result = RETURN_OK; std::string filename = Filenaming::generateAbsoluteFilename( eventBufferReq.path, eventBufferReq.filename, timestamping); std::ofstream file(filename, std::ios_base::app | std::ios_base::out); uint32_t packetsRead = 0; size_t requestLen = 0; - ploc::SpTmReader tmReader(tmBuf.data(), tmBuf.size()); + bool firstPacket = true; for (packetsRead = 0; packetsRead < NUM_EVENT_BUFFER_PACKETS; packetsRead++) { if (terminate) { triggerEvent(SUPV_EVENT_BUFFER_REQUEST_TERMINATED, packetsRead - 1); @@ -734,6 +765,10 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception() { } else { requestLen = SIZE_EVENT_BUFFER_FULL_PACKET; } + if (firstPacket) { + firstPacket = false; + requestLen -= 6; + } result = handleTmReception(requestLen); if (result != RETURN_OK) { sif::debug << "PlocSupvHelper::handleEventBufferReception: Failed while trying to read packet" @@ -741,20 +776,20 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception() { file.close(); return result; } - ReturnValue_t result = tmReader.checkCrc(); + ReturnValue_t result = reader.checkCrc(); if (result != RETURN_OK) { triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); return result; } - uint16_t apid = tmReader.getApid(); + uint16_t apid = reader.getApid(); if (apid != supv::APID_MRAM_DUMP_TM) { sif::warning << "PlocSupvHelper::handleEventBufferReception: Did not expect space packet " << "with APID 0x" << std::hex << apid << std::endl; file.close(); return EVENT_BUFFER_REPLY_INVALID_APID; } - file.write(reinterpret_cast(tmReader.getPacketData()), - tmReader.getPayloadDataLength()); + file.write(reinterpret_cast(reader.getPacketData()), + reader.getPayloadDataLength()); } return result; } diff --git a/linux/devices/ploc/PlocSupvHelper.h b/linux/devices/ploc/PlocSupvHelper.h index 3fc60145..c79af01f 100644 --- a/linux/devices/ploc/PlocSupvHelper.h +++ b/linux/devices/ploc/PlocSupvHelper.h @@ -116,8 +116,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha * * @return RETURN_OK if successful, otherwise error return value */ - ReturnValue_t performUpdate(std::string file, uint8_t memoryId, uint32_t startAddress, - size_t startBytesWritten, uint16_t initSeqCount); + ReturnValue_t performUpdate(const supv::UpdateParams& params); ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress); ReturnValue_t performMemCheck(uint8_t memoryId, uint32_t startAddress, size_t sizeToCheck, @@ -177,6 +176,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha uint32_t packetNum; uint16_t sequenceCount; uint8_t progressPercent; + bool deleteMemory = false; }; struct Update update; @@ -220,7 +220,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha void executeFullCheckMemoryCommand(); - ReturnValue_t performUpdate(); + ReturnValue_t executeUpdate(); ReturnValue_t continueUpdate(); ReturnValue_t updateOperation(); ReturnValue_t writeUpdatePackets(); @@ -268,7 +268,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha * @return The size of the file */ uint32_t getFileSize(std::string filename); - ReturnValue_t handleEventBufferReception(); + ReturnValue_t handleEventBufferReception(ploc::SpTmReader& reader); + ReturnValue_t handleRemainingExeReport(ploc::SpTmReader& reader); void resetSpParams(); }; diff --git a/tmtc b/tmtc index aec55035..ac782157 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit aec55035d7602226a2e61845565c94b5ed8f561c +Subproject commit ac7821575c16b2c08740722f8d9ae0b456c60ece