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:
parent
ae66394b6b
commit
23c38158ee
16
.gitignore
vendored
16
.gitignore
vendored
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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_)
|
||||||
|
{
|
||||||
|
case ConnectionStatus::IDLE:
|
||||||
|
case ConnectionStatus::SENT_SOCKETINFO_MESSAGE:
|
||||||
|
case ConnectionStatus::SENT_NETWORKINFO_MESSAGE:
|
||||||
|
case ConnectionStatus::PHONE_RESP_NETWORKINFO:
|
||||||
|
case ConnectionStatus::ERROR:
|
||||||
break;
|
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:
|
||||||
|
handshakeState_ = ConnectionStatus::SENDING_NETWORKINFO_MESSAGE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PHONE_RESP_SOCKETINFO:
|
case ConnectionStatus::SENDING_NETWORKINFO_MESSAGE:
|
||||||
handshakeState = SENDING_NETWORKINFO_MESSAGE;
|
this->writeNetworkInfoMessage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SENDING_NETWORKINFO_MESSAGE:
|
|
||||||
writeNetworkInfoMessage();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SENT_NETWORKINFO_MESSAGE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PHONE_RESP_NETWORKINFO:
|
|
||||||
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;
|
QString ipAddr;
|
||||||
QList<QHostAddress> list = QNetworkInterface::allAddresses();
|
foreach(QHostAddress addr, QNetworkInterface::allAddresses())
|
||||||
|
|
||||||
for(int nIter=0; nIter<list.count(); nIter++)
|
|
||||||
{
|
{
|
||||||
if(!list[nIter].isLoopback())
|
if(!addr.isLoopback() && (addr.protocol() == QAbstractSocket::IPv4Protocol))
|
||||||
if (list[nIter].protocol() == QAbstractSocket::IPv4Protocol )
|
{
|
||||||
ipAddr = list[nIter].toString();
|
ipAddr = addr.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
btservice::proto::SocketInfo socketInfo;
|
||||||
socketInfo.set_address(ipAddr.toStdString());
|
socketInfo.set_address(ipAddr.toStdString());
|
||||||
socketInfo.set_port(5000);
|
socketInfo.set_port(5000);
|
||||||
socketInfo.set_unknown_1(0);
|
socketInfo.set_unknown_1(0);
|
||||||
|
|
||||||
if(writeProtoMessage(7, socketInfo)){
|
if(this->writeProtoMessage(7, socketInfo))
|
||||||
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent Socket Info";
|
{
|
||||||
handshakeState = SENT_SOCKETINFO_MESSAGE;
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Sent socket info.";
|
||||||
|
handshakeState_ = ConnectionStatus::SENT_SOCKETINFO_MESSAGE;
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
OPENAUTO_LOG(error) << "[AndroidBluetoothServer] Error Sending Socket Info";
|
{
|
||||||
handshakeState = ERROR;
|
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;
|
return;
|
||||||
QByteArray data = socket->read(1024);
|
}
|
||||||
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:
|
case 2:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
resp.ParseFromString(data.toStdString().c_str());
|
resp.ParseFromString(data.toStdString().c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
switch(handshakeState){
|
|
||||||
case IDLE:
|
switch(handshakeState_)
|
||||||
|
{
|
||||||
|
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;
|
break;
|
||||||
|
|
||||||
case DEVICE_CONNECTED:
|
case ConnectionStatus::SENT_SOCKETINFO_MESSAGE:
|
||||||
|
if(messageType == 2)
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged socket info.";
|
||||||
|
handshakeState_ = ConnectionStatus::PHONE_RESP_SOCKETINFO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Got unexpected message.";
|
||||||
|
handshakeState_ = ConnectionStatus::ERROR;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SENDING_SOCKETINFO_MESSAGE:
|
case ConnectionStatus::SENT_NETWORKINFO_MESSAGE:
|
||||||
break;
|
if(messageType == 6)
|
||||||
|
{
|
||||||
case SENT_SOCKETINFO_MESSAGE:
|
OPENAUTO_LOG(info) << "[AndroidBluetoothServer] Phone acknowledged network info with status code: " << resp.status_code();
|
||||||
if(messageType == 2){
|
handshakeState_ = ConnectionStatus::PHONE_RESP_NETWORKINFO;
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
address = adapters.at(0).address();
|
||||||
else{
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
@ -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;
|
||||||
|
@ -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,29 +18,8 @@ namespace openauto
|
|||||||
namespace btservice
|
namespace btservice
|
||||||
{
|
{
|
||||||
|
|
||||||
class AndroidBluetoothServer: public QObject, public IAndroidBluetoothServer
|
enum class ConnectionStatus
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config_);
|
|
||||||
|
|
||||||
bool start(const QBluetoothAddress& address, uint16_t portNumber) override;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onClientConnected();
|
|
||||||
void readSocket();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<QBluetoothServer> rfcommServer_;
|
|
||||||
QBluetoothSocket* socket;
|
|
||||||
|
|
||||||
void writeSocketInfoMessage();
|
|
||||||
void writeNetworkInfoMessage();
|
|
||||||
void stateMachine();
|
|
||||||
bool writeProtoMessage(uint16_t messageType, google::protobuf::Message &message);
|
|
||||||
|
|
||||||
enum CONNECTION_STATUS {
|
|
||||||
IDLE,
|
IDLE,
|
||||||
DEVICE_CONNECTED,
|
DEVICE_CONNECTED,
|
||||||
SENDING_SOCKETINFO_MESSAGE,
|
SENDING_SOCKETINFO_MESSAGE,
|
||||||
@ -51,9 +31,29 @@ private:
|
|||||||
ERROR
|
ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
CONNECTION_STATUS handshakeState = IDLE;
|
class AndroidBluetoothServer: public QObject, public IAndroidBluetoothServer
|
||||||
protected:
|
{
|
||||||
openauto::configuration::IConfiguration::Pointer config;
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AndroidBluetoothServer(openauto::configuration::IConfiguration::Pointer config);
|
||||||
|
bool start(const QBluetoothAddress& address, uint16_t portNumber) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onClientConnected();
|
||||||
|
void readSocket();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<QBluetoothServer> rfcommServer_;
|
||||||
|
QBluetoothSocket* socket_;
|
||||||
|
openauto::configuration::IConfiguration::Pointer config_;
|
||||||
|
std::atomic<ConnectionStatus> handshakeState_;
|
||||||
|
|
||||||
|
void writeSocketInfoMessage();
|
||||||
|
void writeNetworkInfoMessage();
|
||||||
|
void eventLoop();
|
||||||
|
bool writeProtoMessage(uint16_t messageType, google::protobuf::Message& message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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:
|
public:
|
||||||
btservice(openauto::configuration::IConfiguration::Pointer config);
|
btservice(openauto::configuration::IConfiguration::Pointer config);
|
||||||
private:
|
|
||||||
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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
@ -34,6 +27,13 @@ add_library(openauto SHARED
|
|||||||
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
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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&)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user