HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java
@@ -2,6 +2,7 @@ import android.content.Context; import android.text.TextUtils; import android.widget.Toast; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -10,9 +11,11 @@ import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.sdk.link.bean.GatewayLocationBean; import com.hdl.sdk.link.bean.LinkGroupControlCreateBean; import com.hdl.sdk.link.bean.LinkIrDeviceBean; import com.hdl.sdk.link.bean.LinkOtaBean; import com.hdl.sdk.link.bean.LinkSidNameBean; import com.hdl.sdk.link.bean.MMWAreaBean; import com.hdl.sdk.link.common.config.TopicConstant; import com.hdl.sdk.link.common.exception.HDLLinkCode; import com.hdl.sdk.link.common.exception.HDLLinkException; @@ -91,7 +94,7 @@ return instance; } private Context context; private static Context context; public void init(Context context) { @@ -118,6 +121,26 @@ return true; else return false; } public static void showToast(String msg){ // runOnUiThread(new Runnable() { // @Override // public void run() { // try { // if (toast == null) { // toast = Toast.makeText(HDLGlobal.getInstance().getContext(), message, Toast.LENGTH_SHORT); // } else { // toast.setText(message); // } // toast.show(); // } catch (Exception ignored) { // // } // } // // }); Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } /** @@ -233,6 +256,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -277,6 +301,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -321,6 +346,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -365,6 +391,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -407,6 +434,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -417,6 +445,39 @@ callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } public void controlDevice(Object object, String gatewayId, String ipAddress, String mac, boolean encrypt, HDLLinkTCallBack<String> callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); JSONObject jsonObject = new JSONObject(); jsonObject.put("id", IdUtils.getUUId()); jsonObject.put("time_stamp", time); List<Object> stringList = new ArrayList<>(); stringList.add(object); jsonObject.put("objects", stringList); String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), encrypt); new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("controlDevice onSuccess"); callBack.onSuccess(""); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true, mac).send(); } /** @@ -448,6 +509,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -489,6 +551,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -528,6 +591,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -538,6 +602,36 @@ callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } public void sidNameChange(List<LinkSidNameBean> bean, String gatewayId, String ipaddress, boolean isLocalEncrypt, HDLLinkTCallBack<String> callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<LinkSidNameBean>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(bean); String topic = String.format(TopicConstant.EDIT_FUNCTION, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), isLocalEncrypt); new HDLConnectHelper(ipaddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sidNameChange onSuccess"); callBack.onSuccess(""); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } /** @@ -567,6 +661,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -577,6 +672,39 @@ callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * sid绑定房间 */ public void sidBindUid(List<LinkSidUidBean> bean, String gatewayId, String ipaddress, boolean isLocalEncrypt, HDLLinkTCallBack<String> callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<LinkSidUidBean>> 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), isLocalEncrypt); new HDLConnectHelper(ipaddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("sidBindUid onSuccess"); callBack.onSuccess("Success"); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } /** @@ -606,6 +734,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -645,6 +774,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -685,6 +815,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -725,6 +856,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -773,6 +905,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -813,6 +946,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -862,6 +996,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -913,6 +1048,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -953,6 +1089,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -993,6 +1130,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1033,6 +1171,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1076,6 +1215,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1120,6 +1260,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1164,6 +1305,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1208,6 +1350,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1262,6 +1405,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1315,6 +1459,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1368,6 +1513,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1409,6 +1555,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1450,6 +1597,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1491,6 +1639,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1543,6 +1692,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1595,6 +1745,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1636,6 +1787,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1697,6 +1849,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1741,6 +1894,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1754,6 +1908,230 @@ } } /** * 服务调用 * * @param topic 主题 * @param callBack 回调 */ public void serviceDown(String topic, JSONArray jsonArray, String ipAddress, boolean encrypt, HDLLinkCallBack callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<JSONArray> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(jsonArray); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), encrypt); new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } /** * 服务调用 * * @param topic 主题 * @param callBack 回调 */ public void serviceDown(String topic, JSONArray jsonArray, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<JSONArray> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(jsonArray); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 服务状态获取 * * @param topic 主题 * @param callBack 回调 */ public void serviceRead(String topic, JSONArray jsonArray, String ipAddress, boolean encrypt, HDLLinkCallBack callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<JSONArray> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(jsonArray); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), encrypt); new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } /** * 服务状态获取 * * @param topic 主题 * @param callBack 回调 */ public void serviceRead(String topic, JSONArray jsonArray, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<JSONArray> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(jsonArray); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取毫米波区域 * * @param sid 请求参数 指定读取的设备sid * @param callBack 回调 */ public void getMillimeterArea(String sid, HDLLinkTCallBack<List<MMWAreaBean>> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<PropertyReadRequest>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List<PropertyReadRequest> list = new ArrayList<>(); list.add(new PropertyReadRequest(sid)); data.setObjects(list); String topic = String.format(TopicConstant.MMW_AREA_GET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); Type type = new TypeToken<BaseLocalResponse<List<MMWAreaBean>>>() { }.getType(); List<MMWAreaBean> 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 读取状态 @@ -1787,12 +2165,20 @@ public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); callBack.onSuccess(msg.toString()); Type type = new TypeToken<BaseLocalResponse<String>>() { }.getType(); String 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1804,6 +2190,58 @@ callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 读取状态 * * @param sids 请求参数 指定读取的设备sid列表 * @param callBack 回调 */ public void propertyRead(List<String> sids, String gatewayId, String ipAddress, String mac, boolean encrypt, HDLLinkCallBack callBack) { if (null == callBack) { return; } String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<PropertyReadRequest>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List<PropertyReadRequest> 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), encrypt); new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("propertyRead onSuccess"); Type type = new TypeToken<BaseLocalResponse<String>>() { }.getType(); String 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true, mac).send(); } /** @@ -1845,6 +2283,105 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } public void getSceneListaa(HDLLinkTCallBack<List<LinkSceneBean>> callBack) { if (null == callBack) { return; } if (!TextUtils.isEmpty("18FE8588AC73E526")) { 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, "18FE8588AC73E526"); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper("192.168.1.100", request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken<BaseLocalResponse<List<LinkSceneBean>>>() { }.getType(); List<LinkSceneBean> 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } public void getSceneListAiks(GatewayBean bean, HDLLinkTCallBack<List<LinkSceneBean>> callBack) { if (null == callBack) { return; } if (!TextUtils.isEmpty(bean.getDevice_mac())) { 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, bean.getDevice_mac()); LinkRequest request = new LinkRequest(topic, jsonObject.toString(), false); new HDLConnectHelper(bean.getIp_address(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneList onSuccess"); if (callBack != null) { Type type = new TypeToken<BaseLocalResponse<List<LinkSceneBean>>>() { }.getType(); List<LinkSceneBean> 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1896,6 +2433,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1944,6 +2482,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -1956,6 +2495,244 @@ } } } /** * 场景控制 * * @param sids 场景sid列表 * @param callBack 回调 */ public void controlAiksScene(GatewayBean bean, List<String> sids, HDLLinkCallBack callBack) { if (null == callBack) { return; } String device_mac = bean.getDevice_mac(); if (!TextUtils.isEmpty(device_mac)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<PropertyReadRequest>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List<PropertyReadRequest> list = new ArrayList<>(); for (String s : sids) { list.add(new PropertyReadRequest(s)); } data.setObjects(list); String topic = String.format(TopicConstant.SCENE_CONTROL, device_mac); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), false); new HDLConnectHelper(bean.getIp_address(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("controlScene onSuccess"); callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 群控增删 */ public void groupControlEdit(List<LinkGroupControlCreateBean> list, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<LinkGroupControlCreateBean>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(list); String topic = String.format(TopicConstant.GROUPCONTROL_EDIT, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneDetail onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 群控控制 */ public void groupControlControl(JSONObject object, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<JSONObject>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List<JSONObject> objectList = new ArrayList<>(); objectList.add(object); data.setObjects(objectList); String topic = String.format(TopicConstant.GROUPCONTROL_CONTROL, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneDetail onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 群控删除 */ public void groupControlDelete(JSONObject object, HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<JSONObject>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); List<JSONObject> objectList = new ArrayList<>(); objectList.add(object); data.setObjects(objectList); String topic = String.format(TopicConstant.GROUPCONTROL_DELETE, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneDetail onSuccess"); if (callBack != null) { callBack.onSuccess(msg.toString()); } } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); HDLLinkLocalSdk.showToast(hdlLinkCode.getMsg()); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 群控列表获取 */ public void getGroupControlList(List<JSONObject> list, HDLLinkTCallBack<List<LinkGroupControlCreateBean>> callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<List<JSONObject>> data = new BaseLocalResponse<>(); data.setId(IdUtils.getUUId()); data.setTime_stamp(time); data.setObjects(list); String topic = String.format(TopicConstant.GROUPCONTROL_LIST_GET, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { LogUtils.i("getSceneDetail onSuccess"); if (callBack != null) { Type type = new TypeToken<BaseLocalResponse<List<LinkGroupControlCreateBean>>>() { }.getType(); List<LinkGroupControlCreateBean> 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(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 通用UDP发送指令 @@ -2038,10 +2815,13 @@ * * @param callBack 回调所有读取到的网关列表 */ public void refreshGateway(GatewayCallBack callBack) { HDLLinkLocalGateway.getInstance().refreshGateway(callBack); } public void refreshGateway(GatewayCallBack callBack,List<String> spks) { HDLLinkLocalGateway.getInstance().refreshGateway(callBack,spks); } /** * 获取当前住宅缓存的所有网关,一般是调试软件使用,三方不用调试此方法 * 如果之前还没有读取过网关,先调用方法refreshGatewayByHome读取一次 @@ -2090,6 +2870,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -2133,6 +2914,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -2145,6 +2927,51 @@ } } } /** * 全量更新房间列表 * * @param callBack */ public void getGatewaylist(HDLLinkCallBack callBack) { if (null == callBack) { return; } String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); if (!TextUtils.isEmpty(gatewayId)) { String time = String.valueOf(System.currentTimeMillis()); final BaseLocalResponse<JSONObject> senData = new BaseLocalResponse<>(); senData.setId(IdUtils.getUUId()); senData.setTime_stamp(time); JSONObject jsonObject = new JSONObject(); jsonObject.put("device_mac", "0C811A93EA13F1F5"); senData.setObjects(jsonObject); String topic = String.format(TopicConstant.GATEWAY_INFO, gatewayId); LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(senData), HDLLinkConfig.getInstance().isLocalEncrypt()); new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (msg instanceof LinkResponse) { callBack.onSuccess(msg.toString()); } } @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } } }, true).send(); } else { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } } /** * 获取房间绑定关系 @@ -2185,6 +3012,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); @@ -2230,6 +3058,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -2272,6 +3101,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } @@ -2287,7 +3117,7 @@ /** * 刚刚绑定网关的时候设置网关经纬度 不需要加密 */ public void gatewayLocation(String mGatewayId, String longitude, String lat, boolean isEncrypt,HDLLinkTCallBack<String> callBack) { public void gatewayLocation(String mGatewayId, String longitude, String lat, boolean isEncrypt, HDLLinkTCallBack<String> callBack) { if (null == callBack) { return; } @@ -2314,6 +3144,7 @@ @Override public void onFailure(HDLLinkCode hdlLinkCode) { //HDLExceptionSubmitUtils.submit(topic, request, HDLLinkCopyException.getErrorWithCode(hdlLinkCode.getCode(), hdlLinkCode.getMsg())); if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java
@@ -24,6 +24,12 @@ * 地理围栏 8 不做 */ private String condition_type; /** * 没有该字段、该值或0: 状态检测(每次收到状态就成立) * 1:动作检测(需要切换状态才成立) */ private String detect_type; private String identifier; //true:临时bypass中、false:启用中 是否过滤 private String bypass; private List<LinkCreateLogicInputConditionBean> condition = new ArrayList<>(); @@ -41,6 +47,22 @@ private LinkCreateSceneFunctionControlAttrsBean controlAttrs; private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); public String getIdentifier() { return identifier == null ? "" : identifier; } public void setIdentifier(@NonNull String identifier) { this.identifier = identifier; } public String getDetect_type() { return detect_type == null ? "" : detect_type; } public void setDetect_type(@NonNull String detect_type) { this.detect_type = detect_type; } public String getBypass() { return bypass == null ? "" : bypass; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java
@@ -33,10 +33,19 @@ private String oid; private String spk; private String online; private String identifier; private LinkCreateSceneImageBean sceneImage; private LinkCreateSceneFunctionControlAttrsBean controlAttrs; private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); public String getIdentifier() { return identifier == null ? "" : identifier; } public void setIdentifier(@NonNull String identifier) { this.identifier = identifier; } public String getStatusDesc() { return statusDesc == null ? "" : statusDesc; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java
@@ -17,12 +17,39 @@ private String sid; private String group; private String can_delete; private String can_edit; private String gatewayId; private String image; private String from; //来源,方便网关识别 private String local; private List<LinkCreateSceneImageToCloudBean> imageBeans = new ArrayList<>(); private List<String> uids = new ArrayList<>(); private List<LinkCreateSceneFunctionBean> functions = new ArrayList<>(); public String getCan_edit() { return can_edit == null ? "" : can_edit; } public void setCan_edit(@NonNull String can_edit) { this.can_edit = can_edit; } public String getLocal() { return local == null ? "" : local; } public void setLocal(@NonNull String local) { this.local = local; } public String getFrom() { return from == null ? "" : from; } public void setFrom(@NonNull String from) { this.from = from; } public String getGatewayId() { return gatewayId == null ? "" : gatewayId; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java
@@ -23,11 +23,20 @@ private String name; private String online; private String type; private String identifier; private LinkCreateSceneImageBean sceneImage = new LinkCreateSceneImageBean(); private List<LinkCreateSceneFunctionStatusBean> status = new ArrayList<>(); private LinkCreateSceneFunctionControlAttrsBean controlAttrs = new LinkCreateSceneFunctionControlAttrsBean(); private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); public String getIdentifier() { return identifier == null ? "" : identifier; } public void setIdentifier(@NonNull String identifier) { this.identifier = identifier; } public LinkCreateSceneImageBean getSceneImage() { if (sceneImage == null) { sceneImage = new LinkCreateSceneImageBean("0", "https://hdl-hz-prod.oss-cn-hangzhou.aliyuncs.com/material/appdebug/scene0.png", "/static/images/scene/scene0.png"); HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkGroupControlCreateBean.java
New file @@ -0,0 +1,114 @@ package com.hdl.sdk.link.bean; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/6/30 * description: */ public class LinkGroupControlCreateBean implements Serializable { private String sid; private String name; private String type; private List<String> uids = new ArrayList<>(); private List<LinkSidSpkBean> sids = new ArrayList<>(); /** * "${已完成数}/${总数}" */ private String progress; /** * 1:配置中 * 2:配置失败 * 3:配置成功 * 4:部分成功 */ private int state; /** * 用户开关记录 可以控制 默认off是关 on是开 */ private String onoff; public LinkGroupControlCreateBean() { } public String getOnoff() { return onoff == null ? "" : onoff; } public void setOnoff(@NonNull String onoff) { this.onoff = onoff; } public String getSid() { return sid == null ? "" : sid; } public void setSid(@NonNull String sid) { this.sid = sid; } public String getName() { return name == null ? "" : name; } public void setName(@NonNull String name) { this.name = name; } public String getType() { return type == null ? "" : type; } public void setType(@NonNull String type) { this.type = type; } public List<String> getUids() { if (uids == null) { return uids = new ArrayList<>(); } return uids; } public int getState() { return state; } public void setState(@NonNull int state) { this.state = state; } public void setUids(@NonNull List<String> uids) { this.uids = uids; } public List<LinkSidSpkBean> getSids() { if (sids == null) { return sids = new ArrayList<>(); } return sids; } public String getProgress() { return progress == null ? "" : progress; } public void setProgress(@NonNull String progress) { this.progress = progress; } public void setSids(@NonNull List<LinkSidSpkBean> sids) { this.sids = sids; } public LinkGroupControlCreateBean(String name, String type) { this.name = name; this.type = type; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java
@@ -16,11 +16,30 @@ private String delay;//延迟 private String modify_time;//修改时间 private String gatewayId; private String from; //来源,方便网关识别 private String local; private LinkCreateSceneBean detailInfo = new LinkCreateSceneBean();//详情 /** * 专门给场景批量操作做处理 */ private boolean isChoose = false; public String getLocal() { return local == null ? "" : local; } public void setLocal(@NonNull String local) { this.local = local; } public String getFrom() { return from == null ? "" : from; } public void setFrom(@NonNull String from) { this.from = from; } public boolean isChoose() { return isChoose; @@ -40,7 +59,7 @@ @NonNull public LinkCreateSceneBean getDetailInfo() { return detailInfo== null ? new LinkCreateSceneBean() : detailInfo; return detailInfo == null ? new LinkCreateSceneBean() : detailInfo; } public void setDetailInfo(@NonNull LinkCreateSceneBean detailInfo) { HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidSpkBean.java
New file @@ -0,0 +1,61 @@ package com.hdl.sdk.link.bean; import java.io.Serializable; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/6/30 * description: */ public class LinkSidSpkBean implements Serializable { private String sid; private String spk; /** * 功能sid配置的状态,0表示成功,其他表示失败 */ private int config_state; private String msg; public LinkSidSpkBean() { } public String getMsg() { return msg == null ? "" : msg; } public void setMsg(@NonNull String msg) { this.msg = msg; } public int getConfig_state() { return config_state; } public void setConfig_state(@NonNull int config_state) { this.config_state = config_state; } public String getSid() { return sid == null ? "" : sid; } public void setSid(@NonNull String sid) { this.sid = sid; } public String getSpk() { return spk == null ? "" : spk; } public void setSpk(@NonNull String spk) { this.spk = spk; } public LinkSidSpkBean(String sid, String spk) { this.sid = sid; this.spk = spk; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaBean.java
New file @@ -0,0 +1,36 @@ package com.hdl.sdk.link.bean; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/11/20 * description: */ public class MMWAreaBean implements Serializable { private String sid; private List<MMWAreaSpaceBean> spaces = new ArrayList<>(); public String getSid() { return sid == null ? "" : sid; } public void setSid(@NonNull String sid) { this.sid = sid; } public List<MMWAreaSpaceBean> getSpaces() { if (spaces == null) { return spaces = new ArrayList<>(); } return spaces; } public void setSpaces(@NonNull List<MMWAreaSpaceBean> spaces) { this.spaces = spaces; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaSpaceBean.java
New file @@ -0,0 +1,85 @@ package com.hdl.sdk.link.bean; import java.io.Serializable; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/11/20 * description: */ public class MMWAreaSpaceBean implements Serializable { private String space_id; private String space_type; private String space_color; private String space_name; private String x_s; private String x_e; private String y_s; private String y_e; public String getSpace_id() { return space_id == null ? "" : space_id; } public void setSpace_id(@NonNull String space_id) { this.space_id = space_id; } public String getSpace_type() { return space_type == null ? "" : space_type; } public void setSpace_type(@NonNull String space_type) { this.space_type = space_type; } public String getSpace_color() { return space_color == null ? "" : space_color; } public void setSpace_color(@NonNull String space_color) { this.space_color = space_color; } public String getSpace_name() { return space_name == null ? "" : space_name; } public void setSpace_name(@NonNull String space_name) { this.space_name = space_name; } public String getX_s() { return x_s == null ? "" : x_s; } public void setX_s(@NonNull String x_s) { this.x_s = x_s; } public String getX_e() { return x_e == null ? "" : x_e; } public void setX_e(@NonNull String x_e) { this.x_e = x_e; } public String getY_s() { return y_s == null ? "" : y_s; } public void setY_s(@NonNull String y_s) { this.y_s = y_s; } public String getY_e() { return y_e == null ? "" : y_e; } public void setY_e(@NonNull String y_e) { this.y_e = y_e; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java
@@ -152,6 +152,9 @@ //读取状态 public static final String PROPERTY_READ = "/base/%s/thing/property/read"; //获取毫米波区域 public static final String MMW_AREA_GET = "/base/%s/thing/service/sub_space_config_get/down"; //读取状态响应 public static final String PROPERTY_READ_REPLY = "/base/%s/thing/property/read_reply"; @@ -312,8 +315,25 @@ public static final String NATIVE_MODBUS_DOWN ="/user/%s/custom/native/inverter/down"; public static final String NATIVE_MODBUS_UP ="/user/%s/custom/native/inverter/up"; public static final String NATIVE_MODBUS_DOWN_REPLY ="/user/%s/custom/native/inverter/down_reply"; /** * 群控增改 */ public static final String GROUPCONTROL_EDIT ="/user/%s/custom/device/group/control/edit"; /** * 群控列表 */ public static final String GROUPCONTROL_LIST_GET ="/user/%s/custom/device/group/control/list"; public static final String NATIVE_MODBUS_DOWN_SLAVE ="/user/%s/custom/native/inverter/down/slaveoid/%s"; public static final String NATIVE_MODBUS_DOWN_SLAVE_REPLY ="/user/%s/custom/native/inverter/down_reply/slaveoid/%s"; /** * 群控删除 */ public static final String GROUPCONTROL_DELETE ="/user/%s/custom/device/group/control/delete"; /** * 群控控制 */ public static final String GROUPCONTROL_CONTROL ="/user/%s/custom/device/group/control/down"; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java
@@ -24,7 +24,7 @@ private static final LockList<EventListener> ALL_TOPICS_EVENT = new LockList<EventListener>();//所有主题消息 // private static final ArrayMap<String, List<EventListener>> EVENT = new ArrayMap<>(); // private static final ArrayMap<String, List<EventListener>> EVENT = new ArrayMap<>(); private static final LockArrayMap<String, List<EventListener>> EVENT = new LockArrayMap<String, List<EventListener>>(); private static final ExecutorService ioThread = ThreadToolUtils.getInstance().newFixedThreadPool(2); @@ -99,7 +99,7 @@ if (ev != null && !ev.isEmpty()) { // TYPE.remove(listener); ev.remove(listener); LogUtils.i(String.format("移除订阅主题:%s,当前回调数量:%s", tag, ev.size())); LogUtils.i(String.format("移除订阅主题:%s,当前回调数量:%s",tag,ev.size())); } } } catch (Exception e) { @@ -112,12 +112,11 @@ /** * 两个主题是否匹配 * * @param desString 字典中的主题 * @param desString 字典中的主题 * @param sourceString 接收到的主题 * @return */ boolean isMatch(String desString, String sourceString) { boolean isMatch(String desString,String sourceString) { String[] des = desString.split("/"); String[] source = sourceString.split("/"); if (des.length != source.length) { @@ -136,11 +135,10 @@ /** * 事件分发器,分发所有在接口列表中的事件 * * @param topicTag - * @param o - * @param topicTag * @param o */ public synchronized void post(String topicTag, final Object o) { public synchronized void post(String topicTag, @NonNull Object o) { try { for (String key : EVENT.keySet()) { if (!isMatch(key, topicTag)) { @@ -170,16 +168,16 @@ } //开发分发事件 for (EventListener listener : ALL_TOPICS_EVENT) { // ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { // @Override // public void run() { if (listener != null) { listener.onMessage(o); } // } // }); ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { @Override public void run() { if (listener != null) { listener.onMessage(o); } } }); } } catch (Exception e) { }catch (Exception e){ LogUtils.e(e.getMessage()); } @@ -191,10 +189,8 @@ public synchronized void filePost() { //TODO } /** * 注册所有主题消息的监听 * * @param listener */ public synchronized void registerAllTopicsListener(EventListener listener) { @@ -210,7 +206,6 @@ /** * 取消所有主题消息的监听 * * @param listener */ public synchronized void removeAllTopicsListener(EventListener listener) { @@ -229,13 +224,13 @@ }); } private synchronized void clear() { public synchronized void clear() { ALL_TOPICS_EVENT.clear(); EVENT.clear(); // TYPE.clear(); } private synchronized void release() { public synchronized void release() { clear(); ioThread.shutdownNow(); } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java
@@ -14,33 +14,31 @@ * @Description : HDLError */ public class HDLLinkCode { public static final HDLLinkCode HDL_UNKOWN_CODE = new HDLLinkCode(-1000, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNKOWN_CODE)); public static final HDLLinkCode HDL_DATA_ERROR = new HDLLinkCode(-2000, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_ERROR)); public static final HDLLinkCode HDL_DATA_NULL_ERROR = new HDLLinkCode(-2001, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_NULL_ERROR)); public static final HDLLinkCode HDL_AUTH_ERROR = new HDLLinkCode(2002, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR)); public static final HDLLinkCode HDL_SEND_ERROR = new HDLLinkCode(2003, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEND_ERROR)); public static final HDLLinkCode HDL_TIMEOUT_ERROR = new HDLLinkCode(2004, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TIMEOUT_ERROR)); public static final HDLLinkCode HDL_UNAUTHORIZED_ERROR = new HDLLinkCode(-2005, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNAUTHORIZED_ERROR)); public static final HDLLinkCode HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED = new HDLLinkCode(-2006, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED)); public static final HDLLinkCode HDL_SEARCH_GATEWAY_TIMEOUT_ERROR = new HDLLinkCode(-2007, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEARCH_GATEWAY_TIMEOUT_ERROR)); public static final HDLLinkCode HDL_AUTH_MAC_KEY_ERROR = new HDLLinkCode(-2008, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_MAC_KEY_ERROR)); public static final HDLLinkCode HDL_DATA_PARSING_ERROR = new HDLLinkCode(-2009, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_PARSING_ERROR)); public static final HDLLinkCode HDL_GET_DEVICE_LIST_ERROR = new HDLLinkCode(-2100, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_DEVICE_LIST_ERROR)); public static final HDLLinkCode HDL_GET_FUNCTION_LIST_ERROR = new HDLLinkCode(-2101, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_LIST_ERROR)); public static final HDLLinkCode HDL_GET_FUNCTION_PROPERTIES_ERROR = new HDLLinkCode(-2102, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_PROPERTIES_ERROR)); public static final HDLLinkCode HDL_CONTROL_FAILURE_ERROR = new HDLLinkCode(-2103, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_CONTROL_FAILURE_ERROR)); public static final HDLLinkCode HDL_GET_GATEWAY_FAILURE_ERROR = new HDLLinkCode(-2104, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_GATEWAY_FAILURE_ERROR)); public static final HDLLinkCode HDL_GET_Zigbee_FAILURE_ERROR = new HDLLinkCode(-2105, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_FAILURE_ERROR)); public static final HDLLinkCode HDL_GATEWAY_NOT_EXIST = new HDLLinkCode(-2106, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_NOT_EXIST)); public static final HDLLinkCode HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR = new HDLLinkCode(-2107, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR)); public static final HDLLinkCode HDL_MILLIMETER_NOT_EXIST = new HDLLinkCode(-2108, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_MILLIMETER_NOT_EXIST)); public static final HDLLinkCode HDL_APPLICATION_CODE = new HDLLinkCode(-2109, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_APPLICATION_EXCEPTION)); public static final HDLLinkCode HDL_TOPIC_NOT_RIGHT = new HDLLinkCode(-2110, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TOPIC_NOT_RIGHT)); public static final HDLLinkCode HDL_OBJECT_NOT_SUPPORT = new HDLLinkCode(-2111, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_OBJECT_NOT_SUPPORT)); public static final HDLLinkCode HDL_GATEWAY_REMOTE_NOT_RESPONSE = new HDLLinkCode(-2112, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_REMOTE_NOT_RESPONSE)); public static final HDLLinkCode HDL_SUCCESS = new HDLLinkCode(0, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.SUCCESS)); public static final HDLLinkCode HDL_GATEWAY_FOUND_LOCALLY = new HDLLinkCode(-2113, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_FOUND_LOCALLY)); public static final HDLLinkCode HDL_UNKOWN_CODE=new HDLLinkCode(-1000,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNKOWN_CODE)); public static final HDLLinkCode HDL_DATA_ERROR =new HDLLinkCode(-2000, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_ERROR)) ; public static final HDLLinkCode HDL_DATA_NULL_ERROR=new HDLLinkCode(-2001, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_NULL_ERROR)); public static final HDLLinkCode HDL_AUTH_ERROR=new HDLLinkCode(2002,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR) ); public static final HDLLinkCode HDL_SEND_ERROR=new HDLLinkCode(2003, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEND_ERROR)); public static final HDLLinkCode HDL_TIMEOUT_ERROR=new HDLLinkCode(2004, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TIMEOUT_ERROR)); public static final HDLLinkCode HDL_UNAUTHORIZED_ERROR=new HDLLinkCode(-2005,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNAUTHORIZED_ERROR)); public static final HDLLinkCode HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED=new HDLLinkCode(-2006, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED)); public static final HDLLinkCode HDL_SEARCH_GATEWAY_TIMEOUT_ERROR=new HDLLinkCode(-2007, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEARCH_GATEWAY_TIMEOUT_ERROR)); public static final HDLLinkCode HDL_AUTH_MAC_KEY_ERROR=new HDLLinkCode(-2008, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_MAC_KEY_ERROR)); public static final HDLLinkCode HDL_DATA_PARSING_ERROR=new HDLLinkCode(-2009, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_PARSING_ERROR)); public static final HDLLinkCode HDL_GET_DEVICE_LIST_ERROR=new HDLLinkCode(-2100, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_DEVICE_LIST_ERROR)); public static final HDLLinkCode HDL_GET_FUNCTION_LIST_ERROR=new HDLLinkCode(-2101, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_LIST_ERROR)); public static final HDLLinkCode HDL_GET_FUNCTION_PROPERTIES_ERROR=new HDLLinkCode(-2102, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_PROPERTIES_ERROR)); public static final HDLLinkCode HDL_CONTROL_FAILURE_ERROR=new HDLLinkCode(-2103, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_CONTROL_FAILURE_ERROR)); public static final HDLLinkCode HDL_GET_GATEWAY_FAILURE_ERROR=new HDLLinkCode(-2104, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_GATEWAY_FAILURE_ERROR)); public static final HDLLinkCode HDL_GET_Zigbee_FAILURE_ERROR=new HDLLinkCode(-2105, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_FAILURE_ERROR)); public static final HDLLinkCode HDL_GATEWAY_NOT_EXIST=new HDLLinkCode(-2106,HDLLinkLocalSdk.getInstance().getContext().getString( R.string.HDL_GATEWAY_NOT_EXIST)); public static final HDLLinkCode HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR=new HDLLinkCode(-2107, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR)); public static final HDLLinkCode HDL_MILLIMETER_NOT_EXIST=new HDLLinkCode(-2108, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_MILLIMETER_NOT_EXIST)); public static final HDLLinkCode HDL_APPLICATION_CODE=new HDLLinkCode(-2109,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_APPLICATION_EXCEPTION)); public static final HDLLinkCode HDL_TOPIC_NOT_RIGHT=new HDLLinkCode(-2110,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TOPIC_NOT_RIGHT)); public static final HDLLinkCode HDL_OBJECT_NOT_SUPPORT=new HDLLinkCode(-2111,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_OBJECT_NOT_SUPPORT)); public static final HDLLinkCode HDL_GATEWAY_REMOTE_NOT_RESPONSE=new HDLLinkCode(-2112,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_REMOTE_NOT_RESPONSE)); public static final HDLLinkCode HDL_SUCCESS=new HDLLinkCode(0,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.SUCCESS)); private String msg; private int code; @@ -48,7 +46,6 @@ this.msg = msg; this.code = code; } public String getMsg() { return msg; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java
@@ -203,8 +203,41 @@ } public static int byteArrayToInt(byte[] b) { return (b[0] & 0xFF) * 256 * 256 * 256 + (b[1] & 0xFF) * 256 * 256 + (b[2] & 0xFF) * 256 + (b[3] & 0xFF); int i = (b[0] & 0xFF) * 256 * 256 * 256 + (b[1] & 0xFF) * 256 * 256 + (b[2] & 0xFF) * 256 + (b[3] & 0xFF); return i; } /** * 解密 * * @param contentByte 待解密待字符串hexStr * @param contentByte 密钥 * @return */ public static byte[] decrypt(byte[] contentByte) { try { //KEY转换 Key key = new SecretKeySpec("HDLRDCENTER1985.".getBytes(), "AES"); //解密 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); IvParameterSpec ivps = new IvParameterSpec("HDLRDCENTER1985.".getBytes()); cipher.init(Cipher.DECRYPT_MODE, key, ivps); byte[] result = cipher.doFinal(contentByte); return result; } catch (NoSuchAlgorithmException e) { LogUtils.e(e.getMessage()); } catch (InvalidKeyException e) { LogUtils.e(e.getMessage()); } catch (NoSuchPaddingException e) { LogUtils.e(e.getMessage()); } catch (BadPaddingException e) { LogUtils.e(e.getMessage()); } catch (IllegalBlockSizeException e) { LogUtils.e(e.getMessage()); } catch (InvalidAlgorithmParameterException e) { LogUtils.e(e.getMessage()); } return null; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java
@@ -4,8 +4,6 @@ import com.hdl.sdk.link.common.utils.ByteUtils; import java.nio.charset.StandardCharsets; /** * Created by Tong on 2021/9/29. @@ -125,7 +123,7 @@ "Length:" + getLength() + "\r\n\r\n"; return ByteUtils.concatBytes(header.getBytes(StandardCharsets.UTF_8), getData()); return ByteUtils.concatBytes(header.getBytes("utf-8"), getData()); } catch (Exception e) { return new byte[]{}; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java
@@ -34,7 +34,7 @@ public void setByteData(byte []data) { this.byteData = data; // this.data = new String(data); this.data = new String(data); this.length=data.length; } @@ -45,7 +45,7 @@ public void setData(String data) { this.data = data; if (!TextUtils.isEmpty(data)) { // this.byteData = data.getBytes(); this.byteData = data.getBytes(); setLength(data.length()); } else { setLength(0); HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddAIMillimeterZTSuccessInfo.java
New file @@ -0,0 +1,13 @@ package com.hdl.sdk.link.core.bean.eventbus; import java.io.Serializable; /** * Created by Zoro * Created on 2023/9/18 * description: */ public class EventNotifyAddAIMillimeterZTSuccessInfo implements Serializable { public EventNotifyAddAIMillimeterZTSuccessInfo() { } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddSlaveGatewaySuccessInfo.java
New file @@ -0,0 +1,60 @@ package com.hdl.sdk.link.core.bean.eventbus; import java.io.Serializable; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2022/6/29 * description: */ public class EventNotifyAddSlaveGatewaySuccessInfo implements Serializable { private String mac; private String auth_code; private String result; private String message; public EventNotifyAddSlaveGatewaySuccessInfo(String mac, String auth_code, String result, String message) { this.mac = mac; this.auth_code = auth_code; this.result = result; this.message = message; } public String getMac() { return mac == null ? "" : mac; } public void setMac(@NonNull String mac) { this.mac = mac; } public String getAuth_code() { return auth_code == null ? "" : auth_code; } public void setAuth_code(@NonNull String auth_code) { this.auth_code = auth_code; } public String getResult() { return result == null ? "" : result; } public void setResult(@NonNull String result) { this.result = result; } public String getMessage() { return message == null ? "" : message; } public void setMessage(@NonNull String message) { this.message = message; } public EventNotifyAddSlaveGatewaySuccessInfo() { } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAiMillimeterZTMacInfo.java
New file @@ -0,0 +1,26 @@ package com.hdl.sdk.link.core.bean.eventbus; import java.io.Serializable; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/10/19 * description: */ public class EventNotifyAiMillimeterZTMacInfo implements Serializable { private String mac; public EventNotifyAiMillimeterZTMacInfo(String mac) { this.mac = mac; } public String getMac() { return mac == null ? "" : mac; } public void setMac(@NonNull String mac) { this.mac = mac; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/DeviceRemoteInfo.java
New file @@ -0,0 +1,71 @@ package com.hdl.sdk.link.core.bean.gateway; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/10/25 * description: */ public class DeviceRemoteInfo implements Serializable { private String gatewayId; private boolean encrypt;//是否加密 private int algorithmType;//0.SM4 1.AES 2.不加密 private String spk; private String mac;//设备mac private String secret;//私钥 public String getGatewayId() { return gatewayId == null ? "" : gatewayId; } public void setGatewayId(@NonNull String gatewayId) { this.gatewayId = gatewayId; } public boolean isEncrypt() { return encrypt; } public void setEncrypt(@NonNull boolean encrypt) { this.encrypt = encrypt; } public int getAlgorithmType() { return algorithmType; } public void setAlgorithmType(@NonNull int algorithmType) { this.algorithmType = algorithmType; } public String getSpk() { return spk == null ? "" : spk; } public void setSpk(@NonNull String spk) { this.spk = spk; } public String getMac() { return mac == null ? "" : mac; } public void setMac(@NonNull String mac) { this.mac = mac; } public String getSecret() { return secret == null ? "" : secret; } public void setSecret(@NonNull String secret) { this.secret = secret; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java
@@ -77,9 +77,10 @@ private String deviceId; /** * sid * 毫米波sid */ private String sid; private String spk = "energy.hdl_inverter"; @@ -87,9 +88,14 @@ private String systemStatusDesc;//云端-状态 private String hwVersion;//云端-软件版本号 private String categorySecondName;//云端-设备类型(产品二级分类名称) /** * 设备来源(自定义:0=表示网关;1=表示平台) */ private String src; //子网号/设备号 private String addresses; @@ -100,6 +106,26 @@ private String powerPvNow;//发电功率 private String totalElectricityPvToday;//今日发电量 /** * 房间归属 */ private List<String> uids = new ArrayList<>(); public List<String> getUids() { return uids; } public void setUids(List<String> uids) { this.uids = uids; } public String getSrc() { return src == null ? "" : this.src; } public void setSrc(String src) { this.src = src; } public String getAesKey() { return aesKey == null ? "" : aesKey; @@ -219,7 +245,7 @@ */ @NonNull public String getGatewayType() { return gatewayType == null ? "" : gatewayType; return gatewayType == null ? gateway_type == null ? "" : gateway_type : gatewayType; } /** @@ -371,21 +397,26 @@ } public String getSystemStatusDesc() { return systemStatusDesc == null ? "" : systemStatusDesc; } public void setSystemStatusDesc(String systemStatusDesc) { this.systemStatusDesc = systemStatusDesc; } public String getHwVersion() { return hwVersion == null ? "" : hwVersion; } public void setHwVersion(String hwVersion) { this.hwVersion = hwVersion; } public String getCategorySecondName() { return categorySecondName == null ? "" : categorySecondName; @@ -395,42 +426,52 @@ this.categorySecondName = categorySecondName; } public String getAddresses() { return addresses == null ? "" : addresses; } public void setAddresses(String addresses) { this.addresses = addresses; } public int getDeviceStatus() { return deviceStatus; } public void setDeviceStatus(int deviceStatus) { this.deviceStatus = deviceStatus; } public String getPowerPvNow() { return powerPvNow == null ? "" : powerPvNow; } public void setPowerPvNow(String powerPvNow) { this.powerPvNow = powerPvNow; } public String getTotalElectricityPvToday() { return totalElectricityPvToday == null ? "" : totalElectricityPvToday; } public void setTotalElectricityPvToday(String totalElectricityPvToday) { this.totalElectricityPvToday = totalElectricityPvToday; } public String getSpk() { return spk == null ? "" : spk; } public void setSpk(String spk) { this.spk = spk; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinAllBean.java
New file @@ -0,0 +1,45 @@ package com.hdl.sdk.link.core.bean.gateway; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/10/24 * description: */ public class SlaveGatewayJoinAllBean implements Serializable { private String id; private String time_stamp; private List<SlaveGatewayJoinBean> objects = new ArrayList<>(); public String getId() { return id == null ? "" : id; } public void setId(@NonNull String id) { this.id = id; } public String getTime_stamp() { return time_stamp == null ? "" : time_stamp; } public void setTime_stamp(@NonNull String time_stamp) { this.time_stamp = time_stamp; } public List<SlaveGatewayJoinBean> getObjects() { if (objects == null) { return objects = new ArrayList<>(); } return objects; } public void setObjects(@NonNull List<SlaveGatewayJoinBean> objects) { this.objects = objects; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinBean.java
New file @@ -0,0 +1,49 @@ package com.hdl.sdk.link.core.bean.gateway; import java.io.Serializable; import androidx.annotation.NonNull; /** * Created by Zoro * Created on 2023/10/24 * description: */ public class SlaveGatewayJoinBean implements Serializable { private String mac; private String auth_code; private String result; private String message; public String getMac() { return mac == null ? "" : mac; } public void setMac(@NonNull String mac) { this.mac = mac; } public String getAuth_code() { return auth_code == null ? "" : auth_code; } public void setAuth_code(@NonNull String auth_code) { this.auth_code = auth_code; } public String getResult() { return result == null ? "" : result; } public void setResult(@NonNull String result) { this.result = result; } public String getMessage() { return message == null ? "" : message; } public void setMessage(@NonNull String message) { this.message = message; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java
@@ -5,6 +5,6 @@ * * @Description : HDLLinkCallBack */ public interface HDLLinkCallBack extends BaseCallBack { public interface HDLLinkCallBack extends BaseCallBack{ void onSuccess(String msg); } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
@@ -114,7 +114,7 @@ /** * 可能返回code属性可能没有 没有的话直接成功 有的话只有200才会成功 */ if (code == null || code == 200 || code == 0) { if (code == null || code.intValue() == 200 || code.intValue() == 0) { notifySucceed(msg); } else { notifyFailure(ErrorUtils.getByCode(code)); @@ -325,8 +325,10 @@ String requestTopic = linkRequest.getCloudTopic(); byte[] encryBytes = null; GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); if (gatewayBean != null && getGatewayTypeList().contains(gatewayBean.getGatewayType())) { //逆变器远程mqtt秘钥不一样 if (gatewayBean != null && getNotGatewayTypeList().contains(gatewayBean.getGatewayType())) { /** * 毫米波这边获取数据的时候 已经设置了主从密钥进去了 这边不作处理 */ encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), gatewayBean.getAesKey()); } else { encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), HDLLinkConfig.getInstance().getAesKey()); @@ -420,16 +422,48 @@ } /** * 支持毫米类型 * * @return 类型列表 */ public static List<String> getGatewayTypeList() { List<String> typeList = new ArrayList<>(); // /** // * 支持毫米类型 // * // * @return 类型列表 // */ // public static List<String> getGatewayTypeList() { // List<String> typeList = new ArrayList<>(); //// typeList.add("sensor.mmv_sleep");//睡眠毫米波spk //// typeList.add("sensor.mmv_pose");//姿态毫米波spk // typeList.add("energy.hdl_inverter");//逆变器spk // typeList.add("sensor.mmv_sleep");//睡眠毫米波spk // typeList.add("sensor.mmv_pose");//姿态毫米波spk // typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本 // return typeList; // } // // public static List<String> getMillimeterTypeList() { // List<String> typeList = new ArrayList<>(); //// typeList.add("AGATEWAY");//网关 // typeList.add("sensor.mmv_sleep");//睡眠毫米波spk // typeList.add("sensor.mmv_pose");//姿态毫米波spk // typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本 // return typeList; // } /** * 获取除了网关的其它网络设备,上面写的那两个方法不一致getGatewayTypeList,getMillimeterTypeList,统一了下,以免后期出问题 * @return */ public static List<String> getNotGatewayTypeList(){ List<String> typeList = new ArrayList<>(); typeList.add("energy.hdl_inverter");//逆变器spk typeList.add("sensor.mmv_sleep");//睡眠毫米波spk typeList.add("sensor.mmv_pose");//姿态毫米波spk typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本 return typeList; } public static List<String> getNewMillimeterTypeList() { List<String> typeList = new ArrayList<>(); typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本 return typeList; } @@ -447,6 +481,7 @@ } public static boolean isInverterTopic(String topic) { if (TextUtils.isEmpty(topic)) { return false; HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java
@@ -508,14 +508,24 @@ }.getType()); GatewayBean gateway = response.getObjects(); if (gateway != null) { if (!TextUtils.isEmpty(gateway.getGatewayId()) && !TextUtils.isEmpty(gateway.getHomeId())) { // if (!TextUtils.isEmpty(HDLLinkConfig.getInstance().getGatewayId()) // && !TextUtils.isEmpty(HDLLinkConfig.getInstance().getHomeId())) { // //主网关并且是当前绑定的网关 // if ("true".equals(gateway.getMaster().toLowerCase())) { // if (gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId()) // || gateway.getDevice_mac().equals(HDLLinkConfig.getInstance().getGatewayId()) // || gateway.getOid().equals(HDLLinkConfig.getInstance().getGatewayId()) // || gateway.getHomeId().equals(HDLLinkConfig.getInstance().getHomeId())) { // HDLLinkConfig.getInstance().setLocalEncrypt(gateway.getIsLocalEncrypt());//设置是否加密 // HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address()); // //更新当前网关的信息 // HDLLinkConfig.getInstance().reSaveConfig(); // } // } if (!TextUtils.isEmpty(gateway.getHomeId())) { //主网关并且是当前绑定的网关 if ("true".equals(gateway.getMaster().toLowerCase())) { if (gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId()) || gateway.getDevice_mac().equals(HDLLinkConfig.getInstance().getGatewayId()) || gateway.getOid().equals(HDLLinkConfig.getInstance().getGatewayId()) || gateway.getHomeId().equals(HDLLinkConfig.getInstance().getHomeId())) { if (gateway.getHomeId().equals(HDLLinkConfig.getInstance().getHomeId())) { HDLLinkConfig.getInstance().setLocalEncrypt(gateway.getIsLocalEncrypt());//设置是否加密 HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address()); //更新当前网关的信息 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java
@@ -114,13 +114,14 @@ response.setByteData(bodyBytes); } else { LogUtils.e("解密失败\r\n" + linkPacket.getTopic() + "\r\n" + ByteUtils.encodeHexString(linkPacket.getBody())); response.setData(new String(linkPacket.getBody(), StandardCharsets.UTF_8)); response.setByteData(linkPacket.getBody()); response.setData(new String(linkPacket.getBody(), "utf-8")); } } else { response.setData(new String(linkPacket.getBody(), StandardCharsets.UTF_8)); response.setByteData(linkPacket.getBody()); response.setData(new String(linkPacket.getBody(), "utf-8")); } if (!linkPacket.isCloudPacket()) { if (HDLConnectHelper.isInverterTopic(response.getTopic())) { @@ -128,6 +129,20 @@ } else { LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData()); } // if (!"/user/all/custom/gateway/broadcast".equals(response.getTopic())) { // LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData()); // } // if(response.getTopic().contains("/custom/scene/list/get_reply")){ // response.setData(response.getData()+"\":1}"); // } // LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData()+ "\r\n" + response.getData().length()); } if (response.getTopic().contains("/user/all/custom/gateway/")) { // LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData() + "\r\n" + response.getData().length()); } else if (response.getTopic().contains("thing/property/up")) { // LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData() + "\r\n" + response.getData().length()); } else { LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData() + "\r\n" + response.getData().length()); } //解析完成,topic发送一次 EventDispatcher.getInstance().post(response.getTopic(), response); HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java
@@ -150,16 +150,16 @@ connOpts.setCleanSession(true); connOpts.setKeepAliveInterval(10); connOpts.setAutomaticReconnect(true); connOpts.setConnectionTimeout(10); connOpts.setConnectionTimeout(60); connOpts.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); sampleClient.setCallback(new MqttCallbackExtended() { public void connectComplete(boolean reconnect, String serverURI) { LogUtils.d(TAG, "mqtt连接成功"); LogUtils.d(TAG, "connect success"); checkAndsubscribeAllTopics(""); } public void connectionLost(Throwable throwable) { LogUtils.d(TAG, "mqtt连接断开"); LogUtils.d(TAG, "连接断开"); lastTopicFilters.clear(); } @@ -209,13 +209,14 @@ return; } LogUtils.d(TAG, "网关重连mqtt秘钥更新通知->" + topic); BaseEventBus baseEventBus=new BaseEventBus(); baseEventBus.setTopic(topic); EventBus.getDefault().post(baseEventBus); // EventNotifyRefreshGatewayAesKeyInfo eventNotifyRefreshGatewayAesKeyInfo = new EventNotifyRefreshGatewayAesKeyInfo(); // eventNotifyRefreshGatewayAesKeyInfo.setGatewayId(topics[2]); // EventBus.getDefault().post(eventNotifyRefreshGatewayAesKeyInfo); EventNotifyRefreshGatewayAesKeyInfo eventNotifyRefreshGatewayAesKeyInfo = new EventNotifyRefreshGatewayAesKeyInfo(); eventNotifyRefreshGatewayAesKeyInfo.setGatewayId(topics[2]); EventBus.getDefault().post(eventNotifyRefreshGatewayAesKeyInfo); return; } @@ -229,8 +230,9 @@ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(cloudsGatewayId); if (cloudsGatewayId.equals(HDLLinkConfig.getInstance().getHomeId())) { aes = getHomeAES(); } else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) { //逆变器mqtt专用秘钥 } else if (gatewayBean != null && HDLConnectHelper.getNotGatewayTypeList().contains(gatewayBean.getGatewayType())) { //毫米波mqtt专用秘钥、逆变器mqtt专用秘钥 aes = gatewayBean.getAesKey(); } else { aes = HDLLinkConfig.getInstance().getAesKey(); @@ -288,7 +290,10 @@ * @param sendTopic 请求主题 */ public synchronized void checkAndsubscribeAllTopics(String sendTopic) { if (null != sampleClient && !sampleClient.isConnected()) { if (null == sampleClient) { return; } if (null != sampleClient && sampleClient.isConnected() == false) { return; } try { @@ -389,6 +394,9 @@ * 切换住宅的时候订阅要全部取消 */ public void removeAllTopic() { if (null == sampleClient) { return; } if (null != sampleClient && sampleClient.isConnected() == false) { return; } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java
@@ -140,7 +140,9 @@ } List<GatewayBean> gatewayBeanList = new ArrayList<>(); for (GatewayBean gatewayBean : this.getGatewayList()) { if (spkList.contains(gatewayBean.getGatewayType()) && !"MIR01R-LK.10".equals(gatewayBean.getDevice_model())) if ((spkList.contains(gatewayBean.getGatewayType())) && !"MIR01R-LK.10".equals(gatewayBean.getDevice_model()) && !"MSMWP-LK.30".equals(gatewayBean.getDevice_model())) gatewayBeanList.add(gatewayBean); } return gatewayBeanList; @@ -158,8 +160,7 @@ } for (GatewayBean gatewayBean : this.getGatewayList()) { if (macAndSid.equals(gatewayBean.getDevice_mac()) || macAndSid.equals(gatewayBean.getSid()) || macAndSid.equals(gatewayBean.getOid())) { || macAndSid.equals(gatewayBean.getSid())) { return gatewayBean; } } @@ -181,6 +182,24 @@ } } return null; } /** * 判断住宅是否有主网关 * * @param homeId * @return */ public boolean hasMainGateway(String homeId) { boolean hasMain = false; for (GatewayBean gatewayBean : this.getGatewayList()) { if (gatewayBean.getMaster().equals("true") && gatewayBean.getHomeId().equals(homeId) && gatewayBean.getGatewayType().equals("AGATEWAY")) { hasMain = true; } } return hasMain; } /** @@ -220,6 +239,56 @@ } /** * 根据住宅id获取网关 * * @param homeId 过滤的住宅id * @param needEmptyHomeIdGateway 网关的住宅id为空时,是否可以加入网关列表 * @param callBack 回调方法 */ public void refreshWifiMillimeterZT(boolean needEmptyHomeIdGateway, GatewayCallBack callBack) { refreshGatewayBySpk(this.getWifiMillimeterZTTypeList(), needEmptyHomeIdGateway, callBack); } /** * 获取网络设备,包括网关及毫米波等网络设备 * * @param spk 网络设备spk * @param needEmptyHomeIdGateway 是否需要空住宅Id设备 * @param callBack 回调 */ public void refreshGatewayBySpk(List<String> spk, boolean needEmptyHomeIdGateway, GatewayCallBack callBack) { String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); EventListener eventListener = getSearchGatewayEvent(spk, needEmptyHomeIdGateway, tempGatewayBeanList); EventDispatcher.getInstance().register(topicReply, eventListener); ThreadToolUtils.getInstance().newFixedThreadPool(1).execute(new Runnable() { @Override public void run() { int count = 5; while (0 < count--) { try { //搜索网关 serchGatewayOneTime(); Thread.sleep(300L); } catch (InterruptedException e) { e.printStackTrace(); } } //超出次数后移除监听事件 EventDispatcher.getInstance().remove(topicReply, eventListener); if (callBack != null) { if (tempGatewayBeanList.size() == 0) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_GATEWAY_FAILURE_ERROR)); } else { callBack.onSuccess(tempGatewayBeanList); } } } }); } /** * 获取网络设备,包括网关及毫米波等网络设备 * * @param homeId 住宅Id @@ -236,7 +305,7 @@ ThreadToolUtils.getInstance().newFixedThreadPool(1).execute(new Runnable() { @Override public void run() { int count = 10; int count = 5; while (0 < count--) { try { //搜索网关 @@ -264,11 +333,15 @@ * * @param callBack 回调 */ public void refreshGateway(GatewayCallBack callBack) { refreshGateway(callBack,this.getGatewayTypeList()); } public void refreshGateway(GatewayCallBack callBack, List<String> spks) { String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); EventListener eventListener = getSearchGatewayEvent(spks, tempGatewayBeanList); // EventListener eventListener = getSearchGatewayEvent(this.getGatewayTypeList(), tempGatewayBeanList); EventDispatcher.getInstance().register(topicReply, eventListener); ThreadToolUtils.getInstance().newFixedThreadPool(1).execute(new Runnable() { @Override @@ -345,6 +418,42 @@ /** * 获取搜索网关事件 * * @return */ private EventListener getSearchGatewayEvent(List<String> spk, boolean needEmptyHomeIdGateway, final List<GatewayBean> tempGatewayBeanList) { //注册搜索网关监听 return new EventListener() { @Override public void onMessage(Object msg) { if (!(msg instanceof LinkResponse)) { return; } GatewayBean gateway = getGatewayBeanByResponse((LinkResponse) msg); if (gateway == null) { return; } gateway.setOnline(true); gateway.setIsLocalGateWay(true);//本地搜索到的网关标识为本地网关 if ("av.zk.aiks".equals(gateway.getGatewayType())) { /** 将主网关的homeid设置到埃克斯主机 */ // gateway.setHomeId(homeId); } //只加载住宅一样的或者网关还没有配置过的,或者不需要住宅id为空的网关 //更新缓存网关,会记录所有收到的网关,以为了保存网关的IP信息 updateGatewayList(gatewayBeanList, gateway); //非搜索的网关类似返回 if (spk.contains(gateway.getGatewayType())) { //更新当前读取网关的列表,这个列表每次都是清空再读取 updateGatewayList(tempGatewayBeanList, gateway); } } }; } /** * 获取搜索网关事件 * * @param homeId * @return */ @@ -362,11 +471,16 @@ } gateway.setOnline(true); gateway.setIsLocalGateWay(true);//本地搜索到的网关标识为本地网关 if ("av.zk.aiks".equals(gateway.getGatewayType())) { /** 将主网关的homeid设置到埃克斯主机 */ // gateway.setHomeId(homeId); } //只加载住宅一样的或者网关还没有配置过的,或者不需要住宅id为空的网关 if (homeId.equals(gateway.getHomeId()) || (needEmptyHomeIdGateway == true && TextUtils.isEmpty(gateway.getHomeId()))) { //更新缓存网关,会记录所有收到的网关,以为了保存网关的IP信息 updateGatewayList(gatewayBeanList, gateway); //非搜索的网关类型返回 //非搜索的网关类似返回 if (spk.contains(gateway.getGatewayType())) { //更新当前读取网关的列表,这个列表每次都是清空再读取 updateGatewayList(tempGatewayBeanList, gateway); @@ -409,10 +523,10 @@ /** * 更新收到的网关到列表 * * @param gatewayBeanList * @param gateway 当前收到的网关 * @param gatewayBeans * @param gateway 当前收到的网关 */ void updateGatewayList(final List<GatewayBean> gatewayBeanList, GatewayBean gateway) { synchronized void updateGatewayList(final List<GatewayBean> gatewayBeans, GatewayBean gateway) { if (TextUtils.isEmpty(gateway.getOid()) || TextUtils.isEmpty(gateway.getDevice_mac())) { LogUtils.e("网关Mac或者Oid为空,无效网关"); @@ -421,26 +535,36 @@ boolean isFound = false;//是否在内存中找到网关对象 //找出mac一样的网关更新最新数据 for (int i = 0; i < gatewayBeanList.size(); i++) { if (gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac())) { for (int i = 0; i < gatewayBeans.size(); i++) { GatewayBean tempGatewayBean = gatewayBeans.get(i); if (tempGatewayBean.getDevice_mac().equals(gateway.getDevice_mac())) { /** * 如果已经有uid 需要设置 */ if(null!=tempGatewayBean.getUids()&&tempGatewayBean.getUids().size()>0){ gateway.setUids(tempGatewayBean.getUids()); } isFound = true; gatewayBeanList.set(i, gateway); gatewayBeans.set(i, gateway); gateway.setAesKey(tempGatewayBean.getAesKey());//保留云端获取的aeskey // break; } } //清除oid一样,mac不一样的网关缓存。一般是在网关替换的情况空间出现 for (int i = 0; i < gatewayBeanList.size(); i++) { if (gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac()) && !gatewayBeanList.get(i).getOid().equals(gateway.getOid())) { gatewayBeanList.remove(i--); for (int i = 0; i < gatewayBeans.size(); i++) { if (gatewayBeans.get(i).getDevice_mac().equals(gateway.getDevice_mac()) && !gatewayBeans.get(i).getOid().equals(gateway.getOid())) { gatewayBeans.remove(i--); } } //没有找到就添加 if (!isFound) { gatewayBeanList.add(gateway); gatewayBeans.add(gateway); } } /** * 获取网关对象 @@ -499,6 +623,44 @@ /* * 绑定网关 * */ public void SetGatewayRemoteInfo(String homeId, String master, String mac, String regionUrl, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { String topic = String.format(TopicConstant.GATEWAY_EDIT_REMOTE, mac); JsonObject jObject = new JsonObject(); if (master.equals("true")) { jObject.addProperty("server_addr", regionUrl); jObject.addProperty("remote", "true"); } else { jObject.addProperty("server_addr", ""); jObject.addProperty("remote", "false"); } jObject.addProperty("homeId", homeId); JsonObject sendJsonObj = new JsonObject(); sendJsonObj.add("objects", jObject); String time = String.valueOf(System.currentTimeMillis()); sendJsonObj.addProperty("time_stamp", time); sendJsonObj.addProperty("id", IdUtils.getUUId()); String sendStr = sendJsonObj.toString(); LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (callBack == null) return; callBack.onSuccess("1"); } @Override public void onFailure(HDLLinkCode hdlLinkCode) { if (callBack == null) return; callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } }, true).send(); } /* * 绑定网关 * 编辑homeId给网关 * */ public void bindGateway(String master, String mac, String homeId, String regionUrl, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { @@ -527,6 +689,65 @@ public void onSucceed(Object msg) { if (callBack == null) return; callBack.onSuccess("1"); } @Override public void onFailure(HDLLinkCode hdlLinkCode) { if (callBack == null) return; callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } }, true).send(); } /* * 绑定毫米波 * 编辑homeId给毫米波 * */ public void bindMillimeterGateway(String homeId, String regionUrl, String ip, String mac, String master, boolean isEncrypt, HDLLinkCallBack callBack) { String topic = String.format(TopicConstant.GATEWAY_EDIT_LOCAL, mac); JsonObject jObject = new JsonObject(); jObject.addProperty("master", master); JsonObject sendJsonObj = new JsonObject(); sendJsonObj.add("objects", jObject); String time = String.valueOf(System.currentTimeMillis()); sendJsonObj.addProperty("time_stamp", time); sendJsonObj.addProperty("id", IdUtils.getUUId()); String sendStr = sendJsonObj.toString(); LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if ("true".equals(master)) { String longStr1 = SPUtils.getString("longitude"); String latStr1 = SPUtils.getString("latitude"); if (!TextUtils.isEmpty(longStr1) && !TextUtils.isEmpty(latStr1)) { HDLLinkLocalSdk.getInstance().gatewayLocation(mac, longStr1, latStr1, isEncrypt, new HDLLinkTCallBack<String>() { @Override public void onSuccess(String data) { } @Override public void onError(HDLLinkException e) { } }); } } if (callBack == null) return; callBack.onSuccess("1"); SetGatewayRemoteInfo(homeId, master, mac, regionUrl, ip, isEncrypt, new HDLLinkCallBack() { @Override public void onSuccess(String msg) { } @Override public void onError(HDLLinkException e) { } }); } @Override @@ -686,6 +907,38 @@ }, true).send(); } /** * 设置网关入网从机模式 网关338可以使用 */ public void AuthGatewayNewVersion(String ip, String mac, String slaveMac, HDLLinkCallBack callBack) { String topic = String.format(TopicConstant.GATEWAY_AUTH, mac); JsonObject sendJsonObj = new JsonObject(); String time = String.valueOf(System.currentTimeMillis()); sendJsonObj.addProperty("time_stamp", time); sendJsonObj.addProperty("id", IdUtils.getUUId()); JsonObject jObject = new JsonObject(); jObject.addProperty("spk", "LINKDEVICE"); jObject.addProperty("mac", slaveMac); jObject.addProperty("time", "120"); sendJsonObj.add("objects", jObject); String sendStr = sendJsonObj.toString(); LinkRequest message = new LinkRequest(topic, sendStr, false); new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { callBack.onSuccess(""); } @Override public void onFailure(HDLLinkCode hdlLinkCode) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); } }, true).send(); } /* * 获取网关信息 * */ @@ -718,6 +971,51 @@ /** * 发送数据到Link网关 * * @param ip 网关IP * @param mac 网关mac * @param isEncrypt 是否加密 * @param topic 请求主题 * @param jObject 负载数据<没有填null></> * @param sendPath 发送路径<类名+方法名>class->methodName</> */ public void sendDataToLinkGateway(String ip, String mac, boolean isEncrypt, String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { String topicSend = topic.replace("%s", mac); //组装需要发送的数据 String sendStr = createSendData(jObject); // LogUtils.i("sendDataToLinkGateway->" + sendPath + "->本地发送\r\n" + topicSend + "\r\n" + sendStr); LinkRequest message = new LinkRequest(topicSend, sendStr, isEncrypt); GatewayBean gatewayBean = this.getLocalGateway(mac); if (gatewayBean != null) { message.setCloudTopic(topic.replace("%s", gatewayBean.getGatewayId())); } new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (callBack == null) return; try { JSONObject jsonObject = new JSONObject(new Gson().toJson(msg)); if (jsonObject.has("data")) { callBack.onSuccess(jsonObject.getString("data")); } } catch (Exception e) { callBack.onSuccess(e.getMessage()); } // LogUtils.i("sendDataToLinkGateway->"+sendPath+"->本地接收数据\r\n"+msg.toString()); } @Override public void onFailure(HDLLinkCode hdlLinkCode) { if (callBack == null) return; callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); // LogUtils.i("sendDataToLinkGateway->" + sendPath + "->本地接收数据->失败(-200)"); } }, true, mac).send(); } /** * 发送数据到Link网关 * * @param mac 网关mac * @param isEncrypt 是否加密 * @param topic 请求主题 @@ -728,10 +1026,10 @@ String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { GatewayBean gatewayBean = this.getLocalGateway(mac); if (gatewayBean == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_FOUND_LOCALLY)); callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); return; } String topicSend = topic.replace("%s", gatewayBean.getOid()); String topicSend = topic.replace("%s", mac); //组装需要发送的数据 String sendStr = createSendData(jObject); // LogUtils.i("sendDataToLinkGateway->" + sendPath + "->本地发送\r\n" + topicSend + "\r\n" + sendStr); @@ -761,6 +1059,7 @@ }, true, mac).send(); } /** * 发送数据到Link网关 * @@ -773,7 +1072,7 @@ String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { GatewayBean gatewayBean = this.getLocalGateway(mac); if (gatewayBean == null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_FOUND_LOCALLY)); callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); return; } String topicSend = topic.replace("%s", gatewayBean.getOid()); @@ -797,6 +1096,7 @@ // LogUtils.i("sendDataToLinkGateway->"+sendPath+"->本地接收数据\r\n"+msg.toString()); } @Override public void onFailure(HDLLinkCode hdlLinkCode) { if (callBack == null) return; @@ -805,6 +1105,7 @@ } }, true, mac).send(); } /** * 组装需要发送的数据 @@ -840,8 +1141,16 @@ private List<String> getGatewayTypeList() { List<String> typeList = new ArrayList<>(); typeList.add("AGATEWAY");//网关 typeList.add("av.zk.aiks");//埃克斯影音主机 typeList.add("sensor.mmv_sleep");//毫米波spk typeList.add("sensor.mmv_pose");//毫米波spk typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本spk return typeList; } private List<String> getWifiMillimeterZTTypeList() { List<String> typeList = new ArrayList<>(); typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本spk return typeList; } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java
@@ -30,19 +30,17 @@ private final IClient client; private IHeartbeat iHeartbeat; public void SetHeartbeat(IHeartbeat iHeartbeat) { this.iHeartbeat = iHeartbeat; public void SetHeartbeat(IHeartbeat iHeartbeat){ this.iHeartbeat=iHeartbeat; } /** * 当前接收到数据的时间 */ private long time = System.currentTimeMillis(); private long time=System.currentTimeMillis(); /** * tcp是否已经连接 */ private boolean connected = false; private boolean connected=false; public IClient getClient() { return client; @@ -56,7 +54,7 @@ private final ArrayMap<String, SendListener> sendMap = new ArrayMap<>(); public TcpSocketBoot(IClient client) { public TcpSocketBoot(IClient client) { TCP_SOCKET_BOOT_LIST.add(this); this.client = client; initConnectThread(); @@ -68,25 +66,25 @@ /** * 记录所有SocketBoot */ final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList<>(); final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList(); /** * 根据IP地址及端口获取当前socketBoot * * @param ipAddress * @param port * @return */ public static TcpSocketBoot getByEndPoint(String ipAddress, int port) { if (ipAddress == null) { return null; public static TcpSocketBoot getByEndPoint(String ipAddress, int port){ if(ipAddress==null){ return null; } for (TcpSocketBoot tcpSocketBoot : TCP_SOCKET_BOOT_LIST) { if (ipAddress.equals(tcpSocketBoot.getClient().getOptions().getIp()) && tcpSocketBoot.getClient().getOptions().getPort() == port) { for(TcpSocketBoot tcpSocketBoot : TCP_SOCKET_BOOT_LIST){ if(ipAddress.equals(tcpSocketBoot.getClient().getOptions().getIp())&& tcpSocketBoot.getClient().getOptions().getPort()==port) { return tcpSocketBoot; } } return null; return null; } /** @@ -94,14 +92,14 @@ */ private synchronized void connect() { try { LogUtils.i("TCP连接:" + this.getClient().getOptions().getIp()); LogUtils.i("TCP连接:"+this.getClient().getOptions().getIp()); client.onConnectStatus(ConnectStatus.CONNECTING); // Thread.sleep(700); client.connect(); LogUtils.i("TCP连接成功:" + this.getClient().getOptions().getIp()); connected = true; LogUtils.i("TCP连接成功:"+this.getClient().getOptions().getIp()); connected=true; client.onConnectStatus(ConnectStatus.CONNECTED); } catch (Exception e) { }catch(Exception e) { LogUtils.e(e.getMessage()); } } @@ -118,7 +116,7 @@ public void run() { while (true) { try { if (!connected) { if(connected==false){ Thread.sleep(100); continue; } @@ -165,7 +163,7 @@ if (connected) { //读取数据 client.onHandleResponse(); time = System.currentTimeMillis(); time= System.currentTimeMillis(); } else { try { Thread.sleep(1000); @@ -198,7 +196,7 @@ if (!connected) { reconect(); } Thread.sleep(5 * 1000); Thread.sleep(5*1000); } catch (Exception e) { LogUtils.e("定时连接线程异常:" + e.getMessage()); @@ -236,7 +234,6 @@ }); } } /** * 重新连接 */ @@ -247,7 +244,6 @@ /** * 发送无需回调 * * @param msg 发送的数据 */ public void sendMsg(byte[] msg) { @@ -283,6 +279,7 @@ } } // /** // * 断开全部的Link网关连接 // */ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java
@@ -1,4 +1,4 @@ //package com.hdl.sdk.link.zigbee.bean; package com.hdl.sdk.link.zigbee.bean;//package com.hdl.sdk.link.zigbee.bean; // //import androidx.annotation.NonNull; // app/build.gradle
@@ -123,8 +123,8 @@ //二维码库 implementation project(path: ':third-zxing') //Link本地库 implementation project(path: ':HDLLinkLocalSdk') // implementation project(path: ':HDLLinkPMSdk') implementation project(path: ':HDLLinkPMSdk') implementation 'com.hdl.android.link.local.sdk:localsdk:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' local.properties
@@ -5,4 +5,4 @@ # For customization when using a Version Control System, please read the # header note. #Sun Aug 06 16:06:53 CST 2023 sdk.dir=/Users/user/Library/Android/sdk sdk.dir=/Users/hdl/Library/Developer/Xamarin/android-sdk-macosx