-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequencesender.cpp
60 lines (53 loc) · 1.31 KB
/
sequencesender.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
#include "sequencesender.h"
#include <QDebug>
#include <QString>
sequenceSender::sequenceSender(QObject *parent) : QObject(parent)
{
}
void sequenceSender::doSetup(QThread &cThread, QSerialPort *port, char *seq, int size, int sendInterval, int sendCount, QString &txtData, int seqId)
{
localPort = port;
sequence = seq;
seqSize = size;
interval = sendInterval;
textDat = txtData;
sendCnt = sendCount;
id = seqId;
connect(&cThread, SIGNAL(started()), this, SLOT(doWork()));
connect(this, SIGNAL(exitThread()), &cThread, SLOT(quit()));
connect(&cThread, SIGNAL(finished()), &cThread, SLOT(deleteLater()));
}
void sequenceSender::doWork()
{
qDebug() << "status: " << localPort->isOpen();
threadStatus = 1;
int localCnt = 0;
while(isAlive())
{
emit writeToPort(sequence, seqSize, textDat);
QThread::msleep(interval);
if(sendCnt)
{
localCnt++;
if(localCnt == sendCnt)
{
countFinished(id);
sequenceSender::finishWork();
}
}
}
emit exitThread();
}
/**
* @brief sequenceSender::finishWork
*
* This will stop already started threads.
*/
void sequenceSender::finishWork()
{
threadStatus = 0;
}
int sequenceSender::isAlive()
{
return threadStatus;
}