1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
using System;
using System.Collections.Generic;
namespace Shared
{
    [System.Serializable]
    public class Sensor : Common
    {
        public Sensor ()
        {
            Type = DeviceType.Sensor;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
        }
 
        public int SensorTypeTestID = SimpleControl.R.MyInternationalizationString.Sensor;
 
        public byte DevicePushType {
            get {
                byte devicePushType = 255;
                switch (Type) {
                case DeviceType.SensorPM25:
                    devicePushType = 0;
                    break;
                case DeviceType.SensorCO2:
                    devicePushType = 1;
                    break;
                case DeviceType.SensorTVOC:
                    devicePushType = 2;
                    break;
                case DeviceType.SensorTemperature:
                    devicePushType = 3;
                    break;
                case DeviceType.SensorHumidity:
                    devicePushType = 4;
                    break;
                }
                return devicePushType;
            }
        }
    }
    /// <summary>
    /// 自动化设备
    /// 一个内存类,存放传感器自动化设备的数据
    /// </summary>
    public class SensorAutomationDevice : Common
    {
        //public byte SubnetID;
        //public byte DeviceID;
        public byte DevicePushType {
            get {
                byte devicePushType = 255;
                switch (Type) {
                case DeviceType.SensorPM25:
                    devicePushType = 0;
                    break;
                case DeviceType.SensorCO2:
                    devicePushType = 1;
                    break;
                case DeviceType.SensorTVOC:
                    devicePushType = 2;
                    break;
                case DeviceType.SensorTemperature:
                    devicePushType = 3;
                    break;
                case DeviceType.SensorHumidity:
                    devicePushType = 4;
                    break;
                }
                return devicePushType;
            }
        }
        public List<SensorAutomation> sensorAutomationList {
            get {
                var sss = new List<SensorAutomation> ();
                List<byte> readAdd = new List<byte> ();
                for (int i = 0; i < 40; i++) {//自动化一共40个,总排序中找出自动化ID相同的,组合成一个自动化
                    if (ConditionIdList == null || AutomationEnableList == null ) {
                        continue;
                    }
                    if (AutomationEnableList [i] == 1 || AutomationEnableList [i] == 2) {
                        var automation = new SensorAutomation ();
                        automation.AutomationId =  (byte)i;
                        automation.AutomationStatus = AutomationEnableList [i];
                        //if (ConditionIdList [i] != 255) {
                            for (int j = 0; j < 40; j++) {//找到第一个自动化之后,取出自动化ID,循环后面的列表,如果相同,就把这个序号加进自动化的条件ID列表里面,这个序号就是条件的ID
                                if (ConditionIdList [j] ==  (byte)i) {
                                    automation.AutomationConditionIdList.Add (j);
                                }
                            }
                        //}
                        readAdd.Add (ConditionIdList [i]);
                        sss.Add (automation);
                    }
                }
                return sss;
            }
        }
        /// <summary>
        /// 自动化状态列表数据  40byte
        /// </summary>
        public byte [] AutomationEnableList;
        /// <summary>
        /// 自动化ID列表数据  40byte
        /// </summary>
        public byte [] ConditionIdList;
    }
    /// <summary>
    /// 自动化
    /// 一个内存类,存放传感器自动化的数据
    /// </summary>
    public class SensorAutomation
    {
        /// <summary>
        /// 自动化的名称
        /// </summary>
        public string AutomationName = "";
        /// <summary>
        /// 自动化的状态
        /// </summary>
        public byte AutomationStatus;
        /// <summary>
        /// 自动化的ID
        /// </summary>
        public byte AutomationId;
        /// <summary>
        /// 自动化包含的条件ID列表
        /// </summary>
        public List<int> AutomationConditionIdList = new List<int>();
        /// <summary>
        /// 自动化包含的条件目标列表
        /// </summary>
        public List<SensorAutomationCondition> sensorAutomationConditionList {
            get {
                var sss = new List<SensorAutomationCondition> ();
                for (int i = 0; i < AutomationConditionIdList.Count; i++) {
                    var automationMsg = new SensorAutomationCondition ();
                    automationMsg.Id = (byte)AutomationConditionIdList [i];
                    automationMsg.Status = AutomationStatus;
                    sss.Add (automationMsg);
                }
                return sss;
            }
        }
        /// <summary>
        /// 自动化触发的目标数据列表
        /// </summary>
        public List<byte []> TargetBytesList = new List<byte []> ();
 
 
        //public SensorAutonmationCycle AutonmationCycle;
 
    }
 
    public class SensorAutonmationCycle
    {
        //1   类型  1.PM2.5        0
        //2.CO2浓度     1
        //3.TVOC浓度    2
        //4.温度         3
        //5.湿度         4
        //2   通道号 预留,这里只有一个通道
        //3   目标级别 Level: 0 ~ 7 每一级别对不同的组范围
        //注:0级为差
        //    1.级为良
        //    2 级为优
 
        /// <summary>
        /// 4   重复周期类型  
        ///     0:系统     
        ///     1:自定义
        /// </summary>
        public byte CycleType = 0;
        /// <summary>
        /// 5   重复周期设置 系统:
        ///     0:只执行一次
        ///     1:每天一次
        ///     2:工作日
        ///     3:周末,非工作日
        /// </summary>
        public byte CycleType_System = 0;
 
        /// <summary>
        /// 自定义:
        ///     启用第 6 个byte 来自定义一周里面的重复时间
        /// 6   自定义重复周期 Bit0 - bit6 代表周日到周六 ( 1:为选定  0:为取消) 第 4 byte(CycleType) 为 1 时有效
        /// 7   年 范围:公元年与2000的差
        /// 8   月   0 - 11
        /// 9   日   0 - 30
        /// 10  时   0 - 23
        /// 11  分   0 - 59 
        /// </summary>
        public byte CycleType_Custom_Begin = 0;
        /// <summary>
        /// 12  年 范围:公元年与2000的差
        /// 13  月   0 - 11
        /// 14  日   0 - 30
        /// 15  时   0 - 23
        /// 16  分   0 - 59 
        /// </summary>
        public byte CycleType_Custom_End = 0;
    }
 
 
    /// <summary>
    /// 自动化的具体条件
    /// 一个内存类,存放传感器自动化条件的数据
    /// </summary>
    public class SensorAutomationCondition
    {
 
        /// <summary>
        /// 自动化条件的具体状态,与自动化类里面的条件是一样的
        /// 0:delete;
        /// 1:enable;
        /// 2:unused
        /// </summary>
        public byte Status;
 
        /// <summary>
        /// 自动化条件ID、条件在自动化里面的index
        /// 0-39
        /// </summary>
        public byte Id;
 
        public byte PushId {
            get {
                return ((byte)(Id / 8));
            }
        }
 
        public byte ConditionLevel {
            get {
                return ((byte)(Id % 8));
            }
        }
        /// <summary>
        /// 自动化条件的名称
        /// </summary>
        public string Name = "";
 
    }
 
 
 
    [System.Serializable]
    public class SensorMobileDetection : Sensor
    {
        public SensorMobileDetection ()
        {
            //  移动探测(01)增加状态广播项设置, 通道号,备注,使能位,灵敏度,状态,
            Type = DeviceType.SensorMobileDetection;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorMobileDetection;
        }
 
        public bool Enable = true;
 
        public byte Sensitivity;
 
        public byte Status;
 
    }
 
    [System.Serializable]
    public class SensorTemperature : Sensor
    {
        public SensorTemperature ()
        {
            //温度(02)增加状态广播项设置,详见操作码4.29   通道号,备注,当前温度(同时支持整形,浮点类型)E3E5的返回数据
            Type = DeviceType.SensorTemperature;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Environmental;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorTemperature;
 
        }
 
