Unverified Commit ad57d68f authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #6110 from mavlink/udpChange

UDP Change
parents 43d3d89a 16cf1826
...@@ -493,6 +493,7 @@ void MissionController::removeAll(void) ...@@ -493,6 +493,7 @@ void MissionController::removeAll(void)
{ {
if (_visualItems) { if (_visualItems) {
_deinitAllVisualItems(); _deinitAllVisualItems();
_visualItems->clearAndDeleteContents();
_visualItems->deleteLater(); _visualItems->deleteLater();
_settingsItem = NULL; _settingsItem = NULL;
_visualItems = new QmlObjectListModel(this); _visualItems = new QmlObjectListModel(this);
......
...@@ -296,7 +296,7 @@ private: ...@@ -296,7 +296,7 @@ private:
static const char* _jsonFixedValueIsAltitudeKey; static const char* _jsonFixedValueIsAltitudeKey;
static const char* _jsonRefly90DegreesKey; static const char* _jsonRefly90DegreesKey;
static const int _hoverAndCaptureDelaySeconds = 1; static const int _hoverAndCaptureDelaySeconds = 2;
}; };
#endif #endif
...@@ -61,14 +61,14 @@ double limitAngleToPMPId(double angle) ...@@ -61,14 +61,14 @@ double limitAngleToPMPId(double angle)
{ {
while (angle < -M_PI) while (angle < -M_PI)
{ {
angle += M_PI; angle += 2.0f * M_PI;
} }
} }
else if (angle > M_PI) else if (angle > M_PI)
{ {
while (angle > M_PI) while (angle > M_PI)
{ {
angle -= M_PI; angle -= 2.0f * M_PI;
} }
} }
} }
......
...@@ -33,6 +33,8 @@ TerrainBatchManager::TerrainBatchManager(void) ...@@ -33,6 +33,8 @@ TerrainBatchManager::TerrainBatchManager(void)
void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates) void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates)
{ {
if (coordinates.length() > 0) { if (coordinates.length() > 0) {
qCDebug(ElevationProviderLog) << "addQuery: elevationProvider:coordinates.count" << elevationProvider << coordinates.count();
connect(elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
QueuedRequestInfo_t queuedRequestInfo = { elevationProvider, coordinates }; QueuedRequestInfo_t queuedRequestInfo = { elevationProvider, coordinates };
_requestQueue.append(queuedRequestInfo); _requestQueue.append(queuedRequestInfo);
if (!_batchTimer.isActive()) { if (!_batchTimer.isActive()) {
...@@ -43,7 +45,7 @@ void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const Q ...@@ -43,7 +45,7 @@ void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const Q
void TerrainBatchManager::_sendNextBatch(void) void TerrainBatchManager::_sendNextBatch(void)
{ {
qCDebug(ElevationProviderLog) << "_sendNextBatch _state:_requestQueue.count" << (int)_state << _requestQueue.count(); qCDebug(ElevationProviderLog) << "_sendNextBatch _state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
if (_state != State::Idle) { if (_state != State::Idle) {
// Waiting for last download the complete, wait some more // Waiting for last download the complete, wait some more
...@@ -60,7 +62,7 @@ void TerrainBatchManager::_sendNextBatch(void) ...@@ -60,7 +62,7 @@ void TerrainBatchManager::_sendNextBatch(void)
// Convert coordinates to point strings for json query // Convert coordinates to point strings for json query
QString points; QString points;
foreach (const QueuedRequestInfo_t& requestInfo, _requestQueue) { foreach (const QueuedRequestInfo_t& requestInfo, _requestQueue) {
SentRequestInfo_t sentRequestInfo = { requestInfo.elevationProvider, requestInfo.coordinates.count() }; SentRequestInfo_t sentRequestInfo = { requestInfo.elevationProvider, false, requestInfo.coordinates.count() };
qCDebug(ElevationProviderLog) << "Building request: coordinate count" << requestInfo.coordinates.count(); qCDebug(ElevationProviderLog) << "Building request: coordinate count" << requestInfo.coordinates.count();
_sentRequests.append(sentRequestInfo); _sentRequests.append(sentRequestInfo);
...@@ -100,20 +102,23 @@ void TerrainBatchManager::_batchFailed(void) ...@@ -100,20 +102,23 @@ void TerrainBatchManager::_batchFailed(void)
QList<float> noAltitudes; QList<float> noAltitudes;
foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) { foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) {
sentRequestInfo.elevationProvider->_signalTerrainData(false, noAltitudes); if (!sentRequestInfo.providerDestroyed) {
disconnect(sentRequestInfo.elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
sentRequestInfo.elevationProvider->_signalTerrainData(false, noAltitudes);
}
} }
_sentRequests.clear(); _sentRequests.clear();
} }
void TerrainBatchManager::_requestFinished() void TerrainBatchManager::_requestFinished()
{ {
qCDebug(ElevationProviderLog) << "_requestFinished";
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender()); QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
_state = State::Idle; _state = State::Idle;
// When an error occurs we still end up here // When an error occurs we still end up here
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCDebug(ElevationProviderLog) << "_requestFinished error:" << reply->error();
_batchFailed(); _batchFailed();
reply->deleteLater(); reply->deleteLater();
return; return;
...@@ -124,6 +129,7 @@ void TerrainBatchManager::_requestFinished() ...@@ -124,6 +129,7 @@ void TerrainBatchManager::_requestFinished()
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument responseJson = QJsonDocument::fromJson(responseBytes, &parseError); QJsonDocument responseJson = QJsonDocument::fromJson(responseBytes, &parseError);
if (parseError.error != QJsonParseError::NoError) { if (parseError.error != QJsonParseError::NoError) {
qCDebug(ElevationProviderLog) << "_requestFinished unable to parse json:" << parseError.errorString();
_batchFailed(); _batchFailed();
reply->deleteLater(); reply->deleteLater();
return; return;
...@@ -132,6 +138,7 @@ void TerrainBatchManager::_requestFinished() ...@@ -132,6 +138,7 @@ void TerrainBatchManager::_requestFinished()
QJsonObject rootObject = responseJson.object(); QJsonObject rootObject = responseJson.object();
QString status = rootObject["status"].toString(); QString status = rootObject["status"].toString();
if (status != "success") { if (status != "success") {
qCDebug(ElevationProviderLog) << "_requestFinished status != success:" << status;
_batchFailed(); _batchFailed();
reply->deleteLater(); reply->deleteLater();
return; return;
...@@ -145,15 +152,56 @@ void TerrainBatchManager::_requestFinished() ...@@ -145,15 +152,56 @@ void TerrainBatchManager::_requestFinished()
int currentIndex = 0; int currentIndex = 0;
foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) { foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) {
QList<float> requestAltitudes = altitudes.mid(currentIndex, sentRequestInfo.cCoord); if (!sentRequestInfo.providerDestroyed) {
sentRequestInfo.elevationProvider->_signalTerrainData(true, requestAltitudes); disconnect(sentRequestInfo.elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
currentIndex += sentRequestInfo.cCoord; QList<float> requestAltitudes = altitudes.mid(currentIndex, sentRequestInfo.cCoord);
sentRequestInfo.elevationProvider->_signalTerrainData(true, requestAltitudes);
currentIndex += sentRequestInfo.cCoord;
}
} }
_sentRequests.clear(); _sentRequests.clear();
reply->deleteLater(); reply->deleteLater();
} }
void TerrainBatchManager::_elevationProviderDestroyed(QObject* elevationProvider)
{
// Remove/Mark deleted objects queries from queues
qCDebug(ElevationProviderLog) << "_elevationProviderDestroyed elevationProvider" << elevationProvider;
int i = 0;
while (i < _requestQueue.count()) {
const QueuedRequestInfo_t& requestInfo = _requestQueue[i];
if (requestInfo.elevationProvider == elevationProvider) {
qCDebug(ElevationProviderLog) << "Removing deleted provider from _requestQueue index:elevationProvider" << i << requestInfo.elevationProvider;
_requestQueue.removeAt(i);
} else {
i++;
}
}
for (int i=0; i<_sentRequests.count(); i++) {
SentRequestInfo_t& sentRequestInfo = _sentRequests[i];
if (sentRequestInfo.elevationProvider == elevationProvider) {
qCDebug(ElevationProviderLog) << "Zombieing deleted provider from _sentRequests index:elevatationProvider" << sentRequestInfo.elevationProvider;
sentRequestInfo.providerDestroyed = true;
}
}
}
QString TerrainBatchManager::_stateToString(State state)
{
switch (state) {
case State::Idle:
return QStringLiteral("Idle");
case State::Downloading:
return QStringLiteral("Downloading");
}
return QStringLiteral("State unknown");
}
ElevationProvider::ElevationProvider(QObject* parent) ElevationProvider::ElevationProvider(QObject* parent)
: QObject(parent) : QObject(parent)
{ {
...@@ -161,7 +209,6 @@ ElevationProvider::ElevationProvider(QObject* parent) ...@@ -161,7 +209,6 @@ ElevationProvider::ElevationProvider(QObject* parent)
} }
void ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinates) void ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinates)
{ {
qCDebug(ElevationProviderLog) << "queryTerrainData: coordinate count" << coordinates.count();
if (coordinates.length() == 0) { if (coordinates.length() == 0) {
return; return;
} }
......
...@@ -30,8 +30,9 @@ public: ...@@ -30,8 +30,9 @@ public:
void addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates); void addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates);
private slots: private slots:
void _sendNextBatch (void); void _sendNextBatch (void);
void _requestFinished (void); void _requestFinished (void);
void _elevationProviderDestroyed (QObject* elevationProvider);
private: private:
typedef struct { typedef struct {
...@@ -41,6 +42,7 @@ private: ...@@ -41,6 +42,7 @@ private:
typedef struct { typedef struct {
ElevationProvider* elevationProvider; ElevationProvider* elevationProvider;
bool providerDestroyed;
int cCoord; int cCoord;
} SentRequestInfo_t; } SentRequestInfo_t;
...@@ -51,6 +53,7 @@ private: ...@@ -51,6 +53,7 @@ private:
}; };
void _batchFailed(void); void _batchFailed(void);
QString _stateToString(State state);
QList<QueuedRequestInfo_t> _requestQueue; QList<QueuedRequestInfo_t> _requestQueue;
QList<SentRequestInfo_t> _sentRequests; QList<SentRequestInfo_t> _sentRequests;
......
This diff is collapsed.
...@@ -34,10 +34,23 @@ ...@@ -34,10 +34,23 @@
#include "QGCConfig.h" #include "QGCConfig.h"
#include "LinkManager.h" #include "LinkManager.h"
class UDPCLient {
public:
UDPCLient(const QHostAddress& address_, quint16 port_)
: address(address_)
, port(port_)
{}
UDPCLient(const UDPCLient* other)
: address(other->address)
, port(other->port)
{}
QHostAddress address;
quint16 port;
};
class UDPConfiguration : public LinkConfiguration class UDPConfiguration : public LinkConfiguration
{ {
Q_OBJECT Q_OBJECT
public: public:
Q_PROPERTY(quint16 localPort READ localPort WRITE setLocalPort NOTIFY localPortChanged) Q_PROPERTY(quint16 localPort READ localPort WRITE setLocalPort NOTIFY localPortChanged)
...@@ -61,30 +74,7 @@ public: ...@@ -61,30 +74,7 @@ public:
*/ */
UDPConfiguration(UDPConfiguration* source); UDPConfiguration(UDPConfiguration* source);
/*! ~UDPConfiguration();
* @brief Begin iteration through the list of target hosts
*
* @param[out] host Host name
* @param[out] port Port number
* @return Returns false if list is empty
*/
bool firstHost (QString& host, int& port);
/*!
* @brief Continues iteration through the list of target hosts
*
* @param[out] host Host name
* @param[out] port Port number
* @return Returns false if reached the end of the list (in which case, both host and port are unchanged)
*/
bool nextHost (QString& host, int& port);
/*!
* @brief Get the number of target hosts
*
* @return Number of hosts in list
*/
int hostCount () { return _hosts.count(); }
/*! /*!
* @brief The UDP port we bind to * @brief The UDP port we bind to
...@@ -106,7 +96,7 @@ public: ...@@ -106,7 +96,7 @@ public:
* @param[in] host Host name, e.g. localhost or 192.168.1.1 * @param[in] host Host name, e.g. localhost or 192.168.1.1
* @param[in] port Port number * @param[in] port Port number
*/ */
void addHost (const QString& host, int port); void addHost (const QString& host, quint16 port);
/*! /*!
* @brief Remove a target host from the list * @brief Remove a target host from the list
...@@ -127,6 +117,8 @@ public: ...@@ -127,6 +117,8 @@ public:
*/ */
QStringList hostList () { return _hostList; } QStringList hostList () { return _hostList; }
const QList<UDPCLient*> targetHosts() { return _targetHosts; }
/// From LinkConfiguration /// From LinkConfiguration
LinkType type () { return LinkConfiguration::TypeUdp; } LinkType type () { return LinkConfiguration::TypeUdp; }
void copyFrom (LinkConfiguration* source); void copyFrom (LinkConfiguration* source);
...@@ -142,13 +134,13 @@ signals: ...@@ -142,13 +134,13 @@ signals:
private: private:
void _updateHostList (); void _updateHostList ();
void _clearTargetHosts ();
void _copyFrom (LinkConfiguration *source);
private: private:
QMutex _confMutex; QList<UDPCLient*> _targetHosts;
QMap<QString, int>::iterator _it; QStringList _hostList; ///< Exposed to QML
QMap<QString, int> _hosts; ///< ("host", port) quint16 _localPort;
QStringList _hostList; ///< Exposed to QML
quint16 _localPort;
}; };
class UDPLink : public LinkInterface class UDPLink : public LinkInterface
...@@ -159,32 +151,28 @@ class UDPLink : public LinkInterface ...@@ -159,32 +151,28 @@ class UDPLink : public LinkInterface
friend class LinkManager; friend class LinkManager;
public: public:
void requestReset() { } void requestReset () override { }
bool isConnected() const; bool isConnected () const override;
QString getName() const; QString getName () const override;
// Extensive statistics for scientific purposes // Extensive statistics for scientific purposes
qint64 getConnectionSpeed() const; qint64 getConnectionSpeed () const override;
qint64 getCurrentInDataRate() const; qint64 getCurrentInDataRate () const;
qint64 getCurrentOutDataRate() const; qint64 getCurrentOutDataRate () const;
void run(); // Thread
void run () override;
// These are left unimplemented in order to cause linker errors which indicate incorrect usage of // These are left unimplemented in order to cause linker errors which indicate incorrect usage of
// connect/disconnect on link directly. All connect/disconnect calls should be made through LinkManager. // connect/disconnect on link directly. All connect/disconnect calls should be made through LinkManager.
bool connect(void); bool connect (void);
bool disconnect(void); bool disconnect (void);
public slots: public slots:
/*! @brief Add a new host to broadcast messages to */ void readBytes ();
void addHost (const QString& host);
/*! @brief Remove a host from broadcasting messages to */
void removeHost (const QString& host);
void readBytes();
private slots: private slots:
void _writeBytes(const QByteArray data); void _writeBytes (const QByteArray data) override;
private: private:
// Links are only created/destroyed by LinkManager so constructor/destructor is not public // Links are only created/destroyed by LinkManager so constructor/destructor is not public
...@@ -192,14 +180,14 @@ private: ...@@ -192,14 +180,14 @@ private:
~UDPLink(); ~UDPLink();
// From LinkInterface // From LinkInterface
virtual bool _connect(void); bool _connect (void) override;
virtual void _disconnect(void); void _disconnect (void) override;
bool _hardwareConnect(); bool _hardwareConnect ();
void _restartConnection(); void _restartConnection ();
void _registerZeroconf (uint16_t port, const std::string& regType);
void _registerZeroconf(uint16_t port, const std::string& regType); void _deregisterZeroconf ();
void _deregisterZeroconf(); void _writeDataGram (const QByteArray data, const UDPCLient* target);
#if defined(QGC_ZEROCONF_ENABLED) #if defined(QGC_ZEROCONF_ENABLED)
DNSServiceRef _dnssServiceRef; DNSServiceRef _dnssServiceRef;
...@@ -209,6 +197,8 @@ private: ...@@ -209,6 +197,8 @@ private:
QUdpSocket* _socket; QUdpSocket* _socket;
UDPConfiguration* _udpConfig; UDPConfiguration* _udpConfig;
bool _connectState; bool _connectState;
QList<UDPCLient*> _sessionTargets;
}; };
#endif // UDPLINK_H #endif // UDPLINK_H
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