QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSProvider.cc
Go to the documentation of this file.
1#include "GPSProvider.h"
2
3#include "GPSDriver.h"
5#include "RTCMMavlink.h"
7
8#include <utility>
9
10QGC_LOGGING_CATEGORY(GPSProviderLog, "GPS.GPSProvider")
11
12GPSProvider::GPSProvider(const QString &device, GPSType type, const GPSReceiverConfig &config, const std::atomic_bool &requestStop, QObject *parent)
13 : QThread(parent)
14 , _device(device)
15 , _type(type)
16 , _requestStop(requestStop)
17 , _config(config)
18{
19 qCDebug(GPSProviderLog) << QStringLiteral("Survey in accuracy: %1 | duration: %2").arg(_config.surveyInAccMeters).arg(_config.surveyInDurationSecs);
20}
21
22void GPSProvider::run()
23{
24#ifdef SIMULATE_RTCM_OUTPUT
25 RTCMMavlink rtcm;
26 rtcm.sendSimulatedData(_requestStop);
27 return;
28#endif
29
30 SerialGPSTransport transport(_device, _requestStop);
31 if (!transport.open()) {
32 if (!_requestStop) {
34 }
35 return;
36 }
37
38 bool gotData = false;
39 GPSDriverSinks sinks;
40 sinks.onPosition = [this](const sensor_gps_s &message) { emit sensorGpsUpdate(message); };
41 sinks.onSatelliteInfo = [this](const satellite_info_s &message) { emit satelliteInfoUpdate(message); };
42 sinks.onRTCM = [this, &gotData](const QByteArray &message) {
43 gotData = true;
44 emit RTCMDataUpdate(message);
45 };
46 sinks.onSurveyIn = [this, &gotData](const GPSSurveyInStatus &status) {
47 gotData = true;
48 qCDebug(GPSProviderLog) << QStringLiteral("Survey-in: %1s accuracy: %2mm valid: %3 active: %4")
49 .arg(status.durationSecs).arg(status.meanAccuracyMM).arg(status.valid).arg(status.active);
50 emit surveyInStatus(status);
51 };
52
53 GPSDriver driver(_type, transport, _config, std::move(sinks));
54
55 bool configErrorReported = false;
56 while (!_requestStop) {
57 if (!driver.configure()) {
58 if (_requestStop) {
59 break; // disconnect aborted configure mid-flight; not a real failure
60 }
61 if (!configErrorReported) {
63 configErrorReported = true;
64 }
65 msleep(kConfigRetryDelayMs);
66 continue;
67 }
68 configErrorReported = false;
69
70 uint8_t idleCycles = 0;
71 while (!_requestStop && (idleCycles < kMaxIdleReceiveCycles)) {
72 gotData = false;
73 const int ret = driver.receive(kGPSReceiveTimeout);
74 const bool progress = (ret > 0) || gotData; // position/sat (ret) or RTCM/survey-in (sinks)
75 idleCycles = progress ? 0 : (idleCycles + 1);
76 }
77
78 if (transport.fatalError()) {
80 break;
81 }
82 }
83
84 qCDebug(GPSProviderLog) << "Exiting GPS thread";
85}
@ ConfigFailed
receiver did not accept configuration
@ DeviceError
fatal serial error after a working connection
@ OpenFailed
serial device could not be opened
GPSType
Receiver families QGC can drive via the px4-gpsdrivers library.
Definition GPSType.h:5
Config config
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void RTCMDataUpdate(const QByteArray &message)
void sensorGpsUpdate(const sensor_gps_s &message)
void satelliteInfoUpdate(const satellite_info_s &message)
void surveyInStatus(const GPSSurveyInStatus &status)
void connectionError(GPSConnectionError error)
std::function< void(const sensor_gps_s &)> onPosition
Definition GPSDriver.h:47
std::function< void(const satellite_info_s &)> onSatelliteInfo
Definition GPSDriver.h:48
std::function< void(const GPSSurveyInStatus &)> onSurveyIn
Definition GPSDriver.h:50
std::function< void(const QByteArray &)> onRTCM
Definition GPSDriver.h:49
RTK base-station configuration, decoupled from QGC settings types.
Definition GPSDriver.h:19
Survey-in progress, translated from the px4 SurveyInStatus.
Definition GPSDriver.h:32