        public double CurrentTemperature;
 
    }
 
 
    [System.Serializable]
    public class SensorHumidity : Sensor
    {
        public SensorHumidity ()
        {
            //湿度(03)增加状态广播项设置,详见操作码4.29   通道号,备注,使能位,当前湿度
            Type = DeviceType.SensorHumidity;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Environmental;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorHumidity;
 
        }
        public bool Enable = true;
 
        public double CurrentHumidity;
 
    }
 
    [System.Serializable]
    public class SensorIllumination : Sensor
    {
        public SensorIllumination ()
        {
            //照度(04)增加状态广播项设置,详见操作码4.29   通道号,备注,使能位,当前照度
            Type = DeviceType.SensorIllumination;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Environmental;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorIllumination;
 
        }
        public bool Enable = true;
 
        public int CurrentIllumination;
 
    }
 
    [System.Serializable]
    public class SensorTVOC : Sensor
    {
        public SensorTVOC ()
        {
            //TVOC(05)   通道号,备注,使能位,当前空气质量等级
            Type = DeviceType.SensorTVOC;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Environmental;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorTVOC;
 
        }
        public bool Enable = true;
 
        public double CurrentTVOC;
 
    }
 
    [System.Serializable]
    public class SensorPM25 : Sensor
    {
        public SensorPM25 ()
        {
            //PM2.5(06)   通道号,备注,使能位,当前空气PM2.5值
            Type = DeviceType.SensorPM25;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorPM25;
 
        }
        public bool Enable = true;
 
        public int CurrentPM25;
 
    }
 
    [System.Serializable]
    public class SensorCO2 : Sensor
    {
        public SensorCO2 ()
        {
            //CO2(07) 通道号,备注,使能位,当前CO2 ppm值
            Type = DeviceType.SensorCO2;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Environmental;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorCO2;
 
        }
        public bool Enable = true;
 
        public int CurrentCO2;
 
    }
 
    [System.Serializable]
    public class SensorLPG : Sensor
    {
        public SensorLPG ()
        {
            //液化石油气(LPG)(08)  通道号,备注,使能位,当前LPG ppm值
            Type = DeviceType.SensorLPG;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorLPG;
 
            //人工煤气(CO,H2)(09) 通道号,备注,使能位,当前综合ppm值
            //天然气(CH4)(10)    通道号,备注,使能位,当前综合ppm值
        }
        public bool Enable = true;
 
        public byte CurrentLPG;
    }
 
    [System.Serializable]
    public class SensorCOH2 : Sensor
    {
        public SensorCOH2 ()
        {
            //人工煤气(CO,H2)(09) 通道号,备注,使能位,当前综合ppm值
            Type = DeviceType.SensorCOH2;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorCOH2;
        }
        public bool Enable = true;
 
        public int CurrentCOH2;
    }
 
    [System.Serializable]
    public class SensorCH4 : Sensor
    {
        public SensorCH4 ()
        {
            //天然气(CH4)(10)    通道号,备注,使能位,当前综合ppm值
            Type = DeviceType.SensorCH4;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorCH4;
        }
        public bool Enable = true;
 
        public int CurrentCH4;
    }
 
    [System.Serializable]
    public class SensorSmoke : Sensor
    {
        public SensorSmoke ()
        {
            //    烟雾(11)  通道号,备注,使能位,当前状态
            Type = DeviceType.SensorSmoke;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorSmoke;
        }
        public bool Enable = true;
 
        public int CurrentStatus;
    }
 
    [System.Serializable]
    public class SensorWindSpeed : Sensor
    {
        public SensorWindSpeed ()
        {
            //风速(12)  通道号,备注,使能位,当前风速
            Type = DeviceType.SensorWindSpeed;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorWindSpeed;
        }
        public bool Enable = true;
 
        public int CurrentWindSpeed;
    }
 
    [System.Serializable]
    public class SensorWindPressure : Sensor
    {
        public SensorWindPressure ()
        {
            //风压(13)  通道号,备注,使能位,当前风压
            Type = DeviceType.SensorWindPressure;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorWindPressure;
        }
        public bool Enable = true;
 
