Merge remote-tracking branch 'ksat/mueller/master' into mueller/master

This commit is contained in:
Robin Müller 2021-08-18 18:06:56 +02:00
commit d0d4359017
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
85 changed files with 1523 additions and 453 deletions

View File

@ -10,6 +10,7 @@ endif()
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
# Options to exclude parts of the FSFW from compilation. # Options to exclude parts of the FSFW from compilation.
option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON) option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
# Optional sources # Optional sources
@ -38,7 +39,7 @@ elseif(${CMAKE_CXX_STANDARD} LESS 11)
endif() endif()
# Backwards comptability # Backwards comptability
if(OS_FSFW) if(OS_FSFW AND NOT FSFW_OSAL)
message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW") message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
set(FSFW_OSAL OS_FSFW) set(FSFW_OSAL OS_FSFW)
endif() endif()

View File

@ -1,6 +1,7 @@
# Core # Core
add_subdirectory(action) add_subdirectory(action)
add_subdirectory(cfdp)
add_subdirectory(container) add_subdirectory(container)
add_subdirectory(controller) add_subdirectory(controller)
add_subdirectory(datapool) add_subdirectory(datapool)

View File

@ -0,0 +1,59 @@
#include "fsfw/cfdp/CFDPHandler.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/objectmanager/ObjectManager.h"
object_id_t CFDPHandler::packetSource = 0;
object_id_t CFDPHandler::packetDestination = 0;
CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist) : SystemObject(setObjectId) {
requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION);
distributor = dist;
}
CFDPHandler::~CFDPHandler() {}
ReturnValue_t CFDPHandler::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
this->distributor->registerHandler(this);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CFDPHandler::handleRequest(uint8_t subservice) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CFDPHandler::handleRequest" << std::endl;
#else
sif::printDebug("CFDPHandler::handleRequest");
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif
return RETURN_OK;
}
ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) {
ReturnValue_t result = this->performService();
return result;
}
ReturnValue_t CFDPHandler::performService() {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CFDPHandler::performService" << std::endl;
#else
sif::printDebug("CFDPHandler::performService");
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif
return RETURN_OK;
}
uint16_t CFDPHandler::getIdentifier() {
return 0;
}
MessageQueueId_t CFDPHandler::getRequestQueue() {
return this->requestQueue->getId();
}

View File

@ -0,0 +1,63 @@
#ifndef FSFW_CFDP_CFDPHANDLER_H_
#define FSFW_CFDP_CFDPHANDLER_H_
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tcdistribution/CFDPDistributor.h"
#include "fsfw/ipc/MessageQueueIF.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
class CFDPHandler :
public ExecutableObjectIF,
public AcceptsTelecommandsIF,
public SystemObject,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
CFDPHandler(object_id_t setObjectId, CFDPDistributor* distributor);
/**
* The destructor is empty.
*/
virtual ~CFDPHandler();
virtual ReturnValue_t handleRequest(uint8_t subservice);
virtual ReturnValue_t performService();
virtual ReturnValue_t initialize() override;
virtual uint16_t getIdentifier() override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t performOperation(uint8_t opCode) override;
protected:
/**
* This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class.
*/
MessageQueueIF* requestQueue = nullptr;
CFDPDistributor* distributor = nullptr;
/**
* The current CFDP packet to be processed.
* It is deleted after handleRequest was executed.
*/
CFDPPacketStored currentPacket;
static object_id_t packetSource;
static object_id_t packetDestination;
private:
/**
* This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one
* #handleRequest call.
*/
static const uint8_t CFDP_HANDLER_MAX_RECEPTION = 10;
};
#endif /* FSFW_CFDP_CFDPHANDLER_H_ */

View File

@ -0,0 +1,4 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
CFDPHandler.cpp
)

View File

