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
5b46a393
Commit
5b46a393
authored
Dec 04, 2015
by
dogmaphobic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First shot at Bluetooth
parent
c58f1378
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
831 additions
and
2 deletions
+831
-2
qgroundcontrol.pro
qgroundcontrol.pro
+14
-1
qgroundcontrol.qrc
qgroundcontrol.qrc
+1
-0
BluetoothLink.cc
src/comm/BluetoothLink.cc
+420
-0
BluetoothLink.h
src/comm/BluetoothLink.h
+166
-0
LinkConfiguration.cc
src/comm/LinkConfiguration.cc
+13
-1
LinkConfiguration.h
src/comm/LinkConfiguration.h
+4
-0
LinkManager.cc
src/comm/LinkManager.cc
+26
-0
main.cc
src/main.cc
+8
-0
BluetoothSettings.qml
src/ui/preferences/BluetoothSettings.qml
+179
-0
No files found.
qgroundcontrol.pro
View file @
5b46a393
...
...
@@ -69,11 +69,16 @@ QT += \
xml
\
!
MobileBuild
{
QT
+=
\
QT
+=
\
printsupport
\
serialport
\
}
!
WindowsBuild
{
QT
+=
\
bluetooth
\
}
contains
(
DEFINES
,
QGC_NOTIFY_TUNES_ENABLED
)
{
QT
+=
multimedia
}
...
...
@@ -304,6 +309,9 @@ HEADERS += \
WindowsBuild
{
PRECOMPILED_HEADER
+=
src
/
stable_headers
.
h
HEADERS
+=
src
/
stable_headers
.
h
}
else
{
HEADERS
+=
\
src
/
comm
/
BluetoothLink
.
h
\
}
!
iOSBuild
{
...
...
@@ -425,6 +433,11 @@ SOURCES += \
src
/
ui
/
SerialConfigurationWindow
.
cc
\
}
!
WindowsBuild
{
SOURCES
+=
\
src
/
comm
/
BluetoothLink
.
cc
\
}
!
MobileBuild
{
SOURCES
+=
\
src
/
comm
/
LogReplayLink
.
cc
\
...
...
qgroundcontrol.qrc
View file @
5b46a393
...
...
@@ -16,6 +16,7 @@
<file alias="FlightModesComponent.qml">src/AutoPilotPlugins/PX4/FlightModesComponent.qml</file>
<file alias="FlightModesComponentSummary.qml">src/AutoPilotPlugins/PX4/FlightModesComponentSummary.qml</file>
<file alias="BluetoothSettings.qml">src/ui/preferences/BluetoothSettings.qml</file>
<file alias="DebugWindow.qml">src/ui/preferences/DebugWindow.qml</file>
<file alias="GeneralSettings.qml">src/ui/preferences/GeneralSettings.qml</file>
<file alias="LinkSettings.qml">src/ui/preferences/LinkSettings.qml</file>
...
...
src/comm/BluetoothLink.cc
0 → 100644
View file @
5b46a393
This diff is collapsed.
Click to expand it.
src/comm/BluetoothLink.h
0 → 100644
View file @
5b46a393
/*=====================================================================
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/>.
======================================================================*/
/*!
* @file
* @brief Bluetooth connection for unmanned vehicles
* @author Gus Grubba <mavlink@grubba.com>
*
*/
#ifndef BTLINK_H
#define BTLINK_H
#include <QString>
#include <QList>
#include <QMutex>
#include <QMutexLocker>
#include <QQueue>
#include <QByteArray>
#include <QBluetoothDeviceInfo>
#include <QtBluetooth/QBluetoothSocket>
#include "QGCConfig.h"
#include "LinkManager.h"
class
QBluetoothDeviceDiscoveryAgent
;
class
BluetoothConfiguration
:
public
LinkConfiguration
{
Q_OBJECT
public:
BluetoothConfiguration
(
const
QString
&
name
);
BluetoothConfiguration
(
BluetoothConfiguration
*
source
);
~
BluetoothConfiguration
();
Q_PROPERTY
(
QString
device
READ
device
WRITE
setDevice
NOTIFY
deviceChanged
)
Q_PROPERTY
(
QString
address
READ
address
WRITE
setAddress
NOTIFY
addressChanged
)
Q_PROPERTY
(
QStringList
deviceList
READ
deviceList
NOTIFY
deviceListChanged
)
Q_PROPERTY
(
bool
scanning
READ
scanning
NOTIFY
scanningChanged
)
Q_INVOKABLE
void
startScan
();
Q_INVOKABLE
void
stopScan
();
QString
device
()
{
return
_device
;
}
QString
address
()
{
return
_address
;
}
QStringList
deviceList
()
{
return
_deviceList
;
}
bool
scanning
()
{
return
_deviceDiscover
!=
NULL
;
}
void
setDevice
(
QString
device
);
void
setAddress
(
QString
address
)
{
_address
=
address
;
emit
addressChanged
();
}
/// From LinkConfiguration
LinkType
type
()
{
return
LinkConfiguration
::
TypeBluetooth
;
}
void
copyFrom
(
LinkConfiguration
*
source
);
void
loadSettings
(
QSettings
&
settings
,
const
QString
&
root
);
void
saveSettings
(
QSettings
&
settings
,
const
QString
&
root
);
void
updateSettings
();
QString
settingsURL
()
{
return
"BluetoothSettings.qml"
;
}
public
slots
:
void
deviceDiscovered
(
QBluetoothDeviceInfo
info
);
void
doneScanning
();
signals:
void
newDevice
(
QBluetoothDeviceInfo
info
);
void
deviceChanged
();
void
addressChanged
();
void
deviceListChanged
();
void
scanningChanged
();
private:
private:
QBluetoothDeviceDiscoveryAgent
*
_deviceDiscover
;
QString
_device
;
QString
_address
;
QStringList
_deviceList
;
QStringList
_addressList
;
};
class
BluetoothLink
:
public
LinkInterface
{
Q_OBJECT
friend
class
BluetoothConfiguration
;
friend
class
LinkManager
;
public:
void
requestReset
()
{
}
bool
isConnected
()
const
;
QString
getName
()
const
;
// Extensive statistics for scientific purposes
qint64
getConnectionSpeed
()
const
;
qint64
getCurrentInDataRate
()
const
;
qint64
getCurrentOutDataRate
()
const
;
void
run
();
// These are left unimplemented in order to cause linker errors which indicate incorrect usage of
// connect/disconnect on link directly. All connect/disconnect calls should be made through LinkManager.
bool
connect
(
void
);
bool
disconnect
(
void
);
LinkConfiguration
*
getLinkConfiguration
()
{
return
_config
;
}
public
slots
:
void
readBytes
();
void
writeBytes
(
const
char
*
data
,
qint64
length
);
void
deviceConnected
();
void
deviceDisconnected
();
void
deviceError
(
QBluetoothSocket
::
SocketError
error
);
void
stateChanged
(
QBluetoothSocket
::
SocketState
state
);
void
deviceDiscovered
(
QBluetoothDeviceInfo
info
);
void
doneScanning
();
protected:
BluetoothConfiguration
*
_config
;
bool
_connectState
;
private:
// Links are only created/destroyed by LinkManager so constructor/destructor is not public
BluetoothLink
(
BluetoothConfiguration
*
config
);
~
BluetoothLink
();
// From LinkInterface
bool
_connect
(
void
);
void
_disconnect
(
void
);
bool
_hardwareConnect
();
void
_restartConnection
();
void
_sendBytes
(
const
char
*
data
,
qint64
size
);
private:
QBluetoothSocket
*
_targetSocket
;
QBluetoothDeviceInfo
*
_targetDevice
;
QBluetoothDeviceDiscoveryAgent
*
_deviceDiscover
;
bool
_running
;
};
#endif // BTLINK_H
src/comm/LinkConfiguration.cc
View file @
5b46a393
...
...
@@ -36,7 +36,9 @@ This file is part of the QGROUNDCONTROL project
#ifndef __mobile__
#include "LogReplayLink.h"
#endif
#ifndef Q_OS_WIN
#include "BluetoothLink.h"
#endif
#ifdef QT_DEBUG
#include "MockLink.h"
#endif
...
...
@@ -101,6 +103,11 @@ LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& na
case
LinkConfiguration
:
:
TypeTcp
:
config
=
new
TCPConfiguration
(
name
);
break
;
#ifndef Q_OS_WIN
case
LinkConfiguration
:
:
TypeBluetooth
:
config
=
new
BluetoothConfiguration
(
name
);
break
;
#endif
#ifndef __mobile__
case
LinkConfiguration
:
:
TypeLogReplay
:
config
=
new
LogReplayLinkConfiguration
(
name
);
...
...
@@ -134,6 +141,11 @@ LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* sourc
case
TypeTcp
:
dupe
=
new
TCPConfiguration
(
dynamic_cast
<
TCPConfiguration
*>
(
source
));
break
;
#ifndef Q_OS_WIN
case
TypeBluetooth
:
dupe
=
new
BluetoothConfiguration
(
dynamic_cast
<
BluetoothConfiguration
*>
(
source
));
break
;
#endif
#ifndef __mobile__
case
TypeLogReplay
:
dupe
=
new
LogReplayLinkConfiguration
(
dynamic_cast
<
LogReplayLinkConfiguration
*>
(
source
));
...
...
src/comm/LinkConfiguration.h
View file @
5b46a393
...
...
@@ -57,12 +57,16 @@ public:
void
setLink
(
LinkInterface
*
link
);
/// The link types supported by QGC
/// Any changes here MUST be reflected in LinkManager::linkTypeStrings()
enum
LinkType
{
#ifndef __ios__
TypeSerial
,
///< Serial Link
#endif
TypeUdp
,
///< UDP Link
TypeTcp
,
///< TCP Link
#ifndef Q_OS_WIN
TypeBluetooth
,
///< Bluetooth Link
#endif
#if 0
// TODO Below is not yet implemented
TypeForwarding, ///< Forwarding Link
...
...
src/comm/LinkManager.cc
View file @
5b46a393
...
...
@@ -44,6 +44,9 @@ This file is part of the QGROUNDCONTROL project
#include "QGCApplication.h"
#include "UDPLink.h"
#include "TCPLink.h"
#ifndef Q_OS_WIN
#include "BluetoothLink.h"
#endif
QGC_LOGGING_CATEGORY
(
LinkManagerLog
,
"LinkManagerLog"
)
QGC_LOGGING_CATEGORY
(
LinkManagerVerboseLog
,
"LinkManagerVerboseLog"
)
...
...
@@ -124,6 +127,11 @@ LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config)
case
LinkConfiguration
:
:
TypeTcp
:
pLink
=
new
TCPLink
(
dynamic_cast
<
TCPConfiguration
*>
(
config
));
break
;
#ifndef Q_OS_WIN
case
LinkConfiguration
:
:
TypeBluetooth
:
pLink
=
new
BluetoothLink
(
dynamic_cast
<
BluetoothConfiguration
*>
(
config
));
break
;
#endif
#ifndef __mobile__
case
LinkConfiguration
:
:
TypeLogReplay
:
pLink
=
new
LogReplayLink
(
dynamic_cast
<
LogReplayLinkConfiguration
*>
(
config
));
...
...
@@ -359,6 +367,11 @@ void LinkManager::loadLinkConfigurationList()
case
LinkConfiguration
:
:
TypeTcp
:
pLink
=
(
LinkConfiguration
*
)
new
TCPConfiguration
(
name
);
break
;
#ifndef Q_OS_WIN
case
LinkConfiguration
:
:
TypeBluetooth
:
pLink
=
(
LinkConfiguration
*
)
new
BluetoothConfiguration
(
name
);
break
;
#endif
#ifndef __mobile__
case
LinkConfiguration
:
:
TypeLogReplay
:
pLink
=
(
LinkConfiguration
*
)
new
LogReplayLinkConfiguration
(
name
);
...
...
@@ -701,12 +714,16 @@ QStringList LinkManager::linkTypeStrings(void) const
#endif
list
+=
"UDP"
;
list
+=
"TCP"
;
#ifndef Q_OS_WIN
list
+=
"Bluetooth"
;
#endif
#ifdef QT_DEBUG
list
+=
"Mock Link"
;
#endif
#ifndef __mobile__
list
+=
"Log Replay"
;
#endif
Q_ASSERT
(
list
.
size
()
==
(
int
)
LinkConfiguration
::
TypeLast
);
}
return
list
;
}
...
...
@@ -828,6 +845,15 @@ void LinkManager::_fixUnnamed(LinkConfiguration* config)
}
}
break
;
#ifndef Q_OS_WIN
case
LinkConfiguration
:
:
TypeBluetooth
:
{
BluetoothConfiguration
*
tconfig
=
dynamic_cast
<
BluetoothConfiguration
*>
(
config
);
if
(
tconfig
)
{
config
->
setName
(
QString
(
"Bluetooth Device on %1"
).
arg
(
tconfig
->
device
()));
}
}
break
;
#endif
#ifndef __mobile__
case
LinkConfiguration
:
:
TypeLogReplay
:
{
LogReplayLinkConfiguration
*
tconfig
=
dynamic_cast
<
LogReplayLinkConfiguration
*>
(
config
);
...
...
src/main.cc
View file @
5b46a393
...
...
@@ -50,6 +50,10 @@ This file is part of the QGROUNDCONTROL project
#endif
#endif
#ifndef Q_OS_WIN
#include <QtBluetooth/QBluetoothSocket>
#endif
#include <iostream>
/* SDL does ugly things to main() */
...
...
@@ -135,6 +139,10 @@ int main(int argc, char *argv[])
// anyway to silence the debug output.
#ifndef __ios__
qRegisterMetaType
<
QSerialPort
::
SerialPortError
>
();
#endif
#ifndef Q_OS_WIN
qRegisterMetaType
<
QBluetoothSocket
::
SocketError
>
();
qRegisterMetaType
<
QBluetoothServiceInfo
>
();
#endif
qRegisterMetaType
<
QAbstractSocket
::
SocketError
>
();
#ifndef __mobile__
...
...
src/ui/preferences/BluetoothSettings.qml
0 → 100644
View file @
5b46a393
/*=====================================================================
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/>.
======================================================================*/
import
QtQuick
2.5
import
QtQuick
.
Controls
1.4
import
QtQuick
.
Dialogs
1.1
import
QGroundControl
1.0
import
QGroundControl
.
Controls
1.0
import
QGroundControl
.
ScreenTools
1.0
import
QGroundControl
.
Palette
1.0
Item
{
id
:
_btSettings
width
:
parent
?
parent
.
width
:
0
height
:
btColumn
.
height
function
saveSettings
()
{
// No need
}
property
var
_currentDevice
:
""
Column
{
id
:
btColumn
spacing
:
ScreenTools
.
defaultFontPixelHeight
/
2
ExclusiveGroup
{
id
:
linkGroup
}
QGCPalette
{
id
:
qgcPal
colorGroupEnabled
:
enabled
}
QGCLabel
{
id
:
btLabel
text
:
"
Bluetooth Link Settings
"
}
Rectangle
{
height
:
1
width
:
btLabel
.
width
color
:
qgcPal
.
button
}
Item
{
height
:
ScreenTools
.
defaultFontPixelHeight
/
2
width
:
parent
.
width
}
Row
{
spacing
:
ScreenTools
.
defaultFontPixelWidth
QGCLabel
{
text
:
"
Device:
"
width
:
_firstColumn
}
QGCLabel
{
id
:
deviceField
text
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
?
subEditConfig
.
device
:
""
}
}
Row
{
spacing
:
ScreenTools
.
defaultFontPixelWidth
QGCLabel
{
text
:
"
Address:
"
width
:
_firstColumn
}
QGCLabel
{
id
:
addressField
text
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
?
subEditConfig
.
address
:
""
}
}
Item
{
height
:
ScreenTools
.
defaultFontPixelHeight
/
2
width
:
parent
.
width
}
QGCLabel
{
text
:
"
Bluetooth Devices:
"
}
Item
{
width
:
hostRow
.
width
height
:
hostRow
.
height
Row
{
id
:
hostRow
spacing
:
ScreenTools
.
defaultFontPixelWidth
Item
{
height
:
1
width
:
_firstColumn
}
Column
{
id
:
hostColumn
spacing
:
ScreenTools
.
defaultFontPixelHeight
/
2
Rectangle
{
height
:
1
width
:
_secondColumn
color
:
qgcPal
.
button
visible
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
&&
subEditConfig
.
deviceList
.
length
>
0
}
Repeater
{
model
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
?
subEditConfig
.
deviceList
:
""
delegate
:
QGCButton
{
text
:
modelData
width
:
_secondColumn
anchors.leftMargin
:
ScreenTools
.
defaultFontPixelWidth
*
2
exclusiveGroup
:
linkGroup
onClicked
:
{
checked
=
true
_btSettings
.
_currentDevice
=
modelData
}
}
}
Rectangle
{
height
:
1
width
:
_secondColumn
color
:
qgcPal
.
button
}
Item
{
height
:
ScreenTools
.
defaultFontPixelHeight
/
2
width
:
parent
.
width
}
Item
{
width
:
_secondColumn
height
:
udpButtonRow
.
height
Row
{
id
:
udpButtonRow
spacing
:
ScreenTools
.
defaultFontPixelWidth
anchors.horizontalCenter
:
parent
.
horizontalCenter
QGCButton
{
width
:
ScreenTools
.
defaultFontPixelWidth
*
10
text
:
"
Scan
"
enabled
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
&&
!
subEditConfig
.
scanning
onClicked
:
{
if
(
subEditConfig
)
subEditConfig
.
startScan
()
}
}
QGCButton
{
width
:
ScreenTools
.
defaultFontPixelWidth
*
10
text
:
"
Stop
"
enabled
:
subEditConfig
&&
subEditConfig
.
linkType
===
LinkConfiguration
.
TypeBluetooth
&&
subEditConfig
.
scanning
onClicked
:
{
if
(
subEditConfig
)
subEditConfig
.
stopScan
()
}
}
QGCButton
{
width
:
ScreenTools
.
defaultFontPixelWidth
*
10
enabled
:
_btSettings
.
_currentDevice
&&
_btSettings
.
_currentDevice
!==
""
text
:
"
Select
"
onClicked
:
{
if
(
subEditConfig
)
subEditConfig
.
device
=
_btSettings
.
_currentDevice
}
}
}
}
}
}
}
}
}
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