From 9d02322cd733aa2e9d21fce3ba90754c860c47f9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Nov 2022 14:26:52 +0100 Subject: [PATCH] continue refactoring --- .../PlocSupervisorDefinitions.h | 76 ++-- linux/devices/ploc/PlocSupervisorHandler.cpp | 328 +++++++++--------- linux/devices/ploc/PlocSupervisorHandler.h | 19 +- linux/devices/ploc/PlocSupvUartMan.cpp | 242 ++++++------- 4 files changed, 347 insertions(+), 318 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index aa28c143..34ac413e 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -142,20 +142,20 @@ static const uint16_t SIZE_ADC_REPORT = 72; /** * SpacePacket apids of telemetry packets */ -static const uint16_t APID_ACK_SUCCESS = 0x200; -static const uint16_t APID_ACK_FAILURE = 0x201; -static const uint16_t APID_EXE_SUCCESS = 0x202; -static const uint16_t APID_EXE_FAILURE = 0x203; -static const uint16_t APID_HK_REPORT = 0x204; -static const uint16_t APID_BOOT_STATUS_REPORT = 0x205; -static const uint16_t APID_UPDATE_STATUS_REPORT = 0x206; -static const uint16_t APID_ADC_REPORT = 0x207; -static const uint16_t APID_LATCHUP_STATUS_REPORT = 0x208; -static const uint16_t APID_SOC_SYSMON = 0x209; -static const uint16_t APID_MRAM_DUMP_TM = 0x20A; -static const uint16_t APID_SRAM = 0x20B; -static const uint16_t APID_NOR_DATA = 0x20C; -static const uint16_t APID_DATA_LOGGER_DATA = 0x20D; +// static const uint16_t APID_ACK_SUCCESS = 0x200; +// static const uint16_t APID_ACK_FAILURE = 0x201; +// static const uint16_t APID_EXE_SUCCESS = 0x202; +// static const uint16_t APID_EXE_FAILURE = 0x203; +// static const uint16_t APID_HK_REPORT = 0x204; +// static const uint16_t APID_BOOT_STATUS_REPORT = 0x205; +// static const uint16_t APID_UPDATE_STATUS_REPORT = 0x206; +// static const uint16_t APID_ADC_REPORT = 0x207; +// static const uint16_t APID_LATCHUP_STATUS_REPORT = 0x208; +// static const uint16_t APID_SOC_SYSMON = 0x209; +// static const uint16_t APID_MRAM_DUMP_TM = 0x20A; +// static const uint16_t APID_SRAM = 0x20B; +// static const uint16_t APID_NOR_DATA = 0x20C; +// static const uint16_t APID_DATA_LOGGER_DATA = 0x20D; /** * APIDs of telecommand packets @@ -163,7 +163,7 @@ static const uint16_t APID_DATA_LOGGER_DATA = 0x20D; // 2 bits APID SRC, 00 for OBC, 2 bits APID DEST, 01 for SUPV, 7 bits CMD ID -> Mask 0x080 static constexpr uint16_t APID_TC_SUPV_MASK = 0x080; -enum Apids { +enum Apid { TMTC_MAN = 0x00, HK = 0x01, BOOT_MAN = 0x02, @@ -445,6 +445,8 @@ class TcBase : public ploc::SpTcBase { class TmBase : public ploc::SpTmReader { public: + TmBase() = default; + TmBase(const uint8_t* data, size_t maxSize) : ploc::SpTmReader(data, maxSize) { if (maxSize < MIN_TMTC_LEN) { sif::error << "SupvTcBase::SupvTcBase: Passed buffer is too small" << std::endl; @@ -507,7 +509,7 @@ class MPSoCBootSelect : public TcBase { * @note Selection of partitions is currently not supported. */ MPSoCBootSelect(TcParams params) - : TcBase(params, Apids::BOOT_MAN, static_cast(tc::BootManId::SELECT_IMAGE), 4) {} + : TcBase(params, Apid::BOOT_MAN, static_cast(tc::BootManId::SELECT_IMAGE), 4) {} ReturnValue_t buildPacket(uint8_t mem = 0, uint8_t bp0 = 0, uint8_t bp1 = 0, uint8_t bp2 = 0) { auto res = checkSizeAndSerializeHeader(); @@ -534,7 +536,7 @@ class SetTimeRef : public TcBase { public: static constexpr size_t PAYLOAD_LEN = 8; SetTimeRef(TcParams params) - : TcBase(params, Apids::TMTC_MAN, static_cast(tc::TmtcId::TIME_REF), 8) {} + : TcBase(params, Apid::TMTC_MAN, static_cast(tc::TmtcId::TIME_REF), 8) {} ReturnValue_t buildPacket(Clock::TimeOfDay_t* time) { auto res = checkSizeAndSerializeHeader(); @@ -609,7 +611,7 @@ class SetBootTimeout : public TcBase { * @param timeout The boot timeout in milliseconds. */ SetBootTimeout(TcParams params) - : TcBase(params, Apids::BOOT_MAN, static_cast(tc::BootManId::SET_BOOT_TIMEOUT), + : TcBase(params, Apid::BOOT_MAN, static_cast(tc::BootManId::SET_BOOT_TIMEOUT), PAYLOAD_LEN) {} ReturnValue_t buildPacket(uint32_t timeout) { @@ -641,7 +643,7 @@ class SetRestartTries : public TcBase { * @param restartTries Maximum restart tries to set. */ SetRestartTries(TcParams params) - : TcBase(params, Apids::BOOT_MAN, static_cast(tc::BootManId::SET_MAX_REBOOT_TRIES), + : TcBase(params, Apid::BOOT_MAN, static_cast(tc::BootManId::SET_MAX_REBOOT_TRIES), 1) {} ReturnValue_t buildPacket(uint8_t restartTries) { @@ -670,7 +672,7 @@ class DisablePeriodicHkTransmission : public TcBase { * @brief Constructor */ DisablePeriodicHkTransmission(TcParams params) - : TcBase(params, Apids::HK, static_cast(tc::HkId::ENABLE), 1) {} + : TcBase(params, Apid::HK, static_cast(tc::HkId::ENABLE), 1) {} ReturnValue_t buildPacket() { auto res = checkSizeAndSerializeHeader(); @@ -699,7 +701,7 @@ class LatchupAlert : public TcBase { * @param latchupId Identifies the latchup to enable/disable (0 - 0.85V, 1 - 1.8V, 2 - MISC, * 3 - 3.3V, 4 - NVM_4XO, 5 - MISSION, 6 - SAFECOTS) */ - LatchupAlert(TcParams params) : TcBase(params, Apids::LATCHUP_MON) { setLenFromPayloadLen(1); } + LatchupAlert(TcParams params) : TcBase(params, Apid::LATCHUP_MON) { setLenFromPayloadLen(1); } ReturnValue_t buildPacket(bool state, uint8_t latchupId) { if (state) { @@ -731,7 +733,7 @@ class SetAlertlimit : public TcBase { * @param dutycycle */ SetAlertlimit(TcParams params) - : TcBase(params, Apids::LATCHUP_MON, static_cast(tc::LatchupMonId::SET_ALERT_LIMIT), + : TcBase(params, Apid::LATCHUP_MON, static_cast(tc::LatchupMonId::SET_ALERT_LIMIT), 5) {} ReturnValue_t buildPacket(uint8_t latchupId, uint32_t dutycycle) { @@ -771,7 +773,7 @@ class SetAdcWindowAndStride : public TcBase { * @param stridingStepSize */ SetAdcWindowAndStride(TcParams params) - : TcBase(params, Apids::ADC_MON, static_cast(tc::AdcMonId::SET_WINDOW_STRIDE), 4) {} + : TcBase(params, Apid::ADC_MON, static_cast(tc::AdcMonId::SET_WINDOW_STRIDE), 4) {} ReturnValue_t buildPacket(uint16_t windowSize, uint16_t stridingStepSize) { auto res = checkSizeAndSerializeHeader(); @@ -804,7 +806,7 @@ class SetAdcThreshold : public TcBase { * @param threshold */ SetAdcThreshold(TcParams params) - : TcBase(params, Apids::ADC_MON, static_cast(tc::AdcMonId::SET_ADC_THRESHOLD), 4) {} + : TcBase(params, Apid::ADC_MON, static_cast(tc::AdcMonId::SET_ADC_THRESHOLD), 4) {} ReturnValue_t buildPacket(uint32_t threshold) { auto res = checkSizeAndSerializeHeader(); @@ -834,7 +836,7 @@ class RunAutoEmTests : public TcBase { * @param test 1 - complete EM test, 2 - Short test (only memory readback NVM0,1,3) */ RunAutoEmTests(TcParams params) - : TcBase(params, Apids::TMTC_MAN, static_cast(tc::TmtcId::RUN_AUTO_EM_TEST), 1) {} + : TcBase(params, Apid::TMTC_MAN, static_cast(tc::TmtcId::RUN_AUTO_EM_TEST), 1) {} ReturnValue_t buildPacket(uint8_t test) { auto res = checkSizeAndSerializeHeader(); @@ -865,7 +867,7 @@ class SetGpio : public TcBase { * @param val */ SetGpio(TcParams params) - : TcBase(params, Apids::TMTC_MAN, static_cast(tc::TmtcId::SET_GPIO), 3) {} + : TcBase(params, Apid::TMTC_MAN, static_cast(tc::TmtcId::SET_GPIO), 3) {} ReturnValue_t buildPacket(uint8_t port, uint8_t pin, uint8_t val) { auto res = checkSizeAndSerializeHeader(); @@ -901,7 +903,7 @@ class ReadGpio : public TcBase { * @param pin */ ReadGpio(TcParams params) - : TcBase(params, Apids::TMTC_MAN, static_cast(tc::TmtcId::READ_GPIO), 2) {} + : TcBase(params, Apid::TMTC_MAN, static_cast(tc::TmtcId::READ_GPIO), 2) {} ReturnValue_t buildPacket(uint8_t port, uint8_t pin) { auto res = checkSizeAndSerializeHeader(); @@ -925,7 +927,7 @@ class ReadGpio : public TcBase { class SetShutdownTimeout : public TcBase { public: SetShutdownTimeout(TcParams params) - : TcBase(params, Apids::BOOT_MAN, static_cast(tc::BootManId::SHUTDOWN_TIMEOUT), 4) {} + : TcBase(params, Apid::BOOT_MAN, static_cast(tc::BootManId::SHUTDOWN_TIMEOUT), 4) {} ReturnValue_t buildPacket(uint32_t timeout) { auto res = checkSizeAndSerializeHeader(); @@ -957,7 +959,7 @@ class CheckMemory : public TcBase { * @param length Length in bytes of memory region */ CheckMemory(TcParams params) - : TcBase(params, Apids::MEM_MAN, static_cast(tc::MemManId::CHECK), 10) {} + : TcBase(params, Apid::MEM_MAN, static_cast(tc::MemManId::CHECK), 10) {} ReturnValue_t buildPacket(uint8_t memoryId, uint32_t startAddress, uint32_t length) { auto res = checkSizeAndSerializeHeader(); @@ -997,7 +999,7 @@ class WriteMemory : public TcBase { * @param updateData Pointer to buffer containing update data */ WriteMemory(TcParams params) - : TcBase(params, Apids::MEM_MAN, static_cast(tc::MemManId::WRITE), 1) {} + : TcBase(params, Apid::MEM_MAN, static_cast(tc::MemManId::WRITE), 1) {} ReturnValue_t buildPacket(ccsds::SequenceFlags seqFlags, uint16_t sequenceCount, uint8_t memoryId, uint32_t startAddress, uint16_t length, uint8_t* updateData) { @@ -1060,7 +1062,7 @@ class WriteMemory : public TcBase { class EraseMemory : public TcBase { public: EraseMemory(TcParams params) - : TcBase(params, Apids::MEM_MAN, static_cast(tc::MemManId::ERASE), PAYLOAD_LENGTH) {} + : TcBase(params, Apid::MEM_MAN, static_cast(tc::MemManId::ERASE), PAYLOAD_LENGTH) {} ReturnValue_t buildPacket(uint8_t memoryId, uint32_t startAddress, uint32_t length) { auto res = checkSizeAndSerializeHeader(); @@ -1100,7 +1102,7 @@ class VerificationReport { if (not readerBase.crcIsOk()) { return result::CRC_FAILURE; } - if (readerBase.getApid() != Apids::TMTC_MAN) { + if (readerBase.getApid() != Apid::TMTC_MAN) { return result::INVALID_APID; } if (readerBase.getBufSize() < MIN_PAYLOAD_LEN + 8) { @@ -1823,7 +1825,7 @@ class FactoryReset : public TcBase { * * @param op */ - FactoryReset(TcParams params) : TcBase(params, Apids::TMTC_MAN, 0x11, 1) {} + FactoryReset(TcParams params) : TcBase(params, Apid::TMTC_MAN, 0x11, 1) {} ReturnValue_t buildPacket(Op op) { auto res = checkSizeAndSerializeHeader(); @@ -1867,7 +1869,7 @@ class EnableNvms : public TcBase { * @param bp1 Partition pin 1 * @param bp2 Partition pin 2 */ - EnableNvms(TcParams params) : TcBase(params, Apids::TMTC_MAN, 0x06, 2) {} + EnableNvms(TcParams params) : TcBase(params, Apid::TMTC_MAN, 0x06, 2) {} ReturnValue_t buildPacket(uint8_t nvm01, uint8_t nvm3) { auto res = checkSizeAndSerializeHeader(); @@ -1901,7 +1903,7 @@ class MramCmd : public TcBase { * * @note The content at the stop address is excluded from the dump or wipe operation. */ - MramCmd(TcParams params) : TcBase(params, Apids::DATA_LOGGER) { setLenFromPayloadLen(6); } + MramCmd(TcParams params) : TcBase(params, Apid::DATA_LOGGER) { setLenFromPayloadLen(6); } ReturnValue_t buildPacket(uint32_t start, uint32_t stop, MramAction action) { if (action == MramAction::WIPE) { @@ -1996,8 +1998,8 @@ class SetAdcEnabledChannels : public TcBase { * @param ch Defines channels to be enabled or disabled. */ SetAdcEnabledChannels(TcParams params) - : TcBase(params, Apids::ADC_MON, static_cast(tc::AdcMonId::SET_ENABLED_CHANNELS), - 2) {} + : TcBase(params, Apid::ADC_MON, static_cast(tc::AdcMonId::SET_ENABLED_CHANNELS), 2) { + } ReturnValue_t buildPacket(uint16_t ch) { auto res = checkSizeAndSerializeHeader(); diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 6ec92f98..9f9ac9ea 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -223,17 +223,17 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d spParams.buf = commandBuffer; switch (deviceCommand) { case GET_HK_REPORT: { - prepareEmptyCmd(Apids::HK, static_cast(tc::HkId::GET_REPORT)); + prepareEmptyCmd(Apid::HK, static_cast(tc::HkId::GET_REPORT)); result = returnvalue::OK; break; } case START_MPSOC: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::START_MPSOC)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::START_MPSOC)); result = returnvalue::OK; break; } case SHUTDOWN_MPSOC: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::SHUTDOWN_MPSOC)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::SHUTDOWN_MPSOC)); result = returnvalue::OK; break; } @@ -243,7 +243,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d break; } case RESET_MPSOC: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::RESET_MPSOC)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::RESET_MPSOC)); result = returnvalue::OK; break; } @@ -267,7 +267,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d break; } case GET_BOOT_STATUS_REPORT: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::GET_BOOT_STATUS_REPORT)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::GET_BOOT_STATUS_REPORT)); result = returnvalue::OK; break; } @@ -299,8 +299,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d // break; // } case GET_LATCHUP_STATUS_REPORT: { - prepareEmptyCmd(Apids::LATCHUP_MON, - static_cast(tc::LatchupMonId::GET_STATUS_REPORT)); + prepareEmptyCmd(Apid::LATCHUP_MON, static_cast(tc::LatchupMonId::GET_STATUS_REPORT)); result = returnvalue::OK; break; } @@ -381,7 +380,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d break; } case FACTORY_FLASH: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::FACTORY_FLASH)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::FACTORY_FLASH)); result = returnvalue::OK; break; } @@ -435,7 +434,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d // break; // } case RESET_PL: { - prepareEmptyCmd(Apids::BOOT_MAN, static_cast(tc::BootManId::RESET_PL)); + prepareEmptyCmd(Apid::BOOT_MAN, static_cast(tc::BootManId::RESET_PL)); result = returnvalue::OK; break; } @@ -654,73 +653,66 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId, size_t* foundLen) { using namespace supv; - if (nextReplyId == FIRST_MRAM_DUMP) { - *foundId = FIRST_MRAM_DUMP; - return parseMramPackets(start, remainingSize, foundLen); - } else if (nextReplyId == CONSECUTIVE_MRAM_DUMP) { - *foundId = CONSECUTIVE_MRAM_DUMP; - return parseMramPackets(start, remainingSize, foundLen); - } + // TODO: Is this still required? + // if (nextReplyId == FIRST_MRAM_DUMP) { + // *foundId = FIRST_MRAM_DUMP; + // return parseMramPackets(start, remainingSize, foundLen); + // } else if (nextReplyId == CONSECUTIVE_MRAM_DUMP) { + // *foundId = CONSECUTIVE_MRAM_DUMP; + // return parseMramPackets(start, remainingSize, foundLen); + // } - ReturnValue_t result = returnvalue::OK; - - uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK; + tmReader.setData(start, remainingSize); + uint16_t apid = tmReader.getApid(); //(*(start) << 8 | *(start + 1)) & APID_MASK; switch (apid) { - case (APID_ACK_SUCCESS): - *foundLen = SIZE_ACK_REPORT; - *foundId = ACK_REPORT; + case (Apid::TMTC_MAN): { + switch (tmReader.getServiceId()) { + case (static_cast(supv::tm::TmtcId::ACK)): + case (static_cast(supv::tm::TmtcId::NAK)): { + *foundLen = SIZE_ACK_REPORT; + *foundId = ACK_REPORT; + return OK; + } + case (static_cast(supv::tm::TmtcId::EXEC_ACK)): + case (static_cast(supv::tm::TmtcId::EXEC_NAK)): { + *foundLen = SIZE_EXE_REPORT; + *foundId = EXE_REPORT; + return OK; + } + } break; - case (APID_ACK_FAILURE): - *foundLen = SIZE_ACK_REPORT; - *foundId = ACK_REPORT; + } + case (Apid::HK): { + if (tmReader.getServiceId() == static_cast(supv::tm::HkId::REPORT)) { + *foundLen = SIZE_HK_REPORT; + *foundId = HK_REPORT; + return OK; + } else if (tmReader.getServiceId() == static_cast(supv::tm::HkId::HARDFAULTS)) { + handleBadApidServiceCombination(SUPV_UNINIMPLEMENTED_TM, apid, tmReader.getServiceId()); + return INVALID_DATA; + } break; - case (APID_HK_REPORT): - *foundLen = SIZE_HK_REPORT; - *foundId = HK_REPORT; + } + case (Apid::BOOT_MAN): { + if (tmReader.getServiceId() == + static_cast(supv::tm::BootManId::BOOT_STATUS_REPORT)) { + *foundLen = SIZE_BOOT_STATUS_REPORT; + *foundId = BOOT_STATUS_REPORT; + return OK; + } break; - case (APID_BOOT_STATUS_REPORT): - *foundLen = SIZE_BOOT_STATUS_REPORT; - *foundId = BOOT_STATUS_REPORT; - break; - case (APID_LATCHUP_STATUS_REPORT): - *foundLen = SIZE_LATCHUP_STATUS_REPORT; - *foundId = LATCHUP_REPORT; - break; - case (APID_DATA_LOGGER_DATA): - *foundLen = SIZE_LOGGING_REPORT; - *foundId = LOGGING_REPORT; - break; - case (APID_ADC_REPORT): - *foundLen = SIZE_ADC_REPORT; - *foundId = ADC_REPORT; - break; - case (APID_EXE_SUCCESS): - *foundLen = SIZE_EXE_REPORT; - *foundId = EXE_REPORT; - break; - case (APID_EXE_FAILURE): - *foundLen = SIZE_EXE_REPORT; - *foundId = EXE_REPORT; - break; - default: { - sif::debug << "PlocSupervisorHandler::scanForReply: Reply has invalid apid" << std::endl; - *foundLen = remainingSize; - return result::INVALID_APID; + } + case (Apid::MEM_MAN): { + if (tmReader.getServiceId() == + static_cast(supv::tm::MemManId::UPDATE_STATUS_REPORT)) { + // TODO: I think this will be handled by the uart manager + } } } - - return result; -} - -ReturnValue_t PlocSupervisorHandler::getSwitches(const uint8_t** switches, - uint8_t* numberOfSwitches) { - if (powerSwitch == power::NO_SWITCH) { - return DeviceHandlerBase::NO_SWITCH; - } - *numberOfSwitches = 1; - *switches = &powerSwitch; - return returnvalue::OK; + handleBadApidServiceCombination(SUPV_UNKNOWN_TM, apid, tmReader.getServiceId()); + *foundLen = remainingSize; + return INVALID_DATA; } ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id, @@ -771,6 +763,16 @@ ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id, return result; } +ReturnValue_t PlocSupervisorHandler::getSwitches(const uint8_t** switches, + uint8_t* numberOfSwitches) { + if (powerSwitch == power::NO_SWITCH) { + return DeviceHandlerBase::NO_SWITCH; + } + *numberOfSwitches = 1; + *switches = &powerSwitch; + return returnvalue::OK; +} + void PlocSupervisorHandler::setNormalDatapoolEntriesInvalid() {} uint32_t PlocSupervisorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { @@ -932,56 +934,57 @@ ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) { ReturnValue_t result = returnvalue::OK; // TODO: Fix - // AcknowledgmentReport ack(data, SIZE_ACK_REPORT); - // result = ack.checkSize(); - // if (result != returnvalue::OK) { - // return result; - // } + + // AcknowledgmentReport ack(data, SIZE_ACK_REPORT); + // result = ack.checkSize(); + // if (result != returnvalue::OK) { + // return result; + // } // - // result = ack.checkCrc(); - // if (result != returnvalue::OK) { - // sif::error << "PlocSupervisorHandler::handleAckReport: CRC failure" << std::endl; - // nextReplyId = supv::NONE; - // replyRawReplyIfnotWiretapped(data, supv::SIZE_ACK_REPORT); - // triggerEvent(SUPV_CRC_FAILURE_EVENT); - // sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::CRC_FAILURE); - // disableAllReplies(); - // return returnvalue::OK; - // } + // result = ack.checkCrc(); + // if (result != returnvalue::OK) { + // sif::error << "PlocSupervisorHandler::handleAckReport: CRC failure" << std::endl; + // nextReplyId = supv::NONE; + // replyRawReplyIfnotWiretapped(data, supv::SIZE_ACK_REPORT); + // triggerEvent(SUPV_CRC_FAILURE_EVENT); + // sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::CRC_FAILURE); + // disableAllReplies(); + // return returnvalue::OK; + // } // - // result = ack.checkApid(); + // result = ack.checkApid(); // - // switch (result) { - // case SupvReturnValuesIF::RECEIVED_ACK_FAILURE: { - // DeviceCommandId_t commandId = getPendingCommand(); - // if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { - // triggerEvent(SUPV_ACK_FAILURE, commandId, static_cast(ack.getStatusCode())); - // } - // printAckFailureInfo(ack.getStatusCode(), commandId); - // sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::RECEIVED_ACK_FAILURE); - // disableAllReplies(); - // nextReplyId = supv::NONE; - // result = IGNORE_REPLY_DATA; - // break; - // } - // case returnvalue::OK: { - // setNextReplyId(); - // break; - // } - // case SupvReturnValuesIF::INVALID_APID: - // sif::warning << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report" - // << std::endl; - // sendFailureReport(supv::ACK_REPORT, result); - // disableAllReplies(); - // nextReplyId = supv::NONE; - // result = IGNORE_REPLY_DATA; - // break; - // default: { - // sif::error << "PlocSupervisorHandler::handleAckReport: APID parsing failed" << std::endl; - // result = returnvalue::FAILED; - // break; - // } - // } + // switch (result) { + // case SupvReturnValuesIF::RECEIVED_ACK_FAILURE: { + // DeviceCommandId_t commandId = getPendingCommand(); + // if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { + // triggerEvent(SUPV_ACK_FAILURE, commandId, static_cast(ack.getStatusCode())); + // } + // printAckFailureInfo(ack.getStatusCode(), commandId); + // sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::RECEIVED_ACK_FAILURE); + // disableAllReplies(); + // nextReplyId = supv::NONE; + // result = IGNORE_REPLY_DATA; + // break; + // } + // case returnvalue::OK: { + // setNextReplyId(); + // break; + // } + // case SupvReturnValuesIF::INVALID_APID: + // sif::warning << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report" + // << std::endl; + // sendFailureReport(supv::ACK_REPORT, result); + // disableAllReplies(); + // nextReplyId = supv::NONE; + // result = IGNORE_REPLY_DATA; + // break; + // default: { + // sif::error << "PlocSupervisorHandler::handleAckReport: APID parsing failed" << std::endl; + // result = returnvalue::FAILED; + // break; + // } + // } return result; } @@ -1806,39 +1809,40 @@ void PlocSupervisorHandler::disableExeReportReply() { info->command->second.expectedReplies = 1; } -ReturnValue_t PlocSupervisorHandler::parseMramPackets(const uint8_t* packet, size_t remainingSize, - size_t* foundLen) { - ReturnValue_t result = IGNORE_FULL_PACKET; - uint16_t packetLen = 0; - *foundLen = 0; - - for (size_t idx = 0; idx < remainingSize; idx++) { - std::memcpy(spacePacketBuffer + bufferTop, packet + idx, 1); - bufferTop += 1; - *foundLen += 1; - if (bufferTop >= ccsds::HEADER_LEN) { - packetLen = readSpacePacketLength(spacePacketBuffer); - } - - if (bufferTop == ccsds::HEADER_LEN + packetLen + 1) { - packetInBuffer = true; - bufferTop = 0; - return checkMramPacketApid(); - } - - if (bufferTop == supv::MAX_PACKET_SIZE) { - *foundLen = remainingSize; - disableAllReplies(); - bufferTop = 0; - sif::info << "PlocSupervisorHandler::parseMramPackets: Can not find MRAM packet in space " - "packet buffer" - << std::endl; - return result::MRAM_PACKET_PARSING_FAILURE; - } - } - - return result; -} +// ReturnValue_t PlocSupervisorHandler::parseMramPackets(const uint8_t* packet, size_t +// remainingSize, +// size_t* foundLen) { +// ReturnValue_t result = IGNORE_FULL_PACKET; +// uint16_t packetLen = 0; +// *foundLen = 0; +// +// for (size_t idx = 0; idx < remainingSize; idx++) { +// std::memcpy(spacePacketBuffer + bufferTop, packet + idx, 1); +// bufferTop += 1; +// *foundLen += 1; +// if (bufferTop >= ccsds::HEADER_LEN) { +// packetLen = readSpacePacketLength(spacePacketBuffer); +// } +// +// if (bufferTop == ccsds::HEADER_LEN + packetLen + 1) { +// packetInBuffer = true; +// bufferTop = 0; +// return checkMramPacketApid(); +// } +// +// if (bufferTop == supv::MAX_PACKET_SIZE) { +// *foundLen = remainingSize; +// disableAllReplies(); +// bufferTop = 0; +// sif::info << "PlocSupervisorHandler::parseMramPackets: Can not find MRAM packet in space " +// "packet buffer" +// << std::endl; +// return result::MRAM_PACKET_PARSING_FAILURE; +// } +// } +// +// return result; +// } ReturnValue_t PlocSupervisorHandler::handleMramDumpPacket(DeviceCommandId_t id) { ReturnValue_t result = returnvalue::FAILED; @@ -1916,13 +1920,14 @@ void PlocSupervisorHandler::increaseExpectedMramReplies(DeviceCommandId_t id) { return; } -ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() { - uint16_t apid = (spacePacketBuffer[0] << 8 | spacePacketBuffer[1]) & supv::APID_MASK; - if (apid != supv::APID_MRAM_DUMP_TM) { - return result::NO_MRAM_PACKET; - } - return APERIODIC_REPLY; -} +// ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() { +// uint16_t apid = (spacePacketBuffer[0] << 8 | spacePacketBuffer[1]) & supv::APID_MASK; +// TODO: Fix +// if (apid != supv::APID_MRAM_DUMP_TM) { +// return result::NO_MRAM_PACKET; +// } +// return APERIODIC_REPLY; +//} ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) { #ifdef XIPHOS_Q7S @@ -2164,6 +2169,19 @@ void PlocSupervisorHandler::handleExecutionFailureReport(uint16_t statusCode) { disableExeReportReply(); } +void PlocSupervisorHandler::handleBadApidServiceCombination(Event event, unsigned int apid, + unsigned int serviceId) { + const char* printString = ""; + if (event == SUPV_UNKNOWN_TM) { + printString = "Unknown"; + } else if (event == SUPV_UNINIMPLEMENTED_TM) { + printString = "Unimplemented"; + } + triggerEvent(event, apid, tmReader.getServiceId()); + sif::error << printString << " APID service combination 0x" << std::setw(2) << std::setfill('0') + << std::hex << apid << ", " << std::setw(2) << serviceId << std::endl; +} + void PlocSupervisorHandler::printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId) { sif::warning << "PlocSupervisorHandler: Received Ack failure report with status code: 0x" << std::hex << statusCode << std::endl; diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index 744d05ea..4221bf4d 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -64,18 +64,21 @@ class PlocSupervisorHandler : public DeviceHandlerBase { //! [EXPORT] : [COMMENT] PLOC supervisor crc failure in telemetry packet static const Event SUPV_MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW); + //! [EXPORT] : [COMMENT] Unhandled event. P1: APID, P2: Service ID + static constexpr Event SUPV_UNKNOWN_TM = MAKE_EVENT(2, severity::LOW); + static constexpr Event SUPV_UNINIMPLEMENTED_TM = MAKE_EVENT(3, severity::LOW); //! [EXPORT] : [COMMENT] PLOC supervisor received acknowledgment failure report - static const Event SUPV_ACK_FAILURE = MAKE_EVENT(2, severity::LOW); + static const Event SUPV_ACK_FAILURE = MAKE_EVENT(4, severity::LOW); //! [EXPORT] : [COMMENT] PLOC received execution failure report //! P1: ID of command for which the execution failed //! P2: Status code sent by the supervisor handler - static const Event SUPV_EXE_FAILURE = MAKE_EVENT(3, severity::LOW); + static const Event SUPV_EXE_FAILURE = MAKE_EVENT(5, severity::LOW); //! [EXPORT] : [COMMENT] PLOC supervisor reply has invalid crc - static const Event SUPV_CRC_FAILURE_EVENT = MAKE_EVENT(4, severity::LOW); + static const Event SUPV_CRC_FAILURE_EVENT = MAKE_EVENT(6, severity::LOW); //! [EXPORT] : [COMMENT] Supervisor helper currently executing a command - static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(5, severity::LOW); + 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(5, severity::LOW); + static const Event SUPV_MPSOC_SHUWDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW); static const uint16_t APID_MASK = 0x7FF; static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; @@ -121,6 +124,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { supv::AdcReport adcReport; const power::Switch_t powerSwitch = power::NO_SWITCH; + supv::TmBase tmReader; PlocSupvHelper* supvHelper = nullptr; MessageQueueIF* eventQueue = nullptr; @@ -210,6 +214,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { ReturnValue_t handleBootStatusReport(const uint8_t* data); ReturnValue_t handleLatchupStatusReport(const uint8_t* data); + void handleBadApidServiceCombination(Event result, unsigned int apid, unsigned int serviceId); // ReturnValue_t handleLoggingReport(const uint8_t* data); ReturnValue_t handleAdcReport(const uint8_t* data); @@ -317,7 +322,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { * @brief Function is called in scanForReply and fills the spacePacketBuffer with the read * data until a full packet has been received. */ - ReturnValue_t parseMramPackets(const uint8_t* packet, size_t remainingSize, size_t* foundlen); + // ReturnValue_t parseMramPackets(const uint8_t* packet, size_t remainingSize, size_t* foundlen); /** * @brief This function generates the Service 8 packets for the MRAM dump data. @@ -335,7 +340,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { * @brief Function checks if the packet written to the space packet buffer is really a * MRAM dump packet. */ - ReturnValue_t checkMramPacketApid(); + // ReturnValue_t checkMramPacketApid(); /** * @brief Writes the data of the MRAM dump to a file. The file will be created when receiving diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 53488ce2..997c6a7a 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -500,7 +500,7 @@ ReturnValue_t PlocSupvHelper::selectMemory() { ReturnValue_t PlocSupvHelper::prepareUpdate() { ReturnValue_t result = returnvalue::OK; resetSpParams(); - supv::NoPayloadPacket packet(spParams, Apids::BOOT_MAN, + supv::NoPayloadPacket packet(spParams, Apid::BOOT_MAN, static_cast(tc::BootManId::PREPARE_UPDATE)); result = packet.buildPacket(); if (result != returnvalue::OK) { @@ -584,7 +584,7 @@ ReturnValue_t PlocSupvHelper::handleAck() { // } // return result; // } - return returnvalue::OK; + return result; } ReturnValue_t PlocSupvHelper::handleExe(uint32_t timeout) { @@ -735,74 +735,76 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() { ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() { ReturnValue_t result = returnvalue::OK; - resetSpParams(); - // Will hold status report for later processing - std::array statusReportBuf{}; - supv::UpdateStatusReport updateStatusReport(tmBuf.data(), tmBuf.size()); - // Verification of update write procedure - supv::CheckMemory packet(spParams); - result = packet.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); - if (result != returnvalue::OK) { - return result; - } - result = sendCommand(packet); - if (result != returnvalue::OK) { - return result; - } - result = handleAck(); - if (result != returnvalue::OK) { - return result; - } - - bool exeAlreadyHandled = false; - uint32_t timeout = std::max(CRC_EXECUTION_TIMEOUT, supv::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) { - 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, - supv::timeout::UPDATE_STATUS_REPORT); - if (result != returnvalue::OK) { - sif::warning - << "PlocSupvHelper::handleCheckMemoryCommand: Failed to receive update status report" - << std::endl; - return result; - } - result = updateStatusReport.checkCrc(); - if (result != returnvalue::OK) { - sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC check failed" << std::endl; - return result; - } - // Copy into other buffer because data will be overwritten when reading execution report - std::memcpy(statusReportBuf.data(), tmBuf.data(), updateStatusReport.getNominalSize()); - } - - if (not exeAlreadyHandled) { - result = handleExe(CRC_EXECUTION_TIMEOUT); - if (result != returnvalue::OK) { - return result; - } - } - - // Now process the status report - updateStatusReport.setData(statusReportBuf.data(), statusReportBuf.size()); - result = updateStatusReport.parseDataField(); - if (result != returnvalue::OK) { - return result; - } - if (update.crcShouldBeChecked) { - result = updateStatusReport.verifycrc(update.crc); - if (result != returnvalue::OK) { - sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC failure. Expected CRC 0x" - << std::setfill('0') << std::hex << std::setw(4) - << static_cast(update.crc) << " but received CRC 0x" << std::setw(4) - << updateStatusReport.getCrc() << std::dec << std::endl; - return result; - } - } + // TODO: Fix + // resetSpParams(); + // // Will hold status report for later processing + // std::array statusReportBuf{}; + // supv::UpdateStatusReport updateStatusReport(tmBuf.data(), tmBuf.size()); + // // Verification of update write procedure + // supv::CheckMemory packet(spParams); + // result = packet.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); + // if (result != returnvalue::OK) { + // return result; + // } + // result = sendCommand(packet); + // if (result != returnvalue::OK) { + // return result; + // } + // result = handleAck(); + // if (result != returnvalue::OK) { + // return result; + // } + // + // bool exeAlreadyHandled = false; + // uint32_t timeout = std::max(CRC_EXECUTION_TIMEOUT, supv::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) { + // 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, + // supv::timeout::UPDATE_STATUS_REPORT); + // if (result != returnvalue::OK) { + // sif::warning + // << "PlocSupvHelper::handleCheckMemoryCommand: Failed to receive update status report" + // << std::endl; + // return result; + // } + // result = updateStatusReport.checkCrc(); + // if (result != returnvalue::OK) { + // sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC check failed" << std::endl; + // return result; + // } + // // Copy into other buffer because data will be overwritten when reading execution report + // std::memcpy(statusReportBuf.data(), tmBuf.data(), updateStatusReport.getNominalSize()); + // } + // + // if (not exeAlreadyHandled) { + // result = handleExe(CRC_EXECUTION_TIMEOUT); + // if (result != returnvalue::OK) { + // return result; + // } + // } + // + // // Now process the status report + // updateStatusReport.setData(statusReportBuf.data(), statusReportBuf.size()); + // result = updateStatusReport.parseDataField(); + // if (result != returnvalue::OK) { + // return result; + // } + // if (update.crcShouldBeChecked) { + // result = updateStatusReport.verifycrc(update.crc); + // if (result != returnvalue::OK) { + // sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC failure. Expected CRC 0x" + // << std::setfill('0') << std::hex << std::setw(4) + // << static_cast(update.crc) << " but received CRC 0x" << + // std::setw(4) + // << updateStatusReport.getCrc() << std::dec << std::endl; + // return result; + // } + // } return result; } @@ -816,55 +818,57 @@ uint32_t PlocSupvHelper::getFileSize(std::string filename) { ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reader) { ReturnValue_t result = returnvalue::OK; -#ifdef XIPHOS_Q7S - if (not sdcMan->getActiveSdCard()) { - return HasFileSystemIF::FILESYSTEM_INACTIVE; - } -#endif - 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; - bool firstPacket = true; - for (packetsRead = 0; packetsRead < NUM_EVENT_BUFFER_PACKETS; packetsRead++) { - if (terminate) { - triggerEvent(SUPV_EVENT_BUFFER_REQUEST_TERMINATED, packetsRead - 1); - file.close(); - return PROCESS_TERMINATED; - } - if (packetsRead == NUM_EVENT_BUFFER_PACKETS - 1) { - requestLen = SIZE_EVENT_BUFFER_LAST_PACKET; - } else { - requestLen = SIZE_EVENT_BUFFER_FULL_PACKET; - } - if (firstPacket) { - firstPacket = false; - requestLen -= 6; - } - result = handleTmReception(requestLen); - if (result != returnvalue::OK) { - sif::debug << "PlocSupvHelper::handleEventBufferReception: Failed while trying to read packet" - << " " << packetsRead + 1 << std::endl; - file.close(); - return result; - } - ReturnValue_t result = reader.checkCrc(); - if (result != returnvalue::OK) { - triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); - return result; - } - 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; - } - // TODO: Fix - // file.write(reinterpret_cast(reader.getPacketData()), - // reader.getPayloadDataLength()); - } + // TODO: Fix + //#ifdef XIPHOS_Q7S + // if (not sdcMan->getActiveSdCard()) { + // return HasFileSystemIF::FILESYSTEM_INACTIVE; + // } + //#endif + // 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; + // bool firstPacket = true; + // for (packetsRead = 0; packetsRead < NUM_EVENT_BUFFER_PACKETS; packetsRead++) { + // if (terminate) { + // triggerEvent(SUPV_EVENT_BUFFER_REQUEST_TERMINATED, packetsRead - 1); + // file.close(); + // return PROCESS_TERMINATED; + // } + // if (packetsRead == NUM_EVENT_BUFFER_PACKETS - 1) { + // requestLen = SIZE_EVENT_BUFFER_LAST_PACKET; + // } else { + // requestLen = SIZE_EVENT_BUFFER_FULL_PACKET; + // } + // if (firstPacket) { + // firstPacket = false; + // requestLen -= 6; + // } + // result = handleTmReception(requestLen); + // if (result != returnvalue::OK) { + // sif::debug << "PlocSupvHelper::handleEventBufferReception: Failed while trying to read + // packet" + // << " " << packetsRead + 1 << std::endl; + // file.close(); + // return result; + // } + // ReturnValue_t result = reader.checkCrc(); + // if (result != returnvalue::OK) { + // triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); + // return result; + // } + // 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; + // } + // // TODO: Fix + // // file.write(reinterpret_cast(reader.getPacketData()), + // // reader.getPayloadDataLength()); + // } return result; }