Commit 7fb7aa16 authored by DonLakeFlyer's avatar DonLakeFlyer

parent 44fa02aa
...@@ -30,7 +30,7 @@ void ADSBVehicleManager::setToolbox(QGCToolbox* toolbox) ...@@ -30,7 +30,7 @@ void ADSBVehicleManager::setToolbox(QGCToolbox* toolbox)
ADSBVehicleManagerSettings* settings = qgcApp()->toolbox()->settingsManager()->adsbVehicleManagerSettings(); ADSBVehicleManagerSettings* settings = qgcApp()->toolbox()->settingsManager()->adsbVehicleManagerSettings();
if (settings->adsbServerConnectEnabled()->rawValue().toBool()) { if (settings->adsbServerConnectEnabled()->rawValue().toBool()) {
_tcpLink = new ADSBTCPLink(this); _tcpLink = new ADSBTCPLink(settings->adsbServerHostAddress()->rawValue().toString(), settings->adsbServerPort()->rawValue().toInt(), this);
connect(_tcpLink, &ADSBTCPLink::adsbVehicleUpdate, this, &ADSBVehicleManager::adsbVehicleUpdate, Qt::QueuedConnection); connect(_tcpLink, &ADSBTCPLink::adsbVehicleUpdate, this, &ADSBVehicleManager::adsbVehicleUpdate, Qt::QueuedConnection);
} }
} }
...@@ -41,6 +41,7 @@ void ADSBVehicleManager::_cleanupStaleVehicles() ...@@ -41,6 +41,7 @@ void ADSBVehicleManager::_cleanupStaleVehicles()
for (int i=_adsbVehicles.count()-1; i>=0; i--) { for (int i=_adsbVehicles.count()-1; i>=0; i--) {
ADSBVehicle* adsbVehicle = _adsbVehicles.value<ADSBVehicle*>(i); ADSBVehicle* adsbVehicle = _adsbVehicles.value<ADSBVehicle*>(i);
if (adsbVehicle->expired()) { if (adsbVehicle->expired()) {
qCDebug(ADSBVehicleManagerLog) << "Expired" << QStringLiteral("%1").arg(adsbVehicle->icaoAddress(), 0, 16);
_adsbVehicles.removeAt(i); _adsbVehicles.removeAt(i);
adsbVehicle->deleteLater(); adsbVehicle->deleteLater();
} }
...@@ -62,10 +63,11 @@ void ADSBVehicleManager::adsbVehicleUpdate(const ADSBVehicle::VehicleInfo_t vehi ...@@ -62,10 +63,11 @@ void ADSBVehicleManager::adsbVehicleUpdate(const ADSBVehicle::VehicleInfo_t vehi
} }
} }
ADSBTCPLink::ADSBTCPLink(QObject* parent) ADSBTCPLink::ADSBTCPLink(const QString& hostAddress, int port, QObject* parent)
: QThread(parent) : QThread (parent)
, _hostAddress (hostAddress)
, _port (port)
{ {
_settings = qgcApp()->toolbox()->settingsManager()->adsbVehicleManagerSettings();
moveToThread(this); moveToThread(this);
start(); start();
} }
...@@ -74,7 +76,6 @@ ADSBTCPLink::~ADSBTCPLink(void) ...@@ -74,7 +76,6 @@ ADSBTCPLink::~ADSBTCPLink(void)
{ {
if (_socket) { if (_socket) {
_socket->disconnectFromHost(); _socket->disconnectFromHost();
_socket->waitForDisconnected();
_socket->deleteLater(); _socket->deleteLater();
_socket = nullptr; _socket = nullptr;
} }
...@@ -94,7 +95,7 @@ void ADSBTCPLink::_hardwareConnect() ...@@ -94,7 +95,7 @@ void ADSBTCPLink::_hardwareConnect()
QObject::connect(_socket, &QTcpSocket::readyRead, this, &ADSBTCPLink::_readBytes); QObject::connect(_socket, &QTcpSocket::readyRead, this, &ADSBTCPLink::_readBytes);
_socket->connectToHost(_settings->adsbServerHostAddress()->rawValue().toString(), _settings->adsbServerPort()->rawValue().toInt()); _socket->connectToHost(_hostAddress, _port);
// Give the socket a second to connect to the other side otherwise error out // Give the socket a second to connect to the other side otherwise error out
if (!_socket->waitForConnected(1000)) { if (!_socket->waitForConnected(1000)) {
......
...@@ -25,7 +25,7 @@ class ADSBTCPLink : public QThread ...@@ -25,7 +25,7 @@ class ADSBTCPLink : public QThread
Q_OBJECT Q_OBJECT
public: public:
ADSBTCPLink(QObject* parent); ADSBTCPLink(const QString& hostAddress, int port, QObject* parent);
~ADSBTCPLink(); ~ADSBTCPLink();
signals: signals:
...@@ -42,8 +42,9 @@ private: ...@@ -42,8 +42,9 @@ private:
void _hardwareConnect(void); void _hardwareConnect(void);
void _parseLine(const QString& line); void _parseLine(const QString& line);
QTcpSocket* _socket = nullptr; QString _hostAddress;
ADSBVehicleManagerSettings* _settings = nullptr; int _port;
QTcpSocket* _socket = nullptr;
}; };
class ADSBVehicleManager : public QGCTool { class ADSBVehicleManager : public QGCTool {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment