hxb
2022-03-21 0188dee359636723190f0f67a6b674b7b08f7bef
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
@@ -117,7 +117,7 @@
                udpSocketBoot.bind();
            }
        } catch (Exception e) {
            return null;
//            return null;
        }
        return udpSocketBoot;
@@ -141,15 +141,15 @@
            public void onMessage(Object msg) {
                NetworkAccessBroadcastResponse bean = getNetworkAccessBroadcastResponse(msg);
                if (bean != null) {
                    LogUtils.i(TAG, "网关入网广播IP: " + bean.getIPAddress());
                    //移除监听
                    EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST);
                    LogUtils.i("网关入网广播IP: " + bean.getIPAddress());
                    String ipStr = bean.getIPAddress();
                    if (!TextUtils.isEmpty(ipStr)) {
                        sendAuthenticateRequest(ipStr, request, callBack);
                    }
                }
                //移除监听
                EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST);
                LogUtils.i(TAG, "移除监听 authEvent");
            }
        });
    }
@@ -228,6 +228,7 @@
            }
        });
    }
//    /**
//     * 发送入网及认证请求
@@ -407,11 +408,11 @@
     */
    public void udpSendMsg(String topic, String bodyStr,boolean broadcast) {
        if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) {
            LogUtils.e("udpSendMsg", "参数不能为空");
            LogUtils.e( "参数不能为空,不能发送UDP数据");
            return;
        }
        if (!HDLLinkConfig.getInstance().checkIfCertified()) {
            LogUtils.e("udpSendMsg", "未认证,请先认证");
            LogUtils.e("未认证,请先认证再调用UDP发送方法");
            return;
        }
        LinkRequest message = new LinkRequest(topic, bodyStr);
@@ -491,12 +492,12 @@
                            }.getType());
                            GatewaySearchBean searchBean = response.getObjects();
                            if (searchBean != null && !TextUtils.isEmpty(searchBean.getGatewayId())) {
                                if (searchBean.getGatewayId().contains(searchGatewayId)) {
                                searchBean.setIp_address(linkResponse.getSource_ipAddress());
                                if (searchBean.getGatewayId().contains(searchGatewayId)&&!TextUtils.isEmpty(searchGatewayId)) {
                                    removeSearchGatewayEvent();//移除搜索网关监听
                                    isSearchGatewaySuccess.set(true);//搜索成功标记
                                    searchGatewayCount.set(11);//次数标记
                                    HDLLinkConfig.getInstance().setCurrentGateway(searchBean);//设置当前网关
                                    HDLLinkConfig.getInstance().setLocalEncrypt(searchBean.isLocalEncrypt());//设置是否加密
                                    if (mSearchGatewayCallBack != null) {
                                        mSearchGatewayCallBack.onSuccess(searchBean);
                                    }
@@ -526,11 +527,14 @@
                            }.getType());
                            GatewaySearchBean gateway = response.getObjects();
                            if (gateway != null && !TextUtils.isEmpty(gateway.getGatewayId())) {
                                //可能网关带过来的ip不对
                                gateway.setIp_address(linkResponse.getSource_ipAddress());
                                //主网关并且是当前绑定的网关
                                if ("true".equals(gateway.getMaster().toLowerCase()) && gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId())) {
                                    HDLLinkConfig.getInstance().setCurrentGateway(gateway);//设置当前网关
                                    HDLLinkConfig.getInstance().setLocalEncrypt(gateway.isLocalEncrypt());//设置是否加密
                                    HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
                                    if(!TextUtils.isEmpty( gateway.getIp_address())) {
                                        HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
                                    }
                                    //更新当前网关的信息
                                    HDLLinkConfig.getInstance().reSaveConfig();
                                }
@@ -583,9 +587,11 @@
                }
                if (!isSearchGatewaySuccess.get()) {
                    //搜索10次,指定网关都没回复,回调超时
                    callBackSearchGatewayTimeout();
                    LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时");
                    try {
                        LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时");
                        //搜索10次,指定网关都没回复,回调超时
                        callBackSearchGatewayTimeout();
                    }catch (Exception e){}
                }
            }
        }).start();