mirror of
https://github.com/wh201906/Proxmark3GUI.git
synced 2026-07-14 22:55:32 +08:00
Optimize with multithread
This commit is contained in:
+11
-21
@@ -11,6 +11,7 @@ PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent)
|
||||
serialListener->setInterval(1000);
|
||||
serialListener->setTimerType(Qt::VeryCoarseTimer);
|
||||
connect(serialListener,&QTimer::timeout,this,&PM3Process::onTimeout);
|
||||
connect(this,&PM3Process::readyRead,this,&PM3Process::onReadyRead);
|
||||
}
|
||||
|
||||
void PM3Process::connectPM3(const QString path, const QString port)
|
||||
@@ -44,18 +45,6 @@ void PM3Process::setRequiringOutput(bool st)
|
||||
if(isRequiringOutput)
|
||||
requiredOutput->clear();
|
||||
}
|
||||
QByteArray PM3Process::readLine(qint64 maxlen)
|
||||
{
|
||||
QByteArray buff;
|
||||
buff=QProcess::readLine(maxlen);
|
||||
if(isRequiringOutput)
|
||||
requiredOutput->append(buff);
|
||||
return buff;
|
||||
}
|
||||
QString PM3Process::getRequiredOutput()
|
||||
{
|
||||
return *requiredOutput;
|
||||
}
|
||||
|
||||
bool PM3Process::waitForReadyRead(int msecs)
|
||||
{
|
||||
@@ -77,7 +66,7 @@ void PM3Process::setSerialListener(const QString& name,bool state)
|
||||
}
|
||||
}
|
||||
|
||||
void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(tested on Windows);
|
||||
void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(only tested on Windows);
|
||||
{
|
||||
qDebug()<<portInfo->isBusy();
|
||||
if(!portInfo->isBusy())
|
||||
@@ -101,12 +90,13 @@ qint64 PM3Process::write(QString data)
|
||||
|
||||
void PM3Process::onReadyRead()
|
||||
{
|
||||
QString btay = readLine();
|
||||
// while(btay != "")
|
||||
// {
|
||||
// qDebug() << btay;
|
||||
// ui->Raw_outputEdit->insertPlainText(btay);
|
||||
// btay = pm3->readLine();
|
||||
// }
|
||||
// ui->Raw_outputEdit->moveCursor(QTextCursor::End);
|
||||
QString out = readAll();
|
||||
if(isRequiringOutput)
|
||||
requiredOutput->append(out);
|
||||
if(out != "")
|
||||
{
|
||||
qDebug()<<"PM3Process::onReadyRead:" << out;
|
||||
emit newOutput(out);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -14,14 +14,11 @@ class PM3Process : public QProcess
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PM3Process(QThread* thread, QObject* parent=nullptr);
|
||||
QByteArray readLine(qint64 maxlen = 0);
|
||||
QString getRequiredOutput();
|
||||
bool waitForReadyRead(int msecs = 2000);
|
||||
|
||||
void testThread();
|
||||
|
||||
public slots:
|
||||
void setRequiringOutput(bool st);
|
||||
void connectPM3(const QString path, const QString port);
|
||||
void setSerialListener(const QString &name, bool state);
|
||||
qint64 write(QString data);
|
||||
@@ -30,7 +27,8 @@ private slots:
|
||||
void onReadyRead();
|
||||
private:
|
||||
bool isRequiringOutput;
|
||||
QString* requiredOutput;
|
||||
QString* requiredOutput; // It only works in this class now
|
||||
void setRequiringOutput(bool st);// It only works in this class now
|
||||
QTimer* serialListener;
|
||||
QSerialPortInfo* portInfo;
|
||||
signals:
|
||||
|
||||
+44
-3
@@ -2,10 +2,51 @@
|
||||
|
||||
Util::Util(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
isRequiringOutput=false;
|
||||
requiredOutput=new QString();
|
||||
timeStamp=QTime::currentTime();
|
||||
}
|
||||
|
||||
void Util::processOutput()
|
||||
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);
|
||||
}
|
||||
|
||||
+18
-3
@@ -2,6 +2,12 @@
|
||||
#define UTIL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
class Util : public QObject
|
||||
{
|
||||
@@ -9,10 +15,19 @@ class Util : public QObject
|
||||
public:
|
||||
explicit Util(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void execCMD(QString cmd);
|
||||
QString execCMDWithOutput(QString cmd, unsigned long timeout=2000);
|
||||
void delay(unsigned int msec);
|
||||
public slots:
|
||||
void processOutput(QString output);
|
||||
|
||||
private slots:
|
||||
void processOutput();
|
||||
private:
|
||||
bool isRequiringOutput;
|
||||
QString* requiredOutput;
|
||||
QTime timeStamp;
|
||||
signals:
|
||||
void refreshOutput(const QString& output);
|
||||
void write(QString data);
|
||||
};
|
||||
|
||||
#endif // UTIL_H
|
||||
|
||||
Reference in New Issue
Block a user