-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketthread.cpp
More file actions
82 lines (66 loc) · 1.79 KB
/
socketthread.cpp
File metadata and controls
82 lines (66 loc) · 1.79 KB
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
73
74
75
76
77
78
79
80
81
82
#include "socketthread.h"
#include <QDebug>
SocketThread::SocketThread(const QString &address, int posInt, int odInt, QObject *parent) :
QObject(parent),
socket(address, this),
posInterval(posInt),
odInterval(odInt)
{
pos_updater = new QTimer();
odetect_updater = new QTimer();
connect(pos_updater, SIGNAL(timeout()), this, SLOT(getPosition()));
connect(odetect_updater, SIGNAL(timeout()), this, SLOT(getODetect()));
pos_updater->setInterval(posInterval);
odetect_updater->setInterval(odInterval);
pos_updater->start();
odetect_updater->start();
qDebug() << Q_FUNC_INFO;
}
SocketThread::~SocketThread()
{
qDebug() << Q_FUNC_INFO;
delete pos_updater;
delete odetect_updater;
}
void SocketThread::getPosition()
{
QCerebellum::PositionMessage m;
socket >> m;
// Slow down timer if server is unavailable
if (!socket.serverOnline()) {
pos_updater->setInterval(5000);
odetect_updater->stop();
return;
} else {
pos_updater->setInterval(posInterval);
odetect_updater->setInterval(odInterval);
odetect_updater->start();
}
emit positionReceived(m);
}
void SocketThread::getODetect()
{
QCerebellum::ODetectMessage m;
socket >> m;
// Slow down timer if server is unavailable
if (!socket.serverOnline()) {
pos_updater->setInterval(5000);
odetect_updater->stop();
return;
} else {
pos_updater->setInterval(posInterval);
odetect_updater->setInterval(odInterval);
odetect_updater->start();
}
emit odetectReceived(m);
}
void SocketThread::sendTwist(QCerebellum::TwistMessage m)
{
socket << m;
}
void SocketThread::stop()
{
qDebug() << "Stop polling thread";
pos_updater->stop();
odetect_updater->stop();
}