-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperedavatordbgclient.cpp
66 lines (52 loc) · 1.44 KB
/
peredavatordbgclient.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
#include "peredavatordbgclient.h"
PeredavatorDbgClient::PeredavatorDbgClient(QObject *parent) : QTcpSocket(parent)
{
connect(this, SIGNAL(readyRead()), SLOT(mReadyRead()) );
connect(this, SIGNAL(disconnected()), SLOT(onDisconn()) );
}
void PeredavatorDbgClient::conn2thisDev(QString add, quint16 port, int timeOut)
{
disconnect(this, SIGNAL(disconnected()), this, SLOT(onDisconn()) );
if(isOpen())
close();
stopAll = false;
connectToHost(add,port);
if(waitForConnected(timeOut)){
connect(this, SIGNAL(disconnected()), this, SLOT(onDisconn()) );
emit onConnectedStateChanged(true);
}else{
emit showMess(tr("Can't connect to device. Error: %1").arg(errorString()));
close();
emit onCantConnect(true);
return;
}
}
void PeredavatorDbgClient::closeConnection()
{
stopAll = true;
onDisconn();
// emit showMess(tr("Done."));
}
void PeredavatorDbgClient::stopAllNow()
{
stopAll = true;
}
void PeredavatorDbgClient::mReadyRead()
{
QByteArray readArr = readAll();
while(!stopAll && waitForReadyRead(100)){
readArr.append(readAll());
}
emit changeCounters(readArr.length(), -1, true);
if(readArr.right(1) == "\n")
readArr.chop(1);
emit appendPlainText(readArr);
if(stopAll)
onDisconn();
}
void PeredavatorDbgClient::onDisconn()
{
qDebug() << "onDisconn";
emit onConnectedStateChanged(false);
close();
}