mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
Fix for OP-1080: Unreliable detection of board through OPLink
Conflicts: ground/openpilotgcs/src/plugins/uavtalk/telemetrymonitor.cpp
This commit is contained in:
parent
df0e51c986
commit
6bb1ae6721
@ -68,10 +68,12 @@ void SerialEnumerationThread::run()
|
||||
}
|
||||
|
||||
|
||||
SerialConnection::SerialConnection()
|
||||
: enablePolling(true), m_enumerateThread(this)
|
||||
SerialConnection::SerialConnection() :
|
||||
serialHandle(NULL),
|
||||
enablePolling(true),
|
||||
m_enumerateThread(this),
|
||||
m_deviceOpened(false)
|
||||
{
|
||||
serialHandle = NULL;
|
||||
m_config = new SerialPluginConfiguration("Serial Telemetry", NULL, this);
|
||||
m_config->restoresettings();
|
||||
|
||||
|
@ -32,25 +32,21 @@
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
TelemetryMonitor::TelemetryMonitor(UAVObjectManager *objMngr, Telemetry *tel)
|
||||
TelemetryMonitor::TelemetryMonitor(UAVObjectManager *objMngr, Telemetry *tel) :
|
||||
objMngr(objMngr),
|
||||
tel(tel),
|
||||
gcsStatsObj(GCSTelemetryStats::GetInstance(objMngr)),
|
||||
flightStatsObj(FlightTelemetryStats::GetInstance(objMngr)),
|
||||
firmwareIAPObj(FirmwareIAPObj::GetInstance(objMngr)),
|
||||
statsTimer(new QTimer(this)),
|
||||
objPending(NULL),
|
||||
mutex(new QMutex(QMutex::Recursive)),
|
||||
connectionTimer(new QTime())
|
||||
{
|
||||
this->objMngr = objMngr;
|
||||
this->tel = tel;
|
||||
this->objPending = NULL;
|
||||
this->connectionTimer = new QTime();
|
||||
|
||||
// Create mutex
|
||||
mutex = new QMutex(QMutex::Recursive);
|
||||
|
||||
// Get stats objects
|
||||
gcsStatsObj = GCSTelemetryStats::GetInstance(objMngr);
|
||||
flightStatsObj = FlightTelemetryStats::GetInstance(objMngr);
|
||||
|
||||
// Listen for flight stats updates
|
||||
connect(flightStatsObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(flightStatsUpdated(UAVObject *)));
|
||||
|
||||
// Start update timer
|
||||
statsTimer = new QTimer(this);
|
||||
connect(statsTimer, SIGNAL(timeout()), this, SLOT(processStatsUpdates()));
|
||||
statsTimer->start(STATS_CONNECT_PERIOD_MS);
|
||||
|
||||
@ -119,14 +115,21 @@ void TelemetryMonitor::retrieveNextObject()
|
||||
// If queue is empty return
|
||||
if (queue.isEmpty()) {
|
||||
qDebug("Object retrieval completed");
|
||||
emit connected();
|
||||
if (firmwareIAPObj->getBoardType()) {
|
||||
emit connected();
|
||||
} else {
|
||||
connect(firmwareIAPObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(firmwareIAPUpdated(UAVObject *)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Get next object from the queue
|
||||
UAVObject *obj = queue.dequeue();
|
||||
// qDebug( tr("Retrieving object: %1").arg(obj->getName()) );
|
||||
|
||||
// Connect to object
|
||||
connect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transactionCompleted(UAVObject *, bool)));
|
||||
|
||||
// Request update
|
||||
obj->requestUpdate();
|
||||
objPending = obj;
|
||||
@ -139,15 +142,19 @@ void TelemetryMonitor::transactionCompleted(UAVObject *obj, bool success)
|
||||
{
|
||||
Q_UNUSED(success);
|
||||
QMutexLocker locker(mutex);
|
||||
// Disconnect from sending object
|
||||
obj->disconnect(this);
|
||||
objPending = NULL;
|
||||
// Process next object if telemetry is still available
|
||||
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
|
||||
if (gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED) {
|
||||
retrieveNextObject();
|
||||
} else {
|
||||
stopRetrievingObjects();
|
||||
|
||||
if (obj == objPending) {
|
||||
// Disconnect from sending object
|
||||
obj->disconnect(this);
|
||||
objPending = NULL;
|
||||
// Process next object if telemetry is still available
|
||||
GCSTelemetryStats::DataFields gcsStats = gcsStatsObj->getData();
|
||||
|
||||
if (gcsStats.Status == GCSTelemetryStats::STATUS_CONNECTED) {
|
||||
retrieveNextObject();
|
||||
} else {
|
||||
stopRetrievingObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +175,19 @@ void TelemetryMonitor::flightStatsUpdated(UAVObject *obj)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time the firmwareIAP object is updated by the autopilot
|
||||
*/
|
||||
void TelemetryMonitor::firmwareIAPUpdated(UAVObject *obj)
|
||||
{
|
||||
Q_UNUSED(obj);
|
||||
QMutexLocker locker(mutex);
|
||||
|
||||
if (firmwareIAPObj->getBoardType() != 0) {
|
||||
emit connected();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called periodically to update the statistics and connection status.
|
||||
*/
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "uavobjectmanager.h"
|
||||
#include "gcstelemetrystats.h"
|
||||
#include "flighttelemetrystats.h"
|
||||
#include "firmwareiapobj.h"
|
||||
#include "systemstats.h"
|
||||
#include "telemetry.h"
|
||||
|
||||
@ -56,6 +57,7 @@ public slots:
|
||||
void transactionCompleted(UAVObject *obj, bool success);
|
||||
void processStatsUpdates();
|
||||
void flightStatsUpdated(UAVObject *obj);
|
||||
void firmwareIAPUpdated(UAVObject *obj);
|
||||
|
||||
private:
|
||||
static const int STATS_UPDATE_PERIOD_MS = 4000;
|
||||
@ -67,6 +69,7 @@ private:
|
||||
QQueue<UAVObject *> queue;
|
||||
GCSTelemetryStats *gcsStatsObj;
|
||||
FlightTelemetryStats *flightStatsObj;
|
||||
FirmwareIAPObj* firmwareIAPObj;
|
||||
QTimer *statsTimer;
|
||||
UAVObject *objPending;
|
||||
QMutex *mutex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user