ningshuxia
2023-03-11 8bf5f0281d3343160e76f7b79dacba9658f1c115
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Expert.Untity;
using IStation.Untity;
 
namespace IStation.Model 
{
    /// <summary>
    /// 
    /// </summary>
    public class BodyWave
    {
        /// <summary>
        /// 
        /// </summary>
        public BodyWave() { }
 
        /// <summary>
        /// 采集器IP(16个字节)
        /// </summary>
        public string IP { get; set; }
 
        /// <summary>
        /// 发送时间 (4个字节)
        /// </summary>
        public DateTime SendTime { get; set; }
 
        /// <summary>
        /// 采集器类型
        /// </summary>
        public eCollectorType CollectorType { get; set; }
 
        /// <summary>
        /// 解析上传的键相个数
        /// </summary>
        public int KeyCount { get; set; }
 
        /// <summary>
        /// 采集时间 (4个字节)
        /// </summary>
        public DateTime DataTime { get; set; }
 
        /// <summary>
        /// 键相号
        /// </summary>
        public int KeyIndex { get; set; }
 
        /// <summary>
        /// 采集类型
        /// </summary>
        public eCollectMethod KeyOn { get; set; }
 
        /// <summary>
        /// 每周期采样点数
        /// </summary>
        public int PointPR { get; set; }
 
        /// <summary>
        /// 每组数据采样点数
        /// </summary>
        public int Len { get; set; }
 
        /// <summary>
        /// 转速
        /// </summary>
        public float Rpm { get; set; }
 
        /// <summary>
        /// 频率
        /// </summary>
        public float Fs { get; set; }
 
        /// <summary>
        /// 上送数据类型
        /// </summary>
        public int StartStopType { get; set; }
 
        /// <summary>
        /// 启停车数据类型
        /// </summary>
        public int StartStopDataType { get; set; }
 
        /// <summary>
        /// 传感器类型
        /// </summary>
        public int SenType { get; set; }
 
        /// <summary>
        /// 放大倍数
        /// </summary>
        public int Magnification { get; set; }
 
        /// <summary>
        /// 通道校准系数
        /// </summary>
        public float[] CalParams { get; set; }
 
        /// <summary>
        /// 积分系数
        /// </summary>
        public float[] CoffParams { get; set; }
 
        /// <summary>
        /// 键相标识
        /// </summary>
        public int ChanIndex { get; set; }
 
        /// <summary>
        /// 通道传感器类型
        /// </summary>
        public eChanSenType[] ChanSenType { get; set; }
 
        /// <summary>
        /// 通道积分类型
        /// </summary>
        public eChanIntegType[] ChanIntegType { get; set; }
 
        /// <summary>
        /// 通道放大倍数
        /// </summary>
        public int[] ChanMagnification { get; set; }
 
        /// <summary>
        /// 通道校准系数
        /// </summary>
        public float[] ChanCalParams { get; set; }
 
        /// <summary>
        /// 通道灵敏度
        /// </summary>
        public float[] ChanSencivity { get; set; }
 
        /// <summary>
        /// 通道一次积分系数
        /// </summary>
        public float[] ChanCoefficient1x { get; set; }
 
        /// <summary>
        /// 通道二次积分系数
        /// </summary>
        public float[] ChanCoefficient2x { get; set; }
 
        /// <summary>
        /// 通道波形
        /// </summary>
        public float[][] ChanWave { get; set; }
 
        /// <summary>
        /// 通道直流量
        /// </summary>
        public float[][] ChanDC { get; set; }
 
        /// <summary>
        /// 获取
        /// </summary>
        public static BodyWave Get(byte[] bts)
        {
            if (bts == null)
                return default;
            if (bts.Count() < 1)
                return default;
            var model = new BodyWave();
            var bufferIndex = 0;
            {
                //解析IP    
                var len_ip = 16;
                var ipBuffer = new byte[len_ip];
                Array.Copy(bts, bufferIndex, ipBuffer, 0, len_ip);
                var ip_str = Encoding.UTF8.GetString(ipBuffer);
                model.IP = ip_str.Replace("\0", "");
                bufferIndex += len_ip;
            }
            {
                //解析SendTime
                var len_sendTime = 4;
                var sendTimeBuffer = new byte[len_sendTime];
                Array.Copy(bts, bufferIndex, sendTimeBuffer, 0, len_sendTime);
                var sendTime_seconds = BitConverter.ToInt32(sendTimeBuffer, 0);
                model.SendTime = DateTimeTransfer.FromSeconds(sendTime_seconds);
                bufferIndex += len_sendTime;
            }
            {
                //解析采集器类型
                var len_collectorType = 4;
                var collectorTypeBuffer = new byte[len_collectorType];
                Array.Copy(bts, bufferIndex, collectorTypeBuffer, 0, len_collectorType);
                var collectorType_int = BitConverter.ToInt32(collectorTypeBuffer, 0);
                model.CollectorType = (eCollectorType)collectorType_int;
                bufferIndex += len_collectorType;
            }
            {
                //解析上传的键相个数
                var len_keyCount = 4;
                var keyCountBuffer = new byte[len_keyCount];
                Array.Copy(bts, bufferIndex, keyCountBuffer, 0, len_keyCount);
                var keyCount_int = BitConverter.ToInt32(keyCountBuffer, 0);
                model.KeyCount = keyCount_int;
                bufferIndex += len_keyCount;
            }
            {
                //解析采集时间(秒)
                var len_dataTime = 4;
                var dataTimeBuffer = new byte[len_dataTime];
                Array.Copy(bts, bufferIndex, dataTimeBuffer, 0, len_dataTime);
                var dataTime_seconds = BitConverter.ToInt32(dataTimeBuffer, 0);
                model.DataTime = DateTimeTransfer.FromSeconds(dataTime_seconds);
                bufferIndex += len_dataTime;
            }
            {
                //解析采集时间微秒部分
                var len_microsecond = 4;
                var microsecondBuffer = new byte[len_microsecond];
                Array.Copy(bts, bufferIndex, microsecondBuffer, 0, len_microsecond);
                var microsecond_int = BitConverter.ToInt32(microsecondBuffer, 0);
                model.DataTime = model.DataTime.AddMilliseconds(microsecond_int / 1000f);
                bufferIndex += len_microsecond;
            }
            {
                //解析键相号
                var len_keyIndex = 4;
                var keyIndexBuffer = new byte[len_keyIndex];
                Array.Copy(bts, bufferIndex, keyIndexBuffer, 0, len_keyIndex);
                var keyIndex_int = BitConverter.ToInt32(keyIndexBuffer, 0);
                model.KeyIndex = keyIndex_int;
                bufferIndex += len_keyIndex;
            }
            {
                //解析采集类型
                var len_keyOn = 4;
                var keyOnBuffer = new byte[len_keyOn];
                Array.Copy(bts, bufferIndex, keyOnBuffer, 0, len_keyOn);
                var keyOn_int = BitConverter.ToInt32(keyOnBuffer, 0);
                model.KeyOn = (eCollectMethod)keyOn_int;
                bufferIndex += len_keyOn;
            }
            {
                //解析每周期采样点数
                var len_pointPR = 4;
                var pointPRBuffer = new byte[len_pointPR];
                Array.Copy(bts, bufferIndex, pointPRBuffer, 0, len_pointPR);
                var pointPR_int = BitConverter.ToInt32(pointPRBuffer, 0);
                model.PointPR = pointPR_int;
                bufferIndex += len_pointPR;
            }
            {
                //解析每组数据采样点数
                var len_len = 4;
                var lenBuffer = new byte[len_len];
                Array.Copy(bts, bufferIndex, lenBuffer, 0, len_len);
                var len_int = BitConverter.ToInt32(lenBuffer, 0);
                model.Len = len_int;
                bufferIndex += len_len;
            }
            {
                //解析转速
                var len_rpm = 4;
                var rpmBuffer = new byte[len_rpm];
                Array.Copy(bts, bufferIndex, rpmBuffer, 0, len_rpm);
                var rpm_float = BitConverter.ToSingle(rpmBuffer, 0);
                model.Rpm = rpm_float;
                bufferIndex += len_rpm;
            }
            {
                //解析频率
                var len_fs = 4;
                var fsBuffer = new byte[len_fs];
                Array.Copy(bts, bufferIndex, fsBuffer, 0, len_fs);
                var fs_float = BitConverter.ToSingle(fsBuffer, 0);
                model.Fs = fs_float;
                bufferIndex += len_fs;
            }
            {
                //解析上送数据类型
                var len_startStopType = 4;
                var startStopTypeBuffer = new byte[len_startStopType];
                Array.Copy(bts, bufferIndex, startStopTypeBuffer, 0, len_startStopType);
                var startStopType_int = BitConverter.ToInt32(startStopTypeBuffer, 0);
                model.StartStopType = startStopType_int;
                bufferIndex += len_startStopType;
            }
            {
                //解析启停车数据类型
                var len_startStopDataType = 4;
                var startStopDataTypeBuffer = new byte[len_startStopDataType];
                Array.Copy(bts, bufferIndex, startStopDataTypeBuffer, 0, len_startStopDataType);
                var startStopDataType_int = BitConverter.ToInt32(startStopDataTypeBuffer, 0);
                model.StartStopType = startStopDataType_int;
                bufferIndex += len_startStopDataType;
            }
            {
                //解析传感器类型
                var len_senType = 4;
                var senTypeBuffer = new byte[len_senType];
                Array.Copy(bts, bufferIndex, senTypeBuffer, 0, len_senType);
                var senType_int = BitConverter.ToInt32(senTypeBuffer, 0);
                model.SenType = senType_int;
                bufferIndex += len_senType;
            }
            {
                //解析放大倍数
                var len_magnification = 4;
                var magnificationBuffer = new byte[len_magnification];
                Array.Copy(bts, bufferIndex, magnificationBuffer, 0, len_magnification);
                var magnification_int = BitConverter.ToInt32(magnificationBuffer, 0);
                model.Magnification = magnification_int;
                bufferIndex += len_magnification;
            }
            {
                //解析通道校准系数
                var len_calParams = 4;
                model.CalParams = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var calParamsBuffer = new byte[len_calParams];
                    Array.Copy(bts, bufferIndex, calParamsBuffer, 0, len_calParams);
                    var calParams_float = BitConverter.ToSingle(calParamsBuffer, 0);
                    model.CalParams[i] = calParams_float;
                    bufferIndex += len_calParams;
 
                }
            }
            {
                //解析积分系数
                var len_coffParams = 4;
                model.CoffParams = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var coffParamsBuffer = new byte[len_coffParams];
                    Array.Copy(bts, bufferIndex, coffParamsBuffer, 0, len_coffParams);
                    var coffParams_float = BitConverter.ToSingle(coffParamsBuffer, 0);
                    model.CoffParams[i] = coffParams_float;
                    bufferIndex += len_coffParams;
                }
            }
            {
                //解析通道标识
                var len_chanIndex = 4;
                var chanIndexBuffer = new byte[len_chanIndex];
                Array.Copy(bts, bufferIndex, chanIndexBuffer, 0, len_chanIndex);
                var chanIndex_int = BitConverter.ToInt32(chanIndexBuffer, 0);
                model.ChanIndex = chanIndex_int;
                bufferIndex += len_chanIndex;
            }
            {
                //解析通道传感器类型
                var len_chanSenType = 4;
                model.ChanSenType = new eChanSenType[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanSenTypeBuffer = new byte[len_chanSenType];
                    Array.Copy(bts, bufferIndex, chanSenTypeBuffer, 0, len_chanSenType);
                    var chanSenType_int = BitConverter.ToInt32(chanSenTypeBuffer, 0);
                    model.ChanSenType[i] = (eChanSenType)chanSenType_int;
                    bufferIndex += len_chanSenType;
                }
            }
            {
                //解析通道积分类型
                var len_chanIntegType = 4;
                model.ChanIntegType = new eChanIntegType[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanIntegTypeBuffer = new byte[len_chanIntegType];
                    Array.Copy(bts, bufferIndex, chanIntegTypeBuffer, 0, len_chanIntegType);
                    var chanIntegType_int = BitConverter.ToInt32(chanIntegTypeBuffer, 0);
                    model.ChanIntegType[i] = (eChanIntegType)chanIntegType_int;
                    bufferIndex += len_chanIntegType;
                }
            }
            {
                //解析通道放大倍数
                var len_chanMagnification = 4;
                model.ChanMagnification = new int[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanMagnificationBuffer = new byte[len_chanMagnification];
                    Array.Copy(bts, bufferIndex, chanMagnificationBuffer, 0, len_chanMagnification);
                    var chanMagnificationBuffer_int = BitConverter.ToInt32(chanMagnificationBuffer, 0);
                    model.ChanMagnification[i] = chanMagnificationBuffer_int;
                    bufferIndex += len_chanMagnification;
 
                }
            }
            {
                //解析通道校准系数
                var len_chanCalParams = 4;
                model.ChanCalParams = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanCalParamsBuffer = new byte[len_chanCalParams];
                    Array.Copy(bts, bufferIndex, chanCalParamsBuffer, 0, len_chanCalParams);
                    var chanCalParamsBuffer_float = BitConverter.ToSingle(chanCalParamsBuffer, 0);
                    model.ChanCalParams[i] = chanCalParamsBuffer_float;
                    bufferIndex += len_chanCalParams;
                }
 
            }
            {
                //解析通道灵敏度
                var len_chanSencivity = 4;
                model.ChanSencivity = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanSencivityBuffer = new byte[len_chanSencivity];
                    Array.Copy(bts, bufferIndex, chanSencivityBuffer, 0, len_chanSencivity);
                    var chanSencivityBuffer_float = BitConverter.ToSingle(chanSencivityBuffer, 0);
                    model.ChanSencivity[i] = chanSencivityBuffer_float;
                    bufferIndex += len_chanSencivity;
                }
            }
            {
                //解析一次积分系数
                var len_chanCoefficient1x = 4;
                model.ChanCoefficient1x = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanCoefficient1xBuffer = new byte[len_chanCoefficient1x];
                    Array.Copy(bts, bufferIndex, chanCoefficient1xBuffer, 0, len_chanCoefficient1x);
                    var chanCoefficient1xBuffer_float = BitConverter.ToSingle(chanCoefficient1xBuffer, 0);
                    model.ChanCoefficient1x[i] = chanCoefficient1xBuffer_float;
                    bufferIndex += len_chanCoefficient1x;
                }
            }
            {
                //解析二次积分系数
                var len_chanCoefficient2x = 4;
                model.ChanCoefficient2x = new float[8];
                for (int i = 0; i < 8; i++)
                {
                    var chanCoefficient2xBuffer = new byte[len_chanCoefficient2x];
                    Array.Copy(bts, bufferIndex, chanCoefficient2xBuffer, 0, len_chanCoefficient2x);
                    var chanCoefficient2xBuffer_float = BitConverter.ToSingle(chanCoefficient2xBuffer, 0);
                    model.ChanCoefficient2x[i] = chanCoefficient2xBuffer_float;
                    bufferIndex += len_chanCoefficient2x;
                }
            }
            {
                //解析波形
                var len_wave = 4;
                model.ChanWave = new float[8][];
                for (int i = 0; i < 8; i++)
                {
                    model.ChanWave[i] = new float[model.Len];
                    for (int j = 0; j < model.Len; j++)
                    {
                        var chanWaveBuffer = new byte[len_wave];
                        Array.Copy(bts, bufferIndex, chanWaveBuffer, 0, len_wave);
                        var chanWaveBuffer_float = BitConverter.ToSingle(chanWaveBuffer, 0);
                        model.ChanWave[i][j] = chanWaveBuffer_float;
                        bufferIndex += len_wave;
                    }
                }
            }
            {
                //解析直流
                var len_dc = 4;
                model.ChanDC = new float[8][];
                for (int i = 0; i < 8; i++)
                {
                    model.ChanDC[i] = new float[32];
                    for (int j = 0; j < 32; j++)
                    {
                        var chanDCBuffer = new byte[len_dc];
                        Array.Copy(bts, bufferIndex, chanDCBuffer, 0, len_dc);
                        var chanDCBuffer_float = BitConverter.ToSingle(chanDCBuffer, 0);
                        model.ChanDC[i][j] = chanDCBuffer_float;
                        bufferIndex += len_dc;
                    }
                }
            }
            {
                //解析尾部
                var chanEndBuffer = new byte[4];
                Array.Copy(bts, bufferIndex, chanEndBuffer, 0, 4);
                var bit_str = BitConverter.ToString(chanEndBuffer);
                bufferIndex += 4;
            }
            return model;
        }
 
 
    }
}