mirror of https://github.com/f1xpl/openauto.git
Merge branch 'feature/wireless' into development
commit
1a30e600e2
|
@ -62,10 +62,13 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
|
||||||
link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
set(autoapp_sources_directory ${sources_directory}/autoapp)
|
set(common_include_directory ${include_directory}/f1x/openauto/Common)
|
||||||
file(GLOB_RECURSE source_files ${autoapp_sources_directory}/*.ui ${autoapp_sources_directory}/*.cpp ${include_directory}/*.hpp ${resources_directory}/*.qrc)
|
|
||||||
|
|
||||||
add_executable(autoapp ${source_files})
|
set(autoapp_sources_directory ${sources_directory}/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)
|
||||||
|
|
||||||
|
add_executable(autoapp ${autoapp_source_files})
|
||||||
|
|
||||||
target_link_libraries(autoapp
|
target_link_libraries(autoapp
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
|
@ -79,3 +82,16 @@ target_link_libraries(autoapp
|
||||||
${WINSOCK2_LIBRARIES}
|
${WINSOCK2_LIBRARIES}
|
||||||
${AASDK_PROTO_LIBRARIES}
|
${AASDK_PROTO_LIBRARIES}
|
||||||
${AASDK_LIBRARIES})
|
${AASDK_LIBRARIES})
|
||||||
|
|
||||||
|
set(btservice_sources_directory ${sources_directory}/btservice)
|
||||||
|
set(btservice_include_directory ${include_directory}/f1x/openauto/btservice)
|
||||||
|
file(GLOB_RECURSE btservice_source_files ${btservice_sources_directory}/*.cpp ${btservice_include_directory}/*.hpp ${common_include_directory}/*.hpp)
|
||||||
|
|
||||||
|
add_executable(btservice ${btservice_source_files})
|
||||||
|
|
||||||
|
target_link_libraries(btservice
|
||||||
|
${Boost_LIBRARIES}
|
||||||
|
${Qt5Bluetooth_LIBRARIES}
|
||||||
|
${Qt5MultimediaWidgets_LIBRARIES}
|
||||||
|
${PROTOBUF_LIBRARIES}
|
||||||
|
${AASDK_PROTO_LIBRARIES})
|
||||||
|
|
|
@ -20,4 +20,4 @@
|
||||||
|
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
#define OPENAUTO_LOG(severity) BOOST_LOG_TRIVIAL(severity) << "[AaApp] "
|
#define OPENAUTO_LOG(severity) BOOST_LOG_TRIVIAL(severity) << "[OpenAuto] "
|
||||||
|
|
|
@ -29,23 +29,21 @@ namespace openauto
|
||||||
{
|
{
|
||||||
namespace autoapp
|
namespace autoapp
|
||||||
{
|
{
|
||||||
namespace usb
|
|
||||||
{
|
|
||||||
|
|
||||||
class USBApp: public projection::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this<USBApp>
|
class App: public projection::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this<App>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<USBApp> Pointer;
|
typedef std::shared_ptr<App> Pointer;
|
||||||
|
|
||||||
USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||||
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
|
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void onAndroidAutoQuit() override;
|
void onAndroidAutoQuit() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using std::enable_shared_from_this<USBApp>::shared_from_this;
|
using std::enable_shared_from_this<App>::shared_from_this;
|
||||||
|
|
||||||
void enumerateDevices();
|
void enumerateDevices();
|
||||||
void waitForDevice();
|
void waitForDevice();
|
||||||
|
@ -64,4 +62,3 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -18,12 +18,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <f1x/aasdk/USB/USBWrapper.hpp>
|
#include <f1x/aasdk/USB/USBWrapper.hpp>
|
||||||
#include <f1x/aasdk/USB/AccessoryModeQueryChain.hpp>
|
#include <f1x/aasdk/USB/AccessoryModeQueryChain.hpp>
|
||||||
#include <f1x/aasdk/USB/AccessoryModeQueryChainFactory.hpp>
|
#include <f1x/aasdk/USB/AccessoryModeQueryChainFactory.hpp>
|
||||||
#include <f1x/aasdk/USB/AccessoryModeQueryFactory.hpp>
|
#include <f1x/aasdk/USB/AccessoryModeQueryFactory.hpp>
|
||||||
#include <f1x/openauto/autoapp/USB/USBApp.hpp>
|
#include <f1x/openauto/autoapp/App.hpp>
|
||||||
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/ServiceFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/ServiceFactory.hpp>
|
||||||
|
@ -34,35 +33,25 @@ namespace openauto
|
||||||
{
|
{
|
||||||
namespace autoapp
|
namespace autoapp
|
||||||
{
|
{
|
||||||
namespace usb
|
|
||||||
{
|
|
||||||
|
|
||||||
class USBMain
|
class Main
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
USBMain(libusb_context* context);
|
Main(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration);
|
||||||
|
|
||||||
int exec(int argc, char* argv[]);
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<std::thread> ThreadPool;
|
aasdk::usb::IUSBWrapper& usbWrapper_;
|
||||||
|
boost::asio::io_service& ioService_;
|
||||||
void startUSBWorkers();
|
|
||||||
void startIOServiceWorkers();
|
|
||||||
|
|
||||||
libusb_context* usbContext_;
|
|
||||||
aasdk::usb::USBWrapper usbWrapper_;
|
|
||||||
boost::asio::io_service ioService_;
|
|
||||||
aasdk::usb::AccessoryModeQueryFactory queryFactory_;
|
aasdk::usb::AccessoryModeQueryFactory queryFactory_;
|
||||||
aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory_;
|
aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory_;
|
||||||
configuration::IConfiguration::Pointer configuration_;
|
|
||||||
projection::ServiceFactory serviceFactory_;
|
projection::ServiceFactory serviceFactory_;
|
||||||
projection::AndroidAutoEntityFactory androidAutoEntityFactory_;
|
projection::AndroidAutoEntityFactory androidAutoEntityFactory_;
|
||||||
autoapp::usb::USBApp::Pointer usbApp_;
|
autoapp::App::Pointer app_;
|
||||||
ThreadPool threadPool_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -19,6 +19,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
#include <f1x/aasdk/Transport/ITransport.hpp>
|
||||||
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/IServiceFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/IServiceFactory.hpp>
|
||||||
|
@ -41,8 +42,11 @@ public:
|
||||||
IServiceFactory& serviceFactory);
|
IServiceFactory& serviceFactory);
|
||||||
|
|
||||||
IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) override;
|
IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) override;
|
||||||
|
IAndroidAutoEntity::Pointer create(aasdk::tcp::ITCPEndpoint::Pointer tcpEndpoint) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
IAndroidAutoEntity::Pointer create(aasdk::transport::ITransport::Pointer transport);
|
||||||
|
|
||||||
aasdk::usb::IUSBWrapper& usbWrapper_;
|
aasdk::usb::IUSBWrapper& usbWrapper_;
|
||||||
boost::asio::io_service& ioService_;
|
boost::asio::io_service& ioService_;
|
||||||
configuration::IConfiguration::Pointer configuration_;
|
configuration::IConfiguration::Pointer configuration_;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <f1x/aasdk/TCP/ITCPEndpoint.hpp>
|
||||||
#include <f1x/aasdk/USB/USBWrapper.hpp>
|
#include <f1x/aasdk/USB/USBWrapper.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp>
|
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp>
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ public:
|
||||||
virtual ~IAndroidAutoEntityFactory() = default;
|
virtual ~IAndroidAutoEntityFactory() = default;
|
||||||
|
|
||||||
virtual IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) = 0;
|
virtual IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) = 0;
|
||||||
|
virtual IAndroidAutoEntity::Pointer create(aasdk::tcp::ITCPEndpoint::Pointer tcpEndpoint) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <QBluetoothServer>
|
||||||
|
#include <f1x/openauto/btservice/IAndroidBluetoothServer.hpp>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
class AndroidBluetoothServer: public QObject, public IAndroidBluetoothServer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AndroidBluetoothServer();
|
||||||
|
|
||||||
|
bool start(const QBluetoothAddress& address, uint16_t portNumber) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onClientConnected();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<QBluetoothServer> rfcommServer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QBluetoothServiceInfo>
|
||||||
|
#include <f1x/openauto/btservice/IAndroidBluetoothService.hpp>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
class AndroidBluetoothService: public IAndroidBluetoothService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AndroidBluetoothService(uint16_t portNumber);
|
||||||
|
|
||||||
|
bool registerService(const QBluetoothAddress& bluetoothAddress) override;
|
||||||
|
bool unregisterService() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QBluetoothServiceInfo serviceInfo_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QBluetoothAddress>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
class IAndroidBluetoothServer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IAndroidBluetoothServer() = default;
|
||||||
|
|
||||||
|
virtual bool start(const QBluetoothAddress& address, uint16_t portNumber) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QBluetoothAddress>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
class IAndroidBluetoothService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IAndroidBluetoothService() = default;
|
||||||
|
|
||||||
|
virtual bool registerService(const QBluetoothAddress& bluetoothAddress) = 0;
|
||||||
|
virtual bool unregisterService() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <f1x/openauto/autoapp/USB/USBApp.hpp>
|
#include <f1x/openauto/autoapp/App.hpp>
|
||||||
#include <f1x/openauto/Common/Log.hpp>
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
|
||||||
namespace f1x
|
namespace f1x
|
||||||
|
@ -26,11 +26,9 @@ namespace openauto
|
||||||
{
|
{
|
||||||
namespace autoapp
|
namespace autoapp
|
||||||
{
|
{
|
||||||
namespace usb
|
|
||||||
{
|
|
||||||
|
|
||||||
USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
App::App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||||
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
||||||
: ioService_(ioService)
|
: ioService_(ioService)
|
||||||
, strand_(ioService_)
|
, strand_(ioService_)
|
||||||
, androidAutoEntityFactory_(androidAutoEntityFactory)
|
, androidAutoEntityFactory_(androidAutoEntityFactory)
|
||||||
|
@ -41,7 +39,7 @@ USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntit
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::start()
|
void App::start()
|
||||||
{
|
{
|
||||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
this->waitForDevice();
|
this->waitForDevice();
|
||||||
|
@ -49,7 +47,7 @@ void USBApp::start()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::stop()
|
void App::stop()
|
||||||
{
|
{
|
||||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
isStopped_ = true;
|
isStopped_ = true;
|
||||||
|
@ -63,9 +61,9 @@ void USBApp::stop()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(info) << "[USBApp] Device connected.";
|
OPENAUTO_LOG(info) << "[App] Device connected.";
|
||||||
|
|
||||||
if(androidAutoEntity_ == nullptr)
|
if(androidAutoEntity_ == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +74,7 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||||
}
|
}
|
||||||
catch(const aasdk::error::Error& error)
|
catch(const aasdk::error::Error& error)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[USBApp] AndroidAutoEntity create error: " << error.what();
|
OPENAUTO_LOG(error) << "[App] AndroidAutoEntity create error: " << error.what();
|
||||||
|
|
||||||
androidAutoEntity_.reset();
|
androidAutoEntity_.reset();
|
||||||
this->waitForDevice();
|
this->waitForDevice();
|
||||||
|
@ -84,37 +82,37 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(warning) << "[USBApp] android auto entity is still running.";
|
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::enumerateDevices()
|
void App::enumerateDevices()
|
||||||
{
|
{
|
||||||
auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_);
|
auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_);
|
||||||
promise->then([this, self = this->shared_from_this()](auto result) {
|
promise->then([this, self = this->shared_from_this()](auto result) {
|
||||||
OPENAUTO_LOG(info) << "[USBApp] Devices enumeration result: " << result;
|
OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result;
|
||||||
},
|
},
|
||||||
[this, self = this->shared_from_this()](auto e) {
|
[this, self = this->shared_from_this()](auto e) {
|
||||||
OPENAUTO_LOG(error) << "[USBApp] Devices enumeration failed: " << e.what();
|
OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what();
|
||||||
});
|
});
|
||||||
|
|
||||||
connectedAccessoriesEnumerator_->enumerate(std::move(promise));
|
connectedAccessoriesEnumerator_->enumerate(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::waitForDevice()
|
void App::waitForDevice()
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(info) << "[USBApp] Waiting for device...";
|
OPENAUTO_LOG(info) << "[App] Waiting for device...";
|
||||||
|
|
||||||
auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_);
|
auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_);
|
||||||
promise->then(std::bind(&USBApp::aoapDeviceHandler, this->shared_from_this(), std::placeholders::_1),
|
promise->then(std::bind(&App::aoapDeviceHandler, this->shared_from_this(), std::placeholders::_1),
|
||||||
std::bind(&USBApp::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
|
std::bind(&App::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
|
||||||
usbHub_->start(std::move(promise));
|
usbHub_->start(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::onAndroidAutoQuit()
|
void App::onAndroidAutoQuit()
|
||||||
{
|
{
|
||||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
OPENAUTO_LOG(info) << "[USBApp] quit.";
|
OPENAUTO_LOG(info) << "[App] quit.";
|
||||||
|
|
||||||
androidAutoEntity_->stop();
|
androidAutoEntity_->stop();
|
||||||
androidAutoEntity_.reset();
|
androidAutoEntity_.reset();
|
||||||
|
@ -126,9 +124,9 @@ void USBApp::onAndroidAutoQuit()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBApp::onUSBHubError(const aasdk::error::Error& error)
|
void App::onUSBHubError(const aasdk::error::Error& error)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[USBApp] usb hub error: " << error.what();
|
OPENAUTO_LOG(error) << "[App] usb hub error: " << error.what();
|
||||||
|
|
||||||
if(error.getCode() == aasdk::error::ErrorCode::OPERATION_ABORTED ||
|
if(error.getCode() == aasdk::error::ErrorCode::OPERATION_ABORTED ||
|
||||||
error.getCode() == aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)
|
error.getCode() == aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)
|
||||||
|
@ -140,4 +138,3 @@ void USBApp::onUSBHubError(const aasdk::error::Error& error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -16,24 +16,43 @@
|
||||||
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
|
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <f1x/openauto/autoapp/USB/USBMain.hpp>
|
#include <QApplication>
|
||||||
#include <f1x/openauto/Common/Log.hpp>
|
#include <f1x/aasdk/USB/USBHub.hpp>
|
||||||
|
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
|
||||||
|
#include <f1x/openauto/autoapp/Main.hpp>
|
||||||
|
|
||||||
namespace aasdk = f1x::aasdk;
|
namespace f1x
|
||||||
namespace autoapp = f1x::openauto::autoapp;
|
{
|
||||||
|
namespace openauto
|
||||||
int main(int argc, char* argv[])
|
{
|
||||||
|
namespace autoapp
|
||||||
{
|
{
|
||||||
libusb_context* context;
|
|
||||||
if(libusb_init(&context) != 0)
|
|
||||||
{
|
|
||||||
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
autoapp::usb::USBMain main(context);
|
Main::Main(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration)
|
||||||
auto result = main.exec(argc, argv);
|
: usbWrapper_(usbWrapper)
|
||||||
|
, ioService_(ioService)
|
||||||
|
, queryFactory_(usbWrapper_, ioService_)
|
||||||
|
, queryChainFactory_(usbWrapper_, ioService_, queryFactory_)
|
||||||
|
, serviceFactory_(ioService_, configuration)
|
||||||
|
, androidAutoEntityFactory_(usbWrapper_, ioService_, configuration, serviceFactory_)
|
||||||
|
{
|
||||||
|
auto usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper_, ioService_, queryChainFactory_));
|
||||||
|
auto ConnectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper_, ioService_, queryChainFactory_));
|
||||||
|
|
||||||
libusb_exit(context);
|
app_ = std::make_shared<autoapp::App>(ioService_, androidAutoEntityFactory_,
|
||||||
return result;
|
std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Main::start()
|
||||||
|
{
|
||||||
|
app_->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Main::stop()
|
||||||
|
{
|
||||||
|
app_->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <f1x/aasdk/USB/AOAPDevice.hpp>
|
#include <f1x/aasdk/USB/AOAPDevice.hpp>
|
||||||
#include <f1x/aasdk/Transport/SSLWrapper.hpp>
|
#include <f1x/aasdk/Transport/SSLWrapper.hpp>
|
||||||
#include <f1x/aasdk/Transport/USBTransport.hpp>
|
#include <f1x/aasdk/Transport/USBTransport.hpp>
|
||||||
|
#include <f1x/aasdk/Transport/TCPTransport.hpp>
|
||||||
#include <f1x/aasdk/Messenger/Cryptor.hpp>
|
#include <f1x/aasdk/Messenger/Cryptor.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp>
|
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp>
|
||||||
|
@ -49,6 +50,17 @@ IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::usb::DeviceH
|
||||||
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
|
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
|
||||||
auto transport(std::make_shared<aasdk::transport::USBTransport>(ioService_, aoapDevice));
|
auto transport(std::make_shared<aasdk::transport::USBTransport>(ioService_, aoapDevice));
|
||||||
|
|
||||||
|
return create(std::move(transport));
|
||||||
|
}
|
||||||
|
|
||||||
|
IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::tcp::ITCPEndpoint::Pointer tcpEndpoint)
|
||||||
|
{
|
||||||
|
auto transport(std::make_shared<aasdk::transport::TCPTransport>(ioService_, std::move(tcpEndpoint)));
|
||||||
|
return create(std::move(transport));
|
||||||
|
}
|
||||||
|
|
||||||
|
IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::transport::ITransport::Pointer transport)
|
||||||
|
{
|
||||||
auto sslWrapper(std::make_shared<aasdk::transport::SSLWrapper>());
|
auto sslWrapper(std::make_shared<aasdk::transport::SSLWrapper>());
|
||||||
auto cryptor(std::make_shared<aasdk::messenger::Cryptor>(std::move(sslWrapper)));
|
auto cryptor(std::make_shared<aasdk::messenger::Cryptor>(std::move(sslWrapper)));
|
||||||
|
|
||||||
|
|
|
@ -1,118 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of openauto project.
|
|
||||||
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
|
||||||
*
|
|
||||||
* openauto 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.
|
|
||||||
|
|
||||||
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <f1x/aasdk/USB/USBHub.hpp>
|
|
||||||
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
|
|
||||||
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
|
||||||
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
|
|
||||||
#include <f1x/openauto/autoapp/UI/SettingsWindow.hpp>
|
|
||||||
#include <f1x/openauto/autoapp/USB/USBMain.hpp>
|
|
||||||
|
|
||||||
namespace f1x
|
|
||||||
{
|
|
||||||
namespace openauto
|
|
||||||
{
|
|
||||||
namespace autoapp
|
|
||||||
{
|
|
||||||
namespace usb
|
|
||||||
{
|
|
||||||
|
|
||||||
USBMain::USBMain(libusb_context* context)
|
|
||||||
: usbContext_(context)
|
|
||||||
, usbWrapper_(usbContext_)
|
|
||||||
, queryFactory_(usbWrapper_, ioService_)
|
|
||||||
, queryChainFactory_(usbWrapper_, ioService_, queryFactory_)
|
|
||||||
, configuration_(std::make_shared<configuration::Configuration>())
|
|
||||||
, serviceFactory_(ioService_, configuration_)
|
|
||||||
, androidAutoEntityFactory_(usbWrapper_, ioService_, configuration_, serviceFactory_)
|
|
||||||
{
|
|
||||||
auto usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper_, ioService_, queryChainFactory_));
|
|
||||||
auto ConnectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper_, ioService_, queryChainFactory_));
|
|
||||||
|
|
||||||
usbApp_ = std::make_shared<autoapp::usb::USBApp>(ioService_, androidAutoEntityFactory_,
|
|
||||||
std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
|
|
||||||
}
|
|
||||||
|
|
||||||
int USBMain::exec(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
QApplication qApplication(argc, argv);
|
|
||||||
|
|
||||||
ui::MainWindow mainWindow;
|
|
||||||
mainWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
|
|
||||||
|
|
||||||
ui::SettingsWindow settingsWindow(configuration_);
|
|
||||||
settingsWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
|
|
||||||
|
|
||||||
QObject::connect(&mainWindow, &ui::MainWindow::exit, []() { std::exit(0); });
|
|
||||||
QObject::connect(&mainWindow, &ui::MainWindow::openSettings, &settingsWindow, &ui::SettingsWindow::showFullScreen);
|
|
||||||
|
|
||||||
qApplication.setOverrideCursor(Qt::BlankCursor);
|
|
||||||
bool cursorVisible = false;
|
|
||||||
QObject::connect(&mainWindow, &ui::MainWindow::toggleCursor, [&cursorVisible, &qApplication]() {
|
|
||||||
cursorVisible = !cursorVisible;
|
|
||||||
qApplication.setOverrideCursor(cursorVisible ? Qt::ArrowCursor : Qt::BlankCursor);
|
|
||||||
});
|
|
||||||
|
|
||||||
mainWindow.showFullScreen();
|
|
||||||
|
|
||||||
boost::asio::io_service::work work(ioService_);
|
|
||||||
this->startIOServiceWorkers();
|
|
||||||
this->startUSBWorkers();
|
|
||||||
usbApp_->start();
|
|
||||||
|
|
||||||
auto result = qApplication.exec();
|
|
||||||
std::for_each(threadPool_.begin(), threadPool_.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void USBMain::startUSBWorkers()
|
|
||||||
{
|
|
||||||
auto usbWorker = [this]() {
|
|
||||||
timeval libusbEventTimeout{180, 0};
|
|
||||||
|
|
||||||
while(!ioService_.stopped())
|
|
||||||
{
|
|
||||||
libusb_handle_events_timeout_completed(usbContext_, &libusbEventTimeout, nullptr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threadPool_.emplace_back(usbWorker);
|
|
||||||
threadPool_.emplace_back(usbWorker);
|
|
||||||
threadPool_.emplace_back(usbWorker);
|
|
||||||
threadPool_.emplace_back(usbWorker);
|
|
||||||
}
|
|
||||||
|
|
||||||
void USBMain::startIOServiceWorkers()
|
|
||||||
{
|
|
||||||
auto ioServiceWorker = [this]() {
|
|
||||||
while(!ioService_.stopped())
|
|
||||||
{
|
|
||||||
ioService_.run();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threadPool_.emplace_back(ioServiceWorker);
|
|
||||||
threadPool_.emplace_back(ioServiceWorker);
|
|
||||||
threadPool_.emplace_back(ioServiceWorker);
|
|
||||||
threadPool_.emplace_back(ioServiceWorker);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
||||||
|
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
|
||||||
|
#include <f1x/openauto/autoapp/UI/SettingsWindow.hpp>
|
||||||
|
#include <f1x/openauto/autoapp/Main.hpp>
|
||||||
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
|
||||||
|
namespace aasdk = f1x::aasdk;
|
||||||
|
namespace autoapp = f1x::openauto::autoapp;
|
||||||
|
using ThreadPool = std::vector<std::thread>;
|
||||||
|
|
||||||
|
void startUSBWorkers(boost::asio::io_service& ioService, libusb_context* usbContext, ThreadPool& threadPool)
|
||||||
|
{
|
||||||
|
auto usbWorker = [&ioService, usbContext]() {
|
||||||
|
timeval libusbEventTimeout{180, 0};
|
||||||
|
|
||||||
|
while(!ioService.stopped())
|
||||||
|
{
|
||||||
|
libusb_handle_events_timeout_completed(usbContext, &libusbEventTimeout, nullptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
threadPool.emplace_back(usbWorker);
|
||||||
|
threadPool.emplace_back(usbWorker);
|
||||||
|
threadPool.emplace_back(usbWorker);
|
||||||
|
threadPool.emplace_back(usbWorker);
|
||||||
|
}
|
||||||
|
|
||||||
|
void startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threadPool)
|
||||||
|
{
|
||||||
|
auto ioServiceWorker = [&ioService]() {
|
||||||
|
ioService.run();
|
||||||
|
};
|
||||||
|
|
||||||
|
threadPool.emplace_back(ioServiceWorker);
|
||||||
|
threadPool.emplace_back(ioServiceWorker);
|
||||||
|
threadPool.emplace_back(ioServiceWorker);
|
||||||
|
threadPool.emplace_back(ioServiceWorker);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
libusb_context* usbContext;
|
||||||
|
if(libusb_init(&usbContext) != 0)
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication qApplication(argc, argv);
|
||||||
|
boost::asio::io_service ioService;
|
||||||
|
boost::asio::io_service::work work(ioService);
|
||||||
|
|
||||||
|
autoapp::ui::MainWindow mainWindow;
|
||||||
|
mainWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
|
||||||
|
mainWindow.showFullScreen();
|
||||||
|
|
||||||
|
auto configuration = std::make_shared<autoapp::configuration::Configuration>();
|
||||||
|
autoapp::ui::SettingsWindow settingsWindow(configuration);
|
||||||
|
settingsWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
|
||||||
|
|
||||||
|
qApplication.setOverrideCursor(Qt::BlankCursor);
|
||||||
|
bool cursorVisible = false;
|
||||||
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&cursorVisible, &qApplication]() {
|
||||||
|
cursorVisible = !cursorVisible;
|
||||||
|
qApplication.setOverrideCursor(cursorVisible ? Qt::ArrowCursor : Qt::BlankCursor);
|
||||||
|
});
|
||||||
|
|
||||||
|
aasdk::usb::USBWrapper usbWrapper(usbContext);
|
||||||
|
autoapp::Main main(usbWrapper, ioService, configuration);
|
||||||
|
|
||||||
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
|
||||||
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
|
||||||
|
|
||||||
|
std::vector<std::thread> threadPool;
|
||||||
|
startUSBWorkers(ioService, usbContext, threadPool);
|
||||||
|
startIOServiceWorkers(ioService, threadPool);
|
||||||
|
main.start();
|
||||||
|
|
||||||
|
auto result = qApplication.exec();
|
||||||
|
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
||||||
|
|
||||||
|
libusb_exit(usbContext);
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
#include <f1x/openauto/btservice/AndroidBluetoothServer.hpp>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
AndroidBluetoothServer::AndroidBluetoothServer()
|
||||||
|
: rfcommServer_(std::make_unique<QBluetoothServer>(QBluetoothServiceInfo::RfcommProtocol, this))
|
||||||
|
{
|
||||||
|
connect(rfcommServer_.get(), &QBluetoothServer::newConnection, this, &AndroidBluetoothServer::onClientConnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AndroidBluetoothServer::start(const QBluetoothAddress& address, uint16_t portNumber)
|
||||||
|
{
|
||||||
|
return rfcommServer_->listen(address, portNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AndroidBluetoothServer::onClientConnected()
|
||||||
|
{
|
||||||
|
auto socket = rfcommServer_->nextPendingConnection();
|
||||||
|
|
||||||
|
if(socket != nullptr)
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] rfcomm client connected, peer name: " << socket->peerName().toStdString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(error) << "[AndroidBluetoothServer] received null socket during client connection.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <f1x/openauto/btservice/AndroidBluetoothService.hpp>
|
||||||
|
|
||||||
|
namespace f1x
|
||||||
|
{
|
||||||
|
namespace openauto
|
||||||
|
{
|
||||||
|
namespace btservice
|
||||||
|
{
|
||||||
|
|
||||||
|
AndroidBluetoothService::AndroidBluetoothService(uint16_t portNumber)
|
||||||
|
{
|
||||||
|
//"4de17a00-52cb-11e6-bdf4-0800200c9a66";
|
||||||
|
//"669a0c20-0008-f4bd-e611-cb52007ae14d";
|
||||||
|
const QBluetoothUuid serviceUuid(QLatin1String("4de17a00-52cb-11e6-bdf4-0800200c9a66"));
|
||||||
|
|
||||||
|
QBluetoothServiceInfo::Sequence classId;
|
||||||
|
classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, classId);
|
||||||
|
classId.prepend(QVariant::fromValue(serviceUuid));
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceName, "OpenAuto Bluetooth Service");
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceDescription, "AndroidAuto WiFi projection automatic setup");
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceProvider, "f1xstudio.com");
|
||||||
|
serviceInfo_.setServiceUuid(serviceUuid);
|
||||||
|
|
||||||
|
QBluetoothServiceInfo::Sequence publicBrowse;
|
||||||
|
publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::BrowseGroupList, publicBrowse);
|
||||||
|
|
||||||
|
QBluetoothServiceInfo::Sequence protocolDescriptorList;
|
||||||
|
QBluetoothServiceInfo::Sequence protocol;
|
||||||
|
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
|
||||||
|
protocolDescriptorList.append(QVariant::fromValue(protocol));
|
||||||
|
protocol.clear();
|
||||||
|
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
|
||||||
|
<< QVariant::fromValue(quint16(portNumber));
|
||||||
|
protocolDescriptorList.append(QVariant::fromValue(protocol));
|
||||||
|
serviceInfo_.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AndroidBluetoothService::registerService(const QBluetoothAddress& bluetoothAddress)
|
||||||
|
{
|
||||||
|
return serviceInfo_.registerService(bluetoothAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AndroidBluetoothService::unregisterService()
|
||||||
|
{
|
||||||
|
return serviceInfo_.unregisterService();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* This file is part of openauto project.
|
||||||
|
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
|
||||||
|
*
|
||||||
|
* openauto 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.
|
||||||
|
|
||||||
|
* openauto 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 openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <f1x/openauto/Common/Log.hpp>
|
||||||
|
#include <f1x/openauto/btservice/AndroidBluetoothService.hpp>
|
||||||
|
#include <f1x/openauto/btservice/AndroidBluetoothServer.hpp>
|
||||||
|
|
||||||
|
namespace btservice = f1x::openauto::btservice;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
QApplication qApplication(argc, argv);
|
||||||
|
|
||||||
|
const QBluetoothAddress address;
|
||||||
|
const uint16_t portNumber = 5000;
|
||||||
|
|
||||||
|
btservice::AndroidBluetoothServer androidBluetoothServer;
|
||||||
|
if(!androidBluetoothServer.start(address, portNumber))
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(error) << "[btservice] Server start failed.";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString()
|
||||||
|
<< ", port: " << portNumber;
|
||||||
|
|
||||||
|
btservice::AndroidBluetoothService androidBluetoothService(portNumber);
|
||||||
|
if(!androidBluetoothService.registerService(address))
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(error) << "[btservice] Service registration failed.";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(info) << "[btservice] Service registered, port: " << portNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
qApplication.exec();
|
||||||
|
androidBluetoothService.unregisterService();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue