eive-obsw/linux/devices/startracker/ArcsecDatalinkLayer.h
Robin Mueller 0256824e37
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
add uart reception handler
2023-03-21 20:35:28 +01:00

84 lines
2.7 KiB
C++

#ifndef BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_
#define BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_
#include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/devicehandlers/CookieIF.h>
#include "arcsec/common/misc.h"
#include "eive/resultClassIds.h"
#include "fsfw/returnvalues/returnvalue.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
/**
* @brief Helper class to handle the datalinklayer of replies from the star tracker of arcsec.
*/
class ArcsecDatalinkLayer {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HANDLER;
//! [EXPORT] : [COMMENT] More data required to complete frame
static const ReturnValue_t DEC_IN_PROGRESS = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Data too short to represent a valid frame
static const ReturnValue_t REPLY_TOO_SHORT = MAKE_RETURN_CODE(0xA1);
//! [EXPORT] : [COMMENT] Detected CRC failure in received frame
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA2);
static const uint8_t STATUS_OK = 0;
ArcsecDatalinkLayer();
virtual ~ArcsecDatalinkLayer();
/**
* Feed received data to the internal ring buffer.
* @param rawData
* @param rawDataLen
* @return
*/
ReturnValue_t feedData(const uint8_t* rawData, size_t rawDataLen);
ReturnValue_t checkRingBufForFrame(const uint8_t** decodedFrame, size_t& frameLen);
/**
* @brief Applies decoding to data referenced by rawData pointer
* TODO: To be deleted soon, replaced by proper buffering.
* @param rawData Pointer to raw data received from star tracker
* @param rawDataSize Size of raw data stream
* @param remainingBytes Number of bytes left
*/
// ReturnValue_t decodeFrame(const uint8_t* rawData, size_t rawDataSize, size_t* bytesLeft);
/**
* @brief SLIP encodes data pointed to by data pointer.
*
* @param data Pointer to data to encode
* @param length Length of buffer to encode
*/
void encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, size_t& frameLen);
private:
static const uint8_t ID_OFFSET = 1;
static const uint8_t STATUS_OFFSET = 2;
// Used by arcsec slip decoding function process received data
uint8_t rxBuffer[startracker::MAX_FRAME_SIZE];
SimpleRingBuffer decodeRingBuf;
uint8_t rxAnalysisBuffer[4096];
// Decoded frame will be copied to this buffer
uint8_t decodedRxFrame[startracker::MAX_FRAME_SIZE];
// Size of decoded frame
uint32_t rxFrameSize = 0;
// Buffer where encoded frames will be stored. First byte of encoded frame represents type of
// reply
uint8_t txEncoded[startracker::MAX_FRAME_SIZE * 2 + 2];
// Size of encoded frame
uint32_t txFrameSize = 0;
slip_decode_state slipInfo;
void slipInit();
};
#endif /* BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_ */