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"
|
2022-08-16 12:48:22 +02:00
|
|
|
#include "fsfw/returnvalues/returnvalue.h"
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/storagemanager/StorageManagerIF.h"
|
|
|
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
|
|
|
#include "fsfw/tmtcservices/TmTcMessage.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
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.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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
|
2016-06-15 23:48:41 +02:00
|
|
|
* 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
|
2016-06-15 23:48:41 +02:00
|
|
|
* destination information from the packet is handled by the child class
|
|
|
|
* implementations.
|
2020-10-01 13:23:06 +02:00
|
|
|
* @ingroup tc_distribution
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2022-08-22 16:21:41 +02:00
|
|
|
class TcDistributorBase : public SystemObject, public ExecutableObjectIF {
|
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);
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-08-01 11:00:36 +02:00
|
|
|
~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-08-01 11:00:36 +02:00
|
|
|
|
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
|
|
|
*/
|
2022-08-01 11:00:36 +02: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.
|
2022-08-16 01:08:26 +02:00
|
|
|
* @return The message queue return value or @c returnvalue::FAILED, in case no
|
2022-02-02 10:29:30 +01:00
|
|
|
* 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.
|
2022-08-16 12:12:21 +02:00
|
|
|
* The default implementation just returns @c returnvalue::OK.
|
2022-02-02 10:29:30 +01:00
|
|
|
* @param queueStatus The status of the message queue after an attempt
|
|
|
|
* to send the TC.
|
2022-08-16 12:12:21 +02:00
|
|
|
* @return - @c returnvalue::OK on success
|
2022-08-22 15:57:22 +02:00
|
|
|
* - @c returnvalue::FAILED on failure
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
|
|
|
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;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
#endif /* FSFW_TMTCSERVICES_TCDISTRIBUTOR_H_ */
|