mueller/master #37

Closed
muellerr wants to merge 126 commits from mueller/master into eive/develop
42 changed files with 1440 additions and 249 deletions

@ -151,8 +151,6 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
// The MSP configuration struct is not required anymore
spiCookie->deleteMspCfg();
return HasReturnvaluesIF::RETURN_OK;
}

@ -59,12 +59,6 @@ spi::MspCfgBase* SpiCookie::getMspCfg() {
return mspCfg;
}
void SpiCookie::deleteMspCfg() {
if(mspCfg != nullptr) {
delete mspCfg;
}
}
spi::TransferModes SpiCookie::getTransferMode() const {
return transferMode;
}

@ -69,7 +69,6 @@ private:
// Only the SpiComIF is allowed to use this to prevent dangling pointers issues
spi::MspCfgBase* getMspCfg();
void deleteMspCfg();
void setTransferState(spi::TransferStates transferState);
spi::TransferStates getTransferState() const;

@ -22,7 +22,7 @@ using mspCb = void (*) (void);
namespace spi {
struct MspCfgBase {
MspCfgBase();
MspCfgBase() {};
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),

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

@ -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();
}

@ -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_ */

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

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

@ -15,6 +15,7 @@ target_sources(${LIB_FSFW_NAME}
TaskFactory.cpp
tcpipHelpers.cpp
unixUtility.cpp
CommandExecutor.cpp
)
find_package(Threads REQUIRED)