        public int CurrentWindPressure;
    }
 
    [System.Serializable]
    public class SensorLiquidFlow : Sensor
    {
        public SensorLiquidFlow ()
        {
            //液体流量(14)    通道号,备注,使能位,当前液体流量
            Type = DeviceType.SensorLiquidFlow;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorLiquidFlow;
        }
        public bool Enable = true;
 
        public int CurrentLiquidFlow;
    }
 
    [System.Serializable]
    public class SensorLiquidPressure : Sensor
    {
        public SensorLiquidPressure ()
        {
            //液体压力(15)    通道号,备注,使能位,当前液体压力
            Type = DeviceType.SensorLiquidPressure;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorLiquidPressure;
        }
        public bool Enable = true;
 
        public int CurrentLiquidPressure;
    }
 
    [System.Serializable]
    public class SensorLiquidDepth : Sensor
    {
        public SensorLiquidDepth ()
        {
            //液体深度(16)    通道号,备注,使能位,当前液体深度(mm)
            Type = DeviceType.SensorLiquidDepth;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorLiquidDepth;
        }
        public bool Enable = true;
 
        public int CurrentLiquidDepth;
    }
 
    [System.Serializable]
    public class SensorRainfall : Sensor
    {
        public SensorRainfall ()
        {
            //雨量(17)  通道号,备注,使能位,当前雨量(无雨,小雨,大雨)
            Type = DeviceType.SensorRainfall;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorRainfall;
        }
        public bool Enable = true;
 
        public int CurrentRainfall;
    }
 
    [System.Serializable]
    public class SensorWeight : Sensor
    {
        public SensorWeight ()
        {
            //重量(18)  通道号,备注,使能位,当前物体重量(KG)
            Type = DeviceType.SensorWeight;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorWeight;
        }
        public bool Enable = true;
 
        public int CurrentWeight;
    }
    [System.Serializable]
    public class SensorHeightLength : Sensor
    {
        public SensorHeightLength ()
        {
            //高度/长度(19)   通道号,备注,使能位,测量高度/长度(mm)
            Type = DeviceType.SensorHeightLength;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorHeightLength;
        }
        public bool Enable = true;
 
        public int CurrentHeightLength;
    }
    [System.Serializable]
    public class SensorVelocity : Sensor
    {
        public SensorVelocity ()
        {
            //物体速度(20)    通道号,备注,当前物体速度(m/s)
            Type = DeviceType.SensorHeightLength;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorVelocity;
        }
        public bool Enable = true;
 
        public int CurrentVelocity;
    }
    [System.Serializable]
    public class SensorVibration : Sensor
    {
        public SensorVibration ()
        {
            //震动(21)  通道号,备注,使能位,震动状态
            Type = DeviceType.SensorVibration;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorVibration;
        }
        public bool Enable = true;
 
        public int CurrentVibration;
    }
    [System.Serializable]
    public class SensorVoltage : Sensor
    {
        public SensorVoltage ()
        {
            //电压(22)  通道号,备注,使能位,当前电压
            Type = DeviceType.SensorVoltage;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorVoltage;
        }
        public bool Enable = true;
 
        public int CurrentVoltage;
    }
    [System.Serializable]
    public class SensorCurrent : Sensor
    {
        public SensorCurrent ()
        {
            //电流(23)  通道号,备注,使能位,当前电流
            Type = DeviceType.SensorVoltage;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorCurrent;
        }
        public bool Enable = true;
 
        public int CurrentCurrent;
    }
    [System.Serializable]
    public class SensorPower : Sensor
    {
        public SensorPower ()
        {
            //功率(24)  通道号,备注,使能位,当前功率
            Type = DeviceType.SensorPower;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Sensor;
            SensorTypeTestID = SimpleControl.R.MyInternationalizationString.SensorPower;
        }
        public bool Enable = true;
 
        public int CurrentPower;
    }
}