From 2563432171bc2c570dc6a1c1046e680ae3f77d35 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 14 Nov 2023 15:28:27 +0100 Subject: [PATCH] somethings wrong --- bsp_q7s/scheduling.cpp | 3 -- linux/payload/FreshSupvHandler.cpp | 49 +++++++++++++++++++----------- linux/payload/FreshSupvHandler.h | 4 +-- linux/payload/PlocSupvUartMan.cpp | 7 ++++- linux/payload/PlocSupvUartMan.h | 4 +-- linux/payload/plocSupvDefs.h | 2 +- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/bsp_q7s/scheduling.cpp b/bsp_q7s/scheduling.cpp index b4344db2..31ccd140 100644 --- a/bsp_q7s/scheduling.cpp +++ b/bsp_q7s/scheduling.cpp @@ -385,9 +385,6 @@ void scheduling::initTasks() { FixedTimeslotTaskIF* plTask = factory->createFixedTimeslotTask( "PL_TASK", 25, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, missedDeadlineFunc, &RR_SCHEDULING); - // plTask->addComponent(objects::CAM_SWITCHER); - // scheduling::addMpsocSupvHandlers(plTask); - // scheduling::scheduleScexDev(plTask); pst::pstPayload(plTask); #if OBSW_ADD_SCEX_DEVICE == 1 diff --git a/linux/payload/FreshSupvHandler.cpp b/linux/payload/FreshSupvHandler.cpp index 798fb652..bd964540 100644 --- a/linux/payload/FreshSupvHandler.cpp +++ b/linux/payload/FreshSupvHandler.cpp @@ -31,6 +31,8 @@ FreshSupvHandler::FreshSupvHandler(DhbConfig cfg, CookieIF* comCookie, Gpio uart latchupStatusReport(this), countersReport(this), adcReport(this) { + spParams.buf = commandBuffer.data(); + spParams.maxSize = commandBuffer.size(); eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); } @@ -83,7 +85,6 @@ void FreshSupvHandler::performDeviceOperation(uint8_t opCode) { } } } else if (opCode == OpCode::PARSE_TM) { - std::vector cmdsToRemove; for (auto& activeCmd : activeActionCmds) { if (activeCmd.second.cmdCountdown.hasTimedOut()) { if (activeCmd.second.commandedBy != MessageQueueIF::NO_QUEUE) { @@ -452,6 +453,7 @@ void FreshSupvHandler::startTransition(Mode_t newMode, Submode_t newSubmode) { } void FreshSupvHandler::handleTransitionToOn() { + sif::debug << "psupv: trans to on" << std::endl; if (startupState == StartupState::IDLE) { bootTimeout.resetTimer(); startupState = StartupState::POWER_SWITCHING; @@ -473,24 +475,31 @@ void FreshSupvHandler::handleTransitionToOn() { return; } } - if (startupState == StartupState::BOOTING) { - if (bootTimeout.hasTimedOut()) { - uartIsolatorSwitch.pullHigh(); - uartManager.start(); - if (SET_TIME_DURING_BOOT) { - // TODO: Send command ,add command to command map. - startupState = StartupState::SET_TIME; - } else { - startupState = StartupState::ON; - } + if (startupState == StartupState::BOOTING and bootTimeout.hasTimedOut()) { + uartIsolatorSwitch.pullHigh(); + uartManager.start(); + if (SET_TIME_DURING_BOOT) { + startupState = StartupState::SET_TIME; + } else { + startupState = StartupState::ON; } } + if (startupState == StartupState::SET_TIME) { + ReturnValue_t result = prepareSetTimeRefCmd(); + if (result != returnvalue::OK) { + sif::error << "FreshSupvHandler: Setting time command prepration failed" << std::endl; + startupState = StartupState::ON; + } + startupState = StartupState::WAIT_FOR_TIME_REPLY; + } if (startupState == StartupState::TIME_WAS_SET) { startupState = StartupState::ON; } if (startupState == StartupState::ON) { hkSet.setReportingEnabled(true); supv::SUPV_ON = true; + sif::debug << "psupv: going on" << std::endl; + transitionActive = false; setMode(targetMode); } } @@ -506,7 +515,9 @@ void FreshSupvHandler::handleTransitionToOff() { } if (shutdownState == ShutdownState::POWER_SWITCHING) { if (switchIF.getSwitchState(switchId) == PowerSwitchIF::SWITCH_OFF or modeHelper.isTimedOut()) { + sif::debug << "psupv: going off" << std::endl; supv::SUPV_ON = false; + transitionActive = false; setMode(MODE_OFF); } } @@ -1115,11 +1126,13 @@ ReturnValue_t FreshSupvHandler::handleAckReport(const uint8_t* data) { return returnvalue::OK; } info.ackRecv = true; - performCommandCompletionHandling(info); + performCommandCompletionHandling(static_cast((infoIter->first >> 16) & 0xffff), + infoIter->first & 0xff, info); return result; } -void FreshSupvHandler::performCommandCompletionHandling(ActiveCmdInfo& info) { +void FreshSupvHandler::performCommandCompletionHandling(supv::Apid apid, uint8_t serviceId, + ActiveCmdInfo& info) { if (info.ackRecv and info.ackExeRecv and (not info.replyPacketExpected or info.replyPacketReceived)) { actionHelper.finish(true, info.commandedBy, info.commandId, returnvalue::OK); @@ -1170,7 +1183,9 @@ ReturnValue_t FreshSupvHandler::handleExecutionReport(const uint8_t* data) { return returnvalue::OK; } info.ackExeRecv = true; - performCommandCompletionHandling(info); + performCommandCompletionHandling(static_cast((infoIter->first >> 16) & 0xffff), + infoIter->first & 0xff, info); + return result; } @@ -1197,9 +1212,6 @@ ReturnValue_t FreshSupvHandler::handleExecutionSuccessReport(ActiveCmdInfo& info break; } case supv::SET_TIME_REF: { - // We could only allow proper bootup when the time was set successfully, but - // this makes debugging difficult. - if (startupState == StartupState::WAIT_FOR_TIME_REPLY) { startupState = StartupState::TIME_WAS_SET; } @@ -1229,7 +1241,8 @@ void FreshSupvHandler::confirmReplyPacketReceived(supv::Apid apid, uint8_t servi if (infoIter != activeActionCmds.end()) { ActiveCmdInfo& info = infoIter->second; info.replyPacketReceived = true; - performCommandCompletionHandling(info); + performCommandCompletionHandling(static_cast((infoIter->first >> 16) & 0xffff), + infoIter->first & 0xff, info); } } diff --git a/linux/payload/FreshSupvHandler.h b/linux/payload/FreshSupvHandler.h index 0f190a1d..2efd5d9d 100644 --- a/linux/payload/FreshSupvHandler.h +++ b/linux/payload/FreshSupvHandler.h @@ -15,7 +15,7 @@ using supv::TcBase; static constexpr bool DEBUG_PLOC_SUPV = true; -static constexpr bool REDUCE_NORMAL_MODE_PRINTOUT = true; +static constexpr bool REDUCE_NORMAL_MODE_PRINTOUT = false; class FreshSupvHandler : public FreshDeviceHandlerBase { public: @@ -176,7 +176,7 @@ class FreshSupvHandler : public FreshDeviceHandlerBase { ReturnValue_t handleHkReport(const uint8_t* data); ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen); void confirmReplyPacketReceived(supv::Apid apid, uint8_t serviceId); - void performCommandCompletionHandling(ActiveCmdInfo& info); + void performCommandCompletionHandling(supv::Apid apid, uint8_t serviceId, ActiveCmdInfo& info); ReturnValue_t handleBootStatusReport(const uint8_t* data); ReturnValue_t genericHandleTm(const char* contextString, const uint8_t* data, LocalPoolDataSetBase& set, supv::Apid apid, uint8_t serviceId); diff --git a/linux/payload/PlocSupvUartMan.cpp b/linux/payload/PlocSupvUartMan.cpp index 00a90fa3..b53a5f32 100644 --- a/linux/payload/PlocSupvUartMan.cpp +++ b/linux/payload/PlocSupvUartMan.cpp @@ -45,10 +45,12 @@ PlocSupvUartManager::PlocSupvUartManager(object_id_t objectId) PlocSupvUartManager::~PlocSupvUartManager() = default; ReturnValue_t PlocSupvUartManager::initializeInterface(CookieIF* cookie) { + sif::debug << "init ploc supv uart IF" << std::endl; auto* uartCookie = dynamic_cast(cookie); if (uartCookie == nullptr) { return FAILED; } + sif::debug << "hello blub" << std::endl; std::string devname = uartCookie->getDeviceFile(); /* Get file descriptor */ serialPort = open(devname.c_str(), O_RDWR); @@ -70,7 +72,7 @@ ReturnValue_t PlocSupvUartManager::initializeInterface(CookieIF* cookie) { tty.c_lflag &= ~(ICANON | ECHO); // Blocking mode, 0.2 seconds timeout - tty.c_cc[VTIME] = 2; + tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 0; serial::setBaudrate(tty, uartCookie->getBaudrate()); @@ -80,6 +82,7 @@ ReturnValue_t PlocSupvUartManager::initializeInterface(CookieIF* cookie) { } // Flush received and unread data tcflush(serialPort, TCIOFLUSH); + sif::debug << "ploc supv cfg complete" << std::endl; return OK; } @@ -114,6 +117,7 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { lock->lockMutex(); InternalState currentState = state; lock->unlockMutex(); + sif::debug << "supv uart man post-lock" << std::endl; switch (currentState) { case InternalState::SLEEPING: case InternalState::GO_TO_SLEEP: { @@ -139,6 +143,7 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { ReturnValue_t PlocSupvUartManager::handleUartReception() { ReturnValue_t result = OK; ReturnValue_t status = OK; + sif::debug << "handling uart reception" << std::endl; ssize_t bytesRead = read(serialPort, reinterpret_cast(recBuf.data()), static_cast(recBuf.size())); if (bytesRead == 0) { diff --git a/linux/payload/PlocSupvUartMan.h b/linux/payload/PlocSupvUartMan.h index 2da9a8b9..e5d01f70 100644 --- a/linux/payload/PlocSupvUartMan.h +++ b/linux/payload/PlocSupvUartMan.h @@ -282,8 +282,8 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; - bool printTc = false; - bool debugMode = false; + bool printTc = true; + bool debugMode = true; bool timestamping = true; // Remembers APID to know at which command a procedure failed diff --git a/linux/payload/plocSupvDefs.h b/linux/payload/plocSupvDefs.h index 79e90560..c7fa3ae7 100644 --- a/linux/payload/plocSupvDefs.h +++ b/linux/payload/plocSupvDefs.h @@ -45,7 +45,7 @@ static const Event SUPV_EXE_ACK_UNKNOWN_COMMAND = MAKE_EVENT(10, severity::LOW); extern std::atomic_bool SUPV_ON; static constexpr uint32_t BOOT_TIMEOUT_MS = 4000; -static constexpr uint32_t MAX_TRANSITION_TIME_TO_ON_MS = 6000; +static constexpr uint32_t MAX_TRANSITION_TIME_TO_ON_MS = BOOT_TIMEOUT_MS + 2000; static constexpr uint32_t MAX_TRANSITION_TIME_TO_OFF_MS = 1000; namespace result {