From a9b19f92d684e1199825c4d0fa06ccd6155bf67f Mon Sep 17 00:00:00 2001 From: wh201906 Date: Wed, 23 Nov 2022 15:26:15 +0800 Subject: [PATCH] More hints For serial ports which look like PM3 hardware, show a '*' behind them. Show message box if the GUI fails to connect to the hardware --- src/common/pm3process.cpp | 3 +++ src/common/pm3process.h | 1 + src/ui/mainwindow.cpp | 28 +++++++++++++++++++++++----- src/ui/mainwindow.h | 1 + 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/common/pm3process.cpp b/src/common/pm3process.cpp index 9af256b..73ed3fb 100644 --- a/src/common/pm3process.cpp +++ b/src/common/pm3process.cpp @@ -61,7 +61,10 @@ void PM3Process::connectPM3(const QString& path, const QStringList args) emit PM3StatedChanged(true, result); } else + { + emit HWConnectFailed(); kill(); + } } setRequiringOutput(false); diff --git a/src/common/pm3process.h b/src/common/pm3process.h index 44c7b3e..5ae747b 100644 --- a/src/common/pm3process.h +++ b/src/common/pm3process.h @@ -48,6 +48,7 @@ signals: void PM3StatedChanged(bool st, const QString& info = ""); void newOutput(const QString& output); void changeClientType(Util::ClientType); + void HWConnectFailed(); }; #endif // PM3PROCESS_H diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index c74e0f4..a79bf8c 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -106,18 +106,31 @@ void MainWindow::initUI() // will be called by main.app void MainWindow::on_portSearchTimer_timeout() { - QStringList newPortList; + QStringList newPortList; // for actural port name + QStringList newPortNameList; // for display name +// QStringList portList; foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { -// qDebug() << info.isBusy() << info.isNull() << info.portName() << info.description(); +// qDebug() << info.isNull() << info.portName() << info.description() << info.serialNumber() << info.manufacturer(); if(!info.isNull()) - newPortList << info.portName(); + { + QString idString = (info.description() + info.serialNumber() + info.manufacturer()).toUpper(); + QString portName = info.portName(); + const QString hint = " *"; + newPortList << portName; + if(info.hasProductIdentifier() && info.hasVendorIdentifier() && info.vendorIdentifier() == 0x9AC4 && info.productIdentifier() == 0x4B8F) + portName += hint; + else if(idString.contains("proxmark") || idString.contains("iceman")) + portName += hint; + newPortNameList << portName; + } } if(newPortList != portList) // update PM3_portBox when available ports changed { portList = newPortList; ui->PM3_portBox->clear(); - ui->PM3_portBox->addItems(portList); + for(int i = 0; i < portList.size(); i++) + ui->PM3_portBox->addItem(newPortNameList[i], newPortList[i]); } } @@ -125,7 +138,7 @@ void MainWindow::on_PM3_connectButton_clicked() { qDebug() << "Main:" << QThread::currentThread(); - QString port = ui->PM3_portBox->currentText(); + QString port = ui->PM3_portBox->currentData().toString(); QString startArgs = ui->Set_Client_startArgsEdit->text(); // on RRG repo, if no port is specified, the client will search the available port @@ -200,7 +213,11 @@ void MainWindow::onPM3ErrorOccurred(QProcess::ProcessError error) qDebug() << "PM3 Error:" << error << pm3->errorString(); if(error == QProcess::FailedToStart) QMessageBox::information(this, tr("Info"), tr("Failed to start the client")); +} +void MainWindow::onPM3HWConnectFailed() +{ + QMessageBox::information(this, tr("Info"), tr("Failed to connect to the hardware")); } void MainWindow::onPM3StateChanged(bool st, const QString& info) @@ -1104,6 +1121,7 @@ void MainWindow::signalInit() connect(pm3, &PM3Process::PM3StatedChanged, this, &MainWindow::onPM3StateChanged); connect(pm3, &PM3Process::PM3StatedChanged, util, &Util::setRunningState); connect(pm3, &PM3Process::errorOccurred, this, &MainWindow::onPM3ErrorOccurred); + connect(pm3, &PM3Process::HWConnectFailed, this, &MainWindow::onPM3HWConnectFailed); connect(this, &MainWindow::killPM3, pm3, &PM3Process::killPM3); connect(this, &MainWindow::setProcEnv, pm3, &PM3Process::setProcEnv); connect(this, &MainWindow::setWorkingDir, pm3, &PM3Process::setWorkingDir); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 135be32..37fccaa 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -61,6 +61,7 @@ public slots: void on_Raw_keyPressed(QObject *obj_addr, QEvent &event); void on_MF_keyWidget_resized(QObject *obj_addr, QEvent &event); void onPM3ErrorOccurred(QProcess::ProcessError error); + void onPM3HWConnectFailed(); private slots: void on_PM3_connectButton_clicked();