Make execCmd() adapted to QThread

pull/2/head
wh201906 5 years ago
parent 5c5fb84811
commit a6a699d33c

@ -20,13 +20,15 @@ SOURCES += \
mainwindow.cpp \ mainwindow.cpp \
mf_attack_hardnesteddialog.cpp \ mf_attack_hardnesteddialog.cpp \
mifare.cpp \ mifare.cpp \
pm3process.cpp pm3process.cpp \
util.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
mf_attack_hardnesteddialog.h \ mf_attack_hardnesteddialog.h \
mifare.h \ mifare.h \
pm3process.h pm3process.h \
util.h
FORMS += \ FORMS += \
mainwindow.ui \ mainwindow.ui \

@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
emit killPM3();
pm3Thread->exit(0); pm3Thread->exit(0);
pm3Thread->wait(5000); pm3Thread->wait(5000);
delete pm3; delete pm3;
@ -62,7 +63,6 @@ void MainWindow::on_PM3_connectButton_clicked()
QMessageBox::information(NULL, "Info", "Plz choose a port first", QMessageBox::Ok); QMessageBox::information(NULL, "Info", "Plz choose a port first", QMessageBox::Ok);
else else
{ {
emit requiringOutput(true);
emit connectPM3(ui->PM3_pathEdit->text(), port); emit connectPM3(ui->PM3_pathEdit->text(), port);
} }
} }
@ -95,11 +95,7 @@ void MainWindow::on_PM3_disconnectButton_clicked()
void MainWindow::on_Raw_sendCMDButton_clicked() void MainWindow::on_Raw_sendCMDButton_clicked()
{ {
if(ui->Raw_CMDHistoryWidget->count() == 0 || ui->Raw_CMDHistoryWidget->item(ui->Raw_CMDHistoryWidget->count() - 1)->text() != ui->Raw_CMDEdit->text()) execCMD(ui->Raw_CMDEdit->text());
ui->Raw_CMDHistoryWidget->addItem(ui->Raw_CMDEdit->text());
qDebug() << (ui->Raw_CMDEdit->text().toLocal8Bit());
pm3->write((ui->Raw_CMDEdit->text() + "\r\n").toLocal8Bit());
pm3->waitForBytesWritten(3000);
} }
void MainWindow::on_Raw_clearOutputButton_clicked() void MainWindow::on_Raw_clearOutputButton_clicked()
@ -466,6 +462,8 @@ void MainWindow::signalInit()
connect(this,&MainWindow::connectPM3,pm3,&PM3Process::connectPM3); connect(this,&MainWindow::connectPM3,pm3,&PM3Process::connectPM3);
connect(pm3, &PM3Process::PM3StatedChanged, this, &MainWindow::onPM3StateChanged); connect(pm3, &PM3Process::PM3StatedChanged, this, &MainWindow::onPM3StateChanged);
connect(this,&MainWindow::killPM3,pm3,&PM3Process::kill); connect(this,&MainWindow::killPM3,pm3,&PM3Process::kill);
connect(this,&MainWindow::write,pm3,&PM3Process::write);
} }
void MainWindow::setStatusBar(QLabel* target, const QString & text) void MainWindow::setStatusBar(QLabel* target, const QString & text)
@ -481,15 +479,18 @@ void MainWindow::setStatusBar(QLabel* target, const QString & text)
void MainWindow::execCMD(QString cmd, bool gotoRawTab) void MainWindow::execCMD(QString cmd, bool gotoRawTab)
{ {
ui->Raw_CMDEdit->setText(cmd); ui->Raw_CMDEdit->setText(cmd);
on_Raw_sendCMDButton_clicked(); if(ui->Raw_CMDHistoryWidget->count() == 0 || ui->Raw_CMDHistoryWidget->item(ui->Raw_CMDHistoryWidget->count() - 1)->text() != cmd)
ui->Raw_CMDHistoryWidget->addItem(cmd);
qDebug() << cmd;
emit write(cmd + "\r\n");
if(gotoRawTab) if(gotoRawTab)
ui->funcTab->setCurrentIndex(1); ui->funcTab->setCurrentIndex(1);
} }
QString MainWindow::execCMDWithOutput(QString cmd, int msec) QString MainWindow::execCMDWithOutput(QString cmd, int msec)
{ {
pm3->setRequiringOutput(true); emit requiringOutput(true);
execCMD(cmd, false); execCMD(cmd);
while(pm3->waitForReadyRead(msec)) while(pm3->waitForReadyRead(msec))
; ;
pm3->setRequiringOutput(false); pm3->setRequiringOutput(false);

@ -31,7 +31,7 @@ public:
public slots: public slots:
void refresh(); void refresh();
void setStatusBar(QLabel* target,const QString & text); void setStatusBar(QLabel* target,const QString & text);
void execCMD(QString cmd, bool gotoRawTab); void execCMD(QString cmd, bool gotoRawTab=false);
void onPM3StateChanged(bool st, QString info); void onPM3StateChanged(bool st, QString info);
private slots: private slots:
@ -89,5 +89,6 @@ signals:
void connectPM3(const QString path, const QString port); void connectPM3(const QString path, const QString port);
void killPM3(); void killPM3();
void setSerialListener(const QString &name, bool state); void setSerialListener(const QString &name, bool state);
void write(QString data);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

@ -623,6 +623,44 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>Lock UFUID Card</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>About UID Card</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_12"> <spacer name="horizontalSpacer_12">
<property name="orientation"> <property name="orientation">
@ -848,6 +886,19 @@
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="Raw_CMDHistoryBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>History:</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QListWidget" name="Raw_CMDHistoryWidget"> <widget class="QListWidget" name="Raw_CMDHistoryWidget">
<property name="sizePolicy"> <property name="sizePolicy">
@ -874,19 +925,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="Raw_CMDHistoryBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>History:</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

@ -77,7 +77,7 @@ void PM3Process::setSerialListener(const QString& name,bool state)
} }
} }
void PM3Process::onTimeout() void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(tested on Windows);
{ {
qDebug()<<portInfo->isBusy(); qDebug()<<portInfo->isBusy();
if(!portInfo->isBusy()) if(!portInfo->isBusy())
@ -92,3 +92,9 @@ void PM3Process::testThread()
{ {
qDebug()<<"PM3:"<<QThread::currentThread(); qDebug()<<"PM3:"<<QThread::currentThread();
} }
qint64 PM3Process::write(QString data)
{
return QProcess::write(data.toLatin1());
}

@ -24,6 +24,7 @@ public slots:
void setRequiringOutput(bool st); void setRequiringOutput(bool st);
void connectPM3(const QString path, const QString port); void connectPM3(const QString path, const QString port);
void setSerialListener(const QString &name, bool state); void setSerialListener(const QString &name, bool state);
qint64 write(QString data);
private slots: private slots:
void onTimeout(); void onTimeout();
private: private:

@ -0,0 +1,6 @@
#include "util.h"
Util::Util(QObject *parent) : QObject(parent)
{
}

@ -0,0 +1,16 @@
#ifndef UTIL_H
#define UTIL_H
#include <QObject>
class Util : public QObject
{
Q_OBJECT
public:
explicit Util(QObject *parent = nullptr);
signals:
};
#endif // UTIL_H
Loading…
Cancel
Save