chonky #670
@ -128,7 +128,7 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashWrite() {
|
|||||||
if (file.bad()) {
|
if (file.bad()) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
result = flashfopen(mpsoc::FileAccessMode::WRITE);
|
result = flashfopen(mpsoc::FileAccessModes::WRITE | mpsoc::FileAccessModes::OPEN_ALWAYS);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -142,8 +142,9 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashWrite() {
|
|||||||
if (terminate) {
|
if (terminate) {
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
if (remainingSize > mpsoc::SP_MAX_DATA_SIZE) {
|
// The minus 4 is necessary for unknown reasons. Maybe some bug in the ILH software?
|
||||||
dataLength = mpsoc::SP_MAX_DATA_SIZE;
|
if (remainingSize > mpsoc::MAX_FLASH_WRITE_DATA_SIZE - 4) {
|
||||||
|
dataLength = mpsoc::MAX_FLASH_WRITE_DATA_SIZE - 4;
|
||||||
} else {
|
} else {
|
||||||
dataLength = remainingSize;
|
dataLength = remainingSize;
|
||||||
}
|
}
|
||||||
@ -177,13 +178,12 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashWrite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() {
|
ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() {
|
||||||
sif::debug << "performing flash read" << std::endl;
|
|
||||||
std::error_code e;
|
std::error_code e;
|
||||||
std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::trunc | std::ios::binary);
|
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(mpsoc::FileAccessMode::READ);
|
ReturnValue_t result = flashfopen(mpsoc::FileAccessModes::READ);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
return result;
|
return result;
|
||||||
@ -199,7 +199,6 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() {
|
|||||||
if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) {
|
if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) {
|
||||||
nextReadSize = flashReadAndWrite.totalReadSize - readSoFar;
|
nextReadSize = flashReadAndWrite.totalReadSize - readSoFar;
|
||||||
}
|
}
|
||||||
sif::debug << "reading " << nextReadSize << " bytes from offset " << readSoFar << std::endl;
|
|
||||||
if (ofile.bad() or not ofile.is_open()) {
|
if (ofile.bad() or not ofile.is_open()) {
|
||||||
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
std::filesystem::remove(flashReadAndWrite.obcFile, e);
|
||||||
return FILE_READ_ERROR;
|
return FILE_READ_ERROR;
|
||||||
@ -227,11 +226,10 @@ ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() {
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
sif::debug << "read file done" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocMpsocSpecialComHelper::flashfopen(mpsoc::FileAccessMode mode) {
|
ReturnValue_t PlocMpsocSpecialComHelper::flashfopen(uint8_t mode) {
|
||||||
spParams.buf = commandBuffer;
|
spParams.buf = commandBuffer;
|
||||||
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
|
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
|
||||||
ReturnValue_t result = flashFopen.setPayload(flashReadAndWrite.mpsocFile, mode);
|
ReturnValue_t result = flashFopen.setPayload(flashReadAndWrite.mpsocFile, mode);
|
||||||
@ -314,8 +312,6 @@ ReturnValue_t PlocMpsocSpecialComHelper::handlePacketTransmissionNoReply(ploc::S
|
|||||||
|
|
||||||
ReturnValue_t PlocMpsocSpecialComHelper::sendCommand(ploc::SpTcBase& tc) {
|
ReturnValue_t PlocMpsocSpecialComHelper::sendCommand(ploc::SpTcBase& tc) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = returnvalue::OK;
|
||||||
sif::debug << "sending TC" << std::endl;
|
|
||||||
arrayprinter::print(tc.getFullPacket(), tc.getFullPacketLen());
|
|
||||||
result = uartComIF->sendMessage(comCookie, tc.getFullPacket(), tc.getFullPacketLen());
|
result = uartComIF->sendMessage(comCookie, tc.getFullPacket(), tc.getFullPacketLen());
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
|
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
|
||||||
@ -412,7 +408,6 @@ ReturnValue_t PlocMpsocSpecialComHelper::handleTmReception() {
|
|||||||
usleepDelay *= 4;
|
usleepDelay *= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sif::debug << "recvd first 6 bytes" << std::endl;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (tmCountdown.hasTimedOut()) {
|
if (tmCountdown.hasTimedOut()) {
|
||||||
triggerEvent(MPSOC_READ_TIMEOUT, tmCountdown.getTimeoutMs());
|
triggerEvent(MPSOC_READ_TIMEOUT, tmCountdown.getTimeoutMs());
|
||||||
@ -421,7 +416,6 @@ ReturnValue_t PlocMpsocSpecialComHelper::handleTmReception() {
|
|||||||
result = receive(tmBuf.data() + readBytes, fullPacketLen - readBytes, ¤tBytes);
|
result = receive(tmBuf.data() + readBytes, fullPacketLen - readBytes, ¤tBytes);
|
||||||
readBytes += currentBytes;
|
readBytes += currentBytes;
|
||||||
if (fullPacketLen == readBytes) {
|
if (fullPacketLen == readBytes) {
|
||||||
// sif::debug << "recvd full " << fullPacketLen << std::endl;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
usleep(usleepDelay);
|
usleep(usleepDelay);
|
||||||
@ -429,7 +423,7 @@ ReturnValue_t PlocMpsocSpecialComHelper::handleTmReception() {
|
|||||||
usleepDelay *= 4;
|
usleepDelay *= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arrayprinter::print(tmBuf.data(), readBytes);
|
// arrayprinter::print(tmBuf.data(), readBytes);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +442,7 @@ ReturnValue_t PlocMpsocSpecialComHelper::handleFlashReadReply(std::ofstream& ofi
|
|||||||
const uint8_t* packetData = spReader.getPacketData();
|
const uint8_t* packetData = spReader.getPacketData();
|
||||||
size_t deserDummy = spReader.getPacketDataLen() - mpsoc::CRC_SIZE;
|
size_t deserDummy = spReader.getPacketDataLen() - mpsoc::CRC_SIZE;
|
||||||
uint32_t receivedReadLen = 0;
|
uint32_t receivedReadLen = 0;
|
||||||
// I think this is buggy..
|
// I think this is buggy, weird stuff in the short name field.
|
||||||
// std::string receivedShortName = std::string(reinterpret_cast<const char*>(packetData), 12);
|
// std::string receivedShortName = std::string(reinterpret_cast<const char*>(packetData), 12);
|
||||||
// if (receivedShortName != flashReadAndWrite.mpsocFile.substr(0, 11)) {
|
// if (receivedShortName != flashReadAndWrite.mpsocFile.substr(0, 11)) {
|
||||||
// sif::warning << "PLOC MPSoC Flash Read: Missmatch between request file name and "
|
// sif::warning << "PLOC MPSoC Flash Read: Missmatch between request file name and "
|
||||||
|
@ -179,7 +179,7 @@ class PlocMpsocSpecialComHelper : public SystemObject, public ExecutableObjectIF
|
|||||||
void resetHelper();
|
void resetHelper();
|
||||||
ReturnValue_t performFlashWrite();
|
ReturnValue_t performFlashWrite();
|
||||||
ReturnValue_t performFlashRead();
|
ReturnValue_t performFlashRead();
|
||||||
ReturnValue_t flashfopen(mpsoc::FileAccessMode mode);
|
ReturnValue_t flashfopen(uint8_t accessMode);
|
||||||
ReturnValue_t flashfclose();
|
ReturnValue_t flashfclose();
|
||||||
ReturnValue_t handlePacketTransmissionNoReply(ploc::SpTcBase& tc);
|
ReturnValue_t handlePacketTransmissionNoReply(ploc::SpTcBase& tc);
|
||||||
ReturnValue_t handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc, std::ofstream& ofile,
|
ReturnValue_t handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc, std::ofstream& ofile,
|
||||||
|
@ -33,6 +33,10 @@ std::string mpsoc::getStatusString(uint16_t status) {
|
|||||||
return "Flash mount failed";
|
return "Flash mount failed";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case (mpsoc::status_code::FLASH_FILE_ALREADY_OPEN): {
|
||||||
|
return "Flash file already open";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case (mpsoc::status_code::FLASH_FILE_ALREADY_CLOSED): {
|
case (mpsoc::status_code::FLASH_FILE_ALREADY_CLOSED): {
|
||||||
return "Flash file already closed";
|
return "Flash file already closed";
|
||||||
break;
|
break;
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
|
|
||||||
namespace mpsoc {
|
namespace mpsoc {
|
||||||
|
|
||||||
enum FileAccessMode : uint8_t {
|
enum FileAccessModes : uint8_t {
|
||||||
|
// Opens a file, fails if the file does not exist.
|
||||||
OPEN_EXISTING = 0x00,
|
OPEN_EXISTING = 0x00,
|
||||||
READ = 0x01,
|
READ = 0x01,
|
||||||
WRITE = 0x02,
|
WRITE = 0x02,
|
||||||
|
// Creates a new file, fails if it already exists.
|
||||||
CREATE_NEW = 0x04,
|
CREATE_NEW = 0x04,
|
||||||
|
// Creates a new file, existing file is truncated and overwritten.
|
||||||
CREATE_ALWAYS = 0x08,
|
CREATE_ALWAYS = 0x08,
|
||||||
|
// Opens the file if it is existing. If not, a new file is created.
|
||||||
OPEN_ALWAYS = 0x10,
|
OPEN_ALWAYS = 0x10,
|
||||||
OPEN_APPEND = 0x30
|
OPEN_APPEND = 0x30
|
||||||
};
|
};
|
||||||
@ -182,6 +186,8 @@ static constexpr size_t SP_MAX_DATA_SIZE = SP_MAX_SIZE - ccsds::HEADER_LEN - CRC
|
|||||||
static constexpr size_t FLASH_READ_MIN_OVERHEAD = 16;
|
static constexpr size_t FLASH_READ_MIN_OVERHEAD = 16;
|
||||||
// 1000 bytes.
|
// 1000 bytes.
|
||||||
static const size_t MAX_FLASH_READ_DATA_SIZE = SP_MAX_DATA_SIZE - FLASH_READ_MIN_OVERHEAD;
|
static const size_t MAX_FLASH_READ_DATA_SIZE = SP_MAX_DATA_SIZE - FLASH_READ_MIN_OVERHEAD;
|
||||||
|
// 1012 bytes, 4 bytes for the write length.
|
||||||
|
static constexpr size_t MAX_FLASH_WRITE_DATA_SIZE = SP_MAX_DATA_SIZE - sizeof(uint32_t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -204,7 +210,7 @@ static const uint16_t TC_EXEUTION_DISABLED = 0x5E2;
|
|||||||
static const uint16_t FLASH_MOUNT_FAILED = 0x5E3;
|
static const uint16_t FLASH_MOUNT_FAILED = 0x5E3;
|
||||||
static const uint16_t FLASH_FILE_ALREADY_CLOSED = 0x5E4;
|
static const uint16_t FLASH_FILE_ALREADY_CLOSED = 0x5E4;
|
||||||
static const uint16_t FLASH_FILE_OPEN_FAILED = 0x5E5;
|
static const uint16_t FLASH_FILE_OPEN_FAILED = 0x5E5;
|
||||||
static const uint16_t FLASH_FILE_ALREDY_OPEN = 0x5E6;
|
static const uint16_t FLASH_FILE_ALREADY_OPEN = 0x5E6;
|
||||||
static const uint16_t FLASH_FILE_NOT_OPEN = 0x5E7;
|
static const uint16_t FLASH_FILE_NOT_OPEN = 0x5E7;
|
||||||
static const uint16_t FLASH_UNMOUNT_FAILED = 0x5E8;
|
static const uint16_t FLASH_UNMOUNT_FAILED = 0x5E8;
|
||||||
static const uint16_t HEAP_ALLOCATION_FAILED = 0x5E9;
|
static const uint16_t HEAP_ALLOCATION_FAILED = 0x5E9;
|
||||||
@ -366,7 +372,7 @@ class FlashFopen : public TcBase {
|
|||||||
FlashFopen(ploc::SpTcParams params, uint16_t sequenceCount)
|
FlashFopen(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||||
: TcBase(params, apid::TC_FLASHFOPEN, sequenceCount) {}
|
: TcBase(params, apid::TC_FLASHFOPEN, sequenceCount) {}
|
||||||
|
|
||||||
ReturnValue_t setPayload(std::string filename, FileAccessMode mode) {
|
ReturnValue_t setPayload(std::string filename, uint8_t mode) {
|
||||||
accessMode = mode;
|
accessMode = mode;
|
||||||
size_t nameSize = filename.size();
|
size_t nameSize = filename.size();
|
||||||
spParams.setFullPayloadLen(256 + sizeof(uint8_t) + CRC_SIZE);
|
spParams.setFullPayloadLen(256 + sizeof(uint8_t) + CRC_SIZE);
|
||||||
@ -378,12 +384,12 @@ class FlashFopen : public TcBase {
|
|||||||
// payloadStart[nameSize] = NULL_TERMINATOR;
|
// payloadStart[nameSize] = NULL_TERMINATOR;
|
||||||
std::memset(payloadStart + nameSize, 0, 256 - nameSize);
|
std::memset(payloadStart + nameSize, 0, 256 - nameSize);
|
||||||
// payloadStart[255] = NULL_TERMINATOR;
|
// payloadStart[255] = NULL_TERMINATOR;
|
||||||
payloadStart[256] = static_cast<uint8_t>(accessMode);
|
payloadStart[256] = accessMode;
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileAccessMode accessMode = FileAccessMode::OPEN_EXISTING;
|
uint8_t accessMode = FileAccessModes::OPEN_EXISTING;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,14 +412,13 @@ class TcFlashWrite : public TcBase {
|
|||||||
: TcBase(params, apid::TC_FLASHWRITE, sequenceCount) {}
|
: TcBase(params, apid::TC_FLASHWRITE, sequenceCount) {}
|
||||||
|
|
||||||
ReturnValue_t setPayload(const uint8_t* writeData, uint32_t writeLen_) {
|
ReturnValue_t setPayload(const uint8_t* writeData, uint32_t writeLen_) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
|
||||||
writeLen = writeLen_;
|
writeLen = writeLen_;
|
||||||
if (writeLen > SP_MAX_DATA_SIZE) {
|
if (writeLen > MAX_FLASH_WRITE_DATA_SIZE) {
|
||||||
sif::error << "TcFlashWrite: 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(sizeof(uint32_t) + static_cast<uint16_t>(writeLen) + CRC_SIZE);
|
||||||
result = checkPayloadLen();
|
ReturnValue_t result = checkPayloadLen();
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -423,7 +428,7 @@ class TcFlashWrite : public TcBase {
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
std::memcpy(payloadStart + sizeof(writeLen), writeData, writeLen);
|
std::memcpy(payloadStart + sizeof(uint32_t), writeData, writeLen);
|
||||||
updateSpFields();
|
updateSpFields();
|
||||||
result = checkSizeAndSerializeHeader();
|
result = checkSizeAndSerializeHeader();
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
|
Loading…
Reference in New Issue
Block a user