diff --git a/common/pm3process.cpp b/common/pm3process.cpp index 6ea2492..dc219b7 100644 --- a/common/pm3process.cpp +++ b/common/pm3process.cpp @@ -16,16 +16,25 @@ PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent) void PM3Process::connectPM3(const QString path, const QString port) { + QString result; setRequiringOutput(true); // using "-f" option to make the client output flushed after every print. start(path, QStringList() << port << "-f", QProcess::Unbuffered | QProcess::ReadWrite); if(waitForStarted(10000)) { - while(waitForReadyRead(1000)) - ; + waitForReadyRead(1000); setRequiringOutput(false); - QString result = *requiredOutput; + result = *requiredOutput; + if(result.indexOf("[=]") != -1) + { + emit changeClientType(Util::CLIENTTYPE_ICEMAN); + setRequiringOutput(true); + write("hw version\r\n"); + waitForReadyRead(1000); + result = *requiredOutput; + setRequiringOutput(false); + } if(result.indexOf("os: ") != -1) // make sure the PM3 is connected { result = result.mid(result.indexOf("os: ")); diff --git a/common/pm3process.h b/common/pm3process.h index 17cee5f..093ebfd 100644 --- a/common/pm3process.h +++ b/common/pm3process.h @@ -9,6 +9,8 @@ #include #include +#include "util.h" + class PM3Process : public QProcess { Q_OBJECT @@ -34,6 +36,7 @@ private: signals: void PM3StatedChanged(bool st, QString info = ""); void newOutput(QString output); + void changeClientType(Util::ClientType); }; #endif // PM3PROCESS_H diff --git a/common/util.cpp b/common/util.cpp index 5eb3af9..11f0a9f 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -1,11 +1,12 @@ #include "util.h" -Util::Util(Util::ClientType clientType, QObject *parent) : QObject(parent) +Util::Util(QObject *parent) : QObject(parent) { isRequiringOutput = false; requiredOutput = new QString(); timeStamp = QTime::currentTime(); - this->clientType = clientType; + this->clientType = CLIENTTYPE_OFFICIAL; + qRegisterMetaType("Util::ClientType"); } void Util::processOutput(QString output) @@ -55,3 +56,8 @@ Util::ClientType Util::getClientType() { return this->clientType; } + +void Util::setClientType(Util::ClientType clientType) +{ + this->clientType = clientType; +} diff --git a/common/util.h b/common/util.h index a790c94..27bee4a 100644 --- a/common/util.h +++ b/common/util.h @@ -8,6 +8,7 @@ #include #include #include +#include class Util : public QObject { @@ -15,10 +16,13 @@ class Util : public QObject public: enum ClientType { - OFFICIAL, - ICEMAN, + CLIENTTYPE_OFFICIAL, + CLIENTTYPE_ICEMAN, }; - explicit Util(Util::ClientType clientType, QObject *parent = nullptr); + + Q_ENUM(Util::ClientType) + + explicit Util(QObject *parent = nullptr); void execCMD(QString cmd); QString execCMDWithOutput(QString cmd, unsigned long timeout = 2000); @@ -26,6 +30,7 @@ public: ClientType getClientType(); public slots: void processOutput(QString output); + void setClientType(Util::ClientType clientType); private: bool isRequiringOutput; diff --git a/module/mifare.cpp b/module/mifare.cpp index 22e86d2..1dbaa10 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -131,7 +131,7 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int w return ""; } - if(util->getClientType() == Util::OFFICIAL) + if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL) { // use the given key type to read the target block result = util->execCMDWithOutput( @@ -205,7 +205,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key, return data; } - if(util->getClientType() == Util::OFFICIAL) + if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL) { result = util->execCMDWithOutput( "hf mf rdsc " diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index f14f9e0..26d60d3 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent): pm3Thread->start(); pm3state = false; - util = new Util(Util::OFFICIAL, this); + util = new Util(this); mifare = new Mifare(ui, util, this); } @@ -784,6 +784,7 @@ void MainWindow::uiInit() void MainWindow::signalInit() { connect(pm3, &PM3Process::newOutput, util, &Util::processOutput); + connect(pm3, &PM3Process::changeClientType, util, &Util::setClientType); connect(util, &Util::refreshOutput, this, &MainWindow::refreshOutput); connect(this, &MainWindow::connectPM3, pm3, &PM3Process::connectPM3); diff --git a/ui/mf_trailerdecoderdialog.ui b/ui/mf_trailerdecoderdialog.ui index afcc957..83d0926 100644 --- a/ui/mf_trailerdecoderdialog.ui +++ b/ui/mf_trailerdecoderdialog.ui @@ -11,7 +11,7 @@ - Dialog + Trailer Decoder