12 changed files with 295 additions and 26 deletions
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
* |
||||
* QGroundControl is licensed according to the terms in the file |
||||
* COPYING.md in the root of the source code directory. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#include "ADSBVehicle.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QtMath> |
||||
|
||||
ADSBVehicle::ADSBVehicle(mavlink_adsb_vehicle_t& adsbVehicle, QObject* parent) |
||||
: QObject (parent) |
||||
, _icaoAddress (adsbVehicle.ICAO_address) |
||||
, _altitude (NAN) |
||||
, _heading (NAN) |
||||
{ |
||||
if (!(adsbVehicle.flags | ADSB_FLAGS_VALID_COORDS)) { |
||||
qWarning() << "At least coords must be valid"; |
||||
return; |
||||
} |
||||
|
||||
update(adsbVehicle); |
||||
} |
||||
|
||||
void ADSBVehicle::update(mavlink_adsb_vehicle_t& adsbVehicle) |
||||
{ |
||||
if (_icaoAddress != adsbVehicle.ICAO_address) { |
||||
qWarning() << "ICAO address mismatch expected:actual" << _icaoAddress << adsbVehicle.ICAO_address; |
||||
return; |
||||
} |
||||
|
||||
if (!(adsbVehicle.flags | ADSB_FLAGS_VALID_COORDS)) { |
||||
return; |
||||
} |
||||
|
||||
QGeoCoordinate newCoordinate(adsbVehicle.lat / qPow(10.0, 7.0), adsbVehicle.lon / qPow(10.0, 7.0)); |
||||
if (newCoordinate != _coordinate) { |
||||
_coordinate = newCoordinate; |
||||
emit coordinateChanged(_coordinate); |
||||
} |
||||
|
||||
double newAltitude = NAN; |
||||
if (adsbVehicle.flags | ADSB_FLAGS_VALID_ALTITUDE) { |
||||
newAltitude = (double)adsbVehicle.altitude / 1000.0; |
||||
} |
||||
if (!(qIsNaN(newAltitude) && qIsNaN(_altitude)) && !qFuzzyCompare(newAltitude, _altitude)) { |
||||
_altitude = newAltitude; |
||||
emit altitudeChanged(_altitude); |
||||
} |
||||
|
||||
double newHeading = NAN; |
||||
if (adsbVehicle.flags | ADSB_FLAGS_VALID_HEADING) { |
||||
newHeading = (double)adsbVehicle.heading / 100.0; |
||||
} |
||||
if (!(qIsNaN(newHeading) && qIsNaN(_heading)) && !qFuzzyCompare(newHeading, _heading)) { |
||||
_heading = newHeading; |
||||
emit headingChanged(_heading); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||
* |
||||
* QGroundControl is licensed according to the terms in the file |
||||
* COPYING.md in the root of the source code directory. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <QObject> |
||||
#include <QGeoCoordinate> |
||||
|
||||
#include "QGCMAVLink.h" |
||||
|
||||
class ADSBVehicle : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
ADSBVehicle(mavlink_adsb_vehicle_t& adsbVehicle, QObject* parent = NULL); |
||||
|
||||
Q_PROPERTY(int icaoAddress READ icaoAddress CONSTANT) |
||||
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) |
||||
Q_PROPERTY(double altitude READ altitude NOTIFY altitudeChanged) // NaN for not available
|
||||
Q_PROPERTY(double heading READ heading NOTIFY headingChanged) // NaN for not available
|
||||
|
||||
int icaoAddress (void) const { return _icaoAddress; } |
||||
QGeoCoordinate coordinate (void) const { return _coordinate; } |
||||
double altitude (void) const { return _altitude; } |
||||
double heading (void) const { return _heading; } |
||||
|
||||
/// Update the vehicle with new information
|
||||
void update(mavlink_adsb_vehicle_t& adsbVehicle); |
||||
|
||||
signals: |
||||
void coordinateChanged(QGeoCoordinate coordinate); |
||||
void altitudeChanged(double altitude); |
||||
void headingChanged(double heading); |
||||
|
||||
private: |
||||
uint32_t _icaoAddress; |
||||
QGeoCoordinate _coordinate; |
||||
double _altitude; |
||||
double _heading; |
||||
}; |
Loading…
Reference in new issue