-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.cpp
204 lines (159 loc) · 3.91 KB
/
data.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "data.h"
#include <QString>
using namespace std;
Data* Data::myData = nullptr;
Data::Data() : QObject()
{
init();
}
Data* Data::getInstance()
{
if (myData == nullptr) myData = new Data();
return myData;
}
void Data::init()
{
setacX(0);
setacY(0);
setacZ(0);
setanX(0);
setanY(0);
setanZ(0);
setavX(0);
setavY(0);
setavZ(0);
setgunValue(0);
setltf(0);
setlts(0);
settemperatureValue(0);
// 测试
qsrand(0);
}
void Data::analyze(QByteArray &data)
{
this->getData = data;
QString sigQue;
QString figQue;
sigQue.clear();
figQue.clear();
for (int i = 0; i < getData.size(); ++i) {
if ('a' <= getData.at(i) && getData.at(i) <= 'z')
{
if (!figQue.isEmpty()) {
if (sigQue == "acx") this->acX = figQue.toFloat();
if (sigQue == "acy") this->acY = figQue.toFloat();
if (sigQue == "acz") this->acZ = figQue.toFloat();
if (sigQue == "avx") this->avX = figQue.toFloat();
if (sigQue == "avy") this->avY = figQue.toFloat();
if (sigQue == "avz") this->avZ = figQue.toFloat();
if (sigQue == "agx") this->anX = figQue.toFloat();
if (sigQue == "agy") this->anY = figQue.toFloat();
if (sigQue == "agz") this->anZ = figQue.toFloat();
if (sigQue == "tem") this->temperatureValue = figQue.toFloat();
if (sigQue == "oi") this->gunValue = figQue.toFloat();
if (sigQue == "ltf") this->ltf = figQue.toFloat();
if (sigQue == "lts") this->lts = figQue.toFloat();
figQue.clear();
sigQue.clear();
}
if (getData.at(i) != 'd') sigQue.append(getData.at(i));
}
else {
figQue.append(getData.at(i));
}
}
}
void Data::setacX(float acX) {
this->acX = acX;
}
float Data::getacX() {
return this->acX;
}
void Data::setacY(float acY) {
this->acY = acY;
}
float Data::getacY() {
return this->acY;
}
void Data::setacZ(float acZ){
this->acZ = acZ;
}
float Data::getacZ() {
return this->acZ;
}
void Data::setavX(float avX) {
this->avX = avX;
}
float Data::getavX() {
return this->avX;
}
void Data::setavY(float avY) {
this->avY = avY;
}
float Data::getavY() {
return this->avY;
}
void Data::setavZ(float avZ){
this->avZ = avZ;
}
float Data::getavZ() {
return this->avZ;
}
void Data::setanX(float anX) {
this->anX = anX;
emit sendagXChange();
}
float Data::getanX() {
return this->anX;
}
void Data::setanY(float anY) {
this->anY = anY;
emit sendagYChange();
}
float Data::getanY() {
return this->anY;
}
void Data::setanZ(float anZ){
this->anZ = anZ;
emit sendagZChange();
}
float Data::getanZ() {
return this->anZ;
}
void Data::setgunValue(float gunValue) {
this->gunValue = gunValue;
}
float Data::getgunValue() {
return this->gunValue;
}
void Data::settemperatureValue(float temperatureValue) {
this->temperatureValue = temperatureValue;
}
float Data::gettemperatureValue() {
return this->temperatureValue;
}
void Data::setltf(float staute) {
this->ltf = staute;
}
float Data::getltf() {
return this->ltf;
}
void Data::setlts(float statue) {
this->lts = statue;
}
float Data::getlts() {
return this->lts;
}
void Data::test() {
setacX(qrand() % 100);
setacY(qrand() % 100);
setacZ(qrand() % 100);
setanX(qrand() % 100);
setanY(qrand() % 100);
setanZ(qrand() % 100);
setavX(qrand() % 100);
setavY(qrand() % 100);
setavZ(qrand() % 100);
setgunValue(qrand() % 100);
settemperatureValue(qrand() % 100);
}