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.
Proxmark3GUI/common/util.cpp

64 lines
1.5 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;
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);
}
Util::ClientType Util::getClientType()
{
return this->clientType;
}
void Util::setClientType(Util::ClientType clientType)
{
this->clientType = clientType;
}