-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatathread.cpp
More file actions
290 lines (265 loc) · 5.76 KB
/
datathread.cpp
File metadata and controls
290 lines (265 loc) · 5.76 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include "datathread.h"
#include <QThread>
#include <QVector>
#include <QQueue>
#include <QByteArray>
#include <QDataStream>
#include <cmath>
#include <QReadWriteLock>
#define FACTOR (4.5*pow(10.0,6)/24.0/(pow(2.0,23)-1)) //降幅值系数
double factor=FACTOR;
class MainWindow;
extern QVector<quint8> buffer;
extern QVector<QByteArray> RxA;
extern QReadWriteLock lock;
extern QQueue<double> allData;
extern QQueue<double> allData2;
extern QQueue<double> allData3;
extern QQueue<double> allData4;
extern QQueue<double> allData5;
extern QQueue<double> allData6;
extern QQueue<double> allData7;
extern QQueue<double> allData8;
dataThread::dataThread()
{
}
dataThread::~dataThread()
{
}
void dataThread::solveSlot()
{
//进行处理的帧是37个字节的,后期要检查帧结构是否符合
lock.lockForWrite();
QVector<quint8> buffer_copy=buffer;
buffer.clear();
lock.unlock();
static int cnt=0;
//检查数据丢失
static quint8 loss=buffer_copy[6];
static int flag=0;
if(buffer_copy[6]!=static_cast<quint8>(loss+1))
{
QString str=QString::number(flag);
emit updateStatusSignal(str+QString(tr(" data loss ")));
++flag;
}
loss=buffer_copy[6];
quint8 ch11=buffer_copy[12];
quint8 ch12=buffer_copy[13];
quint8 ch13=buffer_copy[14];
qint32 temp;
if((ch11 & 0x80) != 0)
{
temp = 0xFF;
}
else
{
temp = 0;
}
temp=temp<<8;
temp=temp|ch11;
temp=temp<<8;
temp=temp|ch12;
temp=temp<<8;
temp=temp|ch13;
double temp_1;
temp_1=temp*factor;
//allData.push_back(temp_1);
quint8 ch21=buffer_copy[15];
quint8 ch22=buffer_copy[16];
quint8 ch23=buffer_copy[17];
qint32 temp2;
if((ch21 & 0x80) != 0)
{
temp2 = 0xFF;
}
else
{
temp2 = 0;
}
temp2=temp2<<8;
temp2=temp2|ch21;
temp2=temp2<<8;
temp2=temp2|ch22;
temp2=temp2<<8;
temp2=temp2|ch23;
double temp_2;
temp_2=temp2*factor;
//allData2.push_back(temp_2);
quint8 ch31=buffer_copy[18];
quint8 ch32=buffer_copy[19];
quint8 ch33=buffer_copy[20];
qint32 temp3;
if((ch31 & 0x80) != 0)
{
temp3 = 0xFF;
}
else
{
temp3 = 0;
}
temp3=temp3<<8;
temp3=temp3|ch31;
temp3=temp3<<8;
temp3=temp3|ch32;
temp3=temp3<<8;
temp3=temp3|ch33;
double temp_3;
temp_3=temp3*factor;
//allData3.push_back(temp_3);
quint8 ch41=buffer_copy[21];
quint8 ch42=buffer_copy[22];
quint8 ch43=buffer_copy[23];
qint32 temp4;
if((ch41 & 0x80) != 0)
{
temp4 = 0xFF;
}
else
{
temp4 = 0;
}
temp4=temp4<<8;
temp4=temp4|ch41;
temp4=temp4<<8;
temp4=temp4|ch42;
temp4=temp4<<8;
temp4=temp4|ch43;
double temp_4;
temp_4=temp4*factor;
//allData4.push_back(temp_4);
quint8 ch51=buffer_copy[24];
quint8 ch52=buffer_copy[25];
quint8 ch53=buffer_copy[26];
qint32 temp5;
if((ch51 & 0x80) != 0)
{
temp5 = 0xFF;
}
else
{
temp5 = 0;
}
temp5=temp5<<8;
temp5=temp5|ch51;
temp5=temp5<<8;
temp5=temp5|ch52;
temp5=temp5<<8;
temp5=temp5|ch53;
double temp_5;
temp_5=temp5*factor;
//allData5.push_back(temp_5);
quint8 ch61=buffer_copy[27];
quint8 ch62=buffer_copy[28];
quint8 ch63=buffer_copy[29];
qint32 temp6;
if((ch61 & 0x80) != 0)
{
temp6 = 0xFF;
}
else
{
temp6 = 0;
}
temp6=temp6<<8;
temp6=temp6|ch61;
temp6=temp6<<8;
temp6=temp6|ch62;
temp6=temp6<<8;
temp6=temp6|ch63;
double temp_6;
temp_6=temp6*factor;
//allData6.push_back(temp_6);
quint8 ch71=buffer_copy[30];
quint8 ch72=buffer_copy[31];
quint8 ch73=buffer_copy[32];
qint32 temp7;
if((ch71 & 0x80) != 0)
{
temp7 = 0xFF;
}
else
{
temp7 = 0;
}
temp7=temp7<<8;
temp7=temp7|ch71;
temp7=temp7<<8;
temp7=temp7|ch72;
temp7=temp7<<8;
temp7=temp7|ch73;
double temp_7;
temp_7=temp7*factor;
//allData7.push_back(temp_7);
quint8 ch81=buffer_copy[33];
quint8 ch82=buffer_copy[34];
quint8 ch83=buffer_copy[35];
qint32 temp8;
if((ch81 & 0x80) != 0)
{
temp8 = 0xFF;
}
else
{
temp8 = 0;
}
temp8=temp8<<8;
temp8=temp8|ch81;
temp8=temp8<<8;
temp8=temp8|ch82;
temp8=temp8<<8;
temp8=temp8|ch83;
double temp_8;
temp_8=temp8*factor;
//allData8.push_back(temp_8);
//降低采样率
if(cnt%8==0)
{
emit plotSignal(temp_1,temp_2,temp_3,temp_4,temp_5,temp_6,temp_7,temp_8);
cnt=0;
}
}
void dataThread::solveRxASlot()
{
lock.lockForRead();
QByteArray cur=RxA.front();
RxA.pop_front();
lock.unlock();
QDataStream out(&cur,QIODevice::ReadWrite); //将字节数组读入
while(!out.atEnd())
{
//每字节填充一次,直到结束
quint8 outChar = 0;
out>>outChar;
//rawbyte.push_back(outChar);
//每字节填充成一个字符串
/*QString str = QString("%1").arg(outChar&0xFF,2,16,QLatin1Char('0')); //十六进制的转换
str=str.toUpper();
rawstring.push_back(str);*/
static int flag=0;
//The first time meet 0xA0
if(flag==0&&outChar==0xA0)
{
lock.lockForWrite();
buffer.push_back(outChar);
lock.unlock();
flag=1;
}
else if(flag==1)
{
lock.lockForWrite();
buffer.push_back(outChar);
lock.unlock();
}
else
;
if(buffer.size()==37)
{
emit solveSignal1();
}
}
}
void dataThread::run()
{
//maybe need to write some code
}