35 #include <QtSerialPort/QSerialPort>
36 #include <QtSerialPort/QSerialPortInfo>
39 #include <QHBoxLayout>
42 #include <QMainWindow>
49 , m_availableDevList(nullptr)
50 , m_connectBtn(nullptr)
53 , m_mainWindow(mainWindow)
55 QHBoxLayout *layout =
new QHBoxLayout;
56 layout->setSpacing(5);
57 layout->setContentsMargins(0, 0, 9, 0);
62 layout->addWidget(
m_monitorWidget, Qt::AlignHCenter | Qt::AlignVCenter);
64 layout->addWidget(
new QLabel(tr(
"Connections:")));
78 modeStack->setCornerWidget(
this, Qt::TopRightCorner);
80 QObject::connect(
m_connectBtn, SIGNAL(clicked()),
this, SLOT(onConnectClicked()));
83 reconnect =
new QTimer(
this);
84 reconnectCheck =
new QTimer(
this);
85 connect(reconnect, SIGNAL(timeout()),
this, SLOT(reconnectSlot()));
86 connect(reconnectCheck, SIGNAL(timeout()),
this, SLOT(reconnectCheckSlot()));
101 QObject::connect(ExtensionSystem::PluginManager::instance(), SIGNAL(objectAdded(QObject *)),
102 this, SLOT(objectAdded(QObject *)));
103 QObject::connect(ExtensionSystem::PluginManager::instance(),
104 SIGNAL(aboutToRemoveObject(QObject *)),
this,
105 SLOT(aboutToRemoveObject(QObject *)));
112 void ConnectionManager::connectDeviceFailed(
DevListItem &device)
115 QString msg(
"<span style='color:red'>Failed</span> to connect device: ");
117 msg.append(device.
device->getDisplayName());
119 msg.append(
"Unknown");
123 msg.append(
"<br />Have you set udev rules?");
127 msgFailedToConnect.setText(msg);
128 msgFailedToConnect.open();
145 io_dev->open(QIODevice::ReadWrite);
148 if (!io_dev->isOpen()) {
163 SLOT(onConnectionDestroyed(QObject *)), Qt::QueuedConnection);
195 if (reconnect->isActive())
197 if (reconnectCheck->isActive())
198 reconnectCheck->stop();
208 qDebug() <<
"Exception: m_connectionDevice.connection->closeDevice("
225 void ConnectionManager::objectAdded(QObject *obj)
233 devChanged(connection);
239 QObject::connect(connection, SIGNAL(availableDevChanged(
IConnection *)),
this,
243 void ConnectionManager::aboutToRemoveObject(QObject *obj)
246 IConnection *connection = Aggregation::query<IConnection>(obj);
262 void ConnectionManager::onConnectionDestroyed(QObject *obj)
279 if (device.connection) {
281 connectDeviceFailed(device);
294 qDebug() <<
"TelemetryMonitor: connected";
296 if (reconnectCheck->isActive())
297 reconnectCheck->stop();
308 qDebug() <<
"TelemetryMonitor: disconnected";
313 if (!reconnect->isActive())
314 reconnect->start(1000);
329 void ConnectionManager::reconnectSlot()
331 qDebug() <<
"reconnect";
335 if (
m_ioDev->open(QIODevice::ReadWrite)) {
336 qDebug() <<
"reconnect successfull";
338 reconnectCheck->start(20000);
340 qDebug() <<
"reconnect NOT successfull";
343 void ConnectionManager::reconnectCheckSlot()
345 reconnectCheck->stop();
346 reconnect->start(1000);
359 qDebug() <<
"findDevice: cannot find " << devName <<
" in device list";
419 if (
iter->connection != connection) {
425 bool found = availableDev.contains(
iter->device);
435 if (!
iter->device.isNull())
436 iter->device->deleteLater();
444 foreach (
IDevice *dev, availableDev) {
469 void ConnectionManager::devChanged(
IConnection *connection)
471 if (!ExtensionSystem::PluginManager::instance()->allPluginsLoaded()) {
472 connectionBackup.append(connection);
473 connect(ExtensionSystem::PluginManager::instance(), SIGNAL(pluginsLoadEnded()),
this,
474 SLOT(connectionsCallBack()), Qt::UniqueConnection);
507 qDebug() <<
"Automatically opening device";
509 qDebug() <<
"ConnectionManager::devChanged autoconnected USB device";
523 void Core::ConnectionManager::connectionsCallBack()
528 connectionBackup.clear();
529 disconnect(ExtensionSystem::PluginManager::instance(), SIGNAL(pluginsLoadEnded()),
this,
530 SLOT(connectionsCallBack()));
virtual QIODevice * openDevice(IDevice *device)=0
QList< IConnection * > m_connectionsList
QGraphicsSvgItem * getBackgroundItem()
virtual void suspendPolling()
QLinkedList< DevListItem > m_devList
virtual void closeDevice(const QString &deviceName)
virtual bool reconnect()
Used to flag that the device wants that we try to reconnect if it gets disconnected Currently this sh...
DevListItem findDevice(const QString &devName)
QPushButton * m_connectBtn
QComboBox * m_availableDevList
virtual QList< IDevice * > availableDevices()=0
virtual void resumePolling()
void telemetryDisconnected()
void updateConnectionList(IConnection *connection)
DevListItem m_connectionDevice
virtual ~ConnectionManager()
void updateConnectionDropdown()
static ICore * instance()
void init(QSvgRenderer *renderer, QGraphicsSvgItem *graph)
void telemetryUpdated(double txRate, double rxRate)
static AlarmsMonitorWidget & getInstance()
void availableDevicesChanged(const QLinkedList< Core::DevListItem > devices)
QSvgRenderer * getRenderer()
void deviceDisconnected()
IPConnection * connection
QPointer< IDevice > device
void telemetryConnected()
void deviceAboutToDisconnect()
Internal::GeneralSettings * generalSettings() const
void registerDevice(IConnection *conn, IDevice *device)
ConnectionManager(Internal::MainWindow *mainWindow, QTabWidget *modeStack)
TelemetryMonitorWidget * m_monitorWidget
void updateTelemetry(double txRate, double rxRate)
Called by the UAVObject which got updated Updates the numeric value and/or the icon if the dial wants...
void deviceConnected(QIODevice *device)
bool connectDevice(DevListItem device)
virtual QString shortName()