@ -1,27 +1,54 @@
#include "fsfw/globalfunctions/DleEncoder.h" #include "fsfw/globalfunctions/DleEncoder.h"
DleEncoder::DleEncoder() {} DleEncoder::DleEncoder(bool escapeStxEtx, bool escapeCr): escapeStxEtx(escapeStxEtx),
escapeCr(escapeCr) {}
DleEncoder::~DleEncoder() {} DleEncoder::~DleEncoder() {}
ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream, ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
size_t sourceLen, uint8_t* destStream, size_t maxDestLen, size_t sourceLen, uint8_t* destStream, size_t maxDestLen,
size_t* encodedLen, bool addStxEtx) { size_t* encodedLen, bool addStxEtx) {
if (maxDestLen < 2) { size_t minAllowedLen = 0;
if(escapeStxEtx) {
minAllowedLen = 2;
}
else {
minAllowedLen = 1;
}
if(maxDestLen < minAllowedLen) {
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
size_t encodedIndex = 0, sourceIndex = 0;
uint8_t nextByte;
if (addStxEtx) { if (addStxEtx) {
if(not escapeStxEtx) {
destStream[0] = DLE_CHAR;
}
destStream[0] = STX_CHAR; destStream[0] = STX_CHAR;
++encodedIndex;
} }
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) if(escapeStxEtx) {
{ return encodeStreamEscaped(sourceStream, sourceLen,
destStream, maxDestLen, encodedLen, addStxEtx);
}
else {
return encodeStreamNonEscaped(sourceStream, sourceLen,
destStream, maxDestLen, encodedLen, addStxEtx);
}
}
ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 1;
size_t sourceIndex = 0;
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
nextByte = sourceStream[sourceIndex]; nextByte = sourceStream[sourceIndex];
// STX, ETX and CR characters in the stream need to be escaped with DLE // STX, ETX and CR characters in the stream need to be escaped with DLE
if (nextByte == STX_CHAR or nextByte == ETX_CHAR or nextByte == CARRIAGE_RETURN) { if ((nextByte == STX_CHAR or nextByte == ETX_CHAR) or
(this->escapeCr and nextByte == CARRIAGE_RETURN)) {
if (encodedIndex + 1 >= maxDestLen) { if (encodedIndex + 1 >= maxDestLen) {
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
@ -69,16 +96,76 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
} }
} }
ReturnValue_t DleEncoder::encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 1;
size_t sourceIndex = 0;
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
nextByte = sourceStream[sourceIndex];
// DLE characters are simply escaped with DLE.
if (nextByte == DLE_CHAR) {
if (encodedIndex + 1 >= maxDestLen) {
return STREAM_TOO_SHORT;
}
else {
destStream[encodedIndex] = DLE_CHAR;
++encodedIndex;
destStream[encodedIndex] = DLE_CHAR;
}
}
else {
destStream[encodedIndex] = nextByte;
}
++encodedIndex;
++sourceIndex;
}
if (sourceIndex == sourceLen and encodedIndex < maxDestLen) {
if (addStxEtx) {
destStream[encodedIndex] = ETX_CHAR;
++encodedIndex;
}
*encodedLen = encodedIndex;
return RETURN_OK;
}
else {
return STREAM_TOO_SHORT;
}
}
ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream, ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
size_t maxDestStreamlen, size_t *decodedLen) { size_t maxDestStreamlen, size_t *decodedLen) {
size_t encodedIndex = 0, decodedIndex = 0; size_t encodedIndex = 0;
uint8_t nextByte; if(not escapeStxEtx) {
if (*sourceStream != STX_CHAR) { if (*sourceStream != DLE_CHAR) {
return DECODING_ERROR; return DECODING_ERROR;
} }
++encodedIndex; ++encodedIndex;
}
if (sourceStream[encodedIndex] != STX_CHAR) {
return DECODING_ERROR;
}
if(escapeStxEtx) {
return decodeStreamEscaped(sourceStream, sourceStreamLen,
readLen, destStream, maxDestStreamlen, decodedLen);
}
else {
return decodeStreamNonEscaped(sourceStream, sourceStreamLen,
readLen, destStream, maxDestStreamlen, decodedLen);
}
}
ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_t sourceStreamLen,
size_t *readLen, uint8_t *destStream,
size_t maxDestStreamlen, size_t *decodedLen) {
// Skip start marker, was already checked
size_t encodedIndex = 1;
size_t decodedIndex = 0;
uint8_t nextByte;
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen) while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
&& (sourceStream[encodedIndex] != ETX_CHAR) && (sourceStream[encodedIndex] != ETX_CHAR)
&& (sourceStream[encodedIndex] != STX_CHAR)) { && (sourceStream[encodedIndex] != STX_CHAR)) {
@ -94,7 +181,8 @@ ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
* was escaped by a DLE character. The actual byte was * was escaped by a DLE character. The actual byte was
* also encoded by adding + 0x40 to prevent having control chars, * also encoded by adding + 0x40 to prevent having control chars,
* in the stream at all, so we convert it back. */ * in the stream at all, so we convert it back. */
if (nextByte == 0x42 or nextByte == 0x43 or nextByte == 0x4D) { if ((nextByte == STX_CHAR + 0x40 or nextByte == ETX_CHAR + 0x40) or
(this->escapeCr and nextByte == CARRIAGE_RETURN + 0x40)) {
destStream[decodedIndex] = nextByte - 0x40; destStream[decodedIndex] = nextByte - 0x40;
} }
else { else {
@ -110,7 +198,6 @@ ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
++encodedIndex; ++encodedIndex;
++decodedIndex; ++decodedIndex;
} }
if (sourceStream[encodedIndex] != ETX_CHAR) { if (sourceStream[encodedIndex] != ETX_CHAR) {
*readLen = ++encodedIndex; *readLen = ++encodedIndex;
return DECODING_ERROR; return DECODING_ERROR;
@ -122,3 +209,39 @@ ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
} }
} }
ReturnValue_t DleEncoder::decodeStreamNonEscaped(const uint8_t *sourceStream,
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
size_t maxDestStreamlen, size_t *decodedLen) {
// Skip start marker, was already checked
size_t encodedIndex = 2;
size_t decodedIndex = 0;
uint8_t nextByte;
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)) {
if (sourceStream[encodedIndex] == DLE_CHAR) {
nextByte = sourceStream[encodedIndex + 1];
if(nextByte == STX_CHAR) {
*readLen = ++encodedIndex;
return DECODING_ERROR;
}
else if(nextByte == DLE_CHAR) {
// The next byte is a DLE character that was escaped by another
// DLE character, so we can write it to the destination stream.
destStream[decodedIndex] = nextByte;
++encodedIndex;
}
else if(nextByte == ETX_CHAR) {
// End of stream reached
*readLen = encodedIndex + 2;
*decodedLen = decodedIndex;
return RETURN_OK;
}
}
else {
destStream[decodedIndex] = sourceStream[encodedIndex];
}
++encodedIndex;
++decodedIndex;
}
return DECODING_ERROR;
}

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ #ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ #define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
#include "../returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstddef> #include <cstddef>
/** /**
@ -12,24 +12,33 @@
* https://en.wikipedia.org/wiki/C0_and_C1_control_codes * https://en.wikipedia.org/wiki/C0_and_C1_control_codes
* *
* This encoder can be used to achieve a basic transport layer when using * This encoder can be used to achieve a basic transport layer when using
* char based transmission systems. * char based transmission systems. There are two implemented variants:
* The passed source strean is converted into a encoded stream by adding
* a STX marker at the start of the stream and an ETX marker at the end of
* the stream. Any STX, ETX, DLE and CR occurrences in the source stream are
* escaped by a DLE character. The encoder also replaces escaped control chars
* by another char, so STX, ETX and CR should not appear anywhere in the actual
* encoded data stream.
* *
* When using a strictly char based reception of packets encoded with DLE, * 1. Escaped variant
*
* The encoded stream starts with a STX marker and ends with an ETX marker.
* STX and ETX occurrences in the stream are escaped and internally encoded as well so the
* receiver side can simply check for STX and ETX markers as frame delimiters. When using a
* strictly char based reception of packets encoded with DLE,
* STX can be used to notify a reader that actual data will start to arrive * STX can be used to notify a reader that actual data will start to arrive
* while ETX can be used to notify the reader that the data has ended. * while ETX can be used to notify the reader that the data has ended.
*
* 2. Non-escaped variant
*
* The encoded stream starts with DLE STX and ends with DLE ETX. All DLE occurrences in the stream
* are escaped with DLE. If the receiver detects a DLE char, it needs to read the next char
* to determine whether a start (STX) or end (ETX) of a frame has been detected.
*/ */
class DleEncoder: public HasReturnvaluesIF { class DleEncoder: public HasReturnvaluesIF {
private: public:
DleEncoder(); /**
* Create an encoder instance with the given configuration.
* @param escapeStxEtx Determines whether the algorithm works in escaped or non-escaped mode
* @param escapeCr In escaped mode, escape all CR occurrences as well
*/
DleEncoder(bool escapeStxEtx = true, bool escapeCr = false);
virtual ~DleEncoder(); virtual ~DleEncoder();
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER; static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER;
static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01); static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01);
static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02); static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02);
@ -45,19 +54,22 @@ public:
/** /**
* Encodes the give data stream by preceding it with the STX marker * Encodes the give data stream by preceding it with the STX marker
* and ending it with an ETX marker. STX, ETX and DLE characters inside * and ending it with an ETX marker. DLE characters inside
* the stream are escaped by DLE characters and also replaced by adding * the stream are escaped by DLE characters. STX, ETX and CR characters can be escaped with a
* 0x40 (which is reverted in the decoding process). * DLE character as well. The escaped characters are also encoded by adding
* 0x40 (which is reverted in the decoding process). This is performed so the source stream
* does not have STX/ETX/CR occurrences anymore, so the receiving side can simply parse for
* start and end markers
* @param sourceStream * @param sourceStream
* @param sourceLen * @param sourceLen
* @param destStream * @param destStream
* @param maxDestLen * @param maxDestLen
* @param encodedLen * @param encodedLen
* @param addStxEtx * @param addStxEtx Adding STX start marker and ETX end marker can be omitted,
* Adding STX and ETX can be omitted, if they are added manually. * if they are added manually
* @return * @return
*/ */
static ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen, ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen, uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx = true); bool addStxEtx = true);
@ -71,9 +83,28 @@ public:
* @param decodedLen * @param decodedLen
* @return * @return
*/ */
static ReturnValue_t decode(const uint8_t *sourceStream, ReturnValue_t decode(const uint8_t *sourceStream,
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream, size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
size_t maxDestStreamlen, size_t *decodedLen); size_t maxDestStreamlen, size_t *decodedLen);
private:
ReturnValue_t encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx = true);
ReturnValue_t encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx = true);
ReturnValue_t decodeStreamEscaped(const uint8_t *sourceStream, size_t sourceStreamLen,
size_t *readLen, uint8_t *destStream, size_t maxDestStreamlen, size_t *decodedLen);
ReturnValue_t decodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceStreamLen,
size_t *readLen, uint8_t *destStream, size_t maxDestStreamlen, size_t *decodedLen);
bool escapeStxEtx;
bool escapeCr;
}; };
#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */ #endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */

View File

@ -0,0 +1,13 @@
#ifndef FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_
#define FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_
/**
* Empty base interface which can be implemented by to pass arguments via the HasFileSystemIF.
* Users can then dynamic_cast the base pointer to the require child pointer.
*/
class FileSystemArgsIF {
public:
virtual~ FileSystemArgsIF() {};
};
#endif /* FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ */

View File