@ -0,0 +1,210 @@
#include "CommandExecutor.h"
#include "fsfw/serviceinterface.h"
#include "fsfw/container/SimpleRingBuffer.h"
#include "fsfw/container/DynamicFIFO.h"
#include <unistd.h>
#include <cstring>
CommandExecutor::CommandExecutor(const size_t maxSize):
readVec(maxSize) {
waiter.events = POLLIN;
}
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
if(state == States::PENDING) {
return COMMAND_PENDING;
}
currentCmd = command;
this->blocking = blocking;
this->printOutput = printOutput;
if(state == States::IDLE) {
state = States::COMMAND_LOADED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CommandExecutor::execute() {
if(state == States::IDLE) {
return NO_COMMAND_LOADED_OR_PENDING;
}
else if(state == States::PENDING) {
return COMMAND_PENDING;
}
currentCmdFile = popen(currentCmd.c_str(), "r");
if(currentCmdFile == nullptr) {
lastError = errno;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(blocking) {
return executeBlocking();
}
else {
currentFd = fileno(currentCmdFile);
waiter.fd = currentFd;
}
state = States::PENDING;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CommandExecutor::close() {
if(state == States::PENDING) {
// Attempt to close process, irrespective of if it is running or not
if(currentCmdFile != nullptr) {
pclose(currentCmdFile);
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void CommandExecutor::printLastError(std::string funcName) const {
if(lastError != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << funcName << " pclose failed with code " <<
lastError << ": " << strerror(lastError) << std::endl;
#else
sif::printError("%s pclose failed with code %d: %s", funcName, lastError,
strerror(lastError));
#endif
}
}
void CommandExecutor::setRingBuffer(SimpleRingBuffer *ringBuffer,
DynamicFIFO<uint16_t>* sizesFifo) {
this->ringBuffer = ringBuffer;
this->sizesFifo = sizesFifo;
}
ReturnValue_t CommandExecutor::check(bool& bytesRead) {
if(blocking) {
return HasReturnvaluesIF::RETURN_OK;
}
switch(state) {
case(States::IDLE):
case(States::COMMAND_LOADED): {
return NO_COMMAND_LOADED_OR_PENDING;
}
case(States::PENDING): {
break;
}
}
int result = poll(&waiter, 1, 0);
switch(result) {
case(0): {
return HasReturnvaluesIF::RETURN_OK;
break;
}
case(1): {
if (waiter.revents & POLLIN) {
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
if(readBytes == 0) {
// Should not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecutor::check: "
"No bytes read after poll event.." << std::endl;
#else
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
#endif
break;
}
else if(readBytes > 0) {
bytesRead = true;
if(printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// It is assumed the command output is line terminated
sif::info << currentCmd << " | " << readVec.data();
#else
sif::printInfo("%s | %s", currentCmd, readVec.data());
#endif
}
if(ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
readVec.data()), readBytes);
}
if(sizesFifo != nullptr) {
if(not sizesFifo->full()) {
sizesFifo->insert(readBytes);
}
}
return BYTES_READ;
}
else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
// Should also not happen
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
strerror(errno) << std::endl;
#else
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
#endif
}
}
else if(waiter.revents & POLLERR) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
#else
sif::printWarning("CommandExecuter::check: Poll error\n");
#endif
return COMMAND_ERROR;
}
else if(waiter.revents & POLLHUP) {
result = pclose(currentCmdFile);
if(result != 0) {
lastError = result;
return HasReturnvaluesIF::RETURN_FAILED;
}
state = States::IDLE;
currentCmdFile = nullptr;
currentFd = 0;
return EXECUTION_FINISHED;
}
break;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void CommandExecutor::reset() {
CommandExecutor::close();
currentCmdFile = nullptr;
currentFd = 0;
state = States::IDLE;
}
int CommandExecutor::getLastError() const {
return this->lastError;
}
CommandExecutor::States CommandExecutor::getCurrentState() const {
return state;
}
ReturnValue_t CommandExecutor::executeBlocking() {
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
std::string output(readVec.data());
if(printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << currentCmd << " | " << output;
#else
sif::printInfo("%s | %s", currentCmd, output);
#endif
}
if(ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
}
if(sizesFifo != nullptr) {
if(not sizesFifo->full()) {
sizesFifo->insert(output.size());
}
}
}
int result = pclose(currentCmdFile);
if(result != 0) {
lastError = result;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}

@ -0,0 +1,134 @@
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include <poll.h>
#include <string>
#include <vector>
class SimpleRingBuffer;
template <typename T> class DynamicFIFO;
/**
* @brief Helper class to execute shell commands in blocking and non-blocking mode
* @details
* This class is able to execute processes by using the Linux popen call. It also has the
* capability of writing the read output of a process into a provided ring buffer.
*
* The executor works by first loading the command which should be executed and specifying
* whether it should be executed blocking or non-blocking. After that, execution can be started
* with the execute command. In blocking mode, the execute command will block until the command
* has finished
*/
class CommandExecutor {
public:
enum class States {
IDLE,
COMMAND_LOADED,
PENDING
};
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
//! [EXPORT] : [COMMENT] Execution of the current command has finished
static constexpr ReturnValue_t EXECUTION_FINISHED =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
//! to load another command but a command is still pending
static constexpr ReturnValue_t COMMAND_PENDING =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
static constexpr ReturnValue_t BYTES_READ =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
//! [EXPORT] : [COMMENT] Command execution failed
static constexpr ReturnValue_t COMMAND_ERROR =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
//! [EXPORT] : [COMMENT]
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
static constexpr ReturnValue_t PCLOSE_CALL_ERROR =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
/**
* Constructor. Is initialized with maximum size of internal buffer to read data from the
* executed process.
* @param maxSize
*/
CommandExecutor(const size_t maxSize);
/**
* Load a new command which should be executed
* @param command
* @param blocking
* @param printOutput
* @return
*/
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
/**
* Execute the loaded command.
* @return
* - In blocking mode, it will return RETURN_FAILED if
* the result of the system call was not 0. The error value can be accessed using
* getLastError
* - In non-blocking mode, this call will start
* the execution and then return RETURN_OK
*/
ReturnValue_t execute();
/**
* Only used in non-blocking mode. Checks the currently running command.
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
* @return
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
* check again after this
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
* - EXECUTION_FINISHED if the process was executed successfully
* - COMMAND_ERROR internal poll error
*/
ReturnValue_t check(bool& bytesRead);
/**
* Abort the current command. Should normally not be necessary, check can be used to find
* out whether command execution was successful
* @return RETURN_OK
*/
ReturnValue_t close();
States getCurrentState() const;
int getLastError() const;
void printLastError(std::string funcName) const;
/**
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
* read from the started process
* @param ringBuffer
* @param sizesFifo
*/
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
/**
* Reset the executor. This calls close internally and then reset the state machine so new
* commands can be loaded and executed
*/
void reset();
private:
std::string currentCmd;
bool blocking = true;
FILE* currentCmdFile = nullptr;
int currentFd = 0;
bool printOutput = true;
std::vector<char> readVec;
struct pollfd waiter {};
SimpleRingBuffer* ringBuffer = nullptr;
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
States state = States::IDLE;
int lastError = 0;
ReturnValue_t executeBlocking();
};
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */

@ -0,0 +1,55 @@
#include "fsfw/osal/linux/Timer.h"
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
#include <errno.h>
Timer::Timer() {
sigevent sigEvent;
sigEvent.sigev_notify = SIGEV_NONE;
sigEvent.sigev_signo = 0;
sigEvent.sigev_value.sival_ptr = &timerId;
int status = timer_create(CLOCK_MONOTONIC, &sigEvent, &timerId);
if(status!=0){
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Timer creation failed with: " << status <<
" errno: " << errno << std::endl;
#endif
}
}
Timer::~Timer() {
timer_delete(timerId);
}
int Timer::setTimer(uint32_t intervalMs) {
itimerspec timer;
timer.it_value.tv_sec = intervalMs / 1000;
timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000);
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = 0;
set = true;
return timer_settime(timerId, 0, &timer, NULL);
}
int Timer::getTimer(uint32_t* remainingTimeMs){
itimerspec timer;
timer.it_value.tv_sec = 0;
timer.it_value.tv_nsec = 0;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = 0;
int status = timer_gettime(timerId, &timer);
*remainingTimeMs = timer.it_value.tv_sec * 1000 + timer.it_value.tv_nsec / 1000000;
return status;
}
bool Timer::isSet() const {
return this->set;
}
void Timer::resetTimer() {
set = false;
setTimer(0);
}

@ -0,0 +1,49 @@
#ifndef FRAMEWORK_OSAL_LINUX_TIMER_H_
#define FRAMEWORK_OSAL_LINUX_TIMER_H_
#include <signal.h>
#include <time.h>
#include <stdint.h>
/**
* This class is a helper for the creation of a Clock Monotonic timer which does not trigger a signal
*/
class Timer {
public:
/**
* Creates the Timer sets the timerId Member
*/
Timer();
/**
* Deletes the timer
*
* Careful! According to POSIX documentation:
* The treatment of any pending signal generated by the deleted timer is unspecified.
*/
virtual ~Timer();
/**
* Set the timer given in timerId to the given interval
*
* @param intervalMs Interval in ms to be set
* @return 0 on Success 1 else
*/
int setTimer(uint32_t intervalMs);
/**
* Get the remaining time of the timer
*
* @param remainingTimeMs Pointer to integer value which is used to return the remaining time
* @return 0 on Success 1 else (see timer_getime documentation of posix function)
*/
int getTimer(uint32_t* remainingTimeMs);
bool isSet() const;
void resetTimer();
private:
bool set = true;
timer_t timerId;
};
#endif /* FRAMEWORK_OSAL_LINUX_TIMER_H_ */

@ -7,8 +7,8 @@
#define CCSDS_DISTRIBUTOR_DEBUGGING 0
CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid,
object_id_t setObjectId):
TcDistributor(setObjectId), defaultApid( setDefaultApid ) {
object_id_t setObjectId):
TcDistributor(setObjectId), defaultApid( setDefaultApid ) {
}
CCSDSDistributor::~CCSDSDistributor() {}
@ -16,97 +16,97 @@ CCSDSDistributor::~CCSDSDistributor() {}
TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() {
#if CCSDS_DISTRIBUTOR_DEBUGGING == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CCSDSDistributor::selectDestination received: " <<
this->currentMessage.getStorageId().poolIndex << ", " <<
this->currentMessage.getStorageId().packetIndex << std::endl;
sif::debug << "CCSDSDistributor::selectDestination received: " <<
this->currentMessage.getStorageId().poolIndex << ", " <<
this->currentMessage.getStorageId().packetIndex << std::endl;
#else
sif::printDebug("CCSDSDistributor::selectDestination received: %d, %d\n",
currentMessage.getStorageId().poolIndex, currentMessage.getStorageId().packetIndex);
sif::printDebug("CCSDSDistributor::selectDestination received: %d, %d\n",
currentMessage.getStorageId().poolIndex, currentMessage.getStorageId().packetIndex);
#endif
#endif
const uint8_t* packet = nullptr;
size_t size = 0;
ReturnValue_t result = this->tcStore->getData(currentMessage.getStorageId(),
&packet, &size );
if(result != HasReturnvaluesIF::RETURN_OK) {
const uint8_t* packet = nullptr;
size_t size = 0;
ReturnValue_t result = this->tcStore->getData(currentMessage.getStorageId(),
&packet, &size );
if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CCSDSDistributor::selectDestination: Getting data from"
" store failed!" << std::endl;
sif::error << "CCSDSDistributor::selectDestination: Getting data from"
" store failed!" << std::endl;
#else
sif::printError("CCSDSDistributor::selectDestination: Getting data from"
sif::printError("CCSDSDistributor::selectDestination: Getting data from"
" store failed!\n");
#endif
#endif
}
SpacePacketBase currentPacket(packet);
}
SpacePacketBase currentPacket(packet);
#if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1
sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex <<
currentPacket.getAPID() << std::dec << std::endl;
sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex <<
currentPacket.getAPID() << std::dec << std::endl;
#endif
TcMqMapIter position = this->queueMap.find(currentPacket.getAPID());
if ( position != this->queueMap.end() ) {
return position;
} else {
//The APID was not found. Forward packet to main SW-APID anyway to
// create acceptance failure report.
return this->queueMap.find( this->defaultApid );
}
TcMqMapIter position = this->queueMap.find(currentPacket.getAPID());
if ( position != this->queueMap.end() ) {
return position;
} else {
//The APID was not found. Forward packet to main SW-APID anyway to
// create acceptance failure report.
return this->queueMap.find( this->defaultApid );
}
}
MessageQueueId_t CCSDSDistributor::getRequestQueue() {
return tcQueue->getId();
return tcQueue->getId();
}
ReturnValue_t CCSDSDistributor::registerApplication(
AcceptsTelecommandsIF* application) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(application->getIdentifier(),
application->getRequestQueue());
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
AcceptsTelecommandsIF* application) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(application->getIdentifier(),
application->getRequestQueue());
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
}
ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid,
MessageQueueId_t id) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(apid, id);
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
MessageQueueId_t id) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(apid, id);
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
}
uint16_t CCSDSDistributor::getIdentifier() {
return 0;
return 0;
}
ReturnValue_t CCSDSDistributor::initialize() {
ReturnValue_t status = this->TcDistributor::initialize();
this->tcStore = ObjectManager::instance()->get<StorageManagerIF>( objects::TC_STORE );
if (this->tcStore == nullptr) {
ReturnValue_t status = this->TcDistributor::initialize();
this->tcStore = ObjectManager::instance()->get<StorageManagerIF>( objects::TC_STORE );
if (this->tcStore == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CCSDSDistributor::initialize: Could not initialize"
" TC store!" << std::endl;
sif::error << "CCSDSDistributor::initialize: Could not initialize"
" TC store!" << std::endl;
#else
sif::printError("CCSDSDistributor::initialize: Could not initialize"
sif::printError("CCSDSDistributor::initialize: Could not initialize"
" TC store!\n");
#endif
#endif
status = RETURN_FAILED;
}
return status;
status = RETURN_FAILED;
}
return status;
}
ReturnValue_t CCSDSDistributor::callbackAfterSending(
ReturnValue_t queueStatus) {
if (queueStatus != RETURN_OK) {
tcStore->deleteData(currentMessage.getStorageId());
}
return RETURN_OK;
ReturnValue_t queueStatus) {
if (queueStatus != RETURN_OK) {
tcStore->deleteData(currentMessage.getStorageId());
}
return RETURN_OK;
}

@ -15,56 +15,57 @@
* The Secondary Header (with Service/Subservice) is ignored.
* @ingroup tc_distribution
*/
class CCSDSDistributor : public TcDistributor,
public CCSDSDistributorIF,
public AcceptsTelecommandsIF {
class CCSDSDistributor:
public TcDistributor,
public CCSDSDistributorIF,
public AcceptsTelecommandsIF {
public:
/**
* @brief The constructor sets the default APID and calls the
* TcDistributor ctor with a certain object id.
* @details
* @c tcStore is set in the @c initialize method.
* @param setDefaultApid The default APID, where packets with unknown
* destination are sent to.
*/
CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId);
/**
* The destructor is empty.
*/
virtual ~CCSDSDistributor();
/**
* @brief The constructor sets the default APID and calls the
* TcDistributor ctor with a certain object id.
* @details
* @c tcStore is set in the @c initialize method.
* @param setDefaultApid The default APID, where packets with unknown
* destination are sent to.
*/
CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId);
/**
* The destructor is empty.
*/
virtual ~CCSDSDistributor();
MessageQueueId_t getRequestQueue() override;
ReturnValue_t registerApplication( uint16_t apid,
MessageQueueId_t id) override;
ReturnValue_t registerApplication(
AcceptsTelecommandsIF* application) override;
uint16_t getIdentifier() override;
ReturnValue_t initialize() override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t registerApplication( uint16_t apid,
MessageQueueId_t id) override;
ReturnValue_t registerApplication(
AcceptsTelecommandsIF* application) override;
uint16_t getIdentifier() override;
ReturnValue_t initialize() override;
protected:
/**
* This implementation checks if an application with fitting APID has
* registered and forwards the packet to the according message queue.
* If the packet is not found, it returns the queue to @c defaultApid,
* where a Acceptance Failure message should be generated.
* @return Iterator to map entry of found APID or iterator to default APID.
*/
TcMqMapIter selectDestination() override;
/**
* This implementation checks if an application with fitting APID has
* registered and forwards the packet to the according message queue.
* If the packet is not found, it returns the queue to @c defaultApid,
* where a Acceptance Failure message should be generated.
* @return Iterator to map entry of found APID or iterator to default APID.
*/
TcMqMapIter selectDestination() override;
/**
* The callback here handles the generation of acceptance
* success/failure messages.
*/
ReturnValue_t callbackAfterSending( ReturnValue_t queueStatus ) override;
/**
* The default APID, where packets with unknown APID are sent to.
*/
uint16_t defaultApid;
/**
* A reference to the TC storage must be maintained, as this class handles
* pure Space Packets and there exists no SpacePacketStored class.
*/
StorageManagerIF* tcStore = nullptr;
/**
* The default APID, where packets with unknown APID are sent to.
*/
uint16_t defaultApid;
/**
* A reference to the TC storage must be maintained, as this class handles
* pure Space Packets and there exists no SpacePacketStored class.
*/
StorageManagerIF* tcStore = nullptr;
};

