mirror of
https://github.com/wh201906/Proxmark3GUI.git
synced 2026-07-14 22:55:32 +08:00
Shorten the waitTime for execCMDWithOutput()
This commit is contained in:
+19
-3
@@ -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;
|
||||
|
||||
+23
-1
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user