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");
}
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)
return "";
QTime currTime = QTime::currentTime();
QTime targetTime = QTime::currentTime().addMSecs(waitTime);
QTime targetTime = QTime::currentTime().addMSecs(trigger.waitTime);
isRequiringOutput = true;
requiredOutput->clear();
execCMD(cmd);
while(QTime::currentTime() < targetTime)
{
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)
{
currTime = timeStamp;
targetTime = timeStamp.addMSecs(waitTime);
targetTime = timeStamp.addMSecs(trigger.waitTime);
}
}
isRequiringOutput = false;

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

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

@ -125,6 +125,10 @@ void MainWindow::refreshCMD(const QString& cmd)
ui->Raw_CMDHistoryWidget->addItem(cmd);
}
void MainWindow::on_stopButton_clicked()
{
}
// *********************************************************
// ******************** raw command ********************
@ -798,12 +802,15 @@ void MainWindow::uiInit()
connectStatusBar = new QLabel(this);
programStatusBar = new QLabel(this);
PM3VersionBar = new QLabel(this);
stopButton = new QPushButton(this);
setStatusBar(connectStatusBar, tr("Not Connected"));
setStatusBar(programStatusBar, tr("Idle"));
setStatusBar(PM3VersionBar, "");
stopButton->setText(tr("Stop"));
ui->statusbar->addPermanentWidget(PM3VersionBar, 1);
ui->statusbar->addPermanentWidget(connectStatusBar, 1);
ui->statusbar->addPermanentWidget(programStatusBar, 1);
ui->statusbar->addPermanentWidget(stopButton);
ui->MF_dataWidget->setColumnCount(3);
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->setColumnWidth(0, 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->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->verticalHeader()->setVisible(false);
ui->MF_keyWidget->setColumnWidth(0, 35);
ui->MF_keyWidget->setColumnWidth(1, 115);
ui->MF_keyWidget->setColumnWidth(2, 115);
ui->MF_keyWidget->setColumnWidth(1, 125);
ui->MF_keyWidget->setColumnWidth(2, 125);
MF_widgetReset();
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_simGroupBox, &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)

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

Loading…
Cancel
Save