@ -1,9 +1,10 @@
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_ #ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
#define FSFW_MEMORY_HASFILESYSTEMIF_H_ #define FSFW_MEMORY_HASFILESYSTEMIF_H_
#include "../returnvalues/HasReturnvaluesIF.h" #include "FileSystemArgsIF.h"
#include "../returnvalues/FwClassIds.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "../ipc/messageQueueDefinitions.h" #include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/ipc/messageQueueDefinitions.h"
#include <cstddef> #include <cstddef>
@ -59,7 +60,7 @@ public:
*/ */
virtual ReturnValue_t appendToFile(const char* repositoryPath, virtual ReturnValue_t appendToFile(const char* repositoryPath,
const char* filename, const uint8_t* data, size_t size, const char* filename, const uint8_t* data, size_t size,
uint16_t packetNumber, void* args = nullptr) = 0; uint16_t packetNumber, FileSystemArgsIF* args = nullptr) = 0;
/** /**
* @brief Generic function to create a new file. * @brief Generic function to create a new file.
@ -72,7 +73,7 @@ public:
*/ */
virtual ReturnValue_t createFile(const char* repositoryPath, virtual ReturnValue_t createFile(const char* repositoryPath,
const char* filename, const uint8_t* data = nullptr, const char* filename, const uint8_t* data = nullptr,
size_t size = 0, void* args = nullptr) = 0; size_t size = 0, FileSystemArgsIF* args = nullptr) = 0;
/** /**
* @brief Generic function to delete a file. * @brief Generic function to delete a file.
@ -82,23 +83,29 @@ public:
* @return * @return
*/ */
virtual ReturnValue_t removeFile(const char* repositoryPath, virtual ReturnValue_t removeFile(const char* repositoryPath,
const char* filename, void* args = nullptr) = 0; const char* filename, FileSystemArgsIF* args = nullptr) = 0;
/** /**
* @brief Generic function to create a directory * @brief Generic function to create a directory
* @param repositoryPath * @param repositoryPath
* @param Equivalent to the -p flag in Unix systems. If some required parent directories
* do not exist, create them as well
* @param args Any other arguments which an implementation might require * @param args Any other arguments which an implementation might require
* @return * @return
*/ */
virtual ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) = 0; virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname,
bool createParentDirs, FileSystemArgsIF* args = nullptr) = 0;
/** /**
* @brief Generic function to remove a directory * @brief Generic function to remove a directory
* @param repositoryPath * @param repositoryPath
* @param args Any other arguments which an implementation might require * @param args Any other arguments which an implementation might require
*/ */
virtual ReturnValue_t removeDirectory(const char* repositoryPath, virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname,
bool deleteRecurively = false, void* args = nullptr) = 0; bool deleteRecurively = false, FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename,
const char* newFilename, FileSystemArgsIF* args = nullptr) = 0;
}; };

View File

