9#include <QtCore/QByteArray>
10#include <QtCore/QByteArrayView>
12#include <QtCore/QVector>
42 std::span<const uint8_t>
frame()
const {
return {_bytes.data(), _frameSize}; }
51 const uint16_t available = _frameSize ? _frameSize : _size;
58 return bytes.size() >=
HEADER_SIZE + 2 && bytes[0] ==
PREAMBLE ? (bytes[3] << 4) | (bytes[4] >> 4) : 0;
61 bool valid()
const {
return _valid; }
63 [[nodiscard]]
static bool isValidFrame(std::span<const uint8_t> bytes)
68 const size_t payloadSize = ((bytes[1] & 3) << 8) | bytes[2];
74 return isValidFrame(std::span<const uint8_t>(
reinterpret_cast<const uint8_t*
>(bytes.data()),
75 static_cast<size_t>(bytes.size())));
79 void _discardPrefix(uint16_t count);
80 uint16_t _discardCandidate();
81 bool _inspect(uint16_t validatedFrameSize);
83 std::array<uint8_t, MAX_FRAME_SIZE> _bytes{};
85 uint16_t _payloadSize = 0;
86 uint16_t _frameSize = 0;
87 uint16_t _recoverySize = 0;
107 std::optional<RTCMDecodedFrame>
addByte(uint8_t
byte, qint64 receivedAtMs);
109 std::optional<RTCMDecodedFrame>
nextFrame();
114 template <
typename Deliver>
115 bool feed(QByteArrayView bytes, qint64 receivedAtMs, Deliver&& deliver)
117 for (
const char byte : bytes) {
118 for (
auto frame =
addByte(
static_cast<uint8_t
>(
byte), receivedAtMs); frame; frame =
nextFrame()) {
119 if (!deliver(*frame)) {
127 void setWhitelist(
const QVector<int>& ids) { _whitelist = QSet<int>(ids.begin(), ids.end()); }
133 QSet<int> _whitelist;
134 std::array<qint64, RTCMFramer::MAX_FRAME_SIZE> _receiptTimes{};
135 size_t _nextReceiptIndex = 0;
Frames RTCM bytes while retaining the first fragment's monotonic receipt time.
void setWhitelist(const QVector< int > &ids)
std::optional< RTCMDecodedFrame > nextFrame()
Drain after addByte() returns a result, before feeding more bytes.
bool feed(QByteArrayView bytes, qint64 receivedAtMs, Deliver &&deliver)
std::optional< RTCMDecodedFrame > addByte(uint8_t byte, qint64 receivedAtMs)
static constexpr uint16_t CRC_SIZE
uint16_t messageId() const
std::span< const uint8_t > frame() const
Complete candidate, including malformed headers; empty while incomplete.
uint16_t bufferedSize() const
Retained suffix length, including bytes beyond the current candidate.
uint16_t payloadLength() const
static constexpr uint16_t HEADER_SIZE
bool hasPartialFrame() const
static constexpr uint8_t PREAMBLE
static constexpr uint16_t MAX_PAYLOAD_SIZE
static uint16_t frameMessageId(std::span< const uint8_t > bytes)
Message number from a frame header; zero when the header is incomplete.
static bool isValidFrame(std::span< const uint8_t > bytes)
static constexpr uint16_t MAX_FRAME_SIZE
bool addByte(uint8_t byte)
static bool isValidFrame(QByteArrayView bytes)
constexpr uint32_t crc24q(std::span< const uint8_t > bytes)
CRC-24Q: polynomial 0x1864CFB, initial value 0, no reflection and no final XOR.