QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NMEASatellites.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <map>
6#include <optional>
7#include <set>
8#include <string_view>
9#include <vector>
10
11#include "GPSReceiverReports.h"
12
13namespace NMEA {
14namespace SatelliteIds {
15inline constexpr int FIRST_LOCAL_ID = 1;
16inline constexpr int GLONASS_FIRST_NMEA_ID = 65;
17inline constexpr int GLONASS_LAST_NMEA_ID = 96;
18inline constexpr int GALILEO_FIRST_NMEA_ID = 301;
19inline constexpr int GALILEO_LAST_NMEA_ID = 336;
20inline constexpr int BEIDOU_EXTENDED_FIRST_NMEA_ID = 401;
21inline constexpr int BEIDOU_EXTENDED_LAST_NMEA_ID = 463;
22inline constexpr int BEIDOU_LEGACY_FIRST_NMEA_ID = 201;
23inline constexpr int BEIDOU_LEGACY_LAST_NMEA_ID = 235;
24inline constexpr int QZSS_FIRST_NMEA_ID = 193;
25inline constexpr int QZSS_LAST_NMEA_ID = 202;
26inline constexpr int SBAS_FIRST_NMEA_ID = 33;
27inline constexpr int SBAS_LAST_NMEA_ID = 64;
28inline constexpr int SBAS_FIRST_PRN = 120;
29} // namespace SatelliteIds
30
32[[nodiscard]] inline int satelliteId(GPSConstellation constellation, int wireId)
33{
34 namespace Id = SatelliteIds;
35
36 switch (constellation) {
38 return wireId >= Id::GLONASS_FIRST_NMEA_ID && wireId <= Id::GLONASS_LAST_NMEA_ID
39 ? wireId - Id::GLONASS_FIRST_NMEA_ID + Id::FIRST_LOCAL_ID
40 : wireId;
42 return wireId >= Id::GALILEO_FIRST_NMEA_ID && wireId <= Id::GALILEO_LAST_NMEA_ID
43 ? wireId - Id::GALILEO_FIRST_NMEA_ID + Id::FIRST_LOCAL_ID
44 : wireId;
46 if (wireId >= Id::BEIDOU_EXTENDED_FIRST_NMEA_ID && wireId <= Id::BEIDOU_EXTENDED_LAST_NMEA_ID) {
47 return wireId - Id::BEIDOU_EXTENDED_FIRST_NMEA_ID + Id::FIRST_LOCAL_ID;
48 }
49 return wireId >= Id::BEIDOU_LEGACY_FIRST_NMEA_ID && wireId <= Id::BEIDOU_LEGACY_LAST_NMEA_ID
50 ? wireId - Id::BEIDOU_LEGACY_FIRST_NMEA_ID + Id::FIRST_LOCAL_ID
51 : wireId;
53 return wireId >= Id::QZSS_FIRST_NMEA_ID && wireId <= Id::QZSS_LAST_NMEA_ID
54 ? wireId - Id::QZSS_FIRST_NMEA_ID + Id::FIRST_LOCAL_ID
55 : wireId;
57 return wireId >= Id::SBAS_FIRST_NMEA_ID && wireId <= Id::SBAS_LAST_NMEA_ID
58 ? wireId - Id::SBAS_FIRST_NMEA_ID + Id::SBAS_FIRST_PRN
59 : wireId;
60 default:
61 return wireId;
62 }
63}
64
65[[nodiscard]] GPSConstellation satelliteConstellation(std::string_view talker, std::optional<int> systemId,
66 std::optional<int> satelliteId);
67
68struct Sentence;
69
75
84
85using SatelliteEpoch = std::vector<SatelliteSystem>;
86
87struct GSV
88{
91 int messages = 0;
92 int message = 0;
94 int signal = -1;
95 std::vector<SatelliteData> satellites = {};
96};
97
98[[nodiscard]] std::optional<GSV> gsv(const Sentence& input);
99
102{
103public:
104 static constexpr std::chrono::microseconds IDLE_TIMEOUT = std::chrono::milliseconds(150);
105 static constexpr std::chrono::microseconds BATCH_TIMEOUT = std::chrono::seconds(1);
106
107 struct Update
108 {
109 bool accepted = false;
111 };
112
113 void clear();
114
115 Update ingest(const Sentence& input, uint64_t receivedAtUs);
116
118 SatelliteEpoch flushDue(uint64_t nowUs);
119 std::optional<uint64_t> deadlineUs() const;
120
121private:
122 struct View
123 {
124 int messages = 0;
125 int count = 0;
126 int next = 1;
127 uint64_t timestamp = 0;
128 std::vector<SatelliteData> satellites = {};
129
130 bool complete() const { return messages > 0 && next == messages + 1; }
131 };
132
133 struct Used
134 {
135 uint64_t timestamp = 0;
136 std::set<int> ids;
137 };
138
139 std::map<GPSConstellation, std::map<int, View>> _views;
140 std::map<GPSConstellation, Used> _used;
141 std::optional<int> _time;
142 std::optional<uint64_t> _batchStartedUs;
143 uint64_t _lastAcceptedUs = 0;
144};
145} // namespace NMEA
GPSConstellation
std::array< MessageId, 4 > messages
Definition UBXPlan.cc:14
Bounded multipart/multisignal assembly; scheduling and delivery remain with the caller.
std::optional< uint64_t > deadlineUs() const
Update ingest(const Sentence &input, uint64_t receivedAtUs)
static constexpr std::chrono::microseconds BATCH_TIMEOUT
SatelliteEpoch flushDue(uint64_t nowUs)
static constexpr std::chrono::microseconds IDLE_TIMEOUT
constexpr int QZSS_FIRST_NMEA_ID
constexpr int QZSS_LAST_NMEA_ID
constexpr int FIRST_LOCAL_ID
constexpr int BEIDOU_EXTENDED_LAST_NMEA_ID
constexpr int BEIDOU_EXTENDED_FIRST_NMEA_ID
constexpr int BEIDOU_LEGACY_LAST_NMEA_ID
constexpr int GLONASS_LAST_NMEA_ID
constexpr int GLONASS_FIRST_NMEA_ID
constexpr int GALILEO_LAST_NMEA_ID
constexpr int SBAS_LAST_NMEA_ID
constexpr int SBAS_FIRST_NMEA_ID
constexpr int SBAS_FIRST_PRN
constexpr int GALILEO_FIRST_NMEA_ID
constexpr int BEIDOU_LEGACY_FIRST_NMEA_ID
std::optional< GSV > gsv(const Sentence &input)
GPSConstellation satelliteConstellation(std::string_view talker, std::optional< int > systemId, std::optional< int > satelliteId)
std::vector< SatelliteSystem > SatelliteEpoch
int satelliteId(GPSConstellation constellation, int wireId)
Canonical constellation-local identifier; preserve unknown/vendor ranges unchanged.
GPSConstellation constellation
Unknown denotes a combined GN report with identities resolved per satellite.
std::vector< SatelliteData > satellites
GPSConstellation constellation
std::optional< int > inUse
GPSConstellation constellation