@ -19,6 +19,9 @@ enum framework_objects: object_id_t {
PUS_SERVICE_200_MODE_MGMT = 0x53000200, PUS_SERVICE_200_MODE_MGMT = 0x53000200,
PUS_SERVICE_201_HEALTH = 0x53000201, PUS_SERVICE_201_HEALTH = 0x53000201,
/* CFDP Distributer */
CFDP_PACKET_DISTRIBUTOR = 0x53001000,
//Generic IDs for IPC, modes, health, events //Generic IDs for IPC, modes, health, events
HEALTH_TABLE = 0x53010000, HEALTH_TABLE = 0x53010000,
// MODE_STORE = 0x53010100, // MODE_STORE = 0x53010100,

View File

@ -62,8 +62,13 @@ ReturnValue_t CommandExecutor::close() {
void CommandExecutor::printLastError(std::string funcName) const { void CommandExecutor::printLastError(std::string funcName) const {
if(lastError != 0) { if(lastError != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << funcName << " pclose failed with code " << sif::error << funcName << " pclose failed with code " <<
lastError << ": " << strerror(lastError) << std::endl; lastError << ": " << strerror(lastError) << std::endl;
#else
sif::printError("%s pclose failed with code %d: %s", funcName, lastError,
strerror(lastError));
#endif
} }
} }
@ -98,15 +103,23 @@ ReturnValue_t CommandExecutor::check(bool& bytesRead) {
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size()); ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
if(readBytes == 0) { if(readBytes == 0) {
// Should not happen // Should not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecutor::check: " sif::warning << "CommandExecutor::check: "
"No bytes read after poll event.." << std::endl; "No bytes read after poll event.." << std::endl;
#else
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
#endif
break; break;
} }
else if(readBytes > 0) { else if(readBytes > 0) {
bytesRead = true; bytesRead = true;
if(printOutput) { if(printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// It is assumed the command output is line terminated // It is assumed the command output is line terminated
sif::info << currentCmd << " | " << readVec.data(); sif::info << currentCmd << " | " << readVec.data();
#else
sif::printInfo("%s | %s", currentCmd, readVec.data());
#endif
} }
if(ringBuffer != nullptr) { if(ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>( ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
@ -120,17 +133,25 @@ ReturnValue_t CommandExecutor::check(bool& bytesRead) {
return BYTES_READ; return BYTES_READ;
} }
else { else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// Should also not happen // Should also not happen
sif::warning << "CommandExecutor::check: Error " << errno << ": " << sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
strerror(errno) << std::endl; strerror(errno) << std::endl;
#else
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
#endif
} }
} }
else if(waiter.revents & POLLERR) { else if(waiter.revents & POLLERR) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecuter::check: Poll error" << std::endl; sif::warning << "CommandExecuter::check: Poll error" << std::endl;
#else
sif::printWarning("CommandExecuter::check: Poll error\n");
#endif
return COMMAND_ERROR; return COMMAND_ERROR;
} }
else if(waiter.revents & POLLHUP) { else if(waiter.revents & POLLHUP) {
int result = pclose(currentCmdFile); result = pclose(currentCmdFile);
if(result != 0) { if(result != 0) {
lastError = result; lastError = result;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
@ -165,7 +186,11 @@ ReturnValue_t CommandExecutor::executeBlocking() {
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) { while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
std::string output(readVec.data()); std::string output(readVec.data());
if(printOutput) { if(printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << currentCmd << " | " << output; sif::info << currentCmd << " | " << output;
#else
sif::printInfo("%s | %s", currentCmd, output);
#endif
} }
if(ringBuffer != nullptr) { if(ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size()); ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());

View File

@ -50,8 +50,6 @@ bool Timer::isSet() const {
} }
void Timer::resetTimer() { void Timer::resetTimer() {
if(not this->set) {
set = false; set = false;
}
setTimer(0); setTimer(0);
} }

View File

@ -15,7 +15,8 @@
* The Secondary Header (with Service/Subservice) is ignored. * The Secondary Header (with Service/Subservice) is ignored.
* @ingroup tc_distribution * @ingroup tc_distribution
*/ */
class CCSDSDistributor : public TcDistributor, class CCSDSDistributor:
public TcDistributor,
public CCSDSDistributorIF, public CCSDSDistributorIF,
public AcceptsTelecommandsIF { public AcceptsTelecommandsIF {
public: public:

View File

@ -36,8 +36,7 @@ public:
/** /**
* The empty virtual destructor. * The empty virtual destructor.
*/ */
virtual ~CCSDSDistributorIF() { virtual ~CCSDSDistributorIF() {}
}
}; };

View File

@ -0,0 +1,147 @@
#include "fsfw/tcdistribution/CCSDSDistributorIF.h"
#include "fsfw/tcdistribution/CFDPDistributor.h"
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
#include "fsfw/objectmanager/ObjectManager.h"
#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING
#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1
#endif
CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId,
object_id_t setPacketSource):
TcDistributor(setObjectId), apid(setApid), checker(setApid),
tcStatus(RETURN_FAILED), packetSource(setPacketSource) {
}
CFDPDistributor::~CFDPDistributor() {}
CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() {
#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1
store_address_t storeId = this->currentMessage.getStorageId();
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " <<
storeId.packetIndex << std::endl;
#else
sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex,
storeId.packetIndex);
#endif
#endif
TcMqMapIter queueMapIt = this->queueMap.end();
if(this->currentPacket == nullptr) {
return queueMapIt;
}
this->currentPacket->setStoreAddress(this->currentMessage.getStorageId());
if (currentPacket->getWholeData() != nullptr) {
tcStatus = checker.checkPacket(currentPacket);
if(tcStatus != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "PUSDistributor::handlePacket: Packet format invalid, code " <<
static_cast<int>(tcStatus) << std::endl;
#else
sif::printDebug("PUSDistributor::handlePacket: Packet format invalid, code %d\n",
static_cast<int>(tcStatus));
#endif
#endif
}
queueMapIt = this->queueMap.find(0);
}
else {
tcStatus = PACKET_LOST;
}
if (queueMapIt == this->queueMap.end()) {
tcStatus = DESTINATION_NOT_FOUND;
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl;
#else
sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n");
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif
}
if (tcStatus != RETURN_OK) {
return this->queueMap.end();
}
else {
return queueMapIt;
}
}
ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) {
uint16_t handlerId = handler->getIdentifier(); //should be 0, because CFDPHandler does not set a set a service-ID
#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast<int>(handlerId) << std::endl;
#else
sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", static_cast<int>(handlerId));
#endif
#endif
MessageQueueId_t queue = handler->getRequestQueue();
auto returnPair = queueMap.emplace(handlerId, queue);
if (not returnPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CFDPDistributor::registerHandler: Service ID already"
" exists in map" << std::endl;
#else
sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n");
#endif
#endif
return SERVICE_ID_ALREADY_EXISTS;
}
return HasReturnvaluesIF::RETURN_OK;
}
MessageQueueId_t CFDPDistributor::getRequestQueue() {
return tcQueue->getId();
}
//ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
// if (queueStatus != RETURN_OK) {
// tcStatus = queueStatus;
// }
// if (tcStatus != RETURN_OK) {
// this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE,
// currentPacket, tcStatus);
// // A failed packet is deleted immediately after reporting,
// // otherwise it will block memory.
// currentPacket->deletePacket();
// return RETURN_FAILED;
// } else {
// this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS,
// currentPacket);
// return RETURN_OK;
// }
//}
uint16_t CFDPDistributor::getIdentifier() {
return this->apid;
}
ReturnValue_t CFDPDistributor::initialize() {
currentPacket = new CFDPPacketStored();
if(currentPacket == nullptr) {
// Should not happen, memory allocation failed!
return ObjectManagerIF::CHILD_INIT_FAILED;
}
CCSDSDistributorIF* ccsdsDistributor = ObjectManager::instance()->get<CCSDSDistributorIF>(
packetSource);
if (ccsdsDistributor == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl;
sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl;
#else
sif::printError("CFDPDistributor::initialize: Packet source invalid\n");
sif::printError("Make sure it exists and implements CCSDSDistributorIF\n");
#endif
return RETURN_FAILED;
}
return ccsdsDistributor->registerApplication(this);
}

View File

@ -0,0 +1,72 @@
#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_
#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_
#include <fsfw/tcdistribution/TcPacketCheckCFDP.h>
#include "CFDPDistributorIF.h"
#include "TcDistributor.h"
#include "../tmtcpacket/cfdp/CFDPPacketStored.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../tmtcservices/VerificationReporter.h"
/**
* This class accepts CFDP Telecommands and forwards them to Application
* services.
* @ingroup tc_distribution
*/
class CFDPDistributor:
public TcDistributor,
public CFDPDistributorIF,
public AcceptsTelecommandsIF {
public:
/**
* The ctor passes @c set_apid to the checker class and calls the
* TcDistribution ctor with a certain object id.
* @param setApid The APID of this receiving Application.
* @param setObjectId Object ID of the distributor itself
* @param setPacketSource Object ID of the source of TC packets.
* Must implement CCSDSDistributorIF.
*/
CFDPDistributor(uint16_t setApid, object_id_t setObjectId,
object_id_t setPacketSource);
/**
* The destructor is empty.
*/
virtual ~CFDPDistributor();
ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t initialize() override;
uint16_t getIdentifier() override;
protected:
uint16_t apid;
/**
* The currently handled packet is stored here.
*/
CFDPPacketStored* currentPacket = nullptr;
TcPacketCheckCFDP checker;
/**
* With this variable, the current check status is stored to generate
* acceptance messages later.
*/
ReturnValue_t tcStatus;
const object_id_t packetSource;
/**
* This method reads the packet service, checks if such a service is
* registered and forwards the packet to the destination.
* It also initiates the formal packet check and sending of verification
* messages.
* @return Iterator to map entry of found service id
* or iterator to @c map.end().
*/
TcMqMapIter selectDestination() override;
/**
* The callback here handles the generation of acceptance
* success/failure messages.
*/
//ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus) override;
};
#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTOR_H_ */

View File

@ -0,0 +1,27 @@
#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_
#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_
#include "../tmtcservices/AcceptsTelecommandsIF.h"
#include "../ipc/MessageQueueSenderIF.h"
/**
* This interface allows CFDP Services to register themselves at a CFDP Distributor.
* @ingroup tc_distribution
*/
class CFDPDistributorIF {
public:
/**
* The empty virtual destructor.
*/
virtual ~CFDPDistributorIF() {
}
/**
* With this method, Handlers can register themselves at the CFDP Distributor.
* @param handler A pointer to the registering Handler.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerHandler(AcceptsTelecommandsIF* handler) = 0;
};
#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ */

View File

@ -2,5 +2,8 @@ target_sources(${LIB_FSFW_NAME} PRIVATE
CCSDSDistributor.cpp CCSDSDistributor.cpp
PUSDistributor.cpp PUSDistributor.cpp
TcDistributor.cpp TcDistributor.cpp
TcPacketCheck.cpp TcPacketCheckPUS.cpp
TcPacketCheckCFDP.cpp
CFDPDistributor.cpp
) )

View File

@ -3,7 +3,7 @@
#include "PUSDistributorIF.h" #include "PUSDistributorIF.h"
#include "TcDistributor.h" #include "TcDistributor.h"
#include "TcPacketCheck.h" #include "TcPacketCheckPUS.h"
#include "fsfw/tmtcpacket/pus/tc.h" #include "fsfw/tmtcpacket/pus/tc.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
@ -43,7 +43,7 @@ protected:
/** /**
* This attribute contains the class, that performs a formal packet check. * This attribute contains the class, that performs a formal packet check.
*/ */
TcPacketCheck checker; TcPacketCheckPUS checker;
/** /**
* With this class, verification messages are sent to the * With this class, verification messages are sent to the
* TC Verification service. * TC Verification service.

View File

@ -1,4 +1,4 @@
#include "fsfw/tcdistribution/TcPacketCheck.h" #include "fsfw/tcdistribution/TcPacketCheckPUS.h"
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h" #include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h"
@ -7,10 +7,10 @@
#include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcservices/VerificationCodes.h" #include "fsfw/tmtcservices/VerificationCodes.h"
TcPacketCheck::TcPacketCheck(uint16_t setApid): apid(setApid) { TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid): apid(setApid) {
} }
ReturnValue_t TcPacketCheck::checkPacket(TcPacketStoredBase* currentPacket) { ReturnValue_t TcPacketCheckPUS::checkPacket(TcPacketStoredBase* currentPacket) {
TcPacketBase* tcPacketBase = currentPacket->getPacketBase(); TcPacketBase* tcPacketBase = currentPacket->getPacketBase();
if(tcPacketBase == nullptr) { if(tcPacketBase == nullptr) {
return RETURN_FAILED; return RETURN_FAILED;
@ -41,6 +41,6 @@ ReturnValue_t TcPacketCheck::checkPacket(TcPacketStoredBase* currentPacket) {
return RETURN_OK; return RETURN_OK;
} }
uint16_t TcPacketCheck::getApid() const { uint16_t TcPacketCheckPUS::getApid() const {
return apid; return apid;
} }

View File

@ -1,5 +1,7 @@
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ #ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ #define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#include "TcPacketCheckIF.h"
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
@ -12,7 +14,9 @@ class TcPacketStoredBase;
* Currently, it only checks if the APID and CRC are correct. * Currently, it only checks if the APID and CRC are correct.
* @ingroup tc_distribution * @ingroup tc_distribution
*/ */
class TcPacketCheck : public HasReturnvaluesIF { class TcPacketCheckPUS :
public TcPacketCheckIF,
public HasReturnvaluesIF {
protected: protected:
/** /**
* Describes the version number a packet must have to pass. * Describes the version number a packet must have to pass.
@ -49,18 +53,11 @@ public:
* The constructor only sets the APID attribute. * The constructor only sets the APID attribute.
* @param set_apid The APID to set. * @param set_apid The APID to set.
*/ */
TcPacketCheck(uint16_t setApid); TcPacketCheckPUS(uint16_t setApid);
/**
* This is the actual method to formally check a certain Telecommand Packet. ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket) override;
* The packet's Application Data can not be checked here.
* @param current_packet The packt to check
* @return - @c RETURN_OK on success.
* - @c INCORRECT_CHECKSUM if checksum is invalid.
* - @c ILLEGAL_APID if APID does not match.
*/
ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket);
uint16_t getApid() const; uint16_t getApid() const;
}; };
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ */ #endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */

View File

@ -0,0 +1,13 @@
#include "fsfw/tcdistribution/TcPacketCheckCFDP.h"
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
TcPacketCheckCFDP::TcPacketCheckCFDP(uint16_t setApid): apid(setApid) {
}
ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketBase* currentPacket) {
return RETURN_OK;
}
uint16_t TcPacketCheckCFDP::getApid() const {
return apid;
}

View File

@ -0,0 +1,35 @@
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_
#include "TcPacketCheckIF.h"
#include "fsfw/FSFW.h"
class CFDPPacketStored;
/**
* This class performs a formal packet check for incoming CFDP Packets.
* @ingroup tc_distribution
*/
class TcPacketCheckCFDP :
public TcPacketCheckIF,
public HasReturnvaluesIF {
protected:
/**
* The packet id each correct packet should have.
* It is composed of the APID and some static fields.
*/
uint16_t apid;
public:
/**
* The constructor only sets the APID attribute.
* @param set_apid The APID to set.
*/
TcPacketCheckCFDP(uint16_t setApid);
ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override;
uint16_t getApid() const;
};
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKCFDP_H_ */

View File

@ -0,0 +1,31 @@
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_
#include "../returnvalues/HasReturnvaluesIF.h"
class SpacePacketBase;
/**
* This interface is used by PacketCheckers for PUS packets and CFDP packets .
* @ingroup tc_distribution
*/
class TcPacketCheckIF {
public:
/**
* The empty virtual destructor.
*/
virtual ~TcPacketCheckIF() {
}
/**
* This is the actual method to formally check a certain Packet.
* The packet's Application Data can not be checked here.
* @param current_packet The packet to check
* @return - @c RETURN_OK on success.
* - @c INCORRECT_CHECKSUM if checksum is invalid.
* - @c ILLEGAL_APID if APID does not match.
*/
virtual ReturnValue_t checkPacket(SpacePacketBase* currentPacket) = 0;
};
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */

View File

@ -0,0 +1,48 @@
#include "fsfw/tcdistribution/TcPacketCheckPUS.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcservices/VerificationCodes.h"
TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid): apid(setApid) {
}
ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) {
TcPacketStoredBase* storedPacket = dynamic_cast<TcPacketStoredBase*>(currentPacket);
TcPacketBase* tcPacketBase = storedPacket->getPacketBase();
if(tcPacketBase == nullptr) {
return RETURN_FAILED;
}
uint16_t calculated_crc = CRC::crc16ccitt(tcPacketBase->getWholeData(),
tcPacketBase->getFullSize());
if (calculated_crc != 0) {
return INCORRECT_CHECKSUM;
}
bool condition = (not tcPacketBase->hasSecondaryHeader()) or
(tcPacketBase->getPacketVersionNumber() != CCSDS_VERSION_NUMBER) or
(not tcPacketBase->isTelecommand());
if (condition) {
return INCORRECT_PRIMARY_HEADER;
}
if (tcPacketBase->getAPID() != this->apid)
return ILLEGAL_APID;
if (not storedPacket->isSizeCorrect()) {
return INCOMPLETE_PACKET;
}
condition = (tcPacketBase->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) ||
(tcPacketBase->getPusVersionNumber() != PUS_VERSION_NUMBER);
if (condition) {
return INCORRECT_SECONDARY_HEADER;
}
return RETURN_OK;
}
uint16_t TcPacketCheckPUS::getApid() const {
return apid;
}

