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 "QGC.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
18ADSBVehicle::~ADSBVehicle()
19{
20 // qCDebug(ADSBVehicleLog) << Q_FUNC_INFO << this;
21}
22
23void ADSBVehicle::update(const ADSB::VehicleInfo_t &vehicleInfo)
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 if (vehicleInfo.availableFlags & ADSB::LocationAvailable) {
33 if (!QGC::fuzzyCompare(vehicleInfo.location.latitude(), coordinate().latitude()) || !QGC::fuzzyCompare(vehicleInfo.location.longitude(), coordinate().longitude())) {
34 _info.location.setLatitude(vehicleInfo.location.latitude());
35 _info.location.setLongitude(vehicleInfo.location.longitude());
36 emit coordinateChanged();
37 }
38 }
39
40 if (vehicleInfo.availableFlags & ADSB::AltitudeAvailable) {
41 if (!QGC::fuzzyCompare(vehicleInfo.location.altitude(), altitude())) {
42 _info.location.setAltitude(vehicleInfo.location.altitude());
43 emit altitudeChanged();
44 }
45 }
46
47 if (vehicleInfo.availableFlags & ADSB::HeadingAvailable) {
48 if (!QGC::fuzzyCompare(vehicleInfo.heading, heading())) {
49 _info.heading = vehicleInfo.heading;
50 emit headingChanged();
51 }
52 }
53
54 if (vehicleInfo.availableFlags & ADSB::VelocityAvailable) {
55 if (!QGC::fuzzyCompare(vehicleInfo.velocity, velocity())) {
56 _info.velocity = vehicleInfo.velocity;
57 emit velocityChanged();
58 }
59 }
60
61 if (vehicleInfo.availableFlags & ADSB::CallsignAvailable) {
62 if (vehicleInfo.callsign != callsign()) {
63 _info.callsign = vehicleInfo.callsign;
64 emit callsignChanged();
65 }
66 }
67
68 if (vehicleInfo.availableFlags & ADSB::SquawkAvailable) {
69 if (!QGC::fuzzyCompare(vehicleInfo.velocity, squawk())) {
70 _info.squawk = vehicleInfo.squawk;
71 emit squawkChanged();
72 }
73 }
74
76 if (!QGC::fuzzyCompare(vehicleInfo.verticalVel, verticalVel())) {
77 _info.verticalVel = vehicleInfo.verticalVel;
78 emit verticalVelChanged();
79 }
80 }
81
82 if (vehicleInfo.availableFlags & ADSB::AlertAvailable) {
83 if (vehicleInfo.alert != alert()) {
84 _info.alert = vehicleInfo.alert;
85 emit alertChanged();
86 }
87 }
88
89 _lastUpdateTimer.start();
90}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void coordinateChanged()
void headingChanged()
void squawkChanged()
void callsignChanged()
void altitudeChanged()
void alertChanged()
void velocityChanged()
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 QGC.cc:106
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