forked from GTRONICK/QPickit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.cpp
72 lines (65 loc) · 2.36 KB
/
worker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "worker.h"
#include <QDebug>
#include <QProcess>
Worker::Worker( QObject *parent, Programmer *programmer ) : QObject( parent ), programmer( programmer ) { giInfoFlag = 0; }
/**
Execute the pk2cmd command with the arguments arriving in an array.
@param aobArguments - QStringList, array of arguments
*/
void Worker::worker_slot_executeCommand( QStringList aobArguments ) {
gobProcess = new QProcess( this );
QString lsProgram = aobArguments.takeFirst();
QString lsCompleteCommand = lsProgram;
QString lsExitStatus;
bool lbReturnValue;
for ( int liIndex = 0; liIndex < aobArguments.size(); liIndex++ ) {
lsCompleteCommand += " " + aobArguments.at( liIndex );
}
if ( programmer->verbose )
qDebug() << lsCompleteCommand;
emit worker_signal_prepareCommandExecution();
gobProcess->setProcessChannelMode( QProcess::MergedChannels );
connect( gobProcess, SIGNAL( readyReadStandardOutput() ), this, SLOT( worker_slot_internalProcessOutputCapture() ) );
gobProcess->start( lsProgram, aobArguments );
if ( !gobProcess->waitForFinished() ) {
lsExitStatus = "ERROR: " + this->gobProcess->errorString();
lbReturnValue = false;
} else {
lsExitStatus = "OK";
lbReturnValue = true;
}
giInfoFlag = 0;
emit worker_signal_taskCompleted( lbReturnValue, lsExitStatus );
}
/**
Execute the command to retrieve the information from the connected PICkit2.
*/
void Worker::worker_slot_pickitInfo() {
giInfoFlag = 1;
QStringList lobArguments;
lobArguments = programmer->getCmd( "pk2Info" );
if ( !lobArguments.isEmpty() )
this->worker_slot_executeCommand( lobArguments );
}
/**
Execute the command to set the new ID for the connected PICkit2.
*/
void Worker::worker_slot_pickitNewID( QString newID ) {
giInfoFlag = 1;
QStringList lobArguments;
lobArguments = programmer->getCmd( "pk2NewID" );
if ( lobArguments.isEmpty() )
return;
lobArguments.append( newID );
this->worker_slot_executeCommand( lobArguments );
}
/**
Sends the output of the executed command to the main thread.
*/
void Worker::worker_slot_internalProcessOutputCapture() {
if ( giInfoFlag == 0 )
emit worker_signal_processOutput( gobProcess->readAllStandardOutput() );
else {
emit worker_signal_pickitInfo( gobProcess->readAllStandardOutput() );
}
}