Shorten the waitTime for execCMDWithOutput()

pull/14/head
wh201906 4 years ago
parent a7985c5c89
commit 862f0775f8

@ -27,22 +27,38 @@ void Util::execCMD(QString cmd)
emit write(cmd + "\r\n"); emit write(cmd + "\r\n");
} }
QString Util::execCMDWithOutput(QString cmd, unsigned long waitTime) QString Util::execCMDWithOutput(QString cmd, ReturnTrigger trigger)
{ {
bool isResultFound = false;
QRegularExpression re;
re.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
if(!isRunning) if(!isRunning)
return ""; return "";
QTime currTime = QTime::currentTime(); QTime currTime = QTime::currentTime();
QTime targetTime = QTime::currentTime().addMSecs(waitTime); QTime targetTime = QTime::currentTime().addMSecs(trigger.waitTime);
isRequiringOutput = true; isRequiringOutput = true;
requiredOutput->clear(); requiredOutput->clear();
execCMD(cmd); execCMD(cmd);
while(QTime::currentTime() < targetTime) while(QTime::currentTime() < targetTime)
{ {
QApplication::processEvents(); QApplication::processEvents();
for(QString otpt : trigger.expectedOutputs)
{
re.setPattern(otpt);
isResultFound = re.match(*requiredOutput).hasMatch();
if(requiredOutput->contains(otpt))
break;
}
if(isResultFound)
{
delay(200);
break;
}
if(timeStamp > currTime) if(timeStamp > currTime)
{ {
currTime = timeStamp; currTime = timeStamp;
targetTime = timeStamp.addMSecs(waitTime); targetTime = timeStamp.addMSecs(trigger.waitTime);
} }
} }
isRequiringOutput = false; isRequiringOutput = false;

@ -9,6 +9,7 @@
#include <QTime> #include <QTime>
#include <QTimer> #include <QTimer>
#include <QMetaType> #include <QMetaType>
#include <QRegularExpression>
class Util : public QObject class Util : public QObject
{ {
@ -20,12 +21,33 @@ public:
CLIENTTYPE_ICEMAN, CLIENTTYPE_ICEMAN,
}; };
struct ReturnTrigger
{
unsigned long waitTime;
QStringList expectedOutputs;
ReturnTrigger(unsigned long time)
{
waitTime = time;
expectedOutputs = QStringList();
}
ReturnTrigger(QStringList outputs)
{
waitTime = 10000;
expectedOutputs = outputs;
}
ReturnTrigger(unsigned long time, QStringList outputs)
{
waitTime = time;
expectedOutputs = outputs;
}
};
Q_ENUM(Util::ClientType) Q_ENUM(Util::ClientType)
explicit Util(QObject *parent = nullptr); explicit Util(QObject *parent = nullptr);
void execCMD(QString cmd); void execCMD(QString cmd);
QString execCMDWithOutput(QString cmd, unsigned long waitTime = 2000); QString execCMDWithOutput(QString cmd, ReturnTrigger trigger = 10000);
void delay(unsigned int msec); void delay(unsigned int msec);
ClientType getClientType(); ClientType getClientType();
public slots: public slots:

@ -119,7 +119,7 @@ void Mifare::chk()
"hf mf chk *" "hf mf chk *"
+ QString::number(cardType.type) + QString::number(cardType.type)
+ " ?", + " ?",
1000 + cardType.type * 1000); Util::ReturnTrigger(1000 + cardType.sector_size * 200, {"No valid", "\\|---\\|----------------\\|----------------\\|"}));
qDebug() << result; qDebug() << result;
int offset = 0; int offset = 0;
@ -183,7 +183,8 @@ void Mifare::nested()
result = util->execCMDWithOutput( result = util->execCMDWithOutput(
"hf mf nested " "hf mf nested "
+ QString::number(cardType.type) + QString::number(cardType.type)
+ " *", 10000); + " *",
Util::ReturnTrigger(10000, {"Can't found", "\\|000\\|"}));
} }
else if(util->getClientType() == Util::CLIENTTYPE_ICEMAN) else if(util->getClientType() == Util::CLIENTTYPE_ICEMAN)
{ {
@ -624,7 +625,7 @@ void Mifare::writeSelected(TargetType targetType)
continue; continue;
else if(choice == QMessageBox::YesToAll) else if(choice == QMessageBox::YesToAll)
yes2All = true; yes2All = true;
else if(QMessageBox::NoToAll) else if(choice == QMessageBox::NoToAll)
{ {
no2All = true; no2All = true;
continue; continue;

@ -125,6 +125,10 @@ void MainWindow::refreshCMD(const QString& cmd)
ui->Raw_CMDHistoryWidget->addItem(cmd); ui->Raw_CMDHistoryWidget->addItem(cmd);
} }
void MainWindow::on_stopButton_clicked()
{
}
// ********************************************************* // *********************************************************
// ******************** raw command ******************** // ******************** raw command ********************
@ -798,12 +802,15 @@ void MainWindow::uiInit()
connectStatusBar = new QLabel(this); connectStatusBar = new QLabel(this);
programStatusBar = new QLabel(this); programStatusBar = new QLabel(this);
PM3VersionBar = new QLabel(this); PM3VersionBar = new QLabel(this);
stopButton = new QPushButton(this);
setStatusBar(connectStatusBar, tr("Not Connected")); setStatusBar(connectStatusBar, tr("Not Connected"));
setStatusBar(programStatusBar, tr("Idle")); setStatusBar(programStatusBar, tr("Idle"));
setStatusBar(PM3VersionBar, ""); setStatusBar(PM3VersionBar, "");
stopButton->setText(tr("Stop"));
ui->statusbar->addPermanentWidget(PM3VersionBar, 1); ui->statusbar->addPermanentWidget(PM3VersionBar, 1);
ui->statusbar->addPermanentWidget(connectStatusBar, 1); ui->statusbar->addPermanentWidget(connectStatusBar, 1);
ui->statusbar->addPermanentWidget(programStatusBar, 1); ui->statusbar->addPermanentWidget(programStatusBar, 1);
ui->statusbar->addPermanentWidget(stopButton);
ui->MF_dataWidget->setColumnCount(3); ui->MF_dataWidget->setColumnCount(3);
ui->MF_dataWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Sec"))); ui->MF_dataWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Sec")));
@ -812,7 +819,7 @@ void MainWindow::uiInit()
ui->MF_dataWidget->verticalHeader()->setVisible(false); ui->MF_dataWidget->verticalHeader()->setVisible(false);
ui->MF_dataWidget->setColumnWidth(0, 55); ui->MF_dataWidget->setColumnWidth(0, 55);
ui->MF_dataWidget->setColumnWidth(1, 55); ui->MF_dataWidget->setColumnWidth(1, 55);
ui->MF_dataWidget->setColumnWidth(2, 430); ui->MF_dataWidget->setColumnWidth(2, 450);
ui->MF_keyWidget->setColumnCount(3); ui->MF_keyWidget->setColumnCount(3);
ui->MF_keyWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Sec"))); ui->MF_keyWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Sec")));
@ -820,8 +827,8 @@ void MainWindow::uiInit()
ui->MF_keyWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("KeyB"))); ui->MF_keyWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("KeyB")));
ui->MF_keyWidget->verticalHeader()->setVisible(false); ui->MF_keyWidget->verticalHeader()->setVisible(false);
ui->MF_keyWidget->setColumnWidth(0, 35); ui->MF_keyWidget->setColumnWidth(0, 35);
ui->MF_keyWidget->setColumnWidth(1, 115); ui->MF_keyWidget->setColumnWidth(1, 125);
ui->MF_keyWidget->setColumnWidth(2, 115); ui->MF_keyWidget->setColumnWidth(2, 125);
MF_widgetReset(); MF_widgetReset();
typeBtnGroup = new QButtonGroup(this); typeBtnGroup = new QButtonGroup(this);
@ -887,6 +894,8 @@ void MainWindow::signalInit()
connect(ui->MF_UIDGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); connect(ui->MF_UIDGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked);
connect(ui->MF_simGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); connect(ui->MF_simGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked);
connect(ui->MF_sniffGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked); connect(ui->MF_sniffGroupBox, &QGroupBox::clicked, this, &MainWindow::on_GroupBox_clicked);
connect(stopButton, &QPushButton::clicked, this, &MainWindow::on_stopButton_clicked);
} }
void MainWindow::setStatusBar(QLabel * target, const QString & text) void MainWindow::setStatusBar(QLabel * target, const QString & text)

@ -19,6 +19,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QSizePolicy> #include <QSizePolicy>
#include <QSettings> #include <QSettings>
#include <QPushButton>
#include "common/pm3process.h" #include "common/pm3process.h"
#include "module/mifare.h" #include "module/mifare.h"
@ -148,12 +149,14 @@ private slots:
void on_MF_selectTrailerBox_stateChanged(int arg1); void on_MF_selectTrailerBox_stateChanged(int arg1);
void on_stopButton_clicked();
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* typeBtnGroup; QButtonGroup* typeBtnGroup;
QLabel* connectStatusBar; QLabel* connectStatusBar;
QLabel* programStatusBar; QLabel* programStatusBar;
QLabel* PM3VersionBar; QLabel* PM3VersionBar;
QPushButton* stopButton;
QAction* myInfo; QAction* myInfo;
QAction* checkUpdate; QAction* checkUpdate;
QSettings* settings; QSettings* settings;

Loading…
Cancel
Save