#ifndef CCSDSHANDLER_H_ #define CCSDSHANDLER_H_ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/parameters/ParameterHelper.h" /** * @brief This class handles the data exchange with the CCSDS IP cores implemented in the * programmable logic of the Q7S. * * @author J. Meier */ class CCSDSHandler: public SystemObject, public ExecutableObjectIF, public HasModesIF, public AcceptsTelemetryIF, public HasReturnvaluesIF, public ReceivesParameterMessagesIF { public: static const uint32_t LINK_UP_DELAY_MS = 2000; //!< The maximum time it takes to reconfigure the CCSDS Board. static const uint32_t MAX_FRAME_SIZE = 1024; static const Submode_t SUBMODE_ACTIVE = 1; //!< Submode where the TM part of the board is on. static const Submode_t SUBMODE_PASSIVE = 0; //!< Submode where the TM part of the board is off. static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CCSDS_BOARD; static const Event CCSDS_BOARD_RESET_FAILED = MAKE_EVENT(0, SEVERITY::LOW); //!> Resetting the communication channel failed. Severity LOW, par1: returnCode, par2: 0 static const Event CCSDS_BOARD_SWITCHED = MAKE_EVENT(1, SEVERITY::INFO); //!> Switched active CCSDS-Board. Par1: objectId of now active board, Par2: objectId of now passive board. static const ActionId_t SET_DATA_RATE_RATIO = 1; static const float SENDS_PER_SECOND = 2.5; static const uint32_t MINIMUM_BYTES_PER_SECOND = (VCGeneration::IDLE_PACKET_SIZE / (VCGeneration::DEFAULT_IDLE_INTERVAL / 1000)) + 1; //!< +1 to be on the safe side. static const float DEFAULT_RATES[BoardHandler::USED_VIRTUAL_CHANNELS_PER_BOARD]; static const uint32_t DEFAULT_BYTES_PER_SECOND = 1300; HealthDevice tmPartHealth; //!< A helper device to dedicatetly set the telemetry part to not healthy. /** * Main Constructor of the class. * Initializes all attributes with default values. Sets the frame buffer to zero. * Creates all TM Virtual Channels (with \c new). Initialization of communication partners * is done in the #initialize routine. * @param setObjectId Object identifier of the class. * @param setSwitchId1 Switch id of the first switch of the board. * @param setSwitchId2 Switch id of the second switch of the board. * @param set_channel RMAP channel identifier. This is forwarded to the #boardHandler class. * @param set_scid Configured SpaceCraft Identifier. Is forwarded to #boardHandler and #dataLinkLayer class. */ CCSDSHandler(object_id_t setObjectId, uint8_t setSwitchId1, uint8_t setSwitchId2, object_id_t setChannel, uint16_t setSCID, BoardHandler::DataPoolIds setPool); /** * The destructor deletes all TM Virtual Channels. */ ~CCSDSHandler(); /** * Main executing method of the CCSDS Board handling. * The method coordinates reading and writing of buffers and registers on the CCSDS Board * as well as checking communication states and looking for frames. The state machine is * executed here as well. To ensure a smooth communication without much delay, the last read * and write calls are checked in the beginning and new requests as well as the state machine * are issued in the end. * @return Always returns #RETURN_OK. */ ReturnValue_t performOperation(void); ReturnValue_t handleMemoryLoad(uint32_t address, const uint8_t* data, uint32_t size, uint8_t** dataPointer); ReturnValue_t handleMemoryDump(uint32_t address, uint32_t size, uint8_t** dataPointer, uint8_t* dumpTarget); /** * Initialization routine of the class. * It initializes connections to the power unit and to the Telemetry store which is set for * every TM Virtual Channel. * @return */ ReturnValue_t initialize(); MessageQueueId_t getCommandQueue() const; /** * Method to configure the TC Virtual Channels in the TC Data Link Layer. * The call is forwarded to the #dataLinkLayer class. * @param virtualChannelId VCID to add. * @param object Pointer to the Virtual Channel object that is added. * @return See the #dataLinkLayer class. */ ReturnValue_t addVirtualChannel(uint8_t virtualChannelId, VirtualChannelReceptionIF* object); Mode_t getMode() const; Submode_t getSubmode() const; void setParentQueue(MessageQueueId_t parentQueueId); MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0); ReturnValue_t setHealth(HealthState health); HasHealthIF::HealthState getHealth(); ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); void triggerEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0); protected: MessageQueue commandQueue; //!< Queue to receive control commands. VCGeneration* virtualChannels[BoardHandler::USED_VIRTUAL_CHANNELS_PER_BOARD];//!< An array of VCGeneration classes which each manage on TM Virtual Channel. uint32_t rateLimitOverload[BoardHandler::USED_VIRTUAL_CHANNELS_PER_BOARD];//!< Used to smooth data rate in case large packets are sent. /** * This method reads the command queue and initializes a state transition if a command of this type was found. */ void readCommandQueue(void); /** * This method flushes all pending messages in the TM queue by calling the \c flush method of * all #virtualChannels. * This is necessary to avoid doubled TM packets if the TM sender issues its messages to both the * nominal and redundant CCSDS Board. */ void flushTmChannels(); /** * This is a helper method to print the current content of the frame buffers. */ void printFrameBuffer(void); /** * This is an important method which triggers searching for and handling found frames. * It first calls the boardHandler method to find a frame in the received data. If a * well-formed frame was found it calls the #dataLinkLayer class to process the frame */ void searchFrame(); /** * Calls the packet processing routine of each TM Virtual Channel. * This triggers reception of incoming packets from the OBSW and forwarding to the CCSDS Board. * There are different sending strategies for forwarding the packets to the board. * @return Returns #RETURN_OK or the status of the failed virtual channel method. */ ReturnValue_t packetProcessing(void); /** * With this method the successful forwarding of Telemetry to the TM Virtual Channels is checked. * The method calls the check routine of each virtual channel. * @return Returns #RETURN_OK or the status of the failed virtual channel method. */ ReturnValue_t packetProcessingCheck(void); ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode); void startTransition(Mode_t mode, Submode_t submode); void getMode(Mode_t *mode, Submode_t *submode); void setToExternalControl(); void announceMode(bool recursive); private: enum CcsdsState_t { STATE_IDLE, STATE_TURN_ON, STATE_TURN_OFF, STATE_DO_PASSIVATE_OFF, STATE_TURN_SWITCH_OFF, STATE_WAIT_ON, STATE_WAIT_LINK, STATE_WAIT_OFF, STATE_INITIALIZE_BOARD, STATE_SELECT_SUBMODE, STATE_WAIT_SUBMODE_ACTIVE, STATE_DO_PASSIVATE, STATE_WAIT_SUBMODE_PASSIVE, STATE_HANDLE_STARTUP, }; CcsdsState_t state; enum CommState { SEND_WRITE, GET_WRITE, SEND_READ, GET_READ }; CommState commState; Mode_t mode; Submode_t submode; BoardHandler boardHandler;//!< The class that handles the low-level communication with the board. DataLinkLayer dataLinkLayer;//!< The class that manages the TC Data Link Layer protocols. uint8_t frameBuffer[MAX_FRAME_SIZE]; //!< The main buffer to store single frames in. uint16_t frameLength; //!< Indicates the current length of the found frame. object_id_t channelId; //!< Defines the id of the RMAP Channel to use. MemoryHelper memoryHelper; //!< Helps handling memory messages. bool pendingWrite; //!< Attribute to manage remote Memory write. bool pendingRead; //!< Attribute to manage remote Memory read. ModeHelper modeHelper; //!< Helps handling mode messages. HealthHelper healthHelper; //!< Helps setting the health information correctly. ParameterHelper parameterHelper; PowerSwitcher powerSwitcher; //!< Helps switching switches on and off. bool switchOffWasReported; //!< To avoid reporting SWITCH_WENT_OFF multiple times. CCSDSBoardFailureIsolation fdir; class DataRateSet: public ControllerSet { public: DataRateSet(); virtual ~DataRateSet(); void setToDefault(); PoolVector dataRate; PoolVector dataRates; }; DataRateSet rateSet; void setMode(Mode_t newMode, Submode_t newSubmode); //!< Method to safely setMode and inform everyone interested about it. /** * State machine of the Handler. * Is responsible for handling mode transitions and for informing the modeHelper. * In addition, it watches the SpW link and changes the Mode in case a link down or a link up is detected. */ void doStateMachine(); void executeAllWriteCommands(); void handleAllWriteReplies(); void executeAllReadCommands(); void handleAllReadReplies(); }; #endif /* CCSDSHANDLER_H_ */