Merge branch 'development' into gaisser_clock_leap_seconds_move

This commit is contained in:
Steffen Gaisser 2021-06-15 15:53:16 +02:00
commit b1f6252e30
7 changed files with 312 additions and 20 deletions

View File

@ -226,16 +226,15 @@ ReturnValue_t DeviceHandlerBase::initialize() {
}
void DeviceHandlerBase::decrementDeviceReplyMap() {
for (std::map<DeviceCommandId_t, DeviceReplyInfo>::iterator iter =
deviceReplyMap.begin(); iter != deviceReplyMap.end(); iter++) {
if (iter->second.delayCycles != 0) {
iter->second.delayCycles--;
if (iter->second.delayCycles == 0) {
if (iter->second.periodic) {
iter->second.delayCycles = iter->second.maxDelayCycles;
for (std::pair<const DeviceCommandId_t, DeviceReplyInfo>& replyPair: deviceReplyMap) {
if (replyPair.second.delayCycles != 0) {
replyPair.second.delayCycles--;
if (replyPair.second.delayCycles == 0) {
if (replyPair.second.periodic) {
replyPair.second.delayCycles = replyPair.second.maxDelayCycles;
}
replyToReply(iter, TIMEOUT);
missedReply(iter->first);
replyToReply(replyPair.first, replyPair.second, TIMEOUT);
missedReply(replyPair.first);
}
}
}
@ -584,17 +583,28 @@ void DeviceHandlerBase::replyToCommand(ReturnValue_t status,
}
}
void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter,
void DeviceHandlerBase::replyToReply(const DeviceCommandId_t command, DeviceReplyInfo& replyInfo,
ReturnValue_t status) {
// No need to check if iter exists, as this is checked by callers.
// If someone else uses the method, add check.
if (iter->second.command == deviceCommandMap.end()) {
if (replyInfo.command == deviceCommandMap.end()) {
//Is most likely periodic reply. Silent return.
return;
}
DeviceCommandInfo* info = &replyInfo.command->second;
if (info == nullptr){
printWarningOrError(sif::OutputTypes::OUT_ERROR,
"replyToReply", HasReturnvaluesIF::RETURN_FAILED,
"Command pointer not found");
return;
}
if (info->expectedReplies > 0){
// Check before to avoid underflow
info->expectedReplies--;
}
// Check if more replies are expected. If so, do nothing.
DeviceCommandInfo* info = &(iter->second.command->second);
if (--info->expectedReplies == 0) {
if (info->expectedReplies == 0) {
// Check if it was transition or internal command.
// Don't send any replies in that case.
if (info->sendReplyTo != NO_COMMANDER) {
@ -602,7 +612,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter,
if(status == HasReturnvaluesIF::RETURN_OK) {
success = true;
}
actionHelper.finish(success, info->sendReplyTo, iter->first, status);
actionHelper.finish(success, info->sendReplyTo, command, status);
}
info->isExecuting = false;
}
@ -801,7 +811,7 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
}
replyToReply(iter, result);
replyToReply(iter->first, iter->second, result);
}
else {
/* Other completion failure messages are created by timeout.

View File

@ -1195,7 +1195,8 @@ private:
* @foundLen the length of the packet
*/
void handleReply(const uint8_t *data, DeviceCommandId_t id, uint32_t foundLen);
void replyToReply(DeviceReplyMap::iterator iter, ReturnValue_t status);
void replyToReply(const DeviceCommandId_t command, DeviceReplyInfo& replyInfo,
ReturnValue_t status);
/**
* Build and send a command to the device.

View File

@ -1,5 +1,6 @@
#include "CommandMessageCleaner.h"
#include "../memory/GenericFileSystemMessage.h"
#include "../devicehandlers/DeviceHandlerMessage.h"
#include "../health/HealthMessage.h"
#include "../memory/MemoryMessage.h"
@ -42,6 +43,9 @@ void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) {
case messagetypes::HOUSEKEEPING:
HousekeepingMessage::clear(message);
break;
case messagetypes::FILE_SYSTEM_MESSAGE:
GenericFileSystemMessage::clear(message);
break;
default:
messagetypes::clearMissionMessage(message);
break;

View File

@ -1,5 +1,5 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
MemoryHelper.cpp
MemoryMessage.cpp
target_sources(${LIB_FSFW_NAME} PRIVATE
MemoryHelper.cpp
MemoryMessage.cpp
GenericFileSystemMessage.cpp
)

View File

@ -0,0 +1,161 @@
#include "GenericFileSystemMessage.h"
#include "../objectmanager/ObjectManager.h"
#include "../storagemanager/StorageManagerIF.h"
void GenericFileSystemMessage::setCreateFileCommand(CommandMessage* message,
store_address_t storeId) {
message->setCommand(CMD_CREATE_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setDeleteFileCommand(
CommandMessage* message, store_address_t storeId) {
message->setCommand(CMD_DELETE_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setCreateDirectoryCommand(
CommandMessage* message, store_address_t storeId) {
message->setCommand(CMD_CREATE_DIRECTORY);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setReportFileAttributesCommand(CommandMessage *message,
store_address_t storeId) {
message->setCommand(CMD_REPORT_FILE_ATTRIBUTES);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setReportFileAttributesReply(CommandMessage *message,
store_address_t storeId) {
message->setCommand(REPLY_REPORT_FILE_ATTRIBUTES);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setDeleteDirectoryCommand(CommandMessage* message,
store_address_t storeId) {
message->setCommand(CMD_DELETE_DIRECTORY);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setLockFileCommand(CommandMessage *message,
store_address_t storeId) {
message->setCommand(CMD_LOCK_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setUnlockFileCommand(CommandMessage *message,
store_address_t storeId) {
message->setCommand(CMD_UNLOCK_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setSuccessReply(CommandMessage *message) {
message->setCommand(COMPLETION_SUCCESS);
}
void GenericFileSystemMessage::setFailureReply(CommandMessage *message,
ReturnValue_t errorCode, uint32_t errorParam) {
message->setCommand(COMPLETION_FAILED);
message->setParameter(errorCode);
message->setParameter2(errorParam);
}
store_address_t GenericFileSystemMessage::getStoreId(const CommandMessage* message) {
store_address_t temp;
temp.raw = message->getParameter2();
return temp;
}
ReturnValue_t GenericFileSystemMessage::getFailureReply(
const CommandMessage *message, uint32_t* errorParam) {
if(errorParam != nullptr) {
*errorParam = message->getParameter2();
}
return message->getParameter();
}
void GenericFileSystemMessage::setFinishStopWriteCommand(CommandMessage *message,
store_address_t storeId) {
message->setCommand(CMD_FINISH_APPEND_TO_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setFinishStopWriteReply(CommandMessage *message,
store_address_t storeId) {
message->setCommand(REPLY_FINISH_APPEND);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setCopyCommand(CommandMessage* message,
store_address_t storeId) {
message->setCommand(CMD_COPY_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setWriteCommand(CommandMessage* message,
store_address_t storeId) {
message->setCommand(CMD_APPEND_TO_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setReadCommand(CommandMessage* message,
store_address_t storeId) {
message->setCommand(CMD_READ_FROM_FILE);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setFinishAppendReply(CommandMessage* message,
store_address_t storageID) {
message->setCommand(REPLY_FINISH_APPEND);
message->setParameter2(storageID.raw);
}
void GenericFileSystemMessage::setReadReply(CommandMessage* message,
bool readFinished, store_address_t storeId) {
message->setCommand(REPLY_READ_FROM_FILE);
message->setParameter(readFinished);
message->setParameter2(storeId.raw);
}
void GenericFileSystemMessage::setReadFinishedReply(CommandMessage *message,
store_address_t storeId) {
message->setCommand(REPLY_READ_FINISHED_STOP);
message->setParameter2(storeId.raw);
}
bool GenericFileSystemMessage::getReadReply(const CommandMessage *message,
store_address_t *storeId) {
if(storeId != nullptr) {
(*storeId).raw = message->getParameter2();
}
return message->getParameter();
}
ReturnValue_t GenericFileSystemMessage::clear(CommandMessage* message) {
switch(message->getCommand()) {
case(CMD_CREATE_FILE):
case(CMD_DELETE_FILE):
case(CMD_CREATE_DIRECTORY):
case(CMD_REPORT_FILE_ATTRIBUTES):
case(REPLY_REPORT_FILE_ATTRIBUTES):
case(CMD_LOCK_FILE):
case(CMD_UNLOCK_FILE):
case(CMD_COPY_FILE):
case(REPLY_READ_FROM_FILE):
case(CMD_READ_FROM_FILE):
case(CMD_APPEND_TO_FILE):
case(CMD_FINISH_APPEND_TO_FILE):
case(REPLY_READ_FINISHED_STOP):
case(REPLY_FINISH_APPEND): {
store_address_t storeId = GenericFileSystemMessage::getStoreId(message);
auto ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
if(ipcStore == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return ipcStore->deleteData(storeId);
}
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,115 @@
#ifndef MISSION_MEMORY_GENERICFILESYSTEMMESSAGE_H_
#define MISSION_MEMORY_GENERICFILESYSTEMMESSAGE_H_
#include <cstdint>
#include <fsfw/ipc/CommandMessageIF.h>
#include <fsfw/ipc/FwMessageTypes.h>
#include <fsfw/ipc/CommandMessage.h>
#include <fsfw/storagemanager/storeAddress.h>
/**
* @brief These messages are sent to an object implementing HasFilesystemIF.
* @details
* Enables a message-based file management. The user can add custo commands be implementing
* this generic class.
* @author Jakob Meier, R. Mueller
*/
class GenericFileSystemMessage {
public:
/* Instantiation forbidden */
GenericFileSystemMessage() = delete;
static const uint8_t MESSAGE_ID = messagetypes::FILE_SYSTEM_MESSAGE;
/* PUS standard (ECSS-E-ST-70-41C15 2016 p.654) */
static const Command_t CMD_CREATE_FILE = MAKE_COMMAND_ID(1);
static const Command_t CMD_DELETE_FILE = MAKE_COMMAND_ID(2);
/** Report file attributes */
static const Command_t CMD_REPORT_FILE_ATTRIBUTES = MAKE_COMMAND_ID(3);
static const Command_t REPLY_REPORT_FILE_ATTRIBUTES = MAKE_COMMAND_ID(4);
/** Command to lock a file, setting it read-only */
static const Command_t CMD_LOCK_FILE = MAKE_COMMAND_ID(5);
/** Command to unlock a file, enabling further operations on it */
static const Command_t CMD_UNLOCK_FILE = MAKE_COMMAND_ID(6);
/**
* Find file in repository, using a search pattern.
* Please note that * is the wildcard character.
* For example, when looking for all files which start with have the
* structure tm<something>.bin, tm*.bin can be used.
*/
static const Command_t CMD_FIND_FILE = MAKE_COMMAND_ID(7);
static const Command_t CMD_CREATE_DIRECTORY = MAKE_COMMAND_ID(9);
static const Command_t CMD_DELETE_DIRECTORY = MAKE_COMMAND_ID(10);
static const Command_t CMD_RENAME_DIRECTORY = MAKE_COMMAND_ID(11);
/** Dump contents of a repository */
static const Command_t CMD_DUMP_REPOSITORY = MAKE_COMMAND_ID(12);
/** Repository dump reply */
static const Command_t REPLY_DUMY_REPOSITORY = MAKE_COMMAND_ID(13);
static constexpr Command_t CMD_COPY_FILE = MAKE_COMMAND_ID(14);
static constexpr Command_t CMD_MOVE_FILE = MAKE_COMMAND_ID(15);
static const Command_t COMPLETION_SUCCESS = MAKE_COMMAND_ID(128);
static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(129);
// These command IDs will remain until CFDP has been introduced and consolidated.
/** Append operation commands */
static const Command_t CMD_APPEND_TO_FILE = MAKE_COMMAND_ID(130);
static const Command_t CMD_FINISH_APPEND_TO_FILE = MAKE_COMMAND_ID(131);
static const Command_t REPLY_FINISH_APPEND = MAKE_COMMAND_ID(132);
static const Command_t CMD_READ_FROM_FILE = MAKE_COMMAND_ID(140);
static const Command_t REPLY_READ_FROM_FILE = MAKE_COMMAND_ID(141);
static const Command_t CMD_STOP_READ = MAKE_COMMAND_ID(142);
static const Command_t REPLY_READ_FINISHED_STOP = MAKE_COMMAND_ID(143);
static void setLockFileCommand(CommandMessage* message, store_address_t storeId);
static void setUnlockFileCommand(CommandMessage* message, store_address_t storeId);
static void setCreateFileCommand(CommandMessage* message,
store_address_t storeId);
static void setDeleteFileCommand(CommandMessage* message,
store_address_t storeId);
static void setReportFileAttributesCommand(CommandMessage* message,
store_address_t storeId);
static void setReportFileAttributesReply(CommandMessage* message,
store_address_t storeId);
static void setCreateDirectoryCommand(CommandMessage* message,
store_address_t storeId);
static void setDeleteDirectoryCommand(CommandMessage* message,
store_address_t storeId);
static void setSuccessReply(CommandMessage* message);
static void setFailureReply(CommandMessage* message,
ReturnValue_t errorCode, uint32_t errorParam = 0);
static void setCopyCommand(CommandMessage* message, store_address_t storeId);
static void setWriteCommand(CommandMessage* message,
store_address_t storeId);
static void setFinishStopWriteCommand(CommandMessage* message,
store_address_t storeId);
static void setFinishStopWriteReply(CommandMessage* message,
store_address_t storeId);
static void setFinishAppendReply(CommandMessage* message,
store_address_t storeId);
static void setReadCommand(CommandMessage* message,
store_address_t storeId);
static void setReadFinishedReply(CommandMessage* message,
store_address_t storeId);
static void setReadReply(CommandMessage* message, bool readFinished,
store_address_t storeId);
static bool getReadReply(const CommandMessage* message,
store_address_t* storeId);
static store_address_t getStoreId(const CommandMessage* message);
static ReturnValue_t getFailureReply(const CommandMessage* message,
uint32_t* errorParam = nullptr);
static ReturnValue_t clear(CommandMessage* message);
};
#endif /* MISSION_MEMORY_GENERICFILESYSTEMMESSAGE_H_ */

View File

@ -75,6 +75,7 @@ enum: uint8_t {
HAL_SPI, //HSPI
HAL_UART, //HURT
HAL_I2C, //HI2C
HAL_GPIO, //HGIO
FW_CLASS_ID_COUNT // [EXPORT] : [END]
};