QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ADSBVehicle.cc
Go to the documentation of this file.
1#include "ADSBVehicle.h"
2#include "QGCMath.h"
4
5#include <QtCore/QtNumeric>
6
7QGC_LOGGING_CATEGORY(ADSBVehicleLog, "ADSB.ADSBVehicle")
8
9ADSBVehicle::ADSBVehicle(const ADSB::VehicleInfo_t &vehicleInfo, QObject *parent)
10 : QObject(parent)
11{
12 // qCDebug(ADSBVehicleLog) << Q_FUNC_INFO << this;
13
14 _info.icaoAddress = vehicleInfo.icaoAddress;
15 update(vehicleInfo);
16}
17
19{
20 // qCDebug(ADSBVehicleLog) << Q_FUNC_INFO << this;
21}
22
24{
25 if (vehicleInfo.icaoAddress != icaoAddress()) {
26 qCWarning(ADSBVehicleLog) << "ICAO address mismatch expected:" << icaoAddress() << "actual:" << vehicleInfo.icaoAddress;
27 return;
28 }
29
30 qCDebug(ADSBVehicleLog) << "Updating" << QStringLiteral("%1 Flags: %2").arg(vehicleInfo.icaoAddress, 0, 16).arg(vehicleInfo.availableFlags.toInt(), 0, 2);
31
32 // Keep-alive for expiration tracking. This must be updated even for throttled updates.
33 _lastUpdateTimer.start();
34
35 // Throttle the property update rate to prevent overloading the ui with map item updates. Skipped info will be
36 // picked up by a later update since ADS-B data is continuously re-transmitted. Alert transitions bypass the
37 // throttle since the collision warning must not be delayed.
38 const bool alertChange = (vehicleInfo.availableFlags & ADSB::AlertAvailable) && (vehicleInfo.alert != alert());
39 if (!alertChange && _lastPropertyUpdateTimer.isValid() && !_lastPropertyUpdateTimer.hasExpired(_propertyUpdateMinIntervalMs)) {
40 return;
41 }
42 _lastPropertyUpdateTimer.start();
43
44 if (vehicleInfo.availableFlags & ADSB::LocationAvailable) {
45 if (!QGC::fuzzyCompare(vehicleInfo.location.latitude(), coordinate().latitude()) || !QGC::fuzzyCompare(vehicleInfo.location.longitude(), coordinate().longitude())) {
46 _info.location.setLatitude(vehicleInfo.location.latitude());
47 _info.location.setLongitude(vehicleInfo.location.longitude());
48 emit coordinateChanged();
49 }
50 }
51
52 if (vehicleInfo.availableFlags & ADSB::AltitudeAvailable) {
53 if (!QGC::fuzzyCompare(vehicleInfo.location.altitude(), altitude())) {
54 _info.location.setAltitude(vehicleInfo.location.altitude());
55 emit altitudeChanged();
56 }
57 }
58
59 if (vehicleInfo.availableFlags & ADSB::HeadingAvailable) {
60 if (!QGC::fuzzyCompare(vehicleInfo.heading, heading())) {
61 _info.heading = vehicleInfo.heading;
62 emit headingChanged();
63 }
64 }
65
66 if (vehicleInfo.availableFlags & ADSB::VelocityAvailable) {
67 if (!QGC::fuzzyCompare(vehicleInfo.velocity, velocity())) {
68 _info.velocity = vehicleInfo.velocity;
69 emit velocityChanged();
70 }
71 }
72
73 if (vehicleInfo.availableFlags & ADSB::CallsignAvailable) {
74 if (vehicleInfo.callsign != callsign()) {
75 _info.callsign = vehicleInfo.callsign;
76 emit callsignChanged();
77 }
78 }
79
80 if (vehicleInfo.availableFlags & ADSB::SquawkAvailable) {
81 if (!QGC::fuzzyCompare(vehicleInfo.velocity, squawk())) {
82 _info.squawk = vehicleInfo.squawk;
83 emit squawkChanged();
84 }
85 }
86
88 if (!QGC::fuzzyCompare(vehicleInfo.verticalVel, verticalVel())) {
89 _info.verticalVel = vehicleInfo.verticalVel;
90 emit verticalVelChanged();
91 }
92 }
93
94 if (vehicleInfo.availableFlags & ADSB::AlertAvailable) {
95 if (vehicleInfo.alert != alert()) {
96 _info.alert = vehicleInfo.alert;
97 emit alertChanged();
98 }
99 }
100}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void coordinateChanged()
double altitude() const
Definition ADSBVehicle.h:35
double velocity() const
Definition ADSBVehicle.h:37
void headingChanged()
void squawkChanged()
double heading() const
Definition ADSBVehicle.h:36
bool alert() const
Definition ADSBVehicle.h:40
QString callsign() const
Definition ADSBVehicle.h:33
void callsignChanged()
uint16_t squawk() const
Definition ADSBVehicle.h:39
QGeoCoordinate coordinate() const
Definition ADSBVehicle.h:34
void update(const ADSB::VehicleInfo_t &vehicleInfo)
void altitudeChanged()
double verticalVel() const
Definition ADSBVehicle.h:38
void alertChanged()
void velocityChanged()
uint32_t icaoAddress() const
Definition ADSBVehicle.h:32
void verticalVelChanged()
Definition ADSB.h:8
@ AlertAvailable
Definition ADSB.h:41
@ SquawkAvailable
Definition ADSB.h:39
@ VelocityAvailable
Definition ADSB.h:37
@ CallsignAvailable
Definition ADSB.h:38
@ AltitudeAvailable
Definition ADSB.h:35
@ LocationAvailable
Definition ADSB.h:34
@ VerticalVelAvailable
Definition ADSB.h:40
@ HeadingAvailable
Definition ADSB.h:36
bool fuzzyCompare(double value1, double value2)
Returns true if the two values are equal or close. Correctly handles 0 and NaN values.
Definition QGCMath.cc:109
uint32_t icaoAddress
Definition ADSB.h:49
double velocity
Definition ADSB.h:54
AvailableInfoTypes availableFlags
Definition ADSB.h:48
double verticalVel
Definition ADSB.h:55
double heading
Definition ADSB.h:52
QString callsign
Definition ADSB.h:50
QGeoCoordinate location
Definition ADSB.h:51
uint16_t squawk
Definition ADSB.h:53