mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
main window
Now working with websocket
This commit is contained in:
+46
-80
@@ -8,45 +8,33 @@
|
|||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
api(new OpenAPI::OAICANApiApi()),
|
m_web_socket(new Web_socket_wrapper(QUrl("ws://localhost:9002"), this)),
|
||||||
error_dialog(new NetworkError(this)),
|
error_dialog(new NetworkError(this)),
|
||||||
sims{{"CANDebugger", new Can_Debugger(api, this)},
|
sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)},
|
||||||
{"Scope_Mux_Tester", new Scope_Mux_Tester(api, this)},
|
{"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)},
|
||||||
{"CVS_I10", new CVS_I10(api, this)}}
|
{"CVS_I10", new CVS_I10(m_web_socket, this)}}
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setWindowTitle("Simulator Selector");
|
this->setWindowTitle("Simulator Selector");
|
||||||
connect(this, &MainWindow::quit, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
|
||||||
|
|
||||||
api->setNewServerForAllOperations(
|
|
||||||
//QUrl("http://localhost:1880"),
|
|
||||||
QUrl("https://cvs-i10.local/api"),
|
|
||||||
"No description provided",
|
|
||||||
QMap<QString, OpenAPI::OAIServerVariable>());
|
|
||||||
api->apiCanapiSimsGet();
|
|
||||||
|
|
||||||
//Default sim
|
//Default sim
|
||||||
defaultSim("CVS_I10");
|
//defaultSim("CVS_I10");
|
||||||
|
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, [=]{open_sim(ui->comboBox->currentText());});
|
connect(ui->pushButton, &QPushButton::clicked, this, [=]{open_sim(ui->comboBox->currentText());});
|
||||||
|
connect(this, &MainWindow::quit, this, &QCoreApplication::quit, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
delete api;
|
delete m_web_socket;
|
||||||
delete error_dialog;
|
delete error_dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setup_cb(void)
|
void MainWindow::setup_cb(void)
|
||||||
{
|
{
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiSimsGetSignal, this, [=](QList<QString> summary){Parse_Sims(summary);});
|
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=](json& j){on_cmd_cb(j);});
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiSimsGetSignalError, this, [=](QList<QString> summary, QNetworkReply::NetworkError error_type, const QString &error_str){Parse_Sims(summary, error_type, error_str);});
|
connect(m_web_socket, &Web_socket_wrapper::on_connected, this, [=]{m_web_socket->send_command(Web_socket_wrapper::Command::get_simulators);});
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiCurrentsimPutSignal, this, [this](bool output){apiCanapiUielements_bool_cb(output);});
|
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiCurrentsimPutSignalError, this, [this](bool output, QNetworkReply::NetworkError error_type, QString error_str){
|
|
||||||
apiCanapiUielements_bool_cb(false, error_type, error_str);});
|
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiCurrentsimGetSignal, this, [this](OpenAPI::OAISimulatorInfo summary){apiCanapiCurrentsimGet_cb(summary);});
|
|
||||||
connect(api, &OpenAPI::OAICANApiApi::apiCanapiCurrentsimGetSignalError, this, [this](OpenAPI::OAISimulatorInfo summary, QNetworkReply::NetworkError error_type, QString error_str){apiCanapiCurrentsimGet_cb(OpenAPI::OAISimulatorInfo(), error_type, error_str);});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent( QShowEvent* event )
|
void MainWindow::showEvent( QShowEvent* event )
|
||||||
@@ -58,7 +46,7 @@ void MainWindow::showEvent( QShowEvent* event )
|
|||||||
void MainWindow::hideEvent(QHideEvent* event)
|
void MainWindow::hideEvent(QHideEvent* event)
|
||||||
{
|
{
|
||||||
QWidget::hideEvent(event);
|
QWidget::hideEvent(event);
|
||||||
disconnect(api, nullptr, nullptr, nullptr);
|
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::defaultSim(QString name)
|
void MainWindow::defaultSim(QString name)
|
||||||
@@ -67,23 +55,11 @@ void MainWindow::defaultSim(QString name)
|
|||||||
this->default_sim = true;
|
this->default_sim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::Parse_Sims(QList<QString> sims, QNetworkReply::NetworkError error_type, const QString error_str)
|
void MainWindow::pase_sim_names(json& sims)
|
||||||
{
|
{
|
||||||
if (error_type) {
|
for (json& item : sims)
|
||||||
QD << "( " << error_type << "," << error_str << ")";
|
|
||||||
error_dialog->set_error(error_str + "\n" + network_reply_to_fix(error_type));
|
|
||||||
error_dialog->open();
|
|
||||||
return;
|
|
||||||
} if (sims.empty()) {
|
|
||||||
QD << " got called with invalid data and no error!";
|
|
||||||
error_dialog->set_error(QString(__FUNCTION__) + " got called with invalid data and no error!");
|
|
||||||
error_dialog->open();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < sims.length(); i++)
|
|
||||||
{
|
{
|
||||||
ui->comboBox->addItem(sims[i]);
|
ui->comboBox->addItem(QString::fromStdString(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
QThread::msleep(30);
|
QThread::msleep(30);
|
||||||
@@ -108,7 +84,7 @@ void MainWindow::open_sim(QString sim_name)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
api->apiCanapiCurrentsimGet();
|
m_web_socket->send_command(Web_socket_wrapper::Command::get_active_simulator_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::open_sim_window(void)
|
void MainWindow::open_sim_window(void)
|
||||||
@@ -117,53 +93,43 @@ void MainWindow::open_sim_window(void)
|
|||||||
selected_sim->show();
|
selected_sim->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::apiCanapiUielements_bool_cb(bool output, QNetworkReply::NetworkError error_type, QString error_str)
|
void MainWindow::check_active_sim(QString name)
|
||||||
{
|
{
|
||||||
if (error_type) {
|
if (name == "")
|
||||||
QD << "( " << Qt::hex << output << "," << error_type << "," << error_str << ")";
|
{
|
||||||
error_dialog->set_error(error_str + "\n" + network_reply_to_fix(error_type));
|
QD << "Name not set";
|
||||||
error_dialog->open();
|
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, selected_sim_name);
|
||||||
return;
|
return;
|
||||||
} if (!output) {
|
}
|
||||||
QD << " got called with invalid data and no error!";
|
|
||||||
error_dialog->set_error(QString(__FUNCTION__) + " got called with invalid data and no error!");
|
|
||||||
error_dialog->open();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
open_sim_window();
|
QD << "Current sim:" << name;
|
||||||
|
|
||||||
|
if (name == selected_sim_name)
|
||||||
|
{
|
||||||
|
QD << "Name set and right";
|
||||||
|
open_sim_window();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QD << "Name set and wrong";
|
||||||
|
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, selected_sim_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::apiCanapiCurrentsimGet_cb(OpenAPI::OAISimulatorInfo summary, QNetworkReply::NetworkError error_type, QString error_str)
|
void MainWindow::on_cmd_cb(json& j)
|
||||||
{
|
{
|
||||||
if (error_type) {
|
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Command::end);
|
||||||
QD << "( " << summary.asJson() << "," << error_type << "," << error_str << ")";
|
switch (response)
|
||||||
error_dialog->set_error(error_str + "\n" + network_reply_to_fix(error_type));
|
|
||||||
error_dialog->open();
|
|
||||||
return;
|
|
||||||
} if (!summary.isValid()) {
|
|
||||||
QD << " got called with invalid data and no error!";
|
|
||||||
error_dialog->set_error(QString(__FUNCTION__) + " got called with invalid data and no error!");
|
|
||||||
error_dialog->open();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!summary.is_name_Set())
|
|
||||||
{
|
{
|
||||||
QD << "Name not set";
|
case Web_socket_wrapper::Command::get_simulators:
|
||||||
api->apiCanapiCurrentsimPut(selected_sim_name);
|
pase_sim_names(j.at("simulators"));
|
||||||
return;
|
break;
|
||||||
|
case Web_socket_wrapper::Command::get_active_simulator_name:
|
||||||
|
check_active_sim(QString::fromStdString(j.at("name")));
|
||||||
|
break;
|
||||||
|
case Web_socket_wrapper::Command::switch_simulator:
|
||||||
|
open_sim_window();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QD << "Current sim:" << summary.getName();
|
|
||||||
|
|
||||||
if (summary.getName() == selected_sim_name)
|
|
||||||
{
|
|
||||||
QD << "Name set and right";
|
|
||||||
open_sim_window();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QD << "Name set and wrong";
|
|
||||||
api->apiCanapiCurrentsimPut(selected_sim_name);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "OAICANApiApi.h"
|
#include "web_socket_wrapper.h"
|
||||||
#include "networkerror.h"
|
#include "networkerror.h"
|
||||||
#include "simulatorbase.h"
|
#include "simulatorbase.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
@@ -21,24 +21,25 @@ class MainWindow : public QMainWindow
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
void defaultSim(QString name);
|
void defaultSim(QString name);
|
||||||
void Parse_Sims(QList<QString> sims, QNetworkReply::NetworkError error_type = QNetworkReply::NetworkError::NoError, QString error_str = QString());
|
void pase_sim_names(json& sims);
|
||||||
void apiCanapiUielements_bool_cb(bool ret, QNetworkReply::NetworkError error_type = QNetworkReply::NetworkError::NoError, QString error_str = QString());
|
|
||||||
void apiCanapiCurrentsimGet_cb(OpenAPI::OAISimulatorInfo summary, QNetworkReply::NetworkError error_type = QNetworkReply::NetworkError::NoError, QString error_str = QString());
|
|
||||||
void open_sim_window(void);
|
void open_sim_window(void);
|
||||||
|
void check_active_sim(QString name);
|
||||||
void open_sim(QString sim_name);
|
void open_sim(QString sim_name);
|
||||||
void setup_cb(void);
|
void setup_cb(void);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void quit(void);
|
void quit(void);
|
||||||
private:
|
private:
|
||||||
void showEvent( QShowEvent* event );
|
void showEvent(QShowEvent* event);
|
||||||
void hideEvent(QHideEvent* event);
|
void hideEvent(QHideEvent* event);
|
||||||
|
|
||||||
|
void on_cmd_cb(json& j);
|
||||||
|
|
||||||
bool default_sim = false;
|
bool default_sim = false;
|
||||||
QString selected_sim_name;
|
QString selected_sim_name;
|
||||||
QMainWindow* selected_sim;
|
QMainWindow* selected_sim;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
OpenAPI::OAICANApiApi *api;
|
Web_socket_wrapper *m_web_socket;
|
||||||
NetworkError* error_dialog;
|
NetworkError* error_dialog;
|
||||||
|
|
||||||
std::map<QString, SimulatorBase*> sims;
|
std::map<QString, SimulatorBase*> sims;
|
||||||
|
|||||||
Reference in New Issue
Block a user