View File

@ -0,0 +1,63 @@
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#include "TcPacketCheckIF.h"
#include "fsfw/FSFW.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tmtcservices/PusVerificationReport.h"
class TcPacketStoredBase;
/**
* This class performs a formal packet check for incoming PUS Telecommand Packets.
* Currently, it only checks if the APID and CRC are correct.
* @ingroup tc_distribution
*/
class TcPacketCheckPUS :
public TcPacketCheckIF,
public HasReturnvaluesIF {
protected:
/**
* Describes the version number a packet must have to pass.
*/
static constexpr uint8_t CCSDS_VERSION_NUMBER = 0;
/**
* Describes the secondary header a packet must have to pass.
*/
static constexpr uint8_t CCSDS_SECONDARY_HEADER_FLAG = 0;
/**
* Describes the TC Packet PUS Version Number a packet must have to pass.
*/
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
static constexpr uint8_t PUS_VERSION_NUMBER = 2;
#else
static constexpr uint8_t PUS_VERSION_NUMBER = 1;
#endif
/**
* The packet id each correct packet should have.
* It is composed of the APID and some static fields.
*/
uint16_t apid;
public:
static const uint8_t INTERFACE_ID = CLASS_ID::TC_PACKET_CHECK;
static const ReturnValue_t ILLEGAL_APID = MAKE_RETURN_CODE( 0 );
static const ReturnValue_t INCOMPLETE_PACKET = MAKE_RETURN_CODE( 1 );
static const ReturnValue_t INCORRECT_CHECKSUM = MAKE_RETURN_CODE( 2 );
static const ReturnValue_t ILLEGAL_PACKET_TYPE = MAKE_RETURN_CODE( 3 );
static const ReturnValue_t ILLEGAL_PACKET_SUBTYPE = MAKE_RETURN_CODE( 4 );
static const ReturnValue_t INCORRECT_PRIMARY_HEADER = MAKE_RETURN_CODE( 5 );
static const ReturnValue_t INCORRECT_SECONDARY_HEADER = MAKE_RETURN_CODE( 6 );
/**
* The constructor only sets the APID attribute.
* @param set_apid The APID to set.
*/
TcPacketCheckPUS(uint16_t setApid);
ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override;
uint16_t getApid() const;
};
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */

View File

@ -3,5 +3,6 @@ target_sources(${LIB_FSFW_NAME} PRIVATE
SpacePacketBase.cpp SpacePacketBase.cpp
) )
add_subdirectory(cfdp)
add_subdirectory(packetmatcher) add_subdirectory(packetmatcher)
add_subdirectory(pus) add_subdirectory(pus)

View File

