Support Iceman fork(Command Line only)

This commit is contained in:
wh201906
2020-08-05 19:08:02 +08:00
parent 6f860111df
commit ef6ebea568
7 changed files with 36 additions and 12 deletions
+12 -3
View File
@@ -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: "));
+3
View File
@@ -9,6 +9,8 @@
#include <QtSerialPort/QSerialPortInfo>
#include <QtSerialPort/QSerialPort>
#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
+8 -2
View File
@@ -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>("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;
}
+8 -3
View File
@@ -8,6 +8,7 @@
#include <QApplication>
#include <QTime>
#include <QTimer>
#include <QMetaType>
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;