diff --git a/Qt/main.cpp b/Qt/main.cpp index fd3e533..fd2b13c 100644 --- a/Qt/main.cpp +++ b/Qt/main.cpp @@ -5,7 +5,27 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; + QCommandLineParser parser; + parser.setApplicationDescription("sim-us client"); + parser.addHelpOption(); + + QCommandLineOption hostOption(QStringList() << "s" + << "server", + QCoreApplication::translate("main", "sim-us server host [default: localhost]."), + QCoreApplication::translate("main", "host"), QLatin1String("localhost")); + parser.addOption(hostOption); + + QCommandLineOption portOption(QStringList() << "p" + << "port", + QCoreApplication::translate("main", "Port for echoserver [default: 9002]."), + QCoreApplication::translate("main", "port"), QLatin1String("9002")); + parser.addOption(portOption); + + parser.process(a); + + QString host = parser.value(hostOption); + uint16_t port = parser.value(portOption).toUShort(); + MainWindow w(host, port); w.show(); return a.exec(); } diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index cd4aae5..d36c219 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -6,10 +6,10 @@ #include "sim-cvs_i10.h" #include "sim-test.h" -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QString host, uint16_t port, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - m_web_socket(new Web_socket_wrapper(QUrl("ws://localhost:9002"), this)), + m_web_socket(new Web_socket_wrapper(QUrl("ws://" + host + ":" + QString::number(port)), this)), m_error_dialog(new NetworkError(this)), m_sims{{"Can_Debugger", new Can_Debugger(m_web_socket, this)}, {"Scope_Mux_Tester", new Scope_Mux_Tester(m_web_socket, this)}, @@ -20,7 +20,6 @@ MainWindow::MainWindow(QWidget *parent) : this->setWindowTitle("Simulator Selector"); m_error_dialog->set_error("Connection timed out\nCheck if the server is running"); - //Default sim //defaultSim("CVS_I10"); diff --git a/Qt/mainwindow.h b/Qt/mainwindow.h index a08761c..58e066f 100644 --- a/Qt/mainwindow.h +++ b/Qt/mainwindow.h @@ -17,7 +17,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QString host, uint16_t port, QWidget *parent = nullptr); ~MainWindow(); void defaultSim(QString name);