Proxmark3GUI/common/util.cpp

64 lines
1.5 KiB
C++
Raw Permalink Normal View History

2020-04-22 16:42:58 +08:00
#include "util.h"
2020-08-05 19:08:02 +08:00
Util::Util(QObject *parent) : QObject(parent)
2020-04-22 16:42:58 +08:00
{
2020-04-22 23:13:00 +08:00
isRequiringOutput = false;
requiredOutput = new QString();
timeStamp = QTime::currentTime();
2020-08-05 19:08:02 +08:00
this->clientType = CLIENTTYPE_OFFICIAL;
qRegisterMetaType<Util::ClientType>("Util::ClientType");
2020-04-22 21:14:33 +08:00
}
2020-04-22 16:42:58 +08:00
2020-04-22 21:14:33 +08:00
void Util::processOutput(QString output)
{
2020-04-23 17:50:20 +08:00
// qDebug() << "Util::processOutput:" << output;
2020-04-22 21:14:33 +08:00
if(isRequiringOutput)
{
requiredOutput->append(output);
2020-04-22 23:13:00 +08:00
timeStamp = QTime::currentTime();
2020-04-22 21:14:33 +08:00
}
emit refreshOutput(output);
2020-04-22 16:42:58 +08:00
}
2020-04-22 21:14:33 +08:00
void Util::execCMD(QString cmd)
2020-04-22 16:42:58 +08:00
{
2020-04-22 21:14:33 +08:00
qDebug() << cmd;
emit write(cmd + "\r\n");
}
2020-04-22 16:42:58 +08:00
QString Util::execCMDWithOutput(QString cmd, unsigned long waitTime)
2020-04-22 21:14:33 +08:00
{
2020-04-22 23:13:00 +08:00
QTime currTime = QTime::currentTime();
QTime targetTime = QTime::currentTime().addMSecs(waitTime);
2020-04-22 23:13:00 +08:00
isRequiringOutput = true;
2020-04-22 21:14:33 +08:00
requiredOutput->clear();
execCMD(cmd);
2020-08-01 21:30:55 +08:00
while(QTime::currentTime() < targetTime)
2020-04-22 21:14:33 +08:00
{
QApplication::processEvents();
2020-04-22 23:13:00 +08:00
if(timeStamp > currTime)
2020-04-22 21:14:33 +08:00
{
2020-04-22 23:13:00 +08:00
currTime = timeStamp;
targetTime = timeStamp.addMSecs(waitTime);
2020-04-22 21:14:33 +08:00
}
}
2020-04-22 23:13:00 +08:00
isRequiringOutput = false;
2020-04-22 21:14:33 +08:00
return *requiredOutput;
}
void Util::delay(unsigned int msec)
{
QTime timer = QTime::currentTime().addMSecs(msec);
2020-08-01 21:30:55 +08:00
while(QTime::currentTime() < timer)
2020-04-22 21:14:33 +08:00
QApplication::processEvents(QEventLoop::AllEvents, 100);
2020-04-22 16:42:58 +08:00
}
2020-08-01 21:30:55 +08:00
Util::ClientType Util::getClientType()
{
return this->clientType;
}
2020-08-05 19:08:02 +08:00
void Util::setClientType(Util::ClientType clientType)
{
this->clientType = clientType;
}