13#include <QtCore/QByteArray>
14#include <QtCore/QByteArrayView>
27 [[nodiscard]]
constexpr uint16_t
value()
const {
return static_cast<uint16_t
>(
cls | (
id << 8)); }
33inline constexpr uint8_t
NAV = 0x01;
34inline constexpr uint8_t
RXM = 0x02;
35inline constexpr uint8_t
INF = 0x04;
36inline constexpr uint8_t
ACK = 0x05;
37inline constexpr uint8_t
CFG = 0x06;
38inline constexpr uint8_t
MON = 0x0a;
39inline constexpr uint8_t
SEC = 0x27;
40inline constexpr uint8_t
RTCM3 = 0xf5;
87inline constexpr std::pair<MessageId, std::string_view>
MESSAGE_NAMES[] = {
107 if (
id.value() == message.
value()) {
108 return QByteArrayView(name).toByteArray();
111 return QByteArrayLiteral(
"UBX-0x") + QByteArray::number(message.
cls, 16) +
"-0x" +
112 QByteArray::number(message.
id, 16);
118inline constexpr uint8_t
SYNC1 = 0xb5;
119inline constexpr uint8_t
SYNC2 = 0x62;
130[[nodiscard]]
constexpr std::span<const uint8_t>
encodeFrame(
MessageId message, std::span<const uint8_t> payload,
131 std::span<uint8_t> out)
139 out[2] = message.
cls;
141 out[4] =
static_cast<uint8_t
>(payload.size());
142 out[5] =
static_cast<uint8_t
>(payload.size() >> 8);
143 std::copy(payload.begin(), payload.end(), out.begin() +
HEADER_SIZE);
145 out[size - 2] = checksum.a;
146 out[size - 1] = checksum.b;
147 return out.first(size);
162 [[nodiscard]]
bool idle()
const {
return _state == State::Sync1; }
166 _state = State::Sync1;
170 [[nodiscard]] std::optional<Frame>
consume(uint8_t
byte)
175 _state = State::Sync2;
181 _state = State::Header;
182 }
else if (
byte !=
SYNC1) {
189 _length =
static_cast<uint16_t
>(_bytes[4] | (_bytes[5] << 8));
194 _state = _length ? State::Payload : State::Checksum1;
204 if (++_payloadRead == _length) {
205 _state = State::Checksum1;
208 case State::Checksum1:
209 if (
byte == _checksum.
a) {
210 _bytes[_size++] = byte;
211 _state = State::Checksum2;
216 case State::Checksum2: {
220 _bytes[_size++] = byte;
221 const std::span<const uint8_t> bytes(_bytes.data(), _size);
222 return Frame{
static_cast<uint16_t
>(_bytes[2] | (_bytes[3] << 8)), bytes,
242 void _add(uint8_t
byte)
245 _bytes[_size++] = byte;
248 std::array<uint8_t, MAX_PAYLOAD_SIZE + FRAME_OVERHEAD> _bytes{
SYNC1,
SYNC2};
250 uint16_t _length = 0;
251 uint16_t _payloadRead = 0;
252 State _state = State::Sync1;
std::optional< Frame > consume(uint8_t byte)
constexpr Fletcher8 fletcher8(std::span< const uint8_t > bytes, Fletcher8 state={})
Continues state over bytes, so a frame checksummed in parts matches the contiguous result.
constexpr MessageId CFG_VALSET
constexpr MessageId NAV_SVIN
constexpr MessageId ACK_NAK
constexpr MessageId RTCM3_1074
constexpr MessageId MON_HW
constexpr MessageId INF_DEBUG
constexpr MessageId MON_RF
constexpr MessageId SEC_SIG
constexpr MessageId RTCM3_1124
constexpr MessageId NAV_EOE
constexpr MessageId RTCM3_1077
constexpr MessageId ACK_ACK
constexpr MessageId RTCM3_1127
constexpr MessageId NAV_STATUS
constexpr MessageId NAV_DOP
constexpr MessageId RTCM3_1097
constexpr MessageId RXM_SFRBX
constexpr MessageId RTCM3_1230
constexpr MessageId NAV_TIMEGPS
constexpr MessageId CFG_VALGET
constexpr MessageId CFG_RATE
constexpr MessageId RXM_RAWX
constexpr MessageId NAV_SAT
constexpr MessageId MON_VER
constexpr MessageId RTCM3_1087
constexpr MessageId NAV_SVINFO
constexpr MessageId RTCM3_1005
constexpr MessageId INF_WARNING
constexpr MessageId CFG_MSG
constexpr MessageId CFG_NAV5
constexpr MessageId INF_ERROR
constexpr MessageId CFG_TMODE3
constexpr MessageId INF_NOTICE
constexpr MessageId NAV_HPPOSLLH
constexpr MessageId RTCM3_1084
constexpr MessageId NAV_PVT
constexpr MessageId RTCM3_1094
constexpr MessageId CFG_PRT
u-blox receivers over UBX: CFG-VALSET configuration from protocol 27, CFG-MSG and CFG-TMODE3 before i...
constexpr size_t HEADER_SIZE
constexpr std::pair< MessageId, std::string_view > MESSAGE_NAMES[]
Readable names of the messages above, as the interface description writes them.
constexpr size_t FRAME_OVERHEAD
Header and checksum.
constexpr std::span< const uint8_t > encodeFrame(MessageId message, std::span< const uint8_t > payload, std::span< uint8_t > out)
Writes the frame of payload to the front of out.
constexpr size_t MAX_SKIPPED_PAYLOAD_SIZE
constexpr size_t MAX_PAYLOAD_SIZE
The longest payload decoded.
QByteArray messageName(MessageId message)
The name of message, such as "UBX-CFG-VALSET", or its class and id in hex when it has none.
8-bit Fletcher checksum: two running byte sums modulo 256.
A received frame. Its views borrow the decoder's storage until the next consume().
std::span< const uint8_t > bytes
From the sync bytes to the checksum.
std::span< const uint8_t > payload
constexpr uint16_t value() const