Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
8ec600aa
Commit
8ec600aa
authored
Dec 10, 2015
by
Gus Grubba
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2375 from dogmaphobic/bluetoothCleanup
Bluetooth Cleanup
parents
ec3047af
09b22dd6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
250 additions
and
139 deletions
+250
-139
QGCCommon.pri
QGCCommon.pri
+1
-0
qgroundcontrol.pro
qgroundcontrol.pro
+15
-3
QGCApplication.cc
src/QGCApplication.cc
+14
-0
QGCApplication.h
src/QGCApplication.h
+45
-40
BluetoothLink.cc
src/comm/BluetoothLink.cc
+111
-67
BluetoothLink.h
src/comm/BluetoothLink.h
+30
-8
LinkConfiguration.cc
src/comm/LinkConfiguration.cc
+6
-6
LinkConfiguration.h
src/comm/LinkConfiguration.h
+1
-1
LinkManager.cc
src/comm/LinkManager.cc
+10
-6
LinkManager.h
src/comm/LinkManager.h
+8
-6
main.cc
src/main.cc
+2
-2
BluetoothSettings.qml
src/ui/preferences/BluetoothSettings.qml
+7
-0
No files found.
QGCCommon.pri
View file @
8ec600aa
...
...
@@ -36,6 +36,7 @@ linux {
CONFIG += AndroidBuild MobileBuild
DEFINES += __android__
DEFINES += __STDC_LIMIT_MACROS
DEFINES += QGC_ENABLE_BLUETOOTH
target.path = $$DESTDIR
} else {
error("Unsuported Linux toolchain, only GCC 32- or 64-bit is supported")
...
...
qgroundcontrol.pro
View file @
8ec600aa
...
...
@@ -44,6 +44,18 @@ exists(user_config.pri):infile(user_config.pri, CONFIG) {
message
(
$$
sprintf
(
"Using user-supplied additional config: '%1' specified in user_config.pri"
,
$$
fromfile
(
user_config
.
pri
,
CONFIG
)))
}
#
Bluetooth
contains
(
DEFINES
,
QGC_DISABLE_BLUETOOTH
)
{
message
(
"Skipping support for Bluetooth (manual override from command line)"
)
DEFINES
-=
QGC_ENABLE_BLUETOOTH
}
else
:
exists
(
user_config
.
pri
)
:
infile
(
user_config
.
pri
,
DEFINES
,
QGC_DISABLE_BLUETOOTH
)
{
message
(
"Skipping support for Bluetooth (manual override from user_config.pri)"
)
DEFINES
-=
QGC_ENABLE_BLUETOOTH
}
else
:
exists
(
user_config
.
pri
)
:
infile
(
user_config
.
pri
,
DEFINES
,
QGC_ENABLE_BLUETOOTH
)
{
message
(
"Including support for Bluetooth (manual override from user_config.pri)"
)
DEFINES
+=
QGC_ENABLE_BLUETOOTH
}
LinuxBuild
{
CONFIG
+=
link_pkgconfig
}
...
...
@@ -74,7 +86,7 @@ QT += \
serialport
\
}
MobileBuild
{
contains
(
DEFINES
,
QGC_ENABLE_BLUETOOTH
)
{
QT
+=
\
bluetooth
\
}
...
...
@@ -284,7 +296,7 @@ WindowsBuild {
HEADERS
+=
src
/
stable_headers
.
h
}
MobileBuild
{
contains
(
DEFINES
,
QGC_ENABLE_BLUETOOTH
)
{
HEADERS
+=
\
src
/
comm
/
BluetoothLink
.
h
\
}
...
...
@@ -402,7 +414,7 @@ SOURCES += \
src
/
ui
/
SerialConfigurationWindow
.
cc
\
}
MobileBuild
{
contains
(
DEFINES
,
QGC_ENABLE_BLUETOOTH
)
{
SOURCES
+=
\
src
/
comm
/
BluetoothLink
.
cc
\
}
...
...
src/QGCApplication.cc
View file @
8ec600aa
...
...
@@ -37,6 +37,10 @@
#include <QStyleFactory>
#include <QAction>
#ifdef QGC_ENABLE_BLUETOOTH
#include <QBluetoothLocalDevice>
#endif
#include <QDebug>
#include "VideoStreaming.h"
...
...
@@ -170,6 +174,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
,
_testHighDPI
(
false
)
#endif
,
_toolbox
(
NULL
)
,
_bluetoothAvailable
(
false
)
{
Q_ASSERT
(
_app
==
NULL
);
_app
=
this
;
...
...
@@ -319,6 +324,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
settings
.
setValue
(
_settingsVersionKey
,
QGC_SETTINGS_VERSION
);
}
// Initialize Bluetooth
#ifdef QGC_ENABLE_BLUETOOTH
QBluetoothLocalDevice
localDevice
;
if
(
localDevice
.
isValid
())
{
_bluetoothAvailable
=
true
;
}
#endif
// Initialize Video Streaming
initializeVideoStreaming
(
argc
,
argv
);
...
...
src/QGCApplication.h
View file @
8ec600aa
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
...
...
@@ -72,35 +72,35 @@ class QGCApplication : public
#endif
{
Q_OBJECT
public:
QGCApplication
(
int
&
argc
,
char
*
argv
[],
bool
unitTesting
);
~
QGCApplication
();
/// @brief Sets the persistent flag to delete all settings the next time QGroundControl is started.
void
deleteAllSettingsNextBoot
(
void
);
/// @brief Clears the persistent flag to delete all settings the next time QGroundControl is started.
void
clearDeleteAllSettingsNextBoot
(
void
);
/// @brief Returns the location of user visible saved file associated with QGroundControl
QString
savedFilesLocation
(
void
);
/// @brief Sets the location of user visible saved file associated with QGroundControl
void
setSavedFilesLocation
(
QString
&
location
);
/// @brief Location to save and load parameter files from.
QString
savedParameterFilesLocation
(
void
);
/// @brief Location to save and load mavlink log files from
QString
mavlinkLogFilesLocation
(
void
);
/// @brief Validates that the specified location will work for the saved files location.
bool
validatePossibleSavedFilesLocation
(
QString
&
location
);
/// @return true: Prompt to save log file when vehicle goes away
bool
promptFlightDataSave
(
void
);
/// @return true: Prompt to save log file even if vehicle was not armed
bool
promptFlightDataSaveNotArmed
(
void
);
...
...
@@ -109,13 +109,13 @@ public:
/// @brief Returns truee if unit test are being run
bool
runningUnitTests
(
void
)
{
return
_runningUnitTests
;
}
/// @return true: dark ui style, false: light ui style
bool
styleIsDark
(
void
)
{
return
_styleIsDark
;
}
/// Set the current UI style
void
setStyle
(
bool
styleIsDark
);
/// Used to report a missing Parameter. Warning will be displayed to user. Method may be called
/// multiple times.
void
reportMissingParameter
(
int
componentId
,
const
QString
&
name
);
...
...
@@ -123,26 +123,29 @@ public:
/// Show a non-modal message to the user
void
showMessage
(
const
QString
&
message
);
/// @return true: Fake ui into showing mobile interface
bool
fakeMobile
(
void
)
{
return
_fakeMobile
;
}
/// @return true: Fake ui into showing mobile interface
bool
fakeMobile
(
void
)
{
return
_fakeMobile
;
}
#ifdef QT_DEBUG
bool
testHighDPI
(
void
)
{
return
_testHighDPI
;
}
#endif
// Still working on getting rid of this and using dependency injection instead for everything
QGCToolbox
*
toolbox
(
void
)
{
return
_toolbox
;
}
/// Do we have Bluetooth Support?
bool
isBluetoothAvailable
()
{
return
_bluetoothAvailable
;
}
public
slots
:
/// You can connect to this slot to show an information message box from a different thread.
void
informationMessageBoxOnMainThread
(
const
QString
&
title
,
const
QString
&
msg
);
/// You can connect to this slot to show a warning message box from a different thread.
void
warningMessageBoxOnMainThread
(
const
QString
&
title
,
const
QString
&
msg
);
/// You can connect to this slot to show a critical message box from a different thread.
void
criticalMessageBoxOnMainThread
(
const
QString
&
title
,
const
QString
&
msg
);
void
showFlyView
(
void
);
void
showPlanView
(
void
);
void
showSetupView
(
void
);
...
...
@@ -158,14 +161,14 @@ signals:
/// Signals that the style has changed
/// @param darkStyle true: dark style, false: light style
void
styleChanged
(
bool
darkStyle
);
/// This is connected to MAVLinkProtocol::checkForLostLogFiles. We signal this to ourselves to call the slot
/// on the MAVLinkProtocol thread;
void
checkForLostLogFiles
(
void
);
public:
// Although public, these methods are internal and should only be called by UnitTest code
/// @brief Perform initialize which is common to both normal application running and unit tests.
/// Although public should only be called by main.
void
_initCommon
(
void
);
...
...
@@ -173,7 +176,7 @@ public:
/// @brief Intialize the application for normal application boot. Or in other words we are not going to run
/// unit tests. Although public should only be called by main.
bool
_initForNormalAppBoot
(
void
);
/// @brief Intialize the application for normal application boot. Or in other words we are not going to run
/// unit tests. Although public should only be called by main.
bool
_initForUnitTests
(
void
);
...
...
@@ -182,12 +185,12 @@ public:
void
_showSetupParameters
(
void
);
void
_showSetupSummary
(
void
);
void
_showSetupVehicleComponent
(
VehicleComponent
*
vehicleComponent
);
static
QGCApplication
*
_app
;
///< Our own singleton. Should be reference directly by qgcApp
private
slots
:
void
_missingParamsDisplay
(
void
);
private:
void
_loadCurrentStyle
(
void
);
QObject
*
_rootQmlObject
(
void
);
...
...
@@ -195,36 +198,38 @@ private:
#ifdef __mobile__
QQmlApplicationEngine
*
_qmlAppEngine
;
#endif
static
const
char
*
_settingsVersionKey
;
///< Settings key which hold settings version
static
const
char
*
_deleteAllSettingsKey
;
///< If this settings key is set on boot, all settings will be deleted
static
const
char
*
_savedFilesLocationKey
;
///< Settings key for user visible saved files location
static
const
char
*
_promptFlightDataSave
;
///< Settings key for promptFlightDataSave
static
const
char
*
_promptFlightDataSaveNotArmed
;
///< Settings key for promptFlightDataSaveNotArmed
static
const
char
*
_styleKey
;
///< Settings key for UI style
static
const
char
*
_defaultSavedFileDirectoryName
;
///< Default name for user visible save file directory
static
const
char
*
_savedFileMavlinkLogDirectoryName
;
///< Name of mavlink log subdirectory
static
const
char
*
_savedFileParameterDirectoryName
;
///< Name of parameter subdirectory
bool
_runningUnitTests
;
///< true: running unit tests, false: normal app
static
const
char
*
_darkStyleFile
;
static
const
char
*
_lightStyleFile
;
bool
_styleIsDark
;
///< true: dark style, false: light style
static
const
int
_missingParamsDelayedDisplayTimerTimeout
=
1000
;
///< Timeout to wait for next missing fact to come in before display
QTimer
_missingParamsDelayedDisplayTimer
;
///< Timer use to delay missing fact display
QStringList
_missingParams
;
///< List of missing facts to be displayed
bool
_fakeMobile
;
///< true: Fake ui into displaying mobile interface
bool
_fakeMobile
;
///< true: Fake ui into displaying mobile interface
#ifdef QT_DEBUG
bool
_testHighDPI
;
///< true: double fonts sizes for simulating high dpi devices
#endif
QGCToolbox
*
_toolbox
;
bool
_bluetoothAvailable
;
/// Unit Test have access to creating and destroying singletons
friend
class
UnitTest
;
};
...
...
src/comm/BluetoothLink.cc
View file @
8ec600aa
...
...
@@ -34,42 +34,26 @@ This file is part of the QGROUNDCONTROL project
#include <QDebug>
#include <iostream>
#include <QtBluetooth/QBluetoothSocket>
#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
#include <QtBluetooth/QBluetoothLocalDevice>
#include <QtBluetooth/QBluetoothUuid>
#include <QtBluetooth/QBluetoothSocket>
#include "BluetoothLink.h"
#include "QGC.h"
/*
static void print_device_info(QBluetoothDeviceInfo info)
{
qDebug() << "Bluetooth: " << info.name();
qDebug() << " Services:" << info.serviceClasses();
qDebug() << " Major Classs:" << info.majorDeviceClass();
qDebug() << " Minor Classs:" << info.minorDeviceClass();
qDebug() << " RSSI:" << info.rssi();
qDebug() << " UUID:" << info.deviceUuid();
qDebug() << " Service UUID:" << info.serviceUuids();
qDebug() << " Core Config:" << info.coreConfigurations();
qDebug() << " Valid:" << info.isValid();
qDebug() << " Address:" << info.address().toString();
}
*/
BluetoothLink
::
BluetoothLink
(
BluetoothConfiguration
*
config
)
:
_connectState
(
false
)
,
_targetSocket
(
NULL
)
,
_targetDevice
(
NULL
)
,
_running
(
false
)
#ifdef __ios__
,
_discoveryAgent
(
NULL
)
#endif
,
_shutDown
(
false
)
{
Q_ASSERT
(
config
!=
NULL
);
_config
=
config
;
_config
->
setLink
(
this
);
// We're doing it wrong - because the Qt folks got the API wrong:
// http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/
moveToThread
(
this
);
//moveToThread(this);
}
BluetoothLink
::~
BluetoothLink
()
...
...
@@ -77,19 +61,18 @@ BluetoothLink::~BluetoothLink()
// Disconnect link from configuration
_config
->
setLink
(
NULL
);
_disconnect
();
// Tell the thread to exit
_running
=
false
;
quit
();
// Wait for it to exit
wait
();
this
->
deleteLater
();
#ifdef __ios__
if
(
_discoveryAgent
)
{
_shutDown
=
true
;
_discoveryAgent
->
stop
();
_discoveryAgent
->
deleteLater
();
_discoveryAgent
=
NULL
;
}
#endif
}
void
BluetoothLink
::
run
()
{
if
(
_running
&&
_hardwareConnect
())
{
exec
();
}
}
void
BluetoothLink
::
_restartConnection
()
...
...
@@ -142,17 +125,17 @@ void BluetoothLink::readBytes()
void
BluetoothLink
::
_disconnect
(
void
)
{
_running
=
false
;
quit
();
wait
();
if
(
_targetDevice
)
{
delete
_targetDevice
;
_targetDevice
=
NULL
;
#ifdef __ios__
if
(
_discoveryAgent
)
{
_shutDown
=
true
;
_discoveryAgent
->
stop
();
_discoveryAgent
->
deleteLater
();
_discoveryAgent
=
NULL
;
}
#endif
if
(
_targetSocket
)
{
_targetSocket
->
deleteLater
()
;
delete
_targetSocket
;
_targetSocket
=
NULL
;
emit
disconnected
();
}
...
...
@@ -161,43 +144,86 @@ void BluetoothLink::_disconnect(void)
bool
BluetoothLink
::
_connect
(
void
)
{
if
(
this
->
isRunning
()
||
_running
)
{
_running
=
false
;
quit
();
wait
();
}
if
(
_targetDevice
)
{
delete
_targetDevice
;
_targetDevice
=
NULL
;
}
//-- Start Thread
_running
=
true
;
start
(
NormalPriority
);
_hardwareConnect
();
return
true
;
}
bool
BluetoothLink
::
_hardwareConnect
()
{
#ifdef __ios__
if
(
_discoveryAgent
)
{
_shutDown
=
true
;
_discoveryAgent
->
stop
();
_discoveryAgent
->
deleteLater
();
_discoveryAgent
=
NULL
;
}
_discoveryAgent
=
new
QBluetoothServiceDiscoveryAgent
(
this
);
QObject
::
connect
(
_discoveryAgent
,
SIGNAL
(
serviceDiscovered
(
QBluetoothServiceInfo
)),
this
,
SLOT
(
serviceDiscovered
(
QBluetoothServiceInfo
)));
QObject
::
connect
(
_discoveryAgent
,
SIGNAL
(
finished
()),
this
,
SLOT
(
discoveryFinished
()));
QObject
::
connect
(
_discoveryAgent
,
SIGNAL
(
canceled
()),
this
,
SLOT
(
discoveryFinished
()));
QObject
::
connect
(
_discoveryAgent
,
SIGNAL
(
error
(
QBluetoothServiceDiscoveryAgent
::
Error
)),
this
,
SLOT
(
discoveryError
(
QBluetoothServiceDiscoveryAgent
::
Error
)));
_shutDown
=
false
;
_discoveryAgent
->
start
();
#else
_createSocket
();
_targetSocket
->
connectToService
(
QBluetoothAddress
(
_config
->
device
().
address
),
QBluetoothUuid
(
QBluetoothUuid
::
Rfcomm
));
#endif
return
true
;
}
void
BluetoothLink
::
_createSocket
()
{
if
(
_targetSocket
)
{
delete
_targetSocket
;
_targetSocket
=
NULL
;
}
_targetDevice
=
new
QBluetoothDeviceInfo
(
QBluetoothAddress
(
_config
->
device
().
address
),
_config
->
device
().
name
,
_config
->
device
().
bits
);
_targetDevice
->
setCoreConfigurations
(
QBluetoothDeviceInfo
::
BaseRateCoreConfiguration
);
_targetSocket
=
new
QBluetoothSocket
(
QBluetoothServiceInfo
::
RfcommProtocol
,
this
);
_targetSocket
->
moveToThread
(
this
);
//print_device_info(*_targetDevice);
QObject
::
connect
(
_targetSocket
,
SIGNAL
(
connected
()),
this
,
SLOT
(
deviceConnected
()));
QObject
::
connect
(
_targetSocket
,
SIGNAL
(
error
(
QBluetoothSocket
::
SocketError
)),
this
,
SLOT
(
deviceError
(
QBluetoothSocket
::
SocketError
)));
QObject
::
connect
(
_targetSocket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readBytes
()));
QObject
::
connect
(
_targetSocket
,
SIGNAL
(
disconnected
()),
this
,
SLOT
(
deviceDisconnected
()));
_targetSocket
->
connectToService
(
_targetDevice
->
address
(),
QBluetoothUuid
(
QBluetoothUuid
::
Rfcomm
));
return
true
;
}
#ifdef __ios__
void
BluetoothLink
::
discoveryError
(
QBluetoothServiceDiscoveryAgent
::
Error
error
)
{
qDebug
()
<<
"Discovery error:"
<<
error
;
qDebug
()
<<
_discoveryAgent
->
errorString
();
}
#endif
#ifdef __ios__
void
BluetoothLink
::
serviceDiscovered
(
const
QBluetoothServiceInfo
&
info
)
{
if
(
!
info
.
device
().
name
().
isEmpty
()
&&
!
_targetSocket
)
{
if
(
_config
->
device
().
uuid
==
info
.
device
().
deviceUuid
()
&&
_config
->
device
().
name
==
info
.
device
().
name
())
{
_createSocket
();
_targetSocket
->
connectToService
(
info
);
}
}
}
#endif
#ifdef __ios__
void
BluetoothLink
::
discoveryFinished
()
{
if
(
_discoveryAgent
&&
!
_shutDown
)
{
_shutDown
=
true
;
_discoveryAgent
->
deleteLater
();
_discoveryAgent
=
NULL
;
if
(
!
_targetSocket
)
{
_connectState
=
false
;
emit
communicationError
(
"Could not locate Bluetooth device:"
,
_config
->
device
().
name
);
}
}
}
#endif
void
BluetoothLink
::
deviceConnected
()
{
_connectState
=
true
;
...
...
@@ -274,18 +300,25 @@ void BluetoothConfiguration::copyFrom(LinkConfiguration *source)
void
BluetoothConfiguration
::
saveSettings
(
QSettings
&
settings
,
const
QString
&
root
)
{
settings
.
beginGroup
(
root
);
settings
.
setValue
(
"name"
,
_device
.
name
);
settings
.
setValue
(
"address"
,
_device
.
address
);
settings
.
setValue
(
"bits"
,
_device
.
bits
);
settings
.
setValue
(
"deviceName"
,
_device
.
name
);
#ifdef __ios__
settings
.
setValue
(
"uuid"
,
_device
.
uuid
.
toString
());
#else
settings
.
setValue
(
"address"
,
_device
.
address
);
#endif
settings
.
endGroup
();
}
void
BluetoothConfiguration
::
loadSettings
(
QSettings
&
settings
,
const
QString
&
root
)
{
settings
.
beginGroup
(
root
);
_device
.
name
=
settings
.
value
(
"name"
,
_device
.
name
).
toString
();
_device
.
name
=
settings
.
value
(
"deviceName"
,
_device
.
name
).
toString
();
#ifdef __ios__
QString
suuid
=
settings
.
value
(
"uuid"
,
_device
.
uuid
.
toString
()).
toString
();
_device
.
uuid
=
QUuid
(
suuid
);
#else
_device
.
address
=
settings
.
value
(
"address"
,
_device
.
address
).
toString
();
_device
.
bits
=
settings
.
value
(
"bits"
,
_device
.
bits
).
toUInt
();
#endif
settings
.
endGroup
();
}
...
...
@@ -337,10 +370,11 @@ void BluetoothConfiguration::deviceDiscovered(QBluetoothDeviceInfo info)
{
BluetoothData
data
;
data
.
name
=
info
.
name
();
#ifdef __ios__
data
.
uuid
=
info
.
deviceUuid
();
#else
data
.
address
=
info
.
address
().
toString
();
data
.
bits
|=
((
qint32
)
info
.
serviceClasses
()
<<
13
);
// Service Class
data
.
bits
|=
((
qint32
)
info
.
majorDeviceClass
()
<<
8
);
// CLASS MAJOR
data
.
bits
|=
((
qint32
)
info
.
minorDeviceClass
()
<<
2
);
// CLASS MINOR
#endif
if
(
!
_deviceList
.
contains
(
data
))
{
_deviceList
+=
data
;
...
...
@@ -369,9 +403,19 @@ void BluetoothConfiguration::setDevName(const QString &name)
{
_device
=
data
;
emit
devNameChanged
();
#ifndef __ios__
emit
addressChanged
();
#endif
return
;
}
}
}
QString
BluetoothConfiguration
::
address
()
{
#ifdef __ios__
return
QString
(
""
);
#else
return
_device
.
address
;
#endif
}
src/comm/BluetoothLink.h
View file @
8ec600aa
...
...
@@ -39,18 +39,20 @@ This file is part of the QGROUNDCONTROL project
#include <QByteArray>
#include <QBluetoothDeviceInfo>
#include <QtBluetooth/QBluetoothSocket>
#include <qbluetoothserviceinfo.h>
#include <qbluetoothservicediscoveryagent.h>
#include "QGCConfig.h"
#include "LinkManager.h"
class
QBluetoothDeviceDiscoveryAgent
;
class
QBluetoothServiceDiscoveryAgent
;
class
BluetoothData
{
public:
BluetoothData
()
{
bits
=
0
;
}
BluetoothData
(
const
BluetoothData
&
other
)
{
...
...
@@ -58,18 +60,28 @@ public:
}
bool
operator
==
(
const
BluetoothData
&
other
)
{
return
bits
==
other
.
bits
&&
name
==
other
.
name
&&
address
==
other
.
address
;
#ifdef __ios__
return
uuid
==
other
.
uuid
&&
name
==
other
.
name
;
#else
return
name
==
other
.
name
&&
address
==
other
.
address
;
#endif
}
BluetoothData
&
operator
=
(
const
BluetoothData
&
other
)
{
bits
=
other
.
bits
;
name
=
other
.
name
;
#ifdef __ios__
uuid
=
other
.
uuid
;
#else
address
=
other
.
address
;
#endif
return
*
this
;
}
quint32
bits
;
QString
name
;
#ifdef __ios__
QBluetoothUuid
uuid
;
#else
QString
address
;
#endif
};
class
BluetoothConfiguration
:
public
LinkConfiguration
...
...
@@ -91,7 +103,7 @@ public:
Q_INVOKABLE
void
stopScan
();
QString
devName
()
{
return
_device
.
name
;
}
QString
address
()
{
return
_device
.
address
;
}
QString
address
()
;
QStringList
nameList
()
{
return
_nameList
;
}
bool
scanning
()
{
return
_deviceDiscover
!=
NULL
;
}
...
...
@@ -159,6 +171,11 @@ public slots:
void
deviceConnected
();
void
deviceDisconnected
();
void
deviceError
(
QBluetoothSocket
::
SocketError
error
);
#ifdef __ios__
void
serviceDiscovered
(
const
QBluetoothServiceInfo
&
info
);
void
discoveryFinished
();
void
discoveryError
(
QBluetoothServiceDiscoveryAgent
::
Error
error
);
#endif
protected:
...
...
@@ -177,12 +194,17 @@ private:
bool
_hardwareConnect
();
void
_restartConnection
();
void
_sendBytes
(
const
char
*
data
,
qint64
size
);
void
_createSocket
();
private:
QBluetoothSocket
*
_targetSocket
;
QBluetoothDeviceInfo
*
_targetDevice
;
bool
_running
;
QBluetoothSocket
*
_targetSocket
;
#ifdef __ios__
QBluetoothServiceDiscoveryAgent
*
_discoveryAgent
;
#endif
bool
_shutDown
;
};
#endif // BTLINK_H
src/comm/LinkConfiguration.cc
View file @
8ec600aa
...
...
@@ -36,7 +36,7 @@ This file is part of the QGROUNDCONTROL project
#ifndef __mobile__
#include "LogReplayLink.h"
#endif
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
#include "BluetoothLink.h"
#endif
#ifdef QT_DEBUG
...
...
@@ -103,7 +103,7 @@ LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& na
case
LinkConfiguration
:
:
TypeTcp
:
config
=
new
TCPConfiguration
(
name
);
break
;
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
case
LinkConfiguration
:
:
TypeBluetooth
:
config
=
new
BluetoothConfiguration
(
name
);
break
;
...
...
@@ -141,10 +141,10 @@ LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* sourc
case
TypeTcp
:
dupe
=
new
TCPConfiguration
(
dynamic_cast
<
TCPConfiguration
*>
(
source
));
break
;
#ifdef
__mobile__
case
TypeBluetooth
:
dupe
=
new
BluetoothConfiguration
(
dynamic_cast
<
BluetoothConfiguration
*>
(
source
));
break
;
#ifdef
QGC_ENABLE_BLUETOOTH
case
TypeBluetooth
:
dupe
=
new
BluetoothConfiguration
(
dynamic_cast
<
BluetoothConfiguration
*>
(
source
));
break
;
#endif
#ifndef __mobile__
case
TypeLogReplay
:
...
...
src/comm/LinkConfiguration.h
View file @
8ec600aa
...
...
@@ -64,7 +64,7 @@ public:
#endif
TypeUdp
,
///< UDP Link
TypeTcp
,
///< TCP Link
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
TypeBluetooth
,
///< Bluetooth Link
#endif
#if 0
...
...
src/comm/LinkManager.cc
View file @
8ec600aa
...
...
@@ -39,10 +39,9 @@ This file is part of the QGROUNDCONTROL project
#include "LinkManager.h"
#include "QGCApplication.h"
#include "QGCApplication.h"
#include "UDPLink.h"
#include "TCPLink.h"
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
#include "BluetoothLink.h"
#endif
...
...
@@ -125,7 +124,7 @@ LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config)
case
LinkConfiguration
:
:
TypeTcp
:
pLink
=
new
TCPLink
(
dynamic_cast
<
TCPConfiguration
*>
(
config
));
break
;
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
case
LinkConfiguration
:
:
TypeBluetooth
:
pLink
=
new
BluetoothLink
(
dynamic_cast
<
BluetoothConfiguration
*>
(
config
));
break
;
...
...
@@ -361,7 +360,7 @@ void LinkManager::loadLinkConfigurationList()
case
LinkConfiguration
:
:
TypeTcp
:
pLink
=
(
LinkConfiguration
*
)
new
TCPConfiguration
(
name
);
break
;
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
case
LinkConfiguration
:
:
TypeBluetooth
:
pLink
=
(
LinkConfiguration
*
)
new
BluetoothConfiguration
(
name
);
break
;
...
...
@@ -708,7 +707,7 @@ QStringList LinkManager::linkTypeStrings(void) const
#endif
list
+=
"UDP"
;
list
+=
"TCP"
;
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
list
+=
"Bluetooth"
;
#endif
#ifdef QT_DEBUG
...
...
@@ -839,7 +838,7 @@ void LinkManager::_fixUnnamed(LinkConfiguration* config)
}
}
break
;
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
case
LinkConfiguration
:
:
TypeBluetooth
:
{
BluetoothConfiguration
*
tconfig
=
dynamic_cast
<
BluetoothConfiguration
*>
(
config
);
if
(
tconfig
)
{
...
...
@@ -888,3 +887,8 @@ bool LinkManager::isAutoconnectLink(LinkInterface* link)
{
return
_autoconnectConfigurations
.
contains
(
link
->
getLinkConfiguration
());
}
bool
LinkManager
::
isBluetoothAvailable
(
void
)
{
return
qgcApp
()
->
isBluetoothAvailable
();
}
src/comm/LinkManager.h
View file @
8ec600aa
...
...
@@ -80,6 +80,7 @@ public:
Q_PROPERTY
(
bool
autoconnectPixhawk
READ
autoconnectPixhawk
WRITE
setAutoconnectPixhawk
NOTIFY
autoconnectPixhawkChanged
)
Q_PROPERTY
(
bool
autoconnect3DRRadio
READ
autoconnect3DRRadio
WRITE
setAutoconnect3DRRadio
NOTIFY
autoconnect3DRRadioChanged
)
Q_PROPERTY
(
bool
autoconnectPX4Flow
READ
autoconnectPX4Flow
WRITE
setAutoconnectPX4Flow
NOTIFY
autoconnectPX4FlowChanged
)
Q_PROPERTY
(
bool
isBluetoothAvailable
READ
isBluetoothAvailable
CONSTANT
)
/// LinkInterface Accessor
Q_PROPERTY
(
QmlObjectListModel
*
links
READ
links
CONSTANT
)
...
...
@@ -104,12 +105,13 @@ public:
// Property accessors
bool
anyConnectedLinks
(
void
);
bool
anyActiveLinks
(
void
);
bool
autoconnectUDP
(
void
)
{
return
_autoconnectUDP
;
}
bool
autoconnectPixhawk
(
void
)
{
return
_autoconnectPixhawk
;
}
bool
autoconnect3DRRadio
(
void
)
{
return
_autoconnect3DRRadio
;
}
bool
autoconnectPX4Flow
(
void
)
{
return
_autoconnectPX4Flow
;
}
bool
anyConnectedLinks
(
void
);
bool
anyActiveLinks
(
void
);
bool
autoconnectUDP
(
void
)
{
return
_autoconnectUDP
;
}
bool
autoconnectPixhawk
(
void
)
{
return
_autoconnectPixhawk
;
}
bool
autoconnect3DRRadio
(
void
)
{
return
_autoconnect3DRRadio
;
}
bool
autoconnectPX4Flow
(
void
)
{
return
_autoconnectPX4Flow
;
}
bool
isBluetoothAvailable
(
void
);
QmlObjectListModel
*
links
(
void
)
{
return
&
_links
;
}
QmlObjectListModel
*
linkConfigurations
(
void
)
{
return
&
_linkConfigurations
;
}
...
...
src/main.cc
View file @
8ec600aa
...
...
@@ -49,7 +49,7 @@ This file is part of the QGROUNDCONTROL project
#endif
#endif
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
#include <QtBluetooth/QBluetoothSocket>
#endif
...
...
@@ -139,7 +139,7 @@ int main(int argc, char *argv[])
#ifndef __ios__
qRegisterMetaType
<
QSerialPort
::
SerialPortError
>
();
#endif
#ifdef
__mobile__
#ifdef
QGC_ENABLE_BLUETOOTH
qRegisterMetaType
<
QBluetoothSocket
::
SocketError
>
();
qRegisterMetaType
<
QBluetoothServiceInfo
>
();
#endif
...
...
src/ui/preferences/BluetoothSettings.qml
View file @
8ec600aa
...
...
@@ -39,9 +39,16 @@ Item {
// No need
}
QGCLabel
{
text
:
"
Bluetooth Not Available
"
visible
:
!
QGroundControl
.
linkManager
.
isBluetoothAvailable
anchors.centerIn
:
parent
}
Column
{
id
:
btColumn
spacing
:
ScreenTools
.
defaultFontPixelHeight
/
2
visible
:
QGroundControl
.
linkManager
.
isBluetoothAvailable
ExclusiveGroup
{
id
:
linkGroup
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment