cleanup wireless device connection (#14)

* initial cleanup passthrough

* bad copypaste

* add back ! and more style fixes

* handling ping and voice session
This commit is contained in:
Robert Stanley Judka 2020-08-28 17:36:43 -05:00 committed by GitHub
parent ae66394b6b
commit 23c38158ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 281 additions and 237 deletions

16
.gitignore vendored
View File

@ -3,6 +3,20 @@
lib/ lib/
bin/ bin/
.idea/
CMakeLists.txt.user CMakeLists.txt.user
cmake-build-*/ cmake-build-*/
.idea/ CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*_autogen/
*.pb.cc
*.pb.h

View File

@ -73,7 +73,6 @@ add_subdirectory(btservice_proto)
set(BTSERVICE_PROTO_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) set(BTSERVICE_PROTO_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${BTSERVICE_PROTO_INCLUDE_DIRS}) include_directories(${BTSERVICE_PROTO_INCLUDE_DIRS})
add_subdirectory(openauto) add_subdirectory(openauto)
add_subdirectory(autoapp) add_subdirectory(autoapp)
add_dependencies(autoapp btservice_proto) add_dependencies(autoapp btservice_proto)

View File

@ -1,74 +1,71 @@
#include "OpenautoLog.hpp"
#include "btservice/AndroidBluetoothServer.hpp"
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QThread> #include <QThread>
#include "OpenautoLog.hpp"
#include "btservice/AndroidBluetoothServer.hpp"
namespace openauto namespace openauto
{ {
namespace btservice namespace btservice
{ {
AndroidBluetoothServer::AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config_) AndroidBluetoothServer::AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config)
: rfcommServer_(std::make_unique<QBluetoothServer>(QBluetoothServiceInfo::RfcommProtocol, this)) : rfcommServer_(std::make_unique<QBluetoothServer>(QBluetoothServiceInfo::RfcommProtocol, this))
, config(std::move(config_)) , socket_(nullptr)
, config_(std::move(config))
, handshakeState_(ConnectionStatus::IDLE)
{ {
handshakeState = IDLE;
connect(rfcommServer_.get(), &QBluetoothServer::newConnection, this, &AndroidBluetoothServer::onClientConnected); connect(rfcommServer_.get(), &QBluetoothServer::newConnection, this, &AndroidBluetoothServer::onClientConnected);
QThread *thread = QThread::create([&]{ this->stateMachine(); });
auto* thread = QThread::create([&]{ this->eventLoop(); });
thread->start(); thread->start();
} }
void AndroidBluetoothServer::stateMachine() void AndroidBluetoothServer::eventLoop()
{ {
while(true){ while(true)
switch(handshakeState){ {
case IDLE: switch(handshakeState_)
break; {
case ConnectionStatus::IDLE:
case ConnectionStatus::SENT_SOCKETINFO_MESSAGE:
case ConnectionStatus::SENT_NETWORKINFO_MESSAGE:
case ConnectionStatus::PHONE_RESP_NETWORKINFO:
case ConnectionStatus::ERROR:
break;
case DEVICE_CONNECTED: case ConnectionStatus::DEVICE_CONNECTED:
handshakeState = SENDING_SOCKETINFO_MESSAGE; handshakeState_ = ConnectionStatus::SENDING_SOCKETINFO_MESSAGE;
break; break;
case SENDING_SOCKETINFO_MESSAGE: case ConnectionStatus::SENDING_SOCKETINFO_MESSAGE:
writeSocketInfoMessage(); this->writeSocketInfoMessage();
break; break;
case SENT_SOCKETINFO_MESSAGE: case ConnectionStatus::PHONE_RESP_SOCKETINFO:
break; handshakeState_ = ConnectionStatus::SENDING_NETWORKINFO_MESSAGE;
break;
case PHONE_RESP_SOCKETINFO:
handshakeState = SENDING_NETWORKINFO_MESSAGE;
break;
case SENDING_NETWORKINFO_MESSAGE:
writeNetworkInfoMessage();
break;
case SENT_NETWORKINFO_MESSAGE:
break;
case PHONE_RESP_NETWORKINFO:
break;
case ConnectionStatus::SENDING_NETWORKINFO_MESSAGE:
this->writeNetworkInfoMessage();
break;
} }
} }
} }
bool AndroidBluetoothServer::start(const QBluetoothAddress& address, uint16_t portNumber) bool AndroidBluetoothServer::start(const QBluetoothAddress& address, uint16_t portNumber)
{ {
OPENAUTO_LOG(info)<<"listening"; OPENAUTO_LOG(info) << "[AndroidBluetoothServer] listening.";
return rfcommServer_->listen(address, portNumber); return rfcommServer_->listen(address, portNumber);
} }
void AndroidBluetoothServer::onClientConnected() void AndroidBluetoothServer::onClientConnected()
{ {
socket = rfcommServer_->nextPendingConnection(); socket_ = rfcommServer_->nextPendingConnection();
if(socket_ != nullptr)
if(socket != nullptr)
{ {
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Device Connected: " << socket->peerName().toStdString(); OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Device Connected: " << socket_->peerName().toStdString();
connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket_, SIGNAL(readyRead()), this, SLOT(readSocket()));
handshakeState = DEVICE_CONNECTED; handshakeState_ = ConnectionStatus::DEVICE_CONNECTED;
} }
else else
{ {
@ -76,139 +73,147 @@ void AndroidBluetoothServer::onClientConnected()
} }
} }
bool AndroidBluetoothServer::writeProtoMessage(uint16_t messageType, google::protobuf::Message &message){ bool AndroidBluetoothServer::writeProtoMessage(uint16_t messageType, google::protobuf::Message& message)
{
QByteArray byteArray(message.SerializeAsString().c_str(), message.ByteSize()); QByteArray byteArray(message.SerializeAsString().c_str(), message.ByteSize());
uint16_t message_length = message.ByteSize(); uint16_t messageLength = message.ByteSize();
char byte1 = messageType & 0x000000ff; byteArray.prepend(messageType & 0x000000ff);
char byte2 = (messageType & 0x0000ff00) >> 8; byteArray.prepend((messageType & 0x0000ff00) >> 8);
byteArray.prepend(byte1); byteArray.prepend(messageLength & 0x000000ff);
byteArray.prepend(byte2); byteArray.prepend((messageLength & 0x0000ff00) >> 8);
byte1 = message_length & 0x000000ff;
byte2 = (message_length & 0x0000ff00) >> 8; if(socket_->write(byteArray) != byteArray.length())
byteArray.prepend(byte1); {
byteArray.prepend(byte2); return false;
int sentBytes = socket->write(byteArray); }
if(sentBytes != byteArray.length()) return false;
return true; return true;
} }
void AndroidBluetoothServer::writeSocketInfoMessage(){ void AndroidBluetoothServer::writeSocketInfoMessage()
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sending Socket Info"; {
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sending socket info.";
btservice::proto::SocketInfo socketInfo; QString ipAddr;
foreach(QHostAddress addr, QNetworkInterface::allAddresses())
QString ipAddr; {
QList<QHostAddress> list = QNetworkInterface::allAddresses(); if(!addr.isLoopback() && (addr.protocol() == QAbstractSocket::IPv4Protocol))
for(int nIter=0; nIter<list.count(); nIter++)
{ {
if(!list[nIter].isLoopback()) ipAddr = addr.toString();
if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
ipAddr = list[nIter].toString();
} }
socketInfo.set_address(ipAddr.toStdString()); }
socketInfo.set_port(5000);
socketInfo.set_unknown_1(0);
if(writeProtoMessage(7, socketInfo)){ btservice::proto::SocketInfo socketInfo;
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent Socket Info"; socketInfo.set_address(ipAddr.toStdString());
handshakeState = SENT_SOCKETINFO_MESSAGE; socketInfo.set_port(5000);
} socketInfo.set_unknown_1(0);
else{
OPENAUTO_LOG(error) << "[AndroidBluetoothServer] Error Sending Socket Info"; if(this->writeProtoMessage(7, socketInfo))
handshakeState = ERROR; {
} OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent socket info.";
handshakeState_ = ConnectionStatus::SENT_SOCKETINFO_MESSAGE;
}
else
{
OPENAUTO_LOG(error) << "[AndroidBluetoothServer] Error sending socket Info.";
handshakeState_ = ConnectionStatus::ERROR;
}
} }
void AndroidBluetoothServer::writeNetworkInfoMessage(){ void AndroidBluetoothServer::writeNetworkInfoMessage()
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sending Network Packet"; {
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sending network packet.";
btservice::proto::NetworkInfo networkMessage; btservice::proto::NetworkInfo networkMessage;
networkMessage.set_ssid(config->getWifiSSID()); networkMessage.set_ssid(config_->getWifiSSID());
networkMessage.set_psk(config->getWifiPassword()); networkMessage.set_psk(config_->getWifiPassword());
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
{ {
// Return only the first non-loopback MAC Address // Return only the first non-loopback MAC Address
if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) if (!(netInterface.flags() & QNetworkInterface::IsLoopBack))
{
networkMessage.set_mac_addr(netInterface.hardwareAddress().toStdString()); networkMessage.set_mac_addr(netInterface.hardwareAddress().toStdString());
}
} }
networkMessage.set_security_mode(8); networkMessage.set_security_mode(8);
networkMessage.set_unknown_2(0); networkMessage.set_unknown_2(0);
if(this->writeProtoMessage(3, networkMessage))
if(writeProtoMessage(3, networkMessage)){ {
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent Network Packet"; OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent network packet.";
handshakeState = SENT_NETWORKINFO_MESSAGE; handshakeState_ = ConnectionStatus::SENT_NETWORKINFO_MESSAGE;
} }
else{ else
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Error sending Network Packet"; {
handshakeState = ERROR; OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Error sending network packet.";
handshakeState_ = ConnectionStatus::ERROR;
} }
} }
void AndroidBluetoothServer::readSocket(){ void AndroidBluetoothServer::readSocket()
{
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] DATA: "; OPENAUTO_LOG(info) << "[AndroidBluetoothServer] DATA: ";
if (!socket) if(!socket_)
return; {
QByteArray data = socket->read(1024); return;
if(data.length()==0) return; }
uint16_t messageType = data[2]<<8 | data[3];
auto data = socket_->read(1024);
if(data.length() == 0)
{
return;
}
uint16_t messageType = (data[2] << 8) | data[3];
btservice::proto::PhoneResponse resp; btservice::proto::PhoneResponse resp;
switch(messageType){ switch(messageType)
case 2: {
break; case 2:
case 6: break;
resp.ParseFromString(data.toStdString().c_str());
break;
case 6:
resp.ParseFromString(data.toStdString().c_str());
break;
} }
switch(handshakeState){
case IDLE:
break;
case DEVICE_CONNECTED: switch(handshakeState_)
break; {
case ConnectionStatus::IDLE:
case ConnectionStatus::DEVICE_CONNECTED:
case ConnectionStatus::SENDING_SOCKETINFO_MESSAGE:
case ConnectionStatus::PHONE_RESP_SOCKETINFO:
case ConnectionStatus::SENDING_NETWORKINFO_MESSAGE:
case ConnectionStatus::PHONE_RESP_NETWORKINFO:
case ConnectionStatus::ERROR:
break;
case SENDING_SOCKETINFO_MESSAGE: case ConnectionStatus::SENT_SOCKETINFO_MESSAGE:
break; if(messageType == 2)
{
case SENT_SOCKETINFO_MESSAGE: OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged socket info.";
if(messageType == 2){ handshakeState_ = ConnectionStatus::PHONE_RESP_SOCKETINFO;
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged Socket Info"; }
handshakeState = PHONE_RESP_SOCKETINFO; else
}else{ {
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Got unexpected message"; OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Got unexpected message.";
handshakeState = ERROR; handshakeState_ = ConnectionStatus::ERROR;
} }
break; break;
case PHONE_RESP_SOCKETINFO:
break;
case SENDING_NETWORKINFO_MESSAGE:
break;
case SENT_NETWORKINFO_MESSAGE:
if(messageType == 6){
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged Network Info with status code: "<<resp.status_code();
handshakeState = PHONE_RESP_NETWORKINFO;
}else{
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Got unexpected message";
handshakeState = ERROR;
}
break;
case PHONE_RESP_NETWORKINFO:
break;
case ConnectionStatus::SENT_NETWORKINFO_MESSAGE:
if(messageType == 6)
{
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged network info with status code: " << resp.status_code();
handshakeState_ = ConnectionStatus::PHONE_RESP_NETWORKINFO;
}
else
{
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Got unexpected message";
handshakeState_ = ConnectionStatus::ERROR;
}
break;
} }
} }
} }
} }

