eive-obsw/mission/acs/str/ArcsecDatalinkLayer.h

96 lines
3.0 KiB
C
Raw Normal View History

2021-12-02 08:05:33 +01:00
#ifndef BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_
#define BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_
2023-03-21 18:47:42 +01:00
#include <fsfw/container/SimpleRingBuffer.h>
2023-03-21 20:35:28 +01:00
#include <fsfw/devicehandlers/CookieIF.h>
#include <mission/acs/str/strHelpers.h>
2023-03-21 18:47:42 +01:00
#include "eive/resultClassIds.h"
2022-08-24 17:27:47 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2021-12-02 08:05:33 +01:00
2023-04-13 17:55:56 +02:00
extern "C" {
2023-04-13 18:09:02 +02:00
#include <wire/common/SLIP.h>
2023-04-13 17:55:56 +02:00
}
2021-12-02 08:05:33 +01:00
/**
* @brief Helper class to handle the datalinklayer of replies from the star tracker of arcsec.
*/
2022-08-24 17:27:47 +02:00
class ArcsecDatalinkLayer {
2022-01-17 15:58:27 +01:00
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);
2023-04-15 15:15:06 +02:00
static const ReturnValue_t SLIP_OVERFLOW_RETVAL = MAKE_RETURN_CODE(0xA3);
static const ReturnValue_t SLIP_ID_MISSMATCH_RETVAL = MAKE_RETURN_CODE(0xA4);
2022-01-17 15:58:27 +01:00
static const uint8_t STATUS_OK = 0;
2023-03-22 10:38:41 +01:00
static constexpr size_t BUFFER_LENGTHS = 4096;
2022-01-17 15:58:27 +01:00
ArcsecDatalinkLayer();
virtual ~ArcsecDatalinkLayer();
2023-03-21 18:47:42 +01:00
/**
* Feed received data to the internal ring buffer.
* @param rawData
* @param rawDataLen
* @return
*/
ReturnValue_t feedData(const uint8_t* rawData, size_t rawDataLen);
2022-01-17 15:58:27 +01:00
/**
2023-03-22 10:38:41 +01:00
* Runs the arcsec datalink layer decoding algorithm on the data in the ring buffer, decoding
* frames in the process.
* @param decodedFrame
* @param frameLen
* @return
* - returnvalue::OK if a frame was found
* - DEC_IN_PROGRESS if frame decoding is in progress
* - Anything else is a decoding error
2022-01-17 15:58:27 +01:00
*/
2023-03-22 10:38:41 +01:00
ReturnValue_t checkRingBufForFrame(const uint8_t** decodedFrame, size_t& frameLen);
2022-01-17 15:58:27 +01:00
/**
* @brief SLIP encodes data pointed to by data pointer.
*
* @param data Pointer to data to encode
* @param length Length of buffer to encode
*/
2023-03-21 20:35:28 +01:00
void encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, size_t& frameLen);
2022-01-17 15:58:27 +01:00
2023-03-22 10:38:41 +01:00
void reset();
2022-01-17 15:58:27 +01:00
private:
static const uint8_t ID_OFFSET = 1;
static const uint8_t STATUS_OFFSET = 2;
2023-03-22 10:38:41 +01:00
// User to buffer and analyse data and allow feeding and checking for frames asychronously.
2023-03-21 18:47:42 +01:00
SimpleRingBuffer decodeRingBuf;
2023-03-22 10:38:41 +01:00
uint8_t rxAnalysisBuffer[BUFFER_LENGTHS];
2023-03-21 18:47:42 +01:00
2023-03-22 10:38:41 +01:00
// Used by arcsec slip decoding function to process received data. This should only be written
// to or read from by arcsec functions!
uint8_t rxBufferArc[startracker::MAX_FRAME_SIZE];
2022-01-17 15:58:27 +01:00
// Decoded frame will be copied to this buffer
2023-03-21 18:47:42 +01:00
uint8_t decodedRxFrame[startracker::MAX_FRAME_SIZE];
// Size of decoded frame
2023-04-15 15:15:06 +02:00
size_t rxFrameSize = 0;
2023-03-21 18:47:42 +01:00
2022-01-17 15:58:27 +01:00
// Buffer where encoded frames will be stored. First byte of encoded frame represents type of
// reply
2023-03-21 18:47:42 +01:00
uint8_t txEncoded[startracker::MAX_FRAME_SIZE * 2 + 2];
2022-01-17 15:58:27 +01:00
// Size of encoded frame
2023-03-21 18:47:42 +01:00
uint32_t txFrameSize = 0;
2022-01-17 15:58:27 +01:00
2023-04-15 15:15:06 +02:00
// slip_decode_state slipInfo;
2022-01-17 15:58:27 +01:00
void slipInit();
2021-12-02 08:05:33 +01:00
};
#endif /* BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_ */