mpsoc flash fopen command

This commit is contained in:
Jakob Meier 2022-01-05 11:26:01 +01:00
parent ee0d3bb446
commit 305e63cf4e
7 changed files with 278 additions and 128 deletions

View File

@ -1,6 +1,7 @@
#include <sstream>
#include "ObjectFactory.h"
#include "bsp_q7s/devices/ploc/PlocMPSoCHandler.h"
#include "bsp_q7s/devices/startracker/StrHelper.h"
#include "bsp_q7s/devices/startracker/StarTrackerDefinitions.h"
#include "OBSWConfig.h"
@ -41,12 +42,11 @@
#include "mission/devices/GyroADIS1650XHandler.h"
#include "mission/devices/IMTQHandler.h"
#include "mission/devices/SyrlinksHkHandler.h"
#include "mission/devices/PlocMPSoCHandler.h"
#include "mission/devices/RadiationSensorHandler.h"
#include "mission/devices/RwHandler.h"
#include "mission/devices/devicedefinitions/GomspaceDefinitions.h"
#include "mission/devices/devicedefinitions/SyrlinksDefinitions.h"
#include "mission/devices/devicedefinitions/PlocMPSoCDefinitions.h"
#include "bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h"
#include "mission/devices/devicedefinitions/RadSensorDefinitions.h"
#include "mission/devices/devicedefinitions/Max31865Definitions.h"
#include "mission/devices/devicedefinitions/RwDefinitions.h"
@ -154,7 +154,7 @@ void ObjectFactory::produce(void* args) {
#if OBSW_ADD_PLOC_MPSOC == 1
UartCookie* plocMpsocCookie = new UartCookie(objects::PLOC_MPSOC_HANDLER,
q7s::UART_PLOC_MPSOC_DEV, UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD,
PLOC_MPSOC::MAX_REPLY_SIZE);
mpsoc::MAX_REPLY_SIZE);
new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, plocMpsocCookie);
#endif /* OBSW_ADD_PLOC_MPSOC == 1 */
@ -1075,7 +1075,7 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) {
#if BOARD_TE0720 == 1 && OBSW_ADD_PLOC_MPSOC == 1
UartCookie* plocUartCookie = new UartCookie(objects::PLOC_MPSOC_HANDLER, "/dev/ttyUL1",
UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, PLOC_MPSOC::MAX_REPLY_SIZE);
UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE);
/* Testing PlocMPSoCHandler on TE0720-03-1CFA */
PlocMPSoCHandler* mpsocPlocHandler = new PlocMPSoCHandler(objects::PLOC_MPSOC_HANDLER,
objects::UART_COM_IF, plocUartCookie);

View File