View File

@ -1,34 +1,41 @@
#include "btservice/btservice.hpp" #include "btservice/btservice.hpp"
namespace openauto{
namespace btservice{ namespace openauto
btservice::btservice(openauto::configuration::IConfiguration::Pointer config) : androidBluetoothService(servicePortNumber), androidBluetoothServer(config){ {
namespace btservice
{
btservice::btservice(openauto::configuration::IConfiguration::Pointer config)
: androidBluetoothService_(cServicePortNumber)
, androidBluetoothServer_(config)
{
QBluetoothAddress address; QBluetoothAddress address;
auto adapters = QBluetoothLocalDevice::allDevices(); auto adapters = QBluetoothLocalDevice::allDevices();
if (adapters.size() > 0) if(adapters.size() > 0)
address =adapters.at(0).address(); {
else{ address = adapters.at(0).address();
OPENAUTO_LOG(error) << "[btservice] No adapter found"; }
else
{
OPENAUTO_LOG(error) << "[btservice] No adapter found.";
} }
if(!androidBluetoothServer_.start(address, cServicePortNumber))
if(!androidBluetoothServer.start(address, servicePortNumber))
{ {
OPENAUTO_LOG(error) << "[btservice] Server start failed."; OPENAUTO_LOG(error) << "[btservice] Server start failed.";
return; return;
} }
OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString() OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString()
<< ", port: " << servicePortNumber; << ", port: " << cServicePortNumber;
if(!androidBluetoothService_.registerService(address))
if(!androidBluetoothService.registerService(address))
{ {
OPENAUTO_LOG(error) << "[btservice] Service registration failed."; OPENAUTO_LOG(error) << "[btservice] Service registration failed.";
} }
else else
{ {
OPENAUTO_LOG(info) << "[btservice] Service registered, port: " << servicePortNumber; OPENAUTO_LOG(info) << "[btservice] Service registered, port: " << cServicePortNumber;
} }
} }

View File

@ -9,5 +9,5 @@ target_link_libraries(btservice_proto ${PROTOBUF_LIBRARIES})
install(TARGETS btservice_proto DESTINATION lib) install(TARGETS btservice_proto DESTINATION lib)
install(DIRECTORY . DESTINATION include/btservice_proto install(DIRECTORY . DESTINATION include/btservice_proto
FILES_MATCHING PATTERN *.h FILES_MATCHING PATTERN *.h
PATTERN CMakeFiles EXCLUDE ) PATTERN CMakeFiles EXCLUDE)

View File

@ -1,8 +1,9 @@
syntax = "proto2"; syntax = "proto2";
package openauto.btservice.proto; package openauto.btservice.proto;
message NetworkInfo
message NetworkInfo{ {
required string ssid = 1; required string ssid = 1;
required string psk = 2; required string psk = 2;
required string mac_addr = 3; required string mac_addr = 3;

View File

@ -1,7 +1,8 @@
syntax = "proto3"; syntax = "proto3";
package openauto.btservice.proto; package openauto.btservice.proto;
message PhoneResponse
message PhoneResponse{ {
int32 status_code = 1; int32 status_code = 1;
} }

View File

@ -1,8 +1,9 @@
syntax = "proto2"; syntax = "proto2";
package openauto.btservice.proto; package openauto.btservice.proto;
message SocketInfo
message SocketInfo{ {
required string address = 1; required string address = 1;
required int32 port = 2; required int32 port = 2;
required int32 unknown_1 = 3; required int32 unknown_1 = 3;

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <atomic>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <QBluetoothServer> #include <QBluetoothServer>
@ -17,13 +18,25 @@ namespace openauto
namespace btservice namespace btservice
{ {
enum class ConnectionStatus
{
IDLE,
DEVICE_CONNECTED,
SENDING_SOCKETINFO_MESSAGE,
SENT_SOCKETINFO_MESSAGE,
PHONE_RESP_SOCKETINFO,
SENDING_NETWORKINFO_MESSAGE,
SENT_NETWORKINFO_MESSAGE,
PHONE_RESP_NETWORKINFO,
ERROR
};
class AndroidBluetoothServer: public QObject, public IAndroidBluetoothServer class AndroidBluetoothServer: public QObject, public IAndroidBluetoothServer
{ {
Q_OBJECT Q_OBJECT
public: public:
AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config_); AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config);
bool start(const QBluetoothAddress& address, uint16_t portNumber) override; bool start(const QBluetoothAddress& address, uint16_t portNumber) override;
private slots: private slots:
@ -32,28 +45,15 @@ private slots:
private: private:
std::unique_ptr<QBluetoothServer> rfcommServer_; std::unique_ptr<QBluetoothServer> rfcommServer_;
QBluetoothSocket* socket; QBluetoothSocket* socket_;
openauto::configuration::IConfiguration::Pointer config_;
std::atomic<ConnectionStatus> handshakeState_;
void writeSocketInfoMessage(); void writeSocketInfoMessage();
void writeNetworkInfoMessage(); void writeNetworkInfoMessage();
void stateMachine(); void eventLoop();
bool writeProtoMessage(uint16_t messageType, google::protobuf::Message &message); bool writeProtoMessage(uint16_t messageType, google::protobuf::Message& message);
enum CONNECTION_STATUS {
IDLE,
DEVICE_CONNECTED,
SENDING_SOCKETINFO_MESSAGE,
SENT_SOCKETINFO_MESSAGE,
PHONE_RESP_SOCKETINFO,
SENDING_NETWORKINFO_MESSAGE,
SENT_NETWORKINFO_MESSAGE,
PHONE_RESP_NETWORKINFO,
ERROR
};
CONNECTION_STATUS handshakeState = IDLE;
protected:
openauto::configuration::IConfiguration::Pointer config;
}; };
} }

View File

@ -5,18 +5,22 @@
#include "btservice/AndroidBluetoothService.hpp" #include "btservice/AndroidBluetoothService.hpp"
#include "btservice/AndroidBluetoothServer.hpp" #include "btservice/AndroidBluetoothServer.hpp"
#include "openauto/Configuration/Configuration.hpp" #include "openauto/Configuration/Configuration.hpp"
namespace openauto{
namespace btservice{ namespace openauto
{
namespace btservice
{
class btservice{ class btservice
public: {
btservice(openauto::configuration::IConfiguration::Pointer config); public:
private: btservice(openauto::configuration::IConfiguration::Pointer config);
const uint16_t servicePortNumber = 22;
openauto::btservice::AndroidBluetoothServer androidBluetoothServer;
openauto::btservice::AndroidBluetoothService androidBluetoothService;
private:
const uint16_t cServicePortNumber = 22;
openauto::btservice::AndroidBluetoothService androidBluetoothService_;
openauto::btservice::AndroidBluetoothServer androidBluetoothServer_;
}; };
} }

View File

@ -69,8 +69,9 @@ public:
void setAudioOutputBackendType(AudioOutputBackendType value) override; void setAudioOutputBackendType(AudioOutputBackendType value) override;
std::string getWifiSSID() override; std::string getWifiSSID() override;
void setWifiSSID(std::string value) override;
std::string getWifiPassword() override; std::string getWifiPassword() override;
void setWifiPassword(std::string value) override;
private: private:
void readButtonCodes(boost::property_tree::ptree& iniConfig); void readButtonCodes(boost::property_tree::ptree& iniConfig);
@ -91,8 +92,8 @@ private:
bool musicAudioChannelEnabled_; bool musicAudioChannelEnabled_;
bool speechAudiochannelEnabled_; bool speechAudiochannelEnabled_;
AudioOutputBackendType audioOutputBackendType_; AudioOutputBackendType audioOutputBackendType_;
std::string ssid; std::string wifiSSID_;
std::string pskey; std::string wifiPassword_;
static const std::string cConfigFileName; static const std::string cConfigFileName;

View File

@ -44,9 +44,6 @@ public:
virtual void reset() = 0; virtual void reset() = 0;
virtual void save() = 0; virtual void save() = 0;
virtual std::string getWifiSSID() = 0;
virtual std::string getWifiPassword() = 0;
virtual void setHandednessOfTrafficType(HandednessOfTrafficType value) = 0; virtual void setHandednessOfTrafficType(HandednessOfTrafficType value) = 0;
virtual HandednessOfTrafficType getHandednessOfTrafficType() const = 0; virtual HandednessOfTrafficType getHandednessOfTrafficType() const = 0;
virtual void showClock(bool value) = 0; virtual void showClock(bool value) = 0;
@ -79,6 +76,11 @@ public:
virtual void setSpeechAudioChannelEnabled(bool value) = 0; virtual void setSpeechAudioChannelEnabled(bool value) = 0;
virtual AudioOutputBackendType getAudioOutputBackendType() const = 0; virtual AudioOutputBackendType getAudioOutputBackendType() const = 0;
virtual void setAudioOutputBackendType(AudioOutputBackendType value) = 0; virtual void setAudioOutputBackendType(AudioOutputBackendType value) = 0;
virtual std::string getWifiSSID() = 0;
virtual void setWifiSSID(std::string value) = 0;
virtual std::string getWifiPassword() = 0;
virtual void setWifiPassword(std::string value) = 0;
}; };
} }

View File

@ -54,10 +54,10 @@ public:
void onShutdownRequest(const aasdk::proto::messages::ShutdownRequest& request) override; void onShutdownRequest(const aasdk::proto::messages::ShutdownRequest& request) override;
void onShutdownResponse(const aasdk::proto::messages::ShutdownResponse& response) override; void onShutdownResponse(const aasdk::proto::messages::ShutdownResponse& response) override;
void onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request) override; void onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request) override;
// void onPingRequest(const aasdk::proto::messages::PingRequest& request) override; // TODO handling ping and voice session void onPingRequest(const aasdk::proto::messages::PingRequest& request) override;
void onPingResponse(const aasdk::proto::messages::PingResponse& response) override; void onPingResponse(const aasdk::proto::messages::PingResponse& response) override;
void onChannelError(const aasdk::error::Error& e) override; void onChannelError(const aasdk::error::Error& e) override;
// void onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request) override; // TODO handling ping and voice session void onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request) override;
private: private:
using std::enable_shared_from_this<AndroidAutoEntity>::shared_from_this; using std::enable_shared_from_this<AndroidAutoEntity>::shared_from_this;

View File

@ -1,12 +1,5 @@
add_library(openauto SHARED add_library(openauto SHARED
App.cpp App.cpp
../btservice/AndroidBluetoothServer.cpp
../btservice/AndroidBluetoothService.cpp
../btservice/btservice.cpp
${CMAKE_SOURCE_DIR}/include/btservice/AndroidBluetoothServer.hpp
${CMAKE_SOURCE_DIR}/include/btservice/AndroidBluetoothService.hpp
${CMAKE_SOURCE_DIR}/include/btservice/IAndroidBluetoothServer.hpp
${CMAKE_SOURCE_DIR}/include/btservice/IAndroidBluetoothService.hpp
Service/BluetoothService.cpp Service/BluetoothService.cpp
Service/InputService.cpp Service/InputService.cpp
Service/MediaAudioService.cpp Service/MediaAudioService.cpp
@ -30,10 +23,17 @@ add_library(openauto SHARED
Projection/SequentialBuffer.cpp Projection/SequentialBuffer.cpp
Projection/DummyBluetoothDevice.cpp Projection/DummyBluetoothDevice.cpp
Projection/QtVideoOutput.cpp Projection/QtVideoOutput.cpp
Projection/GSTVideoOutput.cpp Projection/GSTVideoOutput.cpp
Projection/QtAudioInput.cpp Projection/QtAudioInput.cpp
Projection/RtAudioOutput.cpp Projection/RtAudioOutput.cpp
Projection/QtAudioOutput.cpp Projection/QtAudioOutput.cpp
${CMAKE_SOURCE_DIR}/btservice/AndroidBluetoothServer.cpp
${CMAKE_SOURCE_DIR}/btservice/AndroidBluetoothService.cpp
${CMAKE_SOURCE_DIR}/btservice/btservice.cpp
${CMAKE_SOURCE_DIR}/include/btservice/AndroidBluetoothServer.hpp
${CMAKE_SOURCE_DIR}/include/btservice/AndroidBluetoothService.hpp
${CMAKE_SOURCE_DIR}/include/btservice/IAndroidBluetoothServer.hpp
${CMAKE_SOURCE_DIR}/include/btservice/IAndroidBluetoothService.hpp
${CMAKE_SOURCE_DIR}/include/openauto/App.hpp ${CMAKE_SOURCE_DIR}/include/openauto/App.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Configuration/Configuration.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Configuration/Configuration.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Configuration/RecentAddressesList.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Configuration/RecentAddressesList.hpp
@ -61,7 +61,7 @@ add_library(openauto SHARED
${CMAKE_SOURCE_DIR}/include/openauto/Service/IService.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Service/IService.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Service/Pinger.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Service/Pinger.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Service/InputService.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Service/InputService.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Projection/IInputDeviceEventHandler.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Projection/IInputDeviceEventHandler.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Projection/IVideoOutput.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Projection/IVideoOutput.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Projection/RtAudioOutput.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Projection/RtAudioOutput.hpp
${CMAKE_SOURCE_DIR}/include/openauto/Projection/LocalBluetoothDevice.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Projection/LocalBluetoothDevice.hpp
@ -84,19 +84,19 @@ add_library(openauto SHARED
if(GST_BUILD) if(GST_BUILD)
target_sources(openauto PRIVATE target_sources(openauto PRIVATE
${CMAKE_SOURCE_DIR}/include/openauto/Projection/GSTVideoOutput.hpp ${CMAKE_SOURCE_DIR}/include/openauto/Projection/GSTVideoOutput.hpp
) )
target_include_directories(openauto SYSTEM PUBLIC target_include_directories(openauto SYSTEM PUBLIC
${QTGSTREAMER_INCLUDE_DIR} ${QTGSTREAMER_INCLUDE_DIR}
${GST_INCLUDE_DIRS} ${GST_INCLUDE_DIRS}
) )
target_link_libraries(openauto PRIVATE target_link_libraries(openauto PRIVATE
${QTGSTREAMER_LIBRARY} ${QTGSTREAMER_LIBRARY}
${GST_LIBRARIES} ${GST_LIBRARIES}
${Qt5QuickWidgets_LIBRARIES} ${Qt5QuickWidgets_LIBRARIES}
${QTGSTREAMER_QUICK_LIBRARY} ${QTGSTREAMER_QUICK_LIBRARY}
) )
endif() endif()
target_include_directories(openauto PRIVATE target_include_directories(openauto PRIVATE

View File

@ -102,8 +102,9 @@ void Configuration::load()
musicAudioChannelEnabled_ = iniConfig.get<bool>(cAudioMusicAudioChannelEnabled, true); musicAudioChannelEnabled_ = iniConfig.get<bool>(cAudioMusicAudioChannelEnabled, true);
speechAudiochannelEnabled_ = iniConfig.get<bool>(cAudioSpeechAudioChannelEnabled, true); speechAudiochannelEnabled_ = iniConfig.get<bool>(cAudioSpeechAudioChannelEnabled, true);
audioOutputBackendType_ = static_cast<AudioOutputBackendType>(iniConfig.get<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(AudioOutputBackendType::RTAUDIO))); audioOutputBackendType_ = static_cast<AudioOutputBackendType>(iniConfig.get<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(AudioOutputBackendType::RTAUDIO)));
ssid = iniConfig.get<std::string>(cWifiSSID, "");
pskey = iniConfig.get<std::string>(cWifiPskey, ""); wifiSSID_ = iniConfig.get<std::string>(cWifiSSID, "");
wifiPassword_ = iniConfig.get<std::string>(cWifiPskey, "");
} }
catch(const boost::property_tree::ini_parser_error& e) catch(const boost::property_tree::ini_parser_error& e)
{ {
@ -154,10 +155,10 @@ void Configuration::save()
iniConfig.put<bool>(cAudioMusicAudioChannelEnabled, musicAudioChannelEnabled_); iniConfig.put<bool>(cAudioMusicAudioChannelEnabled, musicAudioChannelEnabled_);
iniConfig.put<bool>(cAudioSpeechAudioChannelEnabled, speechAudiochannelEnabled_); iniConfig.put<bool>(cAudioSpeechAudioChannelEnabled, speechAudiochannelEnabled_);
iniConfig.put<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(audioOutputBackendType_)); iniConfig.put<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(audioOutputBackendType_));
iniConfig.put<std::string>(cWifiSSID, ssid);
iniConfig.put<std::string>(cWifiPskey, pskey);
boost::property_tree::ini_parser::write_ini(cConfigFileName, iniConfig);
iniConfig.put<std::string>(cWifiSSID, wifiSSID_);
iniConfig.put<std::string>(cWifiPskey, wifiPassword_);
boost::property_tree::ini_parser::write_ini(cConfigFileName, iniConfig);
} }
void Configuration::setHandednessOfTrafficType(HandednessOfTrafficType value) void Configuration::setHandednessOfTrafficType(HandednessOfTrafficType value)
@ -302,14 +303,23 @@ void Configuration::setAudioOutputBackendType(AudioOutputBackendType value)
std::string Configuration::getWifiSSID() std::string Configuration::getWifiSSID()
{ {
return ssid; return wifiSSID_;
}
void Configuration::setWifiSSID(std::string value)
{
wifiSSID_ = value;
} }
std::string Configuration::getWifiPassword() std::string Configuration::getWifiPassword()
{ {
return pskey; return wifiPassword_;
} }
void Configuration::setWifiPassword(std::string value)
{
wifiPassword_ = value;
}
void Configuration::readButtonCodes(boost::property_tree::ptree& iniConfig) void Configuration::readButtonCodes(boost::property_tree::ptree& iniConfig)
{ {

View File

@ -223,11 +223,9 @@ void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::N
controlServiceChannel_->receive(this->shared_from_this()); controlServiceChannel_->receive(this->shared_from_this());
} }
/* void AndroidAutoEntity::onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request) void AndroidAutoEntity::onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request)
{ {
OPENAUTO_LOG(info) << "[AndroidAutoEntity] Voice session request, type: " << ((request.type() == 1) ? "START" : ((request.type() == 2) ? "STOP" : "UNKNOWN"));
OPENAUTO_LOG(info) << "[AndroidAutoEntity] Voice session request, type: " << (request.type()==1)?("START"):((request.type()==2)?("STOP"):("UNKNOWN"));
auto promise = aasdk::channel::SendPromise::defer(strand_); auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));
@ -237,13 +235,14 @@ void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::N
void AndroidAutoEntity::onPingRequest(const aasdk::proto::messages::PingRequest& request) void AndroidAutoEntity::onPingRequest(const aasdk::proto::messages::PingRequest& request)
{ {
OPENAUTO_LOG(info) << "[AndroidAutoEntity] Ping Request"; OPENAUTO_LOG(info) << "[AndroidAutoEntity] Ping Request";
aasdk::proto::messages::PingResponse response; aasdk::proto::messages::PingResponse response;
response.set_timestamp(request.timestamp()); response.set_timestamp(request.timestamp());
auto promise = aasdk::channel::SendPromise::defer(strand_); auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));
controlServiceChannel_->sendPingResponse(response, std::move(promise)); controlServiceChannel_->sendPingResponse(response, std::move(promise));
controlServiceChannel_->receive(this->shared_from_this()); controlServiceChannel_->receive(this->shared_from_this());
} */ // TODO handling ping and voice session }
void AndroidAutoEntity::onPingResponse(const aasdk::proto::messages::PingResponse&) void AndroidAutoEntity::onPingResponse(const aasdk::proto::messages::PingResponse&)
{ {