@ -0,0 +1,20 @@
#include "fsfw/tmtcpacket/cfdp/CFDPPacket.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <cstring>
CFDPPacket::CFDPPacket(const uint8_t* setData): SpacePacketBase(setData) {}
CFDPPacket::~CFDPPacket() {}
void CFDPPacket::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "CFDPPacket::print:" << std::endl;
#else
sif::printInfo("CFDPPacket::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -0,0 +1,27 @@
#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#include "fsfw/tmtcpacket/SpacePacketBase.h"
class CFDPPacket : public SpacePacketBase {
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
CFDPPacket( const uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~CFDPPacket();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
};
#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ */

View File

@ -0,0 +1,85 @@
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
#include "fsfw/objectmanager/ObjectManager.h"
StorageManagerIF* CFDPPacketStored::store = nullptr;
CFDPPacketStored::CFDPPacketStored(): CFDPPacket(nullptr) {
}
CFDPPacketStored::CFDPPacketStored(store_address_t setAddress): CFDPPacket(nullptr) {
this->setStoreAddress(setAddress);
}
CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size): CFDPPacket(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(storePtr);
}
}
ReturnValue_t CFDPPacketStored::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData(nullptr);
return result;
}
//CFDPPacket* CFDPPacketStored::getPacketBase() {
// return this;
//}
void CFDPPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
if (status == StorageManagerIF::RETURN_OK) {
this->setData(tempData);
}
else {
this->setData(nullptr);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
store_address_t CFDPPacketStored::getStoreAddress() {
return this->storeAddress;
}
bool CFDPPacketStored::checkAndSetStore() {
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!"
<< std::endl;
#endif
return false;
}
}
return true;
}
bool CFDPPacketStored::isSizeCorrect() {
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
}
return false;
}

View File

@ -0,0 +1,64 @@
#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_
#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_
#include "../pus/tc/TcPacketStoredBase.h"
#include "CFDPPacket.h"
class CFDPPacketStored:
public CFDPPacket {
public:
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
CFDPPacketStored(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
CFDPPacketStored(store_address_t setAddress);
CFDPPacketStored();
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize);
void setStoreAddress(store_address_t setAddress);
store_address_t getStoreAddress();
ReturnValue_t deletePacket();
private:
bool isSizeCorrect();
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
};
#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ */

View File

@ -0,0 +1,4 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
CFDPPacket.cpp
CFDPPacketStored.cpp
)

View File

@ -14,7 +14,6 @@
#include "fsfw/container/FIFO.h" #include "fsfw/container/FIFO.h"
#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"
class TcPacketStored;
class TcPacketStoredBase; class TcPacketStoredBase;
namespace Factory{ namespace Factory{

View File

@ -1,9 +1,9 @@
#include "fsfw_tests/internal/InternalUnitTester.h" #include "fsfw_tests/internal/InternalUnitTester.h"
#include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw_tests/internal/UnittDefinitions.h"
#include "fsfw_tests/internal/osal/IntTestMq.h" #include "fsfw_tests/internal/osal/testMq.h"
#include "fsfw_tests/internal/osal/IntTestSemaphore.h" #include "fsfw_tests/internal/osal/testSemaphore.h"
#include "fsfw_tests/internal/osal/IntTestMutex.h" #include "fsfw_tests/internal/osal/testMutex.h"
#include "fsfw_tests/internal/serialize/IntTestSerialization.h" #include "fsfw_tests/internal/serialize/IntTestSerialization.h"
#include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h" #include "fsfw_tests/internal/globalfunctions/TestArrayPrinter.h"

View File

@ -1,5 +1,5 @@
target_sources(${LIB_FSFW_NAME} PRIVATE target_sources(${LIB_FSFW_NAME} PRIVATE
IntTestMq.cpp testMq.cpp
IntTestMutex.cpp testMutex.cpp
IntTestSemaphore.cpp testSemaphore.cpp
) )

View File

@ -0,0 +1 @@
#include "testCmdExecutor.h"

View File

@ -0,0 +1,10 @@
#ifndef FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_
#define FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_
namespace testcmdexec {
}
#endif /* FSFW_TESTS_SRC_FSFW_TESTS_INTERNAL_OSAL_TESTCMDEXECUTOR_H_ */

View File

@ -1,4 +1,4 @@
#include "fsfw_tests/internal/osal/IntTestMq.h" #include "testMq.h"
#include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw_tests/internal/UnittDefinitions.h"
#include <fsfw/ipc/MessageQueueIF.h> #include <fsfw/ipc/MessageQueueIF.h>

View File

@ -1,4 +1,4 @@
#include "fsfw_tests/internal/osal/IntTestMutex.h" #include "testMutex.h"
#include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw_tests/internal/UnittDefinitions.h"
#include "fsfw/platform.h" #include "fsfw/platform.h"

View File

@ -1,5 +1,5 @@
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "fsfw_tests/internal/osal/IntTestSemaphore.h" #include "testSemaphore.h"
#include "fsfw_tests/internal/UnittDefinitions.h" #include "fsfw_tests/internal/UnittDefinitions.h"
#include "fsfw/tasks/SemaphoreFactory.h" #include "fsfw/tasks/SemaphoreFactory.h"

View File

@ -1,3 +1,16 @@
target_sources(${TARGET_NAME} PRIVATE
CatchDefinitions.cpp
CatchFactory.cpp
printChar.cpp
)
if(FSFW_CUSTOM_UNITTEST_RUNNER)
target_sources(${TARGET_NAME} PRIVATE
CatchRunner.cpp
CatchSetup.cpp
)
endif()
add_subdirectory(action) add_subdirectory(action)
add_subdirectory(container) add_subdirectory(container)
add_subdirectory(osal) add_subdirectory(osal)

View File

@ -1,17 +1,21 @@
#include "CatchFactory.h" #include "CatchFactory.h"
#include "datapoollocal/LocalPoolOwnerBase.h"
#include "mocks/HkReceiverMock.h"
#include <fsfw/datapoollocal/LocalDataPoolManager.h> #include <fsfw/datapoollocal/LocalDataPoolManager.h>
#include <fsfw/devicehandlers/DeviceHandlerBase.h> #include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/events/EventManager.h> #include <fsfw/events/EventManager.h>
#include <fsfw/health/HealthTable.h> #include <fsfw/health/HealthTable.h>
#include <fsfw/internalError/InternalErrorReporter.h> #include <fsfw/internalerror/InternalErrorReporter.h>
#include <fsfw/objectmanager/frameworkObjects.h> #include <fsfw/objectmanager/frameworkObjects.h>
#include <fsfw/storagemanager/PoolManager.h> #include <fsfw/storagemanager/PoolManager.h>
#include <fsfw/tmtcpacket/pus/tm/TmPacketStored.h> #include <fsfw/tmtcpacket/pus/tm/TmPacketStored.h>
#include <fsfw/tmtcservices/CommandingServiceBase.h> #include <fsfw/tmtcservices/CommandingServiceBase.h>
#include <fsfw/tmtcservices/PusServiceBase.h> #include <fsfw/tmtcservices/PusServiceBase.h>
#include <fsfw/unittest/tests/datapoollocal/LocalPoolOwnerBase.h>
#include <fsfw/unittest/tests/mocks/HkReceiverMock.h>
#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1
/** /**
* @brief Produces system objects. * @brief Produces system objects.
@ -26,7 +30,7 @@
* *
* @ingroup init * @ingroup init
*/ */
void Factory::produce(void) { void Factory::produceFrameworkObjects(void* args) {
setStaticFrameworkObjectIds(); setStaticFrameworkObjectIds();
new EventManager(objects::EVENT_MANAGER); new EventManager(objects::EVENT_MANAGER);
new HealthTable(objects::HEALTH_TABLE); new HealthTable(objects::HEALTH_TABLE);
@ -55,7 +59,6 @@ void Factory::produce(void) {
}; };
new PoolManager(objects::IPC_STORE, poolCfg); new PoolManager(objects::IPC_STORE, poolCfg);
} }
} }
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {
@ -77,5 +80,4 @@ void Factory::setStaticFrameworkObjectIds() {
TmPacketBase::timeStamperId = objects::NO_OBJECT; TmPacketBase::timeStamperId = objects::NO_OBJECT;
} }
#endif

