mirror of https://github.com/wh201906/Proxmark3GUI
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#include "util.h"
|
|
|
|
Util::Util(QObject *parent) : QObject(parent)
|
|
{
|
|
isRequiringOutput = false;
|
|
requiredOutput = new QString();
|
|
timeStamp = QTime::currentTime();
|
|
}
|
|
|
|
void Util::processOutput(QString output)
|
|
{
|
|
// qDebug() << "Util::processOutput:" << output;
|
|
if(isRequiringOutput)
|
|
{
|
|
requiredOutput->append(output);
|
|
timeStamp = QTime::currentTime();
|
|
}
|
|
emit refreshOutput(output);
|
|
}
|
|
|
|
void Util::execCMD(QString cmd)
|
|
{
|
|
qDebug() << cmd;
|
|
emit write(cmd + "\r\n");
|
|
}
|
|
|
|
QString Util::execCMDWithOutput(QString cmd, unsigned long timeout)
|
|
{
|
|
QTime currTime = QTime::currentTime();
|
|
QTime targetTime = QTime::currentTime().addMSecs(timeout);
|
|
isRequiringOutput = true;
|
|
requiredOutput->clear();
|
|
execCMD(cmd);
|
|
while( QTime::currentTime() < targetTime)
|
|
{
|
|
QApplication::processEvents();
|
|
if(timeStamp > currTime)
|
|
{
|
|
currTime = timeStamp;
|
|
targetTime = timeStamp.addMSecs(timeout);
|
|
}
|
|
}
|
|
isRequiringOutput = false;
|
|
return *requiredOutput;
|
|
}
|
|
|
|
void Util::delay(unsigned int msec)
|
|
{
|
|
QTime timer = QTime::currentTime().addMSecs(msec);
|
|
while( QTime::currentTime() < timer )
|
|
QApplication::processEvents(QEventLoop::AllEvents, 100);
|
|
}
|