fsfw/datalinklayer/MapPacketExtraction.h

74 lines
2.9 KiB
C
Raw Normal View History

2020-12-08 15:14:39 +01:00
#ifndef FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_
#define FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_
2020-08-13 20:53:35 +02:00
#include "MapPacketExtractionIF.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MessageQueueSenderIF.h"
class StorageManagerIF;
/**
* Implementation of a MAP Packet Extraction class.
* The class implements the full MAP Packet Extraction functionality as described in the CCSDS
* TC Space Data Link Protocol. It internally stores incomplete segmented packets until they are
* fully received. All found packets are forwarded to a single distribution entity.
2020-12-03 13:17:28 +01:00
* @author B. Baetz
*/
class MapPacketExtraction: public MapPacketExtractionIF {
private:
static const uint32_t MAX_PACKET_SIZE = 4096;
uint8_t lastSegmentationFlag; //!< The segmentation flag of the last received frame.
uint8_t mapId; //!< MAP ID of this MAP Channel.
2020-12-08 15:14:39 +01:00
uint32_t packetLength = 0; //!< Complete length of the current Space Packet.
uint8_t* bufferPosition; //!< Position to write to in the internal Packet buffer.
uint8_t packetBuffer[MAX_PACKET_SIZE]; //!< The internal Space Packet Buffer.
object_id_t packetDestination;
2020-12-08 15:14:39 +01:00
//!< Pointer to the store where full TC packets are stored.
StorageManagerIF* packetStore = nullptr;
MessageQueueId_t tcQueueId; //!< QueueId to send found packets to the distributor.
/**
* Debug method to print the packet Buffer's content.
*/
void printPacketBuffer();
/**
* Method that is called if the segmentation flag is @c NO_SEGMENTATION.
* The method extracts one or more packets within the frame and forwards them to the OBSW.
* @param frame The TC Transfer Frame to work on.
* @return @c RETURN_OK if all Packets were extracted. If something is entirely wrong,
* @c DATA_CORRUPTED is returned, if some bytes are left over @c RESIDUAL_DATA.
*/
ReturnValue_t unpackBlockingPackets(TcTransferFrame* frame);
/**
* Helper method to forward a complete packet to the OBSW.
* @param data Pointer to the data, either directly from the frame or from the packetBuffer.
* @param size Complete total size of the packet.
* @return Return Code of the Packet Store or the Message Queue.
*/
ReturnValue_t sendCompletePacket( uint8_t* data, uint32_t size );
/**
* Helper method to reset the internal buffer.
*/
void clearBuffers();
public:
/**
* Default constructor.
* Members are set to default values.
* @param setMapId The MAP ID of the instance.
*/
MapPacketExtraction( uint8_t setMapId, object_id_t setPacketDestination );
ReturnValue_t extractPackets(TcTransferFrame* frame);
/**
* The #packetStore and the default destination of #tcQueue are initialized here.
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
*/
ReturnValue_t initialize();
/**
* Getter.
* @return The MAP ID of this instance.
*/
uint8_t getMapId() const;
};
2020-12-08 15:14:39 +01:00
#endif /* FSFW_DATALINKLAYER_MAPPACKETEXTRACTION_H_ */