first flash read impl almost done
This commit is contained in:
parent
0a109e552d
commit
ff47fafdc2
@ -51,6 +51,16 @@ ReturnValue_t PlocMPSoCHelper::performOperation(uint8_t operationCode) {
|
|||||||
internalState = InternalState::IDLE;
|
internalState = InternalState::IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case InternalState::FLASH_READ: {
|
||||||
|
result = performFlashRead();
|
||||||
|
if (result == returnvalue::OK) {
|
||||||
|
triggerEvent(MPSOC_FLASH_READ_SUCCESSFUL);
|
||||||
|
} else {
|
||||||
|
triggerEvent(MPSOC_FLASH_READ_FAILED);
|
||||||
|
}
|
||||||
|
internalState = InternalState::IDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
|
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
|
||||||
break;
|
break;
|
||||||
@ -132,29 +142,32 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
|
|||||||
size_t bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
while (remainingSize > 0) {
|
while (remainingSize > 0) {
|
||||||
if (terminate) {
|
if (terminate) {
|
||||||
|
flashfclose();
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
if (remainingSize > mpsoc::MAX_DATA_SIZE) {
|
if (remainingSize > mpsoc::SP_MAX_DATA_SIZE) {
|
||||||
dataLength = mpsoc::MAX_DATA_SIZE;
|
dataLength = mpsoc::SP_MAX_DATA_SIZE;
|
||||||
} else {
|
} else {
|
||||||
dataLength = remainingSize;
|
dataLength = remainingSize;
|
||||||
}
|
}
|
||||||
if (file.is_open()) {
|
if (file.bad() or not file.is_open()) {
|
||||||
|
flashfclose();
|
||||||
|
return FILE_WRITE_ERROR;
|
||||||
|
}
|
||||||
file.seekg(bytesRead, file.beg);
|
file.seekg(bytesRead, file.beg);
|
||||||
file.read(reinterpret_cast<char*>(fileBuf.data()), dataLength);
|
file.read(reinterpret_cast<char*>(fileBuf.data()), dataLength);
|
||||||
bytesRead += dataLength;
|
bytesRead += dataLength;
|
||||||
remainingSize -= dataLength;
|
remainingSize -= dataLength;
|
||||||
} else {
|
|
||||||
return FILE_CLOSED_ACCIDENTALLY;
|
|
||||||
}
|
|
||||||
(*sequenceCount)++;
|
(*sequenceCount)++;
|
||||||
mpsoc::TcFlashWrite tc(spParams, *sequenceCount);
|
mpsoc::TcFlashWrite tc(spParams, *sequenceCount);
|
||||||
result = tc.buildPacket(fileBuf.data(), dataLength);
|
result = tc.buildPacket(fileBuf.data(), dataLength);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
flashfclose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = handlePacketTransmission(tc);
|
result = handlePacketTransmissionNoReply(tc);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
flashfclose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,27 +179,68 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::performFlashRead() {
|
ReturnValue_t PlocMPSoCHelper::performFlashRead() {
|
||||||
std::ofstream ofile(flashReadAndWrite.obcFile);
|
std::error_code e;
|
||||||
|
std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::trunc | std::ios::binary);
|
||||||
if (ofile.bad()) {
|
if (ofile.bad()) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
ReturnValue_t result = flashfopen();
|
ReturnValue_t result = flashfopen();
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
size_t readSoFar = 0;
|
||||||
|
size_t nextReadSize = mpsoc::MAX_FLASH_READ_DATA_SIZE;
|
||||||
|
while (readSoFar < flashReadAndWrite.totalReadSize) {
|
||||||
|
if (terminate) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
|
flashfclose();
|
||||||
|
return returnvalue::OK;
|
||||||
|
}
|
||||||
|
nextReadSize = mpsoc::MAX_FLASH_READ_DATA_SIZE;
|
||||||
|
if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) {
|
||||||
|
nextReadSize = flashReadAndWrite.totalReadSize - readSoFar;
|
||||||
|
}
|
||||||
|
if (ofile.bad() or not ofile.is_open()) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
|
flashfclose();
|
||||||
|
return FILE_READ_ERROR;
|
||||||
|
}
|
||||||
|
mpsoc::TcFlashRead flashReadRequest(spParams, *sequenceCount);
|
||||||
|
result = flashReadRequest.buildPacket(nextReadSize);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
|
flashfclose();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = handlePacketTransmissionFlashRead(flashReadRequest);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
|
flashfclose();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = handleFlashReadReply(ofile, nextReadSize);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
|
flashfclose();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
(*sequenceCount)++;
|
||||||
|
readSoFar += nextReadSize;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::flashfopen() {
|
ReturnValue_t PlocMPSoCHelper::flashfopen() {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
|
||||||
spParams.buf = commandBuffer;
|
spParams.buf = commandBuffer;
|
||||||
(*sequenceCount)++;
|
(*sequenceCount)++;
|
||||||
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
|
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
|
||||||
result = flashFopen.createPacket(flashReadAndWrite.mpsocFile, mpsoc::FlashFopen::APPEND);
|
ReturnValue_t result =
|
||||||
|
flashFopen.createPacket(flashReadAndWrite.mpsocFile, mpsoc::FlashFopen::APPEND);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = handlePacketTransmission(flashFopen);
|
result = handlePacketTransmissionNoReply(flashFopen);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -194,24 +248,18 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::flashfclose() {
|
ReturnValue_t PlocMPSoCHelper::flashfclose() {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
|
||||||
spParams.buf = commandBuffer;
|
spParams.buf = commandBuffer;
|
||||||
(*sequenceCount)++;
|
(*sequenceCount)++;
|
||||||
mpsoc::FlashFclose flashFclose(spParams, *sequenceCount);
|
mpsoc::FlashFclose flashFclose(spParams, *sequenceCount);
|
||||||
result = flashFclose.createPacket(flashReadAndWrite.mpsocFile);
|
ReturnValue_t result = flashFclose.createPacket(flashReadAndWrite.mpsocFile);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = handlePacketTransmission(flashFclose);
|
return handlePacketTransmissionNoReply(flashFclose);
|
||||||
if (result != returnvalue::OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return returnvalue::OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::handlePacketTransmission(ploc::SpTcBase& tc) {
|
ReturnValue_t PlocMPSoCHelper::handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = sendCommand(tc);
|
||||||
result = sendCommand(tc);
|
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -219,11 +267,24 @@ ReturnValue_t PlocMPSoCHelper::handlePacketTransmission(ploc::SpTcBase& tc) {
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = handleExe();
|
result = handleTmReception(ccsds::HEADER_LEN + mpsoc::FLASH_READ_MIN_OVERHEAD + tc.readSize +
|
||||||
|
mpsoc::CRC_SIZE);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return handleExe();
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PlocMPSoCHelper::handlePacketTransmissionNoReply(ploc::SpTcBase& tc) {
|
||||||
|
ReturnValue_t result = sendCommand(tc);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = handleAck();
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return handleExe();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::sendCommand(ploc::SpTcBase& tc) {
|
ReturnValue_t PlocMPSoCHelper::sendCommand(ploc::SpTcBase& tc) {
|
||||||
@ -323,6 +384,46 @@ ReturnValue_t PlocMPSoCHelper::handleTmReception(size_t remainingBytes) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PlocMPSoCHelper::handleFlashReadReply(std::ofstream& ofile, size_t expectedReadLen) {
|
||||||
|
SpTmReader tmPacket(tmBuf.data(), tmBuf.size());
|
||||||
|
ReturnValue_t result = checkReceivedTm(tmPacket);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
uint16_t apid = tmPacket.getApid();
|
||||||
|
if (apid != mpsoc::apid::TM_FLASH_READ_REPORT) {
|
||||||
|
triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_APID_ERROR);
|
||||||
|
sif::warning << "PLOC MPSoC Flash Read: Unexpected APID" << std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const uint8_t* packetData = tmPacket.getPacketData();
|
||||||
|
size_t deserDummy = tmPacket.getPacketDataLen() - mpsoc::CRC_SIZE;
|
||||||
|
uint32_t receivedReadLen = 0;
|
||||||
|
std::string receivedShortName = std::string(reinterpret_cast<const char*>(packetData), 12);
|
||||||
|
if (receivedShortName != flashReadAndWrite.mpsocFile.substr(0, 12)) {
|
||||||
|
sif::warning << "PLOC MPSoC Flash Read: Missmatch between request file name and "
|
||||||
|
"received file name"
|
||||||
|
<< std::endl;
|
||||||
|
triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_FILENAME_ERROR);
|
||||||
|
return returnvalue::FAILED;
|
||||||
|
}
|
||||||
|
packetData += 12;
|
||||||
|
result = SerializeAdapter::deSerialize(&receivedReadLen, &packetData, &deserDummy,
|
||||||
|
SerializeIF::Endianness::NETWORK);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (receivedReadLen != expectedReadLen) {
|
||||||
|
sif::warning << "PLOC MPSoC Flash Read: Missmatch between request read length and "
|
||||||
|
"received read length"
|
||||||
|
<< std::endl;
|
||||||
|
triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_READLEN_ERROR);
|
||||||
|
return returnvalue::FAILED;
|
||||||
|
}
|
||||||
|
ofile.write(reinterpret_cast<const char*>(packetData), receivedReadLen);
|
||||||
|
return returnvalue::OK;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) {
|
ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) {
|
||||||
ReturnValue_t result = reader.checkSize();
|
ReturnValue_t result = reader.checkSize();
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
@ -29,7 +29,7 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
//! [EXPORT] : [COMMENT] Flash write fails
|
//! [EXPORT] : [COMMENT] Flash write fails
|
||||||
static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW);
|
static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW);
|
||||||
//! [EXPORT] : [COMMENT] Flash write successful
|
//! [EXPORT] : [COMMENT] Flash write successful
|
||||||
static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::LOW);
|
static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::INFO);
|
||||||
//! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command
|
//! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command
|
||||||
//! to the MPSoC
|
//! to the MPSoC
|
||||||
//! P1: Return value returned by the communication interface sendMessage function
|
//! P1: Return value returned by the communication interface sendMessage function
|
||||||
@ -71,6 +71,15 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW);
|
static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW);
|
||||||
static const Event MPSOC_TM_SIZE_ERROR = MAKE_EVENT(12, severity::LOW);
|
static const Event MPSOC_TM_SIZE_ERROR = MAKE_EVENT(12, severity::LOW);
|
||||||
static const Event MPSOC_TM_CRC_MISSMATCH = MAKE_EVENT(13, severity::LOW);
|
static const Event MPSOC_TM_CRC_MISSMATCH = MAKE_EVENT(13, severity::LOW);
|
||||||
|
static const Event MPSOC_FLASH_READ_PACKET_ERROR = MAKE_EVENT(14, severity::LOW);
|
||||||
|
static const Event MPSOC_FLASH_READ_FAILED = MAKE_EVENT(15, severity::LOW);
|
||||||
|
static const Event MPSOC_FLASH_READ_SUCCESSFUL = MAKE_EVENT(16, severity::INFO);
|
||||||
|
|
||||||
|
enum FlashReadErrorType : uint32_t {
|
||||||
|
FLASH_READ_APID_ERROR = 0,
|
||||||
|
FLASH_READ_FILENAME_ERROR = 1,
|
||||||
|
FLASH_READ_READLEN_ERROR = 2
|
||||||
|
};
|
||||||
|
|
||||||
PlocMPSoCHelper(object_id_t objectId);
|
PlocMPSoCHelper(object_id_t objectId);
|
||||||
virtual ~PlocMPSoCHelper();
|
virtual ~PlocMPSoCHelper();
|
||||||
@ -104,8 +113,10 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
private:
|
private:
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER;
|
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER;
|
||||||
|
|
||||||
//! [EXPORT] : [COMMENT] File accidentally close
|
//! [EXPORT] : [COMMENT] File error occured for file transfers from OBC to the MPSoC.
|
||||||
static const ReturnValue_t FILE_CLOSED_ACCIDENTALLY = MAKE_RETURN_CODE(0xA0);
|
static const ReturnValue_t FILE_WRITE_ERROR = MAKE_RETURN_CODE(0xA0);
|
||||||
|
//! [EXPORT] : [COMMENT] File error occured for file transfers from MPSoC to OBC.
|
||||||
|
static const ReturnValue_t FILE_READ_ERROR = MAKE_RETURN_CODE(0xA1);
|
||||||
|
|
||||||
// Maximum number of times the communication interface retries polling data from the reply
|
// Maximum number of times the communication interface retries polling data from the reply
|
||||||
// buffer
|
// buffer
|
||||||
@ -117,7 +128,7 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct FlashRead : public FlashInfo {
|
struct FlashRead : public FlashInfo {
|
||||||
size_t readSize = 0;
|
size_t totalReadSize = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FlashRead flashReadAndWrite;
|
struct FlashRead flashReadAndWrite;
|
||||||
@ -137,7 +148,7 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
SpacePacketCreator creator;
|
SpacePacketCreator creator;
|
||||||
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
|
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
|
||||||
|
|
||||||
std::array<uint8_t, mpsoc::MAX_DATA_SIZE> fileBuf{};
|
std::array<uint8_t, mpsoc::SP_MAX_DATA_SIZE> fileBuf{};
|
||||||
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf{};
|
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf{};
|
||||||
|
|
||||||
bool terminate = false;
|
bool terminate = false;
|
||||||
@ -157,7 +168,9 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
|||||||
ReturnValue_t performFlashRead();
|
ReturnValue_t performFlashRead();
|
||||||
ReturnValue_t flashfopen();
|
ReturnValue_t flashfopen();
|
||||||
ReturnValue_t flashfclose();
|
ReturnValue_t flashfclose();
|
||||||
ReturnValue_t handlePacketTransmission(ploc::SpTcBase& tc);
|
ReturnValue_t handlePacketTransmissionNoReply(ploc::SpTcBase& tc);
|
||||||
|
ReturnValue_t handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc);
|
||||||
|
ReturnValue_t handleFlashReadReply(std::ofstream& ofile, size_t expectedReadLen);
|
||||||
ReturnValue_t sendCommand(ploc::SpTcBase& tc);
|
ReturnValue_t sendCommand(ploc::SpTcBase& tc);
|
||||||
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
|
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
|
||||||
ReturnValue_t handleAck();
|
ReturnValue_t handleAck();
|
||||||
|
@ -102,7 +102,8 @@ static const uint16_t TC_DOWNLINK_PWR_ON = 0x113;
|
|||||||
static const uint16_t TC_MEM_WRITE = 0x114;
|
static const uint16_t TC_MEM_WRITE = 0x114;
|
||||||
static const uint16_t TC_MEM_READ = 0x115;
|
static const uint16_t TC_MEM_READ = 0x115;
|
||||||
static const uint16_t TC_CAM_TAKE_PIC = 0x116;
|
static const uint16_t TC_CAM_TAKE_PIC = 0x116;
|
||||||
static const uint16_t TC_FLASHWRITE = 0x117;
|
static constexpr uint16_t TC_FLASHWRITE = 0x117;
|
||||||
|
static constexpr uint16_t TC_FLASHREAD = 0x118;
|
||||||
static const uint16_t TC_FLASHFOPEN = 0x119;
|
static const uint16_t TC_FLASHFOPEN = 0x119;
|
||||||
static const uint16_t TC_FLASHFCLOSE = 0x11A;
|
static const uint16_t TC_FLASHFCLOSE = 0x11A;
|
||||||
static const uint16_t TC_FLASHDELETE = 0x11C;
|
static const uint16_t TC_FLASHDELETE = 0x11C;
|
||||||
@ -115,11 +116,12 @@ static constexpr uint16_t TM_HK_GET_REPORT = 0x408;
|
|||||||
static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124;
|
static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124;
|
||||||
static const uint16_t TC_CAM_CMD_SEND = 0x12C;
|
static const uint16_t TC_CAM_CMD_SEND = 0x12C;
|
||||||
static const uint16_t TC_SIMPLEX_SEND_FILE = 0x130;
|
static const uint16_t TC_SIMPLEX_SEND_FILE = 0x130;
|
||||||
static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
|
|
||||||
static const uint16_t ACK_SUCCESS = 0x400;
|
static const uint16_t ACK_SUCCESS = 0x400;
|
||||||
static const uint16_t ACK_FAILURE = 0x401;
|
static const uint16_t ACK_FAILURE = 0x401;
|
||||||
static const uint16_t EXE_SUCCESS = 0x402;
|
static const uint16_t EXE_SUCCESS = 0x402;
|
||||||
static const uint16_t EXE_FAILURE = 0x403;
|
static const uint16_t EXE_FAILURE = 0x403;
|
||||||
|
static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
|
||||||
|
static const uint16_t TM_FLASH_READ_REPORT = 0x405;
|
||||||
static const uint16_t TM_CAM_CMD_RPT = 0x407;
|
static const uint16_t TM_CAM_CMD_RPT = 0x407;
|
||||||
} // namespace apid
|
} // namespace apid
|
||||||
|
|
||||||
@ -153,9 +155,13 @@ static const uint16_t LENGTH_TC_MEM_READ = 8;
|
|||||||
* at sheet README
|
* at sheet README
|
||||||
*/
|
*/
|
||||||
static constexpr size_t SP_MAX_SIZE = 1024;
|
static constexpr size_t SP_MAX_SIZE = 1024;
|
||||||
static const size_t MAX_REPLY_SIZE = SP_MAX_SIZE * 3;
|
static constexpr size_t MAX_REPLY_SIZE = SP_MAX_SIZE * 3;
|
||||||
static const size_t MAX_COMMAND_SIZE = SP_MAX_SIZE;
|
static constexpr size_t MAX_COMMAND_SIZE = SP_MAX_SIZE;
|
||||||
static const size_t MAX_DATA_SIZE = 1016;
|
// 1016 bytes.
|
||||||
|
static constexpr size_t SP_MAX_DATA_SIZE = SP_MAX_SIZE - ccsds::HEADER_LEN - CRC_SIZE;
|
||||||
|
static constexpr size_t FLASH_READ_MIN_OVERHEAD = 16;
|
||||||
|
// 1000 bytes.
|
||||||
|
static const size_t MAX_FLASH_READ_DATA_SIZE = SP_MAX_DATA_SIZE - FLASH_READ_MIN_OVERHEAD;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The replay write sequence command has a maximum delay for the execution report which amounts to
|
* The replay write sequence command has a maximum delay for the execution report which amounts to
|
||||||
@ -421,8 +427,8 @@ class TcFlashWrite : public ploc::SpTcBase {
|
|||||||
ReturnValue_t buildPacket(const uint8_t* writeData, uint32_t writeLen_) {
|
ReturnValue_t buildPacket(const uint8_t* writeData, uint32_t writeLen_) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = returnvalue::OK;
|
||||||
writeLen = writeLen_;
|
writeLen = writeLen_;
|
||||||
if (writeLen > MAX_DATA_SIZE) {
|
if (writeLen > SP_MAX_DATA_SIZE) {
|
||||||
sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl;
|
sif::error << "TcFlashWrite: Command data too big" << std::endl;
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
spParams.setFullPayloadLen(static_cast<uint16_t>(writeLen) + 4 + CRC_SIZE);
|
spParams.setFullPayloadLen(static_cast<uint16_t>(writeLen) + 4 + CRC_SIZE);
|
||||||
@ -438,9 +444,9 @@ class TcFlashWrite : public ploc::SpTcBase {
|
|||||||
}
|
}
|
||||||
std::memcpy(payloadStart + sizeof(writeLen), writeData, writeLen);
|
std::memcpy(payloadStart + sizeof(writeLen), writeData, writeLen);
|
||||||
updateSpFields();
|
updateSpFields();
|
||||||
auto res = checkSizeAndSerializeHeader();
|
result = checkSizeAndSerializeHeader();
|
||||||
if (res != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return res;
|
return result;
|
||||||
}
|
}
|
||||||
return calcAndSetCrc();
|
return calcAndSetCrc();
|
||||||
}
|
}
|
||||||
@ -449,6 +455,43 @@ class TcFlashWrite : public ploc::SpTcBase {
|
|||||||
uint32_t writeLen = 0;
|
uint32_t writeLen = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TcFlashRead : public ploc::SpTcBase {
|
||||||
|
public:
|
||||||
|
TcFlashRead(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||||
|
: ploc::SpTcBase(params, apid::TC_FLASHWRITE, sequenceCount) {}
|
||||||
|
|
||||||
|
ReturnValue_t buildPacket(uint32_t readLen) {
|
||||||
|
if (readLen > MAX_FLASH_READ_DATA_SIZE) {
|
||||||
|
sif::error << "TcFlashRead: Read length " << readLen << " too large" << std::endl;
|
||||||
|
return returnvalue::FAILED;
|
||||||
|
}
|
||||||
|
spParams.setFullPayloadLen(readLen + FLASH_READ_MIN_OVERHEAD + CRC_SIZE);
|
||||||
|
ReturnValue_t result = checkPayloadLen();
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
size_t serializedSize = ccsds::HEADER_LEN;
|
||||||
|
result = SerializeAdapter::serialize(&readLen, payloadStart, &serializedSize, spParams.maxSize,
|
||||||
|
SerializeIF::Endianness::NETWORK);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
updateSpFields();
|
||||||
|
result = checkSizeAndSerializeHeader();
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = calcAndSetCrc();
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
readSize = readLen;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t readSize = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class to help creation of flash delete command.
|
* @brief Class to help creation of flash delete command.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user