Merge remote-tracking branch 'origin/develop' into heater_handling
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Robin Müller 2022-11-25 10:28:36 +01:00
commit 073ebb4afe
8 changed files with 105 additions and 134 deletions

View File

@ -15,7 +15,7 @@
#define OBSW_ENABLE_TIMERS 1 #define OBSW_ENABLE_TIMERS 1
#define OBSW_ADD_STAR_TRACKER 0 #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_PLOC_MPSOC 0
#define OBSW_ADD_SUN_SENSORS 0 #define OBSW_ADD_SUN_SENSORS 0
#define OBSW_ADD_MGT 0 #define OBSW_ADD_MGT 0

View File

@ -501,7 +501,7 @@ class TcBase : public ploc::SpTcBase {
uint16_t getModuleApid() const { return getApid() & APID_MODULE_MASK; } 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) { static size_t fullSpDataLenFromPayloadLen(size_t payloadLen) {
return SECONDARY_HEADER_LEN + payloadLen + CRC_LEN; return SECONDARY_HEADER_LEN + payloadLen + CRC_LEN;
@ -1154,8 +1154,11 @@ class WriteMemory : public TcBase {
} }
spParams.creator.setSeqFlags(seqFlags); spParams.creator.setSeqFlags(seqFlags);
spParams.creator.setSeqCount(sequenceCount); spParams.creator.setSeqCount(sequenceCount);
initPacket(memoryId, startAddress, length, updateData); auto res = initPacket(memoryId, startAddress, length, updateData);
auto res = checkSizeAndSerializeHeader(); if (res != returnvalue::OK) {
return res;
}
res = checkSizeAndSerializeHeader();
if (res != returnvalue::OK) { if (res != returnvalue::OK) {
return res; return res;
} }
@ -1182,7 +1185,7 @@ class WriteMemory : public TcBase {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
size_t serializedSize = 6; size_t serializedSize = MIN_TMTC_LEN;
SerializeAdapter::serialize(&memoryId, &data, &serializedSize, spParams.maxSize, SerializeAdapter::serialize(&memoryId, &data, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
SerializeAdapter::serialize(&n, &data, &serializedSize, spParams.maxSize, SerializeAdapter::serialize(&n, &data, &serializedSize, spParams.maxSize,
@ -1681,7 +1684,7 @@ class UpdateStatusReport {
if (not tmReader.crcIsOk()) { if (not tmReader.crcIsOk()) {
return result::CRC_FAILURE; return result::CRC_FAILURE;
} }
if (tmReader.getApid() != Apid::MEM_MAN) { if (tmReader.getModuleApid() != Apid::MEM_MAN) {
return result::INVALID_APID; return result::INVALID_APID;
} }
if (tmReader.getBufSize() < MIN_TMTC_LEN + PAYLOAD_LEN or if (tmReader.getBufSize() < MIN_TMTC_LEN + PAYLOAD_LEN or
@ -1690,10 +1693,7 @@ class UpdateStatusReport {
<< std::endl; << std::endl;
return result::BUF_TOO_SMALL; return result::BUF_TOO_SMALL;
} }
size_t remLen = PAYLOAD_LEN; size_t remLen = tmReader.getPayloadLen();
if (remLen < PAYLOAD_LEN) {
return result::INVALID_REPLY_LENGTH;
}
const uint8_t* dataFieldPtr = tmReader.getPayloadStart(); const uint8_t* dataFieldPtr = tmReader.getPayloadStart();
SerializeAdapter::deSerialize(&memoryId, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&memoryId, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG);
SerializeAdapter::deSerialize(&n, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&n, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG);

View File

@ -2,6 +2,7 @@
#include <fsfw/filesystem/HasFileSystemIF.h> #include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/globalfunctions/arrayprinter.h> #include <fsfw/globalfunctions/arrayprinter.h>
#include <fsfw/tasks/TaskFactory.h>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@ -84,7 +85,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
break; break;
} }
if (plocSupvHelperExecuting) { if (uartManager.longerRequestActive()) {
return result::SUPV_HELPER_EXECUTING; 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) { if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return result::FILENAME_TOO_LONG; return result::FILENAME_TOO_LONG;
} }
shutdownCmdSent = false;
UpdateParams params; UpdateParams params;
result = extractUpdateCommand(data, size, params); result = extractUpdateCommand(data, size, params);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -107,15 +109,15 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case CONTINUE_UPDATE: { case CONTINUE_UPDATE: {
shutdownCmdSent = false;
uartManager.initiateUpdateContinuation(); uartManager.initiateUpdateContinuation();
plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case MEMORY_CHECK_WITH_FILE: { case MEMORY_CHECK_WITH_FILE: {
shutdownCmdSent = false;
UpdateParams params; UpdateParams params;
ReturnValue_t result = extractBaseParams(&data, size, params); ReturnValue_t result = extractBaseParams(&data, size, params);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -125,7 +127,6 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
return HasFileSystemIF::FILE_DOES_NOT_EXIST; return HasFileSystemIF::FILE_DOES_NOT_EXIST;
} }
uartManager.performMemCheck(params.file, params.memId, params.startAddr); uartManager.performMemCheck(params.file, params.memId, params.startAddr);
plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
default: default:
@ -136,28 +137,19 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
void PlocSupervisorHandler::doStartUp() { void PlocSupervisorHandler::doStartUp() {
if (setTimeDuringStartup) { if (setTimeDuringStartup) {
switch (startupState) { if (startupState == StartupState::OFF) {
case StartupState::OFF: { bootTimeout.resetTimer();
bootTimeout.resetTimer(); startupState = StartupState::BOOTING;
}
if (startupState == StartupState::BOOTING) {
if (bootTimeout.hasTimedOut()) {
uartIsolatorSwitch.pullHigh();
uartManager.start(); uartManager.start();
startupState = StartupState::BOOTING; startupState = StartupState::SET_TIME;
break;
} }
case StartupState::BOOTING: { }
if (bootTimeout.hasTimedOut()) { if (startupState == StartupState::ON) {
uartIsolatorSwitch.pullHigh(); setMode(_MODE_TO_ON);
startupState = StartupState::SET_TIME;
}
break;
}
case StartupState::SET_TIME_EXECUTING:
break;
case StartupState::ON: {
setMode(_MODE_TO_ON);
break;
}
default:
break;
} }
} else { } else {
uartIsolatorSwitch.pullHigh(); uartIsolatorSwitch.pullHigh();
@ -586,8 +578,8 @@ ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t r
// } // }
tmReader.setData(start, remainingSize); tmReader.setData(start, remainingSize);
sif::debug << "PlocSupervisorHandler::scanForReply: Received Packet" << std::endl; // sif::debug << "PlocSupervisorHandler::scanForReply: Received Packet" << std::endl;
arrayprinter::print(start, remainingSize); // arrayprinter::print(start, remainingSize);
uint16_t apid = tmReader.getModuleApid(); uint16_t apid = tmReader.getModuleApid();
switch (apid) { switch (apid) {
@ -786,7 +778,6 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
Event event = eventMessage->getEvent(); Event event = eventMessage->getEvent();
switch (objectId) { switch (objectId) {
case objects::PLOC_SUPERVISOR_HELPER: { case objects::PLOC_SUPERVISOR_HELPER: {
plocSupvHelperExecuting = false;
// After execution of update procedure, PLOC is in a state where it draws approx. 700 mA of // 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. // current. To leave this state the shutdown MPSoC command must be sent here.
if (event == PlocSupvUartManager::SUPV_UPDATE_FAILED || if (event == PlocSupvUartManager::SUPV_UPDATE_FAILED ||
@ -795,13 +786,18 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_SUCCESSFUL || event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_SUCCESSFUL ||
event == PlocSupvUartManager::SUPV_MEM_CHECK_FAIL || event == PlocSupvUartManager::SUPV_MEM_CHECK_FAIL ||
event == PlocSupvUartManager::SUPV_MEM_CHECK_OK) { event == PlocSupvUartManager::SUPV_MEM_CHECK_OK) {
result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); // Wait for a short period for the uart state machine to adjust
if (result != returnvalue::OK) { // TaskFactory::delayTask(5);
triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED); if (not shutdownCmdSent) {
sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown " shutdownCmdSent = true;
"command" result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0);
<< std::endl; if (result != returnvalue::OK) {
return; triggerEvent(SUPV_MPSOC_SHUTDOWN_BUILD_FAILED);
sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown "
"command"
<< std::endl;
return;
}
} }
} }
break; break;
@ -1226,14 +1222,6 @@ size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) {
return replyLen; 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::doOffActivity() {}
void PlocSupervisorHandler::handleDeviceTm(const uint8_t* data, size_t dataSize, void PlocSupervisorHandler::handleDeviceTm(const uint8_t* data, size_t dataSize,

View File

@ -59,7 +59,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
uint8_t expectedReplies = 1, bool useAlternateId = false, uint8_t expectedReplies = 1, bool useAlternateId = false,
DeviceCommandId_t alternateReplyID = 0) override; DeviceCommandId_t alternateReplyID = 0) override;
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override; size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
ReturnValue_t doSendReadHook() override; // ReturnValue_t doSendReadHook() override;
void doOffActivity() override; void doOffActivity() override;
private: private:
@ -81,7 +81,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
//! [EXPORT] : [COMMENT] Supervisor helper currently executing a command //! [EXPORT] : [COMMENT] Supervisor helper currently executing a command
static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(7, severity::LOW); static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(7, severity::LOW);
//! [EXPORT] : [COMMENT] Failed to build the command to shutdown the MPSoC //! [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 APID_MASK = 0x7FF;
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
@ -119,6 +119,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
SerialComIF* uartComIf = nullptr; SerialComIF* uartComIf = nullptr;
LinuxLibgpioIF* gpioComIF = nullptr; LinuxLibgpioIF* gpioComIF = nullptr;
Gpio uartIsolatorSwitch; Gpio uartIsolatorSwitch;
bool shutdownCmdSent = false;
supv::HkSet hkset; supv::HkSet hkset;
supv::BootStatusReport bootStatusReport; supv::BootStatusReport bootStatusReport;
@ -151,9 +152,6 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
std::string supervisorFilePath = "ploc/supervisor"; std::string supervisorFilePath = "ploc/supervisor";
std::string activeMramFile; std::string activeMramFile;
// Supervisor helper class currently executing a command
bool plocSupvHelperExecuting = false;
Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false); Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false);
Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false); Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false);
// Vorago nees some time to boot properly // Vorago nees some time to boot properly

View File

@ -68,8 +68,8 @@ ReturnValue_t PlocSupvUartManager::initializeInterface(CookieIF* cookie) {
// Use non-canonical mode and clear echo flag // Use non-canonical mode and clear echo flag
tty.c_lflag &= ~(ICANON | ECHO); tty.c_lflag &= ~(ICANON | ECHO);
// Blocking mode, 0.5 seconds timeout // Blocking mode, 0.2 seconds timeout
tty.c_cc[VTIME] = 5; tty.c_cc[VTIME] = 2;
tty.c_cc[VMIN] = 0; tty.c_cc[VMIN] = 0;
uart::setBaudrate(tty, uartCookie->getBaudrate()); uart::setBaudrate(tty, uartCookie->getBaudrate());
@ -101,12 +101,11 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) {
lock->unlockMutex(); lock->unlockMutex();
semaphore->acquire(); semaphore->acquire();
while (true) { while (true) {
// sif::debug << "SUPV UART MAN: Running.." << std::endl;
putTaskToSleep = handleUartReception();
if (putTaskToSleep) { if (putTaskToSleep) {
performUartShutdown(); performUartShutdown();
break; break;
} }
handleUartReception();
lock->lockMutex(); lock->lockMutex();
InternalState currentState = state; InternalState currentState = state;
lock->unlockMutex(); lock->unlockMutex();
@ -126,44 +125,39 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) {
break; break;
} }
} }
if (putTaskToSleep) {
performUartShutdown();
break;
}
} }
} }
} }
bool PlocSupvUartManager::handleUartReception() { ReturnValue_t PlocSupvUartManager::handleUartReception() {
ReturnValue_t result = OK; ReturnValue_t result = OK;
ReturnValue_t status = OK;
ssize_t bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()), ssize_t bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
static_cast<unsigned int>(recBuf.size())); static_cast<unsigned int>(recBuf.size()));
if (bytesRead == 0) { if (bytesRead == 0) {
{
MutexGuard mg(lock);
if (state == InternalState::GO_TO_SLEEP) {
return true;
}
}
while (result != NO_PACKET_FOUND) { while (result != NO_PACKET_FOUND) {
result = tryHdlcParsing(); result = tryHdlcParsing();
if (result != NO_PACKET_FOUND and result != OK) {
status = result;
}
} }
} else if (bytesRead < 0) { } else if (bytesRead < 0) {
sif::warning << "PlocSupvHelper::performOperation: read call failed with error [" << errno sif::warning << "PlocSupvHelper::performOperation: read call failed with error [" << errno
<< ", " << strerror(errno) << "]" << std::endl; << ", " << strerror(errno) << "]" << std::endl;
return true; return FAILED;
} else if (bytesRead >= static_cast<int>(recBuf.size())) { } else if (bytesRead >= static_cast<int>(recBuf.size())) {
sif::error << "PlocSupvHelper::performOperation: Receive buffer too small for " << bytesRead sif::error << "PlocSupvHelper::performOperation: Receive buffer too small for " << bytesRead
<< " bytes" << std::endl; << " bytes" << std::endl;
return FAILED;
} else if (bytesRead > 0) { } else if (bytesRead > 0) {
if (debugMode) { if (debugMode) {
sif::info << "Received " << bytesRead << " bytes from the PLOC Supervisor:" << std::endl; sif::info << "Received " << bytesRead << " bytes from the PLOC Supervisor:" << std::endl;
arrayprinter::print(recBuf.data(), bytesRead); arrayprinter::print(recBuf.data(), bytesRead);
} }
recRingBuf.writeData(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, ReturnValue_t PlocSupvUartManager::startUpdate(std::string file, uint8_t memoryId,
@ -320,17 +314,17 @@ void PlocSupvUartManager::executeFullCheckMemoryCommand() {
sif::info << "PLOC SUPV Mem Check: Selecting Memory" << std::endl; sif::info << "PLOC SUPV Mem Check: Selecting Memory" << std::endl;
result = selectMemory(); result = selectMemory();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
triggerEvent(SUPV_MEM_CHECK_FAIL, result); triggerEvent(SUPV_MEM_CHECK_FAIL, result, 1);
return; return;
} }
sif::info << "PLOC SUPV Mem Check: Preparing Update" << std::endl; sif::info << "PLOC SUPV Mem Check: Preparing Update" << std::endl;
result = prepareUpdate(); result = prepareUpdate();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
triggerEvent(SUPV_MEM_CHECK_FAIL, result); triggerEvent(SUPV_MEM_CHECK_FAIL, result, 2);
return; return;
} }
sif::info << "PLOC SUPV Mem Check: Memory Check" << std::endl; sif::info << "PLOC SUPV Mem Check: Memory Check" << std::endl;
handleCheckMemoryCommand(); handleCheckMemoryCommand(3);
} }
ReturnValue_t PlocSupvUartManager::executeUpdate() { ReturnValue_t PlocSupvUartManager::executeUpdate() {
@ -375,7 +369,7 @@ ReturnValue_t PlocSupvUartManager::updateOperation() {
return result; return result;
} }
sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl; sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl;
return handleCheckMemoryCommand(); return handleCheckMemoryCommand(0);
} }
ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { ReturnValue_t PlocSupvUartManager::writeUpdatePackets() {
@ -435,8 +429,7 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() {
update.bytesWritten); update.bytesWritten);
return result; return result;
} }
result = handlePacketTransmissionNoReply(packet); result = handlePacketTransmissionNoReply(packet, 5000);
// result = encodeAndSendPacket(packet.getFullPacket(), packet.getFullPacketLen());
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
triggerEvent(WRITE_MEMORY_FAILED, buildProgParams1(progPercent, update.sequenceCount), triggerEvent(WRITE_MEMORY_FAILED, buildProgParams1(progPercent, update.sequenceCount),
update.bytesWritten); update.bytesWritten);
@ -450,7 +443,7 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() {
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1 #if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progressPrinter.print(update.bytesWritten); progressPrinter.print(update.bytesWritten);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
TaskFactory::delayTask(1); // TaskFactory::delayTask(1);
} }
return result; return result;
} }
@ -500,19 +493,6 @@ uint32_t PlocSupvUartManager::buildProgParams1(uint8_t percent, uint16_t seqCoun
// return result; // 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 PlocSupvUartManager::selectMemory() {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
resetSpParams(); resetSpParams();
@ -521,7 +501,7 @@ ReturnValue_t PlocSupvUartManager::selectMemory() {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = handlePacketTransmissionNoReply(packet); result = handlePacketTransmissionNoReply(packet, 2000);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -571,23 +551,20 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply(
bool ackReceived = false; bool ackReceived = false;
bool packetWasHandled = false; bool packetWasHandled = false;
while (true) { while (true) {
while (result != NO_PACKET_FOUND) { handleUartReception();
result = tryHdlcParsing();
}
if (not decodedQueue.empty()) { if (not decodedQueue.empty()) {
size_t packetLen = 0; size_t packetLen = 0;
decodedQueue.retrieve(&packetLen); decodedQueue.retrieve(&packetLen);
decodedRingBuf.readData(decodedBuf.data(), packetLen); decodedRingBuf.readData(decodedBuf.data(), packetLen, true);
tmReader.setData(decodedBuf.data(), packetLen); tmReader.setData(decodedBuf.data(), packetLen);
result = checkReceivedTm(); result = checkReceivedTm();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
continue; continue;
} }
if (tmReader.getModuleApid() == Apid::TMTC_MAN) { if (tmReader.getModuleApid() == Apid::TMTC_MAN) {
uint8_t serviceId = tmReader.getServiceId();
int retval = 0; int retval = 0;
if (not ackReceived) { if (not ackReceived) {
retval = handleAckReception(packet, serviceId, packetLen); retval = handleAckReception(packet, packetLen);
if (retval == 1) { if (retval == 1) {
ackReceived = true; ackReceived = true;
packetWasHandled = true; packetWasHandled = true;
@ -595,7 +572,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply(
return returnvalue::FAILED; return returnvalue::FAILED;
} }
} else { } else {
retval = handleExeAckReception(packet, serviceId, packetLen); retval = handleExeAckReception(packet, packetLen);
if (retval == 1) { if (retval == 1) {
break; break;
} else if (retval == -1) { } else if (retval == -1) {
@ -608,7 +585,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply(
decodedRingBuf.deleteData(packetLen); decodedRingBuf.deleteData(packetLen);
} }
} else { } else {
TaskFactory::delayTask(50); TaskFactory::delayTask(20);
} }
if (countdown.hasTimedOut()) { if (countdown.hasTimedOut()) {
return result::NO_REPLY_TIMEOUT; return result::NO_REPLY_TIMEOUT;
@ -617,7 +594,8 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply(
return returnvalue::OK; 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<uint8_t>(supv::tm::TmtcId::ACK) or if (serviceId == static_cast<uint8_t>(supv::tm::TmtcId::ACK) or
serviceId == static_cast<uint8_t>(supv::tm::TmtcId::NAK)) { serviceId == static_cast<uint8_t>(supv::tm::TmtcId::NAK)) {
AcknowledgmentReport ackReport(tmReader); AcknowledgmentReport ackReport(tmReader);
@ -648,8 +626,8 @@ int PlocSupvUartManager::handleAckReception(supv::TcBase& tc, uint8_t serviceId,
return 0; return 0;
} }
int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, uint8_t serviceId, int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, size_t packetLen) {
size_t packetLen) { uint8_t serviceId = tmReader.getServiceId();
if (serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK) or if (serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK) or
serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK)) { serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK)) {
ExecutionReport exeReport(tmReader); ExecutionReport exeReport(tmReader);
@ -658,7 +636,7 @@ int PlocSupvUartManager::handleExeAckReception(supv::TcBase& tc, uint8_t service
triggerEvent(EXE_RECEPTION_FAILURE); triggerEvent(EXE_RECEPTION_FAILURE);
return -1; return -1;
} }
if (exeReport.getRefModuleApid() == tc.getApid() and if (exeReport.getRefModuleApid() == tc.getModuleApid() and
exeReport.getRefServiceId() == tc.getServiceId()) { exeReport.getRefServiceId() == tc.getServiceId()) {
if (serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)) { if (serviceId == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)) {
return 1; return 1;
@ -686,8 +664,7 @@ ReturnValue_t PlocSupvUartManager::checkReceivedTm() {
triggerEvent(SUPV_REPLY_SIZE_MISSMATCH, rememberApid); triggerEvent(SUPV_REPLY_SIZE_MISSMATCH, rememberApid);
return result; return result;
} }
result = tmReader.checkCrc(); if (not tmReader.verifyCrc()) {
if (result != returnvalue::OK) {
triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid);
return result; return result;
} }
@ -740,15 +717,15 @@ ReturnValue_t PlocSupvUartManager::calcImageCrc() {
return result; return result;
} }
ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() { ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand(uint8_t failStep) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
resetSpParams(); resetSpParams();
supv::CheckMemory packet(spParams); supv::CheckMemory tcPacket(spParams);
result = packet.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); result = tcPacket.buildPacket(update.memoryId, update.startAddress, update.fullFileSize);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = encodeAndSendPacket(packet.getFullPacket(), packet.getFullPacketLen()); result = encodeAndSendPacket(tcPacket.getFullPacket(), tcPacket.getFullPacketLen());
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -758,13 +735,11 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
bool packetWasHandled = false; bool packetWasHandled = false;
bool exeReceived = false; bool exeReceived = false;
while (true) { while (true) {
while (result != NO_PACKET_FOUND) { handleUartReception();
result = tryHdlcParsing();
}
if (not decodedQueue.empty()) { if (not decodedQueue.empty()) {
size_t packetLen = 0; size_t packetLen = 0;
decodedQueue.retrieve(&packetLen); decodedQueue.retrieve(&packetLen);
decodedRingBuf.readData(decodedBuf.data(), packetLen); decodedRingBuf.readData(decodedBuf.data(), packetLen, true);
tmReader.setData(decodedBuf.data(), packetLen); tmReader.setData(decodedBuf.data(), packetLen);
result = checkReceivedTm(); result = checkReceivedTm();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -772,10 +747,9 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
} }
packetWasHandled = false; packetWasHandled = false;
if (tmReader.getModuleApid() == Apid::TMTC_MAN) { if (tmReader.getModuleApid() == Apid::TMTC_MAN) {
uint8_t serviceId = tmReader.getServiceId();
int retval = 0; int retval = 0;
if (not ackReceived) { if (not ackReceived) {
retval = handleAckReception(packet, serviceId, packetLen); retval = handleAckReception(tcPacket, packetLen);
if (retval == 1) { if (retval == 1) {
packetWasHandled = true; packetWasHandled = true;
ackReceived = true; ackReceived = true;
@ -783,11 +757,10 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
} else { } else {
retval = handleExeAckReception(packet, serviceId, packetLen); retval = handleExeAckReception(tcPacket, packetLen);
if (retval == 1) { if (retval == 1) {
packetWasHandled = true; packetWasHandled = true;
exeReceived = true; exeReceived = true;
break;
} else if (retval == -1) { } else if (retval == -1) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
@ -805,7 +778,6 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
result = report.verifyCrc(update.crc); result = report.verifyCrc(update.crc);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
triggerEvent(SUPV_MEM_CHECK_OK, result); triggerEvent(SUPV_MEM_CHECK_OK, result);
return result;
} else { } else {
sif::warning sif::warning
@ -813,7 +785,7 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
<< std::setfill('0') << std::hex << std::setw(4) << std::setfill('0') << std::hex << std::setw(4)
<< static_cast<uint16_t>(update.crc) << " but received CRC 0x" << std::setw(4) << static_cast<uint16_t>(update.crc) << " but received CRC 0x" << std::setw(4)
<< report.getCrc() << std::dec << std::endl; << report.getCrc() << std::dec << std::endl;
triggerEvent(SUPV_MEM_CHECK_FAIL, result); triggerEvent(SUPV_MEM_CHECK_FAIL, result, failStep);
} }
} }
} }
@ -823,7 +795,7 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
decodedRingBuf.deleteData(packetLen); decodedRingBuf.deleteData(packetLen);
} }
} else { } else {
TaskFactory::delayTask(50); TaskFactory::delayTask(20);
} }
if (ackReceived and exeReceived and checkReplyReceived) { if (ackReceived and exeReceived and checkReplyReceived) {
break; break;
@ -833,7 +805,6 @@ ReturnValue_t PlocSupvUartManager::handleCheckMemoryCommand() {
} }
} }
return returnvalue::OK; return returnvalue::OK;
return result;
} }
uint32_t PlocSupvUartManager::getFileSize(std::string filename) { uint32_t PlocSupvUartManager::getFileSize(std::string filename) {
@ -973,8 +944,10 @@ ReturnValue_t PlocSupvUartManager::handleRunningLongerRequest() {
ReturnValue_t PlocSupvUartManager::encodeAndSendPacket(const uint8_t* sendData, size_t sendLen) { ReturnValue_t PlocSupvUartManager::encodeAndSendPacket(const uint8_t* sendData, size_t sendLen) {
size_t encodedLen = 0; size_t encodedLen = 0;
addHdlcFraming(sendData, sendLen, encodedSendBuf.data(), &encodedLen, encodedSendBuf.size()); addHdlcFraming(sendData, sendLen, encodedSendBuf.data(), &encodedLen, encodedSendBuf.size());
sif::debug << "Sending TC" << std::endl; if (printTc) {
arrayprinter::print(encodedSendBuf.data(), encodedLen); sif::debug << "Sending TC" << std::endl;
arrayprinter::print(encodedSendBuf.data(), encodedLen);
}
size_t bytesWritten = write(serialPort, encodedSendBuf.data(), encodedLen); size_t bytesWritten = write(serialPort, encodedSendBuf.data(), encodedLen);
if (bytesWritten != encodedLen) { if (bytesWritten != encodedLen) {
sif::warning sif::warning
@ -1158,3 +1131,8 @@ int PlocSupvUartManager::removeHdlcFramingWithCrcCheck(const uint8_t* src, size_
*dlen = tlen - 2; *dlen = tlen - 2;
return 0; return 0;
} }
bool PlocSupvUartManager::longerRequestActive() const {
MutexGuard mg(lock);
return state == InternalState::DEDICATED_REQUEST;
}

View File

@ -159,6 +159,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
* @brief Can be used to start the UART reception * @brief Can be used to start the UART reception
*/ */
void start(); void start();
bool longerRequestActive() const;
static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount);
static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId); static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId);
@ -252,6 +253,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{}; std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{};
bool printTc = false;
bool debugMode = false; bool debugMode = false;
bool timestamping = true; bool timestamping = true;
@ -259,7 +261,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
uint16_t rememberApid = 0; uint16_t rememberApid = 0;
ReturnValue_t handleRunningLongerRequest(); 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); 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); int removeHdlcFramingWithCrcCheck(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen);
@ -274,9 +276,9 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
ReturnValue_t writeUpdatePackets(); ReturnValue_t writeUpdatePackets();
// ReturnValue_t performEventBufferRequest(); // ReturnValue_t performEventBufferRequest();
ReturnValue_t handlePacketTransmissionNoReply(supv::TcBase& packet, ReturnValue_t handlePacketTransmissionNoReply(supv::TcBase& packet,
uint32_t timeoutExecutionReport = 60000); uint32_t timeoutExecutionReport);
int handleAckReception(supv::TcBase& tc, uint8_t serviceId, size_t packetLen); int handleAckReception(supv::TcBase& tc, size_t packetLen);
int handleExeAckReception(supv::TcBase& tc, uint8_t serviceId, size_t packetLen); int handleExeAckReception(supv::TcBase& tc, size_t packetLen);
/** /**
* @brief Handles reading of TM packets from the communication interface * @brief Handles reading of TM packets from the communication interface
@ -298,7 +300,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
// Calculates CRC over image. Will be used for verification after update writing has // Calculates CRC over image. Will be used for verification after update writing has
// finished. // finished.
ReturnValue_t calcImageCrc(); ReturnValue_t calcImageCrc();
ReturnValue_t handleCheckMemoryCommand(); ReturnValue_t handleCheckMemoryCommand(uint8_t failStep);
ReturnValue_t exeReportHandling(); ReturnValue_t exeReportHandling();
/** /**
* @brief Return size of file with name filename * @brief Return size of file with name filename
@ -309,7 +311,6 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
*/ */
uint32_t getFileSize(std::string filename); uint32_t getFileSize(std::string filename);
ReturnValue_t handleEventBufferReception(ploc::SpTmReader& reader); ReturnValue_t handleEventBufferReception(ploc::SpTmReader& reader);
ReturnValue_t handleRemainingExeReport(ploc::SpTmReader& reader);
void resetSpParams(); void resetSpParams();
void pushIpcData(const uint8_t* data, size_t len); void pushIpcData(const uint8_t* data, size_t len);

View File

@ -65,6 +65,8 @@ void scheduling::addMpsocSupvHandlers(PeriodicTaskIF* plTask) {
plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::GET_WRITE); 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::SEND_READ);
plTask->addComponent(objects::PLOC_SUPERVISOR_HANDLER, DeviceHandlerIF::GET_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 #endif
#if OBSW_ADD_PLOC_MPSOC == 1 #if OBSW_ADD_PLOC_MPSOC == 1
@ -73,5 +75,7 @@ void scheduling::addMpsocSupvHandlers(PeriodicTaskIF* plTask) {
plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::GET_WRITE); 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::SEND_READ);
plTask->addComponent(objects::PLOC_MPSOC_HANDLER, DeviceHandlerIF::GET_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 #endif
} }

View File

@ -46,6 +46,8 @@ class SpTcBase {
void updateLenFromParams() { spParams.creator.setDataLenField(spParams.fullPayloadLen - 1); } void updateLenFromParams() { spParams.creator.setDataLenField(spParams.fullPayloadLen - 1); }
const uint8_t* getFullPacket() const { return spParams.buf; } 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(); } size_t getFullPacketLen() const { return spParams.creator.getFullPacketLen(); }
uint16_t getApid() const { return spParams.creator.getApid(); } uint16_t getApid() const { return spParams.creator.getApid(); }