From e91af284643d5e370b0d18c384fe8de65f59d9b3 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 24 九月 2020 12:01:10 +0800
Subject: [PATCH] 2020-09-24 1.修改MQTTSDK引用方式,修复闪退问题。

---
 Android_HDL_SDK_XW/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/SearchZigbeeGateway.java |  191 ++++++++++++++++++++++++-----------------------
 1 files changed, 96 insertions(+), 95 deletions(-)

diff --git a/Android_HDL_SDK_XW/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/SearchZigbeeGateway.java b/Android_HDL_SDK_XW/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/SearchZigbeeGateway.java
index c7c367d..11018a1 100644
--- a/Android_HDL_SDK_XW/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/SearchZigbeeGateway.java
+++ b/Android_HDL_SDK_XW/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/SearchZigbeeGateway.java
@@ -12,7 +12,6 @@
 import java.util.TimerTask;
 
 
-
 import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ZigbeeBean.ZigbeeGatewayInfoBean;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.Callback.PushCallback;
 import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
@@ -30,13 +29,15 @@
     public static Timer searchTimer = null;
     private static DatagramSocket datagramSocket; // 鏁版嵁鎶ュ鎺ュ瓧
     private static boolean isStop = false;
-    public interface OnSearchListener{
-         void onSuccess( List<ZigbeeGatewayInfoBean> zigbeeGatewayInfoBeanList);
-         void onEorror(Exception e);
+
+    public interface OnSearchListener {
+        void onSuccess(List<ZigbeeGatewayInfoBean> zigbeeGatewayInfoBeanList);
+
+        void onEorror(Exception e);
     }
 
     public static void release() {
-        if (datagramSocket != null){
+        if (datagramSocket != null) {
             isStop = true;
             datagramSocket.disconnect();
             datagramSocket = null;
@@ -58,99 +59,99 @@
             public void run() {
                 if (zigbeeGatewayInfoBean.getCount() < 20) {
                     zigbeeGatewayInfoBean.setCount(zigbeeGatewayInfoBean.getCount() + 1);
-                            try {
-                                    byte[] sendBytes = new byte[44];
-                                    sendBytes[0] = (byte) 0xFE;
-                                    sendBytes[1] = 0x29;
-                                    sendBytes[2] = 0;
-                                    sendBytes[3] = 0;
-                                    sendBytes[4] = 0;
-                                    sendBytes[5] = 0;
-                                    sendBytes[6] = 0;
-                                    //鑾峰彇鎵�鏈夌綉鍏筹紙鏃犻渶houseID妯″紡锛夛紝鍚庨潰瑕佹敼
-                                    sendBytes[7] = 0x67;
-                                    sendBytes[8] = 0x65;
-                                    sendBytes[9] = 0x74;
-                                    sendBytes[10] = 0x61;
-                                    sendBytes[11] = 0x6c;
-                                    sendBytes[12] = 0x6c;
-                                    sendBytes[13] = 0x67;
-                                    sendBytes[14] = 0x77;
-                                    for (int i = 15; i<sendBytes.length-1;i++){
-                                        sendBytes[i] = 0;
-                                    }
-                                    sendBytes[sendBytes.length - 1] = 0x02;
-                                    //Log.d(TAG, "sendBytes: "+StringUtil.ByteArrToHex(sendBytes,0,sendBytes.length));
-                                    InetAddress address = InetAddress.getByName(NetWorkUtil.getLocalBroadCast());
-                                    DatagramPacket packet = new DatagramPacket(
-                                            sendBytes,
-                                            sendBytes.length,
-                                            address, 7624);
-                                    datagramSocket= new DatagramSocket();
-                                    datagramSocket.send(packet);
+                    try {
+                        byte[] sendBytes = new byte[44];
+                        sendBytes[0] = (byte) 0xFE;
+                        sendBytes[1] = 0x29;
+                        sendBytes[2] = 0;
+                        sendBytes[3] = 0;
+                        sendBytes[4] = 0;
+                        sendBytes[5] = 0;
+                        sendBytes[6] = 0;
+                        //鑾峰彇鎵�鏈夌綉鍏筹紙鏃犻渶houseID妯″紡锛夛紝鍚庨潰瑕佹敼
+                        sendBytes[7] = 0x67;
+                        sendBytes[8] = 0x65;
+                        sendBytes[9] = 0x74;
+                        sendBytes[10] = 0x61;
+                        sendBytes[11] = 0x6c;
+                        sendBytes[12] = 0x6c;
+                        sendBytes[13] = 0x67;
+                        sendBytes[14] = 0x77;
+                        for (int i = 15; i < sendBytes.length - 1; i++) {
+                            sendBytes[i] = 0;
+                        }
+                        sendBytes[sendBytes.length - 1] = 0x02;
+                        //Log.d(TAG, "sendBytes: "+StringUtil.ByteArrToHex(sendBytes,0,sendBytes.length));
+                        InetAddress address = InetAddress.getByName(NetWorkUtil.getLocalBroadCast());
+                        DatagramPacket packet = new DatagramPacket(
+                                sendBytes,
+                                sendBytes.length,
+                                address, 7624);
+                        datagramSocket = new DatagramSocket();
+                        datagramSocket.send(packet);
 
-                                    byte[] receiveBytes = new byte[1024];
-                                    DatagramPacket dataPacket = new DatagramPacket(receiveBytes, receiveBytes.length);
-                                    datagramSocket.receive(dataPacket);
-                                    //鏄惁涓荤綉鍏�-01涓轰富缃戝叧-00涓轰粠缃戝叧
-                                    String IsDomain = StringUtil.Byte2Hex(dataPacket.getData()[44]);
-                                    int headLength = 1 + 2 + 4 + 36 + 1 + 1 + 4 ;
-                                    if (receiveBytes.length > headLength) {
-                                        //缃戝叧鍚嶇О闀垮害
-                                        String str = StringUtil.Byte2Hex(dataPacket.getData()[49]);
-                                        int GwNameLength = Integer.parseInt(str,16);
+                        byte[] receiveBytes = new byte[1024];
+                        DatagramPacket dataPacket = new DatagramPacket(receiveBytes, receiveBytes.length);
+                        datagramSocket.receive(dataPacket);
+                        //鏄惁涓荤綉鍏�-01涓轰富缃戝叧-00涓轰粠缃戝叧
+                        String IsDomain = StringUtil.Byte2Hex(dataPacket.getData()[44]);
+                        int headLength = 1 + 2 + 4 + 36 + 1 + 1 + 4;
+                        if (receiveBytes.length > headLength) {
+                            //缃戝叧鍚嶇О闀垮害
+                            String str = StringUtil.Byte2Hex(dataPacket.getData()[49]);
+                            int GwNameLength = Integer.parseInt(str, 16);
 
-                                        //缃戝叧鍚嶇О
-                                        byte[] gwnamebyte = new byte[GwNameLength];
-                                        for (int i = 0 ;i< GwNameLength ; i++){
-                                            gwnamebyte[i] = dataPacket.getData()[i+50];
-                                        }
-                                        String GwName =new String(gwnamebyte,0,gwnamebyte.length);
-
-                                        //缃戝叧id闀垮害
-                                        String str1 = StringUtil.Byte2Hex(dataPacket.getData()[50+GwNameLength]);
-                                        int GwIdLength = Integer.parseInt(str1,16);
-
-                                        //鑾峰彇缃戝叧id
-                                        byte[] gatewayId = new byte[GwIdLength];
-                                        for (int i = 0 ;i< GwIdLength ; i++){
-                                            gatewayId[i] = dataPacket.getData()[i+51+GwNameLength];
-                                        }
-
-                                        if (gatewayId.length > 1) {
-                                            String stringGateWayId = new String(gatewayId,0,gatewayId.length);
-                                            Log.d(TAG, "缃戝叧id: "+stringGateWayId);
-
-                                            ZigbeeGatewayInfoBean zigbeeGatewayInfoBean = new ZigbeeGatewayInfoBean();
-                                            zigbeeGatewayInfoBean.setGatewayId(stringGateWayId);
-                                            zigbeeGatewayInfoBean.setIpAddress(dataPacket.getAddress().getHostAddress());
-                                            if (IsDomain.equals("01")){
-                                                zigbeeGatewayInfoBean.setDomain(true);
-                                            }else {
-                                                zigbeeGatewayInfoBean.setDomain(false);
-                                            }
-                                            zigbeeGatewayInfoBean.setGatewayName(GwName);
-                                            boolean isExit = false;
-                                            for (int i = 0; i < zigbeeGatewayInfoBeanList.size(); i++) {
-                                                if (zigbeeGatewayInfoBeanList.get(i).getGatewayId()
-                                                        .equals(zigbeeGatewayInfoBean.getGatewayId())) {
-                                                        isExit = true;
-                                                        break;
-                                                }
-                                            }
-                                            if (!isExit) {
-                                                zigbeeGatewayInfoBeanList.add(zigbeeGatewayInfoBean);
-                                                Log.d(TAG, "addList:鎴愬姛娣诲姞 ");
-                                            }
-                                        }
-                                    }
-                                datagramSocket.close();
-                            } catch (Exception e) {
-                                Log.d(TAG, "run: "+e.toString());
-                                e.printStackTrace();
-                                datagramSocket.close();
-                                onSearchListener.onEorror(e);
+                            //缃戝叧鍚嶇О
+                            byte[] gwnamebyte = new byte[GwNameLength];
+                            for (int i = 0; i < GwNameLength; i++) {
+                                gwnamebyte[i] = dataPacket.getData()[i + 50];
                             }
+                            String GwName = new String(gwnamebyte, 0, gwnamebyte.length);
+
+                            //缃戝叧id闀垮害
+                            String str1 = StringUtil.Byte2Hex(dataPacket.getData()[50 + GwNameLength]);
+                            int GwIdLength = Integer.parseInt(str1, 16);
+
+                            //鑾峰彇缃戝叧id
+                            byte[] gatewayId = new byte[GwIdLength];
+                            for (int i = 0; i < GwIdLength; i++) {
+                                gatewayId[i] = dataPacket.getData()[i + 51 + GwNameLength];
+                            }
+
+                            if (gatewayId.length > 1) {
+                                String stringGateWayId = new String(gatewayId, 0, gatewayId.length);
+                                Log.d(TAG, "缃戝叧id: " + stringGateWayId);
+
+                                ZigbeeGatewayInfoBean zigbeeGatewayInfoBean = new ZigbeeGatewayInfoBean();
+                                zigbeeGatewayInfoBean.setGatewayId(stringGateWayId);
+                                zigbeeGatewayInfoBean.setIpAddress(dataPacket.getAddress().getHostAddress());
+                                if (IsDomain.equals("01")) {
+                                    zigbeeGatewayInfoBean.setDomain(true);
+                                } else {
+                                    zigbeeGatewayInfoBean.setDomain(false);
+                                }
+                                zigbeeGatewayInfoBean.setGatewayName(GwName);
+                                boolean isExit = false;
+                                for (int i = 0; i < zigbeeGatewayInfoBeanList.size(); i++) {
+                                    if (zigbeeGatewayInfoBeanList.get(i).getGatewayId()
+                                            .equals(zigbeeGatewayInfoBean.getGatewayId())) {
+                                        isExit = true;
+                                        break;
+                                    }
+                                }
+                                if (!isExit) {
+                                    zigbeeGatewayInfoBeanList.add(zigbeeGatewayInfoBean);
+                                    Log.d(TAG, "addList:鎴愬姛娣诲姞 ");
+                                }
+                            }
+                        }
+                        datagramSocket.close();
+                    } catch (Exception e) {
+                        Log.d(TAG, "run: " + e.toString());
+                        e.printStackTrace();
+                        datagramSocket.close();
+                        onSearchListener.onEorror(e);
+                    }
                 } else {
                     if (searchTimer != null) {
                         //鎵ц瀹屾悳绱㈠悗鍒拌繖

--
Gitblit v1.8.0