this should do the job

This commit is contained in:
Robin Müller 2023-05-11 20:21:44 +02:00
parent 71ef1edb68
commit f72c797f53
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
7 changed files with 77 additions and 35 deletions

View File

@ -36,6 +36,8 @@ will consitute of a breaking change warranting a new major release:
- Add support for MPSoC HK packet.
- Dynamically enable and disable HK packets for MPSoC on `ON` and `OFF` commands.
- Add support for MPSoC Flash Directory Content Report.
- Larger allowed path and file sizes for STR and PLOC MPSoC modules.
- More robust MPSoC flash read and write command data handling.
## Added

View File

@ -34,8 +34,8 @@ static constexpr uint32_t STR_IMG_HELPER_QUEUE_SIZE = 50;
static constexpr uint8_t LIVE_TM = 0;
/* Limits for filename and path checks */
static constexpr uint32_t MAX_PATH_SIZE = 100;
static constexpr uint32_t MAX_FILENAME_SIZE = 50;
static constexpr uint32_t MAX_PATH_SIZE = 200;
static constexpr uint32_t MAX_FILENAME_SIZE = 100;
static constexpr uint32_t SA_DEPL_INIT_BUFFER_SECS = 120;
// Burn time for autonomous deployment

View File

@ -125,10 +125,7 @@ ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueI
switch (actionId) {
case mpsoc::TC_FLASH_WRITE_FULL_FILE: {
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return MPSoCReturnValuesIF::FILENAME_TOO_LONG;
}
mpsoc::FlashWritePusCmd flashWritePusCmd;
mpsoc::FlashBasePusCmd flashWritePusCmd;
result = flashWritePusCmd.extractFields(data, size);
if (result != returnvalue::OK) {
return result;
@ -142,7 +139,19 @@ ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueI
return EXECUTION_FINISHED;
}
case mpsoc::TC_FLASH_READ_FULL_FILE: {
// TODO: Finsh this.
mpsoc::FlashReadPusCmd flashReadPusCmd;
result = flashReadPusCmd.extractFields(data, size);
if (result != returnvalue::OK) {
return result;
}
result = plocMPSoCHelper->startFlashRead(flashReadPusCmd.getObcFile(),
flashReadPusCmd.getMPSoCFile(),
flashReadPusCmd.getReadSize());
if (result != returnvalue::OK) {
return result;
}
plocMPSoCHelperExecuting = true;
return EXECUTION_FINISHED;
break;
}
case (mpsoc::OBSW_RESET_SEQ_COUNT): {

View File

@ -84,7 +84,7 @@ void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) {
}
ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string mpsocFile) {
ReturnValue_t result = startFlashReadOrWriteBase(obcFile, mpsocFile);
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
if (result != returnvalue::OK) {
return result;
}
@ -94,7 +94,7 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string
ReturnValue_t PlocMPSoCHelper::startFlashRead(std::string obcFile, std::string mpsocFile,
size_t readFileSize) {
ReturnValue_t result = startFlashReadOrWriteBase(obcFile, mpsocFile);
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
if (result != returnvalue::OK) {
return result;
}
@ -437,8 +437,8 @@ ReturnValue_t PlocMPSoCHelper::startFlashReadOrWriteBase(std::string obcFile,
return result;
}
flashReadAndWrite.obcFile = obcFile;
flashReadAndWrite.mpsocFile = mpsocFile;
flashReadAndWrite.obcFile = std::move(obcFile);
flashReadAndWrite.mpsocFile = std::move(mpsocFile);
return resetHelper();
}

View File

@ -736,36 +736,69 @@ class TcReplayWriteSeq : public TcBase {
/**
* @brief Helps to extract the fields of the flash write command from the PUS packet.
*/
class FlashWritePusCmd : public MPSoCReturnValuesIF {
class FlashBasePusCmd : public MPSoCReturnValuesIF {
public:
FlashWritePusCmd(){};
FlashBasePusCmd() = default;
virtual ~FlashBasePusCmd() = default;
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) {
virtual 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)) {
size_t fileLen = strnlen(reinterpret_cast<const char*>(commandData), commandDataLen);
if (fileLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) {
return FILENAME_TOO_LONG;
}
mpsocFile = std::string(
reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR));
if (mpsocFile.size() > MAX_FILENAME_SIZE) {
obcFile = std::string(reinterpret_cast<const char*>(commandData), fileLen);
fileLen =
strnlen(reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR),
commandDataLen - obcFile.size() - 1);
if (fileLen > MAX_FILENAME_SIZE) {
return MPSOC_FILENAME_TOO_LONG;
}
mpsocFile = std::string(
reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR),
fileLen);
return returnvalue::OK;
}
std::string getObcFile() { return obcFile; }
const std::string& getObcFile() const { return obcFile; }
std::string getMPSoCFile() { return mpsocFile; }
const std::string& getMPSoCFile() const { return mpsocFile; }
protected:
size_t getParsedSize() const {
return getObcFile().size() + getMPSoCFile().size() + 2 * SIZE_NULL_TERMINATOR;
}
static const size_t SIZE_NULL_TERMINATOR = 1;
private:
static const size_t SIZE_NULL_TERMINATOR = 1;
std::string obcFile = "";
std::string mpsocFile = "";
std::string obcFile;
std::string mpsocFile;
};
class FlashReadPusCmd : public FlashBasePusCmd {
public:
FlashReadPusCmd(){};
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) override {
ReturnValue_t result = FlashBasePusCmd::extractFields(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
if (commandDataLen < (getParsedSize() + 4)) {
return returnvalue::FAILED;
}
size_t deserDummy = 4;
return SerializeAdapter::deSerialize(&readSize, commandData + getParsedSize(), &deserDummy,
SerializeIF::Endianness::NETWORK);
}
size_t getReadSize() const { return readSize; }
private:
size_t readSize = 0;
};
/**
* @brief Class to build replay stop space packet.
*/

