panlili2024
2024-11-12 69afac92a320033297d71e901e3c5b65e690f0b2
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
//package com.hdl.sdk.ttl_sdk.activity;
//
//import android.support.v7.app.AppCompatActivity;
//import android.os.Bundle;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.Button;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.hdl.sdk.ttl.Config.MCUConstants;
//import com.hdl.sdk.ttl.HDLDeviceManger.Core.Crc;
//import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand;
//import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode;
//import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent;
//import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLStringUtils;
//import com.hdl.sdk.ttl_sdk.R;
//import com.hdl.sdk.ttl_sdk.base.BaseActivity;
//import com.hdl.sdk.ttl_sdk.utlis.HDLLog;
//
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.util.Timer;
//import java.util.TimerTask;
//
//public class ZigbeeActivity extends BaseActivity {
//    /**
//     * Topbar
//     */
//    private RelativeLayout topBarBack;
//    private TextView topBarTitle;
//    private Button btn_PassThrough, btn_PassThrough_close;
//    private TextView  tv_other_mes;
//    private Button btn_close;
//    private Button btn_open_switch2;
//
//
//    /**
//     * 复写isRegisterEventBus()  要注册使用EventBus,这里要设置返回true
//     *
//     * @return true
//     */
//    @Override
//    protected boolean isRegisterEventBus() {
//        return true;
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_zigbee);
//        initToolbar();
//        initView();
//        initOnClick();
//        getJson();
//    }
//
//
//
//    /**
//     * 初始化Toolbar
//     */
//    private void initToolbar() {
//        topBarBack = findViewById(R.id.ll_top_b_left);
//        setViewVisible(topBarBack);
//        topBarTitle = findViewById(R.id.tv_top_b_header_title);
//        topBarBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                finish();
//            }
//        });
//        topBarTitle.setText("Zigbee调试");
//    }
//
//    /**
//     * initView
//     */
//    private void initView() {
//        btn_PassThrough = findViewById(R.id.btn_PassThrough);
//        btn_PassThrough_close = findViewById(R.id.btn_PassThrough_close);
//        tv_other_mes = findViewById(R.id.tv_other_mes);
//
//        btn_close = findViewById(R.id.btn_close);
//        btn_open_switch2 = findViewById(R.id.btn_close);
//    }
//
//    /**
//     * initOnClick
//     */
//    private void initOnClick() {
//        btn_PassThrough.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                startSendHeartPacketTimer();
//
//            }
//        });
//
//        btn_PassThrough_close.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                setHDLPassThroughOpen(false);
//                tv_other_mes.setText("关闭透传");
//
//            }
//        });
//
//        btn_close.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                cancelTimer();
//            }
//        });
//
//    }
//
//    /**
//     * 2019-8-9
//     * 发送透传参数
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     * mcuSendTransparentData接口调用一次以后,默认所有接收数据走透传
//     * 可以调用setHDLPassThroughOpen关闭透传数据
//     */
//    private void mcuSendTransparentData() {
//        startSendHeartPacketTimer();
//    }
//
//    /**
//     * 设置是否开启透传数据
//     * 要想直接接收透传数据,直接调用这个接口打开就可以,不走bus协议处理
//     * 不想透传的话,要记得设置回关闭状态
//     */
//    private void setHDLPassThroughOpen(Boolean bOpen){
//
//        HDLCommand.setHDLPassThroughOpen(bOpen);
//
//    }
//
//
//    private int DeviceType = 0x6666;
//    private int Command1002 =  0x1002;
//    private int CommandHeartbeat =  0x2000;
//    private int DeviceID =   0x01;
//    private int sendCount = 0;//发送序列号
//    /**
//     * @return
//     */
//    private byte[] GetHeartbeatBytes() {
//        sendCount++;
//        if(sendCount > 254){
//            sendCount = 0;
//        }
//        byte[] crcBytes = new byte[13];
//        byte[] sendBytes = new byte[2 + crcBytes.length];
//        //Boot code
//        sendBytes[0] = (byte) 0xAA;
//        sendBytes[1] = (byte) 0xAA;
//        crcBytes[0] = (byte) (crcBytes.length / 256);
//        crcBytes[1] = (byte) (crcBytes.length % 256);
//        crcBytes[2] = (byte) 0x01;
//        crcBytes[3] = (byte) 0x01;
//        crcBytes[4] = (byte) (DeviceType / 256);
//        crcBytes[5] = (byte) (DeviceType % 256);
//        crcBytes[6] = (byte) (CommandHeartbeat / 256);
//        crcBytes[7] = (byte) (CommandHeartbeat % 256);
//        crcBytes[8] = (byte) 0x02;
//        crcBytes[9] = (byte) 0x02;
//        crcBytes[10] = (byte) sendCount;
//
//        Crc.ConCRC(crcBytes, crcBytes.length - 2);
//        System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length);
//        return sendBytes;
//    }
//
//    /**
//     * @return
//     */
//    private byte[] GetSendBytes(byte[] addBytes, int mCommand) {
//        sendCount++;
//        if(sendCount > 254){
//            sendCount = 0;
//        }
//
//        byte[] crcBytes = new byte[15 + addBytes.length];
//        byte[] sendBytes = new byte[2 + crcBytes.length];
//        //Boot code
//        sendBytes[0] = (byte) 0xAA;
//        sendBytes[1] = (byte) 0xAA;
//        crcBytes[0] = (byte) (crcBytes.length / 256);
//        crcBytes[1] = (byte) (crcBytes.length % 256);
//        crcBytes[2] = (byte) 0x01;
//        crcBytes[3] = (byte) 0x01;
//        crcBytes[4] = (byte) (DeviceType / 256);
//        crcBytes[5] = (byte) (DeviceType % 256);
//        crcBytes[6] = (byte) (mCommand / 256);
//        crcBytes[7] = (byte) (mCommand % 256);
//        crcBytes[8] = (byte) 0x02;
//        crcBytes[9] = (byte) 0x02;
//        crcBytes[10] = (byte) sendCount;
//        crcBytes[11] = (byte) (addBytes.length / 256);
//        crcBytes[12] = (byte) (addBytes.length % 256);
//        System.arraycopy(addBytes, 0, crcBytes, 13, addBytes.length);
//        Crc.ConCRC(crcBytes, crcBytes.length - 2);
//        System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length);
//        return sendBytes;
//    }
//
//
//
//    //    private int HeartData = 0x2000;
////    private byte[]  HeartDataBytes = {(byte) (HeartData / 256),(byte) (HeartData %  256) };
//    private String sendDataStr = "";
//
//
//    private boolean bFrist = true;
//    private void SendHeartPacket(){
////        if(sendCount > 4){
////            cancelTimer();
////            return;
////        }
//
//        byte[] sendBytes = GetHeartbeatBytes();
//        HDLCommand.mcuSendTransparentData(sendBytes);
//        if(bFrist){
//            bFrist = false;
//            bBeginSendData = true;
//        }
//    }
//
//    private void SendGetDeviceList(){
//        byte[] bytes = sendDataStr.getBytes();
//        byte[] sendBytes = GetSendBytes(bytes, Command1002 );
//        HDLCommand.mcuSendTransparentData(sendBytes);
//
//    }
//
//
//    private boolean bGetData = false;
//    private boolean bBeginSendData = false;
//    // 定时器
//    private Timer mTimer = new Timer();
//    // 定时任务
//    private MyTimerTask mTask;
//
//    class MyTimerTask extends TimerTask{
//        @Override
//        public void run() {
//            // TODO Auto-generated method stub
//            // 要做的事情
//            if(!bGetData) {
//                if(bBeginSendData){
//                    SendGetDeviceList();
//                    bBeginSendData = false;
//
//                }else {
//
//                    SendHeartPacket();
//                }
//            }
//        }
//
//    }
//
//    private void startSendHeartPacketTimer(){
//
//        if(mTimer == null){
//            mTimer = new Timer();
//        }
//        if(mTask != null){
//            mTask.cancel();
//
//        }
//        mTask = new MyTimerTask();
//        mTimer.schedule(mTask, 200, 500);
//    }
//
//    private void cancelTimer() {
//        if (mTimer != null) {
//            mTask.cancel();
//            mTimer.cancel();
//            mTimer = null;
//
//        }
//    }
//
//    /**
//     * ***********************************************************处理MCU回复数据***********************************************************
//     */
//    /**
//     * MCU控制回调Event
//     *
//     * @param event
//     */
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onMCUFeedBackEventMain(MCUFeedBackEvent event) {
//        if (event.getEventCode() == EventCode.FAILURE_TIMEOUT) {
//            if (TextUtils.isEmpty(event.getError())) {
//                showToast("MCU请求超时,请稍后再试");
//            } else {
//                showToast(event.getError());
//            }
//            return;
//        }
//
//        switch (event.getMCUDataBean().command) {
//            case MCUConstants.MCU_COMMAND_SEND_BACK:    //
//                //透传返回的数据
//                handleMCUPassThroughDataBack(event);
//                break;
//            default:
//                break;
//        }
//    }
//
//
//    /**
//     * 处理MCU透传回调数据
//     * 透传数据,不走bus协议,直接转发,不做数据格式处理
//     *
//     * @param event
//     */
//    private void handleMCUPassThroughDataBack(MCUFeedBackEvent event) {
//        if (event.getEventCode() != EventCode.SUCCESS) {
//            tv_other_mesSetText("MCU透传数据出错,返回数据异常");
//            return;
//        }
//        String receiveString = HDLStringUtils.ByteArrToHex(event.getMCUDataBean().receiveBytes, 0, event.getMCUDataBean().receiveBytes.length);
//
//        tv_other_mes.append("GET: "+receiveString + "\n");
////        tv_other_mes.setText("收到的透传数据:" + receiveString);
//        HDLLog.Log("收到的透传数据:" + receiveString);
//    }
//
//    private void tv_other_mesSetText(String mes) {
//        tv_other_mes.setText(mes);
//        showToast(mes);
//    }
//
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        cancelTimer();
//    }
//
////    private class ZIGBEECommand{
////        private int Cluster_ID = 0;
////        private int Command = 93;
////        private ZIGBEECommand(int Cluster_ID, int Command){
////            this.Cluster_ID = Cluster_ID;
////            this.Command = Command;
////        }
////    }
//
//    private void getJson(){
//        try {
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("Cluster_ID", 0);
//            jsonObject.put("Command", 93);
//            HDLLog.Log("getJson:" + jsonObject.toString());
//            sendDataStr =  jsonObject.toString();
//
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//    }
//
//
////    /**
////     * 处理HDL Data
////     *
////     * @param receiveBytes
////     */
////    private void HandleMCUdata(byte[] receiveBytes) {
////        if (receiveBytes.length < 5) {
////            return;
////        }
////
////    }
//}