restructured flash write command
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "MPSoCReturnValuesIF.h"
|
||||
#include <fsfw/tmtcpacket/SpacePacket.h>
|
||||
#include <fsfw/globalfunctions/CRC.h>
|
||||
#include <fsfw/serialize/SerializeAdapter.h>
|
||||
@ -81,19 +83,12 @@ static const uint16_t TC_WRITE_SEQ_EXECUTION_DELAY = 60;
|
||||
/**
|
||||
* @brief Abstract base class for TC space packet of MPSoC.
|
||||
*/
|
||||
class TcBase : public SpacePacket, public HasReturnvaluesIF {
|
||||
class TcBase : public SpacePacket, public MPSoCReturnValuesIF {
|
||||
public:
|
||||
|
||||
// Initial length field of space packet. Will always be updated when packet is created.
|
||||
static const uint16_t INIT_LENGTH = 1;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MPSOC_CMD;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Received command with invalid length
|
||||
static const ReturnValue_t INVALID_LENGTH = MAKE_RETURN_CODE(0xC0);
|
||||
//! [EXPORT] : [COMMENT] Command has invalid parameter
|
||||
static const ReturnValue_t INVALID_PARAMETER = MAKE_RETURN_CODE(0xC1);
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
@ -113,13 +108,13 @@ public:
|
||||
* @return RETURN_OK if packet creation was successful, otherwise error return value
|
||||
*/
|
||||
virtual ReturnValue_t createPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = initPacket(commandData, commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
@ -133,21 +128,21 @@ protected:
|
||||
* @param commandDataLen Length of received command data
|
||||
*/
|
||||
virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the CRC
|
||||
*/
|
||||
ReturnValue_t addCrc() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
size_t serializedSize = 0;
|
||||
uint32_t full_size = getFullSize();
|
||||
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
|
||||
result = SerializeAdapter::serialize<uint16_t>(&crc,
|
||||
this->localData.byteStream + full_size - CRC_SIZE, &serializedSize, sizeof(crc),
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl;
|
||||
}
|
||||
return result;
|
||||
@ -157,13 +152,9 @@ protected:
|
||||
/**
|
||||
* @brief Class for handling tm replies of the PLOC MPSoC.
|
||||
*/
|
||||
class TmPacket : public SpacePacket, public HasReturnvaluesIF {
|
||||
class TmPacket : public SpacePacket, public MPSoCReturnValuesIF {
|
||||
public:
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MPSOC_CMD;
|
||||
|
||||
//! [EXPORT] : [COMMENT] CRC check of received packet failed
|
||||
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0);
|
||||
/**
|
||||
* @brief Constructor creates idle packet and sets length field to maximum allowed size.
|
||||
*/
|
||||
@ -177,7 +168,7 @@ public:
|
||||
if (recalculatedCrc != receivedCrc) {
|
||||
return CRC_FAILURE;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -202,9 +193,9 @@ public:
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE);
|
||||
@ -214,7 +205,7 @@ protected:
|
||||
const uint8_t* memLenPtr = commandData + MEM_ADDRESS_SIZE;
|
||||
result = SerializeAdapter::deSerialize(&memLen, &memLenPtr, &size,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if(result != RETURN_OK) {
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
@ -233,7 +224,7 @@ private:
|
||||
if (commandDataLen != COMMAND_LENGTH){
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -252,9 +243,9 @@ public:
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(this->localData.fields.buffer, commandData, commandDataLen);
|
||||
@ -276,7 +267,7 @@ private:
|
||||
sif::warning << "TcMemWrite: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -295,17 +286,17 @@ public:
|
||||
static const char READ = 'r';
|
||||
|
||||
ReturnValue_t createPacket(std::string filename, char accessMode) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
size_t nameSize = filename.size();
|
||||
std::memcpy(this->getPacketData(), filename.c_str(),
|
||||
nameSize);
|
||||
std::memcpy(this->getPacketData() + nameSize, &accessMode,
|
||||
sizeof(accessMode));
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -321,14 +312,14 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t createPacket(std::string filename) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
size_t nameSize = filename.size();
|
||||
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -346,12 +337,16 @@ public:
|
||||
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;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
std::memcpy(this->getPacketData(), writeData, writeLen);
|
||||
addCrc();
|
||||
std::memcpy(this->getPacketData(), &writeLen, sizeof(writeLen));
|
||||
std::memcpy(this->getPacketData() + sizeof(writeLen), writeData, writeLen);
|
||||
this->setPacketDataLength(static_cast<uint16_t>(writeLen + CRC_SIZE - 1));
|
||||
return RETURN_OK;
|
||||
ReturnValue_t result = addCrc();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -366,12 +361,12 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t createPacket(std::string filename) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
size_t nameSize = filename.size();
|
||||
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
|
||||
this->setPacketDataLength(nameSize + CRC_SIZE - 1);
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
@ -389,13 +384,13 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t createPacket() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -413,13 +408,13 @@ public:
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = checkData(*commandData);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(this->localData.fields.buffer, commandData, commandDataLen);
|
||||
@ -438,7 +433,7 @@ private:
|
||||
sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t checkData(uint8_t replay) {
|
||||
@ -446,7 +441,7 @@ private:
|
||||
sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl;
|
||||
return INVALID_PARAMETER;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -464,17 +459,17 @@ public:
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = modeCheck(*commandData);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = laneRateCheck(*(commandData + 1));
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(this->localData.fields.buffer, commandData, commandDataLen);
|
||||
@ -503,7 +498,7 @@ private:
|
||||
sif::warning << "TcDownlinkPwrOn: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t modeCheck(uint8_t mode) {
|
||||
@ -511,7 +506,7 @@ private:
|
||||
sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl;
|
||||
return INVALID_MODE;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t laneRateCheck(uint8_t laneRate) {
|
||||
@ -519,7 +514,7 @@ private:
|
||||
sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl;
|
||||
return INVALID_LANE_RATE;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -534,13 +529,13 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t createPacket() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = addCrc();
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
@ -558,9 +553,9 @@ public:
|
||||
protected:
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(this->localData.fields.buffer, commandData, commandDataLen);
|
||||
@ -577,10 +572,42 @@ private:
|
||||
sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
class FlashWritePusCmd : public MPSoCReturnValuesIF {
|
||||
public:
|
||||
FlashWritePusCmd(){};
|
||||
|
||||
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) {
|
||||
if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
obcFile = std::string(reinterpret_cast<const char*>(commandData));
|
||||
if (obcFile.size() > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) {
|
||||
return FILENAME_TOO_LONG;
|
||||
}
|
||||
mpsocFile = std::string(reinterpret_cast<const char*>(commandData + obcFile.size()));
|
||||
if (mpsocFile.size() > MAX_FILENAME_SIZE) {
|
||||
return MPSOC_FILENAME_TOO_LONG;
|
||||
}
|
||||
return HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
std::string getObcFile() {
|
||||
return obcFile;
|
||||
}
|
||||
|
||||
std::string getMPSoCFile() {
|
||||
return mpsocFile;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string obcFile = "";
|
||||
std::string mpsocFile = "";
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */
|
||||
|
Reference in New Issue
Block a user