refactor ws code and add remote wireless aa connect
This commit is contained in:
parent
b563281f78
commit
e30db459c6
@ -4,16 +4,12 @@
|
|||||||
|
|
||||||
namespace autoapp
|
namespace autoapp
|
||||||
{
|
{
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
|
||||||
ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITCPWrapper& tcpWrapper, openauto::configuration::IRecentAddressesList& recentAddressesList, QWidget *parent)
|
ConnectDialog::ConnectDialog(boost::asio::io_service &ioService, aasdk::tcp::ITCPWrapper &tcpWrapper, openauto::configuration::IRecentAddressesList &recentAddressesList, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent), ioService_(ioService), tcpWrapper_(tcpWrapper), recentAddressesList_(recentAddressesList), ui_(new Ui::ConnectDialog)
|
||||||
, ioService_(ioService)
|
{
|
||||||
, tcpWrapper_(tcpWrapper)
|
|
||||||
, recentAddressesList_(recentAddressesList)
|
|
||||||
, ui_(new Ui::ConnectDialog)
|
|
||||||
{
|
|
||||||
qRegisterMetaType<aasdk::tcp::ITCPEndpoint::SocketPointer>("aasdk::tcp::ITCPEndpoint::SocketPointer");
|
qRegisterMetaType<aasdk::tcp::ITCPEndpoint::SocketPointer>("aasdk::tcp::ITCPEndpoint::SocketPointer");
|
||||||
qRegisterMetaType<std::string>("std::string");
|
qRegisterMetaType<std::string>("std::string");
|
||||||
|
|
||||||
@ -26,33 +22,33 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC
|
|||||||
|
|
||||||
ui_->listViewRecent->setModel(&recentAddressesModel_);
|
ui_->listViewRecent->setModel(&recentAddressesModel_);
|
||||||
this->loadRecentList();
|
this->loadRecentList();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectDialog::~ConnectDialog()
|
ConnectDialog::~ConnectDialog()
|
||||||
{
|
{
|
||||||
delete ui_;
|
delete ui_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::onConnectButtonClicked()
|
void ConnectDialog::onConnectButtonClicked()
|
||||||
{
|
{
|
||||||
this->setControlsEnabledStatus(false);
|
this->setControlsEnabledStatus(false);
|
||||||
|
|
||||||
const auto& ipAddress = ui_->lineEditIPAddress->text().toStdString();
|
const auto &ipAddress = ui_->lineEditIPAddress->text().toStdString();
|
||||||
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket));
|
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket));
|
||||||
}
|
}
|
||||||
catch(const boost::system::system_error& se)
|
catch (const boost::system::system_error &se)
|
||||||
{
|
{
|
||||||
emit connectionFailed(QString(se.what()));
|
emit connectionFailed(QString(se.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::connectHandler(const boost::system::error_code& ec, const std::string& ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
|
void ConnectDialog::connectHandler(const boost::system::error_code &ec, const std::string &ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
|
||||||
{
|
{
|
||||||
if(!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
emit connectionSucceed(std::move(socket), ipAddress);
|
emit connectionSucceed(std::move(socket), ipAddress);
|
||||||
this->close();
|
this->close();
|
||||||
@ -61,59 +57,72 @@ void ConnectDialog::connectHandler(const boost::system::error_code& ec, const st
|
|||||||
{
|
{
|
||||||
emit connectionFailed(QString::fromStdString(ec.message()));
|
emit connectionFailed(QString::fromStdString(ec.message()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer, const std::string& ipAddress)
|
void ConnectDialog::onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer, const std::string &ipAddress)
|
||||||
{
|
{
|
||||||
this->insertIpAddress(ipAddress);
|
this->insertIpAddress(ipAddress);
|
||||||
this->setControlsEnabledStatus(true);
|
this->setControlsEnabledStatus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::onConnectionFailed(const QString& message)
|
void ConnectDialog::onConnectionFailed(const QString &message)
|
||||||
{
|
{
|
||||||
this->setControlsEnabledStatus(true);
|
this->setControlsEnabledStatus(true);
|
||||||
|
|
||||||
QMessageBox errorMessage(QMessageBox::Critical, "Connect error", message, QMessageBox::Ok);
|
QMessageBox errorMessage(QMessageBox::Critical, "Connect error", message, QMessageBox::Ok);
|
||||||
errorMessage.setWindowFlags(Qt::WindowStaysOnTopHint);
|
errorMessage.setWindowFlags(Qt::WindowStaysOnTopHint);
|
||||||
errorMessage.exec();
|
errorMessage.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::onRecentAddressClicked(const QModelIndex& index)
|
void ConnectDialog::onRecentAddressClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
const auto& recentAddressesList = recentAddressesList_.getList();
|
const auto &recentAddressesList = recentAddressesList_.getList();
|
||||||
|
|
||||||
if(static_cast<size_t>(index.row()) <= recentAddressesList.size())
|
if (static_cast<size_t>(index.row()) <= recentAddressesList.size())
|
||||||
{
|
{
|
||||||
ui_->lineEditIPAddress->setText(QString::fromStdString(recentAddressesList.at(index.row())));
|
ui_->lineEditIPAddress->setText(QString::fromStdString(recentAddressesList.at(index.row())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::setControlsEnabledStatus(bool status)
|
void ConnectDialog::setControlsEnabledStatus(bool status)
|
||||||
{
|
{
|
||||||
ui_->pushButtonConnect->setVisible(status);
|
ui_->pushButtonConnect->setVisible(status);
|
||||||
ui_->pushButtonCancel->setEnabled(status);
|
ui_->pushButtonCancel->setEnabled(status);
|
||||||
ui_->lineEditIPAddress->setEnabled(status);
|
ui_->lineEditIPAddress->setEnabled(status);
|
||||||
ui_->listViewRecent->setEnabled(status);
|
ui_->listViewRecent->setEnabled(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::loadRecentList()
|
void ConnectDialog::loadRecentList()
|
||||||
{
|
{
|
||||||
QStringList stringList;
|
QStringList stringList;
|
||||||
const auto& configList = recentAddressesList_.getList();
|
const auto &configList = recentAddressesList_.getList();
|
||||||
|
|
||||||
for(const auto& element : configList)
|
for (const auto &element : configList)
|
||||||
{
|
{
|
||||||
stringList.append(QString::fromStdString(element));
|
stringList.append(QString::fromStdString(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
recentAddressesModel_.setStringList(stringList);
|
recentAddressesModel_.setStringList(stringList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::insertIpAddress(const std::string& ipAddress)
|
void ConnectDialog::insertIpAddress(const std::string &ipAddress)
|
||||||
{
|
{
|
||||||
recentAddressesList_.insertAddress(ipAddress);
|
recentAddressesList_.insertAddress(ipAddress);
|
||||||
this->loadRecentList();
|
this->loadRecentList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void ConnectDialog::connectToAddress(const QString &ip)
|
||||||
|
{
|
||||||
|
const auto &ipAddress = ip.toStdString();
|
||||||
|
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket));
|
||||||
|
}
|
||||||
|
catch (const boost::system::system_error &se)
|
||||||
|
{
|
||||||
|
emit connectionFailed(QString(se.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtWebSockets/QWebSocket>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonParseError>
|
|
||||||
|
|
||||||
#include "autoapp/UI/MainWindow.hpp"
|
#include "autoapp/UI/MainWindow.hpp"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
@ -32,77 +28,25 @@ namespace autoapp
|
|||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), ui_(new Ui::MainWindow), webSocket(new QWebSocket),
|
: QMainWindow(parent), ui_(new Ui::MainWindow)
|
||||||
reconnectTimer(new QTimer(this)),
|
|
||||||
shuttingDown(false)
|
|
||||||
{
|
{
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::openSettings);
|
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::openSettings);
|
||||||
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit);
|
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit);
|
||||||
connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor);
|
connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor);
|
||||||
connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog);
|
connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog);
|
||||||
|
|
||||||
// RADIO WEBSOCKET STUFF
|
|
||||||
reconnectTimer->setSingleShot(true);
|
|
||||||
reconnectTimer->setInterval(3000);
|
|
||||||
|
|
||||||
connect(reconnectTimer, &QTimer::timeout, this, &MainWindow::connectWebSocket);
|
|
||||||
|
|
||||||
connect(webSocket, &QWebSocket::connected, this, [this]()
|
|
||||||
{
|
|
||||||
qDebug() << "WebSocket connected";
|
|
||||||
webSocket->sendTextMessage(QStringLiteral("Hello from MainWindow WebSocket!")); });
|
|
||||||
|
|
||||||
connect(webSocket, &QWebSocket::textMessageReceived, this, [this](const QString &message)
|
|
||||||
{
|
|
||||||
qDebug() << "Message received:" << message;
|
|
||||||
handleIncomingMessage(message); });
|
|
||||||
|
|
||||||
connect(webSocket, &QWebSocket::disconnected, this, [this]()
|
|
||||||
{
|
|
||||||
qDebug() << "WebSocket disconnected";
|
|
||||||
if (!shuttingDown) {
|
|
||||||
qDebug() << "Attempting to reconnect in 3 seconds...";
|
|
||||||
reconnectTimer->start();
|
|
||||||
} });
|
|
||||||
|
|
||||||
connect(webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
|
|
||||||
this, [this](QAbstractSocket::SocketError)
|
|
||||||
{ qDebug() << "WebSocket error:" << webSocket->errorString(); });
|
|
||||||
|
|
||||||
connectWebSocket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
shuttingDown = true;
|
|
||||||
webSocket->abort();
|
|
||||||
webSocket->deleteLater();
|
|
||||||
delete ui_;
|
delete ui_;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoapp::ui::MainWindow::connectWebSocket()
|
void autoapp::ui::MainWindow::handleIncomingMessage(const QJsonObject &rootObj)
|
||||||
{
|
{
|
||||||
QUrl url(QStringLiteral("ws://127.0.0.1:5000")); // Change to your real server
|
|
||||||
qDebug() << "Connecting to WebSocket:" << url;
|
|
||||||
webSocket->open(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void autoapp::ui::MainWindow::handleIncomingMessage(const QString &message)
|
|
||||||
{
|
|
||||||
qDebug() << "[Handler] Processing message:" << message;
|
|
||||||
|
|
||||||
QJsonParseError error;
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error);
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
qDebug() << "JSON parse error:" << error.errorString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject rootObj = doc.object();
|
|
||||||
if (rootObj.contains("bluetooth")) {
|
if (rootObj.contains("bluetooth")) {
|
||||||
ui_->stackedWidget->setCurrentIndex(0);
|
ui_->stackedWidget->setCurrentIndex(0);
|
||||||
QJsonObject btObj = rootObj["bluetooth"].toObject();
|
QJsonObject btObj = rootObj["bluetooth"].toObject();
|
||||||
@ -121,5 +65,8 @@ void autoapp::ui::MainWindow::handleIncomingMessage(const QString &message)
|
|||||||
ui_->radioScreen->setText(radioObj["screen"].toString());
|
ui_->radioScreen->setText(radioObj["screen"].toString());
|
||||||
ui_->radioPreset->setText(radioObj["preset"].toString());
|
ui_->radioPreset->setText(radioObj["preset"].toString());
|
||||||
ui_->radioSecondLine->setText(radioObj["second"].toString());
|
ui_->radioSecondLine->setText(radioObj["second"].toString());
|
||||||
|
} else if (rootObj.contains("connect_wireless_aa")) {
|
||||||
|
QJsonObject aaObj = rootObj["connect_wireless_aa"].toObject();
|
||||||
|
//connectWirelessAndroidAuto(aaObj["address"].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,11 @@
|
|||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QtWebSockets/QWebSocket>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonParseError>
|
||||||
#include "aasdk/USB/USBHub.hpp"
|
#include "aasdk/USB/USBHub.hpp"
|
||||||
#include "aasdk/USB/ConnectedAccessoriesEnumerator.hpp"
|
#include "aasdk/USB/ConnectedAccessoriesEnumerator.hpp"
|
||||||
#include "aasdk/USB/AccessoryModeQueryChain.hpp"
|
#include "aasdk/USB/AccessoryModeQueryChain.hpp"
|
||||||
@ -38,12 +43,13 @@
|
|||||||
using namespace openauto;
|
using namespace openauto;
|
||||||
using ThreadPool = std::vector<std::thread>;
|
using ThreadPool = std::vector<std::thread>;
|
||||||
|
|
||||||
void startUSBWorkers(boost::asio::io_service& ioService, libusb_context* usbContext, ThreadPool& threadPool)
|
void startUSBWorkers(boost::asio::io_service &ioService, libusb_context *usbContext, ThreadPool &threadPool)
|
||||||
{
|
{
|
||||||
auto usbWorker = [&ioService, usbContext]() {
|
auto usbWorker = [&ioService, usbContext]()
|
||||||
|
{
|
||||||
timeval libusbEventTimeout{180, 0};
|
timeval libusbEventTimeout{180, 0};
|
||||||
|
|
||||||
while(!ioService.stopped())
|
while (!ioService.stopped())
|
||||||
{
|
{
|
||||||
libusb_handle_events_timeout_completed(usbContext, &libusbEventTimeout, nullptr);
|
libusb_handle_events_timeout_completed(usbContext, &libusbEventTimeout, nullptr);
|
||||||
}
|
}
|
||||||
@ -55,9 +61,10 @@ void startUSBWorkers(boost::asio::io_service& ioService, libusb_context* usbCont
|
|||||||
threadPool.emplace_back(usbWorker);
|
threadPool.emplace_back(usbWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threadPool)
|
void startIOServiceWorkers(boost::asio::io_service &ioService, ThreadPool &threadPool)
|
||||||
{
|
{
|
||||||
auto ioServiceWorker = [&ioService]() {
|
auto ioServiceWorker = [&ioService]()
|
||||||
|
{
|
||||||
ioService.run();
|
ioService.run();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,10 +74,10 @@ void startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threa
|
|||||||
threadPool.emplace_back(ioServiceWorker);
|
threadPool.emplace_back(ioServiceWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
libusb_context* usbContext;
|
libusb_context *usbContext;
|
||||||
if(libusb_init(&usbContext) != 0)
|
if (libusb_init(&usbContext) != 0)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
||||||
return 1;
|
return 1;
|
||||||
@ -97,15 +104,16 @@ int main(int argc, char* argv[])
|
|||||||
autoapp::ui::ConnectDialog connectDialog(ioService, tcpWrapper, recentAddressesList);
|
autoapp::ui::ConnectDialog connectDialog(ioService, tcpWrapper, recentAddressesList);
|
||||||
connectDialog.setWindowFlags(Qt::WindowStaysOnTopHint);
|
connectDialog.setWindowFlags(Qt::WindowStaysOnTopHint);
|
||||||
|
|
||||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []()
|
||||||
|
{ std::exit(0); });
|
||||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
|
||||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openConnectDialog, &connectDialog, &autoapp::ui::ConnectDialog::exec);
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openConnectDialog, &connectDialog, &autoapp::ui::ConnectDialog::exec);
|
||||||
|
|
||||||
qApplication.setOverrideCursor(Qt::BlankCursor);
|
qApplication.setOverrideCursor(Qt::BlankCursor);
|
||||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&qApplication]() {
|
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&qApplication]()
|
||||||
|
{
|
||||||
const auto cursor = qApplication.overrideCursor()->shape() == Qt::BlankCursor ? Qt::ArrowCursor : Qt::BlankCursor;
|
const auto cursor = qApplication.overrideCursor()->shape() == Qt::BlankCursor ? Qt::ArrowCursor : Qt::BlankCursor;
|
||||||
qApplication.setOverrideCursor(cursor);
|
qApplication.setOverrideCursor(cursor); });
|
||||||
});
|
|
||||||
|
|
||||||
mainWindow.showFullScreen();
|
mainWindow.showFullScreen();
|
||||||
|
|
||||||
@ -119,12 +127,62 @@ int main(int argc, char* argv[])
|
|||||||
auto connectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper, ioService, queryChainFactory));
|
auto connectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper, ioService, queryChainFactory));
|
||||||
auto app = std::make_shared<openauto::App>(ioService, usbWrapper, tcpWrapper, androidAutoEntityFactory, std::move(usbHub), std::move(connectedAccessoriesEnumerator));
|
auto app = std::make_shared<openauto::App>(ioService, usbWrapper, tcpWrapper, androidAutoEntityFactory, std::move(usbHub), std::move(connectedAccessoriesEnumerator));
|
||||||
|
|
||||||
QObject::connect(&connectDialog, &autoapp::ui::ConnectDialog::connectionSucceed, [&app](auto socket) {
|
QObject::connect(&connectDialog, &autoapp::ui::ConnectDialog::connectionSucceed, [&app](auto socket)
|
||||||
app->start(std::move(socket));
|
{ app->start(std::move(socket)); });
|
||||||
});
|
|
||||||
|
|
||||||
app->waitForDevice(true);
|
app->waitForDevice(true);
|
||||||
|
|
||||||
|
QWebSocket webSocket;
|
||||||
|
QTimer reconnectTimer;
|
||||||
|
const QUrl websocketUrl(QStringLiteral("ws://127.0.0.1:5959/ws"));
|
||||||
|
|
||||||
|
auto tryConnect = [&webSocket, &websocketUrl]()
|
||||||
|
{
|
||||||
|
if (webSocket.state() != QAbstractSocket::ConnectedState &&
|
||||||
|
webSocket.state() != QAbstractSocket::ConnectingState)
|
||||||
|
{
|
||||||
|
qDebug() << "[WebSocket] Attempting to connect to" << websocketUrl.toString();
|
||||||
|
webSocket.open(websocketUrl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connect events
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::connected, [&]()
|
||||||
|
{
|
||||||
|
qDebug() << "[WebSocket] Connected.";
|
||||||
|
webSocket.sendTextMessage("Hello from OpenAuto WebSocket client!");
|
||||||
|
reconnectTimer.stop(); });
|
||||||
|
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::disconnected, [&]()
|
||||||
|
{
|
||||||
|
qDebug() << "[WebSocket] Disconnected. Will retry...";
|
||||||
|
reconnectTimer.start(3000); });
|
||||||
|
|
||||||
|
QObject::connect(&webSocket, &QWebSocket::textMessageReceived, [&mainWindow, &connectDialog](const QString &message)
|
||||||
|
{
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error);
|
||||||
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
qDebug() << "JSON parse error:" << error.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QJsonObject rootObj = doc.object();
|
||||||
|
if (rootObj.contains("wireless_aa_ip")) {
|
||||||
|
QString ipAddr = rootObj["wireless_aa_ip"].toString();
|
||||||
|
connectDialog.connectToAddress(ipAddr);
|
||||||
|
}
|
||||||
|
else if (rootObj.contains("button")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mainWindow.handleIncomingMessage(rootObj);
|
||||||
|
} });
|
||||||
|
|
||||||
|
reconnectTimer.setInterval(3000);
|
||||||
|
reconnectTimer.setSingleShot(true);
|
||||||
|
QObject::connect(&reconnectTimer, &QTimer::timeout, tryConnect);
|
||||||
|
tryConnect();
|
||||||
|
|
||||||
auto result = qApplication.exec();
|
auto result = qApplication.exec();
|
||||||
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class ConnectDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITCPWrapper& tcpWrapper, openauto::configuration::IRecentAddressesList& recentAddressesList, QWidget *parent = nullptr);
|
explicit ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITCPWrapper& tcpWrapper, openauto::configuration::IRecentAddressesList& recentAddressesList, QWidget *parent = nullptr);
|
||||||
~ConnectDialog() override;
|
~ConnectDialog() override;
|
||||||
|
void connectToAddress(const QString& ip);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectToDevice(const QString& ipAddress);
|
void connectToDevice(const QString& ipAddress);
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QtWebSockets/QWebSocket>
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -38,6 +37,7 @@ namespace autoapp
|
|||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow() override;
|
~MainWindow() override;
|
||||||
|
void handleIncomingMessage(const QJsonObject &rootObj);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void exit();
|
void exit();
|
||||||
@ -46,15 +46,9 @@ namespace autoapp
|
|||||||
void openConnectDialog();
|
void openConnectDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void connectWebSocket();
|
|
||||||
void handleIncomingMessage(const QString &message);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui_;
|
Ui::MainWindow *ui_;
|
||||||
QWebSocket *webSocket;
|
|
||||||
QTimer *reconnectTimer;
|
|
||||||
bool shuttingDown;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ void Configuration::load()
|
|||||||
videoMargins_ = QRect(0, 0, iniConfig.get<int32_t>(cVideoMarginWidth, 0), iniConfig.get<int32_t>(cVideoMarginHeight, 0));
|
videoMargins_ = QRect(0, 0, iniConfig.get<int32_t>(cVideoMarginWidth, 0), iniConfig.get<int32_t>(cVideoMarginHeight, 0));
|
||||||
whitescreenWorkaround_ = iniConfig.get<bool>(cVideoWhitescreenWorkaround, true);
|
whitescreenWorkaround_ = iniConfig.get<bool>(cVideoWhitescreenWorkaround, true);
|
||||||
|
|
||||||
enableTouchscreen_ = iniConfig.get<bool>(cInputEnableTouchscreenKey, true);
|
enableTouchscreen_ = iniConfig.get<bool>(cInputEnableTouchscreenKey, false);
|
||||||
this->readButtonCodes(iniConfig);
|
this->readButtonCodes(iniConfig);
|
||||||
|
|
||||||
bluetoothAdapterType_ = static_cast<BluetoothAdapterType>(iniConfig.get<uint32_t>(cBluetoothAdapterTypeKey,
|
bluetoothAdapterType_ = static_cast<BluetoothAdapterType>(iniConfig.get<uint32_t>(cBluetoothAdapterTypeKey,
|
||||||
@ -134,7 +134,7 @@ void Configuration::reset()
|
|||||||
omxLayerIndex_ = 1;
|
omxLayerIndex_ = 1;
|
||||||
videoMargins_ = QRect(0, 0, 0, 0);
|
videoMargins_ = QRect(0, 0, 0, 0);
|
||||||
whitescreenWorkaround_ = true;
|
whitescreenWorkaround_ = true;
|
||||||
enableTouchscreen_ = true;
|
enableTouchscreen_ = false;
|
||||||
buttonCodes_.clear();
|
buttonCodes_.clear();
|
||||||
bluetoothAdapterType_ = BluetoothAdapterType::NONE;
|
bluetoothAdapterType_ = BluetoothAdapterType::NONE;
|
||||||
bluetoothRemoteAdapterAddress_ = "";
|
bluetoothRemoteAdapterAddress_ = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user