From 1cd46f049fa7d43196dec71f26d80dfd9aca124a Mon Sep 17 00:00:00 2001 From: m_thread Date: Wed, 21 Jan 2015 10:01:10 +0100 Subject: [PATCH] OP-1628 Adding more fine grained connection states to TelemetryManager. --- .../src/plugins/uavtalk/telemetrymanager.cpp | 19 ++++++++++++++----- .../src/plugins/uavtalk/telemetrymanager.h | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp index cc3602ed3..9705898cb 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.cpp @@ -32,7 +32,7 @@ #include #include -TelemetryManager::TelemetryManager() : m_isAutopilotConnected(false) +TelemetryManager::TelemetryManager() : m_connectionState(TELEMETRY_DISCONNECTED) { moveToThread(Core::ICore::instance()->threadManager()->getRealTimeThread()); // Get UAVObjectManager instance @@ -47,13 +47,20 @@ TelemetryManager::TelemetryManager() : m_isAutopilotConnected(false) TelemetryManager::~TelemetryManager() {} -bool TelemetryManager::isConnected() +bool TelemetryManager::isConnected() const { - return m_isAutopilotConnected; + return m_connectionState == TELEMETRY_CONNECTED; +} + +TelemetryManager::ConnectionState TelemetryManager::connectionState() const { + return m_connectionState; } void TelemetryManager::start(QIODevice *dev) { + m_connectionState = TELEMETRY_CONNECTING; + emit connecting(); + m_telemetryDevice = dev; // OP-1383 // take ownership of the device by moving it to the TelemetryManager thread (see TelemetryManager constructor) @@ -98,6 +105,8 @@ void TelemetryManager::onStart() void TelemetryManager::stop() { + m_connectionState = TELEMETRY_DISCONNECTING; + emit disconnecting(); emit myStop(); if (false) { @@ -117,13 +126,13 @@ void TelemetryManager::onStop() void TelemetryManager::onConnect() { - m_isAutopilotConnected = true; + m_connectionState = TELEMETRY_CONNECTED; emit connected(); } void TelemetryManager::onDisconnect() { - m_isAutopilotConnected = false; + m_connectionState = TELEMETRY_DISCONNECTED; emit disconnected(); } diff --git a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h index b7a00c3cb..f42959283 100644 --- a/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h +++ b/ground/openpilotgcs/src/plugins/uavtalk/telemetrymanager.h @@ -41,15 +41,25 @@ class UAVTALK_EXPORT TelemetryManager : public QObject { Q_OBJECT public: + enum ConnectionState { + TELEMETRY_DISCONNECTED, + TELEMETRY_CONNECTED, + TELEMETRY_DISCONNECTING, + TELEMETRY_CONNECTING + }; + TelemetryManager(); ~TelemetryManager(); void start(QIODevice *dev); void stop(); - bool isConnected(); + bool isConnected() const; + ConnectionState connectionState() const; signals: + void connecting(); void connected(); + void disconnecting(); void disconnected(); void telemetryUpdated(double txRate, double rxRate); void myStart(); @@ -68,7 +78,7 @@ private: Telemetry *m_telemetry; TelemetryMonitor *m_telemetryMonitor; QIODevice *m_telemetryDevice; - bool m_isAutopilotConnected; + ConnectionState m_connectionState; QThread m_telemetryReaderThread; };