JLChen
2020-06-24 2e80ba72598546c8f80ab50d2395e70e0d9e66a0
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
package com.hdl.sdk.hdl_sdk.activity;
 
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
 
import com.hdl.sdk.hdl_core.Config.Configuration;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Parser.DeviceParser;
import com.hdl.sdk.hdl_sdk.R;
 
import java.util.ArrayList;
 
 
/** SDK目前支持手动添加的大类:小类
 * 灯光类(大类1):调光回路(0)、开关回路(1)、混合调光类(9)、混合开关类(10)
 * 窗帘类(大类2):开合帘电机(0)、卷帘电机(1)、窗帘模块(2)
 * 空调功能(大类7):HVAC 模块(0)、通用空调面板(3)
 * 背景音乐功能(大类9):背景音乐模块 2018新背景音乐模块小类3
 * 传感器(大类5):干结点0 到 功率24
 * 逻辑功能(大类12):逻辑模块(0)
 * 全局场景(大类17):全局场景(0)
 * 地热功能:地热模块(0)
 * 新风(大类19):新风系统(0)
 * 通用开关(大类100):通用开关(0)
 
 * 格式 支持的模块名字 大类ID:小类ID
 *
 * 灯光类 1:0 ,1,9,10
 * 窗帘类 2:0,1,2
 * 传感器 5:0~24
 * 空调类 7:0,3
 * 地热模块 8:0
 * 背景音乐功能 9:0
 * 逻辑功能 12:0
 * 全局场景 17:0
 * 新风模块 19:0
 * 通用开关 100:0
 *
 * 该方法应用于提供项目交付前的提取批量数据生成好数据。
 * 模拟生成设备回路数据,在项目不支持简易编程搜索情况下,可以通过该方法,先快捷生成目标数据 得到 List<DevicesData> 格式的设备列表数据
 *
 * 上层做本地保存或者云端备份,App启动时读取恢复
 * 每次启动时先加载生成好的设备列表数据,然后在 SDK 初始化后,赋值给 HDLDeviceManager.devicesDataList
 */
public class AddDevicesActivity extends Activity {
 
    private int bigType;
    private int littleType;
    private int mSubnetID;
    private int mDeviceID;
    private int mChannelNum;
    private int port = 6000;
    private String parentRemarks;
    private ArrayList<String> parentRemarksList = new ArrayList();
 
    private EditText et_subnetID, et_deviceID, et_bitType, et_littleType, et_remarks, et_remarks_mk, et_mChannelNum,et_scene,et_mPort,et_scene2;
    private Button btn_add,btn_scene,btn_addAll;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_devices);
 
        et_subnetID = findViewById(R.id.et_subnetID);
        et_deviceID = findViewById(R.id.et_deviceID);
        et_bitType = findViewById(R.id.et_bitType);
        et_littleType = findViewById(R.id.et_littleType);
        et_remarks = findViewById(R.id.et_remarks);
