fsfw/src/fsfw/tcdistribution/TcDistributorBase.h

113 lines
4.3 KiB
C
Raw Normal View History

2020-10-01 13:23:06 +02:00
#ifndef FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_
#define FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_
2022-02-02 10:29:30 +01:00
#include <map>
2022-08-01 17:16:37 +02:00
#include "fsfw/events/Event.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/ipc/MessageQueueIF.h"
2021-07-13 20:22:54 +02:00
#include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
/**
2020-10-01 13:23:06 +02:00
* @defgroup tc_distribution Telecommand Distribution
* All classes associated with Routing and Distribution of Telecommands
* belong to this group.
*/
/**
2022-07-29 12:03:14 +02:00
* This is the base class to implement distributors for telecommands.
* Typically, the distribution is required to forward telecommand packets
* over the satellite applications and services. The class receives
2022-07-29 12:03:14 +02:00
* TC packets over a message queue and holds a map that links other
* message queue IDs to some identifier. The process of unpacking the
* destination information from the packet is handled by the child class
* implementations.
2020-10-01 13:23:06 +02:00
* @ingroup tc_distribution
*/
class TcDistributorBase : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF {
2022-02-02 10:29:30 +01:00
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::PACKET_DISTRIBUTION;
static constexpr ReturnValue_t PACKET_LOST = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t DESTINATION_NOT_FOUND = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t SERVICE_ID_ALREADY_EXISTS = MAKE_RETURN_CODE(3);
2022-08-01 17:16:37 +02:00
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TC_DISTRIBUTION;
//! P1: Returnvalue, P2: Line number
static constexpr Event HANDLE_PACKET_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW);
2022-02-02 10:29:30 +01:00
/**
* Within the default constructor, the SystemObject id is set and the
* message queue is initialized.
* Filling the map is under control of the child classes.
* @param set_object_id This id is assigned to the distributor
* implementation.
*/
2022-08-01 17:16:37 +02:00
explicit TcDistributorBase(object_id_t objectId, MessageQueueIF* tcQueue = nullptr);
2022-02-02 10:29:30 +01:00
/**
* The destructor is empty, the message queues are not in the vicinity of
* this class.
*/
~TcDistributorBase() override;
2022-02-02 10:29:30 +01:00
/**
* The method is called cyclically and fetches new incoming packets from
* the message queue.
* In case a new packet is found, it calls the handlePacket method to deal
* with distribution.
* @return The error code of the message queue call.
*/
2022-07-29 12:03:14 +02:00
ReturnValue_t performOperation(uint8_t opCode) override;
2020-10-01 13:23:06 +02:00
2022-02-02 10:29:30 +01:00
protected:
2022-08-01 17:16:37 +02:00
bool ownedQueue = false;
2022-02-02 10:29:30 +01:00
/**
* This is the receiving queue for incoming Telecommands.
* The child classes must make its queue id public.
*/
MessageQueueIF* tcQueue = nullptr;
/**
* The last received incoming packet information is stored in this
* member.
* As different child classes unpack the incoming packet differently
2022-08-01 14:23:52 +02:00
* (i.e. as a CCSDS Space Packet or as a PUS Telecommand Packet), no unpacking will be
* done in this class.
2022-02-02 10:29:30 +01:00
*/
TmTcMessage currentMessage;
2022-02-02 10:29:30 +01:00
/**
* This method shall unpack the routing information from the incoming
* packet and select the map entry which represents the packet's target.
2022-08-01 14:23:52 +02:00
* @return
* - @c RETURN_OK if a desitnation was selected successfully
2022-02-02 10:29:30 +01:00
*/
virtual ReturnValue_t selectDestination(MessageQueueId_t& destId) = 0;
2022-02-02 10:29:30 +01:00
/**
* The handlePacket method calls the child class's selectDestination method
* and forwards the packet to its destination, if found.
* @return The message queue return value or @c RETURN_FAILED, in case no
* destination was found.
*/
ReturnValue_t handlePacket();
/**
* This method gives the child class a chance to perform some kind of
* operation after the parent tried to forward the message.
* A typically application would be sending success/failure messages.
* The default implementation just returns @c RETURN_OK.
* @param queueStatus The status of the message queue after an attempt
* to send the TC.
* @return - @c RETURN_OK on success
* - @c RETURN_FAILED on failure
*/
virtual ReturnValue_t callbackAfterSending(ReturnValue_t queueStatus);
2020-10-01 13:23:06 +02:00
2022-02-02 10:29:30 +01:00
private:
/**
* This constant sets the maximum number of packets distributed per call.
*/
static constexpr uint8_t DISTRIBUTER_MAX_PACKETS = 128;
};
2020-10-01 13:23:06 +02:00
#endif /* FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_ */