2020-12-14 21:30:39 +01:00
|
|
|
#ifndef FSFW_TMTCSERVICES_PUSSERVICEBASE_H_
|
|
|
|
#define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_
|
|
|
|
|
|
|
|
#include "AcceptsTelecommandsIF.h"
|
2022-07-26 16:49:46 +02:00
|
|
|
#include "AcceptsTelemetryIF.h"
|
2022-07-20 22:21:15 +02:00
|
|
|
#include "TmSendHelper.h"
|
|
|
|
#include "TmStoreHelper.h"
|
2020-12-14 21:30:39 +01:00
|
|
|
#include "VerificationCodes.h"
|
|
|
|
#include "VerificationReporter.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/tasks/ExecutableObjectIF.h"
|
2022-07-29 12:03:14 +02:00
|
|
|
#include "fsfw/tcdistribution/PusDistributorIF.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-07-19 18:13:25 +02:00
|
|
|
class StorageManagerIF;
|
|
|
|
|
2022-07-26 16:49:46 +02:00
|
|
|
/**
|
|
|
|
* Configuration parameters for the PUS Service Base
|
|
|
|
*/
|
|
|
|
struct PsbParams {
|
|
|
|
PsbParams() = default;
|
|
|
|
PsbParams(uint16_t apid, AcceptsTelemetryIF* tmReceiver) : apid(apid), tmReceiver(tmReceiver) {}
|
2022-08-01 11:00:36 +02:00
|
|
|
PsbParams(const char* name, uint16_t apid, AcceptsTelemetryIF* tmReceiver)
|
|
|
|
: name(name), apid(apid), tmReceiver(tmReceiver) {}
|
2022-07-26 16:49:46 +02:00
|
|
|
PsbParams(object_id_t objectId, uint16_t apid, uint8_t serviceId)
|
|
|
|
: objectId(objectId), apid(apid), serviceId(serviceId) {}
|
2022-08-01 11:00:36 +02:00
|
|
|
PsbParams(const char* name, object_id_t objectId, uint16_t apid, uint8_t serviceId)
|
|
|
|
: name(name), objectId(objectId), apid(apid), serviceId(serviceId) {}
|
|
|
|
const char* name = "";
|
2022-07-26 16:49:46 +02:00
|
|
|
object_id_t objectId = objects::NO_OBJECT;
|
|
|
|
uint16_t apid = 0;
|
|
|
|
uint8_t serviceId = 0;
|
|
|
|
/**
|
|
|
|
* The default destination ID for generated telemetry. If this is not set, @initialize of PSB
|
|
|
|
* will attempt to find a suitable object with the object ID @PusServiceBase::packetDestination
|
|
|
|
*/
|
|
|
|
AcceptsTelemetryIF* tmReceiver = nullptr;
|
|
|
|
/**
|
|
|
|
* An instance of the VerificationReporter class, that simplifies
|
|
|
|
* sending any kind of verification message to the TC Verification Service. If this is not set,
|
|
|
|
* @initialize of PSB will attempt to find a suitable global object with the ID
|
|
|
|
* @objects::TC_VERIFICATOR
|
|
|
|
*/
|
|
|
|
VerificationReporterIF* verifReporter = nullptr;
|
|
|
|
/**
|
|
|
|
* This is a complete instance of the telecommand reception queue
|
|
|
|
* of the class. It is initialized on construction of the class.
|
|
|
|
*/
|
|
|
|
MessageQueueIF* reqQueue = nullptr;
|
|
|
|
/**
|
|
|
|
* The internal error reporter which will be used if there are issues sending telemetry.
|
|
|
|
* If this is not set, and the TM send or store helpers are initialized with the PSB,
|
|
|
|
* the class will attempt to find a suitable global object with the ID
|
|
|
|
* @objects::INTERNAL_ERROR_REPORTER
|
|
|
|
*/
|
|
|
|
InternalErrorReporterIF* errReporter = nullptr;
|
2022-07-26 17:41:10 +02:00
|
|
|
/**
|
|
|
|
* The storage manager which will be used to retrieve any TC packet using the store ID
|
|
|
|
* received via a message. If this is not set, the class will attempt to find a suitable global
|
|
|
|
* object with the ID @objects::TC_STORE
|
|
|
|
*/
|
|
|
|
StorageManagerIF* tcPool = nullptr;
|
|
|
|
/**
|
|
|
|
* Usually, packets are sent via a dedicated PUS distributor. If this distributor is set,
|
|
|
|
* the PUS service will register itself there. Otherwise, the base class will try to find
|
|
|
|
* a suitable global distributor with the static ID @PusServiceBase::pusDistributor and
|
|
|
|
* register itself at that object.
|
|
|
|
*/
|
2022-09-05 16:22:41 +02:00
|
|
|
PusDistributorIF* pusDistributor = nullptr;
|
2022-09-05 14:44:35 +02:00
|
|
|
TimeWriterIF* timeStamper = nullptr;
|
2022-07-26 16:49:46 +02:00
|
|
|
};
|
|
|
|
|
2022-07-26 18:46:28 +02:00
|
|
|
namespace Factory {
|
|
|
|
void setStaticFrameworkObjectIds();
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
2020-06-10 21:36:21 +02:00
|
|
|
* @defgroup pus_services PUS Service Framework
|
2016-06-15 23:48:41 +02:00
|
|
|
* These group contains all implementations of PUS Services in the OBSW.
|
|
|
|
* Most of the Services are directly taken from the ECSS PUS Standard.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-06-10 21:36:21 +02:00
|
|
|
* @brief This class is the basis for all PUS Services,
|
|
|
|
* which can immediately process Telecommand Packets.
|
|
|
|
* @details
|
|
|
|
* It manages Telecommand reception and the generation of Verification Reports.
|
|
|
|
* Every class that inherits from this abstract class has to implement
|
|
|
|
* handleRequest and performService. Services that are created with this
|
2016-06-15 23:48:41 +02:00
|
|
|
* Base class have to handle any kind of request immediately on reception.
|
2020-06-10 21:36:21 +02:00
|
|
|
* All PUS Services are System Objects, so an Object ID needs to be specified
|
|
|
|
* on construction.
|
|
|
|
* @ingroup pus_services
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-06-10 20:28:44 +02:00
|
|
|
class PusServiceBase : public ExecutableObjectIF,
|
2022-02-02 10:29:30 +01:00
|
|
|
public AcceptsTelecommandsIF,
|
2022-08-16 01:08:26 +02:00
|
|
|
public SystemObject {
|
2022-07-26 18:46:28 +02:00
|
|
|
friend void Factory::setStaticFrameworkObjectIds();
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
public:
|
2022-07-26 16:49:46 +02:00
|
|
|
/**
|
|
|
|
* This constant sets the maximum number of packets accepted per call.
|
|
|
|
* Remember that one packet must be completely handled in one
|
|
|
|
* #handleRequest call.
|
|
|
|
*/
|
|
|
|
static constexpr uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
|
|
|
|
static constexpr uint8_t PSB_DEFAULT_QUEUE_DEPTH = 10;
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief The passed values are set, but inter-object initialization is
|
|
|
|
* done in the initialize method.
|
2022-07-26 16:49:46 +02:00
|
|
|
* @param params All configuration parameters for the PUS Service Base
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
2022-07-26 16:49:46 +02:00
|
|
|
explicit PusServiceBase(PsbParams params);
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* The destructor is empty.
|
|
|
|
*/
|
2022-07-19 18:13:25 +02:00
|
|
|
~PusServiceBase() override;
|
2022-07-20 22:21:15 +02:00
|
|
|
|
2022-07-29 12:03:14 +02:00
|
|
|
ReturnValue_t registerService(PusDistributorIF& distributor);
|
2022-07-26 16:49:46 +02:00
|
|
|
/**
|
|
|
|
* Set the request queue which is used to receive requests. If none is set, the initialize
|
|
|
|
* function will create one
|
|
|
|
* @param reqQueue
|
|
|
|
*/
|
2022-07-26 18:46:28 +02:00
|
|
|
void setRequestQueue(MessageQueueIF& reqQueue);
|
|
|
|
void setTmReceiver(AcceptsTelemetryIF& tmReceiver);
|
|
|
|
void setTcPool(StorageManagerIF& tcStore);
|
|
|
|
void setVerificationReporter(VerificationReporterIF& reporter);
|
|
|
|
void setErrorReporter(InternalErrorReporterIF& errReporter);
|
2022-07-20 22:21:15 +02:00
|
|
|
|
2022-07-26 13:59:09 +02:00
|
|
|
/**
|
|
|
|
* Helper methods if the implementing class wants to send telemetry
|
|
|
|
* @param tmSendHelper
|
|
|
|
*/
|
2022-07-27 19:40:54 +02:00
|
|
|
ReturnValue_t initializeTmSendHelper(TmSendHelper& tmSendHelper);
|
2022-07-26 13:59:09 +02:00
|
|
|
/**
|
2022-07-27 17:00:43 +02:00
|
|
|
* Helper methods if the implementing class wants to store telemetry. It will set the correct APID
|
|
|
|
* and it will also attempt to set a valid time stamper. If the manually specified time stamper is
|
|
|
|
* null, it will attempt to find a suitable one using @objects::TIME_STAMPER
|
2022-07-26 13:59:09 +02:00
|
|
|
* @param tmSendHelper
|
|
|
|
*/
|
2022-07-27 19:40:54 +02:00
|
|
|
ReturnValue_t initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const;
|
2022-07-26 13:59:09 +02:00
|
|
|
/**
|
|
|
|
* Helper methods if the implementing class wants to both send and store telemetry
|
|
|
|
* @param tmSendHelper
|
|
|
|
*/
|
2022-07-27 19:40:54 +02:00
|
|
|
ReturnValue_t initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper);
|
2022-07-26 13:59:09 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief The handleRequest method shall handle any kind of Telecommand
|
|
|
|
* Request immediately.
|
|
|
|
* @details
|
|
|
|
* Implemetations can take the Telecommand in currentPacket and perform
|
|
|
|
* any kind of operation.
|
|
|
|
* They may send additional "Start Success (1,3)" messages with the
|
|
|
|
* verifyReporter, but Completion Success or Failure Reports are generated
|
|
|
|
* automatically after execution of this method.
|
|
|
|
*
|
|
|
|
* If a Telecommand can not be executed within one call cycle,
|
|
|
|
* this Base class is not the right parent.
|
|
|
|
*
|
|
|
|
* The child class may add additional error information by setting
|
|
|
|
* #errorParameters which aren attached to the generated verification
|
|
|
|
* message.
|
|
|
|
*
|
|
|
|
* Subservice checking should be implemented in this method.
|
|
|
|
*
|
|
|
|
* @return The returned status_code is directly taken as main error code
|
|
|
|
* in the Verification Report.
|
2022-08-16 12:12:21 +02:00
|
|
|
* On success, returnvalue::OK shall be returned.
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
|
|
|
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
|
|
|
|
/**
|
|
|
|
* In performService, implementations can handle periodic,
|
|
|
|
* non-TC-triggered activities.
|
|
|
|
* The performService method is always called.
|
2022-08-16 12:12:21 +02:00
|
|
|
* @return Currently, everything other that returnvalue::OK only triggers
|
2022-02-02 10:29:30 +01:00
|
|
|
* diagnostic output.
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t performService() = 0;
|
|
|
|
/**
|
|
|
|
* This method implements the typical activity of a simple PUS Service.
|
|
|
|
* It checks for new requests, and, if found, calls handleRequest, sends
|
|
|
|
* completion verification messages and deletes
|
|
|
|
* the TC requests afterwards.
|
|
|
|
* performService is always executed afterwards.
|
2022-08-16 12:12:21 +02:00
|
|
|
* @return @c returnvalue::OK if the periodic performService was successful.
|
2022-08-22 15:57:22 +02:00
|
|
|
* @c returnvalue::FAILED else.
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
|
|
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
2022-08-01 11:00:36 +02:00
|
|
|
uint32_t getIdentifier() const override;
|
|
|
|
MessageQueueId_t getRequestQueue() const override;
|
2022-07-19 18:13:25 +02:00
|
|
|
ReturnValue_t initialize() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-19 18:13:25 +02:00
|
|
|
void setTaskIF(PeriodicTaskIF* taskHandle) override;
|
2022-08-01 11:00:36 +02:00
|
|
|
[[nodiscard]] const char* getName() const override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Handle to the underlying task
|
|
|
|
* @details
|
|
|
|
* Will be set by setTaskIF(), which is called on task creation.
|
|
|
|
*/
|
|
|
|
PeriodicTaskIF* taskHandle = nullptr;
|
2022-08-01 11:00:36 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* One of two error parameters for additional error information.
|
|
|
|
*/
|
|
|
|
uint32_t errorParameter1 = 0;
|
|
|
|
/**
|
|
|
|
* One of two error parameters for additional error information.
|
|
|
|
*/
|
|
|
|
uint32_t errorParameter2 = 0;
|
2022-07-26 16:49:46 +02:00
|
|
|
PsbParams psbParams;
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* The current Telecommand to be processed.
|
|
|
|
* It is deleted after handleRequest was executed.
|
|
|
|
*/
|
2022-07-19 18:13:25 +02:00
|
|
|
PusTcReader currentPacket;
|
2022-07-26 16:49:46 +02:00
|
|
|
bool ownedQueue = true;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-07-26 18:46:28 +02:00
|
|
|
static object_id_t PACKET_DESTINATION;
|
|
|
|
static object_id_t PUS_DISTRIBUTOR;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
private:
|
|
|
|
void handleRequestQueue();
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-12-14 21:30:39 +01:00
|
|
|
#endif /* FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ */
|