v1.10.0 #220

Merged
meierj merged 592 commits from develop into main 2022-04-22 07:42:20 +02:00
5 changed files with 73 additions and 116 deletions
Showing only changes of commit 8bf91f2645 - Show all commits

View File

@ -85,14 +85,14 @@ public:
} }
/** /**
* @brief Function to initialitze the space packet * @brief Function to initialize the space packet
* *
* @param commandData Pointer to command specific data * @param commandData Pointer to command specific data
* @param commandDataLen Length of command data * @param commandDataLen Length of command data
* *
* @return RETURN_OK if packet creation was successful, otherwise error return value * @return RETURN_OK if packet creation was successful, otherwise error return value
*/ */
ReturnValue_t createPacket(const uint8_t* commandData, size_t commandDataLen) { virtual ReturnValue_t createPacket(const uint8_t* commandData, size_t commandDataLen) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = initPacket(commandData, commandDataLen); result = initPacket(commandData, commandDataLen);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -112,9 +112,10 @@ protected:
* @param commandData Pointer to received command data * @param commandData Pointer to received command data
* @param commandDataLen Length of received command data * @param commandDataLen Length of received command data
*/ */
virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) = 0; virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
return RETURN_OK;
}
private:
/** /**
* @brief Calculates and adds the CRC * @brief Calculates and adds the CRC
*/ */
@ -268,33 +269,23 @@ public:
TcBase(apid::TC_FLASHFOPEN, sequenceCount) { TcBase(apid::TC_FLASHFOPEN, sequenceCount) {
} }
protected: static const char APPEND = 'a';
static const char WRITE = 'w';
static const char READ = 'r';
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { ReturnValue_t createPacket(std::string filename, char accessMode) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = lengthCheck(commandDataLen); size_t nameSize = filename.size();
std::memcpy(this->getPacketData(), filename.c_str(),
nameSize);
std::memcpy(this->getPacketData() + nameSize, &accessMode,
sizeof(accessMode));
result = addCrc();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1); this->setPacketDataLength(nameSize + CRC_SIZE - 1);
accessMode = *(commandData + commandDataLen); return result;
uint16_t truePacketLen = filename.size() + sizeof(accessMode) + CRC_SIZE;
this->setPacketDataLength(truePacketLen - 1);
std::memcpy(this->getPacketData(), filename.c_str(),
truePacketLen - CRC_SIZE - sizeof(accessMode));
std::memcpy(this->getPacketData() + truePacketLen - CRC_SIZE, &accessMode,
sizeof(accessMode));
return RETURN_OK;
}
private:
uint8_t accessMode = 0;
ReturnValue_t lengthCheck(size_t commandDataLen) {
if (commandDataLen > MAX_FILENAME_SIZE + sizeof(accessMode)) {
return INVALID_LENGTH;
}
return RETURN_OK;
} }
}; };
@ -308,29 +299,16 @@ public:
TcBase(apid::TC_FLASHFCLOSE, sequenceCount) { TcBase(apid::TC_FLASHFCLOSE, sequenceCount) {
} }
protected: ReturnValue_t createPacket(std::string filename) {
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = lengthCheck(commandDataLen); size_t nameSize = filename.size();
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
result = addCrc();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1); this->setPacketDataLength(nameSize + CRC_SIZE - 1);
uint16_t truePacketLen = filename.size() + CRC_SIZE; return result;
this->setPacketDataLength(truePacketLen - 1);
std::memcpy(this->getPacketData(), filename.c_str(),
truePacketLen - CRC_SIZE);
return RETURN_OK;
}
private:
ReturnValue_t lengthCheck(size_t commandDataLen) {
if (commandDataLen > MAX_FILENAME_SIZE) {
return INVALID_LENGTH;
}
return RETURN_OK;
} }
}; };
@ -344,15 +322,13 @@ public:
TcBase(apid::TC_FLASHWRITE, sequenceCount) { TcBase(apid::TC_FLASHWRITE, sequenceCount) {
} }
protected: ReturnValue_t createPacket(uint8_t* writeData, uint32_t writeLen) {
if (writeLen > MAX_DATA_SIZE) {
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl;
if (commandDataLen > MAX_DATA_SIZE) {
sif::debug << "FlashWrite::initPacket: Command data too big" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
std::memcpy(this->getPacketData(), commandData, commandDataLen); std::memcpy(this->getPacketData(), writeData, writeLen);
this->setPacketDataLength(static_cast<uint16_t>(commandDataLen + CRC_SIZE - 1)); this->setPacketDataLength(static_cast<uint16_t>(writeLen + CRC_SIZE - 1));
return RETURN_OK; return RETURN_OK;
} }
}; };

View File

