CrabtreeOn,印度客户定制APP,迁移2.0平台版本
JLChen
2021-01-20 4c993fcb71b92f8e9837ca8f50f3b5e8f9c59cfe
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
//using System;
//using System.Collections.Generic;
//using Shared;
 
//namespace SmartHome
//{
//    /// <summary>
//    /// HDLLink协议 工具类
//    /// </summary>
//    public class HDLLinkUtlis
//    {
//        #region ■ Current___________________________
//        /// <summary>
//        /// 通用方法
//        /// </summary>
//        private static HDLLinkUtlis m_Current = null;
//        /// <summary>
//        /// 通用方法
//        /// </summary>
//        public static HDLLinkUtlis Current {
//            get {
//                if (m_Current == null) {
//                    m_Current = new HDLLinkUtlis ();
//                }
//                return m_Current;
//            }
//        }
//        #endregion
 
 
 
 
//        /// <summary>
//        /// 将在线设备转换成sid + 属性列表
//        /// </summary>
//        /// <param name="onlineDevices"></param>
//        /// <returns></returns>
//        public List<Sid> ConvertToSidListToIotCloud (string sOid, Common onlineDevice)
//        {
//            List<Sid> tmpResult = new List<Sid> ();
//            try {
//                if (onlineDevice.bytSimpleParam == null || onlineDevice.bytSimpleParam.Length == 0) {
//                    string sSimpleList = DeviceTypeList.GetSimpleFunctionListFromPublicModeGroup (onlineDevice.DeviceType);
//                    #region
//                    string [] ArayStr = sSimpleList.Trim ().Split (new char [] { ' ' });
//                    List<byte> ArayTmp = new List<byte> ();
//                    for (int i = 0; i < ArayStr.Length; i++) {
//                        if (ArayStr [i] != null && ArayStr [i] != "" && ArayStr [i].Trim () != "") {
//                            ArayTmp.Add (Convert.ToByte (ArayStr [i], 16));
//                        }
//                    }
//                    onlineDevice.bytSimpleParam = ArayTmp.ToArray ();
//                    #endregion
//                }
//                if (onlineDevice.bytSimpleParam != null && onlineDevice.bytSimpleParam.Length > 0) {
//                    for (int intI = 0; intI < onlineDevice.bytSimpleParam.Length / 3; intI++) {
//                        byte BigType = onlineDevice.bytSimpleParam [0 + intI * 3];
//                        byte SmallType = onlineDevice.bytSimpleParam [1 + intI * 3];
//                        int Count = onlineDevice.bytSimpleParam [2 + intI * 3];
//                        if (Count > 0) {
//                            for (int j = 1; j <= Count; j++) {
//                                Sid tmpSid = new Sid ();
//                                tmpSid.sid = HDLSysPF.FormingNewSid (onlineDevice.Type, sOid, j, false, BigType, SmallType);
//                                tmpSid.oid = sOid;
 
//                                try {
//                                    tmpSid.name = onlineDevice.myEasyDesignChannelRemark [intI] [j - 1];
//                                } catch (Exception ex) {
//                                    tmpSid.name = "";
//                                }
//                                if (tmpSid.name == null || tmpSid.name == "" || tmpSid.name == "Unread") {
//                                    tmpSid.name = onlineDevice.Remark + CsConst.mstrINIDefault.IniReadValue ("public", "00000", "") + " " + j.Tostring ();
//                                    if (onlineDevice.Remark == "") {
//                                        tmpSid.name = onlineDevice.strDescription + CsConst.mstrINIDefault.IniReadValue ("public", "00000", "") + " " + j.Tostring ();
//                                    }
//                                }
//                                GateWay.sidObject tmp = HDLSysPF.UpdateSidAttributesToDeviceList (onlineDevice, tmpSid.name, sOid, j, BigType, SmallType, true);
//                                tmpSid.attributes = tmp.attributes;//UpdateSidAttributesToDeviceList(onlineDevice.DeviceType, sOid, j, BigType, SmallType, ref spk);
//                                tmpSid.spk = tmp.spk;
//                                tmpResult.Add (tmpSid);
//                            }
//                        }
//                    }
//                }
//                return tmpResult;
//            } catch (Exception) {
//                return tmpResult;
//                //throw;
//            }
//        }
 
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="homeId"></param>
//        /// <param name="onlineDevices"></param>
//        /// <param name="gatewayId"></param>
//        /// <param name="currentProject"></param>
//        public void ConvertOidListToIotStruct (string homeId, List<Common> onlineDevices, string gatewayId, ref IotCloud currentProject)
//        {
//            try {
//                //step 1 ;抓换类型
//                Sids functionList = currentProject.functions;
//                List<Sid> tmpFunction = new List<Sid> ();
 