@ -13,31 +13,30 @@
*/
class CCSDSDistributorIF {
public:
/**
* With this call, a class implementing the CCSDSApplicationIF can register
* at the distributor.
* @param application A pointer to the Application to register.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerApplication(
AcceptsTelecommandsIF* application) = 0;
/**
* With this call, other Applications can register to the CCSDS distributor.
* This is done by passing an APID and a MessageQueueId to the method.
* @param apid The APID to register.
* @param id The MessageQueueId of the message queue to send the
* TC Packets to.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerApplication( uint16_t apid,
MessageQueueId_t id) = 0;
/**
* The empty virtual destructor.
*/
virtual ~CCSDSDistributorIF() {
}
/**
* With this call, a class implementing the CCSDSApplicationIF can register
* at the distributor.
* @param application A pointer to the Application to register.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerApplication(
AcceptsTelecommandsIF* application) = 0;
/**
* With this call, other Applications can register to the CCSDS distributor.
* This is done by passing an APID and a MessageQueueId to the method.
* @param apid The APID to register.
* @param id The MessageQueueId of the message queue to send the
* TC Packets to.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerApplication( uint16_t apid,
MessageQueueId_t id) = 0;
/**
* The empty virtual destructor.
*/
virtual ~CCSDSDistributorIF() {}
};