@ -138,14 +138,6 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
result = prepareTcMemReadCommand(commandData, commandDataLen); result = prepareTcMemReadCommand(commandData, commandDataLen);
break; break;
} }
case(mpsoc::TC_FLASHFOPEN): {
result = prepareFlashFopenCmd(commandData, commandDataLen);
break;
}
case(mpsoc::TC_FLASHFCLOSE): {
result = prepareFlashFcloseCmd(commandData, commandDataLen);
break;
}
default: default:
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented" << std::endl; sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented" << std::endl;
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
@ -165,8 +157,6 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
void PlocMPSoCHandler::fillCommandAndReplyMap() { void PlocMPSoCHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(mpsoc::TC_MEM_WRITE); this->insertInCommandMap(mpsoc::TC_MEM_WRITE);
this->insertInCommandMap(mpsoc::TC_MEM_READ); this->insertInCommandMap(mpsoc::TC_MEM_READ);
this->insertInCommandMap(mpsoc::TC_FLASHFOPEN);
this->insertInCommandMap(mpsoc::TC_FLASHFCLOSE);
this->insertInReplyMap(mpsoc::ACK_REPORT, 1, nullptr, mpsoc::SIZE_ACK_REPORT); this->insertInReplyMap(mpsoc::ACK_REPORT, 1, nullptr, mpsoc::SIZE_ACK_REPORT);
this->insertInReplyMap(mpsoc::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_REPORT); this->insertInReplyMap(mpsoc::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_REPORT);
this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT); this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT);
@ -297,32 +287,6 @@ ReturnValue_t PlocMPSoCHandler::prepareTcMemReadCommand(const uint8_t * commandD
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t PlocMPSoCHandler::prepareFlashFopenCmd(const uint8_t * commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
sequenceCount++;
mpsoc::FlashFopen flashFopen(sequenceCount);
result = flashFopen.createPacket(commandData, commandDataLen);
if (result != RETURN_OK) {
return result;
}
copyToCommandBuffer(&flashFopen);
return RETURN_OK;
}
ReturnValue_t PlocMPSoCHandler::prepareFlashFcloseCmd(const uint8_t * commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
sequenceCount++;
mpsoc::FlashFclose flashFclose(sequenceCount);
result = flashFclose.createPacket(commandData, commandDataLen);
if (result != RETURN_OK) {
return result;
}
copyToCommandBuffer(&flashFclose);
return RETURN_OK;
}
void PlocMPSoCHandler::copyToCommandBuffer(mpsoc::TcBase* tc) { void PlocMPSoCHandler::copyToCommandBuffer(mpsoc::TcBase* tc) {
if (tc == nullptr) { if (tc == nullptr) {
sif::debug << "PlocMPSoCHandler::copyToCommandBuffer: Invalid TC" << std::endl; sif::debug << "PlocMPSoCHandler::copyToCommandBuffer: Invalid TC" << std::endl;
@ -455,8 +419,6 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator
switch (command->first) { switch (command->first) {
case mpsoc::TC_MEM_WRITE: case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHFOPEN:
case mpsoc::TC_FLASHFCLOSE:
enabledReplies = 2; enabledReplies = 2;
break; break;
case mpsoc::TC_MEM_READ: { case mpsoc::TC_MEM_READ: {
@ -581,7 +543,6 @@ void PlocMPSoCHandler::disableAllReplies() {
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */ /* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
switch (commandId) { switch (commandId) {
case mpsoc::TC_MEM_WRITE: case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHFOPEN:
break; break;
case mpsoc::TC_MEM_READ: { case mpsoc::TC_MEM_READ: {
iter = deviceReplyMap.find(mpsoc::TM_MEMORY_READ_REPORT); iter = deviceReplyMap.find(mpsoc::TM_MEMORY_READ_REPORT);

View File

@ -126,8 +126,6 @@ private:
ReturnValue_t prepareTcMemWriteCommand(const uint8_t * commandData, size_t commandDataLen); ReturnValue_t prepareTcMemWriteCommand(const uint8_t * commandData, size_t commandDataLen);
ReturnValue_t prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen); ReturnValue_t prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen);
ReturnValue_t prepareFlashFopenCmd(const uint8_t * commandData, size_t commandDataLen);
ReturnValue_t prepareFlashFcloseCmd(const uint8_t * commandData, size_t commandDataLen);
/** /**
* @brief Copies space packet into command buffer * @brief Copies space packet into command buffer

View File

@ -80,6 +80,10 @@ void PlocMPSoCHelper::stopProcess() { terminate = true; }
ReturnValue_t PlocMPSoCHelper::performFlashWrite() { ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = flashfopen();
if (result != RETURN_OK) {
return result;
}
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
@ -113,6 +117,10 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
return result; return result;
} }
} }
result = flashfclose();
if (result != RETURN_OK) {
return result;
}
return result; return result;
} }
@ -120,16 +128,31 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
(*sequenceCount)++; (*sequenceCount)++;
mpsoc::FlashFopen flashFopen(*sequenceCount); mpsoc::FlashFopen flashFopen(*sequenceCount);
sendCommand(&flashFopen); result = flashFopen.createPacket(flashWrite.file);
result = flashFopen.createPacket(commandData, commandDataLen); if (result != RETURN_OK) {
return result;
}
result = sendCommand(&flashFopen);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
copyToCommandBuffer(&flashFopen);
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t PlocMPSoCHelper::flashfclose() {} ReturnValue_t PlocMPSoCHelper::flashfclose() {
ReturnValue_t result = RETURN_OK;
(*sequenceCount)++;
mpsoc::FlashFclose flashFclose(*sequenceCount);
result = flashFclose.createPacket(flashWrite.file);
if (result != RETURN_OK) {
return result;
}
result = sendCommand(&flashFclose);
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) { ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;

View File

@ -101,12 +101,11 @@ private:
// buffer // buffer
static const int RETRIES = 3; static const int RETRIES = 3;
class FlashWrite { struct FlashWrite {
public:
std::string file; std::string file;
}; };
FlashWrite flashWrite; struct FlashWrite flashWrite;
enum class InternalState { enum class InternalState {
IDLE, IDLE,