QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SBFBlocks.h
Go to the documentation of this file.
1// Block layouts as the Septentrio SBF reference guide defines them.
2#pragma once
3
4#include <cstddef>
5#include <cstdint>
6#include <optional>
7#include <span>
8#include <tuple>
9
10#include "Checksums.h"
11#include "WireFields.h"
12
15namespace SBF {
16
17inline constexpr uint8_t SYNC1 = 0x24;
18inline constexpr uint8_t SYNC2 = 0x40;
19
22{
23 uint16_t sync;
24 uint16_t crc;
25 uint16_t id;
26 uint16_t length;
27
29 [[nodiscard]] constexpr uint16_t number() const { return static_cast<uint16_t>(id & 0x1fff); }
30};
31
32} // namespace SBF
33
34namespace SBF::BlockId {
35inline constexpr uint16_t PVT_GEODETIC = 4007;
36} // namespace SBF::BlockId
37
38namespace SBF {
39
41{
42 uint32_t tow;
43 uint16_t wnc;
44 uint8_t mode;
45 uint8_t error;
46 double latitude;
47 double longitude;
48 double height;
50 float vn;
51 float ve;
52 float vu;
53 float cog;
54 uint8_t datum;
55 uint8_t nrSV;
56 uint16_t hAccuracy;
57 uint16_t vAccuracy;
58
59 [[nodiscard]] constexpr uint8_t modeType() const { return static_cast<uint8_t>(mode & 0x0f); }
60
61 [[nodiscard]] constexpr bool modeAutoSet() const { return (mode & 0x40) != 0; }
62
63 [[nodiscard]] constexpr bool mode2D() const { return (mode & 0x80) != 0; }
64};
65
66} // namespace SBF
67
68namespace Wire {
69template <>
70struct Layout<SBF::BlockHeader>
71{
73 static constexpr size_t SIZE = 8;
74 static constexpr auto FIELDS =
76};
77
78template <>
89} // namespace Wire
90
91static_assert(Wire::VALID_LAYOUT<SBF::BlockHeader>);
92static_assert(Wire::VALID_LAYOUT<SBF::PVTGeodetic>);
93
94namespace SBF {
95
97[[nodiscard]] inline std::optional<BlockHeader> checkedHeader(std::span<const uint8_t> block)
98{
99 // The block CRC covers everything from the id field to the end of the block.
100 constexpr size_t CRC_START = 4;
101 if (block.size() < Wire::SIZE<BlockHeader>) {
102 return std::nullopt;
103 }
104 const auto header = Wire::decode<BlockHeader>(block);
105 if (header.length < Wire::SIZE<BlockHeader> || header.length > block.size() ||
106 header.crc != QGC::crc16Xmodem(block.subspan(CRC_START, header.length - CRC_START))) {
107 return std::nullopt;
108 }
109 return header;
110}
111
112} // namespace SBF
constexpr uint16_t crc16Xmodem(std::span< const uint8_t > bytes)
CRC-16/XMODEM: polynomial 0x1021, initial value 0, no reflection and no final XOR.
Definition Checksums.h:28
constexpr uint16_t PVT_GEODETIC
Definition SBFBlocks.h:35
Septentrio receivers configured as RTK bases with SBF commands; they stream PVTGeodetic blocks and RT...
constexpr uint8_t SYNC1
Definition SBFBlocks.h:17
std::optional< BlockHeader > checkedHeader(std::span< const uint8_t > block)
The header of a block candidate whose length fits the candidate and whose CRC matches; nullopt otherw...
Definition SBFBlocks.h:97
constexpr uint8_t SYNC2
Definition SBFBlocks.h:18
constexpr std::size_t SIZE
Definition WireFields.h:28
Starts every block. The CRC covers id through the end of the block; length counts the whole block.
Definition SBFBlocks.h:22
constexpr uint16_t number() const
Bits 0-12 of the id; bits 13-15 are the block revision.
Definition SBFBlocks.h:29
uint16_t sync
Definition SBFBlocks.h:23
uint16_t length
Definition SBFBlocks.h:26
constexpr bool modeAutoSet() const
Definition SBFBlocks.h:61
constexpr bool mode2D() const
Definition SBFBlocks.h:63
constexpr uint8_t modeType() const
Definition SBFBlocks.h:59
uint16_t vAccuracy
Definition SBFBlocks.h:57
uint16_t hAccuracy
Definition SBFBlocks.h:56