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.
72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
#include "util.h"
|
|
|
|
Util::Util(QObject *parent) : QObject(parent)
|
|
{
|
|
isRequiringOutput = false;
|
|
requiredOutput = new QString();
|
|
timeStamp = QTime::currentTime();
|
|
this->clientType = CLIENTTYPE_OFFICIAL;
|
|
qRegisterMetaType<Util::ClientType>("Util::ClientType");
|
|
}
|
|
|
|
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;
|
|
if(isRunning)
|
|
emit write(cmd + "\r\n");
|
|
}
|
|
|
|
QString Util::execCMDWithOutput(QString cmd, unsigned long waitTime)
|
|
{
|
|
if(!isRunning)
|
|
return "";
|
|
QTime currTime = QTime::currentTime();
|
|
QTime targetTime = QTime::currentTime().addMSecs(waitTime);
|
|
isRequiringOutput = true;
|
|
requiredOutput->clear();
|
|
execCMD(cmd);
|
|
while(QTime::currentTime() < targetTime)
|
|
{
|
|
QApplication::processEvents();
|
|
if(timeStamp > currTime)
|
|
{
|
|
currTime = timeStamp;
|
|
targetTime = timeStamp.addMSecs(waitTime);
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
Util::ClientType Util::getClientType()
|
|
{
|
|
return this->clientType;
|
|
}
|
|
|
|
void Util::setClientType(Util::ClientType clientType)
|
|
{
|
|
this->clientType = clientType;
|
|
}
|
|
|
|
void Util::setRunningState(bool st)
|
|
{
|
|
this->isRunning = st;
|
|
}
|