View File

@ -0,0 +1,24 @@
#ifndef FSFW_CATCHFACTORY_H_
#define FSFW_CATCHFACTORY_H_
#include "TestConfig.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/objectmanager/ObjectManager.h"
// TODO: It is possible to solve this more cleanly using a special class which
// is allowed to set the object IDs and has virtual functions.
#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1
namespace Factory {
/**
* @brief Creates all SystemObject elements which are persistent
* during execution.
*/
void produceFrameworkObjects(void* args);
void setStaticFrameworkObjectIds();
}
#endif /* FSFW_ADD_DEFAULT_FSFW_FACTORY == 1 */
#endif /* FSFW_CATCHFACTORY_H_ */

View File

@ -6,7 +6,7 @@
* from the eclipse market place to get colored characters. * from the eclipse market place to get colored characters.
*/ */
#include <TestsConfig.h> #include "CatchRunner.h"
#define CATCH_CONFIG_COLOUR_WINDOWS #define CATCH_CONFIG_COLOUR_WINDOWS
@ -14,7 +14,7 @@
extern int customSetup(); extern int customSetup();
int main( int argc, char* argv[] ) { int fsfwtest::customMain(int argc, char* argv[]) {
customSetup(); customSetup();
// Catch internal function call // Catch internal function call

View File

@ -0,0 +1,14 @@
#ifndef FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_
#define FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_
namespace fsfwtest {
/**
* Can be called by upper level main() if default Catch2 main is overriden
* @return
*/
int customMain(int argc, char* argv[]);
}
#endif /* FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ */

View File

@ -5,10 +5,9 @@
#include <gcov.h> #include <gcov.h>
#endif #endif
#include <fsfw/objectmanager/ObjectManager.h> #include "fsfw/objectmanager/ObjectManager.h"
#include <fsfw/objectmanager/ObjectManagerIF.h> #include "fsfw/storagemanager/StorageManagerIF.h"
#include <fsfw/storagemanager/StorageManagerIF.h> #include "fsfw/serviceinterface/ServiceInterface.h"
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
/* Global instantiations normally done in main.cpp */ /* Global instantiations normally done in main.cpp */
@ -24,13 +23,11 @@ ServiceInterfaceStream warning("WARNING");
} }
#endif #endif
/* Global object manager */
ObjectManagerIF *objectManager;
int customSetup() { int customSetup() {
// global setup // global setup
objectManager = new ObjectManager(Factory::produce); ObjectManager* objMan = ObjectManager::instance();
objectManager -> initialize(); objMan->setObjectFactoryFunction(Factory::produceFrameworkObjects, nullptr);
objMan->initialize();
return 0; return 0;
} }

View File

@ -1,13 +1,10 @@
#include "TestActionHelper.h" #include "TestActionHelper.h"
#include "fsfw_tests/unit/mocks/MessageQueueMockBase.h"
#include <unittest/core/CatchDefinitions.h>
#include <fsfw/action/ActionHelper.h> #include <fsfw/action/ActionHelper.h>
#include <fsfw/ipc/CommandMessage.h> #include <fsfw/ipc/CommandMessage.h>
#include <fsfw/tests/unit/mocks/MessageQueueMockBase.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <array> #include <array>

View File

