Commit 0c5b5e5c32582d72dfa85248de4f8a9d00be1601
0 parents
Initial commit. dependencies not resolved yet.
Showing
15 changed files
with
1117 additions
and
0 deletions
.gitignore
0 → 100644
CMakeLists.txt
0 → 100644
1 | +++ a/CMakeLists.txt | |
1 | +cmake_minimum_required(VERSION 3.0) | |
2 | + | |
3 | +# Check to see where cmake is located. | |
4 | +if( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) | |
5 | + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |
6 | +elseif( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../cmake ) | |
7 | + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | |
8 | +else() | |
9 | + return() | |
10 | +endif() | |
11 | + | |
12 | +# Check to see if there is versioning information available | |
13 | +if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake) | |
14 | + LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/osdev_versioning/cmake) | |
15 | + include(osdevversion) | |
16 | +endif() | |
17 | + | |
18 | +include(projectheader) | |
19 | +project_header(osdev_qt-bluetooth) | |
20 | + | |
21 | +add_subdirectory(src) | |
22 | +add_subdirectory(tests) | |
23 | + | |
24 | +# include(packaging) | |
25 | +# package_component() | ... | ... |
README.md
0 → 100644
1 | +++ a/README.md | ... | ... |
src/CMakeLists.txt
0 → 100644
1 | +++ a/src/CMakeLists.txt | |
1 | +cmake_minimum_required(VERSION 3.0) | |
2 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake) | |
3 | +include(projectheader) | |
4 | +project_header(bluetooth) | |
5 | + | |
6 | +find_package( Qt5Core REQUIRED ) | |
7 | +find_package( Qt5Bluetooth REQUIRED ) | |
8 | + | |
9 | +include_directories( SYSTEM | |
10 | + ${Qt5Core_INCLUDE_DIRS} | |
11 | + ${Qt5Bluetooth_INCLUDE_DIRS} | |
12 | +) | |
13 | + | |
14 | +include(compiler) | |
15 | + | |
16 | +include_directories( | |
17 | + ${CMAKE_CURRENT_SOURCE_DIR}/../logutils | |
18 | +) | |
19 | + | |
20 | +set(SRC_LIST | |
21 | + ${CMAKE_CURRENT_SOURCE_DIR}/bluetoothbaseclass.cpp | |
22 | + ${CMAKE_CURRENT_SOURCE_DIR}/connectionhandler.cpp | |
23 | + ${CMAKE_CURRENT_SOURCE_DIR}/devicefinder.cpp | |
24 | + ${CMAKE_CURRENT_SOURCE_DIR}/devicehandler.cpp | |
25 | + ${CMAKE_CURRENT_SOURCE_DIR}/deviceinfo.cpp | |
26 | +) | |
27 | + | |
28 | +include(qtmoc) | |
29 | +create_mocs( SRC_LIST MOC_LIST | |
30 | + ${CMAKE_CURRENT_SOURCE_DIR}/bluetoothbaseclass.h | |
31 | + ${CMAKE_CURRENT_SOURCE_DIR}/connectionhandler.h | |
32 | + ${CMAKE_CURRENT_SOURCE_DIR}/devicefinder.h | |
33 | + ${CMAKE_CURRENT_SOURCE_DIR}/devicehandler.h | |
34 | + ${CMAKE_CURRENT_SOURCE_DIR}/deviceinfo.h | |
35 | +) | |
36 | + | |
37 | +link_directories( | |
38 | + ${CMAKE_BINARY_DIR}/lib | |
39 | +) | |
40 | + | |
41 | +include(library) | |
42 | +add_libraries( | |
43 | + ${Qt5Core_LIBRARIES} | |
44 | + ${Qt5Bluetooth_LIBRARIES} | |
45 | + logutils | |
46 | +) | |
47 | + | |
48 | +include(installation) | |
49 | +install_component() | ... | ... |
src/bluetoothbaseclass.cpp
0 → 100644
1 | +++ a/src/bluetoothbaseclass.cpp | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +// Qt | |
23 | +#include <QDebug> | |
24 | + | |
25 | +// osdev::components::bluetooth | |
26 | +#include "bluetoothbaseclass.h" | |
27 | + | |
28 | +using namespace osdev::components::bluetooth; | |
29 | + | |
30 | +BluetoothBaseClass::BluetoothBaseClass( QObject *parent ) | |
31 | + : QObject( parent ) | |
32 | + , m_error() | |
33 | + , m_info() | |
34 | +{ | |
35 | + | |
36 | +} | |
37 | + | |
38 | +QString BluetoothBaseClass::error() const | |
39 | +{ | |
40 | + return m_error; | |
41 | +} | |
42 | + | |
43 | +void BluetoothBaseClass::setError( const QString &error ) | |
44 | +{ | |
45 | + if( m_error != error ) | |
46 | + { | |
47 | + m_error = error; | |
48 | + qInfo() << m_error; | |
49 | + emit signalErrorChanged(); | |
50 | + } | |
51 | +} | |
52 | + | |
53 | +QString BluetoothBaseClass::info() const | |
54 | +{ | |
55 | + return m_info; | |
56 | +} | |
57 | + | |
58 | +void BluetoothBaseClass::setInfo( const QString &info ) | |
59 | +{ | |
60 | + if( m_info != info ) | |
61 | + { | |
62 | + m_info = info; | |
63 | + qInfo() << m_info; | |
64 | + emit signalInfoChanged(); | |
65 | + } | |
66 | +} | |
67 | + | |
68 | +void BluetoothBaseClass::clearMessages() | |
69 | +{ | |
70 | + setInfo( "" ); | |
71 | + setError( "" ); | |
72 | +} | ... | ... |
src/bluetoothbaseclass.h
0 → 100644
1 | +++ a/src/bluetoothbaseclass.h | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +#ifndef OSDEV_COMPONENTS_BLUETOOTH_BLUETOOTHBASECLASS_H | |
23 | +#define OSDEV_COMPONENTS_BLUETOOTH_BLUETOOTHBASECLASS_H | |
24 | + | |
25 | +#include <QObject> | |
26 | + | |
27 | +namespace osdev { | |
28 | +namespace components { | |
29 | +namespace bluetooth { | |
30 | + | |
31 | +class BluetoothBaseClass : public QObject | |
32 | +{ | |
33 | + Q_OBJECT | |
34 | + | |
35 | +public: | |
36 | + explicit BluetoothBaseClass( QObject *parent = nullptr ); | |
37 | + | |
38 | + QString error() const; | |
39 | + void setError( const QString &error ); | |
40 | + | |
41 | + QString info() const; | |
42 | + void setInfo( const QString &info ); | |
43 | + | |
44 | + void clearMessages(); | |
45 | + | |
46 | +signals: | |
47 | + void signalErrorChanged(); | |
48 | + void signalInfoChanged(); | |
49 | + | |
50 | +private: | |
51 | + QString m_error; | |
52 | + QString m_info; | |
53 | + | |
54 | +}; | |
55 | + | |
56 | +} /* End namespace bluetooth */ | |
57 | +} /* End namespace components */ | |
58 | +} /* End namespace osdev */ | |
59 | + | |
60 | +#endif /* OSDEV_COMPONENTS_BLUETOOTH_BLUETOOTHBASECLASS_H */ | ... | ... |
src/connectionhandler.cpp
0 → 100644
1 | +++ a/src/connectionhandler.cpp | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +// osdev::components::bluetooth | |
23 | +#include "connectionhandler.h" | |
24 | +//Qt | |
25 | +#include <QtBluetooth/qtbluetooth-config.h> | |
26 | +#include <QtCore/qsystemdetection.h> | |
27 | + | |
28 | +using namespace osdev::components::bluetooth; | |
29 | + | |
30 | +ConnectionHandler::ConnectionHandler( QObject *parent ) | |
31 | + : QObject( parent ) | |
32 | + , m_localDevice() | |
33 | +{ | |
34 | + connect( &m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &ConnectionHandler::slotHostModeChanged ); | |
35 | +} | |
36 | + | |
37 | +bool ConnectionHandler::alive() const | |
38 | +{ | |
39 | + // Bit hacky but basically just a large 'AND' statement. | |
40 | + return m_localDevice.isValid() && m_localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff; | |
41 | +} | |
42 | + | |
43 | +bool ConnectionHandler::requiresAddressType() const | |
44 | +{ | |
45 | +#if QT_CONFIG( bluez ) | |
46 | + return true; | |
47 | +#else | |
48 | + return false; | |
49 | +#endif | |
50 | +} | |
51 | + | |
52 | +QString ConnectionHandler::name() const | |
53 | +{ | |
54 | + return m_localDevice.name(); | |
55 | +} | |
56 | + | |
57 | +QString ConnectionHandler::address() const | |
58 | +{ | |
59 | + return m_localDevice.address().toString(); | |
60 | +} | |
61 | + | |
62 | +void ConnectionHandler::slotHostModeChanged( QBluetoothLocalDevice::HostMode /* mode */ ) | |
63 | +{ | |
64 | + emit signalDeviceChanged(); | |
65 | +} | ... | ... |
src/connectionhandler.h
0 → 100644
1 | +++ a/src/connectionhandler.h | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +#ifndef OSDEV_COMPONENTS_BLUETOOTH_CONNECTIONHANDLER_H | |
23 | +#define OSDEV_COMPONENTS_BLUETOOTH_CONNECTIONHANDLER_H | |
24 | + | |
25 | +// Qt | |
26 | +#include <QObject> | |
27 | +#include <QBluetoothLocalDevice> | |
28 | + | |
29 | +namespace osdev { | |
30 | +namespace components { | |
31 | +namespace bluetooth { | |
32 | + | |
33 | +class ConnectionHandler : public QObject | |
34 | +{ | |
35 | + Q_OBJECT | |
36 | + | |
37 | +public: | |
38 | + explicit ConnectionHandler( QObject *parent = nullptr ); | |
39 | + | |
40 | + bool alive() const; | |
41 | + bool requiresAddressType() const; | |
42 | + QString name() const; | |
43 | + QString address() const; | |
44 | + | |
45 | +signals: | |
46 | + void signalDeviceChanged(); | |
47 | + | |
48 | +private slots: | |
49 | + void slotHostModeChanged( QBluetoothLocalDevice::HostMode mode ); | |
50 | + | |
51 | +private: | |
52 | + QBluetoothLocalDevice m_localDevice; | |
53 | +}; | |
54 | + | |
55 | +} /* End namespace bluetooth */ | |
56 | +} /* End namespace components */ | |
57 | +} /* End namespace osdev */ | |
58 | + | |
59 | +#endif /* OSDEV_COMPONENTS_BLUETOOTH_CONNECTIONHANDLER_H */ | ... | ... |
src/devicefinder.cpp
0 → 100644
1 | +++ a/src/devicefinder.cpp | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +// osdev::components::bluetooth | |
23 | +#include "devicefinder.h" | |
24 | +#include "devicehandler.h" | |
25 | +#include "deviceinfo.h" | |
26 | + | |
27 | +using namespace osdev::components::bluetooth; | |
28 | + | |
29 | +DeviceFinder::DeviceFinder( DeviceHandler *handler, QObject *parent ) | |
30 | + : BluetoothBaseClass( parent ) | |
31 | + , m_pDeviceHandler( handler ) | |
32 | + , m_pDeviceDiscoveryAgent( new QBluetoothDeviceDiscoveryAgent() ) | |
33 | + , m_devices() | |
34 | +{ | |
35 | + //! [devicediscovery-1] | |
36 | + m_pDeviceDiscoveryAgent->setLowEnergyDiscoveryTimeout( 5000 ); | |
37 | + | |
38 | + connect( m_pDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &DeviceFinder::slotAddDevice ); | |
39 | + connect( m_pDeviceDiscoveryAgent, static_cast<void (QBluetoothDeviceDiscoveryAgent::*) | |
40 | + (QBluetoothDeviceDiscoveryAgent::Error)>(&QBluetoothDeviceDiscoveryAgent::error), this, &DeviceFinder::slotScanError ); | |
41 | + connect( m_pDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &DeviceFinder::slotScanFinished ); | |
42 | + connect( m_pDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &DeviceFinder::slotScanFinished ); | |
43 | + | |
44 | + connect( m_pDeviceHandler, &DeviceHandler::signalReceivedValue, this, &DeviceFinder::signalSendData ); | |
45 | +} | |
46 | + | |
47 | +DeviceFinder::~DeviceFinder() | |
48 | +{ | |
49 | + qDeleteAll( m_devices ); | |
50 | + m_devices.clear(); | |
51 | +} | |
52 | + | |
53 | +void DeviceFinder::slotStartSearch() | |
54 | +{ | |
55 | + clearMessages(); | |
56 | + m_pDeviceHandler->setDevice( nullptr ); | |
57 | + qDeleteAll( m_devices ); | |
58 | + m_devices.clear(); | |
59 | + | |
60 | + emit signalDevicesChanged(); | |
61 | + | |
62 | + m_pDeviceDiscoveryAgent->start( QBluetoothDeviceDiscoveryAgent::LowEnergyMethod ); | |
63 | + | |
64 | + emit signalScanningChanged(); | |
65 | + setInfo( tr( "Scanning for devices..." ) ); | |
66 | +} | |
67 | + | |
68 | +void DeviceFinder::slotAddDevice( const QBluetoothDeviceInfo &device ) | |
69 | +{ | |
70 | + // If device is LowEnergy-device and its services contain the one we're looking for, add it to the list. | |
71 | + if( device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration ) | |
72 | + { | |
73 | + qInfo() << device.serviceUuids() << " : Looking for : " << m_pDeviceHandler->requestedServiceUuid(); | |
74 | + | |
75 | + m_devices.append( new DeviceInfo( device ) ); | |
76 | + setInfo( tr( "Low Energy Device Found. Scanning for more...." ) ); | |
77 | + emit signalDevicesChanged(); | |
78 | + } | |
79 | +} | |
80 | + | |
81 | +void DeviceFinder::slotScanError( QBluetoothDeviceDiscoveryAgent::Error error ) | |
82 | +{ | |
83 | + if( error == QBluetoothDeviceDiscoveryAgent::PoweredOffError ) | |
84 | + { | |
85 | + setError( tr( "The Bluetooth adapter is powered off." ) ); | |
86 | + } | |
87 | + else if( error == QBluetoothDeviceDiscoveryAgent::InputOutputError ) | |
88 | + { | |
89 | + setError( tr( "Writing or reading from the device resulted in an error." ) ); | |
90 | + } | |
91 | + else | |
92 | + { | |
93 | + setError( tr( "An unknown error has occured." ) ); | |
94 | + } | |
95 | +} | |
96 | + | |
97 | +void DeviceFinder::slotScanFinished() | |
98 | +{ | |
99 | + if( m_devices.isEmpty() ) | |
100 | + setError( tr( "No Low Energy devices found." ) ); | |
101 | + else | |
102 | + setInfo( tr( "Scanning done." ) ); | |
103 | + | |
104 | + emit signalScanningChanged(); | |
105 | + emit signalDevicesChanged(); | |
106 | + emit signalScanFinished(); | |
107 | +} | |
108 | + | |
109 | +void DeviceFinder::slotConnectToService( const QString &address ) | |
110 | +{ | |
111 | + m_pDeviceDiscoveryAgent->stop(); | |
112 | + | |
113 | + DeviceInfo *currentDevice = nullptr; | |
114 | + for( auto entry : qAsConst( m_devices ) ) | |
115 | + { | |
116 | + if( entry && entry->getAddress() == address ) | |
117 | + { | |
118 | + currentDevice = entry; | |
119 | + break; | |
120 | + } | |
121 | + } | |
122 | + | |
123 | + if( currentDevice ) | |
124 | + m_pDeviceHandler->setDevice( currentDevice ); | |
125 | + | |
126 | + clearMessages(); | |
127 | +} | |
128 | + | |
129 | +bool DeviceFinder::scanning() const | |
130 | +{ | |
131 | + return m_pDeviceDiscoveryAgent->isActive(); | |
132 | +} | |
133 | + | |
134 | +QList<DeviceInfo*> DeviceFinder::devices() | |
135 | +{ | |
136 | + return m_devices; | |
137 | +} | |
138 | + | |
139 | +QString DeviceFinder::getAddressByName( const QString &name ) | |
140 | +{ | |
141 | + if( name.isEmpty() || name.isNull() ) | |
142 | + return QString(); | |
143 | + | |
144 | + for( const auto &device : qAsConst( m_devices ) ) | |
145 | + { | |
146 | + if( device->getName() == name ) | |
147 | + return device->getAddress(); | |
148 | + } | |
149 | + | |
150 | + return QString(); | |
151 | +} | |
152 | + | |
153 | +void DeviceFinder::slotDisconnect() | |
154 | +{ | |
155 | + m_pDeviceHandler->slotDisconnectService(); | |
156 | +} | ... | ... |
src/devicefinder.h
0 → 100644
1 | +++ a/src/devicefinder.h | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +#ifndef OSDEV_COMPONENTS_BLUETOOTH_DEVICEFINDER_H | |
23 | +#define OSDEV_COMPONENTS_BLUETOOTH_DEVICEFINDER_H | |
24 | + | |
25 | +// osdev::components::bluetooh | |
26 | +#include "bluetoothbaseclass.h" | |
27 | +#include "deviceinfo.h" | |
28 | +#include "devicehandler.h" | |
29 | +//Qt | |
30 | +#include <QTimer> | |
31 | +#include <QVariant> | |
32 | +#include <QBluetoothDeviceDiscoveryAgent> | |
33 | +#include <QBluetoothDeviceInfo> | |
34 | + | |
35 | +namespace osdev { | |
36 | +namespace components { | |
37 | +namespace bluetooth { | |
38 | + | |
39 | +class DeviceFinder : public BluetoothBaseClass | |
40 | +{ | |
41 | + Q_OBJECT | |
42 | + | |
43 | +public: | |
44 | + DeviceFinder( DeviceHandler *handler, QObject *parent = nullptr ); | |
45 | + ~DeviceFinder(); | |
46 | + | |
47 | + /// Deleted copy-constructor | |
48 | + DeviceFinder( const DeviceFinder& ) = delete; | |
49 | + /// Deleted assignment operator | |
50 | + DeviceFinder& operator=(const DeviceFinder&) = delete; | |
51 | + /// Deleted move-constructor | |
52 | + DeviceFinder( DeviceFinder&& ) = delete; | |
53 | + /// Deleted move operator | |
54 | + DeviceFinder& operator=( DeviceFinder&& ) = delete; | |
55 | + | |
56 | + bool scanning() const; | |
57 | + QList<DeviceInfo*> devices(); | |
58 | + QString getAddressByName( const QString &name ); | |
59 | + | |
60 | +public slots: | |
61 | + void slotStartSearch(); | |
62 | + void slotConnectToService( const QString &address ); | |
63 | + void slotAddDevice( const QBluetoothDeviceInfo &device ); | |
64 | + void slotScanError( QBluetoothDeviceDiscoveryAgent::Error error ); | |
65 | + void slotScanFinished(); | |
66 | + void slotDisconnect(); | |
67 | + | |
68 | +signals: | |
69 | + void signalScanningChanged(); | |
70 | + void signalDevicesChanged(); | |
71 | + void signalScanFinished(); | |
72 | + void signalSendData( const QString &data ); | |
73 | + | |
74 | +private: | |
75 | + DeviceHandler *m_pDeviceHandler; | |
76 | + QBluetoothDeviceDiscoveryAgent *m_pDeviceDiscoveryAgent; | |
77 | + QList<DeviceInfo*> m_devices; | |
78 | +}; | |
79 | + | |
80 | +} /* End namespace bluetooth */ | |
81 | +} /* End namespace components */ | |
82 | +} /* End namepsace osdev */ | |
83 | + | |
84 | +#endif /* OSDEV_COMPONENTS_BLUETOOTH_DEVICEFINDER_H */ | ... | ... |
src/devicehandler.cpp
0 → 100644
1 | +++ a/src/devicehandler.cpp | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +// osdev::components::bluetooth | |
23 | +#include "devicehandler.h" | |
24 | +#include "deviceinfo.h" | |
25 | +#include <QtEndian> | |
26 | +#include <QRandomGenerator> | |
27 | +#include <QScopedPointer> | |
28 | + | |
29 | +using namespace osdev::components::bluetooth; | |
30 | + | |
31 | +DeviceHandler::DeviceHandler( QObject *parent ) | |
32 | + : BluetoothBaseClass( parent ) | |
33 | + , m_pControl( nullptr ) | |
34 | + , m_pService( nullptr ) | |
35 | + , m_notificationDescriptor() | |
36 | + , m_pCurrentDevice( nullptr ) | |
37 | + , m_foundRequestedService( false ) | |
38 | + , m_measuring( false ) | |
39 | + , m_measurements() | |
40 | + , m_addressType( QLowEnergyController::PublicAddress ) | |
41 | + , m_requestedServiceUuid() | |
42 | + , m_requestedCharacteristicUuid() | |
43 | +{ | |
44 | + | |
45 | +} | |
46 | + | |
47 | +void DeviceHandler::setAddressType( AddressType type ) | |
48 | +{ | |
49 | + switch( type ) | |
50 | + { | |
51 | + case DeviceHandler::AddressType::PublicAddress: | |
52 | + { | |
53 | + m_addressType = QLowEnergyController::PublicAddress; | |
54 | + break; | |
55 | + } | |
56 | + case DeviceHandler::AddressType::RandomAddress: | |
57 | + { | |
58 | + m_addressType = QLowEnergyController::RandomAddress; | |
59 | + break; | |
60 | + } | |
61 | + } | |
62 | +} | |
63 | + | |
64 | +DeviceHandler::AddressType DeviceHandler::addressType() const | |
65 | +{ | |
66 | + if( m_addressType == QLowEnergyController::RandomAddress ) | |
67 | + return DeviceHandler::AddressType::RandomAddress; | |
68 | + | |
69 | + return DeviceHandler::AddressType::PublicAddress; | |
70 | +} | |
71 | + | |
72 | +void DeviceHandler::setDevice( DeviceInfo *device ) | |
73 | +{ | |
74 | + clearMessages(); | |
75 | + m_pCurrentDevice = device; | |
76 | + | |
77 | + // Disconnect and delete old connection | |
78 | + if( m_pControl ) | |
79 | + { | |
80 | + m_pControl->disconnectFromDevice(); | |
81 | + delete m_pControl; | |
82 | + m_pControl = nullptr; | |
83 | + } | |
84 | + | |
85 | + // Create new controller and connect it if device is available. | |
86 | + if( m_pCurrentDevice ) | |
87 | + { | |
88 | + // Make connections | |
89 | + //! [connect signals-1] | |
90 | + m_pControl = QLowEnergyController::createCentral( m_pCurrentDevice->getDevice(), this ); | |
91 | + m_pControl->setRemoteAddressType( m_addressType ); | |
92 | + | |
93 | + connect( m_pControl, &QLowEnergyController::serviceDiscovered, this, &DeviceHandler::slotServiceDiscovered ); | |
94 | + connect( m_pControl, &QLowEnergyController::discoveryFinished, this, &DeviceHandler::slotServiceScanDone ); | |
95 | + connect( m_pControl, | |
96 | + static_cast<void (QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error), | |
97 | + this, | |
98 | + [this](QLowEnergyController::Error error) | |
99 | + { | |
100 | + Q_UNUSED( error ); | |
101 | + emit signalConnectionStateChanged( false ); | |
102 | + setError( "Cannot connect to remote device." ); | |
103 | + } | |
104 | + ); | |
105 | + connect( m_pControl, &QLowEnergyController::disconnected, this, [this]() | |
106 | + { | |
107 | + emit signalConnectionStateChanged( false ); | |
108 | + setError( "LowEnergy controller disconnected" ); | |
109 | + }); | |
110 | + connect( m_pControl, &QLowEnergyController::connected, this, [this]() | |
111 | + { | |
112 | + emit signalConnectionStateChanged( true ); | |
113 | + setInfo( "LowEnergy controller connected... Search Services" ); | |
114 | + m_pControl->discoverServices(); | |
115 | + }); | |
116 | + | |
117 | + // Connect | |
118 | + m_pControl->connectToDevice(); | |
119 | + } | |
120 | +} | |
121 | + | |
122 | +void DeviceHandler::setRequestedServiceUuid( const QBluetoothUuid &service_uuid ) | |
123 | +{ | |
124 | + m_requestedServiceUuid = service_uuid; | |
125 | +} | |
126 | + | |
127 | +QBluetoothUuid DeviceHandler::requestedServiceUuid() const | |
128 | +{ | |
129 | + return m_requestedServiceUuid; | |
130 | +} | |
131 | + | |
132 | +void DeviceHandler::setRequestedCharacteristicUuid( const QBluetoothUuid &char_uuid ) | |
133 | +{ | |
134 | + m_requestedCharacteristicUuid = char_uuid; | |
135 | +} | |
136 | + | |
137 | +QBluetoothUuid DeviceHandler::requestedCharacteristicUuid() const | |
138 | +{ | |
139 | + return m_requestedCharacteristicUuid; | |
140 | +} | |
141 | + | |
142 | +void DeviceHandler::slotStartMeasurement() | |
143 | +{ | |
144 | + | |
145 | +} | |
146 | + | |
147 | +void DeviceHandler::slotStopMeasurement() | |
148 | +{ | |
149 | + | |
150 | +} | |
151 | + | |
152 | +void DeviceHandler::slotServiceDiscovered( const QBluetoothUuid &gatt ) | |
153 | +{ | |
154 | + if( gatt == m_requestedServiceUuid ) | |
155 | + { | |
156 | + setInfo( "Requested service discovered. Waiting for service scan to be done..." ); | |
157 | + m_foundRequestedService = true; | |
158 | + } | |
159 | +} | |
160 | + | |
161 | +void DeviceHandler::slotServiceScanDone() | |
162 | +{ | |
163 | + setInfo( "Service scan done." ); | |
164 | + | |
165 | + // Delete old service if available. | |
166 | + if( m_pService ) | |
167 | + { | |
168 | + delete m_pService; | |
169 | + m_pService = nullptr; | |
170 | + } | |
171 | + | |
172 | + // If Requested service is found, create a new service. | |
173 | + if( m_foundRequestedService ) | |
174 | + m_pService = m_pControl->createServiceObject( m_requestedServiceUuid, this ); | |
175 | + | |
176 | + if( m_pService ) | |
177 | + { | |
178 | + qInfo() << "Connected to service : " << m_requestedServiceUuid; | |
179 | + connect( m_pService, &QLowEnergyService::stateChanged, this, &DeviceHandler::slotServiceStateChanged ); | |
180 | + connect( m_pService, &QLowEnergyService::characteristicChanged, this, &DeviceHandler::slotUpdateMeasuredValue ); | |
181 | + connect( m_pService, &QLowEnergyService::descriptorWritten, this, &DeviceHandler::slotConfirmedDescriptorWrite ); | |
182 | + m_pService->discoverDetails(); | |
183 | + } | |
184 | + else | |
185 | + { | |
186 | + setError( "Requested Service was not found." ); | |
187 | + } | |
188 | +} | |
189 | + | |
190 | +void DeviceHandler::slotServiceStateChanged( QLowEnergyService::ServiceState state ) | |
191 | +{ | |
192 | + switch( state ) | |
193 | + { | |
194 | + case QLowEnergyService::DiscoveringServices: | |
195 | + setInfo( tr("Discovering Services..." ) ); | |
196 | + break; | |
197 | + case QLowEnergyService::ServiceDiscovered: | |
198 | + { | |
199 | + setInfo( tr( "Service discovered." ) ); | |
200 | + | |
201 | + const QLowEnergyCharacteristic fChar = m_pService->characteristic( m_requestedCharacteristicUuid ); | |
202 | + if( !fChar.isValid() ) | |
203 | + { | |
204 | + setError( "Requasted Data not Found." ); | |
205 | + break; | |
206 | + } | |
207 | + | |
208 | + m_notificationDescriptor = fChar.descriptor( QBluetoothUuid::ClientCharacteristicConfiguration ); | |
209 | + if( m_notificationDescriptor.isValid() ) | |
210 | + { | |
211 | + m_pService->writeDescriptor( m_notificationDescriptor, QByteArray::fromHex( "0100" ) ); | |
212 | + } | |
213 | + break; | |
214 | + } | |
215 | + | |
216 | + default: | |
217 | + // nothing for now | |
218 | + break; | |
219 | + } | |
220 | + | |
221 | + emit signalAliveChanged(); | |
222 | +} | |
223 | + | |
224 | +void DeviceHandler::slotUpdateMeasuredValue( const QLowEnergyCharacteristic &c, const QByteArray &value ) | |
225 | +{ | |
226 | + // Ignore any other characteristic change -> shouldn't really happen, though | |
227 | + if( c.uuid() != m_requestedCharacteristicUuid ) | |
228 | + return; | |
229 | + | |
230 | + qInfo() << "QByteArray() : " << value << " => Size : " << value.size(); | |
231 | + | |
232 | + QString read_value = QString( value ); | |
233 | + emit signalReceivedValue( read_value ); | |
234 | +} | |
235 | + | |
236 | +void DeviceHandler::slotConfirmedDescriptorWrite( const QLowEnergyDescriptor &d, const QByteArray &value ) | |
237 | +{ | |
238 | + if( d.isValid() && d == m_notificationDescriptor && value == QByteArray::fromHex( "0000" ) ) | |
239 | + { | |
240 | + // disabled notifications -> assume disconnect intent | |
241 | + m_pControl->disconnectFromDevice(); | |
242 | + delete m_pService; | |
243 | + m_pService = nullptr; | |
244 | + } | |
245 | +} | |
246 | + | |
247 | +void DeviceHandler::slotDisconnectService() | |
248 | +{ | |
249 | + m_foundRequestedService = false; | |
250 | + | |
251 | + // disable notifications | |
252 | + if( m_notificationDescriptor.isValid() && m_pService && m_notificationDescriptor.value() == QByteArray::fromHex( "0100" ) ) | |
253 | + { | |
254 | + m_pService->writeDescriptor( m_notificationDescriptor, QByteArray::fromHex( "0000" ) ); | |
255 | + } | |
256 | + else | |
257 | + { | |
258 | + if( m_pControl ) | |
259 | + m_pControl->disconnectFromDevice(); | |
260 | + | |
261 | + delete m_pService; | |
262 | + m_pService = nullptr; | |
263 | + } | |
264 | +} | |
265 | + | |
266 | +bool DeviceHandler::measuring() const | |
267 | +{ | |
268 | + return m_measuring; | |
269 | +} | |
270 | + | |
271 | +bool DeviceHandler::alive() const | |
272 | +{ | |
273 | + if( m_pService ) | |
274 | + return m_pService->state() == QLowEnergyService::ServiceDiscovered; | |
275 | + | |
276 | + return false; | |
277 | +} | ... | ... |
src/devicehandler.h
0 → 100644
1 | +++ a/src/devicehandler.h | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +#ifndef OSDEV_COMPONENTS_BLUETOOTH_DEVICEHANDLER_H | |
23 | +#define OSDEV_COMPONENTS_BLUETOOTH_DEVICEHANDLER_H | |
24 | + | |
25 | +#include "bluetoothbaseclass.h" | |
26 | +#include "deviceinfo.h" | |
27 | + | |
28 | +#include <QDateTime> | |
29 | +#include <QTimer> | |
30 | +#include <QVector> | |
31 | + | |
32 | +#include <QLowEnergyController> | |
33 | +#include <QLowEnergyService> | |
34 | + | |
35 | +namespace osdev { | |
36 | +namespace components { | |
37 | +namespace bluetooth { | |
38 | + | |
39 | +class DeviceHandler : public BluetoothBaseClass | |
40 | +{ | |
41 | + Q_OBJECT | |
42 | + | |
43 | +public: | |
44 | + enum class AddressType | |
45 | + { | |
46 | + PublicAddress, | |
47 | + RandomAddress | |
48 | + }; | |
49 | + | |
50 | + DeviceHandler( QObject *parent = nullptr ); | |
51 | + | |
52 | + /// Deleted copy-constructor | |
53 | + DeviceHandler( const DeviceHandler& ) = delete; | |
54 | + /// Deleted assignment operator | |
55 | + DeviceHandler& operator=(const DeviceHandler&) = delete; | |
56 | + /// Deleted move-constructor | |
57 | + DeviceHandler( DeviceHandler&& ) = delete; | |
58 | + /// Deleted move operator | |
59 | + DeviceHandler& operator=( DeviceHandler&& ) = delete; | |
60 | + | |
61 | + void setDevice( DeviceInfo *device ); | |
62 | + void setAddressType( AddressType type ); | |
63 | + AddressType addressType() const; | |
64 | + | |
65 | + bool measuring() const; | |
66 | + bool alive() const; | |
67 | + | |
68 | + void setRequestedServiceUuid( const QBluetoothUuid &service_uuid ); | |
69 | + QBluetoothUuid requestedServiceUuid() const; | |
70 | + | |
71 | + void setRequestedCharacteristicUuid( const QBluetoothUuid &char_uuid ); | |
72 | + QBluetoothUuid requestedCharacteristicUuid() const; | |
73 | + | |
74 | +signals: | |
75 | + void signalMeasuringChanged(); | |
76 | + void signalAliveChanged(); | |
77 | + void signalConnectionStateChanged( bool state ); | |
78 | + void signalStatsChanged(); | |
79 | + | |
80 | + void signalReceivedValue( const QString &value ); | |
81 | + | |
82 | +public slots: | |
83 | + void slotStartMeasurement(); | |
84 | + void slotStopMeasurement(); | |
85 | + void slotDisconnectService(); | |
86 | + | |
87 | + // QLowEnergyController | |
88 | + void slotServiceDiscovered( const QBluetoothUuid &gatt ); | |
89 | + void slotServiceScanDone(); | |
90 | + | |
91 | + // QLowEnergyService | |
92 | + void slotServiceStateChanged( QLowEnergyService::ServiceState state ); | |
93 | + void slotUpdateMeasuredValue( const QLowEnergyCharacteristic &characteristic, const QByteArray &value ); | |
94 | + void slotConfirmedDescriptorWrite( const QLowEnergyDescriptor &descriptor, const QByteArray &value ); | |
95 | + | |
96 | +private: | |
97 | + QLowEnergyController *m_pControl; | |
98 | + QLowEnergyService *m_pService; | |
99 | + QLowEnergyDescriptor m_notificationDescriptor; | |
100 | + DeviceInfo *m_pCurrentDevice; | |
101 | + | |
102 | + bool m_foundRequestedService; | |
103 | + bool m_measuring; | |
104 | + | |
105 | + QVector<int> m_measurements; | |
106 | + QLowEnergyController::RemoteAddressType m_addressType; | |
107 | + QBluetoothUuid m_requestedServiceUuid; | |
108 | + QBluetoothUuid m_requestedCharacteristicUuid; | |
109 | +}; | |
110 | + | |
111 | +} /* End namespace bluetooth */ | |
112 | +} /* End namespace components */ | |
113 | +} /* End namespace osdev */ | |
114 | + | |
115 | +#endif /* OSDEV_COMPONENTS_BLUETOOTH_DEVICEHANDLER_H */ | ... | ... |
src/deviceinfo.cpp
0 → 100644
1 | +++ a/src/deviceinfo.cpp | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +// osdev::components::bluetooth | |
23 | +#include "deviceinfo.h" | |
24 | +// Qt | |
25 | +#include <QBluetoothAddress> | |
26 | +#include <QBluetoothUuid> | |
27 | + | |
28 | +using namespace osdev::components::bluetooth; | |
29 | + | |
30 | +DeviceInfo::DeviceInfo( const QBluetoothDeviceInfo &info, QObject *parent ) | |
31 | + : QObject( parent ) | |
32 | + , m_device( info ) | |
33 | +{ | |
34 | + | |
35 | +} | |
36 | + | |
37 | +QBluetoothDeviceInfo DeviceInfo::getDevice() const | |
38 | +{ | |
39 | + return m_device; | |
40 | +} | |
41 | + | |
42 | +QString DeviceInfo::getName() const | |
43 | +{ | |
44 | + return m_device.name(); | |
45 | +} | |
46 | + | |
47 | +QString DeviceInfo::getAddress() const | |
48 | +{ | |
49 | +#if defined Q_OS_DARWIN | |
50 | + return m_device.deviceUuid().toString(); | |
51 | +#else | |
52 | + return m_device.address().toString(); | |
53 | +#endif | |
54 | +} | |
55 | + | |
56 | +QString DeviceInfo::getUuid() const | |
57 | +{ | |
58 | + return m_device.deviceUuid().toString(); | |
59 | +} | |
60 | + | |
61 | +void DeviceInfo::setDevice( const QBluetoothDeviceInfo &device ) | |
62 | +{ | |
63 | + m_device = device; | |
64 | + emit signalDeviceChanged(); | |
65 | +} | ... | ... |
src/deviceinfo.h
0 → 100644
1 | +++ a/src/deviceinfo.h | |
1 | +/* **************************************************************************** | |
2 | + * Copyright 2019 Open Systems Development BV * | |
3 | + * * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
5 | + * copy of this software and associated documentation files (the "Software"), * | |
6 | + * to deal in the Software without restriction, including without limitation * | |
7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
9 | + * Software is furnished to do so, subject to the following conditions: * | |
10 | + * * | |
11 | + * The above copyright notice and this permission notice shall be included in * | |
12 | + * all copies or substantial portions of the Software. * | |
13 | + * * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
20 | + * DEALINGS IN THE SOFTWARE. * | |
21 | + * ***************************************************************************/ | |
22 | +#ifndef OSDEV_COMPONENTS_BLUETOOTH_DEVICEINFO_H | |
23 | +#define OSDEV_COMPONENTS_BLUETOOTH_DEVICEINFO_H | |
24 | + | |
25 | +#include <QString> | |
26 | +#include <QObject> | |
27 | +#include <QBluetoothDeviceInfo> | |
28 | + | |
29 | +namespace osdev { | |
30 | +namespace components { | |
31 | +namespace bluetooth { | |
32 | + | |
33 | +class DeviceInfo : public QObject | |
34 | +{ | |
35 | + Q_OBJECT | |
36 | + | |
37 | +public: | |
38 | + DeviceInfo( const QBluetoothDeviceInfo &device, QObject *parent = nullptr ); | |
39 | + | |
40 | + void setDevice( const QBluetoothDeviceInfo &device ); | |
41 | + | |
42 | + QString getName() const; | |
43 | + QString getAddress() const; | |
44 | + QString getUuid() const; | |
45 | + QBluetoothDeviceInfo getDevice() const; | |
46 | + | |
47 | +signals: | |
48 | + void signalDeviceChanged(); | |
49 | + | |
50 | +private: | |
51 | + QBluetoothDeviceInfo m_device; | |
52 | +}; | |
53 | + | |
54 | +} /* End namespace bluetooth */ | |
55 | +} /* End namespace components */ | |
56 | +} /* End namespace osdev */ | |
57 | + | |
58 | +#endif /* OSDEV_COMPONENTS_BLUETOOTH_DEVICEINFO_H */ | ... | ... |
tests/CMakeLists.txt
0 → 100644
1 | +++ a/tests/CMakeLists.txt | |
1 | +cmake_minimum_required(VERSION 3.0) | |
2 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | |
3 | + | |
4 | +include(projectheader) | |
5 | +project_header(test_logutils) | |
6 | + | |
7 | +include_directories( SYSTEM | |
8 | + ${CMAKE_CURRENT_SOURCE_DIR}/../../src | |
9 | +) | |
10 | + | |
11 | +include(compiler) | |
12 | +set(SRC_LIST | |
13 | +) | |
14 | + | |
15 | +# add_executable( ${PROJECT_NAME} | |
16 | +# ${SRC_LIST} | |
17 | +# ) | |
18 | + | |
19 | +# target_link_libraries( | |
20 | +# ${PROJECT_NAME} | |
21 | +# ) | |
22 | + | |
23 | +# set_target_properties( ${PROJECT_NAME} PROPERTIES | |
24 | +# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | |
25 | +# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib | |
26 | +# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive | |
27 | +# ) | |
28 | + | |
29 | +# include(installation) | |
30 | +# install_application() | ... | ... |