added command to list directory into file
This commit is contained in:
@ -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,
|
||||
SdCardManager::SdStatusPair& statusPair) {
|
||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||
|
Reference in New Issue
Block a user