@ -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);
}

@ -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_ */

@ -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_ */

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

@ -30,19 +30,19 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() {
if(tcStatus != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
const char* keyword = "unnamed error";
if(tcStatus == TcPacketCheck::INCORRECT_CHECKSUM) {
if(tcStatus == TcPacketCheckPUS::INCORRECT_CHECKSUM) {
keyword = "checksum";
}
else if(tcStatus == TcPacketCheck::INCORRECT_PRIMARY_HEADER) {
else if(tcStatus == TcPacketCheckPUS::INCORRECT_PRIMARY_HEADER) {
keyword = "incorrect primary header";
}
else if(tcStatus == TcPacketCheck::ILLEGAL_APID) {
else if(tcStatus == TcPacketCheckPUS::ILLEGAL_APID) {
keyword = "illegal APID";
}
else if(tcStatus == TcPacketCheck::INCORRECT_SECONDARY_HEADER) {
else if(tcStatus == TcPacketCheckPUS::INCORRECT_SECONDARY_HEADER) {
keyword = "incorrect secondary header";
}
else if(tcStatus == TcPacketCheck::INCOMPLETE_PACKET) {
else if(tcStatus == TcPacketCheckPUS::INCOMPLETE_PACKET) {
keyword = "incomplete packet";
}
#if FSFW_CPP_OSTREAM_ENABLED == 1

@ -3,7 +3,7 @@
#include "PUSDistributorIF.h"
#include "TcDistributor.h"
#include "TcPacketCheck.h"
#include "TcPacketCheckPUS.h"
#include "fsfw/tmtcpacket/pus/tc.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
@ -17,65 +17,65 @@
* @ingroup tc_distribution
*/
class PUSDistributor: public TcDistributor,
public PUSDistributorIF,
public AcceptsTelecommandsIF {
public PUSDistributorIF,
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.
*/
PUSDistributor(uint16_t setApid, object_id_t setObjectId,
object_id_t setPacketSource);
/**
* The destructor is empty.
*/
virtual ~PUSDistributor();
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t initialize() override;
uint16_t getIdentifier() override;
/**
* 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.
*/
PUSDistributor(uint16_t setApid, object_id_t setObjectId,
object_id_t setPacketSource);
/**
* The destructor is empty.
*/
virtual ~PUSDistributor();
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t initialize() override;
uint16_t getIdentifier() override;
protected:
/**
* This attribute contains the class, that performs a formal packet check.
*/
TcPacketCheck checker;
/**
* With this class, verification messages are sent to the
* TC Verification service.
*/
VerificationReporter verifyChannel;
/**
* The currently handled packet is stored here.
*/
TcPacketStoredPus* currentPacket = nullptr;
/**
* This attribute contains the class, that performs a formal packet check.
*/
TcPacketCheckPUS checker;
/**
* With this class, verification messages are sent to the
* TC Verification service.
*/
VerificationReporter verifyChannel;
/**
* The currently handled packet is stored here.
*/
TcPacketStoredPus* currentPacket = nullptr;
/**
* With this variable, the current check status is stored to generate
* acceptance messages later.
*/
ReturnValue_t tcStatus;
/**
* With this variable, the current check status is stored to generate
* acceptance messages later.
*/
ReturnValue_t tcStatus;
const object_id_t packetSource;
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;
/**
* 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_PUSDISTRIBUTOR_H_ */

@ -10,18 +10,18 @@
*/
class PUSDistributorIF {
public:
/**
* The empty virtual destructor.
*/
virtual ~PUSDistributorIF() {
}
/**
* With this method, Services can register themselves at the PUS Distributor.
* @param service A pointer to the registering Service.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerService( AcceptsTelecommandsIF* service ) = 0;
/**
* The empty virtual destructor.
*/
virtual ~PUSDistributorIF() {
}
/**
* With this method, Services can register themselves at the PUS Distributor.
* @param service A pointer to the registering Service.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerService( AcceptsTelecommandsIF* service ) = 0;
};
#endif /* FSFW_TCDISTRIBUTION_PUSDISTRIBUTORIF_H_ */

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

@ -1,5 +1,7 @@
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_
#ifndef FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#define FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_
#include "TcPacketCheckIF.h"
#include "fsfw/FSFW.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
@ -12,7 +14,9 @@ class TcPacketStoredBase;
* Currently, it only checks if the APID and CRC are correct.
* @ingroup tc_distribution
*/
class TcPacketCheck : public HasReturnvaluesIF {
class TcPacketCheckPUS :
public TcPacketCheckIF,
public HasReturnvaluesIF {
protected:
/**
* Describes the version number a packet must have to pass.
@ -49,18 +53,11 @@ public:
* The constructor only sets the APID attribute.
* @param set_apid The APID to set.
*/
TcPacketCheck(uint16_t setApid);
/**
* This is the actual method to formally check a certain Telecommand Packet.
* 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);
TcPacketCheckPUS(uint16_t setApid);
ReturnValue_t checkPacket(TcPacketStoredBase* currentPacket) override;
uint16_t getApid() const;
};
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECK_H_ */
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKPUS_H_ */

@ -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;
}

@ -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_ */

@ -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_ */

@ -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;
}

@ -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_ */

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

@ -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());
}

@ -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_ */

@ -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;
}

@ -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_ */

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

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

@ -20,4 +20,4 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${FSFW_TEST_TGT} PRIVATE
events/translateEvents.cpp
)
endif()
endif()

@ -1,15 +0,0 @@
#ifndef CONFIG_TMTC_TMTCSIZE_H_
#define CONFIG_TMTC_TMTCSIZE_H_
#include <cstdint>
#include <cstddef>
#define OBSW_PRINT_MISSED_DEADLINES 0
#define OBSW_VERBOSE_LEVEL 0
#define OBSW_ADD_TEST_CODE 1
namespace config {
static constexpr uint32_t MAX_STORED_TELECOMMANDS = 2000;
}
#endif /* CONFIG_TMTC_TMTCSIZE_H_ */

@ -5,7 +5,7 @@
#ifdef __cplusplus
#include "objects/systemObjectList.h"
#include "objects/testObjectList.h"
#include "events/subsystemIdRanges.h"
#include "returnvalues/classIds.h"

@ -11,17 +11,17 @@ namespace objects {
FSFW_CONFIG_RESERVED_START = PUS_SERVICE_1_VERIFICATION,
FSFW_CONFIG_RESERVED_END = TM_STORE,
UDP_BRIDGE = 15,
UDP_POLLING_TASK = 16,
UDP_BRIDGE = FSFW_OBJECTS_END,
UDP_POLLING_TASK = FSFW_OBJECTS_END + 1,
TEST_ECHO_COM_IF = 20,
TEST_DEVICE = 21,
TEST_ECHO_COM_IF = FSFW_OBJECTS_END + 2,
TEST_DEVICE = FSFW_OBJECTS_END + 3,
HK_RECEIVER_MOCK = 22,
TEST_LOCAL_POOL_OWNER_BASE = 25,
SHARED_SET_ID = 26
HK_RECEIVER_MOCK = FSFW_OBJECTS_END + 4,
TEST_LOCAL_POOL_OWNER_BASE = FSFW_OBJECTS_END + 5,
SHARED_SET_ID = FSFW_OBJECTS_END + 6,
FSFW_END_TEST_IDS = FSFW_OBJECTS_END + 7
};
}