//                //step 2 转换类型
//                Oids tmp = ConvertToOidListToIotCloud (onlineDevices, ref tmpFunction);
//                if (currentProject.modules == null || currentProject.modules.devices == null || currentProject.modules.devices.Count == 0) currentProject.modules = tmp;
//                else {
//                    foreach (Oid tmpModule in tmp.devices) {
//                        Oid tmpFind = currentProject.modules.devices.Find (P => P.mac.Equals (tmpModule.mac));
//                        if (tmpFind == null) currentProject.modules.devices.Add (tmpModule);
//                    }
//                }
//                tmp.homeId = homeId;
 
//                //上传功能列表
//                #region
//                //if (functionList == null)
//                //{
//                functionList = new Sids ();
//                functionList.devices = new List<Sid> ();
//                functionList.devices = tmpFunction;
//                //}
//                functionList.homeId = homeId;
//                functionList.gatewayId = gatewayId;
//                currentProject.modules = tmp;
//                currentProject.functions = functionList;
//                #endregion
 
//            } catch (Exception ex) {
//                //MessageBox.Show (ex.Tostring ());
//                //throw;
//            }
//        }
 
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="homeId"></param>
//        /// <param name="onlineDevices"></param>
//        /// <param name="gatewayId"></param>
//        /// <param name="currentProject"></param>
//        public void ConvertOidListToIotStruct (string homeId, List<Common> onlineDevices, string gatewayId, ref IotCloud currentProject)
//        {
//            try {
//                //step 1 转换类型
//                Sids functionList = currentProject.functions;
//                List<Sid> tmpFunction = new List<Sid> ();
 
//                //step 2 转换类型
//                Oids tmp = ConvertToOidListToIotCloud (onlineDevices, ref tmpFunction);
//                if (currentProject.modules == null || currentProject.modules.devices == null || currentProject.modules.devices.Count == 0) currentProject.modules = tmp;
//                else {
//                    foreach (Oid tmpModule in tmp.devices) {
//                        Oid tmpFind = currentProject.modules.devices.Find (P => P.mac.Equals (tmpModule.mac));
//                        if (tmpFind == null) currentProject.modules.devices.Add (tmpModule);
//                    }
//                }
//                tmp.homeId = homeId;
 
//                //上传功能列表
//                #region
//                //if (functionList == null)
//                //{
//                functionList = new Sids ();
//                functionList.devices = new List<Sid> ();
//                functionList.devices = tmpFunction;
//                //}
//                functionList.homeId = homeId;
//                functionList.gatewayId = gatewayId;
//                currentProject.modules = tmp;
//                currentProject.functions = functionList;
//                #endregion
 
//            } catch (Exception ex) {
//                //MessageBox.Show (ex.Tostring ());
//                //throw;
//            }
//        }
 
//        /// <summary>
//        /// 生成设备Oid
//        /// </summary>
//        /// <param name="iDeviceType"></param>
//        /// <returns></returns>
//        public string FormingNewOid (DeviceType deviceType)
//        {
//            string sOid = "";
//            try {
//                //1.生成 厂商 + 通讯方式 
//                string sOidBeginsWith = "000101";//厂商 + 通讯方式
//                //2.生成产品时间戳
//                long sTimeSp = ConvertDateTimeLong (); //以2020年1月1日算出的时间戳0.1s为单位
//                string sTimeSpan = "";
//                ConvertIntToByteArray (sTimeSp, ref sTimeSpan);
//                if (sTimeSpan.Length != 8) return sOid;
//                //延迟10ms
 
