2020-09-01 12:58:29 +02:00
|
|
|
#ifndef FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
|
|
|
#define FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 21:30:39 +01:00
|
|
|
#include "AcceptsTelecommandsIF.h"
|
2022-07-20 22:21:15 +02:00
|
|
|
#include "TmSendHelper.h"
|
|
|
|
#include "TmStoreHelper.h"
|
2020-12-14 21:30:39 +01:00
|
|
|
#include "VerificationReporter.h"
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/FSFW.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/container/FIFO.h"
|
|
|
|
#include "fsfw/container/FixedMap.h"
|
|
|
|
#include "fsfw/ipc/CommandMessage.h"
|
|
|
|
#include "fsfw/ipc/MessageQueueIF.h"
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/objectmanager/SystemObject.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/serialize/SerializeIF.h"
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/storagemanager/StorageManagerIF.h"
|
|
|
|
#include "fsfw/tasks/ExecutableObjectIF.h"
|
2022-07-26 11:14:40 +02:00
|
|
|
#include "fsfw/tmtcservices/TmStoreAndSendHelper.h"
|
2020-12-14 21:30:39 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
namespace Factory {
|
2020-07-16 11:47:11 +02:00
|
|
|
void setStaticFrameworkObjectIds();
|
2022-07-26 18:46:28 +02:00
|
|
|
};
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2020-06-10 22:13:49 +02:00
|
|
|
* @brief This class is the basis for all PUS Services, which have to
|
|
|
|
* relay Telecommands to software bus.
|
2019-08-28 14:50:24 +02:00
|
|
|
*
|
2020-06-10 22:13:49 +02:00
|
|
|
* It manages Telecommand reception and the generation of Verification Reports
|
2022-07-27 11:41:06 +02:00
|
|
|
* similar to @PusServiceBase. This class is used if a telecommand can't be
|
2020-06-10 22:13:49 +02:00
|
|
|
* handled immediately and must be relayed to the internal software bus.
|
2019-08-28 14:50:24 +02:00
|
|
|
* - isValidSubservice
|
|
|
|
* - getMessageQueueAndObject
|
|
|
|
* - prepareCommand
|
|
|
|
* - handleReply
|
2022-07-27 11:41:06 +02:00
|
|
|
*
|
|
|
|
* Please note that the TM packets generated by this class will not have a valid CRC. It is
|
|
|
|
* generally assumed that all packets will pass through a layer where the sequence count is set
|
|
|
|
* and the CRC16 needs to be re-calculated anyway.
|
2020-06-10 22:13:49 +02:00
|
|
|
* @author gaisser
|
|
|
|
* @ingroup pus_services
|
2019-08-28 14:50:24 +02:00
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
class CommandingServiceBase : public SystemObject,
|
|
|
|
public AcceptsTelecommandsIF,
|
2022-08-16 01:08:26 +02:00
|
|
|
public ExecutableObjectIF {
|
2022-07-26 18:46:28 +02:00
|
|
|
friend void Factory::setStaticFrameworkObjectIds();
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
// We could make this configurable via preprocessor and the FSFWConfig file.
|
|
|
|
static constexpr uint8_t COMMAND_INFO_FIFO_DEPTH = fsfwconfig::FSFW_CSB_FIFO_DEPTH;
|
|
|
|
|
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
|
|
|
|
|
|
|
|
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
|
|
|
|
static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2);
|
2022-07-29 10:23:59 +02:00
|
|
|
/**
|
|
|
|
* Target object has too many pending requests
|
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3);
|
2022-07-29 10:23:59 +02:00
|
|
|
/**
|
|
|
|
* Command map is full
|
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4);
|
|
|
|
static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5);
|
|
|
|
static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6);
|
|
|
|
static const ReturnValue_t INVALID_REPLY = MAKE_RETURN_CODE(7);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class constructor. Initializes two important MessageQueues:
|
|
|
|
* commandQueue for command reception and requestQueue for device reception
|
|
|
|
* @param setObjectId
|
|
|
|
* @param apid
|
|
|
|
* @param service
|
|
|
|
* @param numberOfParallelCommands
|
|
|
|
* @param commandTimeout_seconds
|
|
|
|
* @param setPacketSource
|
|
|
|
* @param setPacketDestination
|
|
|
|
* @param queueDepth
|
|
|
|
*/
|
|
|
|
CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service,
|
|
|
|
uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds,
|
2022-07-26 13:59:09 +02:00
|
|
|
size_t queueDepth = 20, VerificationReporterIF* reporter = nullptr);
|
2022-07-20 22:21:15 +02:00
|
|
|
~CommandingServiceBase() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-25 11:24:13 +02:00
|
|
|
void setCustomTmStore(StorageManagerIF& store);
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* This setter can be used to set the packet source individually instead
|
|
|
|
* of using the default static framework ID set in the factory.
|
|
|
|
* This should be called at object initialization and not during run-time!
|
|
|
|
* @param packetSource
|
|
|
|
*/
|
|
|
|
void setPacketSource(object_id_t packetSource);
|
|
|
|
/**
|
|
|
|
* This setter can be used to set the packet destination individually
|
|
|
|
* instead of using the default static framework ID set in the factory.
|
|
|
|
* This should be called at object initialization and not during run-time!
|
|
|
|
* @param packetDestination
|
|
|
|
*/
|
|
|
|
void setPacketDestination(object_id_t packetDestination);
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is the periodically called function.
|
|
|
|
* Handle request queue for external commands.
|
|
|
|
* Handle command Queue for internal commands.
|
|
|
|
* @param opCode is unused here at the moment
|
|
|
|
* @return RETURN_OK
|
|
|
|
*/
|
2022-07-20 22:21:15 +02:00
|
|
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
uint16_t getIdentifier() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the requestQueue MessageQueueId_t
|
|
|
|
*
|
|
|
|
* The requestQueue is the queue for external commands (TC)
|
|
|
|
*
|
|
|
|
* @return requestQueue messageQueueId_t
|
|
|
|
*/
|
2022-07-20 22:21:15 +02:00
|
|
|
MessageQueueId_t getRequestQueue() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the commandQueue MessageQueueId_t
|
|
|
|
*
|
|
|
|
* Remember the CommandQueue is the queue for internal communication
|
|
|
|
* @return commandQueue messageQueueId_t
|
|
|
|
*/
|
|
|
|
virtual MessageQueueId_t getCommandQueue();
|
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
ReturnValue_t initialize() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ExecutableObjectIF function
|
|
|
|
*
|
|
|
|
* Used to setup the reference of the task, that executes this component
|
|
|
|
* @param task Pointer to the taskIF of this task
|
|
|
|
*/
|
2022-07-20 22:21:15 +02:00
|
|
|
void setTaskIF(PeriodicTaskIF* task) override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Check the target subservice
|
|
|
|
* @param subservice[in]
|
|
|
|
* @return
|
|
|
|
* -@c RETURN_OK Subservice valid, continue message handling
|
|
|
|
* -@c INVALID_SUBSERVICE if service is not known, rejects packet.
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Once a TC Request is valid, the existence of the destination and its
|
|
|
|
* target interface is checked and retrieved. The target message queue ID
|
|
|
|
* can then be acquired by using the target interface.
|
|
|
|
* @param subservice
|
|
|
|
* @param tcData Application Data of TC Packet
|
|
|
|
* @param tcDataLen
|
|
|
|
* @param id MessageQueue ID is stored here
|
|
|
|
* @param objectId Object ID is extracted and stored here
|
|
|
|
* @return
|
|
|
|
* - @c RETURN_OK Cotinue message handling
|
2022-08-16 01:08:26 +02:00
|
|
|
* - @c returnvalue::FAILED Reject the packet and generates a start failure
|
2022-02-02 10:29:30 +01:00
|
|
|
* verification
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, const uint8_t* tcData,
|
|
|
|
size_t tcDataLen, MessageQueueId_t* id,
|
|
|
|
object_id_t* objectId) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After the Message Queue and Object ID are determined, the command is
|
|
|
|
* prepared by using an implementation specific CommandMessage type
|
|
|
|
* which is sent to the target object. It contains all necessary information
|
|
|
|
* for the device to execute telecommands.
|
|
|
|
* @param message [out] message which can be set and is sent to the object
|
|
|
|
* @param subservice Subservice of the current communication
|
|
|
|
* @param tcData Application data of command
|
|
|
|
* @param tcDataLen Application data length
|
|
|
|
* @param state [out/in] Setable state of the communication.
|
|
|
|
* communication
|
|
|
|
* @param objectId Target object ID
|
|
|
|
* @return
|
|
|
|
* - @c RETURN_OK to generate a verification start message
|
2022-05-09 10:47:23 +02:00
|
|
|
* - @c EXECUTION_COMPLETE Fire-and-forget command. Generate a completion
|
2022-02-02 10:29:30 +01:00
|
|
|
* verification message.
|
|
|
|
* - @c Anything else rejects the packets and generates a start failure
|
|
|
|
* verification.
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t prepareCommand(CommandMessage* message, uint8_t subservice,
|
|
|
|
const uint8_t* tcData, size_t tcDataLen, uint32_t* state,
|
|
|
|
object_id_t objectId) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is implemented by child services to specify how replies
|
|
|
|
* to a command from another software component are handled.
|
|
|
|
* @param reply
|
|
|
|
* This is the reply in form of a generic read-only command message.
|
|
|
|
* @param previousCommand
|
|
|
|
* Command_t of related command
|
|
|
|
* @param state [out/in]
|
|
|
|
* Additional parameter which can be used to pass state information.
|
|
|
|
* State of the communication
|
|
|
|
* @param optionalNextCommand [out]
|
|
|
|
* An optional next command which can be set in this function
|
|
|
|
* @param objectId Source object ID
|
|
|
|
* @param isStep Flag value to mark steps of command execution
|
|
|
|
* @return
|
|
|
|
* - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
|
|
|
|
* generate TC verification success
|
|
|
|
* - @c INVALID_REPLY Calls handleUnrequestedReply
|
2022-08-16 01:08:26 +02:00
|
|
|
* - Anything else triggers a TC verification failure. If returnvalue::FAILED or
|
2022-02-02 10:29:30 +01:00
|
|
|
* INVALID_REPLY is returned and the command ID is
|
|
|
|
* CommandMessage::REPLY_REJECTED, a failure verification message with
|
|
|
|
* the reason as the error parameter and the initial command as
|
|
|
|
* failure parameter 1 is generated.
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t handleReply(const CommandMessage* reply, Command_t previousCommand,
|
|
|
|
uint32_t* state, CommandMessage* optionalNextCommand,
|
|
|
|
object_id_t objectId, bool* isStep) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function can be overidden to handle unrequested reply,
|
|
|
|
* when the reply sender ID is unknown or is not found is the command map.
|
|
|
|
* The default implementation will clear the command message and all
|
|
|
|
* its contents.
|
|
|
|
* @param reply
|
|
|
|
* Reply which is non-const so the default implementation can clear the
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
virtual void handleUnrequestedReply(CommandMessage* reply);
|
|
|
|
|
|
|
|
virtual void doPeriodicOperation();
|
|
|
|
|
|
|
|
struct CommandInfo : public SerializeIF {
|
2022-07-26 13:59:09 +02:00
|
|
|
struct TcInfo {
|
2022-02-02 10:29:30 +01:00
|
|
|
uint8_t ackFlags;
|
|
|
|
uint16_t tcPacketId;
|
|
|
|
uint16_t tcSequenceControl;
|
|
|
|
} tcInfo;
|
|
|
|
uint32_t uptimeOfStart;
|
|
|
|
uint8_t step;
|
|
|
|
uint8_t subservice;
|
|
|
|
uint32_t state;
|
|
|
|
Command_t command;
|
|
|
|
object_id_t objectId;
|
|
|
|
FIFO<store_address_t, COMMAND_INFO_FIFO_DEPTH> fifo;
|
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
|
|
|
Endianness streamEndianness) const override {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2021-12-03 15:37:49 +01:00
|
|
|
};
|
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
[[nodiscard]] size_t getSerializedSize() const override { return 0; };
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
Endianness streamEndianness) override {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
using CommandMapIter = FixedMap<MessageQueueId_t, CommandingServiceBase::CommandInfo>::Iterator;
|
|
|
|
|
|
|
|
const uint16_t apid;
|
|
|
|
|
|
|
|
const uint8_t service;
|
|
|
|
|
|
|
|
const uint16_t timeoutSeconds;
|
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
PusTcReader tcReader;
|
|
|
|
TmStoreHelper tmStoreHelper;
|
|
|
|
TmSendHelper tmSendHelper;
|
2022-07-26 11:09:57 +02:00
|
|
|
TmStoreAndSendWrapper tmHelper;
|
2022-07-20 22:21:15 +02:00
|
|
|
|
|
|
|
StorageManagerIF* tcStore = nullptr;
|
2022-07-26 11:09:57 +02:00
|
|
|
StorageManagerIF* ipcStore = nullptr;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
MessageQueueIF* commandQueue = nullptr;
|
|
|
|
MessageQueueIF* requestQueue = nullptr;
|
|
|
|
|
2022-07-27 17:00:43 +02:00
|
|
|
TimeStamperIF* tmTimeStamper = nullptr;
|
2022-07-26 13:59:09 +02:00
|
|
|
VerificationReporterIF* verificationReporter;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-20 22:21:15 +02:00
|
|
|
InternalErrorReporterIF* errReporter = nullptr;
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
FixedMap<MessageQueueId_t, CommandInfo> commandMap;
|
|
|
|
|
|
|
|
/* May be set be children to return a more precise failure condition. */
|
|
|
|
uint32_t failureParameter1 = 0;
|
|
|
|
uint32_t failureParameter2 = 0;
|
|
|
|
|
|
|
|
static object_id_t defaultPacketSource;
|
|
|
|
object_id_t packetSource = objects::NO_OBJECT;
|
|
|
|
static object_id_t defaultPacketDestination;
|
|
|
|
object_id_t packetDestination = objects::NO_OBJECT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pointer to the task which executes this component,
|
|
|
|
* is invalid before setTaskIF was called.
|
|
|
|
*/
|
|
|
|
PeriodicTaskIF* executingTask = nullptr;
|
|
|
|
|
2022-07-26 13:59:09 +02:00
|
|
|
ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t* sourceData, size_t sourceDataLen);
|
|
|
|
ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t* data,
|
|
|
|
size_t dataLen);
|
|
|
|
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF& sourceData);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
void checkAndExecuteFifo(CommandMapIter& iter);
|
2022-07-26 13:59:09 +02:00
|
|
|
VerifFailureParams failParams;
|
|
|
|
VerifSuccessParams successParams;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* This method handles internal execution of a command,
|
2022-07-26 13:59:09 +02:00
|
|
|
* once it has been started by @startExecution in the request
|
2022-02-02 10:29:30 +01:00
|
|
|
* queue handler.
|
|
|
|
* It handles replies generated by the devices and relayed by the specific
|
|
|
|
* service implementation. This means that it determines further course of
|
|
|
|
* action depending on the return values specified in the service
|
|
|
|
* implementation.
|
|
|
|
* This includes the generation of TC verification messages. Note that
|
|
|
|
* the static framework object ID @c VerificationReporter::messageReceiver
|
|
|
|
* needs to be set.
|
|
|
|
* - TM[1,5] Step Successs
|
|
|
|
* - TM[1,6] Step Failure
|
|
|
|
* - TM[1,7] Completion Success
|
|
|
|
* - TM[1,8] Completion Failure
|
|
|
|
*/
|
|
|
|
void handleCommandQueue();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Handler function for request queue
|
|
|
|
* @details
|
|
|
|
* Sequence of request queue handling:
|
2022-07-26 13:59:09 +02:00
|
|
|
* @isValidSubservice -> @getMessageQueueAndObject -> @startExecution
|
2022-02-02 10:29:30 +01:00
|
|
|
* Generates a Start Success Reports TM[1,3] in subfunction
|
2022-07-26 13:59:09 +02:00
|
|
|
* @startExecution or a Start Failure Report TM[1,4] by using the
|
2022-02-02 10:29:30 +01:00
|
|
|
* TC Verification Service.
|
|
|
|
*/
|
|
|
|
void handleRequestQueue();
|
|
|
|
|
2022-07-21 13:48:58 +02:00
|
|
|
ReturnValue_t setUpTcReader(store_address_t storeId);
|
|
|
|
|
2022-07-29 10:23:59 +02:00
|
|
|
/**
|
|
|
|
* The TC format is invalid or there was an issue retrieving a TC packet from the store.
|
|
|
|
* @param errorCode Result of the failed operation, will be sent with the verification failure
|
|
|
|
* message
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
ReturnValue_t rejectPacketInvalidTc(ReturnValue_t errorCode, store_address_t tcStoreId);
|
|
|
|
ReturnValue_t rejectPacket(uint8_t reportId, store_address_t tcStoreId, ReturnValue_t errorCode);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-29 10:23:59 +02:00
|
|
|
ReturnValue_t acceptPacket(uint8_t reportId, store_address_t tcStoreId);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-07-26 13:59:09 +02:00
|
|
|
void startExecution(store_address_t storeId, CommandMapIter& iter);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
void handleCommandMessage(CommandMessage* reply);
|
|
|
|
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
|
|
|
|
CommandMessage* nextCommand, CommandMessage* reply, bool& isStep);
|
2022-07-29 10:23:59 +02:00
|
|
|
void prepareVerificationFailureWithNoTcInfo(uint8_t reportId, ReturnValue_t errorCode,
|
|
|
|
bool setCachedFailParams);
|
2022-07-26 13:59:09 +02:00
|
|
|
void prepareVerificationFailureWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo,
|
|
|
|
ReturnValue_t errorCode, bool setCachedFailParams);
|
|
|
|
void prepareVerificationSuccessWithFullInfo(uint8_t reportId, CommandInfo::TcInfo& tcInfo);
|
2022-02-02 10:29:30 +01:00
|
|
|
void checkTimeout();
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-09-01 12:58:29 +02:00
|
|
|
#endif /* FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_ */
|