meier/plocMPSoC #188
@ -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 commandDataLen Length of command data
|
||||
*
|
||||
* @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;
|
||||
result = initPacket(commandData, commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
@ -112,9 +112,10 @@ protected:
|
||||
* @param commandData Pointer to 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
|
||||
*/
|
||||
@ -268,70 +269,47 @@ public:
|
||||
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 result = RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1);
|
||||
accessMode = *(commandData + commandDataLen);
|
||||
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;
|
||||
ReturnValue_t createPacket(std::string filename, char accessMode) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
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) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to help creation of flash fclose command.
|
||||
*/
|
||||
class FlashFclose : public TcBase {
|
||||
class FlashFclose: public TcBase {
|
||||
public:
|
||||
|
||||
FlashFclose(uint16_t sequenceCount) :
|
||||
TcBase(apid::TC_FLASHFCLOSE, sequenceCount) {
|
||||
}
|
||||
FlashFclose(uint16_t sequenceCount) :
|
||||
TcBase(apid::TC_FLASHFCLOSE, sequenceCount) {
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1);
|
||||
uint16_t truePacketLen = filename.size() + CRC_SIZE;
|
||||
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;
|
||||
}
|
||||
ReturnValue_t createPacket(std::string filename) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
size_t nameSize = filename.size();
|
||||
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -344,16 +322,14 @@ public:
|
||||
TcBase(apid::TC_FLASHWRITE, sequenceCount) {
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
if (commandDataLen > MAX_DATA_SIZE) {
|
||||
sif::debug << "FlashWrite::initPacket: Command data too big" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
std::memcpy(this->getPacketData(), commandData, commandDataLen);
|
||||
this->setPacketDataLength(static_cast<uint16_t>(commandDataLen + CRC_SIZE - 1));
|
||||
return RETURN_OK;
|
||||
ReturnValue_t createPacket(uint8_t* writeData, uint32_t writeLen) {
|
||||
if (writeLen > MAX_DATA_SIZE) {
|
||||
sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
std::memcpy(this->getPacketData(), writeData, writeLen);
|
||||
this->setPacketDataLength(static_cast<uint16_t>(writeLen + CRC_SIZE - 1));
|
||||
return RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -138,14 +138,6 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
|
||||
result = prepareTcMemReadCommand(commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
case(mpsoc::TC_FLASHFOPEN): {
|
||||
result = prepareFlashFopenCmd(commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
case(mpsoc::TC_FLASHFCLOSE): {
|
||||
result = prepareFlashFcloseCmd(commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented" << std::endl;
|
||||
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
@ -165,8 +157,6 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
|
||||
void PlocMPSoCHandler::fillCommandAndReplyMap() {
|
||||
this->insertInCommandMap(mpsoc::TC_MEM_WRITE);
|
||||
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::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (tc == nullptr) {
|
||||
sif::debug << "PlocMPSoCHandler::copyToCommandBuffer: Invalid TC" << std::endl;
|
||||
@ -455,8 +419,6 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator
|
||||
|
||||
switch (command->first) {
|
||||
case mpsoc::TC_MEM_WRITE:
|
||||
case mpsoc::TC_FLASHFOPEN:
|
||||
case mpsoc::TC_FLASHFCLOSE:
|
||||
enabledReplies = 2;
|
||||
break;
|
||||
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 */
|
||||
switch (commandId) {
|
||||
case mpsoc::TC_MEM_WRITE:
|
||||
case mpsoc::TC_FLASHFOPEN:
|
||||
break;
|
||||
case mpsoc::TC_MEM_READ: {
|
||||
iter = deviceReplyMap.find(mpsoc::TM_MEMORY_READ_REPORT);
|
||||
|
@ -126,8 +126,6 @@ private:
|
||||
|
||||
ReturnValue_t prepareTcMemWriteCommand(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
|
||||
|
@ -80,6 +80,10 @@ void PlocMPSoCHelper::stopProcess() { terminate = true; }
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = flashfopen();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
uint8_t tempData[mpsoc::MAX_DATA_SIZE];
|
||||
std::ifstream file(flashWrite.file, std::ifstream::binary);
|
||||
// Set position of next character to end of file input stream
|
||||
@ -113,6 +117,10 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result = flashfclose();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -120,16 +128,31 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
(*sequenceCount)++;
|
||||
mpsoc::FlashFopen flashFopen(*sequenceCount);
|
||||
sendCommand(&flashFopen);
|
||||
result = flashFopen.createPacket(commandData, commandDataLen);
|
||||
result = flashFopen.createPacket(flashWrite.file);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = sendCommand(&flashFopen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
copyToCommandBuffer(&flashFopen);
|
||||
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 result = RETURN_OK;
|
||||
|
@ -101,12 +101,11 @@ private:
|
||||
// buffer
|
||||
static const int RETRIES = 3;
|
||||
|
||||
class FlashWrite {
|
||||
public:
|
||||
struct FlashWrite {
|
||||
std::string file;
|
||||
};
|
||||
|
||||
FlashWrite flashWrite;
|
||||
struct FlashWrite flashWrite;
|
||||
|
||||
enum class InternalState {
|
||||
IDLE,
|
||||
|
Loading…
Reference in New Issue
Block a user