v1.10.0 #220
@ -15,6 +15,7 @@ static const DeviceCommandId_t ACK_REPORT = 3;
|
||||
static const DeviceCommandId_t EXE_REPORT = 5;
|
||||
static const DeviceCommandId_t TM_MEMORY_READ_REPORT = 6;
|
||||
static const DeviceCommandId_t TC_FLASHFOPEN = 7;
|
||||
static const DeviceCommandId_t TC_FLASHFCLOSE = 8;
|
||||
|
||||
static const uint16_t SIZE_ACK_REPORT = 14;
|
||||
static const uint16_t SIZE_EXE_REPORT = 14;
|
||||
@ -27,6 +28,7 @@ namespace apid {
|
||||
static const uint16_t TC_MEM_WRITE = 0x114;
|
||||
static const uint16_t TC_MEM_READ = 0x115;
|
||||
static const uint16_t TC_FLASHFOPEN = 0x119;
|
||||
static const uint16_t TC_FLASHFCLOSE = 0x11A;
|
||||
static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
|
||||
static const uint16_t ACK_SUCCESS = 0x400;
|
||||
static const uint16_t ACK_FAILURE = 0x401;
|
||||
@ -130,142 +132,95 @@ private:
|
||||
|
||||
/**
|
||||
* @brief This class helps to build the memory read command for the PLOC.
|
||||
*
|
||||
* @details The last two bytes of the packet data field contain a CRC calculated over the whole
|
||||
* space packet. This is the CRC-16-CCITT as specified in
|
||||
* ECSS-E-ST-70-41C Telemetry and telecommand packet utilization.
|
||||
*/
|
||||
class TcMemRead: public SpacePacket {
|
||||
class TcMemRead: public TcBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param memAddr The memory address to read from.
|
||||
*/
|
||||
TcMemRead(const uint32_t memAddr, uint16_t sequenceCount) :
|
||||
SpacePacket(LENGTH_TC_MEM_READ - 1, true, apid::TC_MEM_READ, sequenceCount) {
|
||||
fillPacketDataField(&memAddr);
|
||||
TcMemRead(uint16_t sequenceCount) :
|
||||
TcBase(apid::TC_MEM_READ, sequenceCount) {
|
||||
this->setPacketDataLength(PACKET_LENGTH);
|
||||
}
|
||||
|
||||
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::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE);
|
||||
std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE,
|
||||
commandData + MEM_ADDRESS_SIZE, MEM_LEN_SIZE);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static const uint8_t OFFSET_ADDRESS = 0;
|
||||
static const uint8_t OFFSET_MEM_LEN_FIELD = 4;
|
||||
static const uint8_t CRC_OFFSET = 6;
|
||||
const uint16_t MEM_LEN = 1;
|
||||
static const size_t COMMAND_LENGTH = 6;
|
||||
static const size_t MEM_ADDRESS_SIZE = 4;
|
||||
static const size_t MEM_LEN_SIZE = 2;
|
||||
static const uint16_t PACKET_LENGTH = 7;
|
||||
|
||||
/**
|
||||
* @brief This function builds the packet data field for the mem read command.
|
||||
*
|
||||
* @param memAddr Pointer to the memory address to read from.
|
||||
*/
|
||||
void fillPacketDataField(const uint32_t* memAddr) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
size_t serializedSize = 0;
|
||||
result = SerializeAdapter::serialize<uint32_t>(memAddr,
|
||||
this->localData.fields.buffer + OFFSET_ADDRESS, &serializedSize, sizeof(*memAddr),
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TcMemRead::fillPacketDataField: Failed to serialize address field"
|
||||
<< std::endl;
|
||||
}
|
||||
result = SerializeAdapter::serialize<uint16_t>(&MEM_LEN,
|
||||
this->localData.fields.buffer + OFFSET_MEM_LEN_FIELD, &serializedSize,
|
||||
sizeof(MEM_LEN), SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TcMemRead::fillPacketDataField: Failed to serialize mem len field"
|
||||
<< std::endl;
|
||||
}
|
||||
// Calculate crc
|
||||
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream,
|
||||
sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE);
|
||||
// Add crc to packet data field of space packet */
|
||||
result = SerializeAdapter::serialize<uint16_t>(&crc,
|
||||
this->localData.fields.buffer + CRC_OFFSET, &serializedSize, sizeof(crc),
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TcMemRead::fillPacketDataField: Failed to serialize crc field"
|
||||
<< std::endl;
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen != COMMAND_LENGTH){
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to generate the space packet to write to a memory address within
|
||||
* @brief This class helps to generate the space packet to write data to a memory address within
|
||||
* the PLOC.
|
||||
* @details The last two bytes of the packet data field contain a CRC calculated over the whole
|
||||
* space packet. This is the CRC-16-CCITT as specified in
|
||||
* ECSS-E-ST-70-41C Telemetry and telecommand packet utilization.
|
||||
*/
|
||||
class TcMemWrite: public SpacePacket {
|
||||
class TcMemWrite: public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param memAddr The PLOC memory address where to write to.
|
||||
* @param memoryData The data to write to the specified memory address.
|
||||
* @param sequenceCount The subsequence count. Must be incremented with each new packet.
|
||||
*/
|
||||
TcMemWrite(const uint32_t memAddr, const uint32_t memoryData, uint16_t sequenceCount) :
|
||||
SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, apid::TC_MEM_WRITE, sequenceCount) {
|
||||
fillPacketDataField(&memAddr, &memoryData);
|
||||
TcMemWrite(uint16_t sequenceCount) : TcBase(apid::TC_MEM_WRITE, sequenceCount) {
|
||||
this->setPacketDataLength(PACKET_LENGTH);
|
||||
}
|
||||
|
||||
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::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE);
|
||||
std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE,
|
||||
commandData + MEM_ADDRESS_SIZE, MEM_DATA_SIZE);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** Offsets from base address of packet data field */
|
||||
static const uint8_t OFFSET_MEM_LEN_FIELD = 4;
|
||||
static const uint8_t OFFSET_MEM_DATA_FIELD = 6;
|
||||
static const uint8_t CRC_OFFSET = 10;
|
||||
static const size_t COMMAND_LENGTH = 8;
|
||||
static const uint16_t PACKET_LENGTH = 9;
|
||||
static const size_t MEM_ADDRESS_SIZE = 4;
|
||||
static const size_t MEM_DATA_SIZE = 4;
|
||||
|
||||
/**
|
||||
* @brief This function builds the packet data field for the mem write command.
|
||||
*
|
||||
* @param memAddrPtr Pointer to the PLOC memory address where to write to.
|
||||
* @param memoryDataPtr Pointer to the memoryData to write
|
||||
*/
|
||||
void fillPacketDataField(const uint32_t* memAddrPtr, const uint32_t* memoryDataPtr) {
|
||||
|
||||
/* Add memAddr to packet data field */
|
||||
size_t serializedSize = 0;
|
||||
uint8_t* memoryAddressPos = this->localData.fields.buffer;
|
||||
SerializeAdapter::serialize<uint32_t>(memAddrPtr, &memoryAddressPos, &serializedSize,
|
||||
sizeof(*memAddrPtr), SerializeIF::Endianness::BIG);
|
||||
|
||||
/* Add memLen to packet data field */
|
||||
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 1;
|
||||
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 0;
|
||||
|
||||
/* Add memData to packet data field */
|
||||
serializedSize = 0;
|
||||
uint8_t* memoryDataPos = this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD;
|
||||
SerializeAdapter::serialize<uint32_t>(memoryDataPtr, &memoryDataPos, &serializedSize,
|
||||
sizeof(*memoryDataPtr), SerializeIF::Endianness::BIG);
|
||||
|
||||
/* Calculate crc */
|
||||
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream,
|
||||
sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE);
|
||||
|
||||
serializedSize = 0;
|
||||
uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET;
|
||||
/* Add crc to packet data field of space packet */
|
||||
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize, sizeof(crc),
|
||||
SerializeIF::Endianness::BIG);
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen != COMMAND_LENGTH) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to generate the flash file open command
|
||||
* @brief Class to help creation of flash fopen command.
|
||||
*/
|
||||
class FlashFopen : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param sequenceCount Packet sequence count which is incremented with each sent and received
|
||||
* packet.
|
||||
*/
|
||||
|
||||
FlashFopen(uint16_t sequenceCount) :
|
||||
TcBase(apid::TC_FLASHFOPEN, sequenceCount) {
|
||||
}
|
||||
@ -278,9 +233,9 @@ protected:
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1);
|
||||
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1);
|
||||
accessMode = *(commandData + commandDataLen);
|
||||
truePacketLen = filename.size() + sizeof(accessMode) + CRC_SIZE;
|
||||
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));
|
||||
@ -291,12 +246,7 @@ protected:
|
||||
|
||||
private:
|
||||
uint8_t accessMode = 0;
|
||||
std::string filename;
|
||||
uint16_t truePacketLen = 0;
|
||||
|
||||
/**
|
||||
* @brief Check length of received command
|
||||
*/
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen > MAX_FILENAME_SIZE + sizeof(accessMode)) {
|
||||
return INVALID_LENGTH;
|
||||
@ -305,6 +255,42 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to help creation of flash fclose command.
|
||||
*/
|
||||
class FlashFclose : public TcBase {
|
||||
public:
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */
|
||||
|
@ -70,6 +70,10 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
|
||||
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;
|
||||
@ -90,6 +94,7 @@ 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);
|
||||
@ -180,37 +185,27 @@ void PlocMPSoCHandler::setModeNormal() {
|
||||
|
||||
ReturnValue_t PlocMPSoCHandler::prepareTcMemWriteCommand(const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
|
||||
| *(commandData + 2) << 8 | *(commandData + 3);
|
||||
const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16
|
||||
| *(commandData + 6) << 8 | *(commandData + 7);
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
|
||||
mpsoc::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount);
|
||||
if (tcMemWrite.getFullSize() > mpsoc::MAX_COMMAND_SIZE) {
|
||||
sif::debug << "PlocMPSoCHandler::prepareTcMemWriteCommand: Command too big" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
mpsoc::TcMemWrite tcMemWrite(packetSequenceCount);
|
||||
result = tcMemWrite.createPacket(commandData, commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
memcpy(commandBuffer, tcMemWrite.getWholeData(), tcMemWrite.getFullSize());
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = tcMemWrite.getFullSize();
|
||||
nextReplyId = mpsoc::ACK_REPORT;
|
||||
copyToCommandBuffer(&tcMemWrite);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHandler::prepareTcMemReadCommand(const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
|
||||
| *(commandData + 2) << 8 | *(commandData + 3);
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
|
||||
mpsoc::TcMemRead tcMemRead(memoryAddress, packetSequenceCount);
|
||||
if (tcMemRead.getFullSize() > mpsoc::MAX_COMMAND_SIZE) {
|
||||
sif::debug << "PlocMPSoCHandler::prepareTcMemReadCommand: Command too big" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
mpsoc::TcMemRead tcMemRead(packetSequenceCount);
|
||||
result = tcMemRead.createPacket(commandData, commandDataLen);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
memcpy(commandBuffer, tcMemRead.getWholeData(), tcMemRead.getFullSize());
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = tcMemRead.getFullSize();
|
||||
nextReplyId = mpsoc::ACK_REPORT;
|
||||
copyToCommandBuffer(&tcMemRead);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
@ -227,6 +222,19 @@ ReturnValue_t PlocMPSoCHandler::prepareFlashFopenCmd(const uint8_t * commandData
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHandler::prepareFlashFcloseCmd(const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
|
||||
mpsoc::FlashFclose flashFclose(packetSequenceCount);
|
||||
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;
|
||||
@ -358,6 +366,7 @@ 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: {
|
||||
|
@ -111,6 +111,7 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user