//                //3.生成产品类别
//                var productType = GetProductType (deviceType);
//                sOid = sOidBeginsWith + sTimeSpan + productType;
 
//                return sOid;
//            } catch {
//                return sOid;
//            }
//        }
 
//        /// <summary>
//        /// 获取产品类别
//        //产品类别 1byte
//        //编号   描述
//        //01    调光器
//        //02    继电器
//        //03    干接点模块
//        //04    传感器
//        //05    面板
//        //06    RCU
//        //07    网关
//        //08    红外发射
//        //09    Android屏
//        //10    场景
//        //11    音乐播放器
//        //12    232/485转换器
//        //21    自动化
//        //22    安防防区
//        //14    窗帘模块
//        //15    HVAC
//        //16    地热模块
//        /// </summary>
//        /// <param name="deviceType"></param>
//        /// <returns></returns>
//        public string GetProductType (DeviceType deviceType)
//        {
//            string productType = "";
//            switch (deviceType) {
//            case DeviceType.LightDimming:
//                productType = "01";//01    调光器
//                break;
//            case DeviceType.LightSwitch:
//                productType = "02";//02 继电器类
//                break;
//            case DeviceType.CurtainModel:
//            case DeviceType.CurtainRoller:
//            case DeviceType.CurtainTrietex:
//                productType = "03";//03    遮阳类(窗帘)
//                break;
//            case DeviceType.SensorWindSpeed:
//                productType = "04";//04    传感器)
//                break;
//            case DeviceType.OnePortWirelessFR:
//            case DeviceType.OnePortBus:
//            case DeviceType.RCU:
//            case DeviceType.SuperWireless:
//            case DeviceType.OnePortMqttFR:
//                productType = "07";//07    网关类
//                break;
//            case DeviceType.ACPanel:
//            case DeviceType.ACDevice:
//            case DeviceType.ACInfrared:
//            case DeviceType.ACCoolmaster:
//            case DeviceType.CustomAC:
//            case DeviceType.HVAC:
//            case DeviceType.FoolHeat:
//            case DeviceType.FoolHeatPanel:
//                productType = "12";//12 恒温器(空调、地热)
//                break;
        
//            }
 
//            return productType;
//        }
 
          
 
//        /// <summary>
//        /// 获取生成物理模型参数
 
//        /// </summary>
//        /// <param name="deviceType"></param>
//        /// <returns></returns>
//        public string GetPhysicalModelType (DeviceType deviceType)
//        {
//            string productType = "";
//            switch (deviceType) {
//            case DeviceType.LightDimming:
//                productType = "0101";
//                break;
//            }
 
//            return productType;
//        }
        
 
 
 
//        /// <summary>
//        /// 生成功能设备Sid
//        /// </summary>
//        /// <param name="iDeviceType"></param>
//        /// <param name="sOid"></param>
//        /// <param name="iChnId"></param>
//        /// <param name="isUseE548ReturnBigSmallType"></param>
//        /// <param name="BigType"></param>
//        /// <param name="SmallType"></param>
//        /// <returns></returns>
//        public string FormingNewSid (int iDeviceType, string sOid, int iChnId, bool isUseE548ReturnBigSmallType, byte BigType, byte SmallType)
//        {
//            if (sOid == null || sOid == "") return "";
//            try {
//                string sSid = "";
//                if (DimmerDeviceTypeList.HDLDimmerDeviceTypeList.Contains (iDeviceType)) {
//                    if (DimmerDeviceTypeList.DALIDimmerDeviceTypeLists.Contains (iDeviceType)) {
//                        BigType = 1;
//                        SmallType = 7;
//                        sSid += "0203";
//                    } else {
//                        sSid += "0202";
//                    }
//                } else if (RelayDeviceTypeList.HDLRelayDeviceTypeList.Contains (iDeviceType)) {
//                    sSid += "0201";
//                } else if (CurtainDeviceType.HDLCurtainModuleDeviceType.Contains (iDeviceType)) {
 
