Skip to content

Commit

Permalink
Merge pull request #661 from OpenHD/consti-dev
Browse files Browse the repository at this point in the history
mostly merge adsb
  • Loading branch information
Consti10 authored Feb 18, 2024
2 parents c04802f + 0b6dda8 commit 1eb49f7
Show file tree
Hide file tree
Showing 25 changed files with 2,596 additions and 4 deletions.
6 changes: 6 additions & 0 deletions QOpenHD.pro
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ LinuxBuild {

# All Generic files / files that literally have 0!! dependencies other than qt
SOURCES += \
app/adsb/adsbvehicle.cpp \
app/adsb/adsbvehiclemanager.cpp \
app/adsb/qmlobjectlistmodel.cpp \
app/logging/hudlogmessagesmodel.cpp \
app/logging/logmessagesmodel.cpp \
app/util/mousehelper.cpp \
Expand All @@ -111,6 +114,9 @@ SOURCES += \
app/main.cpp \

HEADERS += \
app/adsb/adsbvehicle.h \
app/adsb/adsbvehiclemanager.h \
app/adsb/qmlobjectlistmodel.h \
app/common/ThreadsafeQueue.hpp \
app/common/util_fs.h \
app/common/StringHelper.hpp \
Expand Down
98 changes: 98 additions & 0 deletions app/adsb/adsbvehicle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/****************************************************************************
*
* This file has been ported from 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(const VehicleInfo_t& vehicleInfo, QObject* parent)
: QObject (parent)
, _icaoAddress (vehicleInfo.icaoAddress)
, _altitude (qQNaN())
, _heading (qQNaN())
, _alert (false)
{
update(vehicleInfo);
}

void ADSBVehicle::update(const VehicleInfo_t& vehicleInfo)
{
if (_icaoAddress != vehicleInfo.icaoAddress) {
qDebug() << "ICAO address mismatch expected:actual" << _icaoAddress << vehicleInfo.icaoAddress;
return;
}
if (vehicleInfo.availableFlags & CallsignAvailable) {
if (vehicleInfo.callsign != _callsign) {
_callsign = vehicleInfo.callsign;
emit callsignChanged();
}
}
if (vehicleInfo.availableFlags & LocationAvailable) {
if (_lat != vehicleInfo.lat || _lon != vehicleInfo.lon) {
_lat = vehicleInfo.lat;
_lon = vehicleInfo.lon;
emit latChanged();
emit lonChanged();
}
}
if (vehicleInfo.availableFlags & AltitudeAvailable) {
if (!(qIsNaN(vehicleInfo.altitude) && qIsNaN(_altitude)) && !qFuzzyCompare(vehicleInfo.altitude, _altitude)) {
_altitude = vehicleInfo.altitude;
emit altitudeChanged();
}
}
if (vehicleInfo.availableFlags & HeadingAvailable) {
if (!(qIsNaN(vehicleInfo.heading) && qIsNaN(_heading)) && !qFuzzyCompare(vehicleInfo.heading, _heading)) {
_heading = vehicleInfo.heading;
emit headingChanged();
}
}
if (vehicleInfo.availableFlags & AlertAvailable) {
if (vehicleInfo.alert != _alert) {
_alert = vehicleInfo.alert;
emit alertChanged();
}
}
if (vehicleInfo.availableFlags & VelocityAvailable) {
if (vehicleInfo.velocity != _velocity) {
_velocity = vehicleInfo.velocity;
emit velocityChanged();
}
}
if (vehicleInfo.availableFlags & VerticalVelAvailable) {
if (vehicleInfo.verticalVel != _verticalVel) {
_verticalVel = vehicleInfo.verticalVel;
emit verticalVelChanged();
}
}
if (vehicleInfo.availableFlags & LastContactAvailable) {
if (vehicleInfo.lastContact != _lastContact) {
_lastContact = vehicleInfo.lastContact;
emit lastContactChanged();
}
}
if (vehicleInfo.availableFlags & DistanceAvailable) {
if (vehicleInfo.distance != _distance) {
_distance = vehicleInfo.distance;
emit distanceChanged();
}
}
_lastUpdateTimer.restart();
}

bool ADSBVehicle::expired()
{
return _lastUpdateTimer.hasExpired(expirationTimeoutMs);
}

bool ADSBVehicle::tooFar()
{
return _too_far;
}
114 changes: 114 additions & 0 deletions app/adsb/adsbvehicle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/****************************************************************************
*
* This file has been ported from 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 <QElapsedTimer>

class ADSBVehicle : public QObject
{
Q_OBJECT

public:
enum {
CallsignAvailable = 1 << 1,
LocationAvailable = 1 << 2,
AltitudeAvailable = 1 << 3,
HeadingAvailable = 1 << 4,
AlertAvailable = 1 << 5,
VelocityAvailable = 1 << 6,
VerticalVelAvailable = 1 << 7,
LastContactAvailable = 1 << 8,
DistanceAvailable = 1 << 8
};

typedef struct {
uint32_t icaoAddress; // Required
QString callsign;
double lat;
double lon;
double altitude;
double velocity;
double heading;
int alert;
uint32_t availableFlags;
int lastContact;
double verticalVel;
double distance;
} VehicleInfo_t;

ADSBVehicle(const VehicleInfo_t& vehicleInfo, QObject* parent);

Q_PROPERTY(int icaoAddress READ icaoAddress CONSTANT)
Q_PROPERTY(QString callsign READ callsign NOTIFY callsignChanged)
Q_PROPERTY(double lat READ lat NOTIFY latChanged)
Q_PROPERTY(double lon READ lon NOTIFY lonChanged)
Q_PROPERTY(double altitude READ altitude NOTIFY altitudeChanged) // NaN for not available
Q_PROPERTY(double velocity READ velocity NOTIFY velocityChanged) // NaN for not available
Q_PROPERTY(double heading READ heading NOTIFY headingChanged) // NaN for not available
Q_PROPERTY(int alert READ alert NOTIFY alertChanged) // Collision path
Q_PROPERTY(int lastContact READ lastContact NOTIFY lastContactChanged)
Q_PROPERTY(double verticalVel READ verticalVel NOTIFY verticalVelChanged)
Q_PROPERTY(double distance READ distance NOTIFY distanceChanged)

int icaoAddress (void) const { return static_cast<int>(_icaoAddress); }
QString callsign (void) const { return _callsign; }
double lat (void) const { return _lat; }
double lon (void) const { return _lon; }
double altitude (void) const { return _altitude; }
double velocity (void) const { return _velocity; }
double heading (void) const { return _heading; }
int alert (void) const { return _alert; }
int lastContact (void) const { return _lastContact; }
double verticalVel (void) const { return _verticalVel; }
double distance (void) const { return _distance; }

void update(const VehicleInfo_t& vehicleInfo);

/// check if the vehicle is expired and should be removed
bool expired();

bool tooFar();

signals:
void latChanged ();
void lonChanged ();
void callsignChanged ();
void altitudeChanged ();
void velocityChanged ();
void headingChanged ();
void alertChanged ();
void lastContactChanged ();
void verticalVelChanged ();
void distanceChanged ();

private:
// This is the time in ms our vehicle will expire and thus removed from map
static constexpr qint64 expirationTimeoutMs = 25000;

uint32_t _icaoAddress;
QString _callsign;
double _lat;
double _lon;
double _altitude;
double _velocity;
double _heading;
int _alert;
int _lastContact;
double _verticalVel;
double _distance;

QElapsedTimer _lastUpdateTimer;

bool _too_far = false;
};

Q_DECLARE_METATYPE(ADSBVehicle::VehicleInfo_t)
Loading

0 comments on commit 1eb49f7

Please sign in to comment.