| | |
| | | @Override |
| | | public void onSucceed(Object msg) { |
| | | if (callBack == null) return; |
| | | try { |
| | | AuthenticateResponse bean = getAuthenticateResponseBean(msg); |
| | | if (bean != null) { |
| | | String localSecret = bean.getAuth().getLocalSecret(); |
| | | String gatewayId = bean.getObjects().getGatewayID(); |
| | | String ipAddress = bean.getObjects().getIPAddress(); |
| | | String localSecret = ""; |
| | | String gatewayId = ""; |
| | | String ipAddress = ""; |
| | | if(bean.getAuth() != null) { |
| | | localSecret = bean.getAuth().getLocalSecret(); |
| | | } |
| | | if(bean.getObjects() != null){ |
| | | gatewayId = bean.getObjects().getGatewayID(); |
| | | ipAddress = bean.getObjects().getIPAddress(); |
| | | } |
| | | //判断网关是否已经注册到云端 |
| | | if (TextUtils.isEmpty(localSecret) || TextUtils.isEmpty(gatewayId)) { |
| | | //认证失败,网关未注册到云端 |
| | |
| | | callBack.onSuccess("认证成功"); |
| | | } |
| | | } else { |
| | | callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR)); |
| | | } |
| | | } catch (Exception e) { |
| | | callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR)); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设备控制 |
| | | */ |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 通用发送指令 只发一次,不监听回复,不重发 |
| | | * |
| | | * @param topic 发送数据 |
| | | * @param bodyStr 回复的主题 |
| | | */ |
| | | public void udpSendMsg(String topic, String bodyStr) { |
| | | if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { |
| | | LogUtils.e("udpSendMsg", "参数不能为空"); |
| | | return; |
| | | } |
| | | LinkRequest message = new LinkRequest(topic, bodyStr); |
| | | String ip = IpUtils.getBroadcastAddress(); |
| | | getUdpBoot(ip).sendMsg(message.getSendBytes()); |
| | | } |
| | | |
| | | private GatewaySearchBean getGatewaySearchBean(Object msg) { |
| | | GatewaySearchBean searchBean = null; |
| | |
| | | * 网关搜索相关 |
| | | */ |
| | | private static final int MAX_SEARCH_COUNT = 10;//总共搜索测试 |
| | | private final AtomicInteger searchGatewayCount = new AtomicInteger(0);; |
| | | private final AtomicInteger searchGatewayCount = new AtomicInteger(0); |
| | | ; |
| | | private final AtomicBoolean isSearchGatewaySuccess = new AtomicBoolean(true); |
| | | private String searchGatewayId = ""; |
| | | private SearchGatewayCallBack mSearchGatewayCallBack; |
| | | |
| | | private void initSearchGatewayEvent(){ |
| | | LogUtils.i("搜索网关--","initSearchGatewayEvent"); |
| | | searchGatewayEvent = new EventListener() { |
| | |
| | | LogUtils.i("搜索网关--","注册搜索网关监听"); |
| | | EventDispatcher.getInstance().registerIo(TopicConstant.GATEWAY_SEARCH_REPLY, searchGatewayEvent); |
| | | } |
| | | |
| | | /** |
| | | * 移除搜索网关监听 |
| | | */ |