View File

@ -17,6 +17,7 @@ extern "C" {
#include <thread>
#include "OBSWConfig.h"
#include "eive/definitions.h"
std::atomic_bool JCFG_DONE(false);
@ -152,7 +153,7 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
return EXECUTION_FINISHED;
}
case (startracker::SET_JSON_FILE_NAME): {
if (size > MAX_PATH_SIZE) {
if (size > config::MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
paramJsonFile = std::string(reinterpret_cast<const char*>(data), size);
@ -189,7 +190,7 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (result != returnvalue::OK) {
return result;
}
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return FILE_PATH_TOO_LONG;
}
result = strHelper->startImageUpload(std::string(reinterpret_cast<const char*>(data), size));
@ -204,7 +205,7 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (result != returnvalue::OK) {
return result;
}
if (size > MAX_PATH_SIZE) {
if (size > config::MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
result =
@ -228,14 +229,14 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
return EXECUTION_FINISHED;
}
case (startracker::CHANGE_IMAGE_DOWNLOAD_FILE): {
if (size > MAX_FILE_NAME) {
if (size > config::MAX_FILENAME_SIZE) {
return FILENAME_TOO_LONG;
}
strHelper->setDownloadImageName(std::string(reinterpret_cast<const char*>(data), size));
return EXECUTION_FINISHED;
}
case (startracker::SET_FLASH_READ_FILENAME): {
if (size > MAX_FILE_NAME) {
if (size > config::MAX_FILENAME_SIZE) {
return FILENAME_TOO_LONG;
}
strHelper->setFlashReadFilename(std::string(reinterpret_cast<const char*>(data), size));
@ -246,7 +247,7 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (result != returnvalue::OK) {
return result;
}
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return FILE_PATH_TOO_LONG;
}
result =
@ -1568,7 +1569,7 @@ ReturnValue_t StarTrackerHandler::executeFlashReadCommand(const uint8_t* command
<< std::endl;
return result;
}
if (commandDataLen - sizeof(startRegion) - sizeof(length) > MAX_PATH_SIZE) {
if (commandDataLen - sizeof(startRegion) - sizeof(length) > config::MAX_PATH_SIZE) {
sif::warning << "StarTrackerHandler::executeFlashReadCommand: Received command with invalid"
<< " path and filename" << std::endl;
return FILE_PATH_TOO_LONG;
@ -1708,7 +1709,7 @@ ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData
bool reinitSet) {
// Stopwatch watch;
ReturnValue_t result = returnvalue::OK;
if (commandDataLen > MAX_PATH_SIZE) {
if (commandDataLen > config::MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
if (reinitSet) {

View File

@ -144,9 +144,6 @@ class StarTrackerHandler : public DeviceHandlerBase {
//! [EXPORT] : [COMMENT] Failed to boot star tracker into bootloader mode
static const Event BOOTING_BOOTLOADER_FAILED_EVENT = MAKE_EVENT(2, severity::LOW);
static const size_t MAX_PATH_SIZE = 50;
static const size_t MAX_FILE_NAME = 30;
static const uint8_t STATUS_OFFSET = 2;
static const uint8_t PARAMS_OFFSET = 2;
static const uint8_t TICKS_OFFSET = 3;