//                    if (CurtainDeviceType.NormalMotorCurtainDeviceType.Contains (iDeviceType) || (iDeviceType == 9700)) //所有开合帘 //0 2020 05 24创明开合帘
//                    {
//                        sSid += "0303";
//                    } else if (CurtainDeviceType.RollerCurtainDeviceType.Contains (iDeviceType)
//                      || (iDeviceType == 9701))//所有 卷帘控制器 
//                      {
//                        sSid += "0304";
//                    } else {
//                        sSid += "0301";
//                    }
//                } else if (HVACModuleDeviceTypeList.HDLHVACModuleDeviceTypeLists.Contains (iDeviceType)) {
//                    sSid += "0401";
//                } else if (Eightin1DeviceTypeList.HDL8in1DeviceType.Contains (iDeviceType)
//                      || Sevenin1DeviceTypeList.HDL7in1DeviceType.Contains (iDeviceType)
//                      || HaikeSensorDeviceTypeList.HaikeSensorDeviceType.Contains (iDeviceType)
//                      || Twelvein1DeviceTypeList.HDL12in1DeviceType.Contains (iDeviceType)
//                      || Rs232DeviceTypeList.HDLRs232DeviceType.Contains (iDeviceType)) {
//                    if (BigType == 19 && SmallType == 0) {
//                        sSid += "1301";
//                    } else if (BigType == 5 && SmallType == 0) {
//                        sSid += "0519";
//                    } else {
//                        sSid += BigType.Tostring ("X2") + SmallType.Tostring ("X2");
//                    }
//                } else if (FloorheatingDeviceTypeList.HDLFloorHeatingDeviceType.Contains (iDeviceType)) {
//                    sSid += "0402";
//                } else if (DMXDeviceTypeList.HDLDMXDeviceTypeList.Contains (iDeviceType)) {
//                    sSid += "0204";
//                } else if (DimmerDeviceTypeList.DALIDimmerDeviceTypeLists.Contains (iDeviceType)) {
//                    sSid += "0203";
//                } else if (AudioDeviceTypeList.AudioBoxDeviceTypeList.Contains (iDeviceType)) {
//                    sSid += "0901";
//                }
//                string sTmpWithE548 = sSid;
//                sSid = sOid + sSid + iChnId.Tostring ("X4");
//                if (isUseE548ReturnBigSmallType) {
//                    sSid += BigType.Tostring ("X2") + SmallType.Tostring ("X2");
//                } else {
//                    sSid += sTmpWithE548;
//                }
 
//                return sSid;
//            } catch {
//                return "";
//            }
//        }
 
//        private long LastTime = 0;
//        /// <summary>
//        /// DateTime时间格式转换为13位带毫秒的Unix时间戳
//        /// </summary>
//        /// <param name="time"> DateTime时间格式</param>
//        /// <returns>Unix时间戳格式</returns>
//        public long ConvertDateTimeLong ()
//        {
//            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (new System.DateTime (2020, 1, 1));
//            long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10);
//            if (l <= LastTime) l = LastTime + 1;
//            LastTime = l;
//            return l;
//        }
 
//        public bool ConvertIntToByteArray (long m, ref string strTmp)
//        {
//            strTmp = "00000000";
//            byte [] arry = new byte [4];
//            arry [0] = (byte)(m & 0xFF);
//            arry [1] = (byte)((m & 0xFF00) >> 8);
//            arry [2] = (byte)((m & 0xFF0000) >> 16);
//            arry [3] = (byte)((m & 0xFF000000) >> 24);
//            strTmp = arry [0].ToString ("X2") + arry [1].ToString ("X2") + arry [2].ToString ("X2") + arry [3].ToString ("X2");
//            return true;
//        }
 
//    }
 
 
//    [Serializable]
//    public class Sids : BaseCloudFeedback
//    {
//        public string homeId { get; set; }
//        public string gatewayId { get; set; }
//        public List<Sid> devices { get; set; }
//    }
 
