From f545928adcbf2a93634059260e5bd47a2a1cf863 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Nov 2022 16:13:55 +0100 Subject: [PATCH 1/9] some bugfixes --- linux/devices/ploc/PlocSupervisorHandler.cpp | 33 +++++++------------- linux/devices/ploc/PlocSupvUartMan.cpp | 11 ++++--- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index e596d768..3293c652 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -136,28 +136,19 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, void PlocSupervisorHandler::doStartUp() { if (setTimeDuringStartup) { - switch (startupState) { - case StartupState::OFF: { - bootTimeout.resetTimer(); - uartManager.start(); - startupState = StartupState::BOOTING; - break; + if (startupState == StartupState::OFF) { + bootTimeout.resetTimer(); + uartManager.start(); + startupState = StartupState::BOOTING; + } + if (startupState == StartupState::BOOTING) { + if (bootTimeout.hasTimedOut()) { + uartIsolatorSwitch.pullHigh(); + startupState = StartupState::SET_TIME; } - case StartupState::BOOTING: { - if (bootTimeout.hasTimedOut()) { - uartIsolatorSwitch.pullHigh(); - startupState = StartupState::SET_TIME; - } - break; - } - case StartupState::SET_TIME_EXECUTING: - break; - case StartupState::ON: { - setMode(_MODE_TO_ON); - break; - } - default: - break; + } + if (startupState == StartupState::ON) { + setMode(_MODE_TO_ON); } } else { uartIsolatorSwitch.pullHigh(); diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 8938b5d3..8bc2019d 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -571,9 +571,9 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( bool ackReceived = false; bool packetWasHandled = false; while (true) { - while (result != NO_PACKET_FOUND) { + do { result = tryHdlcParsing(); - } + } while (result != NO_PACKET_FOUND); if (not decodedQueue.empty()) { size_t packetLen = 0; decodedQueue.retrieve(&packetLen); @@ -589,6 +589,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( if (not ackReceived) { retval = handleAckReception(packet, serviceId, packetLen); if (retval == 1) { + sif::debug << "ACK received" << std::endl; ackReceived = true; packetWasHandled = true; } else if (retval == -1) { @@ -597,6 +598,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( } else { retval = handleExeAckReception(packet, serviceId, packetLen); if (retval == 1) { + sif::debug << "EXE ACK received" << std::endl; break; } else if (retval == -1) { return returnvalue::FAILED; @@ -758,9 +760,10 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { bool packetWasHandled = false; bool exeReceived = false; while (true) { - while (result != NO_PACKET_FOUND) { + do { result = tryHdlcParsing(); - } + + } while (result != NO_PACKET_FOUND); if (not decodedQueue.empty()) { size_t packetLen = 0; decodedQueue.retrieve(&packetLen); From 98fcf06e31c66f5c6ce482394283d659d20912db Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 18 Nov 2022 17:25:52 +0100 Subject: [PATCH 2/9] various improvements and bugfixes --- .../PlocSupervisorDefinitions.h | 2 +- linux/devices/ploc/PlocSupervisorHandler.cpp | 2 +- linux/devices/ploc/PlocSupvUartMan.cpp | 67 ++++++++----------- linux/devices/ploc/PlocSupvUartMan.h | 8 +-- linux/scheduling.cpp | 4 ++ mission/devices/devicedefinitions/SpBase.h | 2 + 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index ac89c8d4..18e92ccb 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -501,7 +501,7 @@ class TcBase : public ploc::SpTcBase { uint16_t getModuleApid() const { return getApid() & APID_MODULE_MASK; } - uint8_t getServiceId() const { return payloadStart[supv::PAYLOAD_OFFSET]; } + uint8_t getServiceId() const { return getPacketData()[TIMESTAMP_LEN]; } static size_t fullSpDataLenFromPayloadLen(size_t payloadLen) { return SECONDARY_HEADER_LEN + payloadLen + CRC_LEN; diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 3293c652..bd027e37 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -138,12 +138,12 @@ void PlocSupervisorHandler::doStartUp() { if (setTimeDuringStartup) { if (startupState == StartupState::OFF) { bootTimeout.resetTimer(); - uartManager.start(); startupState = StartupState::BOOTING; } if (startupState == StartupState::BOOTING) { if (bootTimeout.hasTimedOut()) { uartIsolatorSwitch.pullHigh(); + uartManager.start(); startupState = StartupState::SET_TIME; } } diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 8bc2019d..0db0feef 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -101,12 +101,11 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { lock->unlockMutex(); semaphore->acquire(); while (true) { - // sif::debug << "SUPV UART MAN: Running.." << std::endl; - putTaskToSleep = handleUartReception(); if (putTaskToSleep) { performUartShutdown(); break; } + handleUartReception(); lock->lockMutex(); InternalState currentState = state; lock->unlockMutex(); @@ -126,44 +125,39 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { break; } } - if (putTaskToSleep) { - performUartShutdown(); - break; - } } } } -bool PlocSupvUartManager::handleUartReception() { +ReturnValue_t PlocSupvUartManager::handleUartReception() { ReturnValue_t result = OK; + ReturnValue_t status = OK; ssize_t bytesRead = read(serialPort, reinterpret_cast(recBuf.data()), static_cast(recBuf.size())); if (bytesRead == 0) { - { - MutexGuard mg(lock); - if (state == InternalState::GO_TO_SLEEP) { - return true; - } - } while (result != NO_PACKET_FOUND) { result = tryHdlcParsing(); + if (result != NO_PACKET_FOUND and result != OK) { + status = result; + } } } else if (bytesRead < 0) { sif::warning << "PlocSupvHelper::performOperation: read call failed with error [" << errno << ", " << strerror(errno) << "]" << std::endl; - return true; + return FAILED; } else if (bytesRead >= static_cast(recBuf.size())) { sif::error << "PlocSupvHelper::performOperation: Receive buffer too small for " << bytesRead << " bytes" << std::endl; + return FAILED; } else if (bytesRead > 0) { if (debugMode) { sif::info << "Received " << bytesRead << " bytes from the PLOC Supervisor:" << std::endl; arrayprinter::print(recBuf.data(), bytesRead); } recRingBuf.writeData(recBuf.data(), bytesRead); - tryHdlcParsing(); + status = tryHdlcParsing(); } - return false; + return status; } ReturnValue_t PlocSupvUartManager::startUpdate(std::string file, uint8_t memoryId, @@ -571,23 +565,20 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( bool ackReceived = false; bool packetWasHandled = false; while (true) { - do { - result = tryHdlcParsing(); - } while (result != NO_PACKET_FOUND); + handleUartReception(); if (not decodedQueue.empty()) { size_t packetLen = 0; decodedQueue.retrieve(&packetLen); - decodedRingBuf.readData(decodedBuf.data(), packetLen); + decodedRingBuf.readData(decodedBuf.data(), packetLen, true); tmReader.setData(decodedBuf.data(), packetLen); result = checkReceivedTm(); if (result != returnvalue::OK) { continue; } if (tmReader.getModuleApid() == Apid::TMTC_MAN) { - uint8_t serviceId = tmReader.getServiceId(); int retval = 0; if (not ackReceived) { - retval = handleAckReception(packet, serviceId, packetLen); + retval = handleAckReception(packet, packetLen); if (retval == 1) { sif::debug << "ACK received" << std::endl; ackReceived = true; @@ -596,7 +587,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( return returnvalue::FAILED; } } else { - retval = handleExeAckReception(packet, serviceId, packetLen); + retval = handleExeAckReception(packet, packetLen); if (retval == 1) { sif::debug << "EXE ACK received" << std::endl; break; @@ -619,7 +610,8 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( return returnvalue::OK; } -int PlocSupvUartManager::handleAckReception(supv::TcBase& tc, uint8_t serviceId, size_t packetLen) { +int PlocSupvUartManager::handleAckReception(supv::TcBase& tc, size_t packetLen) { + uint8_t serviceId = tmReader.getServiceId(); if (serviceId == static_cast(supv::tm::TmtcId::ACK) or serviceId == static_cast(supv::tm::TmtcId::NAK)) { AcknowledgmentReport ackReport(tmReader); @@ -650,8 +642,8 @@ int PlocSupvUartManager::handleAckReception(supv::TcBase& tc, uint8_t serviceId, return 0; } -int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, uint8_t serviceId, - size_t packetLen) { +int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, size_t packetLen) { + uint8_t serviceId = tmReader.getServiceId(); if (serviceId == static_cast(supv::tm::TmtcId::EXEC_ACK) or serviceId == static_cast(supv::tm::TmtcId::EXEC_NAK)) { ExecutionReport exeReport(tmReader); @@ -660,7 +652,7 @@ int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, uint8_t service triggerEvent(EXE_RECEPTION_FAILURE); return -1; } - if (exeReport.getRefModuleApid() == tc.getApid() and + if (exeReport.getRefModuleApid() == tc.getModuleApid() and exeReport.getRefServiceId() == tc.getServiceId()) { if (serviceId == static_cast(supv::tm::TmtcId::EXEC_ACK)) { return 1; @@ -688,8 +680,7 @@ ReturnValue_t PlocSupvUartManager::checkReceivedTm() { triggerEvent(SUPV_REPLY_SIZE_MISSMATCH, rememberApid); return result; } - result = tmReader.checkCrc(); - if (result != returnvalue::OK) { + if (not tmReader.verifyCrc()) { triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); return result; } @@ -745,12 +736,12 @@ ReturnValue_t PlocSupvUartManager::calcImageCrc() { ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { ReturnValue_t result = returnvalue::OK; resetSpParams(); - supv::CheckMemory packet(spParams); - result = packet.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); + supv::CheckMemory tcPacket(spParams); + result = tcPacket.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); if (result != returnvalue::OK) { return result; } - result = encodeAndSendPacket(packet.getFullPacket(), packet.getFullPacketLen()); + result = encodeAndSendPacket(tcPacket.getFullPacket(), tcPacket.getFullPacketLen()); if (result != returnvalue::OK) { return result; } @@ -760,14 +751,11 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { bool packetWasHandled = false; bool exeReceived = false; while (true) { - do { - result = tryHdlcParsing(); - - } while (result != NO_PACKET_FOUND); + handleUartReception(); if (not decodedQueue.empty()) { size_t packetLen = 0; decodedQueue.retrieve(&packetLen); - decodedRingBuf.readData(decodedBuf.data(), packetLen); + decodedRingBuf.readData(decodedBuf.data(), packetLen, true); tmReader.setData(decodedBuf.data(), packetLen); result = checkReceivedTm(); if (result != returnvalue::OK) { @@ -775,10 +763,9 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { } packetWasHandled = false; if (tmReader.getModuleApid() == Apid::TMTC_MAN) { - uint8_t serviceId = tmReader.getServiceId(); int retval = 0; if (not ackReceived) { - retval = handleAckReception(packet, serviceId, packetLen); + retval = handleAckReception(tcPacket, packetLen); if (retval == 1) { packetWasHandled = true; ackReceived = true; @@ -786,7 +773,7 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { return returnvalue::FAILED; } } else { - retval = handleExeAckReception(packet, serviceId, packetLen); + retval = handleExeAckReception(tcPacket, packetLen); if (retval == 1) { packetWasHandled = true; exeReceived = true; diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index ce24e721..9d9e3738 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -252,14 +252,14 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; - bool debugMode = false; + bool debugMode = true; bool timestamping = true; // Remembers APID to know at which command a procedure failed uint16_t rememberApid = 0; ReturnValue_t handleRunningLongerRequest(); - bool handleUartReception(); + ReturnValue_t handleUartReception(); void addHdlcFraming(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen, size_t maxDest); int removeHdlcFramingWithCrcCheck(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen); @@ -275,8 +275,8 @@ class PlocSupvUartManager : public DeviceCommunicationIF, // ReturnValue_t performEventBufferRequest(); ReturnValue_t handlePacketTransmissionNoReply(supv::TcBase& packet, uint32_t timeoutExecutionReport = 60000); - int handleAckReception(supv::TcBase& tc, uint8_t serviceId, size_t packetLen); - int handleExeAckReception(supv::TcBase& tc, uint8_t serviceId, size_t packetLen); + int handleAckReception(supv::TcBase& tc, size_t packetLen); + int handleExeAckReception(supv::TcBase& tc, size_t packetLen); /** * @brief Handles reading of TM packets from the communication interface diff --git a/linux/scheduling.cpp b/linux/scheduling.cpp index 1300266f..75706185 100644 --- a/linux/scheduling.cpp +++ b/linux/scheduling.cpp @@ -54,6 +54,8 @@ void scheduling::addMpsocSupvHandlers(PeriodicTaskIF* plTask) { plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::GET_WRITE); plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::SEND_READ); plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::GET_READ); + plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::SEND_READ); + plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::GET_READ); #endif #if OBSW_ADD_PLOC_MPSOC == 1 @@ -62,5 +64,7 @@ void scheduling::addMpsocSupvHandlers(PeriodicTaskIF* plTask) { plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::GET_WRITE); plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::SEND_READ); plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::GET_READ); + plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::SEND_READ); + plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::GET_READ); #endif } diff --git a/mission/devices/devicedefinitions/SpBase.h b/mission/devices/devicedefinitions/SpBase.h index 22c138b5..11d67a59 100644 --- a/mission/devices/devicedefinitions/SpBase.h +++ b/mission/devices/devicedefinitions/SpBase.h @@ -46,6 +46,8 @@ class SpTcBase { void updateLenFromParams() { spParams.creator.setDataLenField(spParams.fullPayloadLen - 1); } const uint8_t* getFullPacket() const { return spParams.buf; } + const uint8_t* getPacketData() const { return spParams.buf + ccsds::HEADER_LEN; } + size_t getFullPacketLen() const { return spParams.creator.getFullPacketLen(); } uint16_t getApid() const { return spParams.creator.getApid(); } From c1e92605d40ceace834e921d1d1582e753fe7749 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 13:38:33 +0100 Subject: [PATCH 3/9] bump tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 9cd4846d..f5766ea4 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 9cd4846d396373325fc5e03a367fed236dfc16d7 +Subproject commit f5766ea419ff2213468dab7e19a81075aefd1ad9 From 9953a49b09ab34d1e75ba1a4ff03ca0b570a0ac6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 17:55:56 +0100 Subject: [PATCH 4/9] minor improvements for PLOC SUPV update --- linux/devices/ploc/PlocSupvUartMan.cpp | 12 ++++++------ linux/devices/ploc/PlocSupvUartMan.h | 2 +- tmtc | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 0db0feef..ee91554e 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -314,17 +314,17 @@ void PlocSupvUartManager::executeFullCheckMemoryCommand() { sif::info << "PLOC SUPV Mem Check: Selecting Memory" << std::endl; result = selectMemory(); if (result != returnvalue::OK) { - triggerEvent(SUPV_MEM_CHECK_FAIL, result); + triggerEvent(SUPV_MEM_CHECK_FAIL, result, 1); return; } sif::info << "PLOC SUPV Mem Check: Preparing Update" << std::endl; result = prepareUpdate(); if (result != returnvalue::OK) { - triggerEvent(SUPV_MEM_CHECK_FAIL, result); + triggerEvent(SUPV_MEM_CHECK_FAIL, result, 2); return; } sif::info << "PLOC SUPV Mem Check: Memory Check" << std::endl; - handleCheckMemoryCommand(); + handleCheckMemoryCommand(3); } ReturnValue_t PlocSupvUartManager::executeUpdate() { @@ -369,7 +369,7 @@ ReturnValue_t PlocSupvUartManager::updateOperation() { return result; } sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl; - return handleCheckMemoryCommand(); + return handleCheckMemoryCommand(0); } ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { @@ -733,7 +733,7 @@ ReturnValue_t PlocSupvUartManager::calcImageCrc() { return result; } -ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { +ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) { ReturnValue_t result = returnvalue::OK; resetSpParams(); supv::CheckMemory tcPacket(spParams); @@ -803,7 +803,7 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { << std::setfill('0') << std::hex << std::setw(4) << static_cast(update.crc) << " but received CRC 0x" << std::setw(4) << report.getCrc() << std::dec << std::endl; - triggerEvent(SUPV_MEM_CHECK_FAIL, result); + triggerEvent(SUPV_MEM_CHECK_FAIL, result, failStep); } } } diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index 9d9e3738..0d191b7e 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -298,7 +298,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, // Calculates CRC over image. Will be used for verification after update writing has // finished. ReturnValue_t calcImageCrc(); - ReturnValue_t handleCheckMemoryCommand(); + ReturnValue_t handleCheckMemoryCommand(uint8_t failStep); ReturnValue_t exeReportHandling(); /** * @brief Return size of file with name filename diff --git a/tmtc b/tmtc index f5766ea4..ac2b9cb7 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit f5766ea419ff2213468dab7e19a81075aefd1ad9 +Subproject commit ac2b9cb712405ee07b9de1950fd6c923a6f184b5 From cc79ffc57bec8fbdad4b22aed3dbeec86de869f3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 18:32:23 +0100 Subject: [PATCH 5/9] some remaining bugfixes --- .../PlocSupervisorDefinitions.h | 7 +--- linux/devices/ploc/PlocSupervisorHandler.cpp | 37 +++++++++---------- linux/devices/ploc/PlocSupervisorHandler.h | 8 ++-- linux/devices/ploc/PlocSupvUartMan.cpp | 5 +++ linux/devices/ploc/PlocSupvUartMan.h | 3 +- tmtc | 2 +- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index 18e92ccb..8c638c83 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -1681,7 +1681,7 @@ class UpdateStatusReport { if (not tmReader.crcIsOk()) { return result::CRC_FAILURE; } - if (tmReader.getApid() != Apid::MEM_MAN) { + if (tmReader.getModuleApid() != Apid::MEM_MAN) { return result::INVALID_APID; } if (tmReader.getBufSize() < MIN_TMTC_LEN + PAYLOAD_LEN or @@ -1690,10 +1690,7 @@ class UpdateStatusReport { << std::endl; return result::BUF_TOO_SMALL; } - size_t remLen = PAYLOAD_LEN; - if (remLen < PAYLOAD_LEN) { - return result::INVALID_REPLY_LENGTH; - } + size_t remLen = tmReader.getPayloadLen(); const uint8_t* dataFieldPtr = tmReader.getPayloadStart(); SerializeAdapter::deSerialize(&memoryId, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&n, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index bd027e37..3a8565eb 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -84,7 +85,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, break; } - if (plocSupvHelperExecuting) { + if (uartManager.longerRequestActive()) { return result::SUPV_HELPER_EXECUTING; } @@ -98,6 +99,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) { return result::FILENAME_TOO_LONG; } + shutdownCmdSent = false; UpdateParams params; result = extractUpdateCommand(data, size, params); if (result != returnvalue::OK) { @@ -107,15 +109,15 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (result != returnvalue::OK) { return result; } - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } case CONTINUE_UPDATE: { + shutdownCmdSent = false; uartManager.initiateUpdateContinuation(); - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } case MEMORY_CHECK_WITH_FILE: { + shutdownCmdSent = false; UpdateParams params; ReturnValue_t result = extractBaseParams(&data, size, params); if (result != returnvalue::OK) { @@ -125,7 +127,6 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, return HasFileSystemIF::FILE_DOES_NOT_EXIST; } uartManager.performMemCheck(params.file, params.memId, params.startAddr); - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } default: @@ -777,7 +778,6 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) { Event event = eventMessage->getEvent(); switch (objectId) { case objects::PLOC_SUPERVISOR_HELPER: { - plocSupvHelperExecuting = false; // After execution of update procedure, PLOC is in a state where it draws approx. 700 mA of // current. To leave this state the shutdown MPSoC command must be sent here. if (event == PlocSupvUartManager::SUPV_UPDATE_FAILED || @@ -786,13 +786,18 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) { event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_SUCCESSFUL || event == PlocSupvUartManager::SUPV_MEM_CHECK_FAIL || event == PlocSupvUartManager::SUPV_MEM_CHECK_OK) { - result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); - if (result != returnvalue::OK) { - triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED); - sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown " - "command" - << std::endl; - return; + // Wait for a short period for the uart state machine to adjust + // TaskFactory::delayTask(5); + if (not shutdownCmdSent) { + shutdownCmdSent = true; + result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); + if (result != returnvalue::OK) { + triggerEvent(SUPV_MPSOC_SHUTDOWN_BUILD_FAILED); + sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown " + "command" + << std::endl; + return; + } } } break; @@ -1217,14 +1222,6 @@ size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) { return replyLen; } -ReturnValue_t PlocSupervisorHandler::doSendReadHook() { - // Prevent DHB from polling UART during commands executed by the supervisor helper task - if (plocSupvHelperExecuting) { - return returnvalue::FAILED; - } - return returnvalue::OK; -} - void PlocSupervisorHandler::doOffActivity() {} void PlocSupervisorHandler::handleDeviceTm(const uint8_t* data, size_t dataSize, diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index 557639e1..4ffe4166 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -59,7 +59,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { uint8_t expectedReplies = 1, bool useAlternateId = false, DeviceCommandId_t alternateReplyID = 0) override; size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override; - ReturnValue_t doSendReadHook() override; + // ReturnValue_t doSendReadHook() override; void doOffActivity() override; private: @@ -81,7 +81,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { //! [EXPORT] : [COMMENT] Supervisor helper currently executing a command static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(7, severity::LOW); //! [EXPORT] : [COMMENT] Failed to build the command to shutdown the MPSoC - static const Event SUPV_MPSOC_SHUWDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW); + static const Event SUPV_MPSOC_SHUTDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW); static const uint16_t APID_MASK = 0x7FF; static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; @@ -119,6 +119,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { SerialComIF* uartComIf = nullptr; LinuxLibgpioIF* gpioComIF = nullptr; Gpio uartIsolatorSwitch; + bool shutdownCmdSent = false; supv::HkSet hkset; supv::BootStatusReport bootStatusReport; @@ -151,9 +152,6 @@ class PlocSupervisorHandler : public DeviceHandlerBase { std::string supervisorFilePath = "ploc/supervisor"; std::string activeMramFile; - // Supervisor helper class currently executing a command - bool plocSupvHelperExecuting = false; - Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false); Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false); // Vorago nees some time to boot properly diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index ee91554e..6d938efe 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -1148,3 +1148,8 @@ int PlocSupvUartManager::removeHdlcFramingWithCrcCheck(const uint8_t* src, size_ *dlen = tlen - 2; return 0; } + +bool PlocSupvUartManager::longerRequestActive() const { + MutexGuard mg(lock); + return state == InternalState::DEDICATED_REQUEST; +} diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index 0d191b7e..d36a9cd4 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -159,6 +159,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, * @brief Can be used to start the UART reception */ void start(); + bool longerRequestActive() const; static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId); @@ -252,7 +253,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; - bool debugMode = true; + bool debugMode = false; bool timestamping = true; // Remembers APID to know at which command a procedure failed diff --git a/tmtc b/tmtc index ac2b9cb7..70a1d492 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit ac2b9cb712405ee07b9de1950fd6c923a6f184b5 +Subproject commit 70a1d49246b5bd5297c22d336e9dd8f58f019f90 From 1b92aa03f32cf366196cc7642ba63e8b83a308b6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Nov 2022 11:22:55 +0100 Subject: [PATCH 6/9] create dummy switcher --- bsp_hosted/ObjectFactory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 89b83041..6db37e93 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -1,5 +1,6 @@ #include "ObjectFactory.h" +#include #include #include #include @@ -79,6 +80,7 @@ void ObjectFactory::produce(void* args) { ObjectFactory::produceGenericObjects(nullptr, &pusFunnel, &cfdpFunnel); DummyGpioIF* dummyGpioIF = new DummyGpioIF(); + auto* dummySwitcher = new DummyPowerSwitcher(objects::PCDU_HANDLER, 18, 0); static_cast(dummyGpioIF); #ifdef PLATFORM_UNIX new SerialComIF(objects::UART_COM_IF); @@ -106,7 +108,7 @@ void ObjectFactory::produce(void* args) { #endif dummy::DummyCfg cfg; - dummy::createDummies(cfg); + dummy::createDummies(cfg, *dummySwitcher); new ThermalController(objects::THERMAL_CONTROLLER); new TestTask(objects::TEST_TASK); } From c7b90fb8e0d0a6bf1e2a20e36aee4e0e7882fbcb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Nov 2022 11:58:41 +0100 Subject: [PATCH 7/9] something hangs up --- linux/devices/ploc/PlocSupervisorHandler.cpp | 4 +-- linux/devices/ploc/PlocSupvUartMan.cpp | 37 ++++++-------------- linux/devices/ploc/PlocSupvUartMan.h | 4 +-- tmtc | 2 +- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 3a8565eb..b022f119 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -578,8 +578,8 @@ ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t r // } tmReader.setData(start, remainingSize); - sif::debug << "PlocSupervisorHandler::scanForReply: Received Packet" << std::endl; - arrayprinter::print(start, remainingSize); + // sif::debug << "PlocSupervisorHandler::scanForReply: Received Packet" << std::endl; + // arrayprinter::print(start, remainingSize); uint16_t apid = tmReader.getModuleApid(); switch (apid) { diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 6d938efe..955484e5 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -68,8 +68,8 @@ ReturnValue_t PlocSupvUartManager::initializeInterface(CookieIF* cookie) { // Use non-canonical mode and clear echo flag tty.c_lflag &= ~(ICANON | ECHO); - // Blocking mode, 0.5 seconds timeout - tty.c_cc[VTIME] = 5; + // Blocking mode, 0.2 seconds timeout + tty.c_cc[VTIME] = 2; tty.c_cc[VMIN] = 0; uart::setBaudrate(tty, uartCookie->getBaudrate()); @@ -429,8 +429,7 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { update.bytesWritten); return result; } - result = handlePacketTransmissionNoReply(packet); - // result = encodeAndSendPacket(packet.getFullPacket(), packet.getFullPacketLen()); + result = handlePacketTransmissionNoReply(packet, 2000); if (result != returnvalue::OK) { triggerEvent(WRITE_MEMORY_FAILED, buildProgParams1(progPercent, update.sequenceCount), update.bytesWritten); @@ -494,19 +493,6 @@ uint32_t PlocSupvUartManager::buildProgParams1(uint8_t percent, uint16_t seqCoun // return result; // } -ReturnValue_t PlocSupvUartManager::handleRemainingExeReport(ploc::SpTmReader& reader) { - size_t remBytes = reader.getPacketDataLen() + 1; - ReturnValue_t result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN); - if (result != returnvalue::OK) { - sif::warning << "Reading exe failure report failed" << std::endl; - } - result = exeReportHandling(); - if (result != returnvalue::OK) { - sif::warning << "Handling exe report failed" << std::endl; - } - return result; -} - ReturnValue_t PlocSupvUartManager::selectMemory() { ReturnValue_t result = returnvalue::OK; resetSpParams(); @@ -515,7 +501,7 @@ ReturnValue_t PlocSupvUartManager::selectMemory() { if (result != returnvalue::OK) { return result; } - result = handlePacketTransmissionNoReply(packet); + result = handlePacketTransmissionNoReply(packet, 2000); if (result != returnvalue::OK) { return result; } @@ -580,7 +566,6 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( if (not ackReceived) { retval = handleAckReception(packet, packetLen); if (retval == 1) { - sif::debug << "ACK received" << std::endl; ackReceived = true; packetWasHandled = true; } else if (retval == -1) { @@ -589,7 +574,6 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( } else { retval = handleExeAckReception(packet, packetLen); if (retval == 1) { - sif::debug << "EXE ACK received" << std::endl; break; } else if (retval == -1) { return returnvalue::FAILED; @@ -601,7 +585,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( decodedRingBuf.deleteData(packetLen); } } else { - TaskFactory::delayTask(50); + TaskFactory::delayTask(20); } if (countdown.hasTimedOut()) { return result::NO_REPLY_TIMEOUT; @@ -777,7 +761,6 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) { if (retval == 1) { packetWasHandled = true; exeReceived = true; - break; } else if (retval == -1) { return returnvalue::FAILED; } @@ -795,7 +778,6 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) { result = report.verifyCrc(update.crc); if (result == returnvalue::OK) { triggerEvent(SUPV_MEM_CHECK_OK, result); - return result; } else { sif::warning @@ -813,7 +795,7 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) { decodedRingBuf.deleteData(packetLen); } } else { - TaskFactory::delayTask(50); + TaskFactory::delayTask(20); } if (ackReceived and exeReceived and checkReplyReceived) { break; @@ -823,7 +805,6 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) { } } return returnvalue::OK; - return result; } uint32_t PlocSupvUartManager::getFileSize(std::string filename) { @@ -963,8 +944,10 @@ ReturnValue_t PlocSupvUartManager::handleRunningLongerRequest() { ReturnValue_t PlocSupvUartManager::encodeAndSendPacket(const uint8_t* sendData, size_t sendLen) { size_t encodedLen = 0; addHdlcFraming(sendData, sendLen, encodedSendBuf.data(), &encodedLen, encodedSendBuf.size()); - sif::debug << "Sending TC" << std::endl; - arrayprinter::print(encodedSendBuf.data(), encodedLen); + if (printTc) { + sif::debug << "Sending TC" << std::endl; + arrayprinter::print(encodedSendBuf.data(), encodedLen); + } size_t bytesWritten = write(serialPort, encodedSendBuf.data(), encodedLen); if (bytesWritten != encodedLen) { sif::warning diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index d36a9cd4..d9739e44 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -253,6 +253,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; + bool printTc = false; bool debugMode = false; bool timestamping = true; @@ -275,7 +276,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, ReturnValue_t writeUpdatePackets(); // ReturnValue_t performEventBufferRequest(); ReturnValue_t handlePacketTransmissionNoReply(supv::TcBase& packet, - uint32_t timeoutExecutionReport = 60000); + uint32_t timeoutExecutionReport); int handleAckReception(supv::TcBase& tc, size_t packetLen); int handleExeAckReception(supv::TcBase& tc, size_t packetLen); @@ -310,7 +311,6 @@ class PlocSupvUartManager : public DeviceCommunicationIF, */ uint32_t getFileSize(std::string filename); ReturnValue_t handleEventBufferReception(ploc::SpTmReader& reader); - ReturnValue_t handleRemainingExeReport(ploc::SpTmReader& reader); void resetSpParams(); void pushIpcData(const uint8_t* data, size_t len); diff --git a/tmtc b/tmtc index 70a1d492..292bafa0 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 70a1d49246b5bd5297c22d336e9dd8f58f019f90 +Subproject commit 292bafa0918d386e7f64bf9ed0e114a887420899 From 6766395f4450a1c8c0513611dfbae3742ef3c6e5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Nov 2022 14:42:17 +0100 Subject: [PATCH 8/9] works, but SW updates hangs at 21504 bytes --- .../devicedefinitions/PlocSupervisorDefinitions.h | 9 ++++++--- linux/devices/ploc/PlocSupvUartMan.cpp | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index 8c638c83..aad0a4c8 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -1154,8 +1154,11 @@ class WriteMemory : public TcBase { } spParams.creator.setSeqFlags(seqFlags); spParams.creator.setSeqCount(sequenceCount); - initPacket(memoryId, startAddress, length, updateData); - auto res = checkSizeAndSerializeHeader(); + auto res = initPacket(memoryId, startAddress, length, updateData); + if (res != returnvalue::OK) { + return res; + } + res = checkSizeAndSerializeHeader(); if (res != returnvalue::OK) { return res; } @@ -1182,7 +1185,7 @@ class WriteMemory : public TcBase { if (result != returnvalue::OK) { return result; } - size_t serializedSize = 6; + size_t serializedSize = MIN_TMTC_LEN; SerializeAdapter::serialize(&memoryId, &data, &serializedSize, spParams.maxSize, SerializeIF::Endianness::BIG); SerializeAdapter::serialize(&n, &data, &serializedSize, spParams.maxSize, diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 955484e5..919ac2aa 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -429,7 +429,7 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { update.bytesWritten); return result; } - result = handlePacketTransmissionNoReply(packet, 2000); + result = handlePacketTransmissionNoReply(packet, 5000); if (result != returnvalue::OK) { triggerEvent(WRITE_MEMORY_FAILED, buildProgParams1(progPercent, update.sequenceCount), update.bytesWritten); @@ -443,7 +443,7 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 progressPrinter.print(update.bytesWritten); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ - TaskFactory::delayTask(1); + // TaskFactory::delayTask(1); } return result; } From c731418b65a7d51697b0e4ae0eeb2f49db40f782 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 25 Nov 2022 10:28:20 +0100 Subject: [PATCH 9/9] disable PLOC SUPV for host build --- bsp_hosted/OBSWConfig.h.in | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp_hosted/OBSWConfig.h.in b/bsp_hosted/OBSWConfig.h.in index 9a80286d..f234e795 100644 --- a/bsp_hosted/OBSWConfig.h.in +++ b/bsp_hosted/OBSWConfig.h.in @@ -15,7 +15,7 @@ #define OBSW_ENABLE_TIMERS 1 #define OBSW_ADD_STAR_TRACKER 0 -#define OBSW_ADD_PLOC_SUPERVISOR 1 +#define OBSW_ADD_PLOC_SUPERVISOR 0 #define OBSW_ADD_PLOC_MPSOC 0 #define OBSW_ADD_SUN_SENSORS 0 #define OBSW_ADD_MGT 0 diff --git a/tmtc b/tmtc index 292bafa0..a54ae782 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 292bafa0918d386e7f64bf9ed0e114a887420899 +Subproject commit a54ae782d46f6f405df8e62ab80b556f971df369