@ -1,12 +1,11 @@
#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_ #ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_ #define UNITTEST_HOSTED_TESTACTIONHELPER_H_
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/action/HasActionsIF.h> #include <fsfw/action/HasActionsIF.h>
#include <fsfw/ipc/MessageQueueIF.h> #include <fsfw/ipc/MessageQueueIF.h>
#include <unittest/core/CatchDefinitions.h>
#include <cstring> #include <cstring>
class ActionHelperOwnerMockBase: public HasActionsIF { class ActionHelperOwnerMockBase: public HasActionsIF {
public: public:
bool getCommandQueueCalled = false; bool getCommandQueueCalled = false;

View File

@ -1,4 +1,4 @@
#include <unittest/core/CatchDefinitions.h> #include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/SimpleRingBuffer.h> #include <fsfw/container/SimpleRingBuffer.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/ArrayList.h> #include <fsfw/container/ArrayList.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
/** /**
* @brief Array List test * @brief Array List test

View File

@ -1,9 +1,10 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/DynamicFIFO.h> #include <fsfw/container/DynamicFIFO.h>
#include <fsfw/container/FIFO.h> #include <fsfw/container/FIFO.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE( "Dynamic Fifo Tests", "[TestDynamicFifo]") { TEST_CASE( "Dynamic Fifo Tests", "[TestDynamicFifo]") {
INFO("Dynamic Fifo Tests"); INFO("Dynamic Fifo Tests");

View File

@ -1,9 +1,10 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/DynamicFIFO.h> #include <fsfw/container/DynamicFIFO.h>
#include <fsfw/container/FIFO.h> #include <fsfw/container/FIFO.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE( "Static Fifo Tests", "[TestFifo]") { TEST_CASE( "Static Fifo Tests", "[TestFifo]") {
INFO("Fifo Tests"); INFO("Fifo Tests");

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/FixedArrayList.h> #include <fsfw/container/FixedArrayList.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE( "FixedArrayList Tests", "[TestFixedArrayList]") { TEST_CASE( "FixedArrayList Tests", "[TestFixedArrayList]") {

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/FixedMap.h> #include <fsfw/container/FixedMap.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
template class FixedMap<unsigned int, unsigned short>; template class FixedMap<unsigned int, unsigned short>;

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/FixedOrderedMultimap.h> #include <fsfw/container/FixedOrderedMultimap.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE( "FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") { TEST_CASE( "FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") {
INFO("FixedOrderedMultimap Tests"); INFO("FixedOrderedMultimap Tests");

View File

@ -1,10 +1,11 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/container/PlacementFactory.h> #include <fsfw/container/PlacementFactory.h>
#include <fsfw/storagemanager/LocalPool.h> #include <fsfw/storagemanager/LocalPool.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/container/ArrayList.h> #include <fsfw/container/ArrayList.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") { TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
INFO("PlacementFactory Tests"); INFO("PlacementFactory Tests");

View File

@ -1,7 +1,5 @@
#include "LocalPoolOwnerBase.h" #include "LocalPoolOwnerBase.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h> #include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
@ -10,7 +8,8 @@
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/globalfunctions/bitutility.h> #include <fsfw/globalfunctions/bitutility.h>
#include <unittest/core/CatchDefinitions.h> #include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
TEST_CASE("DataSetTest" , "[DataSetTest]") { TEST_CASE("DataSetTest" , "[DataSetTest]") {
LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->

View File

@ -1,7 +1,5 @@
#include "LocalPoolOwnerBase.h" #include "LocalPoolOwnerBase.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
@ -10,7 +8,10 @@
#include <fsfw/housekeeping/HousekeepingSnapshot.h> #include <fsfw/housekeeping/HousekeepingSnapshot.h>
#include <fsfw/ipc/CommandMessageCleaner.h> #include <fsfw/ipc/CommandMessageCleaner.h>
#include <fsfw/timemanager/CCSDSTime.h> #include <fsfw/timemanager/CCSDSTime.h>
#include <unittest/core/CatchDefinitions.h>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <iostream> #include <iostream>

View File

@ -2,6 +2,7 @@
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"
#include "../mocks/MessageQueueMockBase.h"
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h> #include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
#include <fsfw/datapoollocal/LocalDataSet.h> #include <fsfw/datapoollocal/LocalDataSet.h>
@ -10,7 +11,6 @@
#include <fsfw/datapoollocal/LocalPoolVector.h> #include <fsfw/datapoollocal/LocalPoolVector.h>
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h> #include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/tests/unit/mocks/MessageQueueMockBase.h>
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
namespace lpool { namespace lpool {

View File

@ -1,10 +1,10 @@
#include "LocalPoolOwnerBase.h" #include "LocalPoolOwnerBase.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <catch2/catch_test_macros.hpp>
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h> #include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
#include <unittest/core/CatchDefinitions.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") { TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") {
LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->

View File

@ -1,9 +1,10 @@
#include "LocalPoolOwnerBase.h" #include "LocalPoolOwnerBase.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h> #include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
#include <unittest/core/CatchDefinitions.h>
TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") { TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") {
LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> LocalPoolOwnerBase* poolOwner = ObjectManager::instance()->

View File

@ -1,2 +1,3 @@
target_sources(${TARGET_NAME} PRIVATE target_sources(${TARGET_NAME} PRIVATE
testDleEncoder.cpp
) )

View File

@ -0,0 +1,62 @@
#include "fsfw/globalfunctions/DleEncoder.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
#include "catch2/catch_test_macros.hpp"
#include <array>
const std::array<uint8_t, 5> TEST_ARRAY_0 = { 0 };
const std::array<uint8_t, 3> TEST_ARRAY_1 = { 0, DleEncoder::DLE_CHAR, 5};
const std::array<uint8_t, 3> TEST_ARRAY_2 = { 0, DleEncoder::STX_CHAR, 5};
const std::array<uint8_t, 3> TEST_ARRAY_3 = { 0, DleEncoder::CARRIAGE_RETURN, DleEncoder::ETX_CHAR};
TEST_CASE("DleEncoder" , "[DleEncoder]") {
DleEncoder dleEncoder;
std::array<uint8_t, 32> buffer;
SECTION("Encoding") {
size_t encodedLen = 0;
ReturnValue_t result = dleEncoder.encode(TEST_ARRAY_0.data(), TEST_ARRAY_0.size(),
buffer.data(), buffer.size(), &encodedLen);
REQUIRE(result == retval::CATCH_OK);
std::vector<uint8_t> expected = {DleEncoder::STX_CHAR, 0, 0, 0, 0, 0,
DleEncoder::ETX_CHAR};
for(size_t idx = 0; idx < expected.size(); idx++) {
REQUIRE(buffer[idx] == expected[idx]);
}
REQUIRE(encodedLen == 7);
result = dleEncoder.encode(TEST_ARRAY_1.data(), TEST_ARRAY_1.size(),
buffer.data(), buffer.size(), &encodedLen);
REQUIRE(result == retval::CATCH_OK);
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR,
DleEncoder::DLE_CHAR, 5, DleEncoder::ETX_CHAR};
for(size_t idx = 0; idx < expected.size(); idx++) {
REQUIRE(buffer[idx] == expected[idx]);
}
REQUIRE(encodedLen == expected.size());
result = dleEncoder.encode(TEST_ARRAY_2.data(), TEST_ARRAY_2.size(),
buffer.data(), buffer.size(), &encodedLen);
REQUIRE(result == retval::CATCH_OK);
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::DLE_CHAR,
DleEncoder::STX_CHAR + 0x40, 5, DleEncoder::ETX_CHAR};
for(size_t idx = 0; idx < expected.size(); idx++) {
REQUIRE(buffer[idx] == expected[idx]);
}
REQUIRE(encodedLen == expected.size());
result = dleEncoder.encode(TEST_ARRAY_3.data(), TEST_ARRAY_3.size(),
buffer.data(), buffer.size(), &encodedLen);
REQUIRE(result == retval::CATCH_OK);
expected = std::vector<uint8_t>{DleEncoder::STX_CHAR, 0, DleEncoder::CARRIAGE_RETURN,
DleEncoder::DLE_CHAR, DleEncoder::ETX_CHAR + 0x40, DleEncoder::ETX_CHAR};
for(size_t idx = 0; idx < expected.size(); idx++) {
REQUIRE(buffer[idx] == expected[idx]);
}
REQUIRE(encodedLen == expected.size());
}
SECTION("Decoding") {
}
}

View File

@ -1,9 +1,12 @@
#ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ #ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
#define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ #define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
#include <fsfw/ipc/MessageQueueIF.h> #include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/ipc/MessageQueueMessage.h>
#include <unittest/core/CatchDefinitions.h> #include "fsfw/ipc/CommandMessage.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/ipc/MessageQueueMessage.h"
#include <cstring> #include <cstring>
#include <queue> #include <queue>

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/ipc/MessageQueueIF.h> #include <fsfw/ipc/MessageQueueIF.h>
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array> #include <array>

View File

@ -1,7 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/serialize/SerialBufferAdapter.h> #include <fsfw/serialize/SerialBufferAdapter.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array> #include <array>

View File

@ -1,10 +1,9 @@
#include "TestSerialLinkedPacket.h" #include "TestSerialLinkedPacket.h"
#include <unittest/core/CatchDefinitions.h> #include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/globalfunctions/arrayprinter.h> #include <fsfw/globalfunctions/arrayprinter.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array> #include <array>

View File

@ -1,8 +1,8 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/serialize/SerializeAdapter.h> #include <fsfw/serialize/SerializeAdapter.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp> #include <catch2/catch_approx.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array> #include <array>

View File

@ -1,6 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/storagemanager/LocalPool.h> #include <fsfw/storagemanager/LocalPool.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <array> #include <array>
#include <cstring> #include <cstring>

View File

@ -1,8 +1,9 @@
#include "fsfw_tests/unit/CatchDefinitions.h"
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/storagemanager/LocalPool.h> #include <fsfw/storagemanager/LocalPool.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <unittest/core/CatchDefinitions.h>
#include <cstring> #include <cstring>

View File

@ -32,7 +32,7 @@ if(NOT FSFW_OSAL)
set(FSFW_OSAL host CACHE STRING "OS for the FSFW.") set(FSFW_OSAL host CACHE STRING "OS for the FSFW.")
endif() endif()
option(CUSTOM_UNITTEST_RUNNER option(FSFW_CUSTOM_UNITTEST_RUNNER
"Specify whether custom main or Catch2 main is used" TRUE "Specify whether custom main or Catch2 main is used" TRUE
) )
@ -49,7 +49,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# Set names and variables # Set names and variables
set(TARGET_NAME ${CMAKE_PROJECT_NAME}) set(TARGET_NAME ${CMAKE_PROJECT_NAME})
if(CUSTOM_UNITTEST_RUNNER) if(FSFW_CUSTOM_UNITTEST_RUNNER)
set(CATCH2_TARGET Catch2) set(CATCH2_TARGET Catch2)
else() else()
set(CATCH2_TARGET Catch2WithMain) set(CATCH2_TARGET Catch2WithMain)

View File

@ -1,6 +1,8 @@
#ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ #ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_
#define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ #define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_
#define FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS 1
#ifdef __cplusplus #ifdef __cplusplus
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"

View File

@ -1 +0,0 @@
add_subdirectory(core)

View File

@ -1,13 +0,0 @@
target_sources(${TARGET_NAME} PRIVATE
CatchDefinitions.cpp
CatchFactory.cpp
CatchRunner.cpp
CatchSetup.cpp
printChar.cpp
)
if(CUSTOM_UNITTEST_RUNNER)
target_sources(${TARGET_NAME} PRIVATE
CatchRunner.cpp
)
endif()

View File

@ -1,16 +0,0 @@
#ifndef FSFW_CATCHFACTORY_H_
#define FSFW_CATCHFACTORY_H_
#include <fsfw/objectmanager/SystemObjectIF.h>
namespace Factory {
/**
* @brief Creates all SystemObject elements which are persistent
* during execution.
*/
void produce(void* args);
void setStaticFrameworkObjectIds();
}
#endif /* FSFW_CATCHFACTORY_H_ */

View File

@ -1,3 +0,0 @@
CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp)
INCLUDES += $(CURRENTPATH)