Reformat Code
This commit is contained in:
parent
7f38e16983
commit
478526b953
@ -18,17 +18,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace configuration
|
||||
{
|
||||
|
||||
enum class BluetoothAdapterType
|
||||
{
|
||||
namespace f1x::openauto::autoapp::configuration {
|
||||
|
||||
enum class BluetoothAdapterType {
|
||||
NONE,
|
||||
LOCAL,
|
||||
REMOTE
|
||||
@ -37,4 +30,6 @@ enum class BluetoothAdapterType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,13 +23,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace projection
|
||||
namespace f1x::openauto::autoapp::projection
|
||||
{
|
||||
|
||||
class LocalBluetoothDevice: public QObject, public IBluetoothDevice
|
||||
@ -37,7 +31,7 @@ class LocalBluetoothDevice: public QObject, public IBluetoothDevice
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LocalBluetoothDevice();
|
||||
LocalBluetoothDevice(const QString &adapterAddress = QString(), QObject *parent = nullptr);
|
||||
|
||||
void stop() override;
|
||||
bool isPaired(const std::string& address) const override;
|
||||
@ -68,6 +62,6 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -24,32 +24,29 @@
|
||||
#include <aap_protobuf/service/control/message/ServiceDiscoveryResponse.pb.h>
|
||||
#include <aap_protobuf/shared/MessageStatus.pb.h>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
|
||||
class IService
|
||||
{
|
||||
public:
|
||||
namespace f1x::openauto::autoapp::service {
|
||||
|
||||
class IService {
|
||||
public:
|
||||
typedef std::shared_ptr<IService> Pointer;
|
||||
|
||||
virtual ~IService() = default;
|
||||
|
||||
virtual void start() = 0;
|
||||
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual void pause() = 0;
|
||||
|
||||
virtual void resume() = 0;
|
||||
virtual void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse& response) = 0;
|
||||
};
|
||||
|
||||
typedef std::vector<IService::Pointer> ServiceList;
|
||||
virtual void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) = 0;
|
||||
};
|
||||
|
||||
typedef std::vector<IService::Pointer> ServiceList;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -26,60 +26,60 @@
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <aasdk/Messenger/IMessenger.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace sensor {
|
||||
class SensorService :
|
||||
public aasdk::channel::sensorsource::ISensorSourceServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<SensorService> {
|
||||
public:
|
||||
SensorService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger);
|
||||
|
||||
bool isNight = false;
|
||||
bool previous = false;
|
||||
bool stopPolling = false;
|
||||
namespace f1x::openauto::autoapp::service::sensor {
|
||||
class SensorService :
|
||||
public aasdk::channel::sensorsource::ISensorSourceServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<SensorService> {
|
||||
public:
|
||||
SensorService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger);
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void pause() override;
|
||||
void resume() override;
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
bool isNight = false;
|
||||
bool previous = false;
|
||||
bool stopPolling = false;
|
||||
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
void start() override;
|
||||
|
||||
void onSensorStartRequest(
|
||||
const aap_protobuf::service::sensorsource::message::SensorRequest &request) override;
|
||||
void stop() override;
|
||||
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
void pause() override;
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<SensorService>::shared_from_this;
|
||||
void resume() override;
|
||||
|
||||
void sendDrivingStatusUnrestricted();
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
|
||||
void sendNightData();
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
|
||||
void sendGPSLocationData();
|
||||
void onSensorStartRequest(
|
||||
const aap_protobuf::service::sensorsource::message::SensorRequest &request) override;
|
||||
|
||||
bool is_file_exist(const char *filename);
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
|
||||
void sensorPolling();
|
||||
private:
|
||||
using std::enable_shared_from_this<SensorService>::shared_from_this;
|
||||
|
||||
void sendDrivingStatusUnrestricted();
|
||||
|
||||
void sendNightData();
|
||||
|
||||
void sendGPSLocationData();
|
||||
|
||||
bool is_file_exist(const char *filename);
|
||||
|
||||
void sensorPolling();
|
||||
|
||||
bool firstRun = true;
|
||||
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::sensorsource::SensorSourceService::Pointer channel_;
|
||||
struct gps_data_t gpsData_;
|
||||
bool gpsEnabled_ = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bool firstRun = true;
|
||||
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::sensorsource::SensorSourceService::Pointer channel_;
|
||||
struct gps_data_t gpsData_;
|
||||
bool gpsEnabled_ = false;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -22,33 +22,26 @@
|
||||
#include <f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp>
|
||||
#include <f1x/openauto/autoapp/Service/IService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace f1x::openauto::autoapp::service {
|
||||
|
||||
class Service
|
||||
: public IService {
|
||||
public:
|
||||
Service(boost::asio::io_service &ioService);
|
||||
class Service
|
||||
: public IService {
|
||||
public:
|
||||
Service(boost::asio::io_service &ioService);
|
||||
|
||||
void start() override;
|
||||
void start() override;
|
||||
|
||||
void stop() override;
|
||||
void stop() override;
|
||||
|
||||
void pause() override;
|
||||
void pause() override;
|
||||
|
||||
void resume() override;
|
||||
void resume() override;
|
||||
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
boost::asio::io_service::strand strand_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -23,39 +23,39 @@
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <aasdk/Messenger/IMessenger.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace vendorextension {
|
||||
|
||||
class VendorExtensionService :
|
||||
public aasdk::channel::vendorextension::IVendorExtensionServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<VendorExtensionService> {
|
||||
public:
|
||||
VendorExtensionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
||||
namespace f1x::openauto::autoapp::service::vendorextension {
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void pause() override;
|
||||
void resume() override;
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
class VendorExtensionService :
|
||||
public aasdk::channel::vendorextension::IVendorExtensionServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<VendorExtensionService> {
|
||||
public:
|
||||
VendorExtensionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
||||
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
void start() override;
|
||||
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
void stop() override;
|
||||
|
||||
void pause() override;
|
||||
|
||||
void resume() override;
|
||||
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<VendorExtensionService>::shared_from_this;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::vendorextension::VendorExtensionService::Pointer channel_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<VendorExtensionService>::shared_from_this;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::vendorextension::VendorExtensionService::Pointer channel_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,41 +23,42 @@
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <aasdk/Messenger/IMessenger.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace wifiprojection {
|
||||
|
||||
class WifiProjectionService :
|
||||
public aasdk::channel::wifiprojection::IWifiProjectionServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<WifiProjectionService> {
|
||||
public:
|
||||
WifiProjectionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
||||
namespace f1x::openauto::autoapp::service::wifiprojection {
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void pause() override;
|
||||
void resume() override;
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
class WifiProjectionService :
|
||||
public aasdk::channel::wifiprojection::IWifiProjectionServiceEventHandler,
|
||||
public IService,
|
||||
public std::enable_shared_from_this<WifiProjectionService> {
|
||||
public:
|
||||
WifiProjectionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
||||
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
void start() override;
|
||||
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
void stop() override;
|
||||
|
||||
void pause() override;
|
||||
|
||||
void resume() override;
|
||||
|
||||
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
|
||||
|
||||
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
|
||||
|
||||
void onChannelError(const aasdk::error::Error &e) override;
|
||||
|
||||
void
|
||||
onWifiCredentialsRequest(
|
||||
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) override;
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<WifiProjectionService>::shared_from_this;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::wifiprojection::WifiProjectionService::Pointer channel_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
onWifiCredentialsRequest(const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) override;
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<WifiProjectionService>::shared_from_this;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
aasdk::channel::wifiprojection::WifiProjectionService::Pointer channel_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -35,13 +35,7 @@ namespace Ui
|
||||
class SettingsWindow;
|
||||
}
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace ui
|
||||
namespace f1x::openauto::autoapp::ui
|
||||
{
|
||||
|
||||
class SettingsWindow : public QWidget
|
||||
@ -112,6 +106,6 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,171 +22,145 @@
|
||||
#include <f1x/openauto/autoapp/App.hpp>
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace f1x::openauto::autoapp {
|
||||
|
||||
App::App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, service::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
||||
: ioService_(ioService)
|
||||
, usbWrapper_(usbWrapper)
|
||||
, tcpWrapper_(tcpWrapper)
|
||||
, strand_(ioService_)
|
||||
, androidAutoEntityFactory_(androidAutoEntityFactory)
|
||||
, usbHub_(std::move(usbHub))
|
||||
, connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator))
|
||||
, acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 5000 ))
|
||||
, isStopped_(false)
|
||||
{
|
||||
App::App(boost::asio::io_service &ioService, aasdk::usb::USBWrapper &usbWrapper, aasdk::tcp::ITCPWrapper &tcpWrapper,
|
||||
service::IAndroidAutoEntityFactory &androidAutoEntityFactory,
|
||||
aasdk::usb::IUSBHub::Pointer usbHub,
|
||||
aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
||||
: ioService_(ioService), usbWrapper_(usbWrapper), tcpWrapper_(tcpWrapper), strand_(ioService_),
|
||||
androidAutoEntityFactory_(androidAutoEntityFactory), usbHub_(std::move(usbHub)),
|
||||
connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator)),
|
||||
acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 5000)), isStopped_(false) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void App::waitForUSBDevice()
|
||||
{
|
||||
void App::waitForUSBDevice() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
try
|
||||
{
|
||||
this->waitForDevice();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() -exception caused by this->waitForDevice();";
|
||||
}
|
||||
try
|
||||
{
|
||||
this->enumerateDevices();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() exception caused by this->enumerateDevices()";
|
||||
}
|
||||
try {
|
||||
this->waitForDevice();
|
||||
}
|
||||
catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() -exception caused by this->waitForDevice();";
|
||||
}
|
||||
try {
|
||||
this->enumerateDevices();
|
||||
}
|
||||
catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() exception caused by this->enumerateDevices()";
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket)
|
||||
{
|
||||
void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket) {
|
||||
strand_.dispatch([this, self = this->shared_from_this(), socket = std::move(socket)]() mutable {
|
||||
OPENAUTO_LOG(info) << "Start from socket";
|
||||
if(androidAutoEntity_ != nullptr)
|
||||
{
|
||||
OPENAUTO_LOG(info) << "Start from socket";
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
// tcpWrapper_.close(*socket);
|
||||
// OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||
// return;
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// usbHub_->cancel();
|
||||
// connectedAccessoriesEnumerator_->cancel();
|
||||
|
||||
auto tcpEndpoint(std::make_shared<aasdk::tcp::TCPEndpoint>(tcpWrapper_, std::move(socket)));
|
||||
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint));
|
||||
androidAutoEntity_->start(*this);
|
||||
}
|
||||
catch(const aasdk::error::Error& error)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what();
|
||||
auto tcpEndpoint(std::make_shared<aasdk::tcp::TCPEndpoint>(tcpWrapper_, std::move(socket)));
|
||||
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint));
|
||||
androidAutoEntity_->start(*this);
|
||||
}
|
||||
catch (const aasdk::error::Error &error) {
|
||||
OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what();
|
||||
|
||||
//androidAutoEntity_.reset();
|
||||
this->waitForDevice();
|
||||
}
|
||||
//androidAutoEntity_.reset();
|
||||
this->waitForDevice();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::stop()
|
||||
{
|
||||
void App::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
isStopped_ = true;
|
||||
try {
|
||||
connectedAccessoriesEnumerator_->cancel();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by connectedAccessoriesEnumerator_->cancel()";
|
||||
}
|
||||
try {
|
||||
usbHub_->cancel();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by usbHub_->cancel();";
|
||||
}
|
||||
isStopped_ = true;
|
||||
try {
|
||||
connectedAccessoriesEnumerator_->cancel();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by connectedAccessoriesEnumerator_->cancel()";
|
||||
}
|
||||
try {
|
||||
usbHub_->cancel();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by usbHub_->cancel();";
|
||||
}
|
||||
|
||||
if(androidAutoEntity_ != nullptr)
|
||||
{
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||
{
|
||||
void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle) {
|
||||
OPENAUTO_LOG(info) << "[App] Device connected.";
|
||||
|
||||
if(androidAutoEntity_ != nullptr)
|
||||
{
|
||||
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||
return;
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// ignore autostart if exit to csng was used
|
||||
if (!disableAutostartEntity) {
|
||||
OPENAUTO_LOG(info) << "[App] Start Android Auto allowed - let's go.";
|
||||
connectedAccessoriesEnumerator_->cancel();
|
||||
try {
|
||||
// ignore autostart if exit to csng was used
|
||||
if (!disableAutostartEntity) {
|
||||
OPENAUTO_LOG(info) << "[App] Start Android Auto allowed - let's go.";
|
||||
connectedAccessoriesEnumerator_->cancel();
|
||||
|
||||
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
|
||||
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice));
|
||||
androidAutoEntity_->start(*this);
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[App] Start Android Auto not allowed - skip.";
|
||||
}
|
||||
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
|
||||
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice));
|
||||
androidAutoEntity_->start(*this);
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[App] Start Android Auto not allowed - skip.";
|
||||
}
|
||||
}
|
||||
catch(const aasdk::error::Error& error)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what();
|
||||
catch (const aasdk::error::Error &error) {
|
||||
OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what();
|
||||
|
||||
androidAutoEntity_.reset();
|
||||
this->waitForDevice();
|
||||
androidAutoEntity_.reset();
|
||||
this->waitForDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::enumerateDevices()
|
||||
{
|
||||
void App::enumerateDevices() {
|
||||
auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_);
|
||||
promise->then([this, self = this->shared_from_this()](auto result) {
|
||||
OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result;
|
||||
},
|
||||
[this, self = this->shared_from_this()](auto e) {
|
||||
OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what();
|
||||
});
|
||||
OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result;
|
||||
},
|
||||
[this, self = this->shared_from_this()](auto e) {
|
||||
OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what();
|
||||
});
|
||||
|
||||
connectedAccessoriesEnumerator_->enumerate(std::move(promise));
|
||||
}
|
||||
}
|
||||
|
||||
void App::waitForDevice()
|
||||
{
|
||||
void App::waitForDevice() {
|
||||
OPENAUTO_LOG(info) << "[App] Waiting for device...";
|
||||
|
||||
auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_);
|
||||
@ -194,80 +168,75 @@ void App::waitForDevice()
|
||||
std::bind(&App::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
|
||||
usbHub_->start(std::move(promise));
|
||||
startServerSocket();
|
||||
}
|
||||
}
|
||||
|
||||
void App::startServerSocket() {
|
||||
void App::startServerSocket() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "startServerSocket() - Listening for WIFI Clients on Port 5000";
|
||||
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
||||
acceptor_.async_accept(
|
||||
*socket,
|
||||
std::bind(&App::handleNewClient, this, socket, std::placeholders::_1)
|
||||
);
|
||||
OPENAUTO_LOG(info) << "startServerSocket() - Listening for WIFI Clients on Port 5000";
|
||||
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
||||
acceptor_.async_accept(
|
||||
*socket,
|
||||
std::bind(&App::handleNewClient, this, socket, std::placeholders::_1)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::handleNewClient(std::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code &err) {
|
||||
void
|
||||
App::handleNewClient(std::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code &err) {
|
||||
OPENAUTO_LOG(info) << "handleNewClient() - Handle WIFI Client Connection";
|
||||
if (!err) {
|
||||
start(std::move(socket));
|
||||
start(std::move(socket));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::pause()
|
||||
{
|
||||
void App::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[App] pause...";
|
||||
androidAutoEntity_->pause();
|
||||
OPENAUTO_LOG(info) << "[App] pause...";
|
||||
androidAutoEntity_->pause();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::resume()
|
||||
{
|
||||
void App::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
if(androidAutoEntity_ != nullptr)
|
||||
{
|
||||
OPENAUTO_LOG(info) << "[App] resume...";
|
||||
androidAutoEntity_->resume();
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[App] Ignore resume -> no androidAutoEntity_ ...";
|
||||
}
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
OPENAUTO_LOG(info) << "[App] resume...";
|
||||
androidAutoEntity_->resume();
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[App] Ignore resume -> no androidAutoEntity_ ...";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::onAndroidAutoQuit()
|
||||
{
|
||||
void App::onAndroidAutoQuit() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[App] onAndroidAutoQuit()";
|
||||
OPENAUTO_LOG(info) << "[App] onAndroidAutoQuit()";
|
||||
|
||||
//acceptor_.close();
|
||||
//acceptor_.close();
|
||||
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
if (androidAutoEntity_ != nullptr) {
|
||||
try {
|
||||
androidAutoEntity_->stop();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
|
||||
}
|
||||
|
||||
if(!isStopped_)
|
||||
{
|
||||
try {
|
||||
this->waitForDevice();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by this->waitForDevice();";
|
||||
}
|
||||
try {
|
||||
androidAutoEntity_.reset();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
|
||||
}
|
||||
}
|
||||
|
||||
if (!isStopped_) {
|
||||
try {
|
||||
this->waitForDevice();
|
||||
} catch (...) {
|
||||
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by this->waitForDevice();";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void App::onUSBHubError(const aasdk::error::Error& error)
|
||||
{
|
||||
void App::onUSBHubError(const aasdk::error::Error &error) {
|
||||
OPENAUTO_LOG(error) << "[App] onUSBHubError(): " << error.what();
|
||||
|
||||
// if(error != aasdk::error::ErrorCode::OPERATION_ABORTED &&
|
||||
@ -279,8 +248,8 @@ void App::onUSBHubError(const aasdk::error::Error& error)
|
||||
// OPENAUTO_LOG(error) << "[App] onUSBHubError: exception caused by this->waitForDevice();";
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,13 +20,10 @@
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
#include <QTouchDevice>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace configuration
|
||||
|
||||
|
||||
|
||||
namespace f1x::openauto::autoapp::configuration
|
||||
{
|
||||
|
||||
const std::string Configuration::cConfigFileName = "openauto.ini";
|
||||
@ -766,6 +763,6 @@ void Configuration::writeButtonCodes(boost::property_tree::ptree& iniConfig)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -18,13 +18,10 @@
|
||||
|
||||
#include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace projection
|
||||
|
||||
|
||||
|
||||
namespace f1x::openauto::autoapp::projection
|
||||
{
|
||||
|
||||
void DummyBluetoothDevice::stop()
|
||||
@ -53,6 +50,6 @@ bool DummyBluetoothDevice::isAvailable() const
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,14 +22,7 @@
|
||||
#include <QBluetoothUuid>
|
||||
#include <QtBluetooth>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace projection
|
||||
{
|
||||
namespace f1x::openauto::autoapp::projection {
|
||||
|
||||
LocalBluetoothDevice::LocalBluetoothDevice()
|
||||
{
|
||||
@ -183,7 +176,3 @@ void LocalBluetoothDevice::onHostModeStateChanged(QBluetoothLocalDevice::HostMod
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,50 +19,46 @@
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
#include <f1x/openauto/autoapp/Service/Bluetooth/BluetoothService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace bluetooth {
|
||||
namespace f1x::openauto::autoapp::service::bluetooth {
|
||||
|
||||
BluetoothService::BluetoothService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IBluetoothDevice::Pointer bluetoothDevice)
|
||||
: strand_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::bluetooth::BluetoothService>(strand_, std::move(messenger))),
|
||||
bluetoothDevice_(std::move(bluetoothDevice)) {
|
||||
BluetoothService::BluetoothService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IBluetoothDevice::Pointer bluetoothDevice)
|
||||
: strand_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::bluetooth::BluetoothService>(strand_, std::move(messenger))),
|
||||
bluetoothDevice_(std::move(bluetoothDevice)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
}
|
||||
void BluetoothService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
}
|
||||
|
||||
void BluetoothService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] stop()";
|
||||
bluetoothDevice_->stop();
|
||||
});
|
||||
}
|
||||
void BluetoothService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] stop()";
|
||||
bluetoothDevice_->stop();
|
||||
});
|
||||
}
|
||||
|
||||
void BluetoothService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] pause()";
|
||||
});
|
||||
}
|
||||
void BluetoothService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void BluetoothService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] resume()";
|
||||
});
|
||||
}
|
||||
void BluetoothService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void BluetoothService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] fillFeatures()";
|
||||
void BluetoothService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] fillFeatures()";
|
||||
|
||||
if (bluetoothDevice_->isAvailable()) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Local Address: " << bluetoothDevice_->getLocalAddress();
|
||||
@ -82,76 +78,81 @@ namespace f1x {
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[BluetoothService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
void
|
||||
BluetoothService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[BluetoothService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::onBluetoothPairingRequest(
|
||||
const aap_protobuf::service::bluetooth::message::BluetoothPairingRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothPairingRequest()";
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone Address: " << request.phone_address();
|
||||
|
||||
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
|
||||
|
||||
const auto isPaired = bluetoothDevice_->isPaired(request.phone_address());
|
||||
if (isPaired) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Already Paired";
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Not Paired";
|
||||
}
|
||||
|
||||
/*
|
||||
* The HU must always sent a STATUS_SUCCESS response,
|
||||
* or STATUS_BLUETOOTH_PAIRING_DELAYED if:
|
||||
* there's a delay in allowing bluetooth
|
||||
* the HU is already engaged in a bluetooth call
|
||||
*/
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
response.set_already_paired(isPaired);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then(std::bind(&BluetoothService::sendBluetoothAuthenticationData, this->shared_from_this()), std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendBluetoothPairingResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::sendBluetoothAuthenticationData() {
|
||||
aap_protobuf::service::bluetooth::message::BluetoothAuthenticationData data;
|
||||
data.set_auth_data("123456");
|
||||
data.set_pairing_method(aap_protobuf::service::bluetooth::message::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN);
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendBluetoothAuthenticationData(data, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::onBluetoothAuthenticationResult(const aap_protobuf::service::bluetooth::message::BluetoothAuthenticationResult &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothAuthenticationResult()";
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] AuthData " << request.status();
|
||||
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[BluetoothService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothService::onBluetoothPairingRequest(
|
||||
const aap_protobuf::service::bluetooth::message::BluetoothPairingRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothPairingRequest()";
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone Address: " << request.phone_address();
|
||||
|
||||
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
|
||||
|
||||
const auto isPaired = bluetoothDevice_->isPaired(request.phone_address());
|
||||
if (isPaired) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Already Paired";
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Not Paired";
|
||||
}
|
||||
|
||||
/*
|
||||
* The HU must always sent a STATUS_SUCCESS response,
|
||||
* or STATUS_BLUETOOTH_PAIRING_DELAYED if:
|
||||
* there's a delay in allowing bluetooth
|
||||
* the HU is already engaged in a bluetooth call
|
||||
*/
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
response.set_already_paired(isPaired);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then(std::bind(&BluetoothService::sendBluetoothAuthenticationData, this->shared_from_this()),
|
||||
std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendBluetoothPairingResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::sendBluetoothAuthenticationData() {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] sendBluetoothAuthenticationData()";
|
||||
|
||||
aap_protobuf::service::bluetooth::message::BluetoothAuthenticationData data;
|
||||
// TODO: Bluetooth Authentication Data
|
||||
data.set_auth_data("123456");
|
||||
data.set_pairing_method(aap_protobuf::service::bluetooth::message::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN);
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendBluetoothAuthenticationData(data, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::onBluetoothAuthenticationResult(
|
||||
const aap_protobuf::service::bluetooth::message::BluetoothAuthenticationResult &request) {
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothAuthenticationResult()";
|
||||
OPENAUTO_LOG(info) << "[BluetoothService] AuthData " << request.status();
|
||||
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void BluetoothService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[BluetoothService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,75 +21,73 @@
|
||||
#include <fstream>
|
||||
#include <QString>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace genericnotification {
|
||||
namespace f1x::openauto::autoapp::service::genericnotification {
|
||||
|
||||
GenericNotificationService::GenericNotificationService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::genericnotification::GenericNotificationService>(strand_, std::move(messenger))) {
|
||||
GenericNotificationService::GenericNotificationService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::genericnotification::GenericNotificationService>(strand_, std::move(
|
||||
messenger))) {
|
||||
|
||||
}
|
||||
|
||||
void GenericNotificationService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *genericNotification = service->mutable_wifi_projection_service();
|
||||
}
|
||||
|
||||
void GenericNotificationService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[GenericNotificationService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&GenericNotificationService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void GenericNotificationService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[GenericNotificationService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenericNotificationService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void GenericNotificationService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *genericNotification = service->mutable_wifi_projection_service();
|
||||
}
|
||||
|
||||
void GenericNotificationService::onChannelOpenRequest(
|
||||
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[GenericNotificationService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[GenericNotificationService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&GenericNotificationService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void GenericNotificationService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[GenericNotificationService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -18,26 +18,22 @@
|
||||
|
||||
#include <f1x/openauto/autoapp/Service/MediaSink/GuidanceAudioService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace mediasink {
|
||||
using f1x::openauto::autoapp::service::mediasink::GuidanceAudioService;
|
||||
using f1x::openauto::autoapp::service::mediasink::AudioMediaSinkService;
|
||||
using aasdk::channel::mediasink::audio::channel::GuidanceAudioChannel;
|
||||
|
||||
GuidanceAudioService::GuidanceAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(
|
||||
ioService,
|
||||
std::make_shared<GuidanceAudioChannel>(strand_, std::move(messenger)),
|
||||
std::move(audioOutput)) {
|
||||
namespace f1x::openauto::autoapp::service::mediasink {
|
||||
using f1x::openauto::autoapp::service::mediasink::GuidanceAudioService;
|
||||
using f1x::openauto::autoapp::service::mediasink::AudioMediaSinkService;
|
||||
using aasdk::channel::mediasink::audio::channel::GuidanceAudioChannel;
|
||||
|
||||
GuidanceAudioService::GuidanceAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(
|
||||
ioService,
|
||||
std::make_shared<GuidanceAudioChannel>(strand_, std::move(messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -19,24 +19,18 @@
|
||||
#include <f1x/openauto/autoapp/Service/MediaSink/MediaAudioService.hpp>
|
||||
|
||||
|
||||
namespace f1x::openauto::autoapp::service::mediasink {
|
||||
MediaAudioService::MediaAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(ioService,
|
||||
std::make_shared<aasdk::channel::mediasink::audio::channel::MediaAudioChannel>(strand_,
|
||||
std::move(
|
||||
messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace mediasink {
|
||||
MediaAudioService::MediaAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(ioService,
|
||||
std::make_shared<aasdk::channel::mediasink::audio::channel::MediaAudioChannel>(strand_,
|
||||
std::move(
|
||||
messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -19,23 +19,20 @@
|
||||
#include <aasdk/Channel/MediaSink/Audio/Channel/SystemAudioChannel.hpp>
|
||||
#include <f1x/openauto/autoapp/Service/MediaSink/SystemAudioService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace mediasink {
|
||||
SystemAudioService::SystemAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(ioService,
|
||||
std::make_shared<aasdk::channel::mediasink::audio::channel::SystemAudioChannel>(strand_,
|
||||
std::move(messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
}
|
||||
namespace f1x::openauto::autoapp::service::mediasink {
|
||||
SystemAudioService::SystemAudioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioOutput::Pointer audioOutput)
|
||||
: AudioMediaSinkService(ioService,
|
||||
std::make_shared<aasdk::channel::mediasink::audio::channel::SystemAudioChannel>(strand_,
|
||||
std::move(
|
||||
messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -16,256 +16,258 @@
|
||||
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
#include <f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace mediasource {
|
||||
|
||||
MediaSourceService::MediaSourceService(boost::asio::io_service &ioService,
|
||||
aasdk::channel::mediasource::IMediaSourceService::Pointer channel,
|
||||
projection::IAudioInput::Pointer audioInput)
|
||||
: strand_(ioService), channel_(std::move(channel)), audioInput_(std::move(audioInput)), session_(-1) {
|
||||
namespace f1x::openauto::autoapp::service::mediasource {
|
||||
|
||||
}
|
||||
MediaSourceService::MediaSourceService(boost::asio::io_service &ioService,
|
||||
aasdk::channel::mediasource::IMediaSourceService::Pointer channel,
|
||||
projection::IAudioInput::Pointer audioInput)
|
||||
: strand_(ioService), channel_(std::move(channel)), audioInput_(std::move(audioInput)), session_(-1) {
|
||||
|
||||
void MediaSourceService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void MediaSourceService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] stop()";
|
||||
audioInput_->stop();
|
||||
});
|
||||
}
|
||||
void MediaSourceService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
}
|
||||
|
||||
void MediaSourceService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] pause()";
|
||||
});
|
||||
}
|
||||
void MediaSourceService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] stop()";
|
||||
audioInput_->stop();
|
||||
});
|
||||
}
|
||||
|
||||
void MediaSourceService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] resume()";
|
||||
});
|
||||
}
|
||||
void MediaSourceService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Service Discovery
|
||||
*/
|
||||
void MediaSourceService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill Features of Service
|
||||
* @param response
|
||||
*/
|
||||
void MediaSourceService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] fillFeatures()";
|
||||
/*
|
||||
* Service Discovery
|
||||
*/
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
/**
|
||||
* Fill Features of Service
|
||||
* @param response
|
||||
*/
|
||||
void MediaSourceService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] fillFeatures()";
|
||||
|
||||
auto *avInputChannel = service->mutable_media_source_service();
|
||||
avInputChannel->set_available_type(
|
||||
aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM);
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto audioConfig = avInputChannel->mutable_audio_config();
|
||||
audioConfig->set_sampling_rate(audioInput_->getSampleRate());
|
||||
audioConfig->set_number_of_bits(audioInput_->getSampleSize());
|
||||
audioConfig->set_number_of_channels(audioInput_->getChannelCount());
|
||||
}
|
||||
auto *avInputChannel = service->mutable_media_source_service();
|
||||
avInputChannel->set_available_type(
|
||||
aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM);
|
||||
|
||||
/*
|
||||
* Base Channel Handling
|
||||
*/
|
||||
auto audioConfig = avInputChannel->mutable_audio_config();
|
||||
audioConfig->set_sampling_rate(audioInput_->getSampleRate());
|
||||
audioConfig->set_number_of_bits(audioInput_->getSampleSize());
|
||||
audioConfig->set_number_of_channels(audioInput_->getChannelCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Service Channel Request
|
||||
* @param request
|
||||
*/
|
||||
void MediaSourceService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
/*
|
||||
* Base Channel Handling
|
||||
*/
|
||||
|
||||
const aap_protobuf::shared::MessageStatus status = audioInput_->open()
|
||||
? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS
|
||||
: aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR;
|
||||
/**
|
||||
* Open Service Channel Request
|
||||
* @param request
|
||||
*/
|
||||
void
|
||||
MediaSourceService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Status determined: " << aap_protobuf::shared::MessageStatus_Name(status);
|
||||
const aap_protobuf::shared::MessageStatus status = audioInput_->open()
|
||||
? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS
|
||||
: aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR;
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
response.set_status(status);
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Status determined: "
|
||||
<< aap_protobuf::shared::MessageStatus_Name(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
response.set_status(status);
|
||||
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
|
||||
/**
|
||||
* Generic Channel Error
|
||||
* @param e
|
||||
*/
|
||||
void MediaSourceService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onChannelError(): " << e.what();
|
||||
}
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
/*
|
||||
* Media Channel Handling
|
||||
*/
|
||||
/**
|
||||
* Generic Channel Error
|
||||
* @param e
|
||||
*/
|
||||
void MediaSourceService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Media Channel Setup Request
|
||||
* @param request
|
||||
*/
|
||||
void
|
||||
MediaSourceService::onMediaChannelSetupRequest(const aap_protobuf::service::media::shared::message::Setup &request) {
|
||||
/*
|
||||
* Media Channel Handling
|
||||
*/
|
||||
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelSetupRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", Codec: " << MediaCodecType_Name(request.type());
|
||||
/**
|
||||
* Generic Media Channel Setup Request
|
||||
* @param request
|
||||
*/
|
||||
void
|
||||
MediaSourceService::onMediaChannelSetupRequest(const aap_protobuf::service::media::shared::message::Setup &request) {
|
||||
|
||||
aap_protobuf::service::media::shared::message::Config response;
|
||||
auto status = aap_protobuf::service::media::shared::message::Config::STATUS_READY;
|
||||
response.set_status(status);
|
||||
response.set_max_unacked(1);
|
||||
response.add_configuration_indices(0);
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelSetupRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId())
|
||||
<< ", Codec: " << MediaCodecType_Name(request.type());
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
aap_protobuf::service::media::shared::message::Config response;
|
||||
auto status = aap_protobuf::service::media::shared::message::Config::STATUS_READY;
|
||||
response.set_status(status);
|
||||
response.set_max_unacked(1);
|
||||
response.add_configuration_indices(0);
|
||||
|
||||
promise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelSetupResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
|
||||
/**
|
||||
* Generic Media Ack
|
||||
*/
|
||||
void MediaSourceService::onMediaChannelAckIndication(
|
||||
const aap_protobuf::service::media::source::message::Ack &) {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] onMediaChannelAckIndication()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
promise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelSetupResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
/*
|
||||
* Source Media Channel Handling
|
||||
*/
|
||||
/**
|
||||
* Generic Media Ack
|
||||
*/
|
||||
void MediaSourceService::onMediaChannelAckIndication(
|
||||
const aap_protobuf::service::media::source::message::Ack &) {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] onMediaChannelAckIndication()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle request to Open or Close Microphone Source Channel
|
||||
* @param request
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceOpenRequest(
|
||||
const aap_protobuf::service::media::source::message::MicrophoneRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaSourceOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Request to Open?: " << request.open() << ", anc: " << request.anc_enabled() << ", ec: " << request.ec_enabled() << ", max unacked: " << request.max_unacked();
|
||||
/*
|
||||
* Source Media Channel Handling
|
||||
*/
|
||||
|
||||
if (request.open()) {
|
||||
// Request for Channel Open
|
||||
auto startPromise = projection::IAudioInput::StartPromise::defer(strand_);
|
||||
startPromise->then(std::bind(&MediaSourceService::onMediaSourceOpenSuccess, this->shared_from_this()),
|
||||
[this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] Media Source Open Failed";
|
||||
/**
|
||||
* Handle request to Open or Close Microphone Source Channel
|
||||
* @param request
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceOpenRequest(
|
||||
const aap_protobuf::service::media::source::message::MicrophoneRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaSourceOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[MediaSourceService] Request to Open?: " << request.open() << ", anc: "
|
||||
<< request.anc_enabled() << ", ec: " << request.ec_enabled() << ", max unacked: "
|
||||
<< request.max_unacked();
|
||||
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
if (request.open()) {
|
||||
// Request for Channel Open
|
||||
auto startPromise = projection::IAudioInput::StartPromise::defer(strand_);
|
||||
startPromise->then(std::bind(&MediaSourceService::onMediaSourceOpenSuccess, this->shared_from_this()),
|
||||
[this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] Media Source Open Failed";
|
||||
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR);
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {},
|
||||
std::bind(&MediaSourceService::onChannelError,
|
||||
this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
});
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR);
|
||||
|
||||
audioInput_->start(std::move(startPromise));
|
||||
} else {
|
||||
// Request for Channel Close
|
||||
audioInput_->stop();
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {},
|
||||
std::bind(&MediaSourceService::onChannelError,
|
||||
this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
});
|
||||
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
audioInput_->start(std::move(startPromise));
|
||||
} else {
|
||||
// Request for Channel Close
|
||||
audioInput_->stop();
|
||||
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
}
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
}
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends response to advise Microphone is Open
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceOpenSuccess() {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceOpenSuccess()";
|
||||
/**
|
||||
* Sends response to advise Microphone is Open
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceOpenSuccess() {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceOpenSuccess()";
|
||||
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
aap_protobuf::service::media::source::message::MicrophoneResponse response;
|
||||
response.set_session_id(session_);
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
|
||||
|
||||
this->readMediaSource();
|
||||
}
|
||||
this->readMediaSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves promise from readMediaSource. Sends Media with Timestamp Indication to channel.
|
||||
* @param data
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceDataReady(aasdk::common::Data data) {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceDataReady()";
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then(std::bind(&MediaSourceService::readMediaSource, this->shared_from_this()),
|
||||
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
/**
|
||||
* Resolves promise from readMediaSource. Sends Media with Timestamp Indication to channel.
|
||||
* @param data
|
||||
*/
|
||||
void MediaSourceService::onMediaSourceDataReady(aasdk::common::Data data) {
|
||||
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceDataReady()";
|
||||
auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
|
||||
sendPromise->then(std::bind(&MediaSourceService::readMediaSource, this->shared_from_this()),
|
||||
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
|
||||
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch());
|
||||
channel_->sendMediaSourceWithTimestampIndication(timestamp.count(), std::move(data), std::move(sendPromise));
|
||||
}
|
||||
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch());
|
||||
channel_->sendMediaSourceWithTimestampIndication(timestamp.count(), std::move(data), std::move(sendPromise));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads audio from a MediaSource (eg Microphone). Promise resolves to onMediaSourceDataReady.
|
||||
*/
|
||||
void MediaSourceService::readMediaSource() {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] readMediaSource()";
|
||||
if (audioInput_->isActive()) {
|
||||
auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_);
|
||||
readPromise->then(
|
||||
std::bind(&MediaSourceService::onMediaSourceDataReady, this->shared_from_this(),
|
||||
std::placeholders::_1),
|
||||
[this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] audio input read rejected.";
|
||||
});
|
||||
/**
|
||||
* Reads audio from a MediaSource (eg Microphone). Promise resolves to onMediaSourceDataReady.
|
||||
*/
|
||||
void MediaSourceService::readMediaSource() {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] readMediaSource()";
|
||||
if (audioInput_->isActive()) {
|
||||
auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_);
|
||||
readPromise->then(
|
||||
std::bind(&MediaSourceService::onMediaSourceDataReady, this->shared_from_this(),
|
||||
std::placeholders::_1),
|
||||
[this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[MediaSourceService] audio input read rejected.";
|
||||
});
|
||||
|
||||
audioInput_->read(std::move(readPromise));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
audioInput_->read(std::move(readPromise));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,22 +19,18 @@
|
||||
#include <aasdk/Channel/MediaSource/Audio/MicrophoneAudioChannel.hpp>
|
||||
#include <f1x/openauto/autoapp/Service/MediaSource/MicrophoneMediaSourceService.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace mediasource {
|
||||
MicrophoneMediaSourceService::MicrophoneMediaSourceService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioInput::Pointer audioOutput)
|
||||
: MediaSourceService(ioService, std::make_shared<aasdk::channel::mediasource::audio::MicrophoneAudioChannel>(strand_,
|
||||
std::move(
|
||||
messenger)),
|
||||
std::move(audioOutput)) {
|
||||
namespace f1x::openauto::autoapp::service::mediasource {
|
||||
MicrophoneMediaSourceService::MicrophoneMediaSourceService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger,
|
||||
projection::IAudioInput::Pointer audioOutput)
|
||||
: MediaSourceService(ioService,
|
||||
std::make_shared<aasdk::channel::mediasource::audio::MicrophoneAudioChannel>(strand_,
|
||||
std::move(
|
||||
messenger)),
|
||||
std::move(audioOutput)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,89 +21,90 @@
|
||||
#include <fstream>
|
||||
#include <QString>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace navigationstatus {
|
||||
namespace f1x::openauto::autoapp::service::navigationstatus {
|
||||
|
||||
NavigationStatusService::NavigationStatusService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::navigationstatus::NavigationStatusService>(strand_, std::move(messenger))) {
|
||||
NavigationStatusService::NavigationStatusService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::navigationstatus::NavigationStatusService>(strand_,
|
||||
std::move(messenger))) {
|
||||
|
||||
}
|
||||
|
||||
void NavigationStatusService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *navigationStatus = service->mutable_navigation_status_service();
|
||||
}
|
||||
|
||||
void NavigationStatusService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&NavigationStatusService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void NavigationStatusService::onStatusUpdate(const aap_protobuf::service::navigationstatus::message::NavigationStatus &navStatus) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
void NavigationStatusService::onTurnEvent(const aap_protobuf::service::navigationstatus::message::NavigationNextTurnEvent &turnEvent) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void NavigationStatusService::onDistanceEvent(const aap_protobuf::service::navigationstatus::message::NavigationNextTurnDistanceEvent &distanceEvent) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
void NavigationStatusService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[NavigationStatusService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationStatusService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void NavigationStatusService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *navigationStatus = service->mutable_navigation_status_service();
|
||||
}
|
||||
|
||||
void NavigationStatusService::onChannelOpenRequest(
|
||||
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[NavigationStatusService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&NavigationStatusService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void NavigationStatusService::onStatusUpdate(
|
||||
const aap_protobuf::service::navigationstatus::message::NavigationStatus &navStatus) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
void NavigationStatusService::onTurnEvent(
|
||||
const aap_protobuf::service::navigationstatus::message::NavigationNextTurnEvent &turnEvent) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void NavigationStatusService::onDistanceEvent(
|
||||
const aap_protobuf::service::navigationstatus::message::NavigationNextTurnDistanceEvent &distanceEvent) {
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
void NavigationStatusService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[NavigationStatusService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -19,86 +19,60 @@
|
||||
#include <f1x/openauto/autoapp/Service/Pinger.hpp>
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
namespace f1x::openauto::autoapp::service {
|
||||
|
||||
Pinger::Pinger(boost::asio::io_service& ioService, time_t duration)
|
||||
: strand_(ioService)
|
||||
, timer_(ioService)
|
||||
, duration_(duration)
|
||||
, cancelled_(false)
|
||||
, pingsCount_(0)
|
||||
, pongsCount_(0)
|
||||
{
|
||||
Pinger::Pinger(boost::asio::io_service &ioService, time_t duration)
|
||||
: strand_(ioService), timer_(ioService), duration_(duration), cancelled_(false), pingsCount_(0), pongsCount_(0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Pinger::ping(Promise::Pointer promise)
|
||||
{
|
||||
void Pinger::ping(Promise::Pointer promise) {
|
||||
strand_.dispatch([this, self = this->shared_from_this(), promise = std::move(promise)]() mutable {
|
||||
cancelled_ = false;
|
||||
cancelled_ = false;
|
||||
|
||||
if(promise_ != nullptr)
|
||||
{
|
||||
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_IN_PROGRESS));
|
||||
}
|
||||
else
|
||||
{
|
||||
++pingsCount_;
|
||||
OPENAUTO_LOG(debug) << "[Pinger] Ping counter: " << pingsCount_;
|
||||
if (promise_ != nullptr) {
|
||||
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_IN_PROGRESS));
|
||||
} else {
|
||||
++pingsCount_;
|
||||
OPENAUTO_LOG(debug) << "[Pinger] Ping counter: " << pingsCount_;
|
||||
|
||||
promise_ = std::move(promise);
|
||||
timer_.expires_from_now(boost::posix_time::milliseconds(duration_));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1)));
|
||||
}
|
||||
promise_ = std::move(promise);
|
||||
timer_.expires_from_now(boost::posix_time::milliseconds(duration_));
|
||||
timer_.async_wait(
|
||||
strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Pinger::pong()
|
||||
{
|
||||
void Pinger::pong() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
++pongsCount_;
|
||||
OPENAUTO_LOG(debug) << "[Pinger] Pong counter: " << pongsCount_;
|
||||
++pongsCount_;
|
||||
OPENAUTO_LOG(debug) << "[Pinger] Pong counter: " << pongsCount_;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Pinger::onTimerExceeded(const boost::system::error_code& error)
|
||||
{
|
||||
if(promise_ == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(error == boost::asio::error::operation_aborted || cancelled_)
|
||||
{
|
||||
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_ABORTED));
|
||||
}
|
||||
else if(pingsCount_ - pongsCount_ > 4)
|
||||
{
|
||||
promise_->reject(aasdk::error::Error());
|
||||
}
|
||||
else
|
||||
{
|
||||
promise_->resolve();
|
||||
void Pinger::onTimerExceeded(const boost::system::error_code &error) {
|
||||
if (promise_ == nullptr) {
|
||||
return;
|
||||
} else if (error == boost::asio::error::operation_aborted || cancelled_) {
|
||||
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_ABORTED));
|
||||
} else if (pingsCount_ - pongsCount_ > 4) {
|
||||
promise_->reject(aasdk::error::Error());
|
||||
} else {
|
||||
promise_->resolve();
|
||||
}
|
||||
|
||||
promise_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Pinger::cancel()
|
||||
{
|
||||
void Pinger::cancel() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
cancelled_ = true;
|
||||
timer_.cancel();
|
||||
cancelled_ = true;
|
||||
timer_.cancel();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,78 +21,74 @@
|
||||
#include <fstream>
|
||||
#include <QString>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace radio {
|
||||
namespace f1x::openauto::autoapp::service::radio {
|
||||
|
||||
RadioService::RadioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::radio::RadioService>(strand_, std::move(messenger))) {
|
||||
RadioService::RadioService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::radio::RadioService>(strand_, std::move(messenger))) {
|
||||
|
||||
}
|
||||
|
||||
void RadioService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[RadioService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *radio = service->mutable_radio_service();
|
||||
}
|
||||
|
||||
void RadioService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[RadioService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[RadioService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&RadioService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void RadioService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[RadioService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RadioService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(debug) << "[RadioService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void RadioService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[RadioService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *radio = service->mutable_radio_service();
|
||||
}
|
||||
|
||||
void RadioService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[RadioService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[RadioService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&RadioService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void RadioService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[RadioService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -23,230 +23,224 @@
|
||||
#include <cmath>
|
||||
#include <gps.h>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace sensor {
|
||||
SensorService::SensorService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::sensorsource::SensorSourceService>(strand_, std::move(messenger))) {
|
||||
namespace f1x::openauto::autoapp::service::sensor {
|
||||
SensorService::SensorService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::sensorsource::SensorSourceService>(strand_, std::move(messenger))) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SensorService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
if (gps_open("127.0.0.1", "2947", &this->gpsData_)) {
|
||||
OPENAUTO_LOG(warning) << "[SensorService] can't connect to GPSD.";
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Connected to GPSD.";
|
||||
gps_stream(&this->gpsData_, WATCH_ENABLE | WATCH_JSON, NULL);
|
||||
this->gpsEnabled_ = true;
|
||||
}
|
||||
|
||||
if (is_file_exist("/tmp/night_mode_enabled")) {
|
||||
this->isNight = true;
|
||||
}
|
||||
this->sensorPolling();
|
||||
|
||||
OPENAUTO_LOG(info) << "[SensorService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void SensorService::stop() {
|
||||
this->stopPolling = true;
|
||||
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
if (this->gpsEnabled_) {
|
||||
gps_stream(&this->gpsData_, WATCH_DISABLE, NULL);
|
||||
gps_close(&this->gpsData_);
|
||||
this->gpsEnabled_ = false;
|
||||
}
|
||||
|
||||
OPENAUTO_LOG(info) << "[SensorService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *sensorChannel = service->mutable_sensor_source_service();
|
||||
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_DRIVING_STATUS_DATA);
|
||||
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_LOCATION);
|
||||
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE);
|
||||
}
|
||||
|
||||
void SensorService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[SensorService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void SensorService::onSensorStartRequest(
|
||||
const aap_protobuf::service::sensorsource::message::SensorRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] onSensorStartRequest()";
|
||||
OPENAUTO_LOG(debug) << "[SensorService] Request Type: "<< request.type();
|
||||
|
||||
aap_protobuf::service::sensorsource::message::SensorStartResponseMessage response;
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
|
||||
if (request.type() == aap_protobuf::service::sensorsource::message::SENSOR_DRIVING_STATUS_DATA)
|
||||
{
|
||||
promise->then(std::bind(&SensorService::sendDrivingStatusUnrestricted, this->shared_from_this()),
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
else if (request.type() == aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE)
|
||||
{
|
||||
promise->then(std::bind(&SensorService::sendNightData, this->shared_from_this()),
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
else
|
||||
{
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
|
||||
channel_->sendSensorStartResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void SensorService::sendDrivingStatusUnrestricted() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendDrivingStatusUnrestricted()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
indication.add_driving_status_data()->set_status(aap_protobuf::service::sensorsource::message::DrivingStatus::DRIVE_STATUS_UNRESTRICTED);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() { },
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
}
|
||||
|
||||
void SensorService::sendNightData() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendNightData()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
|
||||
if (SensorService::isNight) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Night Mode Triggered";
|
||||
indication.add_night_mode_data()->set_night_mode(true);
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Day Mode Triggered";
|
||||
indication.add_night_mode_data()->set_night_mode(false);
|
||||
}
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
if (this->firstRun) {
|
||||
this->firstRun = false;
|
||||
this->previous = this->isNight;
|
||||
}
|
||||
}
|
||||
|
||||
void SensorService::sendGPSLocationData() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendGPSLocationData()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
|
||||
auto *locInd = indication.add_location_data();
|
||||
|
||||
// epoch seconds
|
||||
// locInd->set_timestamp(this->gpsData_.fix.time * 1e3);
|
||||
// degrees
|
||||
locInd->set_latitude_e7(this->gpsData_.fix.latitude * 1e7);
|
||||
locInd->set_longitude_e7(this->gpsData_.fix.longitude * 1e7);
|
||||
// meters
|
||||
auto accuracy = sqrt(pow(this->gpsData_.fix.epx, 2) + pow(this->gpsData_.fix.epy, 2));
|
||||
locInd->set_accuracy_e3(accuracy * 1e3);
|
||||
|
||||
if (this->gpsData_.set & ALTITUDE_SET) {
|
||||
// meters above ellipsoid
|
||||
locInd->set_altitude_e2(this->gpsData_.fix.altitude * 1e2);
|
||||
}
|
||||
if (this->gpsData_.set & SPEED_SET) {
|
||||
// meters per second to knots
|
||||
locInd->set_speed_e3(this->gpsData_.fix.speed * 1.94384 * 1e3);
|
||||
}
|
||||
if (this->gpsData_.set & TRACK_SET) {
|
||||
// degrees
|
||||
locInd->set_bearing_e6(this->gpsData_.fix.track * 1e6);
|
||||
}
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
}
|
||||
|
||||
void SensorService::sensorPolling() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sensorPolling()";
|
||||
if (!this->stopPolling) {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
this->isNight = is_file_exist("/tmp/night_mode_enabled");
|
||||
if (this->previous != this->isNight && !this->firstRun) {
|
||||
this->previous = this->isNight;
|
||||
this->sendNightData();
|
||||
}
|
||||
|
||||
if ((this->gpsEnabled_) &&
|
||||
(gps_waiting(&this->gpsData_, 0)) &&
|
||||
(gps_read(&this->gpsData_) > 0) &&
|
||||
(this->gpsData_.status != STATUS_NO_FIX) &&
|
||||
(this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) &&
|
||||
(this->gpsData_.set & TIME_SET) &&
|
||||
(this->gpsData_.set & LATLON_SET))
|
||||
{
|
||||
this->sendGPSLocationData();
|
||||
}
|
||||
|
||||
timer_.expires_from_now(boost::posix_time::milliseconds(250));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&SensorService::sensorPolling, this->shared_from_this())));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool SensorService::is_file_exist(const char *fileName) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] is_file_exist()";
|
||||
std::ifstream ifile(fileName, std::ios::in);
|
||||
return ifile.good();
|
||||
}
|
||||
|
||||
void SensorService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[SensorService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
void SensorService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
if (gps_open("127.0.0.1", "2947", &this->gpsData_)) {
|
||||
OPENAUTO_LOG(warning) << "[SensorService] can't connect to GPSD.";
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Connected to GPSD.";
|
||||
gps_stream(&this->gpsData_, WATCH_ENABLE | WATCH_JSON, NULL);
|
||||
this->gpsEnabled_ = true;
|
||||
}
|
||||
|
||||
if (is_file_exist("/tmp/night_mode_enabled")) {
|
||||
this->isNight = true;
|
||||
}
|
||||
this->sensorPolling();
|
||||
|
||||
OPENAUTO_LOG(info) << "[SensorService] start()";
|
||||
channel_->receive(this->shared_from_this());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void SensorService::stop() {
|
||||
this->stopPolling = true;
|
||||
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
if (this->gpsEnabled_) {
|
||||
gps_stream(&this->gpsData_, WATCH_DISABLE, NULL);
|
||||
gps_close(&this->gpsData_);
|
||||
this->gpsEnabled_ = false;
|
||||
}
|
||||
|
||||
OPENAUTO_LOG(info) << "[SensorService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void SensorService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *sensorChannel = service->mutable_sensor_source_service();
|
||||
sensorChannel->add_sensors()->set_sensor_type(
|
||||
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_DRIVING_STATUS_DATA);
|
||||
sensorChannel->add_sensors()->set_sensor_type(
|
||||
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_LOCATION);
|
||||
sensorChannel->add_sensors()->set_sensor_type(
|
||||
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE);
|
||||
}
|
||||
|
||||
void SensorService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[SensorService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void SensorService::onSensorStartRequest(
|
||||
const aap_protobuf::service::sensorsource::message::SensorRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] onSensorStartRequest()";
|
||||
OPENAUTO_LOG(debug) << "[SensorService] Request Type: " << request.type();
|
||||
|
||||
aap_protobuf::service::sensorsource::message::SensorStartResponseMessage response;
|
||||
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
|
||||
if (request.type() == aap_protobuf::service::sensorsource::message::SENSOR_DRIVING_STATUS_DATA) {
|
||||
promise->then(std::bind(&SensorService::sendDrivingStatusUnrestricted, this->shared_from_this()),
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
} else if (request.type() == aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE) {
|
||||
promise->then(std::bind(&SensorService::sendNightData, this->shared_from_this()),
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
} else {
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
|
||||
channel_->sendSensorStartResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void SensorService::sendDrivingStatusUnrestricted() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendDrivingStatusUnrestricted()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
indication.add_driving_status_data()->set_status(
|
||||
aap_protobuf::service::sensorsource::message::DrivingStatus::DRIVE_STATUS_UNRESTRICTED);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
}
|
||||
|
||||
void SensorService::sendNightData() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendNightData()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
|
||||
if (SensorService::isNight) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Night Mode Triggered";
|
||||
indication.add_night_mode_data()->set_night_mode(true);
|
||||
} else {
|
||||
OPENAUTO_LOG(info) << "[SensorService] Day Mode Triggered";
|
||||
indication.add_night_mode_data()->set_night_mode(false);
|
||||
}
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
if (this->firstRun) {
|
||||
this->firstRun = false;
|
||||
this->previous = this->isNight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SensorService::sendGPSLocationData() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sendGPSLocationData()";
|
||||
aap_protobuf::service::sensorsource::message::SensorBatch indication;
|
||||
|
||||
auto *locInd = indication.add_location_data();
|
||||
|
||||
// epoch seconds
|
||||
// locInd->set_timestamp(this->gpsData_.fix.time * 1e3);
|
||||
// degrees
|
||||
locInd->set_latitude_e7(this->gpsData_.fix.latitude * 1e7);
|
||||
locInd->set_longitude_e7(this->gpsData_.fix.longitude * 1e7);
|
||||
// meters
|
||||
auto accuracy = sqrt(pow(this->gpsData_.fix.epx, 2) + pow(this->gpsData_.fix.epy, 2));
|
||||
locInd->set_accuracy_e3(accuracy * 1e3);
|
||||
|
||||
if (this->gpsData_.set & ALTITUDE_SET) {
|
||||
// meters above ellipsoid
|
||||
locInd->set_altitude_e2(this->gpsData_.fix.altitude * 1e2);
|
||||
}
|
||||
if (this->gpsData_.set & SPEED_SET) {
|
||||
// meters per second to knots
|
||||
locInd->set_speed_e3(this->gpsData_.fix.speed * 1.94384 * 1e3);
|
||||
}
|
||||
if (this->gpsData_.set & TRACK_SET) {
|
||||
// degrees
|
||||
locInd->set_bearing_e6(this->gpsData_.fix.track * 1e6);
|
||||
}
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {},
|
||||
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||
}
|
||||
|
||||
void SensorService::sensorPolling() {
|
||||
OPENAUTO_LOG(info) << "[SensorService] sensorPolling()";
|
||||
if (!this->stopPolling) {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
this->isNight = is_file_exist("/tmp/night_mode_enabled");
|
||||
if (this->previous != this->isNight && !this->firstRun) {
|
||||
this->previous = this->isNight;
|
||||
this->sendNightData();
|
||||
}
|
||||
|
||||
if ((this->gpsEnabled_) &&
|
||||
(gps_waiting(&this->gpsData_, 0)) &&
|
||||
(gps_read(&this->gpsData_) > 0) &&
|
||||
(this->gpsData_.status != STATUS_NO_FIX) &&
|
||||
(this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) &&
|
||||
(this->gpsData_.set & TIME_SET) &&
|
||||
(this->gpsData_.set & LATLON_SET)) {
|
||||
this->sendGPSLocationData();
|
||||
}
|
||||
|
||||
timer_.expires_from_now(boost::posix_time::milliseconds(250));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&SensorService::sensorPolling, this->shared_from_this())));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool SensorService::is_file_exist(const char *fileName) {
|
||||
OPENAUTO_LOG(info) << "[SensorService] is_file_exist()";
|
||||
std::ifstream ifile(fileName, std::ios::in);
|
||||
return ifile.good();
|
||||
}
|
||||
|
||||
void SensorService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[SensorService] onChannelError(): " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -49,30 +49,28 @@
|
||||
#include <f1x/openauto/autoapp/Projection/RemoteBluetoothDevice.hpp>
|
||||
#include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace f1x::openauto::autoapp::service {
|
||||
|
||||
ServiceFactory::ServiceFactory(boost::asio::io_service &ioService,
|
||||
configuration::IConfiguration::Pointer configuration)
|
||||
: ioService_(ioService), configuration_(std::move(configuration)) {
|
||||
ServiceFactory::ServiceFactory(boost::asio::io_service &ioService,
|
||||
configuration::IConfiguration::Pointer configuration)
|
||||
: ioService_(ioService), configuration_(std::move(configuration)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] create()";
|
||||
ServiceList serviceList;
|
||||
ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] create()";
|
||||
ServiceList serviceList;
|
||||
|
||||
this->createMediaSinkServices(serviceList, messenger);
|
||||
this->createMediaSourceServices(serviceList, messenger);
|
||||
serviceList.emplace_back(this->createSensorService(messenger));
|
||||
serviceList.emplace_back(this->createBluetoothService(messenger));
|
||||
serviceList.emplace_back(this->createInputService(messenger));
|
||||
//serviceList.emplace_back(this->createWifiProjectionService(messenger));
|
||||
this->createMediaSinkServices(serviceList, messenger);
|
||||
this->createMediaSourceServices(serviceList, messenger);
|
||||
serviceList.emplace_back(this->createSensorService(messenger));
|
||||
serviceList.emplace_back(this->createBluetoothService(messenger));
|
||||
serviceList.emplace_back(this->createInputService(messenger));
|
||||
// TODO: What is WiFi Projection Service?
|
||||
//serviceList.emplace_back(this->createWifiProjectionService(messenger));
|
||||
|
||||
return serviceList;
|
||||
}
|
||||
return serviceList;
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createBluetoothService()";
|
||||
@ -97,123 +95,123 @@ namespace f1x {
|
||||
break;
|
||||
}
|
||||
|
||||
return std::make_shared<bluetooth::BluetoothService>(ioService_, messenger, std::move(bluetoothDevice));
|
||||
}
|
||||
return std::make_shared<bluetooth::BluetoothService>(ioService_, messenger, std::move(bluetoothDevice));
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createInputService()";
|
||||
QRect videoGeometry;
|
||||
switch (configuration_->getVideoResolution()) {
|
||||
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1280x720:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1280x720";
|
||||
videoGeometry = QRect(0, 0, 1280, 720);
|
||||
break;
|
||||
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1920x1080:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1920x1080";
|
||||
videoGeometry = QRect(0, 0, 1920, 1080);
|
||||
break;
|
||||
default:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 800x480";
|
||||
videoGeometry = QRect(0, 0, 800, 480);
|
||||
break;
|
||||
}
|
||||
IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createInputService()";
|
||||
QRect videoGeometry;
|
||||
switch (configuration_->getVideoResolution()) {
|
||||
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1280x720:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1280x720";
|
||||
videoGeometry = QRect(0, 0, 1280, 720);
|
||||
break;
|
||||
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1920x1080:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1920x1080";
|
||||
videoGeometry = QRect(0, 0, 1920, 1080);
|
||||
break;
|
||||
default:
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 800x480";
|
||||
videoGeometry = QRect(0, 0, 800, 480);
|
||||
break;
|
||||
}
|
||||
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
QRect screenGeometry = screen == nullptr ? QRect(0, 0, 1, 1) : screen->geometry();
|
||||
projection::IInputDevice::Pointer inputDevice(
|
||||
std::make_shared<projection::InputDevice>(*QApplication::instance(), configuration_,
|
||||
std::move(screenGeometry), std::move(videoGeometry)));
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
QRect screenGeometry = screen == nullptr ? QRect(0, 0, 1, 1) : screen->geometry();
|
||||
projection::IInputDevice::Pointer inputDevice(
|
||||
std::make_shared<projection::InputDevice>(*QApplication::instance(), configuration_,
|
||||
std::move(screenGeometry), std::move(videoGeometry)));
|
||||
|
||||
return std::make_shared<inputsource::InputSourceService>(ioService_, messenger, std::move(inputDevice));
|
||||
}
|
||||
return std::make_shared<inputsource::InputSourceService>(ioService_, messenger, std::move(inputDevice));
|
||||
}
|
||||
|
||||
void ServiceFactory::createMediaSinkServices(ServiceList &serviceList,
|
||||
aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSinkServices()";
|
||||
if (configuration_->musicAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Media Audio Channel enabled";
|
||||
auto mediaAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(2, 16, 48000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(2, 16, 48000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
void ServiceFactory::createMediaSinkServices(ServiceList &serviceList,
|
||||
aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSinkServices()";
|
||||
if (configuration_->musicAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Media Audio Channel enabled";
|
||||
auto mediaAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(2, 16, 48000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(2, 16, 48000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput)));
|
||||
}
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput)));
|
||||
}
|
||||
|
||||
if (configuration_->guidanceAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Guidance Audio Channel enabled";
|
||||
auto guidanceAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
if (configuration_->guidanceAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Guidance Audio Channel enabled";
|
||||
auto guidanceAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::GuidanceAudioService>(ioService_, messenger,
|
||||
std::move(guidanceAudioOutput)));
|
||||
}
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::GuidanceAudioService>(ioService_, messenger,
|
||||
std::move(guidanceAudioOutput)));
|
||||
}
|
||||
|
||||
if (configuration_->telephonyAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled";
|
||||
auto telephonyAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
if (configuration_->telephonyAudioChannelEnabled()) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled";
|
||||
auto telephonyAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger,
|
||||
std::move(telephonyAudioOutput)));
|
||||
}
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger,
|
||||
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.
|
||||
*/
|
||||
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] System Audio Channel enabled";
|
||||
auto systemAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] System Audio Channel enabled";
|
||||
auto systemAudioOutput =
|
||||
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
|
||||
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
|
||||
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));
|
||||
|
||||
#ifdef USE_OMX
|
||||
auto videoOutput(std::make_shared<projection::OMXVideoOutput>(configuration_));
|
||||
auto videoOutput(std::make_shared<projection::OMXVideoOutput>(configuration_));
|
||||
#else
|
||||
projection::IVideoOutput::Pointer videoOutput(new projection::QtVideoOutput(configuration_),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
projection::IVideoOutput::Pointer videoOutput(new projection::QtVideoOutput(configuration_),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
#endif
|
||||
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Video Channel enabled";
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::VideoService>(ioService_, messenger, std::move(videoOutput)));
|
||||
}
|
||||
|
||||
void ServiceFactory::createMediaSourceServices(f1x::openauto::autoapp::service::ServiceList &serviceList,
|
||||
aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSourceServices()";
|
||||
projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
serviceList.emplace_back(std::make_shared<mediasource::MicrophoneMediaSourceService>(ioService_, messenger,
|
||||
std::move(audioInput)));
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createSensorService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createSensorService()";
|
||||
return std::make_shared<sensor::SensorService>(ioService_, messenger);
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createWifiProjectionService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createWifiProjectionService()";
|
||||
return std::make_shared<wifiprojection::WifiProjectionService>(ioService_, messenger);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] Video Channel enabled";
|
||||
serviceList.emplace_back(
|
||||
std::make_shared<mediasink::VideoService>(ioService_, messenger, std::move(videoOutput)));
|
||||
}
|
||||
|
||||
void ServiceFactory::createMediaSourceServices(f1x::openauto::autoapp::service::ServiceList &serviceList,
|
||||
aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSourceServices()";
|
||||
projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000),
|
||||
std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
serviceList.emplace_back(std::make_shared<mediasource::MicrophoneMediaSourceService>(ioService_, messenger,
|
||||
std::move(audioInput)));
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createSensorService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createSensorService()";
|
||||
return std::make_shared<sensor::SensorService>(ioService_, messenger);
|
||||
}
|
||||
|
||||
IService::Pointer ServiceFactory::createWifiProjectionService(aasdk::messenger::IMessenger::Pointer messenger) {
|
||||
OPENAUTO_LOG(info) << "[ServiceFactory] createWifiProjectionService()";
|
||||
return std::make_shared<wifiprojection::WifiProjectionService>(ioService_, messenger);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,74 +21,72 @@
|
||||
#include <fstream>
|
||||
#include <QString>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace vendorextension {
|
||||
namespace f1x::openauto::autoapp::service::vendorextension {
|
||||
|
||||
VendorExtensionService::VendorExtensionService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::vendorextension::VendorExtensionService>(strand_, std::move(messenger))) {
|
||||
VendorExtensionService::VendorExtensionService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(
|
||||
std::make_shared<aasdk::channel::vendorextension::VendorExtensionService>(strand_, std::move(messenger))) {
|
||||
|
||||
}
|
||||
|
||||
void VendorExtensionService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *vendorExtension = service->mutable_vendor_extension_service();
|
||||
}
|
||||
|
||||
void VendorExtensionService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[VendorExtensionService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
void VendorExtensionService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&VendorExtensionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VendorExtensionService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void VendorExtensionService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *vendorExtension = service->mutable_vendor_extension_service();
|
||||
}
|
||||
|
||||
void VendorExtensionService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[VendorExtensionService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
void VendorExtensionService::onChannelOpenRequest(
|
||||
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(info) << "[VendorExtensionService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&VendorExtensionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,97 +22,97 @@
|
||||
#include <QString>
|
||||
#include <QNetworkInterface>
|
||||
|
||||
namespace f1x {
|
||||
namespace openauto {
|
||||
namespace autoapp {
|
||||
namespace service {
|
||||
namespace wifiprojection {
|
||||
WifiProjectionService::WifiProjectionService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(std::make_shared<aasdk::channel::wifiprojection::WifiProjectionService>(strand_, std::move(messenger))) {
|
||||
|
||||
}
|
||||
namespace f1x::openauto::autoapp::service::wifiprojection {
|
||||
WifiProjectionService::WifiProjectionService(boost::asio::io_service &ioService,
|
||||
aasdk::messenger::IMessenger::Pointer messenger)
|
||||
: strand_(ioService),
|
||||
timer_(ioService),
|
||||
channel_(
|
||||
std::make_shared<aasdk::channel::wifiprojection::WifiProjectionService>(strand_, std::move(messenger))) {
|
||||
|
||||
void WifiProjectionService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *wifiChannel = service->mutable_wifi_projection_service();
|
||||
wifiChannel->set_car_wifi_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
|
||||
}
|
||||
|
||||
void WifiProjectionService::onWifiCredentialsRequest(
|
||||
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) {
|
||||
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] onWifiCredentialsRequest()";
|
||||
|
||||
aap_protobuf::service::wifiprojection::message::WifiCredentialsResponse response;
|
||||
|
||||
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
|
||||
response.set_car_wifi_ssid("CRANKSHAFT-NG");
|
||||
response.set_car_wifi_password("1234567890");
|
||||
response.set_car_wifi_security_mode(aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_PERSONAL);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendWifiCredentialsResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
|
||||
}
|
||||
|
||||
void WifiProjectionService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[WifiProjectionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void WifiProjectionService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[WifiProjectionService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProjectionService::start() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] start()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::stop() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] stop()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::pause() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] pause()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::resume() {
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] resume()";
|
||||
});
|
||||
}
|
||||
|
||||
void WifiProjectionService::fillFeatures(
|
||||
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] fillFeatures()";
|
||||
|
||||
auto *service = response.add_channels();
|
||||
service->set_id(static_cast<uint32_t>(channel_->getId()));
|
||||
|
||||
auto *wifiChannel = service->mutable_wifi_projection_service();
|
||||
wifiChannel->set_car_wifi_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
|
||||
}
|
||||
|
||||
void WifiProjectionService::onWifiCredentialsRequest(
|
||||
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) {
|
||||
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] onWifiCredentialsRequest()";
|
||||
|
||||
aap_protobuf::service::wifiprojection::message::WifiCredentialsResponse response;
|
||||
|
||||
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
|
||||
response.set_car_wifi_ssid("CRANKSHAFT-NG");
|
||||
response.set_car_wifi_password("1234567890");
|
||||
response.set_car_wifi_security_mode(
|
||||
aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_PERSONAL);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendWifiCredentialsResponse(response, std::move(promise));
|
||||
channel_->receive(this->shared_from_this());
|
||||
|
||||
}
|
||||
|
||||
void WifiProjectionService::onChannelOpenRequest(
|
||||
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
|
||||
OPENAUTO_LOG(info) << "[WifiProjectionService] onChannelOpenRequest()";
|
||||
OPENAUTO_LOG(debug) << "[WifiProjectionService] Channel Id: " << request.service_id() << ", Priority: "
|
||||
<< request.priority();
|
||||
|
||||
aap_protobuf::service::control::message::ChannelOpenResponse response;
|
||||
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
|
||||
response.set_status(status);
|
||||
|
||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
|
||||
std::placeholders::_1));
|
||||
channel_->sendChannelOpenResponse(response, std::move(promise));
|
||||
|
||||
channel_->receive(this->shared_from_this());
|
||||
}
|
||||
|
||||
void WifiProjectionService::onChannelError(const aasdk::error::Error &e) {
|
||||
OPENAUTO_LOG(error) << "[WifiProjectionService] onChannelError(): " << e.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user