BugFix finalisation of re-worked btservice for Bluetooth Handling.
Redeclare function scoped variables to be on on class object for persistent handling in memory.
This commit is contained in:
parent
361e1467b7
commit
d97edf539b
@ -11,9 +11,9 @@ set(CMAKE_AUTOUIC ON)
|
|||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
# Set Compile Versions
|
# Set Compile Versions
|
||||||
set(OPENAUTO_BUILD_DATE 20241121) # Binary Release Build Date
|
set(OPENAUTO_BUILD_DATE 20241124) # Binary Release Build Date
|
||||||
set(OPENAUTO_BUILD_MAJOR_RELEASE 4) # Binary Release Build Major Number
|
set(OPENAUTO_BUILD_MAJOR_RELEASE 4) # Binary Release Build Major Number
|
||||||
set(OPENAUTO_BUILD_MINOR_RELEASE 0) # Binary Release Build Minor Number
|
set(OPENAUTO_BUILD_MINOR_RELEASE 1) # Binary Release Build Minor Number
|
||||||
set(OPENAUTO_BUILD_INCREMENTAL 0) # Binary Build Version - Increment for Each Build
|
set(OPENAUTO_BUILD_INCREMENTAL 0) # Binary Build Version - Increment for Each Build
|
||||||
|
|
||||||
# Configure CMAKE
|
# Configure CMAKE
|
||||||
@ -26,6 +26,9 @@ set(CMAKE_CXX_FLAGS_RELEASE "-g -O3")
|
|||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
message(STATUS "Forcing Release build type")
|
message(STATUS "Forcing Release build type")
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/local/qt5/lib")
|
||||||
|
|
||||||
# Set the possible values of build type for cmake-gui
|
# Set the possible values of build type for cmake-gui
|
||||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
||||||
endif()
|
endif()
|
||||||
@ -87,7 +90,7 @@ find_package(aap_protobuf REQUIRED)
|
|||||||
find_package(aasdk REQUIRED)
|
find_package(aasdk REQUIRED)
|
||||||
find_package(Boost REQUIRED COMPONENTS system log OPTIONAL_COMPONENTS unit_test_framework)
|
find_package(Boost REQUIRED COMPONENTS system log OPTIONAL_COMPONENTS unit_test_framework)
|
||||||
find_package(libusb-1.0 REQUIRED)
|
find_package(libusb-1.0 REQUIRED)
|
||||||
find_package(Qt5 COMPONENTS Multimedia MultimediaWidgets Bluetooth Network)
|
find_package(Qt5 COMPONENTS DBus Multimedia MultimediaWidgets Bluetooth Network)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
find_package(rtaudio REQUIRED)
|
find_package(rtaudio REQUIRED)
|
||||||
find_package(taglib REQUIRED)
|
find_package(taglib REQUIRED)
|
||||||
@ -119,7 +122,7 @@ set(common_include_directory ${include_directory}/f1x/openauto/Common)
|
|||||||
set(autoapp_sources_directory ${sources_directory}/autoapp)
|
set(autoapp_sources_directory ${sources_directory}/autoapp)
|
||||||
set(autoapp_include_directory ${include_directory}/f1x/openauto/autoapp)
|
set(autoapp_include_directory ${include_directory}/f1x/openauto/autoapp)
|
||||||
|
|
||||||
file(GLOB_RECURSE autoapp_source_files ${autoapp_sources_directory}/*.ui ${autoapp_sources_directory}/*.cpp ${autoapp_include_directory}/*.hpp ${common_include_directory}/*.hpp ${resources_directory}/*.qrc)
|
file(GLOB_RECURSE autoapp_source_files ${autoapp_sources_directory}/*.ui ${autoapp_sources_directory}/*.cpp ${autoapp_include_directory}/*.hpp ${autoapp_include_directory}/*.h ${common_include_directory}/*.hpp ${resources_directory}/*.qrc)
|
||||||
|
|
||||||
add_executable(autoapp ${autoapp_source_files})
|
add_executable(autoapp ${autoapp_source_files})
|
||||||
|
|
||||||
@ -128,6 +131,7 @@ target_include_directories(autoapp PUBLIC ${AAP_PROTOBUF_INCLUDE_DIR} ${AASDK_IN
|
|||||||
target_link_libraries(autoapp PUBLIC
|
target_link_libraries(autoapp PUBLIC
|
||||||
libusb
|
libusb
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
|
${Qt5DBus_LIBRARIES}
|
||||||
${Qt5Multimedia_LIBRARIES}
|
${Qt5Multimedia_LIBRARIES}
|
||||||
${Qt5MultimediaWidgets_LIBRARIES}
|
${Qt5MultimediaWidgets_LIBRARIES}
|
||||||
${Qt5Bluetooth_LIBRARIES}
|
${Qt5Bluetooth_LIBRARIES}
|
||||||
@ -152,7 +156,8 @@ set(btservice_sources_directory ${sources_directory}/btservice)
|
|||||||
set(btservice_include_directory ${include_directory}/f1x/openauto/btservice)
|
set(btservice_include_directory ${include_directory}/f1x/openauto/btservice)
|
||||||
file(GLOB_RECURSE btservice_source_files ${btservice_sources_directory}/*.cpp ${btservice_include_directory}/*.hpp ${autoapp_sources_directory}/Configuration/*.cpp ${autoapp_includes_directory}/Configuration/*.hpp ${common_include_directory}/*.hpp)
|
file(GLOB_RECURSE btservice_source_files ${btservice_sources_directory}/*.cpp ${btservice_include_directory}/*.hpp ${autoapp_sources_directory}/Configuration/*.cpp ${autoapp_includes_directory}/Configuration/*.hpp ${common_include_directory}/*.hpp)
|
||||||
|
|
||||||
add_executable(btservice ${btservice_source_files})
|
add_executable(btservice ${btservice_source_files}
|
||||||
|
src/btservice/BluetoothHandler.cpp)
|
||||||
|
|
||||||
target_link_libraries(btservice PUBLIC
|
target_link_libraries(btservice PUBLIC
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
@ -162,11 +167,11 @@ target_link_libraries(btservice PUBLIC
|
|||||||
${PROTOBUF_LIBRARIES}
|
${PROTOBUF_LIBRARIES}
|
||||||
${AAP_PROTOBUF_LIB_DIR})
|
${AAP_PROTOBUF_LIB_DIR})
|
||||||
|
|
||||||
set_target_properties(openauto
|
set_target_properties(autoapp
|
||||||
PROPERTIES VERSION ${LIBRARY_VERSION_STRING} SOVERSION ${LIBRARY_BUILD_INCREMENTAL})
|
PROPERTIES VERSION ${PROGRAM_VERSION_STRING} SOVERSION ${OPENAUTO_BUILD_INCREMENTAL})
|
||||||
|
|
||||||
# Install rules
|
# Install rules
|
||||||
install(TARGETS openauto btservice
|
#install(TARGETS autoapp btservice
|
||||||
EXPORT aasdkTargets
|
# EXPORT aasdkTargets
|
||||||
RUNTIME DESTINATION bin
|
# RUNTIME DESTINATION bin
|
||||||
)
|
#)
|
18
RELEASE.txt
18
RELEASE.txt
@ -1,7 +1,15 @@
|
|||||||
Release Notes
|
Release Notes
|
||||||
|
|
||||||
20241121 - 4.0.0
|
20241124 - 4.1.0 - Bluetooth Updates
|
||||||
Added support for new services provided by AASDK and AAP Protocol version 1.6.
|
* Rename BluetootAdapterType to BluetoothAdapterType, and change from NONE, LOCAL, REMOTE to NONE, LOCAL, EXTERNAL to better match available settings
|
||||||
Add extensive logging
|
* getLocalAddress() on Dummy, Local and Remote bluetooth changed to getAdapterAddress()
|
||||||
Add logo for forked version
|
* Removed RemoteBluetoothDevice replacing all references with LocalBluetoothDevice. RemoteBluetoothDevice is a wrapper essentially with all pairing work handled by btservice.
|
||||||
Resolve display issue where if Raspberry Pi thinks both HDMI and LCD are enabled, the display width is appearing as two side by side monitors (double width) rather than just using the physical width of the screen.
|
* Pairing overlaps between btservice and LocalBluetoothDevice - removed duplicated elements from LocalBluetoothDevice to rely on btservice.
|
||||||
|
* Swap Bluetooth dropdown in Settings from none, builtin or external, to showing a list of detected Bluetooth Adapters. Write hardware address to config file.
|
||||||
|
|
||||||
|
20241121 - 4.0.0 - AAP 1.6 Support
|
||||||
|
* Added support for new services provided by AASDK and AAP Protocol version 1.6.
|
||||||
|
* Add extensive logging
|
||||||
|
* Add logo for forked version
|
||||||
|
* Resolve display issue where if Raspberry Pi thinks both HDMI and LCD are enabled, the display width is appearing as two side by side monitors (double width) rather than just using the physical width of the screen.
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ namespace f1x::openauto::btservice {
|
|||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void onClientConnected();
|
void onClientConnected();
|
||||||
|
void onError(QBluetoothServer::Error error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<QBluetoothServer> rfcommServer_;
|
std::unique_ptr<QBluetoothServer> rfcommServer_;
|
||||||
|
@ -27,9 +27,9 @@ namespace f1x::openauto::btservice
|
|||||||
class AndroidBluetoothService: public IAndroidBluetoothService
|
class AndroidBluetoothService: public IAndroidBluetoothService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AndroidBluetoothService(uint16_t portNumber);
|
AndroidBluetoothService();
|
||||||
|
|
||||||
bool registerService(const QBluetoothAddress& bluetoothAddress) override;
|
bool registerService(int16_t portNumber, const QBluetoothAddress& bluetoothAddress) override;
|
||||||
bool unregisterService() override;
|
bool unregisterService() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,16 +6,20 @@
|
|||||||
#define OPENAUTO_BLUETOOTHHANDLER_HPP
|
#define OPENAUTO_BLUETOOTHHANDLER_HPP
|
||||||
|
|
||||||
#include <f1x/openauto/btservice/IBluetoothHandler.hpp>
|
#include <f1x/openauto/btservice/IBluetoothHandler.hpp>
|
||||||
|
#include <f1x/openauto/btservice/IAndroidBluetoothServer.hpp>
|
||||||
|
#include <f1x/openauto/btservice/IAndroidBluetoothService.hpp>
|
||||||
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
namespace f1x::openauto::btservice {
|
namespace f1x::openauto::btservice {
|
||||||
|
|
||||||
class BluetoothHandler : public QObject, public IBluetoothHandler {
|
class BluetoothHandler : public QObject, public IBluetoothHandler {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BluetoothHandler(autoapp::configuration::IConfiguration::Pointer configuration);
|
BluetoothHandler(btservice::IAndroidBluetoothService::Pointer androidBluetoothService,
|
||||||
|
autoapp::configuration::IConfiguration::Pointer configuration);
|
||||||
|
|
||||||
|
void shutdownService() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin);
|
void onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin);
|
||||||
@ -28,9 +32,12 @@ namespace f1x::openauto::btservice {
|
|||||||
|
|
||||||
void onHostModeStateChanged(QBluetoothLocalDevice::HostMode state);
|
void onHostModeStateChanged(QBluetoothLocalDevice::HostMode state);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<QBluetoothLocalDevice> localDevice_;
|
std::unique_ptr<QBluetoothLocalDevice> localDevice_;
|
||||||
autoapp::configuration::IConfiguration::Pointer configuration_;
|
autoapp::configuration::IConfiguration::Pointer configuration_;
|
||||||
|
btservice::IAndroidBluetoothService::Pointer androidBluetoothService_;
|
||||||
|
btservice::IAndroidBluetoothServer::Pointer androidBluetoothServer_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,20 +18,19 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QBluetoothAddress>
|
#include <QBluetoothAddress>
|
||||||
|
|
||||||
|
namespace f1x::openauto::btservice {
|
||||||
|
|
||||||
|
class IAndroidBluetoothServer {
|
||||||
|
public:
|
||||||
|
typedef std::shared_ptr<IAndroidBluetoothServer> Pointer;
|
||||||
|
|
||||||
namespace f1x::openauto::btservice
|
|
||||||
{
|
|
||||||
|
|
||||||
class IAndroidBluetoothServer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IAndroidBluetoothServer() = default;
|
virtual ~IAndroidBluetoothServer() = default;
|
||||||
|
|
||||||
virtual uint16_t start(const QBluetoothAddress& address) = 0;
|
virtual uint16_t start(const QBluetoothAddress &address) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#include <QBluetoothAddress>
|
#include <QBluetoothAddress>
|
||||||
|
|
||||||
namespace f1x::openauto::btservice
|
namespace f1x::openauto::btservice
|
||||||
@ -26,10 +26,12 @@ namespace f1x::openauto::btservice
|
|||||||
class IAndroidBluetoothService
|
class IAndroidBluetoothService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IAndroidBluetoothService() = default;
|
typedef std::shared_ptr<IAndroidBluetoothService> Pointer;
|
||||||
|
|
||||||
virtual bool registerService(const QBluetoothAddress& bluetoothAddress) = 0;
|
virtual ~IAndroidBluetoothService() = default;
|
||||||
virtual bool unregisterService() = 0;
|
|
||||||
|
virtual bool registerService(int16_t portNumber, const QBluetoothAddress& bluetoothAddress) = 0;
|
||||||
|
virtual bool unregisterService() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef OPENAUTO_IBLUETOOTHHANDLER_HPP
|
#ifndef OPENAUTO_IBLUETOOTHHANDLER_HPP
|
||||||
#define OPENAUTO_IBLUETOOTHHANDLER_HPP
|
#define OPENAUTO_IBLUETOOTHHANDLER_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QBluetoothAddress>
|
#include <QBluetoothAddress>
|
||||||
#include <QBluetoothLocalDevice>
|
#include <QBluetoothLocalDevice>
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ namespace f1x::openauto::btservice {
|
|||||||
public:
|
public:
|
||||||
virtual ~IBluetoothHandler() = default;
|
virtual ~IBluetoothHandler() = default;
|
||||||
|
|
||||||
|
virtual void shutdownService() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,7 @@ namespace f1x::openauto::autoapp::service {
|
|||||||
std::move(guidanceAudioOutput)));
|
std::move(guidanceAudioOutput)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (configuration_->telephonyAudioChannelEnabled()) {
|
if (configuration_->telephonyAudioChannelEnabled()) {
|
||||||
OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled";
|
OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled";
|
||||||
auto telephonyAudioOutput =
|
auto telephonyAudioOutput =
|
||||||
@ -153,7 +154,7 @@ namespace f1x::openauto::autoapp::service {
|
|||||||
std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger,
|
std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger,
|
||||||
std::move(telephonyAudioOutput)));
|
std::move(telephonyAudioOutput)));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* No Need to Check for systemAudioChannelEnabled - MUST be enabled by default.
|
* No Need to Check for systemAudioChannelEnabled - MUST be enabled by default.
|
||||||
*/
|
*/
|
||||||
|
@ -39,22 +39,30 @@ namespace f1x::openauto::btservice {
|
|||||||
AndroidBluetoothServer::AndroidBluetoothServer(autoapp::configuration::IConfiguration::Pointer configuration)
|
AndroidBluetoothServer::AndroidBluetoothServer(autoapp::configuration::IConfiguration::Pointer configuration)
|
||||||
: rfcommServer_(std::make_unique<QBluetoothServer>(QBluetoothServiceInfo::RfcommProtocol, this)),
|
: rfcommServer_(std::make_unique<QBluetoothServer>(QBluetoothServiceInfo::RfcommProtocol, this)),
|
||||||
configuration_(std::move(configuration)) {
|
configuration_(std::move(configuration)) {
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer::AndroidBluetoothServer] Initialising";
|
||||||
|
|
||||||
connect(rfcommServer_.get(), &QBluetoothServer::newConnection, this,
|
connect(rfcommServer_.get(), &QBluetoothServer::newConnection, this,
|
||||||
&AndroidBluetoothServer::onClientConnected);
|
&AndroidBluetoothServer::onClientConnected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start Server listening on Address
|
/// Start Server listening on Address
|
||||||
uint16_t AndroidBluetoothServer::start(const QBluetoothAddress &address) {
|
uint16_t AndroidBluetoothServer::start(const QBluetoothAddress &address) {
|
||||||
OPENAUTO_LOG(debug) << "[AndroidBluetoothServer] start()";
|
OPENAUTO_LOG(debug) << "[AndroidBluetoothServer::start]";
|
||||||
if (rfcommServer_->listen(address)) {
|
if (rfcommServer_->listen(address)) {
|
||||||
|
|
||||||
return rfcommServer_->serverPort();
|
return rfcommServer_->serverPort();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AndroidBluetoothServer::onError(QBluetoothServer::Error error) {
|
||||||
|
OPENAUTO_LOG(debug) << "[AndroidBluetoothServer::onError]";
|
||||||
|
}
|
||||||
|
|
||||||
/// Call-Back for when Client Connected
|
/// Call-Back for when Client Connected
|
||||||
void AndroidBluetoothServer::onClientConnected() {
|
void AndroidBluetoothServer::onClientConnected() {
|
||||||
OPENAUTO_LOG(debug) << "[AndroidBluetoothServer] onClientConnected()";
|
OPENAUTO_LOG(debug) << "[AndroidBluetoothServer::onClientConnected]";
|
||||||
if (socket != nullptr) {
|
if (socket != nullptr) {
|
||||||
socket->deleteLater();
|
socket->deleteLater();
|
||||||
}
|
}
|
||||||
@ -159,8 +167,9 @@ namespace f1x::openauto::btservice {
|
|||||||
response.set_password(
|
response.set_password(
|
||||||
configuration_->getParamFromFile("/etc/hostapd/hostapd.conf", "wpa_passphrase").toStdString());
|
configuration_->getParamFromFile("/etc/hostapd/hostapd.conf", "wpa_passphrase").toStdString());
|
||||||
response.set_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
|
response.set_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
|
||||||
|
// TODO: AAP uses different values than WiFiProjection....
|
||||||
response.set_security_mode(
|
response.set_security_mode(
|
||||||
aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_PERSONAL);
|
aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_ENTERPRISE);
|
||||||
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
|
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
|
||||||
|
|
||||||
sendMessage(response, 3);
|
sendMessage(response, 3);
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <f1x/openauto/btservice/AndroidBluetoothService.hpp>
|
#include <f1x/openauto/btservice/AndroidBluetoothService.hpp>
|
||||||
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
|
||||||
namespace f1x::openauto::btservice {
|
namespace f1x::openauto::btservice {
|
||||||
|
|
||||||
AndroidBluetoothService::AndroidBluetoothService(uint16_t portNumber) {
|
AndroidBluetoothService::AndroidBluetoothService() {
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothService::AndroidBluetoothService] Initialising";
|
||||||
const QBluetoothUuid serviceUuid(QLatin1String("4de17a00-52cb-11e6-bdf4-0800200c9a66"));
|
const QBluetoothUuid serviceUuid(QLatin1String("4de17a00-52cb-11e6-bdf4-0800200c9a66"));
|
||||||
|
|
||||||
QBluetoothServiceInfo::Sequence classId;
|
QBluetoothServiceInfo::Sequence classId;
|
||||||
@ -36,6 +38,10 @@ namespace f1x::openauto::btservice {
|
|||||||
QBluetoothServiceInfo::Sequence publicBrowse;
|
QBluetoothServiceInfo::Sequence publicBrowse;
|
||||||
publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
|
publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
|
||||||
serviceInfo_.setAttribute(QBluetoothServiceInfo::BrowseGroupList, publicBrowse);
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::BrowseGroupList, publicBrowse);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AndroidBluetoothService::registerService(int16_t portNumber, const QBluetoothAddress &bluetoothAddress) {
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothService::registerService] Registering Service";
|
||||||
|
|
||||||
QBluetoothServiceInfo::Sequence protocolDescriptorList;
|
QBluetoothServiceInfo::Sequence protocolDescriptorList;
|
||||||
QBluetoothServiceInfo::Sequence protocol;
|
QBluetoothServiceInfo::Sequence protocol;
|
||||||
@ -46,13 +52,12 @@ namespace f1x::openauto::btservice {
|
|||||||
<< QVariant::fromValue(quint16(portNumber));
|
<< QVariant::fromValue(quint16(portNumber));
|
||||||
protocolDescriptorList.append(QVariant::fromValue(protocol));
|
protocolDescriptorList.append(QVariant::fromValue(protocol));
|
||||||
serviceInfo_.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList);
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList);
|
||||||
}
|
|
||||||
|
|
||||||
bool AndroidBluetoothService::registerService(const QBluetoothAddress &bluetoothAddress) {
|
|
||||||
return serviceInfo_.registerService(bluetoothAddress);
|
return serviceInfo_.registerService(bluetoothAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AndroidBluetoothService::unregisterService() {
|
bool AndroidBluetoothService::unregisterService() {
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothService::unregisterService] Unregistering";
|
||||||
return serviceInfo_.unregisterService();
|
return serviceInfo_.unregisterService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,11 @@
|
|||||||
#include <f1x/openauto/Common/Log.hpp>
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
|
||||||
namespace f1x::openauto::btservice {
|
namespace f1x::openauto::btservice {
|
||||||
BluetoothHandler::BluetoothHandler(autoapp::configuration::IConfiguration::Pointer configuration)
|
BluetoothHandler::BluetoothHandler(btservice::IAndroidBluetoothService::Pointer androidBluetoothService,
|
||||||
: configuration_(std::move(configuration)) {
|
autoapp::configuration::IConfiguration::Pointer configuration)
|
||||||
|
: configuration_(std::move(configuration)),
|
||||||
|
androidBluetoothService_(std::move(androidBluetoothService)),
|
||||||
|
androidBluetoothServer_(std::make_unique<btservice::AndroidBluetoothServer>(configuration_)) {
|
||||||
|
|
||||||
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Starting Up...";
|
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Starting Up...";
|
||||||
|
|
||||||
@ -35,8 +38,7 @@ namespace f1x::openauto::btservice {
|
|||||||
// Make it visible to others
|
// Make it visible to others
|
||||||
localDevice_->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
|
localDevice_->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
|
||||||
|
|
||||||
btservice::AndroidBluetoothServer androidBluetoothServer(configuration_);
|
uint16_t portNumber = androidBluetoothServer_->start(address);
|
||||||
uint16_t portNumber = androidBluetoothServer.start(address);
|
|
||||||
|
|
||||||
if (portNumber == 0) {
|
if (portNumber == 0) {
|
||||||
OPENAUTO_LOG(error) << "[BluetoothHandler::BluetoothHandler] Server start failed.";
|
OPENAUTO_LOG(error) << "[BluetoothHandler::BluetoothHandler] Server start failed.";
|
||||||
@ -46,15 +48,19 @@ namespace f1x::openauto::btservice {
|
|||||||
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Listening for connections, address: " << address.toString().toStdString()
|
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Listening for connections, address: " << address.toString().toStdString()
|
||||||
<< ", port: " << portNumber;
|
<< ", port: " << portNumber;
|
||||||
|
|
||||||
btservice::AndroidBluetoothService androidBluetoothService(portNumber);
|
if (!androidBluetoothService_->registerService(portNumber, address)) {
|
||||||
if (!androidBluetoothService.registerService(address)) {
|
|
||||||
OPENAUTO_LOG(error) << "[BluetoothHandler::BluetoothHandler] Service registration failed.";
|
OPENAUTO_LOG(error) << "[BluetoothHandler::BluetoothHandler] Service registration failed.";
|
||||||
throw std::runtime_error("Unable to register btservice");
|
throw std::runtime_error("Unable to register btservice");
|
||||||
} else {
|
} else {
|
||||||
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Service registered, port: " << portNumber;
|
OPENAUTO_LOG(info) << "[BluetoothHandler::BluetoothHandler] Service registered, port: " << portNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
androidBluetoothService.unregisterService();
|
// TODO: Connect to any previously paired devices
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothHandler::shutdownService() {
|
||||||
|
OPENAUTO_LOG(info) << "[BluetoothHandler::shutdownService] Shutdown initiated";
|
||||||
|
androidBluetoothService_->unregisterService();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothHandler::onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin) {
|
void BluetoothHandler::onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <f1x/openauto/Common/Log.hpp>
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
||||||
#include <f1x/openauto/btservice/BluetoothHandler.hpp>
|
#include <f1x/openauto/btservice/BluetoothHandler.hpp>
|
||||||
|
#include <f1x/openauto/btservice/AndroidBluetoothService.hpp>
|
||||||
|
|
||||||
namespace btservice = f1x::openauto::btservice;
|
namespace btservice = f1x::openauto::btservice;
|
||||||
|
|
||||||
@ -31,7 +32,8 @@ int main(int argc, char *argv[]) {
|
|||||||
auto configuration = std::make_shared<f1x::openauto::autoapp::configuration::Configuration>();
|
auto configuration = std::make_shared<f1x::openauto::autoapp::configuration::Configuration>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
btservice::BluetoothHandler bluetoothHandler(configuration);
|
auto androidBluetoothService = std::make_shared<btservice::AndroidBluetoothService>();
|
||||||
|
btservice::BluetoothHandler bluetoothHandler(androidBluetoothService, configuration);
|
||||||
QCoreApplication::exec();
|
QCoreApplication::exec();
|
||||||
} catch (std::runtime_error& e) {
|
} catch (std::runtime_error& e) {
|
||||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user