@ -4,15 +4,17 @@
#include <fsfw/tmtcpacket/SpacePacket.h>
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/serialize/SerializeAdapter.h>
#include <bsp_q7s/devices/ploc/PlocMPSoCHandler.h>
namespace PLOC_MPSOC {
namespace mpsoc {
static const DeviceCommandId_t NONE = 0x0;
static const DeviceCommandId_t TC_MEM_WRITE = 0x1;
static const DeviceCommandId_t TC_MEM_READ = 0x2;
static const DeviceCommandId_t ACK_REPORT = 0x3;
static const DeviceCommandId_t EXE_REPORT = 0x5;
static const DeviceCommandId_t TM_MEMORY_READ_REPORT = 0x6;
static const DeviceCommandId_t NONE = 0;
static const DeviceCommandId_t TC_MEM_WRITE = 1;
static const DeviceCommandId_t TC_MEM_READ = 2;
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 uint16_t SIZE_ACK_REPORT = 14;
static const uint16_t SIZE_EXE_REPORT = 14;
@ -21,15 +23,18 @@ static const uint16_t SIZE_TM_MEM_READ_REPORT = 18;
/**
* SpacePacket apids of PLOC telecommands and telemetry.
*/
static const uint16_t APID_TC_MEM_WRITE = 0x714;
static const uint16_t APID_TC_MEM_READ = 0x715;
static const uint16_t APID_TM_MEMORY_READ_REPORT = 0x404;
static const uint16_t APID_ACK_SUCCESS = 0x400;
static const uint16_t APID_ACK_FAILURE = 0x401;
static const uint16_t APID_EXE_SUCCESS = 0x402;
static const uint16_t APID_EXE_FAILURE = 0x403;
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 TM_MEMORY_READ_REPORT = 0x404;
static const uint16_t ACK_SUCCESS = 0x400;
static const uint16_t ACK_FAILURE = 0x401;
static const uint16_t EXE_SUCCESS = 0x402;
static const uint16_t EXE_FAILURE = 0x403;
}
/** Offset from first byte in Space packet to first byte of data field */
/** Offset from first byte in space packet to first byte of data field */
static const uint8_t DATA_FIELD_OFFSET = 6;
/**
@ -38,6 +43,8 @@ static const uint8_t DATA_FIELD_OFFSET = 6;
*/
static const uint8_t SIZE_MEM_READ_REPORT_DATA = 10;
static const size_t MAX_FILENAME_SIZE = 256;
/**
* PLOC space packet length for fixed size packets. This is the size of the whole packet data
* field. For the length field in the space packet this size will be substracted by one.
@ -48,6 +55,79 @@ static const uint16_t LENGTH_TC_MEM_READ = 8;
static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT;
static const size_t MAX_COMMAND_SIZE = 18;
/**
* @breif Abstract base class for TC space packet of MPSoC.
*/
class TcBase : public SpacePacket, public HasReturnvaluesIF {
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(0xA0);
/**
* @brief Constructor
*
* @param sequenceCount Sequence count of space packet which will be incremented with each
* sent and received packet.s
*/
TcBase(uint16_t apid, uint16_t sequenceCount) :
SpacePacket(INIT_LENGTH, true, apid, sequenceCount) {
}
/**
* @brief Function to initialitze 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) {
ReturnValue_t result = RETURN_OK;
result = initPacket(commandData, commandDataLen);
if (result != RETURN_OK) {
return result;
}
result = addCrc();
if (result != RETURN_OK) {
return result;
}
return result;
}
protected:
/**
* @brief Must be overwritten by the child class to define the command specific parameters
*
* @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;
private:
/**
* @brief Calculates and adds the CRC
*/
ReturnValue_t addCrc() {
ReturnValue_t result = 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) {
sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl;
}
return result;
}
};
/**
* @brief This class helps to build the memory read command for the PLOC.
*
@ -64,7 +144,7 @@ public:
* @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) {
SpacePacket(LENGTH_TC_MEM_READ - 1, true, apid::TC_MEM_READ, sequenceCount) {
fillPacketDataField(&memAddr);
}
@ -128,12 +208,17 @@ public:
* @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) {
SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, apid::TC_MEM_WRITE, sequenceCount) {
fillPacketDataField(&memAddr, &memoryData);
}
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;
/**
* @brief This function builds the packet data field for the mem write command.
*
@ -168,11 +253,56 @@ private:
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize, sizeof(crc),
SerializeIF::Endianness::BIG);
}
};
/** 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;
/**
* @brief Class to generate the flash file open 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) {
}
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;
}
filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen - 1);
accessMode = *(commandData + commandDataLen);
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;
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;
}
return RETURN_OK;
}
};
}

View File

@ -2,4 +2,5 @@ target_sources(${TARGET_NAME} PRIVATE
PlocSupervisorHandler.cpp
PlocUpdater.cpp
PlocMemoryDumper.cpp
PlocMPSoCHandler.cpp
)

View File

@ -1,4 +1,5 @@
#include "PlocMPSoCHandler.h"
#include "../../bsp_q7s/devices/ploc/PlocMPSoCHandler.h"
#include "OBSWConfig.h"
#include <fsfw/globalfunctions/CRC.h>
@ -57,14 +58,18 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
switch(deviceCommand) {
case(PLOC_MPSOC::TC_MEM_WRITE): {
case(mpsoc::TC_MEM_WRITE): {
result = prepareTcMemWriteCommand(commandData, commandDataLen);
break;
}
case(PLOC_MPSOC::TC_MEM_READ): {
case(mpsoc::TC_MEM_READ): {
result = prepareTcMemReadCommand(commandData, commandDataLen);
break;
}
case(mpsoc::TC_FLASHFOPEN): {
result = prepareFlashFopenCmd(commandData, commandDataLen);
break;
}
default:
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented" << std::endl;
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
@ -82,11 +87,12 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
}
void PlocMPSoCHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(PLOC_MPSOC::TC_MEM_WRITE);
this->insertInCommandMap(PLOC_MPSOC::TC_MEM_READ);
this->insertInReplyMap(PLOC_MPSOC::ACK_REPORT, 1, nullptr, PLOC_MPSOC::SIZE_ACK_REPORT);
this->insertInReplyMap(PLOC_MPSOC::EXE_REPORT, 3, nullptr, PLOC_MPSOC::SIZE_EXE_REPORT);
this->insertInReplyMap(PLOC_MPSOC::TM_MEMORY_READ_REPORT, 2, nullptr, PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT);
this->insertInCommandMap(mpsoc::TC_MEM_WRITE);
this->insertInCommandMap(mpsoc::TC_MEM_READ);
this->insertInCommandMap(mpsoc::TC_FLASHFOPEN);
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);
}
ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t *start,
@ -97,25 +103,25 @@ ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t *start,
uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK;
switch(apid) {
case(PLOC_MPSOC::APID_ACK_SUCCESS):
*foundLen = PLOC_MPSOC::SIZE_ACK_REPORT;
*foundId = PLOC_MPSOC::ACK_REPORT;
case(mpsoc::apid::ACK_SUCCESS):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case(PLOC_MPSOC::APID_ACK_FAILURE):
*foundLen = PLOC_MPSOC::SIZE_ACK_REPORT;
*foundId = PLOC_MPSOC::ACK_REPORT;
case(mpsoc::apid::ACK_FAILURE):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case(PLOC_MPSOC::APID_TM_MEMORY_READ_REPORT):
*foundLen = PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT;
*foundId = PLOC_MPSOC::TM_MEMORY_READ_REPORT;
case(mpsoc::apid::TM_MEMORY_READ_REPORT):
*foundLen = mpsoc::SIZE_TM_MEM_READ_REPORT;
*foundId = mpsoc::TM_MEMORY_READ_REPORT;
break;
case(PLOC_MPSOC::APID_EXE_SUCCESS):
*foundLen = PLOC_MPSOC::SIZE_EXE_REPORT;
*foundId = PLOC_MPSOC::EXE_REPORT;
case(mpsoc::apid::EXE_SUCCESS):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
case(PLOC_MPSOC::APID_EXE_FAILURE):
*foundLen = PLOC_MPSOC::SIZE_EXE_REPORT;
*foundId = PLOC_MPSOC::EXE_REPORT;
case(mpsoc::apid::EXE_FAILURE):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
default: {
sif::debug << "PlocMPSoCHandler::scanForReply: Reply has invalid apid" << std::endl;
@ -133,15 +139,15 @@ ReturnValue_t PlocMPSoCHandler::interpretDeviceReply(DeviceCommandId_t id,
ReturnValue_t result = RETURN_OK;
switch (id) {
case PLOC_MPSOC::ACK_REPORT: {
case mpsoc::ACK_REPORT: {
result = handleAckReport(packet);
break;
}
case (PLOC_MPSOC::TM_MEMORY_READ_REPORT): {
case (mpsoc::TM_MEMORY_READ_REPORT): {
result = handleMemoryReadReport(packet);
break;
}
case (PLOC_MPSOC::EXE_REPORT): {
case (mpsoc::EXE_REPORT): {
result = handleExecutionReport(packet);
break;
}
@ -179,15 +185,15 @@ ReturnValue_t PlocMPSoCHandler::prepareTcMemWriteCommand(const uint8_t * command
const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16
| *(commandData + 6) << 8 | *(commandData + 7);
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
PLOC_MPSOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount);
if (tcMemWrite.getFullSize() > PLOC_MPSOC::MAX_COMMAND_SIZE) {
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;
}
memcpy(commandBuffer, tcMemWrite.getWholeData(), tcMemWrite.getFullSize());
rawPacket = commandBuffer;
rawPacketLen = tcMemWrite.getFullSize();
nextReplyId = PLOC_MPSOC::ACK_REPORT;
nextReplyId = mpsoc::ACK_REPORT;
return RETURN_OK;
}
@ -196,18 +202,41 @@ ReturnValue_t PlocMPSoCHandler::prepareTcMemReadCommand(const uint8_t * commandD
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
| *(commandData + 2) << 8 | *(commandData + 3);
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
PLOC_MPSOC::TcMemRead tcMemRead(memoryAddress, packetSequenceCount);
if (tcMemRead.getFullSize() > PLOC_MPSOC::MAX_COMMAND_SIZE) {
mpsoc::TcMemRead tcMemRead(memoryAddress, packetSequenceCount);
if (tcMemRead.getFullSize() > mpsoc::MAX_COMMAND_SIZE) {
sif::debug << "PlocMPSoCHandler::prepareTcMemReadCommand: Command too big" << std::endl;
return RETURN_FAILED;
}
memcpy(commandBuffer, tcMemRead.getWholeData(), tcMemRead.getFullSize());
rawPacket = commandBuffer;
rawPacketLen = tcMemRead.getFullSize();
nextReplyId = PLOC_MPSOC::ACK_REPORT;
nextReplyId = mpsoc::ACK_REPORT;
return RETURN_OK;
}
ReturnValue_t PlocMPSoCHandler::prepareFlashFopenCmd(const uint8_t * commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
mpsoc::FlashFopen flashFopen(packetSequenceCount);
result = flashFopen.createPacket(commandData, commandDataLen);
if (result != RETURN_OK) {
return result;
}
copyToCommandBuffer(&flashFopen);
return RETURN_OK;
}
void PlocMPSoCHandler::copyToCommandBuffer(mpsoc::TcBase* tc) {
if (tc == nullptr) {
sif::debug << "PlocMPSoCHandler::copyToCommandBuffer: Invalid TC" << std::endl;
}
memcpy(commandBuffer, tc->getWholeData(), tc->getFullSize());
rawPacket = commandBuffer;
rawPacketLen = tc->getFullSize();
nextReplyId = mpsoc::ACK_REPORT;
}
ReturnValue_t PlocMPSoCHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
@ -221,13 +250,13 @@ ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
ReturnValue_t result = RETURN_OK;
result = verifyPacket(data, PLOC_MPSOC::SIZE_ACK_REPORT);
result = verifyPacket(data, mpsoc::SIZE_ACK_REPORT);
if(result == CRC_FAILURE) {
sif::error << "PlocMPSoCHandler::handleAckReport: CRC failure" << std::endl;
nextReplyId = PLOC_MPSOC::NONE;
replyRawReplyIfnotWiretapped(data, PLOC_MPSOC::SIZE_ACK_REPORT);
nextReplyId = mpsoc::NONE;
replyRawReplyIfnotWiretapped(data, mpsoc::SIZE_ACK_REPORT);
triggerEvent(CRC_FAILURE_EVENT);
sendFailureReport(PLOC_MPSOC::ACK_REPORT, CRC_FAILURE);
sendFailureReport(mpsoc::ACK_REPORT, CRC_FAILURE);
disableAllReplies();
return IGNORE_REPLY_DATA;
}
@ -235,20 +264,20 @@ ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch(apid) {
case PLOC_MPSOC::APID_ACK_FAILURE: {
case mpsoc::apid::ACK_FAILURE: {
//TODO: Interpretation of status field in acknowledgment report
sif::debug << "PlocMPSoCHandler::handleAckReport: Received Ack failure report" << std::endl;
DeviceCommandId_t commandId = getPendingCommand();
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
triggerEvent(ACK_FAILURE, commandId);
}
sendFailureReport(PLOC_MPSOC::ACK_REPORT, RECEIVED_ACK_FAILURE);
sendFailureReport(mpsoc::ACK_REPORT, RECEIVED_ACK_FAILURE);
disableAllReplies();
nextReplyId = PLOC_MPSOC::NONE;
nextReplyId = mpsoc::NONE;
result = IGNORE_REPLY_DATA;
break;
}
case PLOC_MPSOC::APID_ACK_SUCCESS: {
case mpsoc::apid::ACK_SUCCESS: {
setNextReplyId();
break;
}
@ -263,23 +292,22 @@ ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
}
ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
ReturnValue_t result = RETURN_OK;
result = verifyPacket(data, PLOC_MPSOC::SIZE_EXE_REPORT);
result = verifyPacket(data, mpsoc::SIZE_EXE_REPORT);
if(result == CRC_FAILURE) {
sif::error << "PlocMPSoCHandler::handleExecutionReport: CRC failure" << std::endl;
nextReplyId = PLOC_MPSOC::NONE;
nextReplyId = mpsoc::NONE;
return result;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch (apid) {
case (PLOC_MPSOC::APID_EXE_SUCCESS): {
case (mpsoc::apid::EXE_SUCCESS): {
break;
}
case (PLOC_MPSOC::APID_EXE_FAILURE): {
case (mpsoc::apid::EXE_FAILURE): {
//TODO: Interpretation of status field in execution report
sif::error << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report"
<< std::endl;
@ -290,7 +318,7 @@ ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
else {
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl;
}
sendFailureReport(PLOC_MPSOC::EXE_REPORT, RECEIVED_EXE_FAILURE);
sendFailureReport(mpsoc::EXE_REPORT, RECEIVED_EXE_FAILURE);
disableExeReportReply();
result = IGNORE_REPLY_DATA;
break;
@ -301,23 +329,21 @@ ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
break;
}
}
nextReplyId = PLOC_MPSOC::NONE;
nextReplyId = mpsoc::NONE;
return result;
}
ReturnValue_t PlocMPSoCHandler::handleMemoryReadReport(const uint8_t* data) {
ReturnValue_t result = RETURN_OK;
result = verifyPacket(data, PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT);
result = verifyPacket(data, mpsoc::SIZE_TM_MEM_READ_REPORT);
if(result == CRC_FAILURE) {
sif::error << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc"
<< std::endl;
}
/** Send data to commanding queue */
handleDeviceTM(data + PLOC_MPSOC::DATA_FIELD_OFFSET, PLOC_MPSOC::SIZE_MEM_READ_REPORT_DATA,
PLOC_MPSOC::TM_MEMORY_READ_REPORT);
nextReplyId = PLOC_MPSOC::EXE_REPORT;
handleDeviceTM(data + mpsoc::DATA_FIELD_OFFSET, mpsoc::SIZE_MEM_READ_REPORT_DATA,
mpsoc::TM_MEMORY_READ_REPORT);
nextReplyId = mpsoc::EXE_REPORT;
return result;
}
@ -330,16 +356,17 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator
uint8_t enabledReplies = 0;
switch (command->first) {
case PLOC_MPSOC::TC_MEM_WRITE:
case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHFOPEN:
enabledReplies = 2;
break;
case PLOC_MPSOC::TC_MEM_READ: {
case mpsoc::TC_MEM_READ: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
PLOC_MPSOC::TM_MEMORY_READ_REPORT);
mpsoc::TM_MEMORY_READ_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
<< PLOC_MPSOC::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
<< mpsoc::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
}
break;
}
@ -353,16 +380,16 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator
* replies will be enabled here.
*/
result = DeviceHandlerBase::enableReplyInReplyMap(command,
enabledReplies, true, PLOC_MPSOC::ACK_REPORT);
enabledReplies, true, mpsoc::ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << PLOC_MPSOC::ACK_REPORT
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result = DeviceHandlerBase::enableReplyInReplyMap(command,
enabledReplies, true, PLOC_MPSOC::EXE_REPORT);
enabledReplies, true, mpsoc::EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << PLOC_MPSOC::EXE_REPORT
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::EXE_REPORT
<< " not in replyMap" << std::endl;
}
@ -371,12 +398,12 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator
void PlocMPSoCHandler::setNextReplyId() {
switch(getPendingCommand()) {
case PLOC_MPSOC::TC_MEM_READ:
nextReplyId = PLOC_MPSOC::TM_MEMORY_READ_REPORT;
case mpsoc::TC_MEM_READ:
nextReplyId = mpsoc::TM_MEMORY_READ_REPORT;
break;
default:
/* If no telemetry is expected the next reply is always the execution report */
nextReplyId = PLOC_MPSOC::EXE_REPORT;
nextReplyId = mpsoc::EXE_REPORT;
break;
}
}
@ -384,7 +411,7 @@ size_t PlocMPSoCHandler::getNextReplyLength(DeviceCommandId_t commandId){
size_t replyLen = 0;
if (nextReplyId == PLOC_MPSOC::NONE) {
if (nextReplyId == mpsoc::NONE) {
return replyLen;
}
@ -435,7 +462,7 @@ void PlocMPSoCHandler::disableAllReplies() {
DeviceReplyMap::iterator iter;
/* Disable ack reply */
iter = deviceReplyMap.find(PLOC_MPSOC::ACK_REPORT);
iter = deviceReplyMap.find(mpsoc::ACK_REPORT);
DeviceReplyInfo *info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
@ -444,10 +471,11 @@ void PlocMPSoCHandler::disableAllReplies() {
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
switch (commandId) {
case PLOC_MPSOC::TC_MEM_WRITE:
case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHFOPEN:
break;
case PLOC_MPSOC::TC_MEM_READ: {
iter = deviceReplyMap.find(PLOC_MPSOC::TM_MEMORY_READ_REPORT);
case mpsoc::TC_MEM_READ: {
iter = deviceReplyMap.find(mpsoc::TM_MEMORY_READ_REPORT);
info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
@ -487,7 +515,7 @@ void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_
}
void PlocMPSoCHandler::disableExeReportReply() {
DeviceReplyIter iter = deviceReplyMap.find(PLOC_MPSOC::EXE_REPORT);
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
DeviceReplyInfo *info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();

View File

@ -1,8 +1,8 @@
#ifndef MISSION_DEVICES_PLOCMPSOCHANDLER_H_
#define MISSION_DEVICES_PLOCMPSOCHANDLER_H_
#ifndef BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
#define BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <mission/devices/devicedefinitions/PlocMPSoCDefinitions.h>
#include <bsp_q7s/devices/devicedefinitions/PlocMPSoCDefinitions.h>
#include <cstring>
#include <fsfw_hal/linux/uart/UartComIF.h>
@ -22,6 +22,19 @@
class PlocMPSoCHandler: public DeviceHandlerBase {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HANDLER;
//! [EXPORT] : [COMMENT] Space Packet received from PLOC has invalid CRC
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Received ACK failure reply from PLOC
static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1);
//! [EXPORT] : [COMMENT] Received execution failure reply from PLOC
static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2);
//! [EXPORT] : [COMMENT] Received space packet with invalid APID from PLOC
static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3);
//! [EXPORT] : [COMMENT] Received command with invalid length
static const ReturnValue_t INVALID_LENGTH = MAKE_RETURN_CODE(0xA4);
PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF * comCookie);
virtual ~PlocMPSoCHandler();
@ -54,17 +67,6 @@ protected:
private:
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HANDLER;
//! [EXPORT] : [COMMENT] Space Packet received from PLOC has invalid CRC
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Received ACK failure reply from PLOC
static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1);
//! [EXPORT] : [COMMENT] Received execution failure reply from PLOC
static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2);
//! [EXPORT] : [COMMENT] Received space packet with invalid APID from PLOC
static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3);
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HANDLER;
//! [EXPORT] : [COMMENT] PLOC crc failure in telemetry packet
@ -83,7 +85,7 @@ private:
static const uint16_t APID_MASK = 0x7FF;
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
uint8_t commandBuffer[PLOC_MPSOC::MAX_COMMAND_SIZE];
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
/**
* @brief This object is incremented each time a packet is sent or received. By checking the
@ -102,29 +104,18 @@ private:
* because the PLOC sends as reply to each command at least one acknowledgment and execution
* report.
*/
DeviceCommandId_t nextReplyId = PLOC_MPSOC::NONE;
DeviceCommandId_t nextReplyId = mpsoc::NONE;
UartComIF* uartComIf = nullptr;
/**
* @brief This function fills the commandBuffer to initiate the write memory command.
*
* @param commandData Pointer to action command data.
* @param commanDataLen Size of command data in bytes.
*
* @return RETURN_OK if successful, else RETURN_FAILURE.
*/
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);
/**
* @brief This function fills the commandBuffer to initiate the write reads command.
*
* @param commandData Pointer to action command data.
* @param commanDataLen Size of command data in bytes.
*
* @return RETURN_OK if successful, else RETURN_FAILURE.
* @brief Copies space packet into command buffer
*/
ReturnValue_t prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen);
void copyToCommandBuffer(mpsoc::TcBase* tc);
/**
* @brief This function checks the crc of the received PLOC reply.
@ -219,4 +210,4 @@ private:
ReturnValue_t checkPacketSequenceCount(const uint8_t* data);
};
#endif /* MISSION_DEVICES_PLOCMPSOCHANDLER_H_ */
#endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */

View File

@ -14,6 +14,7 @@ enum commonClassIds: uint8_t {
RW_HANDLER, //RWHA
STR_HANDLER, //STRH
PLOC_MPSOC_HANDLER, //PLMP
MPSOC_CMD, //MPCMD
PLOC_SUPERVISOR_HANDLER, //PLSV
SUS_HANDLER, //SUSS
CCSDS_IP_CORE_BRIDGE, //IPCI

View File

@ -11,7 +11,6 @@ target_sources(${TARGET_NAME} PUBLIC
Max31865PT1000Handler.cpp
IMTQHandler.cpp
HeaterHandler.cpp
PlocMPSoCHandler.cpp
RadiationSensorHandler.cpp
GyroADIS1650XHandler.cpp
RwHandler.cpp