v1.10.0 #220

Merged
meierj merged 592 commits from develop into main 2022-04-22 07:42:20 +02:00
3 changed files with 197 additions and 190 deletions
Showing only changes of commit 595b9aff6c - Show all commits

View File

@ -78,7 +78,7 @@ public:
* @brief Constructor * @brief Constructor
* *
* @param sequenceCount Sequence count of space packet which will be incremented with each * @param sequenceCount Sequence count of space packet which will be incremented with each
* sent and received packet.s * sent and received packets.
*/ */
TcBase(uint16_t apid, uint16_t sequenceCount) : TcBase(uint16_t apid, uint16_t sequenceCount) :
SpacePacket(INIT_LENGTH, true, apid, sequenceCount) { SpacePacket(INIT_LENGTH, true, apid, sequenceCount) {

View File

@ -1,242 +1,247 @@
#include "PlocMPSoCHelper.h" #include "PlocMPSoCHelper.h"
#include "mission/utility/Timestamp.h"
#include "bsp_q7s/memory/FileSystemHelper.h"
#include <fstream>
#include <filesystem> #include <filesystem>
#include <fstream>
PlocMPSoCHelper::PlocMPSoCHelper(object_id_t objectId) : SystemObject(objectId){ #include "bsp_q7s/memory/FileSystemHelper.h"
#include "mission/utility/Timestamp.h"
} PlocMPSoCHelper::PlocMPSoCHelper(object_id_t objectId) : SystemObject(objectId) {}
PlocMPSoCHelper::~PlocMPSoCHelper() { PlocMPSoCHelper::~PlocMPSoCHelper() {}
}
ReturnValue_t PlocMPSoCHelper::initialize() { ReturnValue_t PlocMPSoCHelper::initialize() {
sdcMan = SdCardManager::instance(); sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) { if (sdcMan == nullptr) {
sif::warning << "PlocMPSoCHelper::initialize: Invalid SD Card Manager" << std::endl; sif::warning << "PlocMPSoCHelper::initialize: Invalid SD Card Manager" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t PlocMPSoCHelper::performOperation(uint8_t operationCode) { ReturnValue_t PlocMPSoCHelper::performOperation(uint8_t operationCode) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
semaphore.acquire(); semaphore.acquire();
while(true) { while (true) {
switch(internalState) { switch (internalState) {
case InternalState::IDLE: { case InternalState::IDLE: {
semaphore.acquire(); semaphore.acquire();
break; break;
} }
case InternalState::FLASH_WRITE: { case InternalState::FLASH_WRITE: {
result = performFlashWrite(); result = performFlashWrite();
if (result == RETURN_OK){ if (result == RETURN_OK) {
triggerEvent(MPSOC_FLASH_WRITE_SUCCESSFUL); triggerEvent(MPSOC_FLASH_WRITE_SUCCESSFUL);
} } else {
else { triggerEvent(MPSOC_FLASH_WRITE_FAILED);
triggerEvent(MPSOC_FLASH_WRITE_FAILED);
}
internalState = InternalState::IDLE;
break;
}
default:
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
break;
} }
internalState = InternalState::IDLE;
break;
}
default:
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
break;
} }
}
} }
ReturnValue_t PlocMPSoCHelper::setComIF(DeviceCommunicationIF* communicationInterface_) { ReturnValue_t PlocMPSoCHelper::setComIF(DeviceCommunicationIF* communicationInterface_) {
uartComIF = dynamic_cast<UartComIF*>(communicationInterface_); uartComIF = dynamic_cast<UartComIF*>(communicationInterface_);
if (uartComIF == nullptr) { if (uartComIF == nullptr) {
sif::warning << "PlocMPSoCHelper::initialize: Invalid uart com if" << std::endl; sif::warning << "PlocMPSoCHelper::initialize: Invalid uart com if" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
void PlocMPSoCHelper::setComCookie(CookieIF* comCookie_) { void PlocMPSoCHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
comCookie = comCookie_;
}
void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) { void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) {
sequenceCount = sequenceCount_; sequenceCount = sequenceCount_;
} }
ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string file) { ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string file) {
ReturnValue_t result = FilesystemHelper::checkPath(file); ReturnValue_t result = FilesystemHelper::checkPath(file);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = FilesystemHelper::fileExists(file); result = FilesystemHelper::fileExists(file);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
flashWrite.file = file; flashWrite.file = file;
internalState = InternalState::FLASH_WRITE; internalState = InternalState::FLASH_WRITE;
semaphore.release(); semaphore.release();
terminate = false; terminate = false;
return RETURN_OK; return RETURN_OK;
} }
void PlocMPSoCHelper::stopProcess() { void PlocMPSoCHelper::stopProcess() { terminate = true; }
terminate = true;
}
ReturnValue_t PlocMPSoCHelper::performFlashWrite() { ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
uint8_t tempData[mpsoc::MAX_DATA_SIZE]; uint8_t tempData[mpsoc::MAX_DATA_SIZE];
std::ifstream file(flashWrite.file, std::ifstream::binary); std::ifstream file(flashWrite.file, std::ifstream::binary);
// Set position of next character to end of file input stream // Set position of next character to end of file input stream
file.seekg(0, file.end); file.seekg(0, file.end);
// tellg returns position of character in input stream // tellg returns position of character in input stream
size_t remainingSize = file.tellg(); size_t remainingSize = file.tellg();
size_t dataLength = 0; size_t dataLength = 0;
while (remainingSize > 0) { while (remainingSize > 0) {
if (terminate) { if (terminate) {
return RETURN_OK; return RETURN_OK;
}
if (remainingSize > mpsoc::MAX_DATA_SIZE) {
dataLength = mpsoc::MAX_DATA_SIZE;
}
else {
dataLength = remainingSize;
}
file.read(reinterpret_cast<char*>(tempData), dataLength);
sequenceCount++;
mpsoc::FlashWrite tc(*sequenceCount);
tc.createPacket(tempData, dataLength);
result = sendCommand(&tc);
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
result = handleExe();
if (result != RETURN_OK) {
return result;
}
} }
return result; if (remainingSize > mpsoc::MAX_DATA_SIZE) {
dataLength = mpsoc::MAX_DATA_SIZE;
} else {
dataLength = remainingSize;
}
file.read(reinterpret_cast<char*>(tempData), dataLength);
(*sequenceCount)++;
mpsoc::FlashWrite tc(*sequenceCount);
tc.createPacket(tempData, dataLength);
result = sendCommand(&tc);
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
result = handleExe();
if (result != RETURN_OK) {
return result;
}
}
return result;
} }
ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) { ReturnValue_t PlocMPSoCHelper::flashfopen() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = uartComIF->sendMessage(comCookie, tc->getWholeData(), tc->getFullSize()); (*sequenceCount)++;
if (result != RETURN_OK) { mpsoc::FlashFopen flashFopen(*sequenceCount);
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl; sendCommand(&flashFopen);
triggerEvent(SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState)); result = flashFopen.createPacket(commandData, commandDataLen);
return result; if (result != RETURN_OK) {
}
return result; return result;
}
copyToCommandBuffer(&flashFopen);
return RETURN_OK;
}
ReturnValue_t PlocMPSoCHelper::flashfclose() {}
ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) {
ReturnValue_t result = RETURN_OK;
result = uartComIF->sendMessage(comCookie, tc->getWholeData(), tc->getFullSize());
if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
triggerEvent(SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
return result;
}
return result;
} }
ReturnValue_t PlocMPSoCHelper::handleAck() { ReturnValue_t PlocMPSoCHelper::handleAck() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
mpsoc::TmPacket tmPacket; mpsoc::TmPacket tmPacket;
result = handleTmReception(&tmPacket, mpsoc::SIZE_ACK_REPORT); result = handleTmReception(&tmPacket, mpsoc::SIZE_ACK_REPORT);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
uint16_t apid = tmPacket.getAPID(); uint16_t apid = tmPacket.getAPID();
if (apid != mpsoc::apid::ACK_SUCCESS) { if (apid != mpsoc::apid::ACK_SUCCESS) {
handleAckApidFailure(apid); handleAckApidFailure(apid);
return RETURN_FAILED; return RETURN_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
void PlocMPSoCHelper::handleAckApidFailure(uint16_t apid) { void PlocMPSoCHelper::handleAckApidFailure(uint16_t apid) {
if (apid == mpsoc::apid::ACK_FAILURE) { if (apid == mpsoc::apid::ACK_FAILURE) {
triggerEvent(ACK_FAILURE_REPORT, static_cast<uint32_t>(internalState)); triggerEvent(ACK_FAILURE_REPORT, static_cast<uint32_t>(internalState));
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Received acknowledgement failure " sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Received acknowledgement failure "
<< "report" << std::endl; << "report" << std::endl;
} } else {
else { triggerEvent(ACK_INVALID_APID, apid, static_cast<uint32_t>(internalState));
triggerEvent(ACK_INVALID_APID, apid, static_cast<uint32_t>(internalState)); sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected acknowledgement report "
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected acknowledgement report " << "but received space packet with apid " << std::hex << apid << std::endl;
<< "but received space packet with apid " << std::hex << apid << std::endl; }
}
} }
ReturnValue_t PlocMPSoCHelper::handleExe() { ReturnValue_t PlocMPSoCHelper::handleExe() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
mpsoc::TmPacket tmPacket; mpsoc::TmPacket tmPacket;
result = handleTmReception(&tmPacket, mpsoc::SIZE_EXE_REPORT); result = handleTmReception(&tmPacket, mpsoc::SIZE_EXE_REPORT);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
uint16_t apid = tmPacket.getAPID(); uint16_t apid = tmPacket.getAPID();
if (apid != mpsoc::apid::EXE_SUCCESS) { if (apid != mpsoc::apid::EXE_SUCCESS) {
handleExeApidFailure(apid); handleExeApidFailure(apid);
return RETURN_FAILED; return RETURN_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) { void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) {
if (apid == mpsoc::apid::EXE_FAILURE) { if (apid == mpsoc::apid::EXE_FAILURE) {
triggerEvent(EXE_FAILURE_REPORT, static_cast<uint32_t>(internalState)); triggerEvent(EXE_FAILURE_REPORT, static_cast<uint32_t>(internalState));
sif::warning << "PlocMPSoCHelper::handleExeApidFailure: Received execution failure " sif::warning << "PlocMPSoCHelper::handleExeApidFailure: Received execution failure "
<< "report" << std::endl; << "report" << std::endl;
} } else {
else { triggerEvent(EXE_INVALID_APID, apid, static_cast<uint32_t>(internalState));
triggerEvent(EXE_INVALID_APID, apid, static_cast<uint32_t>(internalState)); sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected execution report "
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected execution report " << "but received space packet with apid " << std::hex << apid << std::endl;
<< "but received space packet with apid " << std::hex << apid << std::endl; }
}
} }
ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes) { ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
size_t readBytes = 0; size_t readBytes = 0;
for(int retries = 0; retries < RETRIES; retries++) { for (int retries = 0; retries < RETRIES; retries++) {
result = receive(tmPacket->getWholeData(), &readBytes, remainingBytes); result = receive(tmPacket->getWholeData(), &readBytes, remainingBytes);
if (result != RETURN_OK) {
return result;
}
remainingBytes = remainingBytes - readBytes;
if (remainingBytes == 0) {
break;
}
}
if (remainingBytes != 0) {
sif::warning << "PlocMPSoCHelper::handleTmReception: Failed to receive reply" << std::endl;
triggerEvent(MISSING_EXE, remainingBytes, static_cast<uint32_t>(internalState));
return RETURN_FAILED;
}
result = tmPacket->checkCrc();
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl; return result;
return result;
} }
uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount(); remainingBytes = remainingBytes - readBytes;
if (recvSeqCnt != *sequenceCount) { if (remainingBytes == 0) {
triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt); break;
*sequenceCount = recvSeqCnt;
return result;
} }
}
if (remainingBytes != 0) {
sif::warning << "PlocMPSoCHelper::handleTmReception: Failed to receive reply" << std::endl;
triggerEvent(MISSING_EXE, remainingBytes, static_cast<uint32_t>(internalState));
return RETURN_FAILED;
}
result = tmPacket->checkCrc();
if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl;
return result; return result;
}
uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount();
if (recvSeqCnt != *sequenceCount) {
triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt);
*sequenceCount = recvSeqCnt;
return result;
}
return result;
} }
ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) { ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = uartComIF->requestReceiveMessage(comCookie, requestBytes); result = uartComIF->requestReceiveMessage(comCookie, requestBytes);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::receive: Failed to request reply" << std::endl; sif::warning << "PlocMPSoCHelper::receive: Failed to request reply" << std::endl;
triggerEvent(MPSOC_HELPER_REQUESTING_REPLY_FAILED, result, triggerEvent(MPSOC_HELPER_REQUESTING_REPLY_FAILED, result,
static_cast<uint32_t>(static_cast<uint32_t>(internalState))); static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
return RETURN_FAILED; return RETURN_FAILED;
} }
result = uartComIF->readReceivedMessage(comCookie, &data, readBytes); result = uartComIF->readReceivedMessage(comCookie, &data, readBytes);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl; sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl;
triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState));
static_cast<uint32_t>(internalState)); return RETURN_FAILED;
return RETURN_FAILED; }
} return result;
return result;
} }

View File

@ -135,6 +135,8 @@ private:
SourceSequenceCounter* sequenceCount; SourceSequenceCounter* sequenceCount;
ReturnValue_t performFlashWrite(); ReturnValue_t performFlashWrite();
ReturnValue_t flashfopen();
ReturnValue_t flashfclose();
ReturnValue_t sendCommand(mpsoc::TcBase* tc); ReturnValue_t sendCommand(mpsoc::TcBase* tc);
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes); ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
ReturnValue_t handleAck(); ReturnValue_t handleAck();