//        et_port = findViewById(R.id.et_port);
        et_remarks_mk = findViewById(R.id.et_remarks_mk);
        et_mChannelNum = findViewById(R.id.et_mChannelNum);
        et_mPort = findViewById(R.id.et_mPort);
 
        et_scene = findViewById(R.id.et_scene);
        et_scene2 = findViewById(R.id.et_scene2);
 
        btn_add = findViewById(R.id.btn_add);
        btn_scene = findViewById(R.id.btn_scene);
        btn_addAll= findViewById(R.id.btn_addAll);
 
 
        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addDevicesManuallyWithoutSearchingAll();
 
            }
        });
 
        btn_scene.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addScene();
 
            }
        });
 
        btn_addAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addMultipleDevices();
 
            }
        });
    }
 
 
    private void addDevicesManuallyWithoutSearchingAll() {
//        parentRemarksList.clear();
 
 
        String subnetIDStr = et_subnetID.getText().toString();
        if (TextUtils.isEmpty(subnetIDStr)) {
            showToast("子网号不能为空");
            return;
        }
 
        String deviceIDStr = et_deviceID.getText().toString();
        if (TextUtils.isEmpty(deviceIDStr)) {
            showToast("设备号不能为空");
            return;
        }
 
        String bitTypeStr = et_bitType.getText().toString();
        if (TextUtils.isEmpty(bitTypeStr)) {
            showToast("大类不能为空");
            return;
        }
 
        String littleTypeStr = et_littleType.getText().toString();
        if (TextUtils.isEmpty(littleTypeStr)) {
            showToast("小类不能为空");
            return;
        }
        String mChannelNumStr = et_mChannelNum.getText().toString();
        if (TextUtils.isEmpty(mChannelNumStr)) {
            showToast("回路号不能为空");
            return;
        }
 
        String mPortStr = et_mPort.getText().toString();
        if (TextUtils.isEmpty(mPortStr)) {
            showToast("端口号不能为空");
            return;
        }
 
 
 
 
        String remarksMkString = et_remarks_mk.getText().toString();
        if (TextUtils.isEmpty(remarksMkString)) {
            showToast("模块备注不能为空");
            return;
        }
 
 
        String remarksString = et_remarks.getText().toString();
        if (TextUtils.isEmpty(remarksString)) {
            showToast("备注不能为空");
            return;
        }
 
//        String et_portString = et_port.getText().toString();
//        if (TextUtils.isEmpty(et_portString)) {
//            showToast("端口不能为空");
//            return;
//        }
 
 
        mSubnetID = Integer.parseInt(subnetIDStr);
        mDeviceID = Integer.parseInt(deviceIDStr);
 
        bigType = Integer.parseInt(bitTypeStr);
        littleType = Integer.parseInt(littleTypeStr);
        mChannelNum = Integer.parseInt(mChannelNumStr);
        parentRemarks = remarksMkString;
        port =  Integer.parseInt(mPortStr);
 
 
        /**
         * 添加设备回路
         * 如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
         * @param bigType 回路大类
         * @param littleType 回路小类
         * @param mSubnetID  回路子网ID
         * @param mDeviceID  回路设备ID
         * @param mChannelNum  回路号
         * @param mChannelRemark 回路备注 例如:窗帘、吊灯、厕所灯、电视
         * @param parentRemarks  当前回路模块的备注 例如: 酒店RCU模块
         * @return
         */
        //如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
        DevicesData mDevicesData = DeviceParser.addDevicesListWithoutSearching(port, bigType, littleType, mSubnetID, mDeviceID, mChannelNum, remarksString, parentRemarks,true);
        if (mDevicesData != null) {
            showToast("添加成功");
        } else {
            showToast("添加失败");
        }
 
 
    }
 
    /**
     * 添加场景设备回路 需指定 场景区号 和 场景号
     * 如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
     *
     * @param mSubnetID
     * @param mDeviceID
     * @param mChannelNum 回路号 这里的回路号需要注意,相同子网号和设备号下的场景需要累加不重复,逻辑模块为例:1区有3个表,2区有2个表 总共5个场景,所以(2区表1 回路号为4、2区表2 回路号为5)
     * @param mAreaNum       //场景 区域号
     * @param mAreaSceneNum  //场景 当前区域场景号
     * @param mChannelRemark 读取场景的备注名称 例如: 入住、起床模式、阅读模式
     * @param parentRemarks  当前回路模块的备注 例如: 酒店RCU模块
     * @param bSaveAndCallBack 是否马上保存本地并且推送DevicesInfoEvent 事件
     * @return
     */
    private void AddScenesDevices(int mSubnetID, int mDeviceID, int mChannelNum, int mAreaNum, int mAreaSceneNum, String mChannelRemark, String parentRemarks, boolean bSaveAndCallBack) {
        //添加场景
        DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, mChannelNum, mAreaNum, mAreaSceneNum, mChannelRemark, parentRemarks,true);
    }
 
 
    /**
     * 添加场景回路
     */
    private void addScene(){
 
        String subnetIDStr = et_subnetID.getText().toString();
        if (TextUtils.isEmpty(subnetIDStr)) {
            showToast("子网号不能为空");
            return;
        }
 
        String deviceIDStr = et_deviceID.getText().toString();
        if (TextUtils.isEmpty(deviceIDStr)) {
            showToast("设备号不能为空");
            return;
        }
 
 
        String mPortStr = et_mPort.getText().toString();
        if (TextUtils.isEmpty(mPortStr)) {
            showToast("端口号不能为空");
            return;
        }
 
        String mChannelNumStr = et_mChannelNum.getText().toString();
        if (TextUtils.isEmpty(mChannelNumStr)) {
            showToast("回路号不能为空");
            return;
        }
 
 
//        String bitTypeStr = et_bitType.getText().toString();
//        if (TextUtils.isEmpty(bitTypeStr)) {
//            showToast("大类不能为空");
//            return;
//        }
//
//        String littleTypeStr = et_littleType.getText().toString();
//        if (TextUtils.isEmpty(littleTypeStr)) {
//            showToast("小类不能为空");
//            return;
//        }
//        String mChannelNumStr = et_mChannelNum.getText().toString();
//        if (TextUtils.isEmpty(littleTypeStr)) {
//            showToast("回路号不能为空");
//            return;
//        }
 
 
        String remarksMkString = et_remarks_mk.getText().toString();
        if (TextUtils.isEmpty(remarksMkString)) {
            showToast("模块备注不能为空");
            return;
        }
 
 
        String remarksString = et_remarks.getText().toString();
        if (TextUtils.isEmpty(remarksString)) {
            showToast("备注不能为空");
            return;
        }
 
        String et_AreaNumString = et_scene.getText().toString();
        if (TextUtils.isEmpty(et_AreaNumString)) {
            showToast("场景:区号不能为空");
            return;
        }
 
        String et_scene2String = et_scene2.getText().toString();
        if (TextUtils.isEmpty(et_scene2String)) {
            showToast("场景:场景号不能为空");
            return;
        }
 
 
 
 
        mSubnetID = Integer.parseInt(subnetIDStr);
        mDeviceID = Integer.parseInt(deviceIDStr);
        port =  Integer.parseInt(mPortStr);
//        bigType = Integer.parseInt(bitTypeStr);
//        littleType = Integer.parseInt(littleTypeStr);
        mChannelNum = Integer.parseInt(mChannelNumStr);
        parentRemarks = remarksMkString;
        int areaID = Integer.parseInt(et_AreaNumString);
        int sceneID = Integer.parseInt(et_scene2String);
 
        DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, mChannelNum, areaID, sceneID, remarksString, parentRemarks,true);
        if (mScenesData != null) {
            showToast("添加成功");
        } else {
            showToast("添加失败");
        }
 
    }
 
    /**
     * 批量添加
     * 仅做演示用
     */
    private void addMultipleDevices(){
 
        String subnetIDStr = et_subnetID.getText().toString();
        if (TextUtils.isEmpty(subnetIDStr)) {
            showToast("子网号不能为空");
            return;
        }
 
        String deviceIDStr = et_deviceID.getText().toString();
        if (TextUtils.isEmpty(deviceIDStr)) {
            showToast("设备号不能为空");
            return;
        }
 
 
 
        String remarksMkString = et_remarks_mk.getText().toString();
        if (TextUtils.isEmpty(remarksMkString)) {
            showToast("模块备注不能为空");
            return;
        }
 
 
 
 
        mSubnetID = Integer.parseInt(subnetIDStr);
        mDeviceID = Integer.parseInt(deviceIDStr);
        parentRemarks = remarksMkString;
 
//        //添加一个灯
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 1, "吧台灯", parentRemarks,false);
//        //添加一个灯
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 2, "休闲灯", parentRemarks,false);
//        //添加一个灯
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 3, "电视灯", parentRemarks,false);
//        //添加一个灯
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 6, "廊灯", parentRemarks,false);
//
//        //添加一个窗帘
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, mSubnetID, mDeviceID, 1, "窗帘", parentRemarks,false);
//        //添加一个窗帘
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, mSubnetID, mDeviceID, 2, "纱窗", parentRemarks,false);
//
//        //添加一个空调
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.AIR_BIG_TYPE, 0, mSubnetID, mDeviceID, 1, "房间空调", parentRemarks,false);
//
////        //添加通用开关 清理
////        DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 15, "清理", parentRemarks,false);
////        //添加通用开关 入住
////        DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 16, "入住", parentRemarks,false);
////        //添加通用开关 稍后
////        DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 13, "稍后", parentRemarks,false);
////        //添加通用开关 勿扰
////        DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 14, "勿扰", parentRemarks,false);
////        //添加一个安防模块
////        DeviceParser.addDevicesListWithoutSearching(port, Configuration.SECURITY_BIG_TYPE, 0, 12, 1, 1, "安防模块", "安防模块",false);
//
//        //添加一个场景 这里场景号和区号 默认一样
//        DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 2, 2, "空置无卡", parentRemarks,false);
//        //添加一个场景
//        DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 3, 3, "插卡场景", parentRemarks,false);
//        //添加一个场景
//        DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 4, 4, "房灯", parentRemarks,false);
//        //添加一个场景 最后一个bSaveAndCallBack 设置为true
//        DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 5, 5, "会客模式", parentRemarks,true);
 
 
//        //添加一个4路继电器
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 1, "吧台灯", "4路继电器",false);
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 2, "休闲灯", "4路继电器",false);
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 3, "电视灯", "4路继电器",false);
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 4, "廊灯", "4路继电器",false);
//
//        //添加一个干节点传感器
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.SENSOR_BIG_TYPE, 0, 111, 99, 1, "干节点", "干节点",false);
//
//
//        //添加一个2路窗帘
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, 111, 8, 1, "窗帘", "2路窗帘",false);
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, 111, 8, 2, "纱窗", "2路窗帘",false);
//        //添加一个开合帘
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 1, 111, 92, 1, "开合帘", "开合帘",false);
//
//        //添加一个空调
//        DeviceParser.addDevicesListWithoutSearching(port, Configuration.AIR_BIG_TYPE, 0, 111, 9, 1, "房间空调", "HVAC空调模块",false);
 
        /**
         * 场景这里的回路号需要注意: 相同子网号和设备号下的场景需要累加不重复,逻辑模块为例:1区有3个表,2区有2个表 总共5个场景,所以(2区表1 回路号为4、2区表2 回路号为5)
         * 不然如果回路号不对简易编程搜索备注的话会出错
         */
        //添加一个场景
        DeviceParser.addLogicScenesDevicesListWithoutSearching(port, 1, 16, 4, 2, 1, "卧室开灯", "逻辑模块",false);
 
        //添加一个场景 最后一个bSaveAndCallBack 设置为true
        DeviceParser.addLogicScenesDevicesListWithoutSearching(port, 1, 16, 5,2, 2, "卧室关灯", "逻辑模块",true);
 
 
 
    }
 
 
 
 
    private void showToast(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }
 
 
}