OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / uploader / oplinkwatchdog.cpp
blobe66d376ca3ee9c597276df22417b42f7bf644333
1 /**
2 ******************************************************************************
4 * @file oplinkwatchdog.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup [Group]
7 * @{
8 * @addtogroup OPLinkWatchdog
9 * @{
10 * @brief [Brief]
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "oplinkwatchdog.h"
29 #include "extensionsystem/pluginmanager.h"
30 #include "uavobjects/uavobjectmanager.h"
31 #include "oplinkstatus.h"
32 #include <QDebug>
34 OPLinkWatchdog::OPLinkWatchdog() : QObject(),
35 m_isConnected(false)
37 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
39 Q_ASSERT(pm);
40 UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
41 Q_ASSERT(objManager);
42 m_opLinkStatus = OPLinkStatus::GetInstance(objManager);
43 Q_ASSERT(m_opLinkStatus);
44 connect(m_opLinkStatus, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(onOPLinkStatusUpdate()));
45 m_watchdog = new QTimer(this);
46 connect(m_watchdog, SIGNAL(timeout()), this, SLOT(onTimeout()));
47 onOPLinkStatusUpdate();
50 OPLinkWatchdog::~OPLinkWatchdog()
53 void OPLinkWatchdog::onOPLinkStatusUpdate()
55 m_watchdog->stop();
56 quint8 type = m_opLinkStatus->getBoardType();
57 if (!m_isConnected) {
58 switch (type) {
59 case 3:
60 m_opLinkType = OPLINK_MINI;
61 m_isConnected = true;
62 emit connected();
63 emit opLinkMiniConnected();
64 break;
65 case 9:
66 m_opLinkType = OPLINK_REVOLUTION;
67 m_isConnected = true;
68 emit connected();
69 emit opLinkRevolutionConnected();
70 break;
71 default:
72 m_isConnected = false;
73 m_opLinkType = OPLINK_UNKNOWN;
74 return;
77 qDebug() << "OPLinkWatchdog - OPLink connected";
79 m_watchdog->start(m_opLinkStatus->getMetadata().flightTelemetryUpdatePeriod * 3);
82 void OPLinkWatchdog::onTimeout()
84 if (m_isConnected) {
85 m_isConnected = false;
86 m_opLinkType = OPLINK_UNKNOWN;
87 qDebug() << "OPLinkWatchdog - OPLink disconnected";
88 emit disconnected();