added command to list directory into file

This commit is contained in:
Robin Müller 2021-07-19 20:06:28 +02:00 committed by Robin Mueller
parent 81ac5a3b2c
commit 5c01401042
3 changed files with 59 additions and 1 deletions

View File

@ -724,7 +724,7 @@ EIVE implementation
### SD Cards ### SD Cards
- Folder `bin` for binaries, for example the OBSW - Folder `bin` for binaries, for example the OBSW
- Folder `misc` for miscellaneous files - Folder `misc` for miscellaneous files. Contains `ls` for directory listings
- Folder `tc` for telecommands - Folder `tc` for telecommands
- Folder `tm` for telemetry - Folder `tm` for telemetry
- Folder `xdi` for XDI components (e.g. for firmware or device tree updates) - Folder `xdi` for XDI components (e.g. for firmware or device tree updates)

View File

@ -109,6 +109,59 @@ ReturnValue_t CoreController::sdCardSetup(SdCardManager& sdcMan,
} }
} }
ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t *data, size_t size) {
switch(actionId) {
case(LIST_DIRECTORY_INTO_FILE): {
// TODO: Packet definition for clean deserialization
// Two bytes for a and R flag, at least 5 bytes for minimum valid path /tmp with
// null termination
if(size < 7) {
return HasActionsIF::INVALID_PARAMETERS;
}
// This flag specifies to run ls with -a
bool aFlag = data[0];
data += 1;
// This flag specifies to run ls with -R
bool RFlag = data[1];
data += 1;
size_t remainingSize = size - 2;
// One larger for null termination, which prevents undefined behaviour if the sent
// string is not 0 terminated
std::vector<uint8_t> repoAndTargetFileBuffer(remainingSize + 1, 0);
std::memcpy(repoAndTargetFileBuffer.data(), data, remainingSize);
const char* currentCharPtr = reinterpret_cast<const char*>(repoAndTargetFileBuffer.data());
// Full target file name
std::string repoName(currentCharPtr);
size_t repoLength = repoName.length();
// The other string needs to be at least one letter plus NULL termination to be valid at all
// The first string also needs to be NULL terminated, but the termination is not included
// in the string length, so this is subtracted from the remaining size as well
if(repoLength > remainingSize - 3) {
return HasActionsIF::INVALID_PARAMETERS;
}
// The file length will not include the NULL termination, so we skip it
currentCharPtr += repoLength + 1;
std::string targetFileName(currentCharPtr);
std::ostringstream oss;
oss << "ls -l";
if(aFlag) {
oss << "a";
}
if(RFlag) {
oss << "R";
}
oss << " " << repoName << " > " << targetFileName;
std::system(oss.str().c_str());
return HasReturnvaluesIF::RETURN_OK;
}
default: {
return HasActionsIF::INVALID_ACTION_ID;
}
}
}
ReturnValue_t CoreController::sdCardColdRedundantInit(SdCardManager* sdcMan, ReturnValue_t CoreController::sdCardColdRedundantInit(SdCardManager* sdcMan,
SdCardManager::SdStatusPair& statusPair) { SdCardManager::SdStatusPair& statusPair) {
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0; sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;

View File

@ -8,6 +8,8 @@
class CoreController: public ExtendedControllerBase { class CoreController: public ExtendedControllerBase {
public: public:
static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0;
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CORE; static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CORE;
static constexpr Event ALLOC_FAILURE = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM); static constexpr Event ALLOC_FAILURE = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM);
@ -16,6 +18,9 @@ public:
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t *data, size_t size) override;
ReturnValue_t handleCommandMessage(CommandMessage *message) override; ReturnValue_t handleCommandMessage(CommandMessage *message) override;
void performControlOperation() override; void performControlOperation() override;