From 3b47201d878ba8ff973b84baf15942475688e964 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期五, 15 十二月 2023 16:04:28 +0800 Subject: [PATCH] 合并第一个版本 --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java | 26 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java | 4 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinAllBean.java | 45 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java | 20 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidSpkBean.java | 61 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java | 41 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java | 22 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkGroupControlCreateBean.java | 114 +++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java | 35 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java | 4 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaBean.java | 36 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 40 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaSpaceBean.java | 85 ++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAiMillimeterZTMacInfo.java | 26 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java | 9 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinBean.java | 49 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/DeviceRemoteInfo.java | 71 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java | 45 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java | 2 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddAIMillimeterZTSuccessInfo.java | 13 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java | 45 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java | 27 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddSlaveGatewaySuccessInfo.java | 60 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java | 345 ++++++++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java | 841 ++++++++++++++++++++++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java | 9 local.properties | 5 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java | 53 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java | 19 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java | 21 30 files changed, 2,040 insertions(+), 133 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java index b308e0b..db9a046 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java +++ b/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; @@ -9,10 +10,14 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; +import com.hdl.linkpm.sdk.core.exception.HDLLinkCopyException; +import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils; 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 +96,7 @@ return instance; } - private Context context; + private static Context context; public void init(Context context) { @@ -118,6 +123,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 +258,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 +303,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 +348,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 +393,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 +436,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 +447,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 +511,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 +553,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 +593,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 +604,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 +663,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 +674,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 +736,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 +776,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 +817,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 +858,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 +907,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 +948,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 +998,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 +1050,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 +1091,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 +1132,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 +1173,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 +1217,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 +1262,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 +1307,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 +1352,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 +1407,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 +1461,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 +1515,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 +1557,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 +1599,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 +1641,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 +1694,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 +1747,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 +1789,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 +1851,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 +1896,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 +1910,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 璇锋眰鍙傛暟 鎸囧畾璇诲彇鐨勮澶噑id + * @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 +2167,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 +2192,58 @@ callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); } } + } + + /** + * 璇诲彇鐘舵�� + * + * @param sids 璇锋眰鍙傛暟 鎸囧畾璇诲彇鐨勮澶噑id鍒楄〃 + * @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 +2285,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 +2435,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 +2484,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 +2497,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 +2817,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 +2872,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 +2916,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 +2929,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 +3014,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 +3060,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 +3103,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 +3119,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 +3146,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)); } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java index 17b4870..2440999 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java +++ b/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涓�乫alse:鍚敤涓� 鏄惁杩囨护 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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java index 9b43655..e2010e6 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java +++ b/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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java index 7b3bb69..91f4f18 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java +++ b/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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java index 1d588dc..a93a83c 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java +++ b/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"); diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkGroupControlCreateBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkGroupControlCreateBean.java new file mode 100644 index 0000000..8f65835 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkGroupControlCreateBean.java @@ -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; + } + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java index 623f2f0..7cc6785 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java +++ b/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) { diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidSpkBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidSpkBean.java new file mode 100644 index 0000000..06648a4 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidSpkBean.java @@ -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; + } + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaBean.java new file mode 100644 index 0000000..2f5c37f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaBean.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaSpaceBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaSpaceBean.java new file mode 100644 index 0000000..3dd42e8 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/MMWAreaSpaceBean.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java index d66e47d..a480450 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java +++ b/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"; } \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java index 256bcb7..37f8b50 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java +++ b/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(); } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java index a2c6adf..2597fa7 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java +++ b/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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java index 2c2f4a1..e4f6a9d 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java +++ b/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; } + /** + * 瑙e瘑 + * + * @param contentByte 寰呰В瀵嗗緟瀛楃涓瞙exStr + * @param contentByte 瀵嗛挜 + * @return + */ + public static byte[] decrypt(byte[] contentByte) { + try { + //KEY杞崲 + Key key = new SecretKeySpec("HDLRDCENTER1985.".getBytes(), "AES"); + //瑙e瘑 + 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; + } } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java index b874aeb..2f8e8d7 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java +++ b/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[]{}; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java index 5a58a0d..ad2f655 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java +++ b/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); diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddAIMillimeterZTSuccessInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddAIMillimeterZTSuccessInfo.java new file mode 100644 index 0000000..5daca20 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddAIMillimeterZTSuccessInfo.java @@ -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() { + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddSlaveGatewaySuccessInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddSlaveGatewaySuccessInfo.java new file mode 100644 index 0000000..c0b93ce --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAddSlaveGatewaySuccessInfo.java @@ -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() { + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAiMillimeterZTMacInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAiMillimeterZTMacInfo.java new file mode 100644 index 0000000..a0004af --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyAiMillimeterZTMacInfo.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/DeviceRemoteInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/DeviceRemoteInfo.java new file mode 100644 index 0000000..465809b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/DeviceRemoteInfo.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java index 38dd20e..a16c7fd 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java @@ -77,9 +77,10 @@ private String deviceId; /** - * sid + * 姣背娉id */ 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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinAllBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinAllBean.java new file mode 100644 index 0000000..e707f63 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinAllBean.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinBean.java new file mode 100644 index 0000000..0bccc53 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/SlaveGatewayJoinBean.java @@ -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; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java index 200b35e..4bdf82f 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java +++ b/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); } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java index 549d298..61564cc 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java +++ b/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())) { - //閫嗗彉鍣ㄨ繙绋媘qtt绉橀挜涓嶄竴鏍� + if (gatewayBean != null && getMillimeterTypeList().contains(gatewayBean.getGatewayType())) { + /** + * 姣背娉㈣繖杈硅幏鍙栨暟鎹殑鏃跺�� 宸茬粡璁剧疆浜嗕富浠庡瘑閽ヨ繘鍘讳簡 杩欒竟涓嶄綔澶勭悊 + */ encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), gatewayBean.getAesKey()); } else { encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), HDLLinkConfig.getInstance().getAesKey()); @@ -334,20 +336,12 @@ if (MqttRecvClient.getInstance() != null) { MqttRecvClient.getInstance().send(requestTopic, encryBytes); } - if (HDLConnectHelper.isInverterTopic(linkRequest.getCloudTopic())) { - LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getCloudSendBytes()))); - } else { - LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes())); - } + LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes())); } //鏈湴TCP else { if (!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅 - if (HDLConnectHelper.isInverterTopic(linkRequest.getTopic())) { - LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getSendBytes()))); - } else { - LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes())); - } + LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes())); } HDLTcpConnect.getTcpSocketBoot(ipAddress).sendMsg(EncryptUtil.getEncryBytes(linkRequest)); } @@ -419,6 +413,7 @@ } + /** * 鏀寔姣背绫诲瀷 * @@ -429,6 +424,24 @@ // typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk // typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk typeList.add("energy.hdl_inverter");//閫嗗彉鍣╯pk + typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk + typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk + typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰 + return typeList; + } + + public static List<String> getMillimeterTypeList() { + List<String> typeList = new ArrayList<>(); +// typeList.add("AGATEWAY");//缃戝叧 + typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk + typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk + typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰 + return typeList; + } + + public static List<String> getNewMillimeterTypeList() { + List<String> typeList = new ArrayList<>(); + typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰 return typeList; } @@ -446,6 +459,7 @@ } + public static boolean isInverterTopic(String topic) { if (TextUtils.isEmpty(topic)) { return false; diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java index 1aac1f7..b4c04e5 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java @@ -114,13 +114,14 @@ response.setByteData(bodyBytes); } else { LogUtils.e("瑙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 (HDLConnectHelper.isLocal()) { 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()); } //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� EventDispatcher.getInstance().post(response.getTopic(), response); diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java index d6a0d1a..09cc1e0 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java +++ b/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())) { - //閫嗗彉鍣╩qtt涓撶敤绉橀挜 + } + else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) { + //姣背娉qtt涓撶敤绉橀挜銆侀�嗗彉鍣╩qtt涓撶敤绉橀挜 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; } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java index 1d2fd4b..ffc31ce 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java +++ b/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 杩囨护鐨勪綇瀹卛d + * @param needEmptyHomeIdGateway 缃戝叧鐨勪綇瀹卛d涓虹┖鏃讹紝鏄惁鍙互鍔犲叆缃戝叧鍒楄〃 + * @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())) { + /** 灏嗕富缃戝叧鐨刪omeid璁剧疆鍒板焹鍏嬫柉涓绘満 + */ +// gateway.setHomeId(homeId); + } + //鍙姞杞戒綇瀹呬竴鏍风殑鎴栬�呯綉鍏宠繕娌℃湁閰嶇疆杩囩殑锛屾垨鑰呬笉闇�瑕佷綇瀹卛d涓虹┖鐨勭綉鍏� + //鏇存柊缂撳瓨缃戝叧锛屼細璁板綍鎵�鏈夋敹鍒扮殑缃戝叧锛屼互涓轰簡淇濆瓨缃戝叧鐨処P淇℃伅 + updateGatewayList(gatewayBeanList, gateway); + //闈炴悳绱㈢殑缃戝叧绫讳技杩斿洖 + if (spk.contains(gateway.getGatewayType())) { + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + updateGatewayList(tempGatewayBeanList, gateway); + } + } + }; + } + + /** + * 鑾峰彇鎼滅储缃戝叧浜嬩欢 + * * @param homeId * @return */ @@ -362,6 +471,11 @@ } gateway.setOnline(true); gateway.setIsLocalGateWay(true);//鏈湴鎼滅储鍒扮殑缃戝叧鏍囪瘑涓烘湰鍦扮綉鍏� + if ("av.zk.aiks".equals(gateway.getGatewayType())) { + /** 灏嗕富缃戝叧鐨刪omeid璁剧疆鍒板焹鍏嬫柉涓绘満 + */ +// gateway.setHomeId(homeId); + } //鍙姞杞戒綇瀹呬竴鏍风殑鎴栬�呯綉鍏宠繕娌℃湁閰嶇疆杩囩殑锛屾垨鑰呬笉闇�瑕佷綇瀹卛d涓虹┖鐨勭綉鍏� if (homeId.equals(gateway.getHomeId()) || (needEmptyHomeIdGateway == true && TextUtils.isEmpty(gateway.getHomeId()))) { //鏇存柊缂撳瓨缃戝叧锛屼細璁板綍鎵�鏈夋敹鍒扮殑缃戝叧锛屼互涓轰簡淇濆瓨缃戝叧鐨処P淇℃伅 @@ -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鎴栬�匫id涓虹┖锛屾棤鏁堢綉鍏�"); @@ -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())) { + /** + * 濡傛灉宸茬粡鏈塽id 闇�瑕佽缃� + */ + 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());//淇濈暀浜戠鑾峰彇鐨刟eskey + // 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 璐熻浇鏁版嵁<娌℃湁濉玭ull></> + * @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");//姣背娉pk typeList.add("sensor.mmv_pose");//姣背娉pk + typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰spk + return typeList; + } + + private List<String> getWifiMillimeterZTTypeList() { + List<String> typeList = new ArrayList<>(); + typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰spk return typeList; } } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java index 6705fe2..d721eea 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java +++ b/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 @@ /** * 璁板綍鎵�鏈塖ocketBoot */ - final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList<>(); + final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList(); /** * 鏍规嵁IP鍦板潃鍙婄鍙h幏鍙栧綋鍓峴ocketBoot - * * @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 @@ } } + // /** // * 鏂紑鍏ㄩ儴鐨凩ink缃戝叧杩炴帴 // */ diff --git a/local.properties b/local.properties index e7b3898..e8d918b 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,6 @@ # Location of the SDK. This is only used by Gradle. # 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 +#Thu Dec 14 10:02:46 CST 2023 +#sdk.dir=/Users/user/Library/Android/sdk +sdk.dir=/Users/hdl/Library/Developer/Xamarin/android-sdk-macosx -- Gitblit v1.8.0