//    [Serializable]
//    public class BaseCloudFeedback
//    {
//        public int code { get; set; }
//        public string timestamp { get; set; }
//        public bool isSuccess { get; set; }
//        public string message { get; set; }
//    }
 
 
//    [Serializable]
//    public class Oids : BaseCloudFeedback
//    {
//        public string homeId { get; set; }
//        public string gatewayId { get; set; }
//        public List<Oid> devices { get; set; }
//    }
 
//    [Serializable]
//    public class Oid
//    {
//        public string protocolType { get; set; }
//        public string device_name { get; set; }
//        public string oid { get; set; }
//        public string addresses { get; set; }
//        public string device_model { get; set; }
 
//        public string fw_version { get; set; }
//        public string hw_info { get; set; }
//        public string mac { get; set; }
//        public string deviceType { get; set; }
//    }
 
//    [Serializable]
//    public class Sid
//    {
//        public string sid { get; set; }
//        public string name { get; set; }
//        public string [] uids { get; set; }
//        public string spk { get; set; }
 
//        public string oid { get; set; }  //设备模块地址
//        public string omodel { get; set; }    //型号
//        public List<Function> attributes { get; set; } //属性列表
//    }
 
 
//    [Serializable]
//    public class Function
//    {
//        //public string name { get; set; }
//        public string key { get; set; }
//        public List<string> value { get; set; }
//        public int max { get; set; }
//        public int min { get; set; }
//        public string data_type { get; set; }
//    }
 
//}
 
 
////sid组成部分:
////sid
////来源    厂商代码    通讯方式    产品时间戳    产品类别    物模型类    通道号    大小类别
////1byte    1byte    1byte    4byte    1byte    2byte    2byte    2byte
////oid组成部分:
////来源    厂商代码    通讯方式    产品时间戳    产品类别
////1byte    1 byte    1 byte    4 byte    1byte
////其中各部分代码列表:
////来源    1byte    编号    描述
////        00    默认原生态系统数据
////        01    网关或者其他A设备
////        02    调试软件
////        03    APP应用程序
////        04    第三方网关或者平台
 
////厂商代码    1byte    编号    描述
////        01    HDL
////        02    
 
////通讯方式    1byte    编号    描述
////        01    HDL Bus
////        02    Zigbee
////        03    KNX
////        04    Z-Wave
 
////产品时间戳    4bytes    以2020年1月1日算出的时间戳0.1s为单位
 
////产品类别    1byte    编号    描述
////        01    调光器
////        02    继电器
////        03    干接点模块
////        04    传感器
////        05    面板
////        06    RCU
////        07    网关
////        08    红外发射
////        09    Android屏
////        10    场景
////        11    音乐播放器
////        12    232/485转换器
////        21    自动化
////        22    安防防区
////        14    窗帘模块
////        15    HVAC
////        16    地热模块
 
////物模型类型    2bytes    编号    描述
////        01    开关类    01    开关
////                02    插座
////                03    
////        02    照明    01    开关
////                02    调光
////                03    色温(CCT)
////                04    RGB
////        03    遮阳    01    窗帘控制器
////                02    百叶窗
////                03    开合帘
////                04    卷帘
////                05     推窗器
////                06     投影幕
////        04    面板    01    按键面板
////        05    传感器    01    移动探测
////                02    温度传感器
////                03    湿度传感器
////                04    照度传感器
////                05    TVOC
////                06    PM2.5
////                07    CO2
////                08    毫米波传感器
////                09    
////                10    
////                11    烟雾传感器
////                25    干接点
////        07    恒温器    01    空调
////                02    风扇
////                03    毛细空调
////        08    地热    01    地热模块
////        09    背景音乐    01    音乐播放器
////                02    Sonos
////        10    场景    01    场景
////                02    电影场景
////        19    新风    01    新风
 
////13    能源    01    电表
////                02    水表
////                03    燃气
////        16    电器    01    风扇
////                02    TV
////        20    安防    01    安防
////        21    自动化    01    自动化
////大类别    1bytes    (预留)
////小类别    1byte    (预留)