2021-09-19 12:27:48 +02:00
# 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 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 ;
2021-09-22 16:54:55 +02:00
2021-09-19 12:27:48 +02:00
/**
2021-09-22 16:54:55 +02:00
* @ brief Function to add a virtual channel
*
* @ param virtualChannelId ID of the virtual channel to add
* @ param virtualChannel Pointer to virtual channel object
*
* @ return RETURN_OK if successful , otherwise RETURN_FAILED
2021-09-19 12:27:48 +02:00
*/
2021-09-22 16:54:55 +02:00
void addVirtualChannel ( VcId_t virtualChannelId , VirtualChannel * virtualChannel ) ;
2021-09-19 12:27:48 +02:00
Mode_t getMode ( ) const ;
Submode_t getSubmode ( ) const ;
void setParentQueue ( MessageQueueId_t parentQueueId ) ;
MessageQueueId_t getReportReceptionQueue ( uint8_t virtualChannel = 0 ) ;
2021-09-22 16:54:55 +02:00
ReturnValue_t getParameter ( uint8_t domainId , uint8_t uniqueIdentifier ,
ParameterWrapper * parameterWrapper , const ParameterWrapper * newValues ,
uint16_t startAtIndex ) ;
2021-09-19 12:27:48 +02:00
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 :
2021-09-22 16:54:55 +02:00
using VcId_t = uint8_t ;
using VirtualChannelMap = std : : unordered_map < VcId_t , VcInterfaceIF * > ;
using VirtualChannelMapIter = VirtualChannelMap : : iterator ;
VirtualChannelMap virtualChannelMap ;
void handleTelemetry ( ) ;
void handleTelecommands ( ) ;
2021-09-19 12:27:48 +02:00
} ;
# endif /* CCSDSHANDLER_H_ */