package com.hdl.sdk.link; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.sdk.link.common.config.TopicConstant; import com.hdl.sdk.link.common.exception.HDLLinkCode; import com.hdl.sdk.link.common.exception.HDLLinkException; import com.hdl.sdk.link.common.utils.IdUtils; import com.hdl.sdk.link.common.utils.LogUtils; import com.hdl.sdk.link.common.utils.TextUtils; import com.hdl.sdk.link.common.utils.gson.GsonConvert; import com.hdl.sdk.link.bean.LinkCreateLogicBean; import com.hdl.sdk.link.bean.LinkCreateSceneBean; import com.hdl.sdk.link.bean.LinkEnableLogicBean; import com.hdl.sdk.link.bean.LinkEnableSecurityBean; import com.hdl.sdk.link.bean.LinkFunctionBean; import com.hdl.sdk.link.bean.LinkLogicBean; import com.hdl.sdk.link.bean.LinkOidBean; import com.hdl.sdk.link.bean.LinkReNameGWBean; import com.hdl.sdk.link.bean.LinkResponseBean; import com.hdl.sdk.link.bean.LinkRoomBean; import com.hdl.sdk.link.bean.LinkRoomBindBean; import com.hdl.sdk.link.bean.LinkSceneBean; import com.hdl.sdk.link.bean.LinkSidStrBean; import com.hdl.sdk.link.bean.LinkSidUidBean; import com.hdl.sdk.link.core.bean.FileRequest; import com.hdl.sdk.link.core.bean.LinkRequest; import com.hdl.sdk.link.core.bean.LinkResponse; import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; import com.hdl.sdk.link.core.bean.request.DeviceControlRequest; import com.hdl.sdk.link.core.bean.request.FunctionAttributeRequest; import com.hdl.sdk.link.core.bean.request.PropertyReadRequest; import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.callback.HDLLinkCallBack; import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; import com.hdl.sdk.link.common.event.EventDispatcher; import com.hdl.sdk.link.common.event.EventListener; import com.hdl.sdk.link.core.callback.HDLLinkTCallBack; import com.hdl.sdk.link.core.config.HDLLinkConfig; import com.hdl.sdk.link.core.connect.HDLUdpConnect; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.connect.HDLConnectHelper; import com.hdl.sdk.link.core.utils.LinkResponseUtils; import com.hdl.sdk.link.core.utils.QueueUtils; import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Locale; /** * Created by jlchen on 11/15/21. * * @Description : HDLLink */ public class HDLLinkLocalSdk { private String language="zh"; /** * instance */ private volatile static HDLLinkLocalSdk instance; /** * getInstance * * @return HDLLink */ public static synchronized HDLLinkLocalSdk getInstance() { if (instance == null) { synchronized (HDLLinkLocalSdk.class) { if (instance == null) { instance = new HDLLinkLocalSdk(); } } } return instance; } /** * 本地SDK初始化,初始化网关Id及本地通讯的密钥 * @param gatewayId 网关Id * @param localSecret 密钥 */ public void init(String gatewayId,String localSecret){ //对HDL应用软件来说,本地通讯密钥和网关Id在使用时要设置 HDLLinkConfig.getInstance().setLocalSecret(localSecret); HDLLinkConfig.getInstance().setGatewayId(gatewayId); QueueUtils.getInstance().start();//初始化接收数据线程 HDLUdpConnect.getInstance().initUdp();//初始化udp监听 searchGatewayBroadcast(null);//搜索网关 } public void setlanguage(String language){ this.language=language; } public String getLanguage(){ return language; } /** * 设置打印是否开启 * @param enable */ public void setLogEnabled(boolean enable){ LogUtils.setEnabled(enable); } /** * 注册所有主题消息的监听 * * @param listener */ public synchronized void registerAllTopicsListener(EventListener listener) { EventDispatcher.getInstance().registerAllTopicsListener(listener); } /** * 取消所有主题消息的监听 * * @param listener */ public synchronized void removeAllTopicsListener(EventListener listener) { if (listener == null) return; EventDispatcher.getInstance().removeAllTopicsListener(listener); } /***********************三方设备和网关通信之前的认证流程****************************/ /** * 检测是否已经认证过 * 认证通过才能进行设备控制 * * @return */ public boolean checkIfCertified() { return HDLLinkConfig.getInstance().checkIfCertified(); } /** * 开始监听和发起入网及认证请求 * * @param request 认证请求信息 * @param callBack 结果回调 */ public void startAuthenticateRequest(AuthenticateRequest request, HDLLinkCallBack callBack) { HDLUdpConnect.getInstance().startAuthenticateRequest(request, callBack); } /** * 发送入网及认证请求 * * @param ip 网关IP * @param request 认证请求信息 * @param callBack 结果回调 */ public void sendAuthenticateRequest(String ip, AuthenticateRequest request, HDLLinkCallBack callBack) { HDLUdpConnect.getInstance().sendAuthenticateRequest(ip, request, callBack); } /***********************三方设备请先认证成功 再调用下面的接口和网关通信****************************/ /** * 组播搜索指定网关是否在线,搜索到则返回指定的网关对象 * * @param callBack 回调 */ public void searchGatewayMulticast(HDLUdpConnect.SearchGatewayCallBack callBack) { HDLUdpConnect.getInstance().searchGatewayMulticast(callBack); } /** * 组播搜索指定网关是否在线,搜索到则返回指定的网关对象 * * @param callBack 回调 */ public void searchGatewayBroadcast(HDLUdpConnect.SearchGatewayCallBack callBack) { HDLUdpConnect.getInstance().searchGatewayBroadcast(callBack); } /** * 获取设备列表 */ public void getDeviceList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.GET_DEVICE_LIST, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getDeviceList onSuccess"); Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 更改网关备注名 */ public void changeGWName(String gateWayName, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); linkReNameGWBean.setDevice_name(gateWayName); data.setObjects(linkReNameGWBean); String topic = String.format(TopicConstant.GATEWAY_RENAME, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { Type type = new TypeToken>() { }.getType(); LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * sid绑定房间 */ public void sidBindUid(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SID_BIND_ROOM, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { Type type = new TypeToken>() { }.getType(); LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); // TODO: 2022/1/13 处理200code callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * sid删除绑定房间关系 */ public void sidDeleteUid(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SID_DELETE_ROOM, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 创建场景 */ public void createScene(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.CREATE_SCENE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 编辑场景 */ public void editScene(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); for(int i=0;i bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SCENE_DELETE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取自动化列表 */ public void getLogicList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.LOGIC_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取自动化详情 */ public void getLogicDetail(List list, HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(list); String topic = String.format(TopicConstant.LOGIC_GET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 新建自动化 */ public void createLogic(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.LOGIC_EDIT, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 开启关闭自动化 */ public void enableLogic(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.LOGIC_ENABLE_EDIT, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 删除自动化 */ public void deleteLogic(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.LOGIC_DELETE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取安防列表 */ public void getSecurityList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.SECURITY_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取自动化详情 */ public void getSecurityDetail(List list, HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(list); String topic = String.format(TopicConstant.SECURITY_GET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 新建安防 */ public void createSecurity(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SECURITY_EDIT, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 删除安防 */ public void deleteSecurity(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SECURITY_DELETE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 开启关闭自动化 */ public void enableSecurity(List bean, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.SECURITY_STATUS_SET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取功能列表 */ public void getFunctionList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.GET_FUNCTION_LIST, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 更改Sid备注名 */ public void editSidName(BaseLocalResponse> data, HDLLinkTCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); // LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); // linkReNameGWBean.setDevice_name(sidName); // data.setObjects(linkReNameGWBean); String topic = String.format(TopicConstant.EDIT_FUNCTION, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { Type type = new TypeToken>() { }.getType(); LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); callBack.onSuccess("Success"); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取功能属性 * 支持批量 * * @param sids * @param callBack */ public void getFunctionAttribute(List sids, HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List list = new ArrayList<>(); for (String s : sids) { list.add(new FunctionAttributeRequest(s)); } data.setObjects(list); String topic = String.format(TopicConstant.GET_FUNCTION_ATTRIBUTE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getFunctionAttribute onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 设备控制 * * @param requestList 控制状态参数 * @param callBack 结果回调 */ public void propertyDown(List requestList, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(requestList); String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 读取状态 * * @param sids 请求参数 指定读取的设备sid列表 * @param callBack 回调 */ public void propertyRead(List sids, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List list = new ArrayList<>(); for (String s : sids) { list.add(new PropertyReadRequest(s)); } data.setObjects(list); String topic = String.format(TopicConstant.PROPERTY_READ, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取场景列表 */ public void getSceneList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.SCENE_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取场景详情 */ public void getSceneDetail(List list, HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(list); String topic = String.format(TopicConstant.SCENE_GET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 场景控制 * * @param sids 场景sid列表 * @param callBack 回调 */ public void controlScene(List sids, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List list = new ArrayList<>(); for (String s : sids) { list.add(new PropertyReadRequest(s)); } data.setObjects(list); String topic = String.format(TopicConstant.SCENE_CONTROL, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 通用UDP发送指令 * 1秒没响应就让他重新发送,重试3次 * * @param topic 发送数据 * @param bodyStr body内容 * @param callBack 回调 */ public void udpSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, false, callBack); } /** * 通用广播UDP发送指令 * 1秒没响应就让他重新发送,重试3次 * * @param topic 发送数据 * @param bodyStr body内容 * @param callBack 回调 */ public void udpBroadcastSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, true, callBack); } /** * 通用TCP发送指令 * 1秒没响应就让他重新发送,重试3次 * * @param topic 发送数据 * @param body body内容 * @param callBack 回调 */ public void tcpSendMsg(String topic, String body, HDLLinkCallBack callBack) { LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } /** * 通用TCP发送指令 只发一次,不监听回复,不重发 * * @param topic 发送数据 * @param body 回复的主题 */ public void tcpSendMsg(String topic, String body) { LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(1, HDLLinkConfig.getInstance().getIpAddress(), request, true); } /** * 创新网关列表,重新读取 * * @param homeId 住宅Id * @param callBack 回调所有读取到的网关列表 */ public void refreshGatewayByHome(String homeId, GatewayCallBack callBack) { HDLLinkLocalGateway.getInstance().refreshGatewayByHome(homeId, callBack); } /** * 创新网关列表,重新读取 * * @param callBack 回调所有读取到的网关列表 */ public void refreshGateway(GatewayCallBack callBack) { HDLLinkLocalGateway.getInstance().refreshGateway(callBack); } /** * 获取当前住宅缓存的所有网关,一般是调试软件使用,三方不用调试此方法 * 如果之前还没有读取过网关,先调用方法refreshGatewayByHome读取一次 * * @return */ public List getGatewayByHome() { return HDLLinkLocalGateway.getInstance().getGatewayList(); } /** * 获取房间列表 * * @param callBack */ public void getRoomList(HDLLinkTCallBack> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); String topic = String.format(TopicConstant.ROOM_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getRoomList onSuccess"); Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 全量更新房间列表 * * @param list * @param callBack */ public void coverAddRoomList(List list, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse> senData = new BaseLocalResponse<>(); senData.setId(IdUtils.getUUId()); senData.setTime_stamp(time); senData.setObjects(list); String topic = String.format(TopicConstant.ROOM_COVER_ADD, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(senData), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sendMsg onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取房间绑定关系 */ public void getRoomBindList(HDLLinkTCallBack> callBack,List uidRoomList) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); JsonArray array = new JsonArray(); for (String uid:uidRoomList){ array.add(uid); } jsonObject.add("objects", array); String topic = String.format(TopicConstant.ROOM_BIND_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); String replyTopic = topic + "_reply"; new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getRoomBindList onSuccess"); Type type = new TypeToken>>() { }.getType(); List list = LinkResponseUtils.convertLinkResponse(msg, type); if (list == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); } else { callBack.onSuccess(list); } } } @Override public void onFailure() { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /*********************** 文件传输 ****************************/ /** * 文件用途通知 * @param fileId 文件Id * @param fileName 文件名称 * @param purpose 用途 用途枚举 * zigbee设备配置恢复: ConfigRecoveryForZigbeeDevices * 数据备份:DataBackup * 数据恢复:DataRecovery * @param callBack */ public void sendFileUserNotification(String fileId,String fileName,String purpose, HDLLinkCallBack callBack){ //帧格式:head+命令字+数据长度+二进制数据 String time = String.valueOf(System.currentTimeMillis()); String data ="hex"+"0001"+ fileId+"\r\n"+fileName+"\r\n"+purpose; byte []dataBytes=data.getBytes(StandardCharsets.UTF_8); FileRequest linkRequest = new FileRequest(fileId,0x0011,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { } @Override public void onFailure() { } }, true).send(); } /** * 发送文件相关命令 */ public void sendFileCommand(byte []dataBytes,Integer command, HDLLinkCallBack callBack){ //帧格式:head+命令字+数据长度+二进制数据 String time = String.valueOf(System.currentTimeMillis()); // byte []dataBytes=data.getBytes(StandardCharsets.UTF_8); FileRequest linkRequest = new FileRequest("65531",command,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { } @Override public void onFailure() { } }, true).send(); } /********************************驱动升级***********************************/ /** * 发送文件相关命令 */ public void sendFileCommand(String ipAddress,byte []dataBytes,String fileId,Integer command, HDLLinkCallBack callBack){ //帧格式:head+命令字+数据长度+二进制数据 FileRequest linkRequest = new FileRequest(fileId,command,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(ipAddress, linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { } @Override public void onFailure() { } }, true).send(); } }