| | |
| | | /** |
| | | * instance |
| | | */ |
| | | private volatile static HDLAuthSocket instance; |
| | | private static final HDLAuthSocket instance=new HDLAuthSocket(); |
| | | |
| | | private HDLAuthSocket() { |
| | | initListenerGatewayEvent(); |
| | |
| | | * |
| | | * @return HDLAuthSocket |
| | | */ |
| | | public static synchronized HDLAuthSocket getInstance() { |
| | | if (instance == null) { |
| | | synchronized (HDLLinkConfig.class) { |
| | | if (instance == null) { |
| | | instance = new HDLAuthSocket(); |
| | | } |
| | | } |
| | | } |
| | | public static HDLAuthSocket getInstance() { |
| | | // if (instance == null) { |
| | | // synchronized (HDLAuthSocket.class) { |
| | | // if (instance == null) { |
| | | // instance = new HDLAuthSocket(); |
| | | // } |
| | | // } |
| | | // } |
| | | return instance; |
| | | } |
| | | |
| | |
| | | * |
| | | * @return 返回当前对象 |
| | | */ |
| | | private UdpSocketBoot getUdpBoot() { |
| | | private synchronized UdpSocketBoot getUdpBoot() { |
| | | try { |
| | | if (udpSocketBoot == null) { |
| | | udpSocketBoot = UdpClient.init(UDP_PORT, getUdpOptions()); |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | // /** |
| | | // * 发送入网及认证请求 |
| | |
| | | */ |
| | | 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); |
| | |
| | | }.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); |
| | | } |
| | |
| | | }.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(); |
| | | } |
| | |
| | | } |
| | | |
| | | if (!isSearchGatewaySuccess.get()) { |
| | | //搜索10次,指定网关都没回复,回调超时 |
| | | callBackSearchGatewayTimeout(); |
| | | LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时"); |
| | | try { |
| | | LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时"); |
| | | //搜索10次,指定网关都没回复,回调超时 |
| | | callBackSearchGatewayTimeout(); |
| | | }catch (Exception e){} |
| | | } |
| | | } |
| | | }).start(); |