-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatareceive.cpp
More file actions
89 lines (73 loc) · 2.45 KB
/
datareceive.cpp
File metadata and controls
89 lines (73 loc) · 2.45 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
83
84
85
86
87
88
89
#include "datareceive.h"
DataReceive::DataReceive(QSerialPort* _port) : port(_port){
}
void DataReceive::GetDataAndEmit(){
bool testMode = true;
QString rawdata;
QStringList dataGroup;
qreal fineData = 0, coarseData = 0;
if(testMode){
fineData = qrand() % ((3 + 1) - 0) + 0;
coarseData = qrand() % ((3 + 1) - 0) + 0;
emit CalculationSignal(fineData, coarseData, ServerTimer::GetInstance().Time());
return;
}
if(port->isReadable()){
rawdata = port->readAll();
QRegExp rx("([0-9]\\.[0-9]{2})\\s([0-9]\\.[0-9]{2})");
int pos = 0;
if(!rawdata.contains(rx)) return;
while((pos = rx.indexIn(rawdata, pos)) != -1){
fineData = rx.cap(1).toDouble();
coarseData = rx.cap(2).toDouble();
pos += rx.matchedLength();
}
emit CalculationSignal(fineData, coarseData, ServerTimer::GetInstance().Time());
}
else{
return;
}
}
/*******************
*
* Data Receiving tab 2
*
* ******************/
DataReceive_2::DataReceive_2(QSerialPort* _port) : DataReceive(_port){
}
void DataReceive_2::GetDataAndEmit(){
bool testMode = false;
QString rawdata;
QStringList dataGroup;
qreal degree = 0, rs = 0, ox = 0, Dr = 0, Dg = 0, Db = 0;
if(testMode){
degree = qrand() % ((3 + 1) - 0) + 0;
rs = qrand() % ((3 + 1) - 0) + 0;
ox = qrand() % ((3 + 1) - 0) + 0;
Dr = qrand() % ((3 + 1) - 0) + 0;
Dg = qrand() % ((3 + 1) - 0) + 0;
Db = qrand() % ((3 + 1) - 0) + 0;
emit SecondTabUpdateSignal(degree, rs, ox, Dr, Dg, Db, ServerTimer::GetInstance().Time());
return;
}
if(port->isReadable()){
rawdata = port->readAll();
qDebug() << rawdata;
QRegExp rx("[0-9]*\\:[0-9]*\\,\\s*([0-9]*)\\,\\s*([0-9]*)\\,\\s*([0-9]*\\.[0-9]*)\\,\\s*([0-9]*\\.[0-9]*)\\,\\s*([0-9]*\\.[0-9]*)\\,\\s*([0-9]*\\.[0-9]*)");
int pos = 0;
if(!rawdata.contains(rx)) return;
while((pos = rx.indexIn(rawdata, pos)) != -1){
degree = rx.cap(2).toDouble();
rs = rx.cap(1).toDouble();
ox = rx.cap(6).toDouble();
Dr = rx.cap(3).toDouble();
Dg = rx.cap(4).toDouble();
Db = rx.cap(5).toDouble();
pos += rx.matchedLength();
}
emit SecondTabUpdateSignal(degree, rs, ox, Dr, Dg, Db, ServerTimer::GetInstance().Time());
}
else{
return;
}
}