| | |
| | | //移除监听 |
| | | EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); |
| | | HDLLinkConfig.getInstance().setIpAddress(bean.getIPAddress()); |
| | | if (!TextUtils.isEmpty(bean.getOID())) { |
| | | HDLLinkConfig.getInstance().setParentOid(bean.getOID()); |
| | | } |
| | | String ipStr = bean.getIPAddress(); |
| | | if (!TextUtils.isEmpty(ipStr)) { |
| | | sendAuthenticateRequest(ipStr, request, callBack); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通用发送指令 |
| | | * 发送一次 |
| | | * |
| | | * @param topic 发送数据 |
| | | * @param bodyStr 回复的主题 |
| | | * @param broadcast 是否要广播 |
| | | * @param callBack 回调 |
| | | */ |
| | | public void udpSendMsgOneTime(String topic, String bodyStr, boolean broadcast, HDLLinkResponseCallBack callBack) { |
| | | if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { |
| | | if (callBack != null) { |
| | | callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_NULL_ERROR)); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (!HDLLinkConfig.getInstance().checkIfCertified()) { |
| | | if (callBack != null) { |
| | | callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | LinkRequest message = new LinkRequest(topic, bodyStr); |
| | | String ip = HDLLinkConfig.getInstance().getIpAddress(); |
| | | if (broadcast) { |
| | | ip = IpUtils.getBroadcastAddress(); |
| | | } |
| | | HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message,"", 1, new HdlSocketHelper.HdlSocketListener() { |
| | | @Override |
| | | public void onSucceed(Object msg) { |
| | | if (callBack == null) return; |
| | | callBack.onSuccess((LinkResponse) msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure() { |
| | | if (callBack == null) return; |
| | | callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 通用发送指令 只发一次,不监听回复,不重发 |
| | | * |
| | | * @param topic 发送数据 |