trying to fuse header / inc
This commit is contained in:
14
src/fsfw/memory/AcceptsMemoryMessagesIF.h
Normal file
14
src/fsfw/memory/AcceptsMemoryMessagesIF.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef FSFW_MEMORY_ACCEPTSMEMORYMESSAGESIF_H_
|
||||
#define FSFW_MEMORY_ACCEPTSMEMORYMESSAGESIF_H_
|
||||
|
||||
#include "HasMemoryIF.h"
|
||||
#include "MemoryMessage.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class AcceptsMemoryMessagesIF : public HasMemoryIF {
|
||||
public:
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_MEMORY_ACCEPTSMEMORYMESSAGESIF_H_ */
|
5
src/fsfw/memory/CMakeLists.txt
Normal file
5
src/fsfw/memory/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
MemoryHelper.cpp
|
||||
MemoryMessage.cpp
|
||||
GenericFileSystemMessage.cpp
|
||||
)
|
168
src/fsfw/memory/GenericFileSystemMessage.cpp
Normal file
168
src/fsfw/memory/GenericFileSystemMessage.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
#include "fsfw/memory/GenericFileSystemMessage.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/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, bool deleteRecursively) {
|
||||
message->setCommand(CMD_DELETE_DIRECTORY);
|
||||
message->setParameter(deleteRecursively);
|
||||
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();
|
||||
}
|
||||
|
||||
store_address_t GenericFileSystemMessage::getDeleteDirectoryCommand(const CommandMessage *message,
|
||||
bool &deleteRecursively) {
|
||||
deleteRecursively = message->getParameter();
|
||||
return getStoreId(message);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
117
src/fsfw/memory/GenericFileSystemMessage.h
Normal file
117
src/fsfw/memory/GenericFileSystemMessage.h
Normal file
@ -0,0 +1,117 @@
|
||||
#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, bool deleteRecursively);
|
||||
static store_address_t getDeleteDirectoryCommand(const CommandMessage* message,
|
||||
bool& deleteRecursively);
|
||||
|
||||
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_ */
|
105
src/fsfw/memory/HasFileSystemIF.h
Normal file
105
src/fsfw/memory/HasFileSystemIF.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../returnvalues/FwClassIds.h"
|
||||
#include "../ipc/messageQueueDefinitions.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Generic interface for objects which expose a file system to enable
|
||||
* message based file handling.
|
||||
* @author J. Meier, R. Mueller
|
||||
*/
|
||||
class HasFileSystemIF {
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::FILE_SYSTEM;
|
||||
|
||||
//! [EXPORT] : P1: Can be file system specific error code
|
||||
static constexpr ReturnValue_t GENERIC_FILE_ERROR = MAKE_RETURN_CODE(0);
|
||||
//! [EXPORT] : File system is currently busy
|
||||
static constexpr ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1);
|
||||
//! [EXPORT] : Invalid parameters like file name or repository path
|
||||
static constexpr ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2);
|
||||
|
||||
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(5);
|
||||
static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(6);
|
||||
static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(7);
|
||||
|
||||
static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(10);
|
||||
static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(11);
|
||||
static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(12);
|
||||
|
||||
//! [EXPORT] : P1: Sequence number missing
|
||||
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(15);
|
||||
//! [EXPORT] : P1: Sequence number missing
|
||||
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16);
|
||||
|
||||
virtual ~HasFileSystemIF() {}
|
||||
|
||||
/**
|
||||
* Function to get the MessageQueueId_t of the implementing object
|
||||
* @return MessageQueueId_t of the object
|
||||
*/
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to append to file.
|
||||
* @param dirname Directory of the file
|
||||
* @param filename The filename of the file
|
||||
* @param data The data to write to the file
|
||||
* @param size The size of the data to write
|
||||
* @param packetNumber Current packet number. Can be used to verify that
|
||||
* there are no missing packets.
|
||||
* @param args Any other arguments which an implementation might require.
|
||||
* @param bytesWritten Actual bytes written to file
|
||||
* For large files the write procedure must be split in multiple calls
|
||||
* to writeToFile
|
||||
*/
|
||||
virtual ReturnValue_t appendToFile(const char* repositoryPath,
|
||||
const char* filename, const uint8_t* data, size_t size,
|
||||
uint16_t packetNumber, void* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a new file.
|
||||
* @param repositoryPath
|
||||
* @param filename
|
||||
* @param data
|
||||
* @param size
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t createFile(const char* repositoryPath,
|
||||
const char* filename, const uint8_t* data = nullptr,
|
||||
size_t size = 0, void* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to delete a file.
|
||||
* @param repositoryPath
|
||||
* @param filename
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t deleteFile(const char* repositoryPath,
|
||||
const char* filename, void* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a directory
|
||||
* @param repositoryPath
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to remove a directory
|
||||
* @param repositoryPath
|
||||
* @param args Any other arguments which an implementation might require
|
||||
*/
|
||||
virtual ReturnValue_t removeDirectory(const char* repositoryPath,
|
||||
bool deleteRecurively = false, void* args = nullptr) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */
|
47
src/fsfw/memory/HasMemoryIF.h
Normal file
47
src/fsfw/memory/HasMemoryIF.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef HASMEMORYIF_H_
|
||||
#define HASMEMORYIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class HasMemoryIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_MEMORY_IF;
|
||||
static const ReturnValue_t DO_IT_MYSELF = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t POINTS_TO_VARIABLE = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t POINTS_TO_MEMORY = MAKE_RETURN_CODE(3);
|
||||
static const ReturnValue_t ACTIVITY_COMPLETED = MAKE_RETURN_CODE(4);
|
||||
static const ReturnValue_t POINTS_TO_VECTOR_UINT8 = MAKE_RETURN_CODE(5);
|
||||
static const ReturnValue_t POINTS_TO_VECTOR_UINT16 = MAKE_RETURN_CODE(6);
|
||||
static const ReturnValue_t POINTS_TO_VECTOR_UINT32 = MAKE_RETURN_CODE(7);
|
||||
static const ReturnValue_t POINTS_TO_VECTOR_FLOAT = MAKE_RETURN_CODE(8);
|
||||
static const ReturnValue_t DUMP_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA0);
|
||||
static const ReturnValue_t INVALID_SIZE = MAKE_RETURN_CODE(0xE0);
|
||||
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0xE1);
|
||||
static const ReturnValue_t INVALID_CONTENT = MAKE_RETURN_CODE(0xE2);
|
||||
static const ReturnValue_t UNALIGNED_ACCESS = MAKE_RETURN_CODE(0xE3);
|
||||
static const ReturnValue_t WRITE_PROTECTED = MAKE_RETURN_CODE(0xE4);
|
||||
// static const ReturnValue_t TARGET_BUSY = MAKE_RETURN_CODE(0xE5);
|
||||
virtual ~HasMemoryIF() {}
|
||||
virtual ReturnValue_t handleMemoryLoad(uint32_t address, const uint8_t* data, uint32_t size, uint8_t** dataPointer) = 0;
|
||||
virtual ReturnValue_t handleMemoryDump(uint32_t address, uint32_t size, uint8_t** dataPointer, uint8_t* dumpTarget ) = 0;
|
||||
/**
|
||||
* Sets the address of the memory, if possible.
|
||||
* startAddress is a proposal for an address, or the base address if multiple addresses are set.
|
||||
*/
|
||||
virtual ReturnValue_t setAddress( uint32_t* startAddress ) { return HasReturnvaluesIF::RETURN_FAILED; }
|
||||
static bool memAccessWasSuccessful(ReturnValue_t result) {
|
||||
switch (result) {
|
||||
case DO_IT_MYSELF:
|
||||
case POINTS_TO_MEMORY:
|
||||
case POINTS_TO_VARIABLE:
|
||||
case HasReturnvaluesIF::RETURN_OK:
|
||||
case ACTIVITY_COMPLETED:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* HASMEMORYIF_H_ */
|
196
src/fsfw/memory/MemoryHelper.cpp
Normal file
196
src/fsfw/memory/MemoryHelper.cpp
Normal file
@ -0,0 +1,196 @@
|
||||
#include "fsfw/memory/MemoryHelper.h"
|
||||
#include "fsfw/memory/MemoryMessage.h"
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serialize/EndianConverter.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
MemoryHelper::MemoryHelper(HasMemoryIF* workOnThis,
|
||||
MessageQueueIF* useThisQueue):
|
||||
workOnThis(workOnThis), queueToUse(useThisQueue), ipcAddress(),
|
||||
lastCommand(CommandMessage::CMD_NONE), busy(false) {
|
||||
}
|
||||
|
||||
ReturnValue_t MemoryHelper::handleMemoryCommand(CommandMessage* message) {
|
||||
lastSender = message->getSender();
|
||||
lastCommand = message->getCommand();
|
||||
if (busy) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "MemHelper: Busy!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
switch (lastCommand) {
|
||||
case MemoryMessage::CMD_MEMORY_DUMP:
|
||||
handleMemoryCheckOrDump(message);
|
||||
return RETURN_OK;
|
||||
case MemoryMessage::CMD_MEMORY_LOAD:
|
||||
handleMemoryLoad(message);
|
||||
return RETURN_OK;
|
||||
case MemoryMessage::CMD_MEMORY_CHECK:
|
||||
handleMemoryCheckOrDump(message);
|
||||
return RETURN_OK;
|
||||
default:
|
||||
lastCommand = CommandMessage::CMD_NONE;
|
||||
return UNKNOWN_CMD;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryHelper::completeLoad(ReturnValue_t errorCode,
|
||||
const uint8_t* dataToCopy, const size_t size, uint8_t* copyHere) {
|
||||
busy = false;
|
||||
switch (errorCode) {
|
||||
case HasMemoryIF::DO_IT_MYSELF:
|
||||
busy = true;
|
||||
return;
|
||||
case HasMemoryIF::POINTS_TO_MEMORY:
|
||||
memcpy(copyHere, dataToCopy, size);
|
||||
break;
|
||||
case HasMemoryIF::POINTS_TO_VARIABLE:
|
||||
EndianConverter::convertBigEndian(copyHere, dataToCopy, size);
|
||||
break;
|
||||
case HasMemoryIF::ACTIVITY_COMPLETED:
|
||||
case RETURN_OK:
|
||||
break;
|
||||
default:
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
CommandMessage reply;
|
||||
MemoryMessage::setMemoryReplyFailed(&reply, errorCode,
|
||||
MemoryMessage::CMD_MEMORY_LOAD);
|
||||
queueToUse->sendMessage(lastSender, &reply);
|
||||
return;
|
||||
}
|
||||
//Only reached on success
|
||||
CommandMessage reply( CommandMessage::REPLY_COMMAND_OK, 0, 0);
|
||||
queueToUse->sendMessage(lastSender, &reply);
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
}
|
||||
|
||||
void MemoryHelper::completeDump(ReturnValue_t errorCode,
|
||||
const uint8_t* dataToCopy, const size_t size) {
|
||||
busy = false;
|
||||
CommandMessage reply;
|
||||
MemoryMessage::setMemoryReplyFailed(&reply, errorCode, lastCommand);
|
||||
switch (errorCode) {
|
||||
case HasMemoryIF::DO_IT_MYSELF:
|
||||
busy = true;
|
||||
return;
|
||||
case HasReturnvaluesIF::RETURN_OK:
|
||||
case HasMemoryIF::POINTS_TO_MEMORY:
|
||||
case HasMemoryIF::POINTS_TO_VARIABLE:
|
||||
//"data" must be valid pointer!
|
||||
if (errorCode == HasMemoryIF::POINTS_TO_VARIABLE) {
|
||||
EndianConverter::convertBigEndian(reservedSpaceInIPC, dataToCopy, size);
|
||||
} else {
|
||||
memcpy(reservedSpaceInIPC, dataToCopy, size);
|
||||
}
|
||||
/* NO BREAK falls through*/
|
||||
case HasMemoryIF::ACTIVITY_COMPLETED:
|
||||
switch (lastCommand) {
|
||||
case MemoryMessage::CMD_MEMORY_DUMP: {
|
||||
MemoryMessage::setMemoryDumpReply(&reply, ipcAddress);
|
||||
break;
|
||||
}
|
||||
case MemoryMessage::CMD_MEMORY_CHECK: {
|
||||
uint16_t crc = CRC::crc16ccitt(reservedSpaceInIPC, size);
|
||||
//Delete data immediately, was temporary.
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
MemoryMessage::setMemoryCheckReply(&reply, crc);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//This should never happen!
|
||||
//Is it ok to send message? Otherwise: return;
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
reply.setParameter(STATE_MISMATCH);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case HasMemoryIF::DUMP_NOT_SUPPORTED:
|
||||
if (lastCommand == MemoryMessage::CMD_MEMORY_CHECK){
|
||||
MemoryMessage::setMemoryCheckReply(&reply, 0);
|
||||
MemoryMessage::setCrcReturnValue(&reply,HasMemoryIF::DUMP_NOT_SUPPORTED);
|
||||
}
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
break;
|
||||
default:
|
||||
//Reply is already set to REJECTED.
|
||||
ipcStore->deleteData(ipcAddress);
|
||||
break;
|
||||
}
|
||||
if (queueToUse->sendMessage(lastSender, &reply) != RETURN_OK) {
|
||||
reply.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryHelper::swapMatrixCopy(uint8_t* out, const uint8_t *in,
|
||||
size_t totalSize, uint8_t datatypeSize) {
|
||||
if (totalSize % datatypeSize != 0){
|
||||
return;
|
||||
}
|
||||
|
||||
while (totalSize > 0){
|
||||
EndianConverter::convertBigEndian(out,in,datatypeSize);
|
||||
out += datatypeSize;
|
||||
in += datatypeSize;
|
||||
totalSize -= datatypeSize;
|
||||
}
|
||||
}
|
||||
|
||||
MemoryHelper::~MemoryHelper() {
|
||||
//Nothing to destroy
|
||||
}
|
||||
|
||||
void MemoryHelper::handleMemoryLoad(CommandMessage* message) {
|
||||
uint32_t address = MemoryMessage::getAddress(message);
|
||||
ipcAddress = MemoryMessage::getStoreID(message);
|
||||
const uint8_t* p_data = NULL;
|
||||
uint8_t* dataPointer = NULL;
|
||||
size_t size = 0;
|
||||
ReturnValue_t returnCode = ipcStore->getData(ipcAddress, &p_data, &size);
|
||||
if (returnCode == RETURN_OK) {
|
||||
returnCode = workOnThis->handleMemoryLoad(address, p_data, size,
|
||||
&dataPointer);
|
||||
completeLoad(returnCode, p_data, size, dataPointer);
|
||||
} else {
|
||||
//At least inform sender.
|
||||
CommandMessage reply;
|
||||
MemoryMessage::setMemoryReplyFailed(&reply, returnCode,
|
||||
MemoryMessage::CMD_MEMORY_LOAD);
|
||||
queueToUse->sendMessage(lastSender, &reply);
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryHelper::handleMemoryCheckOrDump(CommandMessage* message) {
|
||||
uint32_t address = MemoryMessage::getAddress(message);
|
||||
uint32_t size = MemoryMessage::getLength(message);
|
||||
uint8_t* dataPointer = NULL;
|
||||
ReturnValue_t returnCode = ipcStore->getFreeElement(&ipcAddress, size,
|
||||
&reservedSpaceInIPC);
|
||||
if (returnCode == RETURN_OK) {
|
||||
returnCode = workOnThis->handleMemoryDump(address, size, &dataPointer,
|
||||
reservedSpaceInIPC);
|
||||
completeDump(returnCode, dataPointer, size);
|
||||
} else {
|
||||
CommandMessage reply;
|
||||
MemoryMessage::setMemoryReplyFailed(&reply, returnCode, lastCommand);
|
||||
queueToUse->sendMessage(lastSender, &reply);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MemoryHelper::initialize(MessageQueueIF* queueToUse_) {
|
||||
if(queueToUse_ == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
this->queueToUse = queueToUse_;
|
||||
return initialize();
|
||||
}
|
||||
|
||||
ReturnValue_t MemoryHelper::initialize() {
|
||||
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore != nullptr) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
49
src/fsfw/memory/MemoryHelper.h
Normal file
49
src/fsfw/memory/MemoryHelper.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef FSFW_MEMORY_MEMORYHELPER_H_
|
||||
#define FSFW_MEMORY_MEMORYHELPER_H_
|
||||
|
||||
#include "AcceptsMemoryMessagesIF.h"
|
||||
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
|
||||
/**
|
||||
* @brief TODO: documentation.
|
||||
*/
|
||||
class MemoryHelper : public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MEMORY_HELPER;
|
||||
static const ReturnValue_t UNKNOWN_CMD = MAKE_RETURN_CODE(0xE0);
|
||||
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0xE1);
|
||||
static const ReturnValue_t INVALID_SIZE = MAKE_RETURN_CODE(0xE2);
|
||||
static const ReturnValue_t STATE_MISMATCH = MAKE_RETURN_CODE(0xE3);
|
||||
|
||||
MemoryHelper(HasMemoryIF* workOnThis, MessageQueueIF* useThisQueue);
|
||||
~MemoryHelper();
|
||||
|
||||
ReturnValue_t handleMemoryCommand(CommandMessage* message);
|
||||
void completeLoad(ReturnValue_t errorCode,
|
||||
const uint8_t* dataToCopy = nullptr, const size_t size = 0,
|
||||
uint8_t* copyHere = nullptr);
|
||||
void completeDump(ReturnValue_t errorCode,
|
||||
const uint8_t* dataToCopy = nullptr, const size_t size = 0);
|
||||
void swapMatrixCopy(uint8_t *out, const uint8_t *in, size_t totalSize,
|
||||
uint8_t datatypeSize);
|
||||
ReturnValue_t initialize(MessageQueueIF* queueToUse_);
|
||||
|
||||
private:
|
||||
HasMemoryIF* workOnThis;
|
||||
MessageQueueIF* queueToUse;
|
||||
StorageManagerIF* ipcStore = nullptr;
|
||||
store_address_t ipcAddress;
|
||||
Command_t lastCommand;
|
||||
MessageQueueId_t lastSender = MessageQueueIF::NO_QUEUE;
|
||||
uint8_t* reservedSpaceInIPC = nullptr;
|
||||
bool busy;
|
||||
void handleMemoryLoad(CommandMessage* message);
|
||||
void handleMemoryCheckOrDump(CommandMessage* message);
|
||||
ReturnValue_t initialize();
|
||||
|
||||
};
|
||||
#endif /* FSFW_MEMORY_MEMORYHELPER_H_ */
|
107
src/fsfw/memory/MemoryMessage.cpp
Normal file
107
src/fsfw/memory/MemoryMessage.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include "fsfw/memory/MemoryMessage.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
|
||||
uint32_t MemoryMessage::getAddress(const CommandMessage* message) {
|
||||
return message->getParameter();
|
||||
}
|
||||
|
||||
store_address_t MemoryMessage::getStoreID(const CommandMessage* message) {
|
||||
store_address_t temp;
|
||||
temp.raw = message->getParameter2();
|
||||
return temp;
|
||||
}
|
||||
|
||||
uint32_t MemoryMessage::getLength(const CommandMessage* message) {
|
||||
return message->getParameter2();
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryDumpCommand(CommandMessage* message,
|
||||
uint32_t address, uint32_t length) {
|
||||
message->setCommand(CMD_MEMORY_DUMP);
|
||||
message->setParameter( address );
|
||||
message->setParameter2( length );
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryDumpReply(CommandMessage* message,
|
||||
store_address_t storageID) {
|
||||
message->setCommand(REPLY_MEMORY_DUMP);
|
||||
message->setParameter2( storageID.raw );
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryLoadCommand(CommandMessage* message,
|
||||
uint32_t address, store_address_t storageID) {
|
||||
message->setCommand(CMD_MEMORY_LOAD);
|
||||
message->setParameter( address );
|
||||
message->setParameter2( storageID.raw );
|
||||
}
|
||||
|
||||
ReturnValue_t MemoryMessage::getErrorCode(const CommandMessage* message) {
|
||||
return message->getParameter();
|
||||
}
|
||||
|
||||
void MemoryMessage::clear(CommandMessage* message) {
|
||||
switch (message->getCommand()) {
|
||||
case CMD_MEMORY_LOAD:
|
||||
case REPLY_MEMORY_DUMP: {
|
||||
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
|
||||
objects::IPC_STORE);
|
||||
if (ipcStore != NULL) {
|
||||
ipcStore->deleteData(getStoreID(message));
|
||||
}
|
||||
}
|
||||
/* NO BREAK falls through*/
|
||||
case CMD_MEMORY_DUMP:
|
||||
case CMD_MEMORY_CHECK:
|
||||
case REPLY_MEMORY_CHECK:
|
||||
case END_OF_MEMORY_COPY:
|
||||
message->setCommand(CommandMessage::CMD_NONE);
|
||||
message->setParameter(0);
|
||||
message->setParameter2(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryCheckCommand(CommandMessage* message,
|
||||
uint32_t address, uint32_t length) {
|
||||
message->setCommand(CMD_MEMORY_CHECK);
|
||||
message->setParameter( address );
|
||||
message->setParameter2( length );
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryCheckReply(CommandMessage* message,
|
||||
uint16_t crc) {
|
||||
message->setCommand(REPLY_MEMORY_CHECK);
|
||||
message->setParameter( crc );
|
||||
}
|
||||
|
||||
void MemoryMessage::setCrcReturnValue(CommandMessage* message,
|
||||
ReturnValue_t returnValue){
|
||||
message->setParameter(returnValue<<16);
|
||||
};
|
||||
|
||||
uint16_t MemoryMessage::getCrc(const CommandMessage* message) {
|
||||
return (uint16_t)(message->getParameter());
|
||||
}
|
||||
|
||||
ReturnValue_t MemoryMessage::getCrcReturnValue(const CommandMessage* message){
|
||||
return (message->getParameter()>>16);
|
||||
}
|
||||
|
||||
Command_t MemoryMessage::getInitialCommand(const CommandMessage* message) {
|
||||
return message->getParameter2();
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryReplyFailed(CommandMessage* message,
|
||||
ReturnValue_t errorCode, Command_t initialCommand) {
|
||||
message->setCommand(REPLY_MEMORY_FAILED);
|
||||
message->setParameter(errorCode);
|
||||
message->setParameter2(initialCommand);
|
||||
}
|
||||
|
||||
void MemoryMessage::setMemoryCopyEnd(CommandMessage* message) {
|
||||
message->setCommand(END_OF_MEMORY_COPY);
|
||||
message->setParameter(0);
|
||||
message->setParameter2(0);
|
||||
}
|
||||
|
48
src/fsfw/memory/MemoryMessage.h
Normal file
48
src/fsfw/memory/MemoryMessage.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef FSFW_MEMORY_MEMORYMESSAGE_H_
|
||||
#define FSFW_MEMORY_MEMORYMESSAGE_H_
|
||||
|
||||
#include "../ipc/CommandMessage.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
|
||||
|
||||
class MemoryMessage {
|
||||
public:
|
||||
// Instantiation forbidden.
|
||||
MemoryMessage() = delete;
|
||||
|
||||
static const uint8_t MESSAGE_ID = messagetypes::MEMORY;
|
||||
static const Command_t CMD_MEMORY_LOAD = MAKE_COMMAND_ID( 0x01 );
|
||||
static const Command_t CMD_MEMORY_DUMP = MAKE_COMMAND_ID( 0x02 );
|
||||
static const Command_t CMD_MEMORY_CHECK = MAKE_COMMAND_ID( 0x03 );
|
||||
static const Command_t REPLY_MEMORY_DUMP = MAKE_COMMAND_ID( 0x10 );
|
||||
static const Command_t REPLY_MEMORY_CHECK = MAKE_COMMAND_ID( 0x30 );
|
||||
static const Command_t REPLY_MEMORY_FAILED = MAKE_COMMAND_ID( 0xE0 );
|
||||
static const Command_t END_OF_MEMORY_COPY = MAKE_COMMAND_ID(0xF0);
|
||||
|
||||
static uint32_t getAddress( const CommandMessage* message );
|
||||
static store_address_t getStoreID(const CommandMessage* message);
|
||||
static uint32_t getLength( const CommandMessage* message );
|
||||
static ReturnValue_t getErrorCode(const CommandMessage* message);
|
||||
static uint16_t getCrc(const CommandMessage* message );
|
||||
static ReturnValue_t getCrcReturnValue(const CommandMessage* message);
|
||||
static Command_t getInitialCommand(const CommandMessage* message);
|
||||
|
||||
static void setMemoryDumpCommand(CommandMessage* message,
|
||||
uint32_t address, uint32_t length );
|
||||
static void setMemoryDumpReply(CommandMessage* message,
|
||||
store_address_t storageID);
|
||||
static void setMemoryLoadCommand(CommandMessage* message,
|
||||
uint32_t address, store_address_t storageID );
|
||||
static void setMemoryCheckCommand(CommandMessage* message,
|
||||
uint32_t address, uint32_t length);
|
||||
static void setMemoryCheckReply(CommandMessage* message,
|
||||
uint16_t crc);
|
||||
static void setMemoryReplyFailed(CommandMessage* message,
|
||||
ReturnValue_t errorCode, Command_t initialCommand);
|
||||
static void setMemoryCopyEnd(CommandMessage* message);
|
||||
static void setCrcReturnValue(CommandMessage*, ReturnValue_t returnValue);
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FSFW_MEMORY_MEMORYMESSAGE_H_ */
|
Reference in New Issue
Block a user