1
0
forked from fsfw/fsfw

Merge remote-tracking branch 'upstream/master' into mueller_FIFO_static_normal

This commit is contained in:
2020-07-28 13:08:04 +02:00
18 changed files with 690 additions and 432 deletions

View File

@ -1,35 +1,33 @@
#ifndef FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#define FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#include <framework/container/FixedMap.h>
#include <framework/container/FIFO.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/objectmanager/SystemObject.h>
#include <framework/serialize/SerializeAdapter.h>
#include <framework/storagemanager/StorageManagerIF.h>
#include <framework/tasks/ExecutableObjectIF.h>
#include <framework/tcdistribution/PUSDistributorIF.h>
#include <framework/tmtcpacket/pus/TcPacketStored.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
#include <framework/ipc/MessageQueueIF.h>
#include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/tmtcservices/TmTcMessage.h>
#include <framework/tmtcservices/VerificationReporter.h>
#include <framework/internalError/InternalErrorReporterIF.h>
#include <framework/ipc/QueueFactory.h>
#include <framework/timemanager/Clock.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/container/FixedMap.h>
#include <framework/container/FIFO.h>
#include <framework/serialize/SerializeIF.h>
class TcPacketStored;
/**
* \brief This class is the basis for all PUS Services, which have to relay Telecommands to software bus.
* @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus.
*
* It manages Telecommand reception and the generation of Verification Reports like PUSServiceBase.
* Every class that inherits from this abstract class has to implement four adaption points:
* It manages Telecommand reception and the generation of Verification Reports
* similar to PusServiceBase. This class is used if a telecommand can't be
* handled immediately and must be relayed to the internal software bus.
* - isValidSubservice
* - getMessageQueueAndObject
* - prepareCommand
* - handleReply
* \ingroup pus_services
* @author gaisser
* @ingroup pus_services
*/
class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF,
@ -59,7 +57,7 @@ public:
*/
CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeout_seconds, object_id_t setPacketSource,
uint16_t commandTimeoutSeconds, object_id_t setPacketSource,
object_id_t setPacketDestination, size_t queueDepth = 20);
virtual ~CommandingServiceBase();
@ -99,9 +97,7 @@ public:
* Used to setup the reference of the task, that executes this component
* @param task_ Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF* task_){
executingTask = task_;
};
virtual void setTaskIF(PeriodicTaskIF* task_);
protected:
/**
@ -113,8 +109,9 @@ protected:
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.
* 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
@ -125,48 +122,69 @@ protected:
* - @c CSB or implementation specific return codes
*/
virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id,
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 to be sent to the object
* @param subservice[in] Subservice of the current communication
* @param tcData Additional data of the command
* @param tcDataLen Length of the additional data
* @param state[out] Setable state of the communication
* 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 on success
* - @c EXECUTION_COMPLETE if exectuin is finished
* - any other return code will be part of (1,4) start failure
* @return
*/
virtual ReturnValue_t prepareCommand(CommandMessage *message,
uint8_t subservice, const uint8_t *tcData, uint32_t tcDataLen,
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 responsible for the communication between the Command Service Base
* and the respective PUS Commanding Service once the execution has started.
* The PUS Commanding Service receives replies from the target device and forwards them by calling this function.
* There are different translations of these replies to specify how the Command Service proceeds.
* @param reply Command Message which contains information about the command
* @param previousCommand Command_t of last command
* @param state state of the communication
* @param optionalNextCommand[out] An optional next command which can be set in this function
* 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 can handle unrequested replies
* - Anything else triggers a TC verification failure
* @return
* - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
* generate TC verification success
* - @c INVALID_REPLY calls handleUnrequestedReply
* - Anything else triggers a TC verification failure. If RETURN_FAILED
* 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.
*/
virtual ReturnValue_t handleReply(const CommandMessage *reply,
virtual ReturnValue_t handleReply(const CommandMessage* reply,
Command_t previousCommand, uint32_t *state,
CommandMessage *optionalNextCommand, object_id_t objectId,
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 {
struct tcInfo {
uint8_t ackFlags;
@ -182,84 +200,92 @@ protected:
FIFO<store_address_t, 3> fifo;
};
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid;
const uint8_t service;
const uint16_t timeout_seconds;
const uint16_t timeoutSeconds;
uint8_t tmPacketCounter;
uint8_t tmPacketCounter = 0;
StorageManagerIF *IPCStore;
StorageManagerIF *IPCStore = nullptr;
StorageManagerIF *TCStore;
StorageManagerIF *TCStore = nullptr;
MessageQueueIF* commandQueue;
MessageQueueIF* commandQueue = nullptr;
MessageQueueIF* requestQueue;
MessageQueueIF* requestQueue = nullptr;
VerificationReporter verificationReporter;
FixedMap<MessageQueueId_t, CommandInfo> commandMap;
uint32_t failureParameter1; //!< May be set be children to return a more precise failure condition.
uint32_t failureParameter2; //!< May be set be children to return a more precise failure condition.
/* May be set be children to return a more precise failure condition. */
uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0;
object_id_t packetSource;
object_id_t packetDestination;
/**
* Pointer to the task which executes this component, is invalid before setTaskIF was called.
* Pointer to the task which executes this component,
* is invalid before setTaskIF was called.
*/
PeriodicTaskIF* executingTask;
PeriodicTaskIF* executingTask = nullptr;
/**
* Send TM data from pointer to data. If a header is supplied it is added before data
* @brief Send TM data from pointer to data.
* If a header is supplied it is added before data
* @param subservice Number of subservice
* @param data Pointer to the data in the Packet
* @param dataLen Lenght of data in the Packet
* @param headerData HeaderData will be placed before data
* @param headerSize Size of HeaderData
*/
void sendTmPacket(uint8_t subservice, const uint8_t *data, uint32_t dataLen,
const uint8_t* headerData = NULL, uint32_t headerSize = 0);
ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t *data,
size_t dataLen, const uint8_t* headerData = nullptr,
size_t headerSize = 0);
/**
* To send TM packets of objects that still need to be serialized and consist of an object ID with appended data
* @brief To send TM packets of objects that still need to be serialized
* and consist of an object ID with appended data.
* @param subservice Number of subservice
* @param objectId ObjectId is placed before data
* @param data Data to append to the packet
* @param dataLen Length of Data
*/
void sendTmPacket(uint8_t subservice, object_id_t objectId,
const uint8_t *data, uint32_t dataLen);
ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId,
const uint8_t *data, size_t dataLen);
/**
* To send packets has data which is in form of a SerializeIF or Adapters implementing it
* @brief To send packets which are contained inside a class implementing
* SerializeIF.
* @param subservice Number of subservice
* @param content This is a pointer to the serialized packet
* @param header Serialize IF header which will be placed before content
*/
void sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = NULL);
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr);
virtual void handleUnrequestedReply(CommandMessage *reply);
virtual void doPeriodicOperation();
void checkAndExecuteFifo(
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *iter);
void checkAndExecuteFifo(CommandMapIter iter);
private:
/**
* This method handles internal execution of a command,
* once it has been started by @sa{startExecution()} in the Request 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.
* once it has been started by @sa{startExecution()} in the request
* 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.
* 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
@ -280,8 +306,11 @@ private:
void acceptPacket(uint8_t reportId, TcPacketStored* packet);
void startExecution(TcPacketStored *storedPacket,
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *iter);
void startExecution(TcPacketStored *storedPacket, CommandMapIter iter);
void handleCommandMessage(CommandMessage* reply);
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
CommandMessage* nextCommand, CommandMessage* reply, bool& isStep);
void checkTimeout();
};