From 2a01ef5e49422cca49bc7476fc1b8be8c8556561 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 08 九月 2022 10:46:57 +0800 Subject: [PATCH] 最新sdk java版本 --- HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/.DS_Store | 0 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java | 37 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java | 57 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java | 158 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java | 149 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java | 226 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java | 174 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java | 22 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java | 1719 +++++++++ HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java | 21 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java | 173 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java | 182 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java | 11 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java | 133 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java | 24 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java | 13 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java | 42 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java | 40 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java | 29 HDLSDK/HDLLinkLocalSdk.zip | 0 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java | 135 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/MqttHelper.java | 8 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java | 12 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java | 48 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java | 71 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java | 58 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java | 75 HDLSDK/.DS_Store | 0 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/TextUtils.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java | 8 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java | 153 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java | 49 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java | 516 ++ HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java | 32 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java | 7 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java | 51 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java | 14 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java | 7 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java | 80 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java | 50 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java | 45 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java | 63 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java | 9 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java | 12 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java | 104 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java | 5 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java | 531 +++ HDLSDK/app/src/main/java/com/hdl/hdlsdk/DemoAdapter.java | 4 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java | 17 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java | 101 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java | 33 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java | 5 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java | 50 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java | 152 HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java | 164 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java | 315 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java | 4 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java | 20 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java | 387 ++ HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java | 37 HDLSDK/HDLLinkLocalSdk/build.gradle | 12 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java | 6 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java | 94 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java | 21 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java | 68 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java | 122 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java | 10 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java | 44 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java | 18 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java | 51 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java | 12 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java | 8 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java | 29 HDLSDK/build.gradle | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java | 36 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java | 18 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java | 154 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java | 55 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java | 112 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java | 5 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java | 44 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java | 342 - HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java | 250 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java | 91 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java | 243 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java | 45 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java | 12 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java | 5 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java | 31 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java | 343 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java | 20 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java | 36 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java | 87 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java | 2 HDLSDK/settings.gradle | 6 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java | 7 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java | 179 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java | 191 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java | 60 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java | 67 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java | 73 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java | 49 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java | 39 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java | 83 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java | 30 HDLSDK/app/build.gradle | 6 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java | 20 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java | 3 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 304 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java | 30 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java | 26 /dev/null | 26 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java | 2 HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java | 289 + HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java | 2 HDLSDK/HDLLinkLocalSdk/.gitignore | 0 131 files changed, 10,033 insertions(+), 561 deletions(-) diff --git a/HDLSDK/.DS_Store b/HDLSDK/.DS_Store index 6e9be3b..da07aa6 100644 --- a/HDLSDK/.DS_Store +++ b/HDLSDK/.DS_Store Binary files differ diff --git a/HDLSDK/HDLLinkLocalSdk.zip b/HDLSDK/HDLLinkLocalSdk.zip new file mode 100644 index 0000000..912e032 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk.zip Binary files differ diff --git a/HDLSDK/hdl-common/.gitignore b/HDLSDK/HDLLinkLocalSdk/.gitignore similarity index 100% rename from HDLSDK/hdl-common/.gitignore rename to HDLSDK/HDLLinkLocalSdk/.gitignore diff --git a/HDLSDK/HDLLinkLocalSdk/build.gradle b/HDLSDK/HDLLinkLocalSdk/build.gradle new file mode 100644 index 0000000..098b7d3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'java-library' +} + +dependencies { + api 'com.google.code.gson:gson:2.8.8' +} + +java { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 +} diff --git a/HDLSDK/hdl-socket/src/.DS_Store b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/.DS_Store similarity index 95% rename from HDLSDK/hdl-socket/src/.DS_Store rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/.DS_Store index bb1962f..770f79e 100644 --- a/HDLSDK/hdl-socket/src/.DS_Store +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/.DS_Store Binary files differ diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java new file mode 100644 index 0000000..6b78aae --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java @@ -0,0 +1,1719 @@ +package com.hdl.sdk.link; + + + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.bean.LinkCreateLogicBean; +import com.hdl.sdk.link.bean.LinkCreateSceneBean; +import com.hdl.sdk.link.bean.LinkEnableLogicBean; +import com.hdl.sdk.link.bean.LinkEnableSecurityBean; +import com.hdl.sdk.link.bean.LinkFunctionBean; +import com.hdl.sdk.link.bean.LinkLogicBean; +import com.hdl.sdk.link.bean.LinkOidBean; +import com.hdl.sdk.link.bean.LinkReNameGWBean; +import com.hdl.sdk.link.bean.LinkResponseBean; +import com.hdl.sdk.link.bean.LinkRoomBean; +import com.hdl.sdk.link.bean.LinkRoomBindBean; +import com.hdl.sdk.link.bean.LinkSceneBean; +import com.hdl.sdk.link.bean.LinkSidStrBean; +import com.hdl.sdk.link.bean.LinkSidUidBean; +import com.hdl.sdk.link.core.bean.FileRequest; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; +import com.hdl.sdk.link.core.bean.request.DeviceControlRequest; +import com.hdl.sdk.link.core.bean.request.FunctionAttributeRequest; +import com.hdl.sdk.link.core.bean.request.PropertyReadRequest; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.core.callback.HDLLinkTCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLUdpConnect; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; +import com.hdl.sdk.link.core.utils.LinkResponseUtils; +import com.hdl.sdk.link.core.utils.QueueUtils; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : HDLLink + */ +public class HDLLinkLocalSdk { + + private String language="zh"; + /** + * instance + */ + private volatile static HDLLinkLocalSdk instance; + + /** + * getInstance + * + * @return HDLLink + */ + public static synchronized HDLLinkLocalSdk getInstance() { + if (instance == null) { + synchronized (HDLLinkLocalSdk.class) { + if (instance == null) { + instance = new HDLLinkLocalSdk(); + } + } + } + return instance; + } + + /** + * 鏈湴SDK鍒濆鍖栵紝鍒濆鍖栫綉鍏矷d鍙婃湰鍦伴�氳鐨勫瘑閽� + * @param gatewayId 缃戝叧Id + * @param localSecret 瀵嗛挜 + */ + public void init(String gatewayId,String localSecret){ + //瀵笻DL搴旂敤杞欢鏉ヨ锛屾湰鍦伴�氳瀵嗛挜鍜岀綉鍏矷d鍦ㄤ娇鐢ㄦ椂瑕佽缃� + HDLLinkConfig.getInstance().setLocalSecret(localSecret); + HDLLinkConfig.getInstance().setGatewayId(gatewayId); + QueueUtils.getInstance().start();//鍒濆鍖栨帴鏀舵暟鎹嚎绋� + HDLUdpConnect.getInstance().initUdp();//鍒濆鍖杣dp鐩戝惉 + searchGatewayBroadcast(null);//鎼滅储缃戝叧 + } + + public void setlanguage(String language){ + this.language=language; + } + public String getLanguage(){ + return language; + } + + + /** + * 璁剧疆鎵撳嵃鏄惁寮�鍚� + * @param enable + */ + public void setLogEnabled(boolean enable){ + LogUtils.setEnabled(enable); + } + + /** + * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * + * @param listener + */ + public synchronized void registerAllTopicsListener(EventListener listener) { + EventDispatcher.getInstance().registerAllTopicsListener(listener); + } + + /** + * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * + * @param listener + */ + public synchronized void removeAllTopicsListener(EventListener listener) { + if (listener == null) return; + EventDispatcher.getInstance().removeAllTopicsListener(listener); + } + + /***********************涓夋柟璁惧鍜岀綉鍏抽�氫俊涔嬪墠鐨勮璇佹祦绋�****************************/ + /** + * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 + * 璁よ瘉閫氳繃鎵嶈兘杩涜璁惧鎺у埗 + * + * @return + */ + public boolean checkIfCertified() { + return HDLLinkConfig.getInstance().checkIfCertified(); + } + + /** + * 寮�濮嬬洃鍚拰鍙戣捣鍏ョ綉鍙婅璇佽姹� + * + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void startAuthenticateRequest(AuthenticateRequest request, HDLLinkCallBack callBack) { + HDLUdpConnect.getInstance().startAuthenticateRequest(request, callBack); + } + + /** + * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 + * + * @param ip 缃戝叧IP + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void sendAuthenticateRequest(String ip, AuthenticateRequest request, HDLLinkCallBack callBack) { + HDLUdpConnect.getInstance().sendAuthenticateRequest(ip, request, callBack); + } + + /***********************涓夋柟璁惧璇峰厛璁よ瘉鎴愬姛 鍐嶈皟鐢ㄤ笅闈㈢殑鎺ュ彛鍜岀綉鍏抽�氫俊****************************/ + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayMulticast(HDLUdpConnect.SearchGatewayCallBack callBack) { + HDLUdpConnect.getInstance().searchGatewayMulticast(callBack); + } + + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayBroadcast(HDLUdpConnect.SearchGatewayCallBack callBack) { + HDLUdpConnect.getInstance().searchGatewayBroadcast(callBack); + } + + /** + * 鑾峰彇璁惧鍒楄〃 + */ + public void getDeviceList(HDLLinkTCallBack<List<LinkOidBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + String topic = String.format(TopicConstant.GET_DEVICE_LIST, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + + + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getDeviceList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkOidBean>>>() { + }.getType(); + List<LinkOidBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鏇存敼缃戝叧澶囨敞鍚� + */ + public void changeGWName(String gateWayName, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<LinkReNameGWBean> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); + linkReNameGWBean.setDevice_name(gateWayName); + data.setObjects(linkReNameGWBean); + String topic = String.format(TopicConstant.GATEWAY_RENAME, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<LinkResponseBean>>() { + }.getType(); + LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid缁戝畾鎴块棿 + */ + public void sidBindUid(List<LinkSidUidBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + 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), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<LinkResponseBean>>() { + }.getType(); + LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); + // TODO: 2022/1/13 澶勭悊200code + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid鍒犻櫎缁戝畾鎴块棿鍏崇郴 + */ + public void sidDeleteUid(List<LinkSidUidBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + 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_DELETE_ROOM, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒涘缓鍦烘櫙 + */ + public void createScene(List<LinkCreateSceneBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateSceneBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.CREATE_SCENE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 + */ + public void editScene(List<LinkCreateSceneBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateSceneBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + for(int i=0;i<data.getObjects().size();i++){ + if(data.getObjects().get(i).getFunctions().size()==0){ + data.getObjects().get(i).setFunctions(null); + } + if(data.getObjects().get(i).getUids().size()==0){ + data.getObjects().get(i).setUids(null); + } + } + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + LogUtils.d("LinkRequestLinkRequest", GsonConvert.getGson().toJson(request)); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鍦烘櫙 + */ + public void deleteScene(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_DELETE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栧垪琛� + */ + public void getLogicList(HDLLinkTCallBack<List<LinkLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.LOGIC_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkLogicBean>>>() { + }.getType(); + List<LinkLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void getLogicDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + + String topic = String.format(TopicConstant.LOGIC_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateLogicBean>>>() { + }.getType(); + List<LinkCreateLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓鑷姩鍖� + */ + public void createLogic(List<LinkCreateLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_EDIT, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void enableLogic(List<LinkEnableLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkEnableLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_ENABLE_EDIT, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鑷姩鍖� + */ + public void deleteLogic(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_DELETE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇瀹夐槻鍒楄〃 + */ + public void getSecurityList(HDLLinkTCallBack<List<LinkLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.SECURITY_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkLogicBean>>>() { + }.getType(); + List<LinkLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void getSecurityDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + + String topic = String.format(TopicConstant.SECURITY_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateLogicBean>>>() { + }.getType(); + List<LinkCreateLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓瀹夐槻 + */ + public void createSecurity(List<LinkCreateLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_EDIT, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎瀹夐槻 + */ + public void deleteSecurity(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_DELETE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void enableSecurity(List<LinkEnableSecurityBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkEnableSecurityBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_STATUS_SET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鑾峰彇鍔熻兘鍒楄〃 + */ + public void getFunctionList(HDLLinkTCallBack<List<LinkFunctionBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.GET_FUNCTION_LIST, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkFunctionBean>>>() { + }.getType(); + List<LinkFunctionBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏇存敼Sid澶囨敞鍚� + */ + public void editSidName(BaseLocalResponse<List<JsonObject>> data, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); +// LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); +// linkReNameGWBean.setDevice_name(sidName); +// data.setObjects(linkReNameGWBean); + String topic = String.format(TopicConstant.EDIT_FUNCTION, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<LinkResponseBean>>() { + }.getType(); + LinkResponseBean bean = LinkResponseUtils.convertLinkResponse(msg, type); + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍔熻兘灞炴�� + * 鏀寔鎵归噺 + * + * @param sids + * @param callBack + */ + public void getFunctionAttribute(List<String> sids, HDLLinkTCallBack<List<LinkFunctionBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + + final BaseLocalResponse<List<FunctionAttributeRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + List<FunctionAttributeRequest> list = new ArrayList<>(); + for (String s : sids) { + list.add(new FunctionAttributeRequest(s)); + } + data.setObjects(list); + + String topic = String.format(TopicConstant.GET_FUNCTION_ATTRIBUTE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionAttribute onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkFunctionBean>>>() { + }.getType(); + List<LinkFunctionBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁惧鎺у埗 + * + * @param requestList 鎺у埗鐘舵�佸弬鏁� + * @param callBack 缁撴灉鍥炶皟 + */ + public void propertyDown(List<DeviceControlRequest> requestList, HDLLinkCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + + final BaseLocalResponse<List<DeviceControlRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(requestList); + + String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); + + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + + } + + /** + * 璇诲彇鐘舵�� + * + * @param sids 璇锋眰鍙傛暟 鎸囧畾璇诲彇鐨勮澶噑id鍒楄〃 + * @param callBack 鍥炶皟 + */ + public void propertyRead(List<String> sids, HDLLinkCallBack 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<>(); + for (String s : sids) { + list.add(new PropertyReadRequest(s)); + } + data.setObjects(list); + + String topic = String.format(TopicConstant.PROPERTY_READ, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙鍒楄〃 + */ + public void getSceneList(HDLLinkTCallBack<List<LinkSceneBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.SCENE_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<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() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙璇︽儏 + */ + public void getSceneDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateSceneBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + String topic = String.format(TopicConstant.SCENE_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateSceneBean>>>() { + }.getType(); + List<LinkCreateSceneBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍦烘櫙鎺у埗 + * + * @param sids 鍦烘櫙sid鍒楄〃 + * @param callBack 鍥炶皟 + */ + public void controlScene(List<String> sids, HDLLinkCallBack 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<>(); + for (String s : sids) { + list.add(new PropertyReadRequest(s)); + } + data.setObjects(list); + + String topic = String.format(TopicConstant.SCENE_CONTROL, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 閫氱敤UDP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr body鍐呭 + * @param callBack 鍥炶皟 + */ + public void udpSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { + HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, false, callBack); + } + + /** + * 閫氱敤骞挎挱UDP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr body鍐呭 + * @param callBack 鍥炶皟 + */ + public void udpBroadcastSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { + HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, true, callBack); + } + + /** + * 閫氱敤TCP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param body body鍐呭 + * @param callBack 鍥炶皟 + */ + public void tcpSendMsg(String topic, String body, HDLLinkCallBack callBack) { + + LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } + + /** + * 閫氱敤TCP鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� + * + * @param topic 鍙戦�佹暟鎹� + * @param body 鍥炲鐨勪富棰� + */ + public void tcpSendMsg(String topic, String body) { + LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(1, HDLLinkConfig.getInstance().getIpAddress(), request, true); + } + /** + * 鍒涙柊缃戝叧鍒楄〃锛岄噸鏂拌鍙� + * + * @param homeId 浣忓畢Id + * @param callBack 鍥炶皟鎵�鏈夎鍙栧埌鐨勭綉鍏冲垪琛� + */ + public void refreshGatewayByHome(String homeId, GatewayCallBack callBack) { + HDLLinkLocalGateway.getInstance().refreshGatewayByHome(homeId, callBack); + } + + /** + * 鍒涙柊缃戝叧鍒楄〃锛岄噸鏂拌鍙� + * + * @param callBack 鍥炶皟鎵�鏈夎鍙栧埌鐨勭綉鍏冲垪琛� + */ + public void refreshGateway(GatewayCallBack callBack) { + HDLLinkLocalGateway.getInstance().refreshGateway(callBack); + } + + /** + * 鑾峰彇褰撳墠浣忓畢缂撳瓨鐨勬墍鏈夌綉鍏筹紝涓�鑸槸璋冭瘯杞欢浣跨敤锛屼笁鏂逛笉鐢ㄨ皟璇曟鏂规硶 + * 濡傛灉涔嬪墠杩樻病鏈夎鍙栬繃缃戝叧锛屽厛璋冪敤鏂规硶refreshGatewayByHome璇诲彇涓�娆� + * + * @return + */ + public List<GatewayBean> getGatewayByHome() { + return HDLLinkLocalGateway.getInstance().getGatewayList(); + } + + + /** + * 鑾峰彇鎴块棿鍒楄〃 + * + * @param callBack + */ + public void getRoomList(HDLLinkTCallBack<List<LinkRoomBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.ROOM_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkRoomBean>>>() { + }.getType(); + List<LinkRoomBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍏ㄩ噺鏇存柊鎴块棿鍒楄〃 + * + * @param list + * @param callBack + */ + public void coverAddRoomList(List<LinkRoomBean> 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<LinkRoomBean>> senData = new BaseLocalResponse<>(); + senData.setId(IdUtils.getUUId()); + senData.setTime_stamp(time); + senData.setObjects(list); + + String topic = String.format(TopicConstant.ROOM_COVER_ADD, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(senData), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鎴块棿缁戝畾鍏崇郴 + */ + public void getRoomBindList(HDLLinkTCallBack<List<LinkRoomBindBean>> callBack,List<String> uidRoomList) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + JsonArray array = new JsonArray(); + for (String uid:uidRoomList){ + array.add(uid); + } + jsonObject.add("objects", array); + + String topic = String.format(TopicConstant.ROOM_BIND_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + String replyTopic = topic + "_reply"; + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, replyTopic, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomBindList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkRoomBindBean>>>() { + }.getType(); + List<LinkRoomBindBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure() { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + + /*********************** 鏂囦欢浼犺緭 ****************************/ + /** + * 鏂囦欢鐢ㄩ�旈�氱煡 + * @param fileId 鏂囦欢Id + * @param fileName 鏂囦欢鍚嶇О + * @param purpose 鐢ㄩ�� 鐢ㄩ�旀灇涓� + * zigbee璁惧閰嶇疆鎭㈠锛� ConfigRecoveryForZigbeeDevices + * 鏁版嵁澶囦唤锛欴ataBackup + * 鏁版嵁鎭㈠锛欴ataRecovery + * @param callBack + */ + public void sendFileUserNotification(String fileId,String fileName,String purpose, HDLLinkCallBack callBack){ + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + String time = String.valueOf(System.currentTimeMillis()); + String data ="hex"+"0001"+ fileId+"\r\n"+fileName+"\r\n"+purpose; + byte []dataBytes=data.getBytes(StandardCharsets.UTF_8); + FileRequest linkRequest = new FileRequest(fileId,0x0011,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure() { + + } + }, true).send(); + } + + /** + * 鍙戦�佹枃浠剁浉鍏冲懡浠� + */ + public void sendFileCommand(byte []dataBytes,Integer command, HDLLinkCallBack callBack){ + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + String time = String.valueOf(System.currentTimeMillis()); +// byte []dataBytes=data.getBytes(StandardCharsets.UTF_8); + FileRequest linkRequest = new FileRequest("65531",command,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure() { + + } + }, true).send(); + } + + + /********************************椹卞姩鍗囩骇***********************************/ + /** + * 鍙戦�佹枃浠剁浉鍏冲懡浠� + */ + public void sendFileCommand(String ipAddress,byte []dataBytes,String fileId,Integer command, HDLLinkCallBack callBack){ + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + FileRequest linkRequest = new FileRequest(fileId,command,dataBytes,HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(ipAddress, linkRequest, linkRequest.getAckTopic(), new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure() { + + } + }, true).send(); + } + + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java new file mode 100644 index 0000000..a5ec41d --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java @@ -0,0 +1,68 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by jlchen on 1/13/22. + * + */ +public class LinkAttributesBean implements Serializable { + + private String key; + private String data_type; + private List<String> value = new ArrayList<>(); + private String max; + private String min; + + + public List<String> getValue() { + if (value == null) { + return new ArrayList<>(); + } + return value; + } + + public void setValue( List<String> value) { + this.value = value; + } + + public String getMax() { + return max == null ? "" : max; + } + + public void setMax(String max) { + this.max = max; + } + + public String getMin() { + return min == null ? "" : min; + } + + public void setMin(String min) { + this.min = min; + } + + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + + public String getData_type() { + return data_type == null ? "" : data_type; + } + + public void setData_type( String data_type) { + this.data_type = data_type; + } + + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java new file mode 100644 index 0000000..18aed58 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java @@ -0,0 +1,122 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicBean implements Serializable { + private String sid; + private String name; + private String relation; + private String enable; + //enable甯冮槻銆乨isable鎾掗槻 + private String status; + //"all"--鍏ㄥ畢甯冮槻锛�"normal"--鏅�氭ā寮�,"all_day":24灏忔椂,"mute"锛氶潤闊� + private String type; + private String gatewayId; + private LinkCreateLogicCycleBean cycle = new LinkCreateLogicCycleBean(); + private List<LinkCreateLogicInputBean> input = new ArrayList<>(); + private List<LinkCreateLogicOutputBean> output = new ArrayList<>(); + private NoticeConfigInfo noticeConfig = new NoticeConfigInfo(); + + public NoticeConfigInfo getNoticeConfig() { + return noticeConfig; + } + + public void setNoticeConfig( NoticeConfigInfo noticeConfig) { + this.noticeConfig = noticeConfig; + } + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId( String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus( String status) { + this.status = status; + } + + public String getType() { + return type == null ? "" : type; + } + + public void setType( String type) { + this.type = type; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public String getRelation() { + return relation == null ? "" : relation; + } + + public void setRelation( String relation) { + this.relation = relation; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable( String enable) { + this.enable = enable; + } + + public LinkCreateLogicCycleBean getCycle() { + return cycle; + } + + public void setCycle( LinkCreateLogicCycleBean cycle) { + this.cycle = cycle; + } + + public List<LinkCreateLogicInputBean> getInput() { + if (input == null) { + return new ArrayList<>(); + } + return input; + } + + public void setInput( List<LinkCreateLogicInputBean> input) { + this.input = input; + } + + public List<LinkCreateLogicOutputBean> getOutput() { + if (output == null) { + return new ArrayList<>(); + } + return output; + } + + public void setOutput( List<LinkCreateLogicOutputBean> output) { + this.output = output; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java new file mode 100644 index 0000000..0a496e3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java @@ -0,0 +1,45 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicCycleBean implements Serializable { + private String type; + private String desc; + private List<String> value = new ArrayList<>(); + + public String getType() { + return type == null ? "" : type; + } + + public void setType( String type) { + this.type = type; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc( String desc) { + this.desc = desc; + } + + public List<String> getValue() { + if (value == null) { + return new ArrayList<>(); + } + return value; + } + + public void setValue( List<String> value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java new file mode 100644 index 0000000..46a3bde --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java @@ -0,0 +1,191 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicInputBean implements Serializable { + private String sid; + /** + * 鏃堕棿鐐规潯浠� 1 + * 鏃堕棿娈垫潯浠� 2 + * 璁惧鐘舵�佸彉鍖栨潯浠� 3 + * 鐜淇℃伅 4 + * 瀹夐槻鏉′欢 5 涓嶅仛 + * 浜戠澶╂皵鏉′欢 6 + * 鏌愪釜閫昏緫/鍦烘櫙鐨勮緭鍑烘潯浠� 7 + * 鍦扮悊鍥存爮 8 涓嶅仛 + */ + private String condition_type; + //true:涓存椂bypass涓�乫alse:鍚敤涓� 鏄惁杩囨护 + private String bypass; + private List<LinkCreateLogicInputConditionBean> condition = new ArrayList<>(); + private String statusDesc; + private String src; + private String omodel; + private String choose; + private String oid; + private String spk; + private String delay; + private String name; + private String online; + private LinkCreateSceneImageBean sceneImage = new LinkCreateSceneImageBean(); + private List<LinkCreateSceneFunctionStatusBean> status = new ArrayList<>(); + private LinkCreateSceneFunctionControlAttrsBean controlAttrs; + private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); + + public String getBypass() { + return bypass == null ? "" : bypass; + } + + public void setBypass( String bypass) { + this.bypass = bypass; + } + + public String getStatusDesc() { + return statusDesc == null ? "" : statusDesc; + } + + public void setStatusDesc( String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel( String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose( String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk( String spk) { + this.spk = spk; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay( String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline( String online) { + this.online = online; + } + + 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"); + } + return sceneImage; + } + + public void setSceneImage( LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs( LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes( List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getCondition_type() { + return condition_type == null ? "" : condition_type; + } + + public void setCondition_type( String condition_type) { + this.condition_type = condition_type; + } + + public List<LinkCreateLogicInputConditionBean> getCondition() { + if (condition == null) { + return new ArrayList<>(); + } + return condition; + } + + public void setCondition( List<LinkCreateLogicInputConditionBean> condition) { + this.condition = condition; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java new file mode 100644 index 0000000..ba3bee5 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java @@ -0,0 +1,49 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicInputConditionBean implements Serializable { + private String key; + private String comparator; + private String data_type; + private String value; + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + public String getComparator() { + return comparator == null ? "" : comparator; + } + + public void setComparator( String comparator) { + this.comparator = comparator; + } + + public String getData_type() { + return data_type == null ? "" : data_type; + } + + public void setData_type( String data_type) { + this.data_type = data_type; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue( String value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java new file mode 100644 index 0000000..8ddd173 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java @@ -0,0 +1,179 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicOutputBean implements Serializable { + /** + * 璁惧=1 + * 鍦烘櫙=2 + * 瀹夐槻=3 + */ + private String target_type; + private String delay; + private String sid; + private String name; + private List<LinkCreateLogicOutputStatusBean> status = new ArrayList<>(); + //鍦烘櫙 + private List<LinkCreateSceneBean> detailInfo = new ArrayList<>(); + + //璁惧 + private String statusDesc; + private String src; + private String omodel; + private String choose; + private String oid; + private String spk; + private String online; + private LinkCreateSceneImageBean sceneImage; + private LinkCreateSceneFunctionControlAttrsBean controlAttrs; + private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); + + public String getStatusDesc() { + return statusDesc == null ? "" : statusDesc; + } + + public void setStatusDesc( String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel( String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose( String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk( String spk) { + this.spk = spk; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline( String online) { + this.online = online; + } + + 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"); + } + return sceneImage; + } + + public void setSceneImage( LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs( LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes( List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public List<LinkCreateSceneBean> getDetailInfo() { + if (detailInfo == null) { + return new ArrayList<>(); + } + return detailInfo; + } + + public void setDetailInfo( List<LinkCreateSceneBean> detailInfo) { + this.detailInfo = detailInfo; + } + + public String getTarget_type() { + return target_type == null ? "" : target_type; + } + + public void setTarget_type( String target_type) { + this.target_type = target_type; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay( String delay) { + this.delay = delay; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public List<LinkCreateLogicOutputStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkCreateLogicOutputStatusBean> status) { + this.status = status; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java new file mode 100644 index 0000000..29ad063 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java @@ -0,0 +1,50 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: + */ +public class LinkCreateLogicOutputStatusBean implements Serializable { + //鈿狅笍 杩欒竟闇�瑕佹坊鍔犲叾浠栧瓧娈� 鍥犱负鍗曠函杩欎簺涓嶅鐢� + private String value; + private String key; + private String attrName; + private String desc; + + public String getAttrName() { + return attrName == null ? "" : attrName; + } + + public void setAttrName( String attrName) { + this.attrName = attrName; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc( String desc) { + this.desc = desc; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue( String value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java new file mode 100644 index 0000000..dea3eae --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java @@ -0,0 +1,112 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneBean implements Serializable { + private String delay; + private String name; + private String sid; + private String can_delete; + private String gatewayId; + private String image; + private List<LinkCreateSceneImageToCloudBean> imageBeans = new ArrayList<>(); + private List<String> uids = new ArrayList<>(); + private List<LinkCreateSceneFunctionBean> functions = new ArrayList<>(); + + public String getGatewayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGatewayId( String gatewayId) { + this.gatewayId = gatewayId; + } + + public String getImage() { + return image == null ? "" : image; + } + + public void setImage( String image) { + this.image = image; + } + + public List<LinkCreateSceneImageToCloudBean> getImageBeans() { + if (imageBeans == null) { + return imageBeans = new ArrayList<>(); + } + return imageBeans; + } + + public void setImageBeans( List<LinkCreateSceneImageToCloudBean> imageBeans) { + this.imageBeans = imageBeans; + } + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId( String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getCan_delete() { + return can_delete == null ? "" : can_delete; + } + + public void setCan_delete( String can_delete) { + this.can_delete = can_delete; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay( String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public List<String> getUids() { + if (uids == null) { + return new ArrayList<>(); + } + return uids; + } + + public void setUids( List<String> uids) { + this.uids = uids; + } + + public List<LinkCreateSceneFunctionBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions( List<LinkCreateSceneFunctionBean> functions) { + this.functions = functions; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java new file mode 100644 index 0000000..dc8ccc5 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java @@ -0,0 +1,149 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneFunctionBean implements Serializable { + private String statusDesc; + private String src; + private String omodel; + private String choose; + private String oid; + private String sid; + private String spk; + private String delay; + private String name; + private String online; + private LinkCreateSceneImageBean sceneImage = new LinkCreateSceneImageBean(); + private List<LinkCreateSceneFunctionStatusBean> status = new ArrayList<>(); + private LinkCreateSceneFunctionControlAttrsBean controlAttrs = new LinkCreateSceneFunctionControlAttrsBean(); + private List<LinkCreateSceneFunctionattributesBean> attributes = new ArrayList<>(); + + 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"); + } + return sceneImage; + } + + public void setSceneImage( LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public String getStatusDesc() { + return statusDesc == null ? "" : statusDesc; + } + + public void setStatusDesc( String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel( String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose( String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk( String spk) { + this.spk = spk; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay( String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline( String online) { + this.online = online; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs( LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes( List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java new file mode 100644 index 0000000..59e8b89 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java @@ -0,0 +1,44 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneFunctionControlAttrsBean implements Serializable { + private String delay1; + private String sid; + private List<LinkCreateSceneFunctionStatusBean> status = new ArrayList<>(); + + public String getDelay1() { + return delay1 == null ? "" : delay1; + } + + public void setDelay1( String delay1) { + this.delay1 = delay1; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java new file mode 100644 index 0000000..b8d6cd4 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java @@ -0,0 +1,57 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneFunctionStatusBean implements Serializable { + private String value; + private String key; + private String attrName; + private String desc; + private String comparator; + + public String getComparator() { + return comparator == null ? "" : comparator; + } + + public void setComparator( String comparator) { + this.comparator = comparator; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue( String value) { + this.value = value; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + public String getAttrName() { + return attrName == null ? "" : attrName; + } + + public void setAttrName( String attrName) { + this.attrName = attrName; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java new file mode 100644 index 0000000..d3d553d --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java @@ -0,0 +1,101 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneFunctionattributesBean implements Serializable { + private String data_type; + private String accessMode; + private String key; + private String desc; + private String maxValue; + private String minValue; + private String unit; + private List<String> value = new ArrayList<>(); + private List<LinkCreateSceneFunctionattributesEnumerationsBean> enumerations = new ArrayList<>(); + + public String getData_type() { + return data_type == null ? "" : data_type; + } + + public void setData_type( String data_type) { + this.data_type = data_type; + } + + public String getAccessMode() { + return accessMode == null ? "" : accessMode; + } + + public void setAccessMode( String accessMode) { + this.accessMode = accessMode; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc( String desc) { + this.desc = desc; + } + + public String getMaxValue() { + return maxValue == null ? "" : maxValue; + } + + public void setMaxValue( String maxValue) { + this.maxValue = maxValue; + } + + public String getMinValue() { + return minValue == null ? "" : minValue; + } + + public void setMinValue( String minValue) { + this.minValue = minValue; + } + + public String getUnit() { + return unit == null ? "" : unit; + } + + public void setUnit( String unit) { + this.unit = unit; + } + + public List<String> getValue() { + if (value == null) { + return new ArrayList<>(); + } + return value; + } + + public void setValue( List<String> value) { + this.value = value; + } + + public List<LinkCreateSceneFunctionattributesEnumerationsBean> getEnumerations() { + if (enumerations == null) { + return new ArrayList<>(); + } + return enumerations; + } + + public void setEnumerations( List<LinkCreateSceneFunctionattributesEnumerationsBean> enumerations) { + this.enumerations = enumerations; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java new file mode 100644 index 0000000..5ef744d --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneFunctionattributesEnumerationsBean implements Serializable { + private String value; + private String desc; + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue( String value) { + this.value = value; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc( String desc) { + this.desc = desc; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java new file mode 100644 index 0000000..172ddf3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java @@ -0,0 +1,48 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneImageBean implements Serializable { + private String id; + private String url; + private String local; + + public LinkCreateSceneImageBean(String id, String url, String local) { + this.id = id; + this.url = url; + this.local = local; + } + + public LinkCreateSceneImageBean() { + } + + public String getId() { + return id == null ? "" : id; + } + + public void setId( String id) { + this.id = id; + } + + public String getUrl() { + return url == null ? "" : url; + } + + public void setUrl( String url) { + this.url = url; + } + + public String getLocal() { + return local == null ? "" : local; + } + + public void setLocal( String local) { + this.local = local; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java new file mode 100644 index 0000000..59e8c98 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java @@ -0,0 +1,39 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneImageToCloudBean implements Serializable { + private String imageId; + private String cloudUrl; + private String localUrl; + + public String getImageId() { + return imageId == null ? "" : imageId; + } + + public void setImageId( String imageId) { + this.imageId = imageId; + } + + public String getCloudUrl() { + return cloudUrl == null ? "" : cloudUrl; + } + + public void setCloudUrl( String cloudUrl) { + this.cloudUrl = cloudUrl; + } + + public String getLocalUrl() { + return localUrl == null ? "" : localUrl; + } + + public void setLocalUrl( String localUrl) { + this.localUrl = localUrl; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java new file mode 100644 index 0000000..83d3ab0 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java @@ -0,0 +1,36 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/2/21 + * description: + */ +public class LinkEnableLogicBean implements Serializable { + private String sid; + private String enable; + + public LinkEnableLogicBean(String sid, String enable) { + this.sid = sid; + this.enable = enable; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable( String enable) { + this.enable = enable; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java new file mode 100644 index 0000000..c7988fe --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java @@ -0,0 +1,51 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/2/21 + * description: + */ +public class LinkEnableSecurityBean implements Serializable { + private String sid; + private String status; + private String alarm; + + public LinkEnableSecurityBean(String sid, String status) { + this.sid = sid; + this.status = status; + } + + public LinkEnableSecurityBean(String sid, String status, String alarm) { + this.sid = sid; + this.status = status; + this.alarm = alarm; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus( String status) { + this.status = status; + } + + public String getAlarm() { + return alarm == null ? "" : alarm; + } + + public void setAlarm( String alarm) { + this.alarm = alarm; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java new file mode 100644 index 0000000..ef44f2f --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java @@ -0,0 +1,135 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by jlchen on 1/6/22. + */ +public class LinkFunctionBean implements Serializable { + private String sid;//鍔熻兘鐨剆id + private String oid;//妯″潡鐨刼id + private String name;//鍔熻兘鍥炶矾鍚嶅瓧 + private String spk;//spk + private String omodel; + private String src; + private String online; + private List<LinkAttributesBean> attributes = new ArrayList<>();//鍔熻兘灞炴�э紝闇�瑕佸崟鐙彂閫佸姛鑳藉睘鎬ц鍙栫殑鎸囦护璇诲洖鏉� + private List<LinkStatusBean> status = new ArrayList<>();//褰撳墠璁惧鐘舵�佸�硷紝璁惧鎺у埗鐨勬椂鍊欐墠鐢ㄥ埌 + + private boolean templateFlag = false;//妯℃澘鏍囪 + + /** + * 1:灞曠ず 2:涓嶅睍绀� + */ + private String show; + + public String getShow() { + return show == null ? "1" : show; + } + + public void setShow( String show) { + this.show = show; + } + + + public boolean isTemplateFlag() { + return templateFlag; + } + + public void setTemplateFlag(boolean templateFlag) { + this.templateFlag = templateFlag; + } + + + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk( String spk) { + this.spk = spk; + } + + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel( String omodel) { + this.omodel = omodel; + } + + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline( String online) { + this.online = online; + } + + + public List<LinkStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkStatusBean> status) { + this.status = status; + } + + + public List<LinkAttributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes( List<LinkAttributesBean> attributes) { + this.attributes = attributes; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java new file mode 100644 index 0000000..ab0ff6e --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java @@ -0,0 +1,154 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by jlchen on 1/6/22. + */ +public class LinkFunctionWithRoomBean implements Serializable { + private String sid;//鍔熻兘鐨剆id + private String oid;//妯″潡鐨刼id + private String name;//鍔熻兘鍥炶矾鍚嶅瓧 + private String spk;//spk + private String omodel; + private String src; + private String online; + private String roomName; + private List<LinkAttributesBean> attributes = new ArrayList<>();//鍔熻兘灞炴�э紝闇�瑕佸崟鐙彂閫佸姛鑳藉睘鎬ц鍙栫殑鎸囦护璇诲洖鏉� + private List<LinkStatusBean> status = new ArrayList<>();//褰撳墠璁惧鐘舵�佸�硷紝璁惧鎺у埗鐨勬椂鍊欐墠鐢ㄥ埌 + + private boolean templateFlag = false;//妯℃澘鏍囪 + + /** + * 1:灞曠ず 2:涓嶅睍绀� + */ + private String show; + + private boolean hasRoom; + + public boolean isHasRoom() { + return hasRoom; + } + + public void setHasRoom( boolean hasRoom) { + this.hasRoom = hasRoom; + } + + public String getRoomName() { + return roomName == null ? "" : roomName; + } + + public void setRoomName( String roomName) { + this.roomName = roomName; + } + + public String getShow() { + return show == null ? "1" : show; + } + + public void setShow( String show) { + this.show = show; + } + + + public boolean isTemplateFlag() { + return templateFlag; + } + + public void setTemplateFlag(boolean templateFlag) { + this.templateFlag = templateFlag; + } + + + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk( String spk) { + this.spk = spk; + } + + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel( String omodel) { + this.omodel = omodel; + } + + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline( String online) { + this.online = online; + } + + + public List<LinkStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus( List<LinkStatusBean> status) { + this.status = status; + } + + + public List<LinkAttributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes( List<LinkAttributesBean> attributes) { + this.attributes = attributes; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java new file mode 100644 index 0000000..edb8a7b --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java @@ -0,0 +1,73 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/2/16 + * description: 鏄惁鍚屾椂琛ㄧず瀹夐槻璺熻嚜鍔ㄥ寲??? 闇�瑕佹爣娉ㄤ竴涓�????鏄惁闇�瑕佹洿鏂颁竴涓被鍚� + */ +public class LinkLogicBean implements Serializable { + private String sid; + private String name; + /** + * 鑷姩鍖栧紑鍚叧闂� + */ + private String enable; + /** + * 瀹夐槻甯冮槻鎾ら槻浣跨敤 + */ + private String status; + private String gatewayId; + private LinkCreateLogicBean detailInfo = new LinkCreateLogicBean(); + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId( String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus( String status) { + this.status = status; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable( String enable) { + this.enable = enable; + } + + public LinkCreateLogicBean getDetailInfo() { + return detailInfo; + } + + public void setDetailInfo( LinkCreateLogicBean detailInfo) { + this.detailInfo = detailInfo; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java new file mode 100644 index 0000000..966ccbc --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java @@ -0,0 +1,174 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by jlchen on 1/10/22. + * Link Oid妯″潡瀵硅薄 + */ +public class LinkOidBean implements Serializable { + + private String oid;//oid + private String device_name;//妯″潡鍚嶅瓧 + private String device_mac;//妯″潡Mac鍦板潃銆乑igBee鐨凞eviceAddr + private String device_model;//ZigBee鐨凪odelIdentifier + private String addresses;// + private String driver_code;// + private String hw_version;//纭欢鐗堟湰 + private String fw_version; + private String src;//鏉ヨ嚜閭d釜椹卞姩 + private String from;//鏉ヨ嚜閭d釜缃戝叧 + private final String protocolType="zigbee";//鍗忚绫诲瀷(bus銆乲nx銆亃igbee) + private String parentOid;//鐖惰澶噊id + private List<ImageInfoBean> image_info = new ArrayList<>();// 涓�涓澶囧彲鑳藉涓浐浠剁増鏈� 鍥轰欢鐗堟湰鍒楄〃 + + // private boolean templateFlag = false;//妯℃澘鏍囪 +// +// public boolean isTemplateFlag() { +// return templateFlag; +// } +// +// public void setTemplateFlag(boolean templateFlag) { +// this.templateFlag = templateFlag; +// } + + public String getParentOid() { + return parentOid == null ? "" : parentOid; + } + + public void setParentOid(String parentOid) { + this.parentOid = parentOid; + } + + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + + public String getDevice_name() { + return device_name == null ? "" : device_name; + } + + public void setDevice_name( String device_name) { + this.device_name = device_name; + } + + + public String getDevice_mac() { + return device_mac == null ? "" : device_mac; + } + + public void setDevice_mac( String device_mac) { + this.device_mac = device_mac; + } + + + public String getDevice_model() { + return device_model == null ? "" : device_model; + } + + public void setDevice_model( String device_model) { + this.device_model = device_model; + } + + + public String getAddresses() { + return addresses == null ? "" : addresses; + } + + public void setAddresses( String addresses) { + this.addresses = addresses; + } + + + public String getDriver_code() { + return driver_code == null ? "" : driver_code; + } + + public void setDriver_code( String driver_code) { + this.driver_code = driver_code; + } + + + public String getHw_version() { + return hw_version == null ? "" : hw_version; + } + + public void setHw_version( String hw_version) { + this.hw_version = hw_version; + } + + + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version( String fw_version) { + this.fw_version = fw_version; + } + + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc( String src) { + this.src = src; + } + + + public String getFrom() { + return from == null ? "" : from; + } + + public void setFrom( String from) { + this.from = from; + } + + + public List<ImageInfoBean> getImage_info() { + if (image_info == null) { + return new ArrayList<>(); + } + return image_info; + } + + public void setImage_info( List<ImageInfoBean> image_info) { + this.image_info = image_info; + } + + /** + * 鍥轰欢鍜岀‖浠剁増鏈� + */ + public static class ImageInfoBean implements Serializable { + private String imageId; + private String fw_version; + + + public String getImageId() { + return imageId == null ? "" : imageId; + } + + public void setImageId( String imageId) { + this.imageId = imageId; + } + + + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version( String fw_version) { + this.fw_version = fw_version; + } + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java new file mode 100644 index 0000000..4c2c203 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java @@ -0,0 +1,17 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; + +public class LinkReNameGWBean implements Serializable { + private String device_name; + + public String getDevice_name() { + return device_name == null ? "" : device_name; + } + + public void setDevice_name( String device_name) { + this.device_name = device_name; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java new file mode 100644 index 0000000..190d9cf --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java @@ -0,0 +1,40 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/1/13 + * description: + */ +public class LinkResponseBean implements Serializable { + private String id; + private String code; + private String time_stamp; + + public String getId() { + return id == null ? "" : id; + } + + public void setId( String id) { + this.id = id; + } + + public String getCode() { + return code == null ? "" : code; + } + + public void setCode( String code) { + this.code = code; + } + + public String getTime_stamp() { + return time_stamp == null ? "" : time_stamp; + } + + public void setTime_stamp( String time_stamp) { + this.time_stamp = time_stamp; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java new file mode 100644 index 0000000..94da605 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java @@ -0,0 +1,71 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; + +/** + * Created by jlchen on 12/20/21. + */ +public class LinkRoomBean implements Serializable { + + private String uid;//鎴块棿鎴栬�呮ゼ灞傜殑Id + private String name;//鎴块棿鎴栬�呮ゼ灞傚悕瀛� + private String roomType;//绫诲瀷 FLOOR = 妤煎眰 ROOM = 鎴块棿 + private String roomImage;//鎴块棿鍥剧墖 + private String parentId;//鐖惰妭鐐笽d锛屾埧闂村垎閰嶇殑妤煎眰鐨処D + + public LinkRoomBean(String name) { + this.name = name; + } + + public LinkRoomBean() { + + } + + + public String getUid() { + return uid == null ? "" : uid; + } + + public void setUid( String uid) { + this.uid = uid; + } + + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + + public String getRoomType() { + return roomType == null ? "" : roomType; + } + + public void setRoomType( String roomType) { + this.roomType = roomType; + } + + + public String getRoomImage() { + return roomImage == null ? "" : roomImage; + } + + public void setRoomImage( String roomImage) { + this.roomImage = roomImage; + } + + + public String getParentId() { + return parentId == null ? "" : parentId; + } + + public void setParentId( String parentId) { + this.parentId = parentId; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java new file mode 100644 index 0000000..6245bd3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java @@ -0,0 +1,51 @@ +package com.hdl.sdk.link.bean; + + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by jlchen on 1/10/22. + */ +public class LinkRoomBindBean implements Serializable{ + + private String uid;//鎴块棿uid + private List<LinkSidStrBean> functions = new ArrayList<>();//鍔熻兘鍒楄〃 + private List<LinkSidStrBean> scenes = new ArrayList<>();//鍦烘櫙鍒楄〃鍒楄〃 + + + public String getUid() { + return uid == null ? "" : uid; + } + + public void setUid( String uid) { + this.uid = uid; + } + + + public List<LinkSidStrBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions( List<LinkSidStrBean> functions) { + this.functions = functions; + } + + + public List<LinkSidStrBean> getScenes() { + if (scenes == null) { + return new ArrayList<>(); + } + return scenes; + } + + public void setScenes( List<LinkSidStrBean> scenes) { + this.scenes = scenes; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java new file mode 100644 index 0000000..a348dac --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java @@ -0,0 +1,91 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by jlchen on 1/10/22. + */ +public class LinkSceneBean implements Serializable { + + private String sid;//鍦烘櫙sid + private String name;//鍦烘櫙鍚嶅瓧 + private String status;//鐘舵�� + private String group;// + private String delay;//寤惰繜 + private String modify_time;//淇敼鏃堕棿 + private String gatewayId; + private LinkCreateSceneBean detailInfo = new LinkCreateSceneBean();//璇︽儏 + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId( String gateWayId) { + this.gatewayId = gateWayId; + } + + + public LinkCreateSceneBean getDetailInfo() { + return detailInfo== null ? new LinkCreateSceneBean() : detailInfo; + } + + public void setDetailInfo( LinkCreateSceneBean detailInfo) { + this.detailInfo = detailInfo; + } + + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } + + + public String getName() { + return name == null ? "" : name; + } + + public void setName( String name) { + this.name = name; + } + + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus( String status) { + this.status = status; + } + + + public String getGroup() { + return group == null ? "" : group; + } + + public void setGroup( String group) { + this.group = group; + } + + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay( String delay) { + this.delay = delay; + } + + + public String getModify_time() { + return modify_time == null ? "" : modify_time; + } + + public void setModify_time( String modify_time) { + this.modify_time = modify_time; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java new file mode 100644 index 0000000..041b578 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.bean; + + +import java.io.Serializable; + +/** + * Created by jlchen on 1/10/22. + * + * 璁惧鎴栬�呭満鏅痵id + */ +public class LinkSidStrBean implements Serializable { + + private String sid;//璁惧鎴栬�呭満鏅痵id + + public LinkSidStrBean() { + } + + public LinkSidStrBean(String sid) { + this.sid = sid; + } + + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid( String sid) { + this.sid = sid; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java new file mode 100644 index 0000000..8767b07 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java @@ -0,0 +1,36 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by Zoro + * Created on 2022/1/13 + * description: + */ +public class LinkSidUidBean implements Serializable { + private String uid; + private List<LinkSidStrBean> functions = new ArrayList<>(); + + public String getUid() { + return uid == null ? "" : uid; + } + + public void setUid( String uid) { + this.uid = uid; + } + + public List<LinkSidStrBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions( List<LinkSidStrBean> functions) { + this.functions = functions; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java new file mode 100644 index 0000000..2f505aa --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java @@ -0,0 +1,33 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by jlchen on 1/13/22. + */ +public class LinkStatusBean implements Serializable { + + private String key; + private String value; + + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey( String key) { + this.key = key; + } + + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue( String value) { + this.value = value; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java new file mode 100644 index 0000000..06d887b --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java @@ -0,0 +1,94 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +public class LinkUploadOidBean implements Serializable{ + + private String oid;//oid + private String device_name;//妯″潡鍚嶅瓧 + private String device_mac;//妯″潡Mac鍦板潃銆乑igBee鐨凞eviceAddr + private String device_model;//ZigBee鐨凪odelIdentifier + private String addresses;// + private String driver_code;// + private String hw_version;//纭欢鐗堟湰 + private String fw_version; + + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid( String oid) { + this.oid = oid; + } + + + public String getDevice_name() { + return device_name == null ? "" : device_name; + } + + public void setDevice_name( String device_name) { + this.device_name = device_name; + } + + + public String getDevice_mac() { + return device_mac == null ? "" : device_mac; + } + + public void setDevice_mac( String device_mac) { + this.device_mac = device_mac; + } + + + public String getDevice_model() { + return device_model == null ? "" : device_model; + } + + public void setDevice_model( String device_model) { + this.device_model = device_model; + } + + + public String getAddresses() { + return addresses == null ? "" : addresses; + } + + public void setAddresses( String addresses) { + this.addresses = addresses; + } + + + public String getDriver_code() { + return driver_code == null ? "" : driver_code; + } + + public void setDriver_code( String driver_code) { + this.driver_code = driver_code; + } + + + public String getHw_version() { + return hw_version == null ? "" : hw_version; + } + + public void setHw_version( String hw_version) { + this.hw_version = hw_version; + } + + + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version( String fw_version) { + this.fw_version = fw_version; + } + + + + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java new file mode 100644 index 0000000..682d0dc --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + + + +/** + * Created by Zoro + * Created on 2022/7/29 + * description: + */ +public class NoticeConfigInfo implements Serializable { + private boolean enable; + private String noticeContent; + + public boolean isEnable() { + return enable; + } + + public void setEnable( boolean enable) { + this.enable = enable; + } + + public String getNoticeContent() { + return noticeContent == null ? "" : noticeContent; + } + + public void setNoticeContent( String noticeContent) { + this.noticeContent = noticeContent; + } +} \ No newline at end of file diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/IHDLClient.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java similarity index 94% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/IHDLClient.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java index 5c6007f..2ba494a 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/IHDLClient.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common; +package com.hdl.sdk.link.common; /** * Created by Tong on 2021/9/28. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java new file mode 100644 index 0000000..affb617 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java @@ -0,0 +1,250 @@ +package com.hdl.sdk.link.common.config; + +/** + * Created by Tong on 2021/9/22. + */ +public class TopicConstant { + + + /* + *閫氱煡鍒犻櫎骞堕��缃戝瓙璁惧鎷撴墤鍏崇郴 + *鍒犻櫎浠庣綉鍏� + * */ + public static final String DELETING_GATEWAY_SLAVE="/base/%s/thing/topo/delete/notify"; + + /* + *缃戝叧鐗╃悊閫�缃戝悗涓婃姤鍒犻櫎(閫�缃�)瀛愯澶� + * */ + public static final String DELETING_GATEWAY_SLAVE_RESULT="/base/%s/thing/topo/delete/up"; + + + + /* + 缃戝叧鏁版嵁澶囦唤杩樺師 + * */ + public static final String GATEWAY_BACKUP_RESTORE_DOWN = "/base/%s/device/backup/restore/down"; + + /* + 璋冭瘯浜哄憳涓诲姩閫氱煡缃戝叧澶囦唤鏁版嵁 + * */ + public static final String GATEWAY_BACKUP_NOTICE_DOWN = "/base/%s/device/backup/notice/down"; + /* + 澶囦唤杩樺師杩涘害鑾峰彇 + * */ + public static final String GATEWAY_BACKUP_PROGRESS_GET = "/base/%s/device/backup/restore/progress/get"; + + /* + * 缃戝叧缂栬緫鍛戒护 + * 鍐欒繙绋嬩俊鎭殑锛屼緥濡傛湇鍔″櫒鍦板潃銆丠omeId銆佸瘑閽ヤ箣绫� + * 涓庢湇鍔″櫒鐩稿叧鐨� + * */ + public static final String GATEWAY_EDIT_REMOTE = "/user/%s/custom/gateway/remote/edit"; + + /* + * 缃戝叧鎭㈠鍑哄満璁剧疆鍛戒护 + * */ + public static final String GATEWAY_INITIALIZE_REMOTE = "/user/%s/custom/gateway/initialize"; + + /* + * 缃戝叧缂栬緫鍛戒护 + * 涓庢湇鍔″櫒鏃犲叧鐨� + * */ + public static final String GATEWAY_EDIT_LOCAL = "/user/%s/custom/gateway/edit"; + + /** + * 璁剧疆缃戝叧鍏ョ綉妯″紡 + * 鍏ョ綉浠庢満璁惧浣跨敤 + * 浠庣綉鍏炽�佺孩澶栧疂绛夌綉缁滆澶� + */ + public static final String GATEWAY_AUTH = "/user/%s/custom/device/auth_gateway"; + //鑾峰彇缃戝叧淇℃伅 + public static final String GATEWAY_GET = "/user/%s/custom/gateway/remote/get"; + + //缃戝叧骞挎挱鍏ョ綉鎸囦护 + public static final String GATEWAY_AUTH_BROADCAST = "/user/all/custom/device/network_access/broadcast"; + + //璁惧鍏ョ綉鍜岃璇� + public static final String DEIVCE_AUTH_REQUEST = "/user/all/custom/device/network_access/request"; + + //璁惧鍏ョ綉鍜岃璇佸搷搴� + public static final String DEIVCE_AUTH_REQUEST_REPLY = "/user/all/custom/device/network_access/request_reply"; + + /** + * 鎼滅储缃戝叧 + */ + public static final String GATEWAY_SEARCH = "/user/all/custom/gateway/search"; + + /** + * 鎼滅储缃戝叧鍝嶅簲 + */ + public static final String GATEWAY_SEARCH_REPLY = "/user/all/custom/gateway/search_reply"; + + //缃戝叧璇︾粏淇℃伅鑾峰彇s=gw_id + public static final String GATEWAY_INFO = "/user/%s/custom/gateway/get"; + + //鑾峰彇鐗╃悊璁惧鍒楄〃 + public static final String GET_DEVICE_LIST = "/user/%s/custom/device/list/get"; + + //鑾峰彇鐗╃悊璁惧鍒楄〃鍝嶅簲 + public static final String GET_DEVICE_LIST_REPLY = "/user/%s/custom/device/list/get_reply"; + + //鑾峰彇鍔熻兘鍒楄〃 + public static final String GET_FUNCTION_LIST = "/user/%s/custom/function/list/get"; + /** + * 缂栬緫sid + */ + public static final String EDIT_FUNCTION = "/user/%S/custom/function/edit"; + + //鑾峰彇鍔熻兘鍝嶅簲 + public static final String GET_FUNCTION_LIST_REPLY = "/user/%s/custom/function/list/get_reply"; + + //鍔熻兘灞炴�ц鍙� + public static final String GET_FUNCTION_ATTRIBUTE = "/user/%s/custom/function/attribute/get"; + + //鍔熻兘灞炴�у搷搴� + public static final String GET_FUNCTION_ATTRIBUTE_REPLY = "/user/%s/custom/function/attribute/get_reply"; + + //鎺у埗 + public static final String PROPERTY_DOWN = "/base/%s/thing/property/down"; + + //鎺у埗鍝嶅簲 + public static final String PROPERTY_DOWN_REPLY = "/base/%s/thing/property/down_reply"; + + //鐘舵�佷笂鎶� + public static final String PROPERTY_UP = "/base/%s/thing/property/up"; + + //鐘舵�佷笂鎶ュ搷搴� + public static final String PROPERTY_UP_REPLY = "/base/%s/thing/property/up_reply"; + + //璇诲彇鐘舵�� + public static final String PROPERTY_READ = "/base/%s/thing/property/read"; + + //璇诲彇鐘舵�佸搷搴� + public static final String PROPERTY_READ_REPLY = "/base/%s/thing/property/read_reply"; + + //鏇存敼缃戝叧澶囨敞鍚� + public static final String GATEWAY_RENAME = "/user/%s/custom/gateway/edit"; + + //8.1鑾峰彇鍦烘櫙鍒楄〃 + public static final String SCENE_LIST_GET = "/user/%s/custom/scene/list/get"; + + //8.2鑾峰彇鍦烘櫙 + public static final String SCENE_GET = "/user/%s/custom/scene/get"; + + //8.3鎵ц鍦烘櫙 + public static final String SCENE_CONTROL = "/user/%s/custom/scene/execute"; + + //8.4鍦烘櫙澧炲姞 + public static final String CREATE_SCENE = "/user/%s/custom/scene/add"; + + //8.5鍦烘櫙缂栬緫 + public static final String SCENE_EDIT = "/user/%s/custom/scene/edit"; + + //8.6鍦烘櫙鍒犻櫎 + public static final String SCENE_DELETE = "/user/%s/custom/scene/delete"; + + //9.1 鎴块棿淇℃伅鍒楄〃鑾峰彇 + public static final String ROOM_LIST_GET = "/user/%s/custom/room/list/get"; + + //9.2 鎴块棿淇℃伅娣诲姞锛堝閲忥級 + public static final String ROOM_ADD = "/user/%s/custom/room/add"; + + //9.2.1 鎴块棿淇℃伅娣诲姞锛堝叏閲忥級 + public static final String ROOM_COVER_ADD = "/user/%s/custom/room/cover/add"; + + //9.3 鎴块棿淇℃伅缂栬緫 + public static final String ROOM_EDIT = "/user/%s/custom/room/edit"; + + //9.4 鎴块棿淇℃伅鍒犻櫎 + public static final String ROOM_DELETE = "/user/%s/custom/room/delete"; + + //9.5 鎴块棿缁戝畾鍏崇郴鍒楄〃鑾峰彇 + public static final String ROOM_BIND_LIST_GET = "/user/%s/custom/room/bind/list/get"; + + //9.6 鎴块棿缁戝畾鍏崇郴娣诲姞锛堝閲忥級 + public static final String ROOM_BIND_ADD = "/user/%s/custom/room/bind/add"; + + //9.6.1 鎴块棿缁戝畾鍏崇郴娣诲姞(鍏ㄩ噺) + public static final String ROOM_BIND_COVER_ADD = "/user/%s/custom/room/bind/cover/add"; + + //9.7 鎴块棿缁戝畾鍏崇郴鍒犻櫎 + public static final String ROOM_BIND_DELETE = "/user/%s/custom/room/bind/delete"; + + //10.1 鑷姩鍖栧垪琛ㄨ幏鍙� + public static final String LOGIC_LIST_GET = "/user/%s/custom/logic/list/get"; + + //10.2 鑷姩鍖栨墜鍔ㄦ墽琛� + public static final String LOGIC_execute = "/user/%s/custom/logic/execute"; + + //10.3 鑷姩鍖栬幏鍙� 鍒楄〃涓�娆℃�ц鍏� + public static final String LOGIC_GET = "/user/%s/custom/logic/get"; + + //10.4 鑷姩鍖栨柊澧�/缂栬緫 + public static final String LOGIC_EDIT = "/user/%s/custom/logic/edit"; + + //10.5 鑷姩鍖栧垹闄� + public static final String LOGIC_DELETE = "/user/%s/custom/logic/delete"; + + //10.6 鑷姩鍖栧惎鐢ㄧ鐢� + public static final String LOGIC_ENABLE_EDIT = "/user/%s/custom/logic/enable/edit"; + + //10.7 鑷姩鍖栫姸鎬佷笂鎶� 鎵ц缁撴灉銆佹湰鍦板惎鐢ㄧ鐢ㄧ姸鎬佷笂鎶� + public static final String LOGIC_STATUS_UP = "/user/%s/custom/logic/status/up"; + + //11.1 瀹夐槻鍒楄〃鑾峰彇 + public static final String SECURITY_LIST_GET = "/user/%s/custom/security/list/get"; + + //11.2 瀹夐槻鑾峰彇 + public static final String SECURITY_GET = "/user/%s/custom/security/get"; + + //11.3 瀹夐槻鏂板/缂栬緫 + public static final String SECURITY_EDIT= "/user/%s/custom/security/edit"; + + //11.4 瀹夐槻鍒犻櫎 + public static final String SECURITY_DELETE = "/user/%s/custom/security/delete"; + + //11.5 甯冮槻璁剧疆 + public static final String SECURITY_STATUS_SET = "/user/%s/custom/security/status/set"; + + //11.6 瀹夐槻闃插尯鐘舵�佽鍙� + public static final String SECURITY_STATUS_GET = "/user/%s/custom/security/status/get"; + + //11.7 瀹夐槻闃插尯鎶ヨ鐘舵�佷笂鎶� + public static final String SECURITY_STATUS_UP = "/user/%s/custom/security/status/up"; + + //11.8 瀹夐槻Bypass璇诲彇 + public static final String SECURITY_BYPASS_GET = "/user/%s/custom/security/bypass/get"; + + //11.9 瀹夐槻Bypass璁剧疆 + public static final String SECURITY_BYPASS_SET = "/user/%s/custom/security/bypass/set"; + + /** + * 璁惧杩炴帴TCP涔嬪墠骞挎挱 + */ + public static final String BROADCAST="/user/all/custom/gateway/broadcast"; + + /** + * 涓荤綉鍏冲洖澶� + */ + public static final String BROADCAST_REPLY="/user/all/custom/gateway/broadcast_reply"; + + /** + * sid缁戝畾鎴块棿 + */ + public static final String SID_BIND_ROOM = "/user/%s/custom/room/bind/add"; + + /** + * sid瑙g粦鎴块棿 + */ + public static final String SID_DELETE_ROOM = "/user/%s/custom/room/bind/delete"; + + /** + * 蹇冭烦妫�娴� + */ + public static final String HEARTBEAT="/user/%s/custom/gateway/heartbeat"; +// public static final String HEARTBEAT="/user/%s/custom/gateway1/qqheartbeat"; + /** + * 蹇冭烦妫�娴嬪洖澶� + */ + public static final String HEARTBEAT_REPLY="/user/%s/custom/gateway/heartbeat_reply"; +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java new file mode 100644 index 0000000..a8315f1 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java @@ -0,0 +1,226 @@ +package com.hdl.sdk.link.common.event; + + + + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; + + +/** + * Created by Tong on 2021/9/22. + * 浜嬩欢鍒嗗彂 + */ +public class EventDispatcher { + + private static final List<EventListener> ALL_TOPICS_EVENT = new ArrayList<>();//鎵�鏈変富棰樻秷鎭� + + private static final Map<String, List<EventListener>> EVENT = new HashMap<>(); + + private static final Map<EventListener, Integer> TYPE = new HashMap<>(); + + private static final int MAIN_TYPE = 0; + private static final int IO_TYPE = 1; + + private static final ExecutorService ioThread = ThreadToolUtils.getInstance().newFixedThreadPool(2); + + private EventDispatcher() { + } + + private static class SingletonInstance { + private static final EventDispatcher INSTANCE = new EventDispatcher(); + } + + public static EventDispatcher getInstance() { + return SingletonInstance.INSTANCE; + } + + public synchronized void register(String tag, EventListener listener) { + if(TYPE.containsKey(listener)){ + return; + } + if (!EVENT.containsKey(tag)) { + EVENT.put(tag, new ArrayList<>()); + } + List<EventListener> events = EVENT.get(tag); + if (events != null && !events.contains(listener)) { + events.add(listener); + LogUtils.i(String.format("澧炲姞璁㈤槄涓婚:%s,褰撳墠鍥炶皟鏁伴噺:%s",tag,events.size())); + } + TYPE.put(listener, MAIN_TYPE); + } + + public synchronized void registerIo(String tag, EventListener listener) { + if(TYPE.containsKey(listener)){ + return; + } + if (!EVENT.containsKey(tag)) { + EVENT.put(tag, new ArrayList<>()); + } + List<EventListener> events = EVENT.get(tag); + if (events != null && !events.contains(listener)) { + events.add(listener); + } + TYPE.put(listener, IO_TYPE); + } + + public synchronized void remove(Object tag) { + ioThread.execute(new Runnable() { + @Override + public void run() { + try { + if (EVENT.containsKey(tag)) { + List<EventListener> list = EVENT.get(tag); + for (EventListener eventListener : list) { + TYPE.remove(eventListener); + } + EVENT.remove(tag); + } + } catch (Exception ignored) { + + } + + } + }); + } + + public synchronized void remove(Object tag, EventListener listener) { + ioThread.execute(new Runnable() { + @Override + public void run() { + try { + if (EVENT.containsKey(tag)) { + List<EventListener> ev = EVENT.get(tag); + if (ev != null && !ev.isEmpty()) { + TYPE.remove(listener); + ev.remove(listener); + LogUtils.i(String.format("绉婚櫎璁㈤槄涓婚:%s,褰撳墠鍥炶皟鏁伴噺:%s",tag,ev.size())); + } + } + } catch (Exception ignored) { + + } + + } + }); + } + + /** + * 涓や釜涓婚鏄惁鍖归厤 + * @param desString 瀛楀吀涓殑涓婚 + * @param sourceString 鎺ユ敹鍒扮殑涓婚 + * @return + */ + boolean isMatch(String desString,String sourceString){ + String []des=desString.split("/"); + String []source=sourceString.split("/"); + if(des.length!=source.length){ + return false; + } + for(int i=0;i<des.length;i++) { + if (!(des[i].equals(source[i]) || des[i].equals("+"))) { + return false; + } + } + return true; + } + + /** + * 浜嬩欢鍒嗗彂鍣紝鍒嗗彂鎵�鏈夊湪鎺ュ彛鍒楄〃涓殑浜嬩欢 + * @param topicTag + * @param o + */ + public synchronized void post(String topicTag, Object o) { + for (String key : EVENT.keySet()) { + if (!isMatch(key, topicTag)) { + continue; + } + List<EventListener> list = EVENT.get(key); + if (list != null && !list.isEmpty()) { + for (EventListener listener : list) { +// ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { +// @Override +// public void run() { + if (listener != null) { + listener.onMessage(o); + } +// } +// }); + } + } + } + //鎵�鏈変富棰樼殑Listener閫氱煡 + if (ALL_TOPICS_EVENT == null || ALL_TOPICS_EVENT.isEmpty()) { + return; + } + //寮�鍙戝垎鍙戜簨浠� + for (EventListener listener : ALL_TOPICS_EVENT) { +// ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { +// @Override +// public void run() { + if (listener != null) { + listener.onMessage(o); + } +// } +// }); + } + + } + + /** + * 鏂囦欢鍙戦�侀�氱煡 wxr 2022-03-08 15:38:59 + */ + public synchronized void filePost() { + //TODO + } + /** + * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * @param listener + */ + public synchronized void registerAllTopicsListener(EventListener listener) { + if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.contains(listener)) { + ALL_TOPICS_EVENT.add(listener); + } + TYPE.put(listener, MAIN_TYPE); + } + + /** + * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * @param listener + */ + public synchronized void removeAllTopicsListener(EventListener listener) { + ioThread.execute(new Runnable() { + @Override + public void run() { + try { + if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.isEmpty()) { + TYPE.remove(listener); + ALL_TOPICS_EVENT.remove(listener); + } + } catch (Exception ignored) { + + } + + } + }); + } + + public synchronized void clear() { + ALL_TOPICS_EVENT.clear(); + EVENT.clear(); + TYPE.clear(); + } + + public synchronized void release() { + clear(); + ioThread.shutdownNow(); + } + + +} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventListener.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java similarity index 73% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventListener.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java index eb82740..e2b3cdf 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventListener.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common.event; +package com.hdl.sdk.link.common.event; /** * Created by Tong on 2021/9/22. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java new file mode 100644 index 0000000..e2e2b91 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java @@ -0,0 +1,60 @@ +package com.hdl.sdk.link.common.exception; + +import com.hdl.sdk.link.HDLLinkLocalSdk; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : HDLError + */ +public enum HDLLinkCode { + HDL_DATA_ERROR(-2000, isZh() == true ? "鍙傛暟寮傚父" : "Parameter exception"), + HDL_DATA_NULL_ERROR(-2001, isZh() == true ? "鍙傛暟涓嶈兘涓虹┖" : "Parameter cannot be empty"), + HDL_AUTH_ERROR(-2002, isZh() == true ? "璁よ瘉澶辫触" : "Authentication failed"), + HDL_SEND_ERROR(-2003, isZh() == true ? "鍙戦�佸け璐�" : "fail in send"), + HDL_TIMEOUT_ERROR(-2004, isZh() == true ? "瓒呮椂" : "timeout"), + HDL_UNAUTHORIZED_ERROR(-2005, isZh() == true ? "鏈璇侊紝璇峰厛璁よ瘉" : "Not certified, please authenticate first"), + HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED(-2006, isZh() == true ? "璁よ瘉澶辫触锛岀綉鍏虫湭娉ㄥ唽鍒颁簯绔�" : "Authentication failed. The gateway is not registered to the cloud"), + HDL_SEARCH_GATEWAY_TIMEOUT_ERROR(-2007, isZh() == true ? "鎼滅储缃戝叧澶辫触锛岃秴鏃�" : "Failed to search gateway, timeout"), + HDL_AUTH_MAC_KEY_ERROR(-2008, isZh() == true ? "璁よ瘉澶辫触锛岃MAC瀵瑰簲鐨勮澶囧瘑閽ヤ笉瀛樺湪" : "Authentication failed. The device key corresponding to the MAC does not exist"), + HDL_DATA_PARSING_ERROR(-2009, isZh() == true ? "鏁版嵁瑙f瀽寮傚父" : "Data parsing error"), + HDL_GET_DEVICE_LIST_ERROR(-2100, isZh() == true ? "鑾峰彇璁惧鍒楄〃澶辫触" : "Failed to get device list"), + HDL_GET_FUNCTION_LIST_ERROR(-2101, isZh() == true ? "鑾峰彇鍔熻兘鍒楄〃澶辫触" : "Failed to get function list"), + HDL_GET_FUNCTION_PROPERTIES_ERROR(-2102, isZh() == true ? "鑾峰彇鍔熻兘灞炴�уけ璐�" : "Failed to get function attribute"), + HDL_CONTROL_FAILURE_ERROR(-2103, isZh() == true ? "鎺у埗澶辫触" : "Control failure"), + HDL_GET_GATEWAY_FAILURE_ERROR(-2104, isZh() == true ? "鑾峰彇缃戝叧鍒楄〃澶辫触" : "Failed to get gateway list"), + HDL_GET_Zigbee_FAILURE_ERROR(-2105, isZh() == true ? "鍙戦�佽秴鏃讹紝缃戝叧鏃犲搷搴�" : "Sending timeout, no response from gateway"), + HDL_GATEWAY_NOT_EXIST(-2106, isZh() == true ? "缃戝叧涓嶅瓨鍦�" : "Gateway does not exist"), + HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR(-2107, isZh() == true ? "鑾峰彇鍘熺敓璁惧鍒楄〃澶辫触" : "Failed to get the device list"); + + private String msg; + private int code; + + private HDLLinkCode(int code, String msg) { + this.msg = msg; + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + static boolean isZh() { + if ("zh".equals(HDLLinkLocalSdk.getInstance().getLanguage())) + return true; + else + return false; + } +} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkException.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java similarity index 93% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkException.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java index a8fd194..0e36635 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkException.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common.exception; +package com.hdl.sdk.link.common.exception; /** * Created by Tong on 2021/11/11. @@ -37,7 +37,8 @@ this.code = code; } - public String getMsg() { + public + String getMsg() { return msg; } diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java new file mode 100644 index 0000000..e4f6a9d --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java @@ -0,0 +1,243 @@ +package com.hdl.sdk.link.common.utils; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * Created by Tong on 2021/9/23. + */ +public class ByteUtils { + + public static byte[] toByteArray(List<Byte> list) { + Byte[] temps = list.toArray(new Byte[0]); + byte[] result = new byte[temps.length]; + for (int i = 0; i < result.length; i++) { + result[i] = temps[i]; + } + return result; + + } + + + public static List<Byte> toByteList(byte[] bytes) { + final List<Byte> list = new ArrayList<>(); + for (byte aByte : bytes) { + list.add(aByte); + } + return list; + + } + + public static byte[] getRangeBytes(List<Byte> list, int start, int end) { + Byte[] temps = Arrays.copyOfRange(list.toArray(new Byte[0]), start, end); + byte[] result = new byte[temps.length]; + for (int i = 0; i < temps.length; i++) { + result[i] = temps[i]; + } + return result; + + } + + public static byte[] copyBytes(byte bytes[], int index, int length) { + byte[] result = new byte[length]; + for (int i = 0; i < result.length; i++) { + result[i] = bytes[index + i]; + } + return result; + } + + /** + * 鎷兼帴byte + */ + public static byte[] concatBytes(byte[] bt1, byte[] bt2) { + if (bt1 == null) { + return bt2; + } + if (bt2 == null) { + return bt1; + } + byte[] bt3 = new byte[bt1.length + bt2.length]; + System.arraycopy(bt1, 0, bt3, 0, bt1.length); + System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length); + return bt3; + } + + + public boolean endWith(Byte[] src, byte[] target) { + if (src.length < target.length) { + return false; + } + for (int i = 0; i < target.length; i++) { + if (target[target.length - i - 1] != src[src.length - i - 1]) { + return false; + } + } + return true; + } + + + public static int byteIndexOf(byte[] searched, byte[] find, int start) { + boolean matched; + int end = find.length - 1; + int skip = 0; + for (int index = start; index <= searched.length - find.length; ++index) { + matched = true; + if (find[0] != searched[index] || find[end] != searched[index + end]) continue; + else skip++; + if (end > 10) + if (find[skip] != searched[index + skip] || find[end - skip] != searched[index + end - skip]) + continue; + else skip++; + for (int subIndex = skip; subIndex < find.length - skip; ++subIndex) { + if (find[subIndex] != searched[index + subIndex]) { + matched = false; + break; + } + } + if (matched) { + return index; + } + } + return -1; + + } + + public static int getByteIndexOf(byte[] sources, byte[] src) { + return getByteIndexOf(sources, src, 0, sources.length); + } + + //鍒ゆ柇涓�涓猙yte鏁板�煎湪鍙﹀涓�涓猙yte鏁扮粍涓搴旂殑娓告爣鍊� + public static int getByteIndexOf(byte[] sources, byte[] src, int startIndex) { + return getByteIndexOf(sources, src, startIndex, sources.length); + } + + + //鍒ゆ柇涓�涓猙yte鏁板�煎湪鍙﹀涓�涓猙yte鏁扮粍涓搴旂殑娓告爣鍊硷紝鎸囧畾寮�濮嬬殑娓告爣鍜岀粨鏉熺殑娓告爣浣嶇疆 + public static int getByteIndexOf(byte[] sources, byte[] src, int startIndex, int endIndex) { + + if (sources == null || src == null || sources.length == 0 || src.length == 0) { + return -1; + } + + if (endIndex > sources.length) { + endIndex = sources.length; + } + + int i, j; + for (i = startIndex; i < endIndex; i++) { + if (sources[i] == src[0] && i + src.length < endIndex) { + for (j = 1; j < src.length; j++) { + if (sources[i + j] != src[j]) { + break; + } + } + + if (j == src.length) { + return i; + } + } + } + return -1; + } + + /** + * 瀛楃涓瞭o Bytes + * + * @param str 瀛楃涓� + * @return + */ + public static byte[] stringToBytes(String str) { + try { + // 浣跨敤鎸囧畾鐨勫瓧绗﹂泦灏嗘瀛楃涓茬紪鐮佷负byte搴忓垪骞跺瓨鍒颁竴涓猙yte鏁扮粍涓� + return str.getBytes("utf-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new byte[]{}; + } + + public static String byte2hex(byte[] bytes) { + StringBuilder sb = new StringBuilder(); + String tmp = null; + for (byte b : bytes) { + //灏嗘瘡涓瓧鑺備笌0xFF杩涜涓庤繍绠楋紝鐒跺悗杞寲涓�10杩涘埗锛岀劧鍚庡�熷姪浜嶪nteger鍐嶈浆鍖栦负16杩涘埗 + tmp = Integer.toHexString(0xFF & b); + if (tmp.length() == 1) { + tmp = "0" + tmp; + } + sb.append(tmp + " "); + } + return sb.toString(); + } + + + public static int bytes2int(byte[] bytes) { + return bytes[3] & 0xFF | // + (bytes[2] & 0xFF) << 8 | // + (bytes[1] & 0xFF) << 16 | // + (bytes[0] & 0xFF) << 24; // + } + + + public static byte[] intToByteArray(int i) { + byte[] result = new byte[4]; + result[0] = (byte) ((i >> 24) & 0xFF); + result[1] = (byte) ((i >> 16) & 0xFF); + result[2] = (byte) ((i >> 8) & 0xFF); + result[3] = (byte) (i & 0xFF); + return result; + } + + public static int byteArrayToInt(byte[] b) { + 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/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java new file mode 100644 index 0000000..2b8e659 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java @@ -0,0 +1,20 @@ +package com.hdl.sdk.link.common.utils; + +import java.util.UUID; + +/** + * Created by Tong on 2021/10/8. + */ +public class IdUtils { + public static String getUUId() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } + + /** + * Uid 鍒楄〃鍒涘缓浣跨敤 + * @return + */ + public static String getUUIdWithBar() { + return UUID.randomUUID().toString(); + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java new file mode 100644 index 0000000..b8ed231 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java @@ -0,0 +1,63 @@ +package com.hdl.sdk.link.common.utils; + + +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +/** + * Created by Tong on 2021/9/27. + */ +public class IpUtils { + + /** + * @return 骞挎挱鍦板潃 + */ + public static String getBroadcastAddress() { + try { + for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); + niEnum.hasMoreElements(); ) { + NetworkInterface ni = niEnum.nextElement(); + if (!ni.isLoopback()) { + for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { + if (interfaceAddress.getBroadcast() != null) { + return interfaceAddress.getBroadcast().toString().substring(1); + } + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return "255.255.255.255"; + } + + public static boolean isLocalIpAddress(String ipAddress) { + try { + for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); + niEnum.hasMoreElements(); ) { + NetworkInterface ni = niEnum.nextElement(); + for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { + if (ipAddress.equals(interfaceAddress.getAddress().getHostAddress())) { + return true; + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return false; + } + + + + private static String intToIp(int i) { + + return (i & 0xFF) + "." + + ((i >> 8) & 0xFF) + "." + + ((i >> 16) & 0xFF) + "." + + (i >> 24 & 0xFF); + } +} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/LogUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java similarity index 97% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/LogUtils.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java index 8f7945d..fdf6995 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/LogUtils.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common.utils; +package com.hdl.sdk.link.common.utils; /** * Created by Tong on 2021/9/23. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java new file mode 100644 index 0000000..ba31063 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java @@ -0,0 +1,152 @@ +package com.hdl.sdk.link.common.utils; + + + + + +import com.hdl.sdk.link.HDLLinkLocalSdk; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +/** + * Created by Tong on 2021/9/28. + */ +public class SPUtils { +// +// +// +// private static final String APP_PREFERENCES_KEY = "profile"; +// private static final SharedPreferences PREFERENCES = +// HDLLinkLocalSdk.getInstance().getContext().getApplicationContext().getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); +// +// private static SharedPreferences getAppPreference() { +// return PREFERENCES; +// } +// +// +// //======閫氱敤瀛樺偍======== +// public static void put( final String key, final String value) { +// getAppPreference().edit().putString(key, value).apply(); +// } +// +// +// public static String getString( final String key) { +// return getString(key, ""); +// } +// +// +// public static String getString( final String key, final String defaultValue) { +// return getAppPreference().getString(key, defaultValue); +// } +// +// +// public static void put( final String key, final int value) { +// put(key, value, false); +// } +// +// +// public static void put( final String key, final int value, final boolean isCommit) { +// getAppPreference().edit().putInt(key, value).apply(); +// } +// +// +// public static int getInt( final String key) { +// return getInt(key, -1); +// } +// +// +// public static int getInt( final String key, final int defaultValue) { +// return getAppPreference().getInt(key, defaultValue); +// } +// +// +// public static void put( final String key, final long value) { +// getAppPreference().edit().putLong(key, value).apply(); +// } +// +// +// public static long getLong( final String key) { +// return getLong(key, -1L); +// } +// +// +// public static long getLong( final String key, final long defaultValue) { +// return getAppPreference().getLong(key, defaultValue); +// } +// +// +// public static void put( final String key, final float value) { +// getAppPreference().edit().putFloat(key, value).apply(); +// } +// +// +// public static float getFloat( final String key) { +// return getFloat(key, -1f); +// } +// +// +// public static float getFloat( final String key, final float defaultValue) { +// return getAppPreference().getFloat(key, defaultValue); +// } +// +// +// public static void put( final String key, final boolean value) { +// getAppPreference().edit().putBoolean(key, value).apply(); +// } +// +// +// public static boolean getBoolean( final String key) { +// return getBoolean(key, false); +// } +// +// +// public static boolean getBoolean( final String key, final boolean defaultValue) { +// return getAppPreference().getBoolean(key, defaultValue); +// } +// +// +// public static void put( final String key, +// final Set<String> value +// ) { +// +// getAppPreference().edit().putStringSet(key, value).apply(); +// +// } +// +// +// public static Set<String> getStringSet( final String key) { +// return getStringSet(key, Collections.<String>emptySet()); +// } +// +// +// public static Set<String> getStringSet( final String key, +// final Set<String> defaultValue) { +// return getAppPreference().getStringSet(key, defaultValue); +// } +// +// +// public static Map<String, ?> getAll() { +// return getAppPreference().getAll(); +// } +// +// +// public static boolean contains( final String key) { +// return getAppPreference().contains(key); +// } +// +// +// public static void remove( final String key) { +// getAppPreference().edit().remove(key).apply(); +// } +// +// public static void clear() { +// getAppPreference() +// .edit() +// .clear() +// .apply(); +// } + + +} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/TextUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/TextUtils.java similarity index 77% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/TextUtils.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/TextUtils.java index aec0aa0..c31cbb4 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/TextUtils.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/TextUtils.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common.utils; +package com.hdl.sdk.link.common.utils; public class TextUtils { diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ThreadToolUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java similarity index 79% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ThreadToolUtils.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java index 6a28c1e..f0693ee 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ThreadToolUtils.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java @@ -1,4 +1,5 @@ -package com.hdl.sdk.common.utils; +package com.hdl.sdk.link.common.utils; + import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -17,10 +18,12 @@ private ThreadToolUtils() { } - private static final ThreadToolUtils instance = new ThreadToolUtils(); + private static class SingletonInstance { + private static final ThreadToolUtils INSTANCE = new ThreadToolUtils(); + } public static ThreadToolUtils getInstance() { - return instance; + return SingletonInstance.INSTANCE; } @@ -56,13 +59,12 @@ return Executors.newCachedThreadPool(); } - /** - * 鍒囨崲鍥炰富绾跨▼ - */ - public void runOnUiThread(Runnable run) { -// uiHandler.post(run); - Thread thread = new Thread(run); - thread.start(); - } +// /** +// * 鍒囨崲鍥炰富绾跨▼ +// */ +// public void runOnUiThread(Runnable run) { +// uiHandler.post(run); +// } + } diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/GsonConvert.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java similarity index 89% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/GsonConvert.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java index f38cfa9..4ba481b 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/GsonConvert.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.common.utils.gson; +package com.hdl.sdk.link.common.utils.gson; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -34,6 +34,10 @@ return gson; } + public static <T> T copyProperties(Object o, Type type) { + return getGson().fromJson(getGson().toJson(o), type); + } + private static class StringTypeAdapter implements JsonSerializer<String>, JsonDeserializer<String> { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/ParameterizedTypeImpl.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java similarity index 93% rename from HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/ParameterizedTypeImpl.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java index e15a526..e699267 100644 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/gson/ParameterizedTypeImpl.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java @@ -1,4 +1,7 @@ -package com.hdl.sdk.common.utils.gson; +package com.hdl.sdk.link.common.utils.gson; + + + import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -22,12 +25,14 @@ return new ParameterizedTypeImpl(rawType, actualTypeArguments, null); } + @Override public Type[] getActualTypeArguments() { return actualTypeArguments; } + @Override public Type getRawType() { return rawType; diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java new file mode 100644 index 0000000..03e7995 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java @@ -0,0 +1,44 @@ +package com.hdl.sdk.link.core.bean; + + +/** + * Created by Tong on 2021/9/29. + */ +public class FileRequest extends LinkRequest { + + private String fileId; + private Integer command; + private byte []fileData; + +// private static int info_number; + public FileRequest(String topic, String data, boolean encrypt) { + super(topic, data, encrypt); + } + + + public FileRequest(String fileId, Integer command, byte []fileData,boolean encrypt) { + this.fileId = fileId; + this.command = command; + this.fileData = fileData; +// super.setEncrypt(encrypt); + super.setEncrypt(false); +// info_number++; +// byte[] headBytes = ("hex" + info_number).getBytes(); +// byte[] sendDataBytes = ByteUtils.concatBytes(headBytes, fileData); + super.setData(fileData); + } + + @Override + public byte [] getSendBytes() { + return getData(); + } + + public String getTopic() { + return fileId + "_" + command; + } + + public String getAckTopic() { + return fileId + "_" + ++command; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java new file mode 100644 index 0000000..eb0f487 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java @@ -0,0 +1,50 @@ +package com.hdl.sdk.link.core.bean; + +/** + * Created by hxb on 2022/8/4. + */ +public class LinkPacket { + /** + * 涓婚鍐呭 + */ + private String topic; + /** + * 鍘熷鎺ユ敹鐨勬暟鎹紝鍙兘闇�瑕佽В瀵� + */ + private byte []body; + /** + * ip鍦板潃 + */ + private String ipAddress; + + public LinkPacket(String topic, byte[] body, String ipAddress) { + this.topic = topic; + this.body = body; + this.ipAddress = ipAddress; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public byte[] getBody() { + return body; + } + + public void setBody(byte[] body) { + this.body = body; + } + + public String isIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java new file mode 100644 index 0000000..5c4b1a7 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java @@ -0,0 +1,104 @@ +package com.hdl.sdk.link.core.bean; + + +import com.hdl.sdk.link.common.utils.ByteUtils; +import com.hdl.sdk.link.common.utils.TextUtils; + + +/** + * Created by Tong on 2021/9/29. + */ +public class LinkRequest { + private String topic; + protected byte []data; + private int length=0; + + private boolean encrypt; + + + public LinkRequest(String topic, String data, boolean encrypt) { + this.topic = topic; + setData(data); + this.encrypt = encrypt; + } + public LinkRequest(String topic, byte []data, boolean encrypt) { + this.topic = topic; + setData(data); + this.encrypt = encrypt; + } + + protected LinkRequest(){} + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public byte[] getData() { + return data; + } + + public void setData(String data) { + if (!TextUtils.isEmpty(data)) { + this.data = ByteUtils.stringToBytes(data); + setLength(this.data.length); + } + } + + public void setData(byte []data) { + this.data = data; + if(data!=null){ + setLength(data.length); + } + } + + public int getLength() { + return length; + } + + private void setLength(int length) { + this.length = length; + } + + /** + * 鍔犲瘑鏍囪瘑 + * + * @return + */ + public boolean isEncrypt() { + return encrypt; + } + + /** + * 鍔犲瘑鏍囪瘑 + * + * @param encrypt + */ + public void setEncrypt(boolean encrypt) { + this.encrypt = encrypt; + } + + + public byte [] getSendBytes() { + try { + String header = "Topic:" + + getTopic() + + "\r\n" + + "Length:" + + getLength() + + "\r\n\r\n"; + return ByteUtils.concatBytes(header.getBytes("utf-8"), getData()); + } catch (Exception e) { + return new byte[]{}; + } + } + + + private int getBytesLength(String str) { + return ByteUtils.stringToBytes(str).length; + } + +} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java similarity index 67% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkResponse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java index 6846097..9b014ba 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkResponse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java @@ -1,7 +1,8 @@ -package com.hdl.sdk.connect.bean; +package com.hdl.sdk.link.core.bean; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.gson.GsonConvert; + +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; import java.io.Serializable; @@ -13,16 +14,7 @@ private String topic; private String data; private int length; - - public String getSource_ipAddress() { - return source_ipAddress; - } - - public void setSource_ipAddress(String source_ipAddress) { - this.source_ipAddress = source_ipAddress; - } - - public String source_ipAddress; + private byte []byteData; public String getTopic() { return topic; @@ -36,9 +28,20 @@ return data; } + public void setByteData(byte []data) { + this.byteData = data; + this.data = new String(data); + this.length=data.length; + } + + public byte []getByteData() { + return byteData; + } + public void setData(String data) { this.data = data; if (!TextUtils.isEmpty(data)) { + this.byteData = data.getBytes(); setLength(data.length()); } else { setLength(0); diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java new file mode 100644 index 0000000..7dca2a8 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java @@ -0,0 +1,87 @@ +package com.hdl.sdk.link.core.bean; + + +import com.hdl.sdk.link.common.utils.gson.GsonConvert; + +import java.io.Serializable; + +/** + * Created by hxb on 2021/12/19. + */ +public class ZigbeeResponse implements Serializable { + + /** + * 鍘熺敓涓婚 + */ + private String topic; + /** + * 鍘熺敓鏁版嵁 + */ + private String data; + + /** + * 缃戝叧Oid + */ + private String oid; + + + /** + * 鑾峰彇鍘熺敓涓婚 + * + * @return + */ + public String getTopic() { + return topic; + } + + /** + * 璁剧疆鍘熺敓涓婚 + * + * @param topic + */ + public void setTopic(String topic) { + this.topic = topic; + } + + /** + * 鑾峰彇鍘熺敓鏁版嵁 + * + * @return + */ + public String getData() { + return data; + } + + /** + * 璁剧疆鍘熺敓鏁版嵁 + * + * @param data + */ + public void setData(String data) { + this.data = data; + } + + /** + * 鑾峰彇缃戝叧涓昏淇℃伅锛屽彲鑳芥槸oid锛屽彲鑳芥槸缃戝叧Id锛屽彲鑳芥槸mac + * + * @return + */ + public String getOid() { + return oid; + } + + /** + * 璁剧疆Oid + * + * @param + */ + public void setOid(String oid) { + this.oid = oid; + } + + + @Override + public String toString() { + return GsonConvert.getGson().toJson(this); + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java new file mode 100644 index 0000000..77177f7 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java @@ -0,0 +1,289 @@ +package com.hdl.sdk.link.core.bean.gateway; + + +import com.hdl.sdk.link.common.utils.TextUtils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by hxb on 2021/12/15. + * 缃戝叧瀵硅薄 + */ +public class GatewayBean implements Serializable { + + + + /** + * true-鍦ㄧ嚎 + * false-绂荤嚎 + */ + private boolean online=true; + /** + * 缃戝叧鍨嬪彿 + */ + private String device_model; + /** + * 缃戝叧澶囨敞 + */ + private String device_name; + /** + * 缃戝叧Mac + */ + private String device_mac; + /** + * 缃戝叧Id + */ + private String gatewayId; + /** + * 缃戝叧绫诲瀷 + */ + private String gatewayType; + private String gateway_type; + /** + * 缃戝叧oid + */ + private String oid; + /** + * IP鍦板潃 + */ + private String ip_address; + /** + * 杩炴帴鐨勭綉鍏崇被鍨� LAN WIFI + */ + private String access_mode; + /** + * 鏄惁涓荤綉鍏� true false + */ + private String master; + /** + * 鏄惁鍔犲瘑 + */ + private boolean isLocalEncrypt; + /** + * 鏄惁鏈湴缃戝叧 + */ + private boolean isLocalGateWay; + /** + * 浣忓畢Id + */ + private String homeId; + + + public boolean getOnline() { + return online; + } + + public void setOnline(boolean online) { + this.online = online; + } + /** + * 缃戝叧鍨嬪彿 + */ + public String getDevice_model() { + return device_model == null ? "" : device_model; + } + /** + * 缃戝叧鍨嬪彿 + */ + public void setDevice_model(String device_model) { + this.device_model = device_model; + } + /** + * 缃戝叧澶囨敞 + */ + public String getDevice_name() { + if(TextUtils.isEmpty(device_name)){ + return getDevice_model(); + }else { + + } + return device_name; + } + + /** + * 妯℃澘鍖归厤鏍囪 wxr 鑷畾涔� 2022-02-23 16:09:44 + */ + private boolean templateSettingFlag = false; + + public boolean isTemplateSettingFlag() { + return templateSettingFlag; + } + + public void setTemplateSettingFlag(boolean templateSettingFlag) { + this.templateSettingFlag = templateSettingFlag; + } + private String templateAddr ; + + public String getTemplateAddr() { + return templateAddr == null ? "" : templateAddr; + } + + public void setTemplateAddr(String templateAddr) { + this.templateAddr = templateAddr; + } + + + + /** + * 缃戝叧澶囨敞 + */ + public void setDevice_name(String device_name) { + this.device_name = device_name; + } + + /** + * 缃戝叧Mac + * @return + */ + + public String getDevice_mac() { + return device_mac == null ? "" : device_mac; + } + + /** + * 缃戝叧Mac + */ + public void setDevice_mac(String device_mac) { + this.device_mac = device_mac; + } + /** + * 缃戝叧Id + */ + + public String getGatewayId() { + return gatewayId == null ? "" : gatewayId; + } + + /** + * 缃戝叧Id + */ + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + /** + * 缃戝叧绫诲瀷 + */ + public String getGatewayType() { + return gatewayType == null ? "" : gatewayType; + } + + /** + * 缃戝叧绫诲瀷 + */ + public void setGatewayType(String gatewayType) { + this.gatewayType = gatewayType; + } + + public String getGateway_type() { + return gateway_type == null ? "" : gateway_type; + } + + public void setGateway_type(String gateway_type) { + this.gateway_type = gateway_type; + } + /** + * 缃戝叧Oid + */ + public String getOid() { + return oid == null ? "" : oid; + } + + /** + * 缃戝叧Oid + */ + public void setOid(String oid) { + this.oid = oid; + } + /** + * IP鍦板潃 + */ + public String getIp_address() { + return ip_address == null ? "" : ip_address; + } + + /** + * IP鍦板潃 + */ + public void setIp_address(String ip_address) { + this.ip_address = ip_address; + } + /** + * 杩炴帴鐨勭綉鍏崇被鍨� LAN WIFI + */ + public String getAccess_mode() { + return access_mode == null ? "" : access_mode; + } + + /** + * 杩炴帴鐨勭綉鍏崇被鍨� LAN WIFI + */ + public void setAccess_mode(String access_mode) { + this.access_mode = access_mode; + } + /** + * 鏄惁涓荤綉鍏� true false + */ + public String getMaster() { + return master == null ? "" : master; + } + + /** + * 鏄惁涓荤綉鍏� true false no_config + */ + public void setMaster(String master) { + this.master = master; + } + /** + * 鏄惁鍔犲瘑 + */ + public boolean getIsLocalEncrypt() { + return isLocalEncrypt; + } + /** + * 鏄惁鍔犲瘑 + */ + public void setIsLocalEncrypt(boolean localEncrypt) { + isLocalEncrypt = localEncrypt; + } + /** + * 鑾峰彇浣忓畢Id + */ + public String getHomeId() { + return homeId == null ? "" : homeId; + } + + /** + * 璁剧疆浣忓畢Id + */ + public void setHomeId(String homeId) { + this.homeId = homeId; + } + /** + * 鏄惁鏈湴缃戝叧 true false + */ + public void setIsLocalGateWay(boolean isLocalGateWay) { + this.isLocalGateWay = isLocalGateWay; + } + /** + * 鑾峰彇缃戝叧鏄惁鏈湴缃戝叧 + */ + public boolean getIsLocalGateway() { + return this.isLocalGateWay; + } + + + /* + * 妯℃澘鏍囪 wxr + * */ + private boolean templateFlag = false; + + public boolean isLocalEncrypt() { + return isLocalEncrypt; + } + + public void setLocalEncrypt(boolean localEncrypt) { + isLocalEncrypt = localEncrypt; + } +} \ No newline at end of file diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/AuthenticateRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java similarity index 87% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/AuthenticateRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java index e7ba0f3..a77548c 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/AuthenticateRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; @@ -34,45 +34,15 @@ this.auth = auth; } - /** - * 璁よ瘉淇℃伅 - */ public static class AuthBean implements Serializable { - /** - * 璁惧MACKey - */ private String mac_key;//(mac+secret)鐨勪袱娆d5鍊� - /** - * 璁惧spk - */ private String spk; - /** - * 璇锋眰淇℃伅 - */ private RequestBean request;//璁惧鐩稿叧淇℃伅 - /** - * MAC key - * @return - */ public String getMACKey() { return mac_key; } - - /** - * MACkey - * @param value - */ public void setMACKey(String value) { this.mac_key = value; } - /** - * SPK - * @return - */ public String getSpk() { return spk; } - - /** - * SPK - * @param value - */ public void setSpk(String value) { this.spk = value; } public RequestBean getRequest() { return request; } @@ -81,13 +51,6 @@ public AuthBean() { } - - /** - * 璁よ瘉淇℃伅 - * @param mac_key mac key - * @param spk 浜у搧spk - * @param request 璇锋眰瀵硅薄 - */ public AuthBean(String mac_key, String spk, RequestBean request) { this.mac_key = mac_key; this.spk = spk; @@ -108,52 +71,16 @@ this.firmware_version = firmware_version; } - /** - * 璁惧MAC - * @return - */ public String getMAC() { return mac; } - - /** - * 璁惧MAC - * @param value - */ public void setMAC(String value) { this.mac = value; } - /** - * 鍘傚 - * @return - */ public String getSupplier() { return supplier; } - - /** - * 鍘傚 - * @param value - */ public void setSupplier(String value) { this.supplier = value; } - /** - * 纭欢鐗堟湰 - * @return - */ public String getHardwareModel() { return hardware_model; } - - /** - * 纭欢鐗堟湰 - * @param value - */ public void setHardwareModel(String value) { this.hardware_model = value; } - /** - * 杞欢鐗堟湰 - * @return - */ public String getFirmwareVersion() { return firmware_version; } - - /** - * 杞欢鐗堟湰 - * @param value - */ public void setFirmwareVersion(String value) { this.firmware_version = value; } } diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BaseLocalRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java similarity index 94% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BaseLocalRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java index 7962b60..44fcccf 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BaseLocalRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BroadcastRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java similarity index 96% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BroadcastRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java index 3092fcd..d760638 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/BroadcastRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/DeviceControlRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java similarity index 95% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/DeviceControlRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java index 9de4dcf..5c4c800 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/DeviceControlRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; import java.util.List; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/FunctionAttributeRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java similarity index 89% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/FunctionAttributeRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java index ad52485..b274fde 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/FunctionAttributeRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyReadRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java similarity index 67% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyReadRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java index 0486f16..4136322 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyReadRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java @@ -1,12 +1,9 @@ -package com.hdl.sdk.connect.bean.request; - -import java.io.Serializable; +package com.hdl.sdk.link.core.bean.request; /** * Created by Tong on 2021/10/8. */ -public class PropertyReadRequest implements Serializable -{ +public class PropertyReadRequest { private String sid; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyUpRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java similarity index 95% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyUpRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java index 93b96b1..dfd46b4 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/request/PropertyUpRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.request; +package com.hdl.sdk.link.core.bean.request; import java.io.Serializable; import java.util.List; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/AuthenticateResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java similarity index 96% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/AuthenticateResponse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java index e2b8b07..ea7d429 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/AuthenticateResponse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.response; +package com.hdl.sdk.link.core.bean.response; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseLocalResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java similarity index 93% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseLocalResponse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java index 56126dd..2000807 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseLocalResponse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.response; +package com.hdl.sdk.link.core.bean.response; import java.io.Serializable; @@ -6,7 +6,6 @@ * Created by Tong on 2021/9/29. */ public class BaseLocalResponse<T> implements Serializable { - private String id; private String time_stamp; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java similarity index 91% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseResponse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java index f409b7e..3337610 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/BaseResponse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.response; +package com.hdl.sdk.link.core.bean.response; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/GatewaySearchBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java similarity index 97% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/GatewaySearchBean.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java index b689546..b574beb 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/GatewaySearchBean.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.response; +package com.hdl.sdk.link.core.bean.response; import java.io.Serializable; diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/NetworkAccessBroadcastResponse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java similarity index 92% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/NetworkAccessBroadcastResponse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java index 9e01eba..23a16c4 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/response/NetworkAccessBroadcastResponse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.bean.response; +package com.hdl.sdk.link.core.bean.response; /** * Created by jlchen on 11/15/21. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java new file mode 100644 index 0000000..88d979b --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.core.callback; + +import com.hdl.sdk.link.common.exception.HDLLinkException; + +/** + * Created by Tong on 2021/11/11. + */ +public interface BaseCallBack { + + void onError(HDLLinkException e); + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java new file mode 100644 index 0000000..5299977 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.core.callback; + +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; + +import java.util.List; + +/** + * Created by hxb on 2021/12/15. + */ +public interface GatewayCallBack extends BaseCallBack { + void onSuccess(List<GatewayBean> gatewayBeanList); +} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java similarity index 80% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkCallBack.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java index fd52428..4bdf82f 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkCallBack.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.connect.callback; +package com.hdl.sdk.link.core.callback; /** * Created by jlchen on 11/16/21. diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkResponseCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java similarity index 68% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkResponseCallBack.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java index 1d33c3e..418152a 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/HDLLinkResponseCallBack.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java @@ -1,6 +1,7 @@ -package com.hdl.sdk.connect.callback; +package com.hdl.sdk.link.core.callback; -import com.hdl.sdk.connect.bean.LinkResponse; + +import com.hdl.sdk.link.core.bean.LinkResponse; /** * Created by jlchen on 11/16/21. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java new file mode 100644 index 0000000..dfa9885 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java @@ -0,0 +1,11 @@ +package com.hdl.sdk.link.core.callback; + +/** + * Created by jlchen on 1/6/22. + * 鏈湴閫氫俊閫氱敤CallBack + */ +public interface HDLLinkTCallBack<T> extends BaseCallBack{ + + void onSuccess(T data); + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java new file mode 100644 index 0000000..a8982e9 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java @@ -0,0 +1,9 @@ +package com.hdl.sdk.link.core.callback; + + +/** + * Created by hxb on 2021/12/15. + */ +public interface ZigbeeCallBack extends BaseCallBack { + void onSuccess(String body); +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java new file mode 100644 index 0000000..629541e --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java @@ -0,0 +1,182 @@ +package com.hdl.sdk.link.core.config; + +import com.hdl.sdk.link.common.utils.SPUtils; +import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; +import com.hdl.sdk.link.core.bean.response.GatewaySearchBean; + + + +/** + * Created by jlchen on 11/11/21. + * + * @Description : HDLLinkConfig + */ +public class HDLLinkConfig { + private static final String AUTHENTICATE_LS_KEY = "auth_ls_key"; + private static final String AUTHENTICATE_GATEWAYID_KEY = "auth_gatewayid_key"; + private static final String AUTHENTICATE_IPADDRESS_KEY = "auth_ipaddress_key"; + private static final String AUTHENTICATE_IS_LS_KEY = "auth_isls_key"; + private static final String HOME_ID="home_id"; + + private String localSecret;//鏈湴鍔犲瘑瀵嗛挜 + private String gatewayId; + private String ipAddress; + private boolean isLocalEncrypt;//缃戝叧鏄惁闇�瑕佸姞瀵嗛�氳 + private String homeId; + private GatewaySearchBean currentGateway;//褰撳墠缃戝叧 + + private AuthenticateRequest.AuthenticateDeviceInfoBean deviceInfoBean;//褰撳墠璁惧鍩烘湰淇℃伅 + + /** + * instance + */ + private volatile static HDLLinkConfig instance; + + /** + * getInstance + * + * @return AuthenticateConfig + */ + public static synchronized HDLLinkConfig getInstance() { + if (instance == null) { + synchronized (HDLLinkConfig.class) { + if (instance == null) { + instance = new HDLLinkConfig(); + instance.loadConfig(); + } + } + } + return instance; + } + + /** + * 娓呯┖缂撳瓨 + */ + public void clearConfig() { + this.gatewayId = ""; + this.ipAddress = ""; + this.localSecret = ""; + this.isLocalEncrypt = false; + this.homeId=""; +// SPUtils.remove(AUTHENTICATE_LS_KEY); +// SPUtils.remove(AUTHENTICATE_GATEWAYID_KEY); +// SPUtils.remove(AUTHENTICATE_IPADDRESS_KEY); +// SPUtils.remove(AUTHENTICATE_IS_LS_KEY); +// SPUtils.remove(HOME_ID); + } + + /** + * 鍔犺浇缂撳瓨 + */ + void loadConfig() { +// localSecret = SPUtils.getString(AUTHENTICATE_LS_KEY, ""); +// gatewayId = SPUtils.getString(AUTHENTICATE_GATEWAYID_KEY, ""); +// ipAddress = SPUtils.getString(AUTHENTICATE_IPADDRESS_KEY, ""); +// isLocalEncrypt = SPUtils.getBoolean(AUTHENTICATE_IS_LS_KEY, false); +// homeId=SPUtils.getString(HOME_ID, ""); + } + + /** + * 淇濆瓨閰嶇疆 + * + * @param localSecret + * @param gatewayId + * @param ipAddress + */ + public void saveConfig(String localSecret, String gatewayId, String ipAddress) { + this.localSecret = localSecret; + this.gatewayId = gatewayId; + this.ipAddress = ipAddress; +// SPUtils.put(AUTHENTICATE_LS_KEY, localSecret); +// SPUtils.put(AUTHENTICATE_GATEWAYID_KEY, gatewayId); +// SPUtils.put(AUTHENTICATE_IPADDRESS_KEY, ipAddress); + } + + /** + * 閲嶆柊淇濆瓨 + */ + public void reSaveConfig() { + this.saveConfig(this.localSecret, this.gatewayId, this.ipAddress); + } + + /** + * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 + * + * @return + */ + public boolean checkIfCertified() { + ///TODO 閽堝涓夋柟瑕佸畬鍠勮繖鍧� + //localSecret涓嶄负绌哄苟涓旈暱搴︾瓑浜�16 缃戝叧id涓嶈兘涓虹┖ + return true;//!TextUtils.isEmpty(localSecret) + //&& localSecret.length() == 16 + //&& !TextUtils.isEmpty(gatewayId); + } + + public void setLocalSecret(String localSecret) { + this.localSecret = localSecret; +// SPUtils.put(AUTHENTICATE_LS_KEY, localSecret); + } + + public String getLocalSecret() { + return localSecret; + } + + /** + * 褰撳墠浣忓畢缃戝叧Id,oid,mac + * @return + */ + public String getGatewayId() { + return gatewayId; + } + + /** + * 褰撳墠浣忓畢缃戝叧Id + * @param gatewayId + */ + public void setGatewayId(String gatewayId) { + this.gatewayId= gatewayId; + } + +// public String getHomeId() { +// return homeId; +// } + +// public void setHomeId(String homeId) { +// this.homeId = homeId; +// } + + public String getIpAddress() { + return ipAddress; + } + public void setIpAddress(String ipAddress){ + this.ipAddress = ipAddress; + } + + public boolean isLocalEncrypt() { + return isLocalEncrypt; + } + + public void setLocalEncrypt(boolean localEncrypt) { + isLocalEncrypt = localEncrypt; +// SPUtils.put(AUTHENTICATE_IS_LS_KEY, isLocalEncrypt); + } + + + /** + * 鎷兼帴缃戝叧ID鑾峰彇瀹屾暣鐨勪富棰� + * + * @param topicStr + * @return + */ + public String getFullTopic(String topicStr) { + return String.format(topicStr, gatewayId); + } + + public AuthenticateRequest.AuthenticateDeviceInfoBean getDeviceInfoBean() { + return deviceInfoBean; + } + + public void setDeviceInfoBean(AuthenticateRequest.AuthenticateDeviceInfoBean deviceInfoBean) { + this.deviceInfoBean = deviceInfoBean; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java new file mode 100644 index 0000000..ba9d721 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java @@ -0,0 +1,304 @@ +package com.hdl.sdk.link.core.connect; + + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.bean.LinkRoomBean; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.utils.EncryptUtil; +import com.hdl.sdk.link.core.utils.LinkResponseUtils; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + + +import java.lang.reflect.Type; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by Tong on 2021/11/11. + */ +public class HDLConnectHelper { + + private static final Long DEF_SEND_TIMEOUT = 8000L; + private static final int DEF_MAX_RETRY = 1;//鏈�澶ч噸鍙戞暟 + private static final int DEF_SEND_ONE = 1; + private static final int TCP_PORT = 8586; + private static final int UDP_PORT = 8585; + + private final Long sendAwaitTime; + private final int maxRetry; + + /** + * 鏄惁tcp鍙戦�佺被鍨� + */ + private boolean isTcp; + /** + * 鍙戦�佺殑鐩爣IP + */ + private String ipAddress; + /** + * 鍙戦�佺殑鐩爣鍦板潃 + */ + private int port; + private final LinkRequest linkRequest; + private final EventListener eventListener; + + private final AtomicInteger sendNumber = new AtomicInteger(0); + + private final AtomicBoolean isSend = new AtomicBoolean(false); + + private HdlSocketListener listener; + + private ScheduledExecutorService sendThread; + + private String observeTopic; + + public interface HdlSocketListener { + void onSucceed(Object msg); + + void onFailure(); + } + + /** + * 鍙戦�乁DP鎴栬�匱CP鏁版嵁 + * + * @param sendAwaitTime 姣忔鍙戦�佺瓑寰呮椂闂� + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param observeTopic 鎺ユ敹涓婚 + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port, + LinkRequest linkRequest, String observeTopic, HdlSocketListener listener, boolean isTcp) { + this.sendAwaitTime = sendAwaitTime; + this.maxRetry = maxRetry; + this.ipAddress = ipAddress; + this.port = port; + this.linkRequest = linkRequest; + this.observeTopic = observeTopic; + this.listener = listener; + this.isTcp = isTcp; + + eventListener = new EventListener() { + @Override + public void onMessage(Object msg) { + try { + //绉婚櫎鐩戝惉 + removeListener(); + isSend.set(true); + if (sendThread != null) { + sendThread.shutdownNow(); + } + + if (listener != null && msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + JsonObject jsonObject = new JsonParser().parse(linkResponse.getData()).getAsJsonObject(); + + String code = null; + if (jsonObject.get("code") != null) { + code = jsonObject.get("code").getAsString(); + } + /** + * 鍙兘杩斿洖code灞炴�у彲鑳芥病鏈� 娌℃湁鐨勮瘽鐩存帴鎴愬姛 鏈夌殑璇濆彧鏈�200鎵嶄細鎴愬姛 + */ + if (code == null || code.equals("200") || code.equals("0")) { + listener.onSucceed(msg); + return; + } + } + } catch (Exception e) { + + } + //涓婇潰娌℃湁姝e父鎵ц锛屽洖璋冨け璐� + notifyFailure(); + } + }; + //娉ㄥ唽鐩戝惉 + registerListener(); + } + + /** + * 鎸夌収鎸囧畾娆℃暟鍙戯紝鍥炶皟 + * + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param observeTopic 鎺ユ敹涓婚 + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(int maxRetry, String ipAddress, int port, + LinkRequest linkRequest, String observeTopic, HdlSocketListener listener, boolean isTcp) { + this(DEF_SEND_TIMEOUT, maxRetry, ipAddress, port, linkRequest, observeTopic, listener, isTcp); + } + + /** + * 鎸夌収鎸囧畾娆℃暟鍙戯紝鍥炶皟 + * + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param observeTopic 鎺ユ敹涓婚 + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(int maxRetry, String ipAddress, + LinkRequest linkRequest, String observeTopic, HdlSocketListener listener, boolean isTcp) { + this(maxRetry, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, observeTopic, listener, isTcp); + } + + /** + * 鎸夌収鎸囧畾娆℃暟鍙戯紝涓嶅洖璋� + * + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(int maxRetry, String ipAddress, + LinkRequest linkRequest, boolean isTcp) { + this(maxRetry, ipAddress, linkRequest, null, null, isTcp); + } + + /** + * 鎸夌収榛樿閲嶅彂鏈哄埗鍙戦�� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param observeTopic 鎺ユ敹涓婚 + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(String ipAddress, int port, + LinkRequest linkRequest, String observeTopic, HdlSocketListener listener, boolean isTcp) { + this(DEF_MAX_RETRY, ipAddress, port, linkRequest, observeTopic, listener, isTcp); + } + + /** + * 榛樿绔彛鍙戦�� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param observeTopic 鎺ユ敹涓婚 + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(String ipAddress, + LinkRequest linkRequest, String observeTopic, HdlSocketListener listener, boolean isTcp) { + this(DEF_SEND_TIMEOUT, DEF_MAX_RETRY, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, observeTopic, listener, isTcp); + } + + /** + * 鍙戦�佷竴娆� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(String ipAddress, LinkRequest linkRequest, boolean isTcp) { + this(DEF_SEND_TIMEOUT, DEF_SEND_ONE, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, null, null, isTcp); + } + + /** + * 娉ㄥ唽鐩戝惉 + */ + private void registerListener() { + if (!TextUtils.isEmpty(observeTopic) && null != listener) { + EventDispatcher.getInstance().register(observeTopic, eventListener); + } + } + + /** + * 绉婚櫎鐩戝惉 + */ + private void removeListener() { + if (!TextUtils.isEmpty(observeTopic)) { + EventDispatcher.getInstance().remove(observeTopic, eventListener); + } + } + + public void send() { + getSendThread().scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + //鍙戦�佹鏁板皬浜庨噸鍙戞鏁� + if ((sendNumber.get() < maxRetry)) { + try { + //杩樻病鏈夋敹鍒板洖澶嶏紝鍐嶅彂閫� + if (!isSend.get()) { + sendNumber.set(sendNumber.get() + 1); + if(!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅 + LogUtils.i("鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes())); + } + //濡傛槸tcp + if (isTcp) { + HDLTcpConnect.getTcpSocketBoot(ipAddress).sendMsg(EncryptUtil.getEncryBytes(linkRequest)); + } else { + //濡傛灉鏄痷dp + HDLUdpConnect.getInstance().getUdpBoot().sendMsg(ipAddress, port, EncryptUtil.getEncryBytes(linkRequest)); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + //瓒呭嚭閲嶅彂娆℃暟骞舵病鏈夋敹鍒板洖澶� + if (!isSend.get()) { + notifyFailure(); + } + } + } + }, 0, sendAwaitTime, TimeUnit.MILLISECONDS); + //initialdelay - 棣栨鎵ц鐨勫欢杩熸椂闂� 0 + //delay - 涓�娆℃墽琛岀粓姝㈠拰涓嬩竴娆℃墽琛屽紑濮嬩箣闂寸殑寤惰繜 + } + + + /** + * 鑾峰彇鍙戦�佺嚎绋� + * + * @return 杩斿洖鑾峰彇鍒扮殑绾跨▼ + */ + private ScheduledExecutorService getSendThread() { + if (sendThread == null) { + sendThread = ThreadToolUtils.getInstance().newScheduledThreadPool(1); + } + return sendThread; + } + + + /** + * 鍙戦�佸け璐� + */ + private void notifyFailure() { + //绉婚櫎鐩戝惉 + removeListener(); + if (sendThread != null) { + sendThread.shutdownNow(); + sendThread = null; + } + if (listener != null) { + listener.onFailure(); + listener = null; + } + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java new file mode 100644 index 0000000..ca0b109 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java @@ -0,0 +1,153 @@ +package com.hdl.sdk.link.core.connect; + + +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.bean.LinkOidBean; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.bean.request.BroadcastRequest; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.protocol.LinkMessageDecoder; +import com.hdl.sdk.link.core.protocol.LinkMessageEncoder; +import com.hdl.sdk.link.core.utils.LinkResponseUtils; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; +import com.hdl.sdk.link.socket.TcpSocketBoot; +import com.hdl.sdk.link.socket.SocketOptions; +import com.hdl.sdk.link.socket.client.IHeartbeat; +import com.hdl.sdk.link.socket.client.TcpClient; +import com.hdl.sdk.link.socket.codec.MessagePipeLine; +import com.hdl.sdk.link.socket.listener.ConnectStatusListener; + +import java.lang.reflect.Type; +import java.util.List; + +/** + * Created by Tong on 2021/9/26. + * 1銆侀�氳繃Udp 缁勬挱鎴栬�呭箍鎾悳绱㈢綉鍏� + * 2銆侀�氳繃Udp 鑾峰彇Tcp ip 绔彛缁熶竴8586 + */ +public class HDLTcpConnect { + + /** + * tcp榛樿绔彛 + */ + private static final int TCP_PORT = 8586; + + + private ConnectStatusListener statusListener; + + private HDLTcpConnect() { + statusListener = new ConnectStatusListener() { + @Override + public void onConnecting() { + broadcastRequest(); + } + + @Override + public void onConnected() { + + } + + @Override + public void onConnectFailed() { + + } + }; + } + + /** + * 骞挎挱鑷韩淇℃伅缁欎富缃戝叧 + */ + private void broadcastRequest() { + String time = String.valueOf(System.currentTimeMillis()); + if (null == HDLLinkConfig.getInstance().getDeviceInfoBean()) { + LogUtils.i("DeviceInfoBean涓虹┖锛岃璁剧疆褰撳墠瀵硅薄"); + return; + } + BroadcastRequest request = new BroadcastRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), "200"); + HDLUdpConnect.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true); + HDLUdpConnect.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true, new HDLLinkResponseCallBack() { + @Override + public void onSuccess(LinkResponse msg) { + LogUtils.i("骞挎挱淇℃伅缁欎富缃戝叧鎴愬姛锛�"); + } + + @Override + public void onError(HDLLinkException e) { + + } + }); + HDLUdpConnect.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true); + } + + private static class SingletonInstance { + private static final HDLTcpConnect INSTANCE = new HDLTcpConnect(); + } + + public static HDLTcpConnect getInstance() { + return SingletonInstance.INSTANCE; + } + + /** + * 閫氳繃IP鍙婄鍙f壘鍑鸿繛鎺ュ鎴风锛屽鏋滃綋鍓嶆病鏈夎繛鎺ャ�備富瑕佹槸閽堝璋冭瘯杞欢浣跨敤锛屾敮鎸佽繛鎺ヤ富缃戝叧銆佷粠缃戝叧 + * + * @param ip 杩炴帴鐨勭綉鍏矷P + * @return + */ + public static synchronized TcpSocketBoot getTcpSocketBoot(String ip) { + return initTcp(ip); + } + + static int dddd; + /** + * 鍒濆鍖杢cp杩炴帴 + * + * @param ip 杩炴帴鐨勭綉鍏矷P + * @return + */ + public static synchronized TcpSocketBoot initTcp(String ip) { + int port = TCP_PORT; + TcpSocketBoot tcpSocketBoot = TcpSocketBoot.getByEndPoint(ip, port); + + if (null == tcpSocketBoot) { + final SocketOptions options = new SocketOptions(); + final MessagePipeLine pipeLine = new MessagePipeLine(); + pipeLine.add(new LinkMessageDecoder()); + pipeLine.add(new LinkMessageEncoder()); + options.setHandleMessage(pipeLine); + tcpSocketBoot = TcpClient.init(ip, port, options); + tcpSocketBoot.SetHeartbeat(new IHeartbeat() { + @Override + public void heartbeat() { + + String time = String.valueOf(System.currentTimeMillis()); + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + GatewayBean gatewayBean= HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(ip); + if(gatewayBean==null){ + return; + } + String topic = String.format(TopicConstant.HEARTBEAT, gatewayBean.getOid()); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), false); + new HDLConnectHelper(ip, request, null, null, true).send(); + } + }); + } + return tcpSocketBoot; + } +} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java similarity index 64% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java index 6986188..edfaaf7 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java @@ -1,55 +1,55 @@ -package com.hdl.sdk.connect.socket; +package com.hdl.sdk.link.core.connect; + import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; -import com.hdl.sdk.common.event.EventDispatcher; -import com.hdl.sdk.common.event.EventListener; -import com.hdl.sdk.common.exception.HDLLinkCode; -import com.hdl.sdk.common.exception.HDLLinkException; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.connect.bean.response.AuthenticateResponse; -import com.hdl.sdk.connect.bean.response.NetworkAccessBroadcastResponse; -import com.hdl.sdk.connect.callback.BaseCallBack; -import com.hdl.sdk.connect.callback.HDLLinkCallBack; -import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.common.config.TopicConstant; -import com.hdl.sdk.common.utils.IdUtils; -import com.hdl.sdk.common.utils.IpUtils; -import com.hdl.sdk.common.utils.gson.GsonConvert; -import com.hdl.sdk.connect.bean.request.AuthenticateRequest; -import com.hdl.sdk.connect.bean.response.BaseLocalResponse; -import com.hdl.sdk.connect.bean.request.DeviceControlRequest; -import com.hdl.sdk.connect.bean.response.GatewaySearchBean; -import com.hdl.sdk.connect.bean.LinkRequest; -import com.hdl.sdk.connect.bean.LinkResponse; -import com.hdl.sdk.connect.protocol.LinkMessageDecoder; -import com.hdl.sdk.connect.protocol.LinkMessageEncoder; -import com.hdl.sdk.socket.client.UdpClient; -import com.hdl.sdk.socket.codec.MessagePipeLine; -import com.hdl.sdk.socket.udp.UdpSocketBoot; -import com.hdl.sdk.socket.udp.UdpSocketOptions; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IpUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; +import com.hdl.sdk.link.core.bean.response.AuthenticateResponse; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.bean.response.GatewaySearchBean; +import com.hdl.sdk.link.core.bean.response.NetworkAccessBroadcastResponse; +import com.hdl.sdk.link.core.callback.BaseCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.protocol.LinkMessageDecoder; +import com.hdl.sdk.link.core.protocol.LinkMessageEncoder; +import com.hdl.sdk.link.socket.client.UdpClient; +import com.hdl.sdk.link.socket.codec.MessagePipeLine; +import com.hdl.sdk.link.socket.udp.UdpSocketBoot; +import com.hdl.sdk.link.socket.udp.UdpSocketOptions; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import static com.hdl.sdk.common.config.TopicConstant.DEIVCE_AUTH_REQUEST; +import static com.hdl.sdk.link.common.config.TopicConstant.DEIVCE_AUTH_REQUEST; /** * Created by jlchen on 11/11/21. * * @Description : HDLAuthSocket 鐢变簬鍓嶆湡宸茬粡鍛藉悕濂斤紝涓嶅仛鏇存敼锛屽彲鐢ㄤ綔Udp鏈嶅姟绔娇鐢� */ -public class HDLAuthSocket { +public class HDLUdpConnect { private static final String TAG = "HDLAuth"; /** * udp榛樿绔彛 */ - private static final int UDP_PORT = 8585; + public static final int UDP_PORT = 8585; /** * 鍥犱负鑰冭檻鍒颁娇鐢ㄤ竴涓鍙o紝瑕佹敮鎸佹帴鏀跺缃戝叧鐨勬暟鎹紝鎵�浠ュ彧鍏佽浣跨敤涓�涓� */ @@ -65,30 +65,26 @@ /** * instance */ - private static final HDLAuthSocket instance=new HDLAuthSocket(); + private volatile static HDLUdpConnect instance; - private HDLAuthSocket() { + private HDLUdpConnect() { initListenerGatewayEvent(); initSearchGatewayEvent(); } - -// public interface CallBack extends BaseCallBack { -// void onSuccess(String msg); -// } /** * getInstance * * @return HDLAuthSocket */ - public static HDLAuthSocket getInstance() { -// if (instance == null) { -// synchronized (HDLAuthSocket.class) { -// if (instance == null) { -// instance = new HDLAuthSocket(); -// } -// } -// } + public static synchronized HDLUdpConnect getInstance() { + if (instance == null) { + synchronized (HDLLinkConfig.class) { + if (instance == null) { + instance = new HDLUdpConnect(); + } + } + } return instance; } @@ -107,14 +103,28 @@ * * @return 杩斿洖褰撳墠瀵硅薄 */ - private synchronized UdpSocketBoot getUdpBoot() { + public synchronized UdpSocketBoot getUdpBoot() { + if (null == initUdp()) { + return null; + } + return udpSocketBoot; + } + + + /** + * 鍒濆鍖杣dp 鐩戝惉鍔熻兘 + * + * @return 杩斿洖褰撳墠瀵硅薄 + */ + public synchronized UdpSocketBoot initUdp() { try { if (udpSocketBoot == null) { - udpSocketBoot = UdpClient.init(UDP_PORT, getUdpOptions()); + udpSocketBoot = UdpClient.init("0.0.0.0",UDP_PORT, getUdpOptions()); udpSocketBoot.bind(); } } catch (Exception e) { - LogUtils.e("鍒濆鍖朣ocket udp寮傚父"+e.getMessage()); + LogUtils.e("鍒濆鍖栫綉鍏冲け璐�:"+e.getMessage()); + return null; } return udpSocketBoot; @@ -133,22 +143,20 @@ //2.鏋勫缓鐩戝惉Listener // authEvent = //3.鐩戝惉缃戝叧骞挎挱鐨勫叆缃戞寚浠� - EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); EventDispatcher.getInstance().register(TopicConstant.GATEWAY_AUTH_BROADCAST, new EventListener() { @Override public void onMessage(Object msg) { - LogUtils.i("鏀跺埌缃戝叧璁よ瘉淇℃伅: "); NetworkAccessBroadcastResponse bean = getNetworkAccessBroadcastResponse(msg); if (bean != null) { - //绉婚櫎鐩戝惉 - EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); - LogUtils.i("缃戝叧鍏ョ綉骞挎挱IP: " + bean.getIPAddress()); + LogUtils.i(TAG, "缃戝叧鍏ョ綉骞挎挱IP: " + bean.getIPAddress()); String ipStr = bean.getIPAddress(); if (!TextUtils.isEmpty(ipStr)) { sendAuthenticateRequest(ipStr, request, callBack); } } - + //绉婚櫎鐩戝惉 + EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); + LogUtils.i(TAG, "绉婚櫎鐩戝惉 authEvent"); } }); } @@ -175,14 +183,11 @@ String topic = DEIVCE_AUTH_REQUEST; Gson gs = new Gson(); String requestStr = gs.toJson(request); - LinkRequest message = new LinkRequest(topic, requestStr); + LinkRequest message = new LinkRequest(topic, requestStr, false); - HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message, new HdlSocketHelper.HdlSocketListener() { + new HDLConnectHelper(ip, message, requestStr + "_reply", new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { - - LogUtils.i("onSucceed msg锛�" + msg); - if (callBack == null) return; try { AuthenticateResponse bean = getAuthenticateResponseBean(msg); @@ -206,10 +211,10 @@ HDLLinkConfig.getInstance().saveConfig(localSecret, gatewayId, ipAddress); callBack.onSuccess("璁よ瘉鎴愬姛"); } - } else if (bean.getCode().equals("14013")){ + } else if (bean.getCode().equals("14013")) { //璁よ瘉澶辫触锛岃MAC瀵瑰簲鐨勮澶囧瘑閽ヤ笉瀛樺湪 - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_MAC_KEY_ERROR_)); - } else{ + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_MAC_KEY_ERROR)); + } else { //璁よ瘉澶辫触锛岄敊璇爜锛� LogUtils.e("璁よ瘉澶辫触锛岄敊璇爜锛�" + bean.getCode()); callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR)); @@ -228,9 +233,8 @@ if (callBack == null) return; callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); } - }); + }, false).send(); } - // /** // * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 @@ -284,14 +288,6 @@ void onSuccess(GatewaySearchBean gatewaySearchBean); } - /** - * 寮�濮嬫悳绱㈡墍鏈夌綉鍏筹紝鏈夌綉鍏冲洖澶嶅氨鍥炶皟锛屼笂灞傝嚜宸卞仛鍘婚噸鍒ゆ柇 - * - * @param callBack 鍥炶皟 - */ - public void startSearchAllGateway(SearchGatewayCallBack callBack) { - - } /** * 鏆傚仠鎼滅储缃戝叧 @@ -325,47 +321,16 @@ searchGateway(HDLLinkConfig.getInstance().getGatewayId(), ip, UDP_PORT, callBack); } - - /** - * 璁惧鎺у埗 - */ - public void propertyDown(List<DeviceControlRequest> request, HDLLinkCallBack callBack) { - String time = String.valueOf(System.currentTimeMillis()); - final BaseLocalResponse<List<DeviceControlRequest>> data = new BaseLocalResponse<>(); - data.setId(IdUtils.getUUId()); - data.setTime_stamp(time); - data.setObjects(request); - String topic = HDLLinkConfig.getInstance().getFullTopic(TopicConstant.PROPERTY_DOWN); - LinkRequest message = new LinkRequest(topic, - GsonConvert.getGson().toJson(data)); - - String ip = IpUtils.getBroadcastAddress(); - HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message, new HdlSocketHelper.HdlSocketListener() { - @Override - public void onSucceed(Object msg) { - if (callBack == null) return; - callBack.onSuccess("鎺у埗鎴愬姛"); - } - - @Override - public void onFailure() { - if (callBack == null) return; - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_CONTROL_FAILURE_ERROR)); - } - }); - - } - /** * 閫氱敤鍙戦�佹寚浠� * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr 鍥炲鐨勪富棰� * @param broadcast 鏄惁瑕佸箍鎾� - * @param callBack 鍥炶皟 + * @param callBack 鍥炶皟 */ - public void udpSendMsg(String topic, String bodyStr,boolean broadcast, HDLLinkResponseCallBack callBack) { + public void udpSendMsg(String topic, String bodyStr, boolean broadcast, HDLLinkResponseCallBack callBack) { if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { if (callBack != null) { callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_NULL_ERROR)); @@ -380,49 +345,49 @@ return; } - LinkRequest message = new LinkRequest(topic, bodyStr); + LinkRequest message = new LinkRequest(topic, bodyStr, false); String ip = HDLLinkConfig.getInstance().getIpAddress(); - if(broadcast) { + if (broadcast) { ip = IpUtils.getBroadcastAddress(); } - HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message, new HdlSocketHelper.HdlSocketListener() { - @Override - public void onSucceed(Object msg) { - if (callBack == null) return; - callBack.onSuccess((LinkResponse) msg); - } + new HDLConnectHelper(ip, message, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess((LinkResponse) msg); + } - @Override - public void onFailure() { - if (callBack == null) return; - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); - } - } - ); + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + } + } + , false).send(); } /** * 閫氱敤鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr 鍥炲鐨勪富棰� * @param broadcast 鏄惁骞挎挱 */ - public void udpSendMsg(String topic, String bodyStr,boolean broadcast) { + public void udpSendMsg(String topic, String bodyStr, boolean broadcast) { if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { - LogUtils.e( "鍙傛暟涓嶈兘涓虹┖锛屼笉鑳藉彂閫乁DP鏁版嵁"); + LogUtils.e("udpSendMsg", "鍙傛暟涓嶈兘涓虹┖"); return; } if (!HDLLinkConfig.getInstance().checkIfCertified()) { - LogUtils.e("鏈璇侊紝璇峰厛璁よ瘉鍐嶈皟鐢║DP鍙戦�佹柟娉�"); + LogUtils.e("udpSendMsg", "鏈璇侊紝璇峰厛璁よ瘉"); return; } - LinkRequest message = new LinkRequest(topic, bodyStr); + LinkRequest message = new LinkRequest(topic, bodyStr, HDLLinkConfig.getInstance().isLocalEncrypt()); String ip = HDLLinkConfig.getInstance().getIpAddress(); - if(broadcast) { + if (broadcast) { ip = IpUtils.getBroadcastAddress(); } - HdlSocketHelper.sendUdpOne(getUdpBoot(), ip, UDP_PORT, message); + new HDLConnectHelper(ip, message, false).send(); } private GatewaySearchBean getGatewaySearchBean(Object msg) { @@ -435,7 +400,6 @@ }.getType()); searchBean = response.getObjects(); } - } return searchBean; } @@ -494,12 +458,11 @@ }.getType()); GatewaySearchBean searchBean = response.getObjects(); if (searchBean != null && !TextUtils.isEmpty(searchBean.getGatewayId())) { - searchBean.setIp_address(linkResponse.getSource_ipAddress()); - if (searchBean.getGatewayId().contains(searchGatewayId)&&!TextUtils.isEmpty(searchGatewayId)) { + if (searchBean.getGatewayId().contains(searchGatewayId)) { removeSearchGatewayEvent();//绉婚櫎鎼滅储缃戝叧鐩戝惉 isSearchGatewaySuccess.set(true);//鎼滅储鎴愬姛鏍囪 searchGatewayCount.set(11);//娆℃暟鏍囪 - HDLLinkConfig.getInstance().setCurrentGateway(searchBean);//璁剧疆褰撳墠缃戝叧 + HDLLinkConfig.getInstance().setLocalEncrypt(searchBean.isLocalEncrypt());//璁剧疆鏄惁鍔犲瘑 if (mSearchGatewayCallBack != null) { mSearchGatewayCallBack.onSuccess(searchBean); } @@ -523,22 +486,28 @@ if (msg instanceof LinkResponse) { LinkResponse linkResponse = (LinkResponse) msg; String data = linkResponse.getData(); - LogUtils.i("鎺ユ敹鍒扮綉鍏充俊鎭細" + data); +// LogUtils.i("鎺ユ敹鍒扮綉鍏充俊鎭細" + data); if (!TextUtils.isEmpty(data)) { - final BaseLocalResponse<GatewaySearchBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() { + final BaseLocalResponse<GatewayBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewayBean>>() { }.getType()); - GatewaySearchBean gateway = response.getObjects(); - if (gateway != null && !TextUtils.isEmpty(gateway.getGatewayId())) { - //鍙兘缃戝叧甯﹁繃鏉ョ殑ip涓嶅 - gateway.setIp_address(linkResponse.getSource_ipAddress()); - //涓荤綉鍏冲苟涓旀槸褰撳墠缁戝畾鐨勭綉鍏� - if ("true".equals(gateway.getMaster().toLowerCase()) && gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId())) { - HDLLinkConfig.getInstance().setCurrentGateway(gateway);//璁剧疆褰撳墠缃戝叧 - if(!TextUtils.isEmpty( gateway.getIp_address())) { - HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address()); + GatewayBean gateway = response.getObjects(); + if (gateway != null) { + if (!TextUtils.isEmpty(HDLLinkConfig.getInstance().getGatewayId())) { + //涓荤綉鍏冲苟涓旀槸褰撳墠缁戝畾鐨勭綉鍏� + if ("true".equals(gateway.getMaster().toLowerCase())) { + if (gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId()) + || gateway.getDevice_mac().equals(HDLLinkConfig.getInstance().getGatewayId()) + || gateway.getOid().equals(HDLLinkConfig.getInstance().getGatewayId())) { + HDLLinkConfig.getInstance().setLocalEncrypt(gateway.getIsLocalEncrypt());//璁剧疆鏄惁鍔犲瘑 + HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address()); + //鏇存柊褰撳墠缃戝叧鐨勪俊鎭� + HDLLinkConfig.getInstance().reSaveConfig(); + } } - //鏇存柊褰撳墠缃戝叧鐨勪俊鎭� - HDLLinkConfig.getInstance().reSaveConfig(); + } + + if(TextUtils.isEmpty(gateway.getGatewayId())||gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId())) { + HDLTcpConnect.initTcp(gateway.getIp_address());//鍒濆鍖朤CP杩炴帴 } } } @@ -570,7 +539,7 @@ jsonObject.addProperty("id", IdUtils.getUUId()); jsonObject.addProperty("time_stamp", time); LinkRequest message = new LinkRequest(TopicConstant.GATEWAY_SEARCH, - jsonObject.toString()); + jsonObject.toString(), false); //娉ㄥ唽鎼滅储缃戝叧鐩戝惉 registerSearchGatewayEvent(); new Thread(new Runnable() { @@ -580,8 +549,8 @@ try { //鎼滅储缃戝叧 searchGatewayCount.set(searchGatewayCount.get() + 1); - LogUtils.i("鎼滅储缃戝叧", "鎼滅储缃戝叧绗�" + searchGatewayCount.get() + "娆�"); - getUdpBoot().sendMsg(ipAddress, port, message.getSendBytes()); + LogUtils.i("鎼滅储缃戝叧绗�" + searchGatewayCount.get() + "娆�"); + new HDLConnectHelper(ipAddress, message, false).send(); Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); @@ -589,11 +558,9 @@ } if (!isSearchGatewaySuccess.get()) { - try { - LogUtils.e("鎼滅储缃戝叧", "鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�"); - //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃� - callBackSearchGatewayTimeout(); - }catch (Exception e){} + //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃� + callBackSearchGatewayTimeout(); + LogUtils.e("鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�"); } } }).start(); @@ -604,7 +571,7 @@ * 娉ㄥ唽鎼滅储缃戝叧鐩戝惉 */ private void registerSearchGatewayEvent() { - LogUtils.i("鎼滅储缃戝叧", "娉ㄥ唽鎼滅储缃戝叧鐩戝惉"); + LogUtils.i("娉ㄥ唽鎼滅储缃戝叧鐩戝惉"); EventDispatcher.getInstance().registerIo(TopicConstant.GATEWAY_SEARCH_REPLY, searchGatewayEvent); } @@ -621,61 +588,10 @@ */ private void callBackSearchGatewayTimeout() { removeSearchGatewayEvent(); - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - if (mSearchGatewayCallBack != null) { - mSearchGatewayCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEARCH_GATEWAY_TIMEOUT_ERROR)); - } - } - }); - LogUtils.i("callBackSearchGatewayTimeout onError锛氭悳绱㈢綉鍏冲け璐ワ紝瓒呮椂"); - + if (mSearchGatewayCallBack != null) { + mSearchGatewayCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEARCH_GATEWAY_TIMEOUT_ERROR)); + } } - /** - * 鎼滅储鍦ㄧ嚎鎵�鏈夌殑缃戝叧锛屽寘鎷綋鍓嶄綇瀹呯殑鍙婃病鏈夌粦瀹氳繃鍏跺畠浣忓畢鐨勭綉鍏� - * - * @param ipAddress 鐩爣鐨処P鍦板潃 - * @param port 鐩爣鐨勭鍙� - * @param callBack 鍥炶皟 - */ - public void searchGateway(String ipAddress, int port, SearchGatewayCallBack callBack) { -// this.searchGatewayId = gatewayId; -// this.mSearchGatewayCallBack = callBack; -// //閲嶇疆鍙傛暟 -// searchGatewayCount.set(0); -// isSearchGatewaySuccess.set(false); - String time = String.valueOf(System.currentTimeMillis()); - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("id", IdUtils.getUUId()); - jsonObject.addProperty("time_stamp", time); - LinkRequest message = new LinkRequest(TopicConstant.GATEWAY_SEARCH, - jsonObject.toString()); - //娉ㄥ唽鎼滅储缃戝叧鐩戝惉 - registerSearchGatewayEvent(); - new Thread(new Runnable() { - @Override - public void run() { - while (searchGatewayCount.get() < 10 && (!isSearchGatewaySuccess.get())) { - try { - //鎼滅储缃戝叧 - searchGatewayCount.set(searchGatewayCount.get() + 1); - LogUtils.i("鎼滅储缃戝叧", "鎼滅储缃戝叧绗�" + searchGatewayCount.get() + "娆�"); - getUdpBoot().sendMsg(ipAddress, port, message.getSendBytes()); - Thread.sleep(1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - if (!isSearchGatewaySuccess.get()) { - //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃� - callBackSearchGatewayTimeout(); - LogUtils.e("鎼滅储缃戝叧", "鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�"); - } - } - }).start(); - } } diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java new file mode 100644 index 0000000..6c45ac2 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java @@ -0,0 +1,343 @@ +package com.hdl.sdk.link.core.connect; + + + +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.ZigbeeResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.callback.ZigbeeCallBack; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * Created by hxb on 2021/12/8. + * 鍘熺敓閫氳鐩稿叧鎺ュ彛 + */ +public class HDLZigbeeConnect { + + private static HDLZigbeeConnect instance; + /** + * 鍐呴儴鐢紝涓昏鏄鐞嗗鐞嗘帀閫忎紶涓婚鍙妉ink涓婚鍚庯紝杩樺師Zigbee鍘熺敓鏁版嵁鍙婁富棰樼敤 + */ + private final String zigbeeAllTopic = "/Zigbee"; + + /** + * 杩斿洖褰撳墠瀹炰緥锛屼笉瀛樺湪灏卞垱寤哄苟鍚屾椂娉ㄥ唽鐩戝惉浜嬩欢 + * + * @return + */ + public static HDLZigbeeConnect getInstance() { + if (null == instance) { + instance = new HDLZigbeeConnect(); + instance.initEventListener(); + } + return instance; + } + + /** + * 娉ㄥ唽鐩戝惉Zigbee鎵�鏈夊師鐢熶富棰樺強鏁版嵁 + * + * @param eventListener + */ + public void registerListener(EventListener eventListener) { + if(null==eventListener){ + return; + } + EventDispatcher.getInstance().register(zigbeeAllTopic, eventListener); + } + + /** + * 绉婚櫎鐩戝惉Zigbee鍘熺敓涓婚鍙婃暟鎹� + * + * @param eventListener + */ + public void removeListener(EventListener eventListener) { + if(null==eventListener){ + return; + } + EventDispatcher.getInstance().remove(zigbeeAllTopic, eventListener); + } + + /** + * 鍒濆鍖栫洃鍚簨浠� + */ + private void initEventListener() { + final EventListener eventListener = new EventListener() { + @Override + public void onMessage(Object msg) { + try { + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String body = linkResponse.getData(); + int index = body.indexOf("{"); + //zigbee鍥炲鐨勬暟鎹墠鏈変富棰橈紝鍚庨潰鎵嶆槸鏁版嵁 + if (index <= 0) + return; + + String zigbeeTopic = body.substring(0, index).trim(); + //zigbee鐨勮礋杞芥暟鎹� + String bodyData = body.substring(index); + + ZigbeeResponse zigbeeResponse = new ZigbeeResponse(); + zigbeeResponse.setTopic(zigbeeTopic); + zigbeeResponse.setData(bodyData); + String oid = null; + //鏄惁鏄�氳繃涓荤綉鍏抽�忎紶涓婚 + if (linkResponse.getTopic().contains("/slaveoid/")) { + oid = linkResponse.getTopic().split("/")[7]; + } else { + oid = linkResponse.getTopic().split("/")[2]; + } + zigbeeResponse.setOid(oid); + for (GatewayBean gatewayBean : HDLLinkLocalGateway.getInstance().getGatewayList()) { + if (oid.equals(gatewayBean.getGatewayId()) || oid.equals(gatewayBean.getDevice_mac()) || oid.equals(gatewayBean.getOid())) { + //涓婇潰鐨刼id鍙兘鏄綉鍏砳d鎴栬�卪ac鎴栬�呮槸oid锛屼笉绠℃槸鍝釜缁熶竴浣跨敤oid琛ㄧず鏂瑰紡 + zigbeeResponse.setOid(gatewayBean.getOid()); + break; + } + } + //鍙戝竷Zigbee鍘熺敓涓婚鍙婃暟鎹� + EventDispatcher.getInstance().post(zigbeeAllTopic, zigbeeResponse); + } + } catch (Exception e) { + LogUtils.e(e.getMessage()); + } + } + }; + // + String tempTopicReply = String.format("/user/%s/custom/native/zigbee/up", "+"); + //娉ㄥ唽鐩存帴閫氳鐨勪富棰橈紝鍖呮嫭鐩存帴鍜屼富缃戝叧閫氳鎴栬�呯洿鎺ュ拰浠庣綉鍏抽�氳 + registerListener(tempTopicReply, eventListener); + + //娉ㄥ唽閫氳繃涓荤綉鍏抽�忎紶浠庣綉鍏崇殑涓婚 + tempTopicReply = String.format("/user/%s/custom/native/zigbee/slaveoid/%s/up", "+", "+"); + registerListener(tempTopicReply, eventListener); + } + + /** + * 鍙戦�佸師鐢熸暟鎹� + * + * @param gatewayOidOrGatewayId 鐩爣缃戝叧鐨刼id鎴栬�呯綉鍏矷d + * @param responeTopic 鍥炲涓婚 + * @param payload 鍙戦�佹暟鎹� + * @param zigbeeCallBack 缁撴灉鍥炶皟 + */ + public void Send(String gatewayOidOrGatewayId, String responeTopic, String payload, final ZigbeeCallBack zigbeeCallBack) { + //濡傛灉鏈湴鏈夐摼鎺ヨ繖涓綉鍏�,鍒欑敤鏈湴杩炴帴 + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(gatewayOidOrGatewayId); + if (null == gatewayBean) { + LogUtils.i("鎵句笉鍒扮綉鍏筹紝Oid鏄�" + gatewayOidOrGatewayId); + if (null != zigbeeCallBack) { + zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + return; + } + boolean isLocal = gatewayBean.getIsLocalGateway(); + //濡傛灉鏄湰鍦伴�氳 + if (isLocal == true) { + + String tempTopic = String.format("/user/%s/custom/native/zigbee/down", gatewayOidOrGatewayId); + String tempTopicReply = String.format("/user/%s/custom/native/zigbee/up", gatewayOidOrGatewayId); + + final boolean[] isCallBack = {false}; + //閫忎紶鍛戒护涓婚澶勭悊 + final EventListener eventListener = new EventListener() { + @Override + public void onMessage(Object msg) { + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + //TODO 濡傛灉閰嶇疆浠庣綉鍏崇殑淇℃伅锛岄�氳繃涓荤綉鍏宠浆杈撅紝杩欓噷oid瑕佸垽鏂笅 + String body = getZigbeeData(responeTopic, linkResponse); + if (null != body) { + isCallBack[0] = true; + removeListener(tempTopicReply, this); + if (null != zigbeeCallBack) { + zigbeeCallBack.onSuccess(body); + } + } + } + } + }; + //娉ㄥ唽鐩戝惉 + registerListener(tempTopicReply, eventListener); + + //涓�瀹氭椂闂村悗杩樻病鏈夋帴鏀跺埌鏁版嵁锛屽氨鍥炶皟澶辫触 + ScheduledExecutorService scheduledExecutorService = ThreadToolUtils.getInstance().newScheduledThreadPool(1); + scheduledExecutorService.schedule(new Runnable() { + @Override + public void run() { + removeListener(tempTopicReply, eventListener); + scheduledExecutorService.shutdownNow(); + if (!isCallBack[0]) { + if (null != zigbeeCallBack) { + zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_Zigbee_FAILURE_ERROR)); + } + } + } + }, 5, TimeUnit.SECONDS); + + //鏈湴鍙戦�� + LinkRequest request = new LinkRequest(tempTopic, payload, gatewayBean.getIsLocalEncrypt()); + new HDLConnectHelper(gatewayBean.getIp_address(), request,true).send(); + } else { + //璇锋眰涓婚 + String tempTopic = null; + //鍥炲涓婚 + String tempTopicReply = null; + + //杩滅▼鍙戦�� + if ("true".equals(gatewayBean.getMaster())) { + tempTopic = String.format("/user/%s/custom/native/zigbee/down", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId()); + tempTopicReply = String.format("/user/%s/custom/native/zigbee/up", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId()); + } else { + tempTopic = String.format("/user/%s/custom/native/zigbee/slaveoid/%s/down", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId(), gatewayOidOrGatewayId); + tempTopicReply = String.format("/user/%s/custom/native/zigbee/slaveoid/%s/up", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId(), "+"); + } + //TODO 鍚庣画瀹屽杽浜戠鐨勫彂閫佹帴鏀舵柟娉� + } + } + + /** + * 鍙戦�佸師鐢熼�忎紶鍛戒护鏁版嵁 + * + * @param gatewayOidOrGatewayId 鐩爣缃戝叧鐨刼id鎴栬�呯綉鍏矷d + * @param responeTopic 鍥炲涓婚 + * @param payload 鍙戦�佹暟鎹� + * @param zigbeeCallBack 缁撴灉鍥炶皟 + */ + public void SendThrough(String gatewayOidOrGatewayId, String responeTopic, String payload, final ZigbeeCallBack zigbeeCallBack) { +// //濡傛灉鏈湴鏈夐摼鎺ヨ繖涓綉鍏�,鍒欑敤鏈湴杩炴帴 +// GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(gatewayOidOrGatewayId); +// if (null == gatewayBean) { +// LogUtils.i("鎵句笉鍒扮綉鍏筹紝Oid鏄�" + gatewayOidOrGatewayId); +// if (null != zigbeeCallBack) { +// zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); +// } +// return; +// } +// boolean isLocal = gatewayBean.getIsLocalGateway(); +// //濡傛灉鏄湰鍦伴�氳 +// if (isLocal == true) { +// +// String tempTopic = String.format("/user/%s/custom/native/zigbee/down", gatewayOidOrGatewayId); +// String tempTopicReply = String.format("/user/%s/custom/native/zigbee/up", gatewayOidOrGatewayId); +// +// final boolean[] isCallBack = {false}; +// //閫忎紶鍛戒护涓婚澶勭悊 +// final EventListener eventListener = new EventListener() { +// @Override +// public void onMessage(Object msg) { +// if (msg instanceof LinkResponse) { +// LinkResponse linkResponse = (LinkResponse) msg; +// //TODO 濡傛灉閰嶇疆浠庣綉鍏崇殑淇℃伅锛岄�氳繃涓荤綉鍏宠浆杈撅紝杩欓噷oid瑕佸垽鏂笅 +// String body = getZigbeeData(responeTopic, linkResponse); +// if (null != body) { +// isCallBack[0] = true; +// removeListener(tempTopicReply, this); +// if (null != zigbeeCallBack) { +// zigbeeCallBack.onSuccess(body); +// } +// } +// } +// } +// }; +// //娉ㄥ唽鐩戝惉 +// registerListener(tempTopicReply, eventListener); +// +// //涓�瀹氭椂闂村悗杩樻病鏈夋帴鏀跺埌鏁版嵁锛屽氨鍥炶皟澶辫触 +// ScheduledExecutorService scheduledExecutorService = ThreadToolUtils.getInstance().newScheduledThreadPool(1); +// scheduledExecutorService.schedule(new Runnable() { +// @Override +// public void run() { +// removeListener(tempTopicReply, eventListener); +// scheduledExecutorService.shutdownNow(); +// if (!isCallBack[0]) { +// if (null != zigbeeCallBack) { +// zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_Zigbee_FAILURE_ERROR)); +// } +// } +// } +// }, 5, TimeUnit.SECONDS); +// +// //鏈湴鍙戦�� +// LinkRequest request = new LinkRequest(tempTopic, payload, gatewayBean.getIsLocalEncrypt()); +// new HDLConnectHelper(gatewayBean.getIp_address(), request,true).send(); +// } else { +// //璇锋眰涓婚 +// String tempTopic = null; +// //鍥炲涓婚 +// String tempTopicReply = null; +// +// //杩滅▼鍙戦�� +// if ("true".equals(gatewayBean.getMaster())) { +// tempTopic = String.format("/user/%s/custom/native/zigbee/down", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId()); +// tempTopicReply = String.format("/user/%s/custom/native/zigbee/up", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId()); +// } else { +// tempTopic = String.format("/user/%s/custom/native/zigbee/slaveoid/%s/down", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId(), gatewayOidOrGatewayId); +// tempTopicReply = String.format("/user/%s/custom/native/zigbee/slaveoid/%s/up", com.hdl.sdk.link.core.config.HDLLinkConfig.getInstance().getGatewayId(), "+"); +// } +// //TODO 鍚庣画瀹屽杽浜戠鐨勫彂閫佹帴鏀舵柟娉� +// } + } + + + /** + * 澶勭悊zigbee鍥炲鐨勬暟鎹� + * + * @param responeTopic 鍥炲涓婚 + * @param linkResponse 鍥炲鐨勯�忎紶鏁版嵁 + */ + private static String getZigbeeData(String responeTopic, LinkResponse linkResponse) { + //涓婚涓虹┖涓嶅鐞� + if(TextUtils.isEmpty(responeTopic)){ + return null; + } + + String body = linkResponse.getData(); + int index = body.indexOf("{"); + //zigbee鍥炲鐨勬暟鎹墠鏈変富棰橈紝鍚庨潰鎵嶆槸鏁版嵁 + if (index <= 0) + return null; + + String zigbeeTopic = body.substring(0, index).trim(); + //zigbee鐨勮礋杞芥暟鎹� + String bodyData = body.substring(index); + + //涓嶆槸褰撳墠璇锋眰鐨勬暟鎹紝涓嶅鐞� + if (!zigbeeTopic.startsWith(responeTopic)) { + return null; + } + + return bodyData; + //Zigbee浠ュ墠鐨勬帴鏀堕�昏緫 +// HdlZbGatewayReceiveLogic.Current.ZigbeeOldReceiveLogic(reportTopic, bodyData, gatewayMac); + } + + /** + * 娉ㄥ唽鐩戝惉 + */ + static void registerListener(String responseTopic, EventListener eventListener) { + if (!TextUtils.isEmpty(responseTopic)) { + EventDispatcher.getInstance().register(responseTopic, eventListener); + } + } + + /** + * 绉婚櫎鐩戝惉 + */ + static void removeListener(String responseTopic, EventListener eventListener) { + if (!TextUtils.isEmpty(responseTopic)) { + EventDispatcher.getInstance().remove(responseTopic, eventListener); + } + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/MqttHelper.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/MqttHelper.java new file mode 100644 index 0000000..5fcecee --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/MqttHelper.java @@ -0,0 +1,8 @@ +package com.hdl.sdk.link.core.connect; + +/** + * Created by hxb on 2022/1/6. + */ +public class MqttHelper { + //TODO 鍚庣画寮�鍙戣繙绋嬭闃呮秷鎭敤 +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java new file mode 100644 index 0000000..0eb18b3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java @@ -0,0 +1,315 @@ +package com.hdl.sdk.link.core.protocol; + + +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.utils.ByteUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.core.bean.LinkPacket; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.utils.ByteBufferUtils; +import com.hdl.sdk.link.core.utils.QueueUtils; +import com.hdl.sdk.link.socket.bean.Packet; +import com.hdl.sdk.link.socket.codec.ByteToMessageDecoder; + +import java.nio.ByteBuffer; + +/** + * Created by Tong on 2021/9/22. + * link鍗忚绮樺寘鎷嗗寘 + */ +public class LinkMessageDecoder extends ByteToMessageDecoder<LinkResponse> { + + /** + * 鎺ユ敹鏁版嵁缂撳啿鍖� + */ + private final ByteBuffer byteBuffer; + + private final byte[] head = "Topic:".getBytes(); + + public LinkMessageDecoder() { + byteBuffer = ByteBuffer.allocate(1024 * 200);//100K + } + + /// <summary> + /// 鑾峰彇鍐呭闀垮害 + /// </summary> + /// <param name="topMsgs"></param> + /// <returns></returns> + int getLenght(String[] topMsgs) { + try { + for (int i = 0; i < topMsgs.length; i++) { + String topMsg = topMsgs[i].trim(); + if (topMsg.startsWith("Length:")) { + return Integer.parseInt(topMsg.replace("Length:", "").trim()); + } + } + } catch (Exception e) { + LogUtils.e("寮傚父鏁版嵁锛�" + topMsgs[0] + "\r\n" + topMsgs[1]); + return -1; + } + //鎵句笉鍒伴暱搴� + return -1; + } + + /// <summary> + /// 鑾峰彇涓婚 + /// </summary> + /// <param name="topMsgs"></param> + /// <returns></returns> + private String getTopic(String[] topMsgs) { + for (int i = 0; i < topMsgs.length; i++) { + String topMsg = topMsgs[i].trim(); + if (topMsg.startsWith("Topic:")) { + return topMsg.replace("Topic:", ""); + } + } + //鎵句笉鍒颁富棰� + return null; + } + + /** + * 鑾峰彇鏁版嵁鐨勫紑濮嬩綅缃� + * + * @return 鏁版嵁浣嶇殑寮�濮嬬储寮� + */ + int getBodyIndex() { + byte r = (byte) '\r'; + byte n = (byte) '\n'; + for (int i = 0; i < byteBuffer.position(); i++) { + //鎵惧嚭鏁版嵁鍐呭鍓嶉潰鐨勪袱涓崲琛� + if (3 <= i && byteBuffer.get(i - 3) == r && byteBuffer.get(i - 2) == n && byteBuffer.get(i - 1) == r && byteBuffer.get(i) == n) { + //鍓╀綑鐨勬暟鎹� + return i + 1; + } + } + return -1; + } + + /** + * 鑾峰彇澶撮儴鏁版嵁 + * + * @return + */ + String getHeader() { + int bodyIndex = getBodyIndex(); + if (bodyIndex < 0) { + //娌℃湁鎵惧埌澶撮儴鏁版嵁 + return null; + } else { + byte bodyBytes[] = ByteBufferUtils.copyBytes(byteBuffer, bodyIndex); + return new String(bodyBytes); + } + } + + /** + * 鑾峰彇鏁版嵁鍐呭 + * + * @param lenght + * @return + */ + byte[] getBody(int index, int lenght) { + //鏄惁宸茬粡鑾峰彇瀹屾暣鎵�鏈夌殑鏁版嵁 + byte[] bodyBytes = new byte[lenght]; + if (index < 0 || byteBuffer.position() < index + lenght) { + //褰撳墠鏁版嵁杩樻病鏈夋帴鏀跺畬鎴� + return null; + } + + for (int i = 0; i < bodyBytes.length; i++) { + bodyBytes[i] = byteBuffer.get(index + i); + } + return bodyBytes; + } + + + /** + * 杩欒竟澶勭悊浜嗙紦瀛樻暟鎹矘鍖呯殑鎯呭喌锛屾瘡娆¤姹傞兘闇�瑕佸惂褰撳墠瀹屾暣鐨勬枃浠堕櫎鍘� 浠ヤ究浜庝笅娆$殑杩斿洖 + * tempList鐢ㄤ簬瀛樺偍澶氫綑鐨勬暟鎹� + * contentList鐢ㄤ簬鏈鏁版嵁鐨勫瓨鍌紙鍙戦�佺粰璁㈤槄鐨勬暟鎹級 + */ + byte[] geBody() { + int len = 3 + 4 + 4 + ((byteBuffer.get(7) & 0xFF) * 256 * 256 * 256) + ((byteBuffer.get(8) & 0xFF) * 256 * 256) + ((byteBuffer.get(9) * 256) & 0xFF) + (byteBuffer.get(10) & 0xFf); + byte[] bodyBytes = new byte[len]; + for (int i = 0; i < len; i++) { + bodyBytes[i] = byteBuffer.get(i); + } + + int endIndex = byteBuffer.position(); + byteBuffer.clear(); + for (int i = len; i < endIndex; i++) { + byteBuffer.put(byteBuffer.get(i)); + } + return bodyBytes; + } + + /** + * 绉婚櫎鍙兘瀛樺湪鐨勬棤鏁堟暟鎹� + */ + void removeInVoidBytes() { + int index = 0; + boolean isMatch = false; + for (; index < byteBuffer.position() - head.length; index++) { + isMatch = true; + for (int j = 0, k = 0; j < head.length; j++, k++) { + if (head[j] != byteBuffer.get(index + k)) { + isMatch = false; + break; + } + } + if (isMatch) { + break; + } + } + + if (0 < index && isMatch) { + int endIndex = byteBuffer.position(); + byteBuffer.flip(); + for (int i = index; i < endIndex; i++) { + byteBuffer.put(byteBuffer.get(i)); + } + } + } + + /** + * 绉婚櫎鍒版寚瀹氫綅缃墠闈㈢殑鏁版嵁 + * + * @param position 鎸囧畾浣嶇疆 + */ + void remove(int position) { + int endIndex = byteBuffer.position(); + byteBuffer.clear(); + for (int i = position; i < endIndex; i++) { + byteBuffer.put(byteBuffer.get(i)); + } + } + + void fileManger(int commandAck, byte[] recevieBytes) { + String topic = "65531_" + commandAck; + LinkResponse response = new LinkResponse(); + response.setTopic(topic); + response.setByteData(recevieBytes); + EventDispatcher.getInstance().post(response.getTopic(), response); + } + + int bytes2int(byte[] bytes) { + int result = 0; + if (bytes.length == 2) { + int c = (bytes[0] & 0xff) << 8; + int d = (bytes[1] & 0xff); + result = c | d; + } else if (bytes.length == 4) { + return bytes[3] & 0xFF | // + (bytes[2] & 0xFF) << 8 | // + (bytes[1] & 0xFF) << 16 | // + (bytes[0] & 0xFF) << 24; // + } + return result; + } + + public String byte2hex(byte[] bytes) { + StringBuilder sb = new StringBuilder(); + String tmp = null; + for (byte b : bytes) { + //灏嗘瘡涓瓧鑺備笌0xFF杩涜涓庤繍绠楋紝鐒跺悗杞寲涓�10杩涘埗锛岀劧鍚庡�熷姪浜嶪nteger鍐嶈浆鍖栦负16杩涘埗 + tmp = Integer.toHexString(0xFF & b); + if (tmp.length() == 1) { + tmp = "0" + tmp; + } + sb.append(tmp + " "); + } + return sb.toString(); + } + + @Override + protected synchronized LinkResponse decoder(Packet packet) { + try { + if (null == packet) { + return null; + } + byteBuffer.put(packet.getBytes()); +// LogUtils.i("鎺ユ敹缂撳啿鍖篵yteBuffer澶у皬锛�" + byteBuffer.position()); + } catch (Exception e) { + LogUtils.e("鎺ユ敹鍒版暟鎹紓甯�:\r\n" + e.getMessage()); + byteBuffer.flip(); + } + + managerPacket(packet); + return null; + } + + /** + * 澶勭悊鎺ユ敹鐨勬暟鎹� + */ + void managerPacket(Packet packet){ + try { + //濡傛灉澶氭潯鍛戒护鎵撳寘鍦ㄤ竴鏉℃暟鎹腑锛岄兘闇�瑕佸鐞嗗畬 + while (true) { +// if (byteBuffer.position() > 2) {//鍒ゆ柇鏄惁鏄枃浠跺鐞嗛�氱煡 wxr +// byte[] topBytes = new byte[3]; +// topBytes[0] = byteBuffer.get(0); +// topBytes[1] = byteBuffer.get(1); +// topBytes[2] = byteBuffer.get(2); +// if (new String(topBytes).equals("hex")) { +// //TODO 杩欏潡浠g爜缁熶竴绉诲嚭鍏跺畠鍦版柟澶勭悊 +// byte[] commandBytes = ByteBufferUtils.copyBytes(byteBuffer, 5, 2); +// int command = bytes2int(commandBytes); +// byte[] submitBytes = geBody(); +// if (command == 258 || command == 260 || command == 261) { +// //璇诲彇椹卞姩鍒楄〃鍝嶅簲 ||椹卞姩瀹夎鐢宠鍝嶅簲 +// if (submitBytes.length > 11) { +// byte[] rangeBytes = ByteUtils.copyBytes(submitBytes, 11, submitBytes.length - 11); +// fileManger(command, rangeBytes); +// } else { +// //鏂逛究闂鎺掓煡 +// fileManger(command, submitBytes); +// } +// } else { +// //缁欑妗′娇鐢� 鍚庨潰鐨勪笟鍔℃渶濂介兘鍦ㄨ繖杈瑰鐞� 涓嶇劧浼氶�犳垚涓氬姟鍒嗘暎 +// fileManger(command, submitBytes); +// } +// continue; +// } +// } + removeInVoidBytes();//绉婚櫎鍙兘瀛樺湪鐨勬棤鏁堟暟鎹� + + //澶撮儴鏁版嵁 + String header = getHeader(); + + if (header == null) { + break; + } + String[] topMsgs = header.split("\r\n"); + + String topic = getTopic(topMsgs); + int lenght = getLenght(topMsgs); + if (topic == null || lenght <= 0) { + //鑾峰彇涓嶅埌涓婚鎴栬�呭ご閮ㄦ暟鎹繕娌℃湁鎺ユ敹瀹屾垚 + break; + } + + int bodyIndex = getBodyIndex(); + //鏄惁宸茬粡鑾峰彇瀹屾暣鎵�鏈夌殑鏁版嵁 + byte[] body = getBody(bodyIndex, lenght); + + if (body == null) { + //褰撳墠鏁版嵁杩樻病鏈夋帴鏀跺畬鎴� + break; + } + + remove(bodyIndex + lenght); + + //鍏煎缃戝叧蹇冭烦鍔熻兘锛岃�佺増鏈綉鍏充笉鍥炲蹇冭烦锛屽洖澶嶆椂鎵嶆墦寮�蹇冭烦妫�娴� + if (topic.contains("heartbeat_reply")) { + if (packet.getSocket() != null) { + packet.getSocket().setSoTimeout(10 * 1000); + } + continue; + } + + QueueUtils.getInstance().add(new LinkPacket(topic, body, packet.getIpAddress())); + } + } catch (Exception ee) { + LogUtils.e("澶勭悊鎺ユ敹鐨勬暟鎹紓甯�:\r\n" + ee.getMessage()); + } + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java new file mode 100644 index 0000000..d09e37a --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java @@ -0,0 +1,18 @@ +package com.hdl.sdk.link.core.protocol; + + +import com.hdl.sdk.link.socket.bean.Packet; +import com.hdl.sdk.link.socket.codec.MessageToByteEncoder; + +/** + * Created by Tong on 2021/9/22. + * link鍗忚鍚堝寘 + */ +public class LinkMessageEncoder extends MessageToByteEncoder { + + @Override + protected Packet encode(Packet packet) throws Exception { + return packet; + } + +} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/AesUtil.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java similarity index 97% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/AesUtil.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java index 53d8ca5..0458a61 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/AesUtil.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java @@ -1,7 +1,8 @@ -package com.hdl.sdk.connect.utils; +package com.hdl.sdk.link.core.utils; -import com.hdl.sdk.common.utils.LogUtils; + +import com.hdl.sdk.link.common.utils.LogUtils; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java new file mode 100644 index 0000000..99e1e5d --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java @@ -0,0 +1,37 @@ +package com.hdl.sdk.link.core.utils; + +import java.nio.ByteBuffer; + +/** + * Created by hxb on 2022/8/3. + * + */ +public class ByteBufferUtils { + + /** + * 鑾峰彇ByteBuffer鎸囧畾浣嶇疆鏁版嵁 + * + * @param byteBuffer 婧愬璞� + * @param length 鎸囧畾闀垮害 + * @return 鏍规嵁闀垮害鐢熸垚鐨勬暟缁� + */ + public static byte[] copyBytes(ByteBuffer byteBuffer, int length) { + return copyBytes(byteBuffer,0,length); + } + + /** + * 澶嶅埗鎸囧畾浣嶇疆鐨勬暟鎹� + * @param byteBuffer + * @param index + * @param length + * @return + */ + public static byte[] copyBytes(ByteBuffer byteBuffer, int index,int length) { + byte[] bytes = new byte[length]; + for (int i = 0; i < bytes.length; i++) { + bytes[i] = byteBuffer.get(index + i); + } + return bytes; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java new file mode 100644 index 0000000..a2e095e --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java @@ -0,0 +1,20 @@ +package com.hdl.sdk.link.core.utils; + +/** + * Created by hxb on 2022/8/5. + */ +public class ByteUtils { + + public static String encodeHexString(byte[] data) { + + StringBuilder sb = new StringBuilder(); + + for (byte b : data) { + + sb.append(String.format("%02x ", b)); + + } + return sb.toString(); + + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java new file mode 100644 index 0000000..3a22ec5 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java @@ -0,0 +1,55 @@ +package com.hdl.sdk.link.core.utils; + +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.utils.ByteUtils; + +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.config.HDLLinkConfig; + +/** + * Created by hxb on 2021/12/23. + */ +public class EncryptUtil { + /** + * 鑾峰彇鍔犲瘑鏁版嵁 + * + * @param linkRequest 璇锋眰鏁版嵁 + * @return + */ + public static byte[] getEncryBytes(LinkRequest linkRequest) { + try { + //鍒ゆ柇鏄惁闇�瑕佸姞瀵� + + if (ifNeedEncrypt(linkRequest.getTopic(), linkRequest.isEncrypt())) { + //闇�瑕佸姞瀵� + byte[] dataBytes = AesUtil.aesEncrypt(linkRequest.getData(), HDLLinkConfig.getInstance().getLocalSecret()); + String headString = "Topic:" + linkRequest.getTopic() + "\r\n" + "Length:" + dataBytes.length + "\r\n" + "\r\n"; + byte[] headBytes = headString.getBytes("utf-8"); + byte[] sendBytes = ByteUtils.concatBytes(headBytes, dataBytes); + return sendBytes; + } else { + return linkRequest.getSendBytes(); + } + + } catch (Exception e) { + return new byte[]{}; + } + } + + /** + * 鍒ゆ柇褰撳墠涓婚鏁版嵁鏄惁闇�瑕佸姞瀵� + * + * @param topicStr 褰撳墠涓婚 + * @return + */ + public static boolean ifNeedEncrypt(String topicStr, boolean isLocalEncrypt) { + //杩囨护鐩稿叧闇�瑕佸姞瀵嗙殑涓婚 + return (!topicStr.contains(TopicConstant.GATEWAY_AUTH_BROADCAST) //缃戝叧骞挎挱鍏ョ綉鎸囦护 + && !topicStr.contains(TopicConstant.DEIVCE_AUTH_REQUEST) //鍏ョ綉璁よ瘉 + && !topicStr.contains(TopicConstant.GATEWAY_SEARCH) //鎼滅储缃戝叧涓婚 + && !topicStr.contains(TopicConstant.GATEWAY_SEARCH_REPLY) //鎼滅储缃戝叧涓婚鍥炲 + && !topicStr.equals(TopicConstant.BROADCAST) + && isLocalEncrypt//鍚敤鍔犲瘑鏍囧織 + ); + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java new file mode 100644 index 0000000..216d380 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java @@ -0,0 +1,49 @@ +package com.hdl.sdk.link.core.utils; + + +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; + +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.config.HDLLinkConfig; + +import java.lang.reflect.Type; + +/** + * Created by jlchen on 1/6/22. + */ +public class LinkResponseUtils<T> { + + public Type getType(){ + return new TypeToken<BaseLocalResponse<T>>() {}.getType(); + } + + /** + * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects + * + * @param msg + * @return + */ + public static <T> T convertLinkResponse(Object msg, Type type) { + T bean = null; + if (msg != null && msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + try { + final BaseLocalResponse<T> response = GsonConvert.getGson().fromJson(data, type); + if (response != null) { + bean = response.getObjects(); + } + } catch (Exception e) { + LogUtils.e("convertLinkResponse catch:" + e.getMessage()); + } + } + } + return bean; + } +} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/ProtocolParse.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java similarity index 94% rename from HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/ProtocolParse.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java index 792eddc..6a715ff 100644 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/utils/ProtocolParse.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java @@ -1,6 +1,7 @@ -package com.hdl.sdk.connect.utils; +package com.hdl.sdk.link.core.utils; -import com.hdl.sdk.common.utils.TextUtils; + +import com.hdl.sdk.link.common.utils.TextUtils; /** * Created by Tong on 2021/9/22. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java new file mode 100644 index 0000000..19c114e --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java @@ -0,0 +1,133 @@ +package com.hdl.sdk.link.core.utils; + + +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.core.bean.LinkPacket; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + + +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.LinkedList; +import java.util.Queue; +import java.util.concurrent.ExecutorService; + +/** + * Created by hxb on 2022/8/4. + */ +public class QueueUtils { + + //杩樻病瑙e瘑鐨勬暟鎹寘 + private final Queue<LinkPacket> linkPackets; + private final ExecutorService executorService; + //鏄惁宸茬粡鍚姩 + private boolean started; + /** + * instance + */ + private volatile static QueueUtils instance; + + private QueueUtils() { + linkPackets = new LinkedList<>(); + executorService = ThreadToolUtils.getInstance().newFixedThreadPool(1); + } + + /** + * getInstance + * + * @return AuthenticateConfig + */ + public static synchronized QueueUtils getInstance() { + if (instance == null) { + synchronized (QueueUtils.class) { + if (instance == null) { + instance = new QueueUtils(); + } + } + } + return instance; + } + + /** + * 澧炲姞鎺ユ敹鍒扮殑姣忔潯鏁版嵁 + * + * @param linkPacket + */ + public void add(LinkPacket linkPacket) { + synchronized (linkPackets) { + linkPackets.add(linkPacket); + } + } + + public LinkPacket poll() { + synchronized (linkPackets) { + return linkPackets.poll(); + } + } + + /** + * 鍚姩澶勭悊鎺ユ敹鍒扮殑鏁版嵁 + */ + public synchronized void start() { + if (started) { + return; + } + started = true; + executorService.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + LinkPacket linkPacket = poll(); + if (linkPacket == null) { + Thread.sleep(10); + continue; + } + + manager(linkPacket); + } catch (Exception e) { + LogUtils.e("澶勭悊鎺ユ敹鍒扮殑鏁版嵁寮傚父:\r\n" + e.getMessage()); + } + } + } + }); + } + + private void manager(LinkPacket linkPacket) throws UnsupportedEncodingException { + + LinkResponse response = new LinkResponse(); + response.setTopic(linkPacket.getTopic()); + + if (encrypt(linkPacket.getBody())) { + //闇�瑕佽В瀵� + byte[] bodyBytes = AesUtil.aesDecrypt(linkPacket.getBody(), HDLLinkConfig.getInstance().getLocalSecret()); + if (bodyBytes != null) { + response.setData(new String(bodyBytes, StandardCharsets.UTF_8)); + } else { + LogUtils.e("瑙e瘑澶辫触\r\n" + linkPacket.getTopic() + "\r\n" + ByteUtils.encodeHexString(linkPacket.getBody())); + response.setData(new String(linkPacket.getBody(), "utf-8")); + } + } else { + response.setData(new String(linkPacket.getBody(), "utf-8")); + } + + LogUtils.i("鎺ユ敹鍒版暟鎹�:\r\n" + response.getTopic() + "\r\n" + response.getData()); + //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� + EventDispatcher.getInstance().post(response.getTopic(), response); + } + + //鏄惁鍔犲瘑 + private boolean encrypt(byte []bytes) { + if (bytes[0] == '{' && bytes[bytes.length - 1] == '}' || (bytes[0] == '[' && bytes[bytes.length - 1] == ']')) { + return false; + } + return true; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java new file mode 100644 index 0000000..63cd018 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java @@ -0,0 +1,531 @@ +package com.hdl.sdk.link.gateway; + + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.IpUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; + +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by hxb on 2021/12/23. + */ +public class HDLLinkLocalGateway { + //instance + private volatile static HDLLinkLocalGateway instance; + + //getInstance + public static synchronized HDLLinkLocalGateway getInstance() { + if (instance == null) { + synchronized (HDLLinkLocalGateway.class) { + if (instance == null) { + instance = new HDLLinkLocalGateway(); + } + } + } + return instance; + } + + /** + * 缃戝叧鍒楄〃锛岃褰曟墍鏈夋悳绱㈠埌鐨勭綉鍏筹紝鍙兘鍖呭惈鏂嚎鐨勭綉鍏� + */ + private final List<GatewayBean> gatewayBeanList = new ArrayList(); + + /** + * 鑾峰彇缂撳瓨鐨勭綉鍏冲垪琛紝鍙兘鍖呭惈鏂嚎鐨勭綉鍏� + * + * @return 缃戝叧鍒楄〃 + */ + public List<GatewayBean> getGatewayList() { + return gatewayBeanList; + } + + /** + * 閫氳繃oid鎴栬�呯綉鍏矷D鎴栬�匒MC鑾峰彇鍐呭瓨涓殑缃戝叧 + * + * @param oidOrGatewayId + * @return + */ + public GatewayBean getGatewayByOidOrGatewayId(String oidOrGatewayId) { + if (TextUtils.isEmpty(oidOrGatewayId)) { + return null; + } + for (GatewayBean gatewayBean : gatewayBeanList) { + if (oidOrGatewayId.equals(gatewayBean.getOid()) + || oidOrGatewayId.equals(gatewayBean.getGatewayId()) + || oidOrGatewayId.equals(gatewayBean.getDevice_mac()) + || oidOrGatewayId.equals(gatewayBean.getIp_address()) + ) + return gatewayBean; + } + return null; + } + + /** + * 閫氳繃IP鑾峰彇缃戝叧淇℃伅 + * + * @param ipAddress + * @return + */ + public GatewayBean getGatewayByIpAddress(String ipAddress) { + if (TextUtils.isEmpty(ipAddress)) { + return null; + } + for (GatewayBean gatewayBean : gatewayBeanList) { + if (ipAddress.equals(gatewayBean.getIp_address())) + return gatewayBean; + } + return null; + } + + /** + * 鎼滅储缃戝叧锛屽彧鍙戜竴娆★紝娌℃湁鍥炶皟 + */ + public void serchGatewayOneTime() { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + LinkRequest message = new LinkRequest(TopicConstant.GATEWAY_SEARCH, + jsonObject.toString(), false); + + String ipAddress = IpUtils.getBroadcastAddress(); + new HDLConnectHelper(1, ipAddress, message, false).send(); + } + + /** + * 鍒涙柊鎵�鏈夊湪绾跨殑缃戝叧锛屽寘鎷綋鍓嶄綇瀹呯殑鍙婃病鏈夌粦瀹氳繃鐨勭綉鍏� + * + * @param callBack 鍥炶皟 + */ + public void refreshGatewayByHome(String homeId, GatewayCallBack callBack) { + refreshGatewayByHome(homeId,callBack,false); + } + + /** + * 鍒涙柊鎵�鏈夊湪绾跨殑缃戝叧锛屽寘鎷綋鍓嶄綇瀹呯殑鍙婃病鏈夌粦瀹氳繃鐨勭綉鍏� + * + * @param callBack 鍥炶皟 + */ + public void refreshGatewayByHome(String homeId, GatewayCallBack callBack,boolean needOldGateway) { + + String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; + final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); + EventListener eventListener = getSearchGatewayEvent(homeId, 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 && needOldGateway) { + for (int i = 0; i < gatewayBeanList.size(); i++) { + if (homeId.equals(gatewayBeanList.get(i).getHomeId())) { + tempGatewayBeanList.add(gatewayBeanList.get(i)); + } + } + } + if (tempGatewayBeanList.size() == 0) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_GATEWAY_FAILURE_ERROR)); + } else { + callBack.onSuccess(tempGatewayBeanList); + } + } + } + }); + } + + /** + * 鍒涙柊鎵�鏈夊湪绾跨殑缃戝叧锛屽寘鎷綋鍓嶄綇瀹呯殑鍙婃病鏈夌粦瀹氳繃鐨勭綉鍏� + * + * @param callBack 鍥炶皟 + */ + public void refreshGateway(GatewayCallBack callBack) { + + String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; + final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); + EventListener eventListener = getSearchGatewayEvent(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 + * @return + */ + private EventListener getSearchGatewayEvent(String homeId, 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 (homeId.equals(gateway.getHomeId()) || TextUtils.isEmpty(gateway.getHomeId())) { + //鏇存柊缂撳瓨缃戝叧锛屼細璁板綍鎵�鏈夋敹鍒扮殑缃戝叧锛屼互涓轰簡淇濆瓨缃戝叧鐨処P淇℃伅 + updateGatewayList(gatewayBeanList, gateway); + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + updateGatewayList(tempGatewayBeanList, gateway); + } + } + }; + } + + /** + * 鑾峰彇鎼滅储缃戝叧浜嬩欢 杩欒竟涓嶈繃婊omeId + * + * @return + */ + private EventListener getSearchGatewayEvent(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.setIsLocalGateWay(true);//鏈湴鎼滅储鍒扮殑缃戝叧鏍囪瘑涓烘湰鍦扮綉鍏� + //鍗囩骇缃戝叧椹卞姩 闇�瑕佹樉绀烘墍鏈夌綉鍏� + //鈿狅笍杩欒竟涓嶉渶瑕佹坊鍔犲埌gatewayBeanList 鍥犱负杩欎釜鏄綉鍏崇绾垮崌绾х殑鏃跺�欑殑鍔熻兘 +// updateGatewayList(gatewayBeanList, gateway); + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + updateGatewayList(tempGatewayBeanList, gateway); + } + }; + } + + /** + * 鏇存柊鏀跺埌鐨勭綉鍏冲埌鍒楄〃 + * + * @param gatewayBeanList + * @param gateway 褰撳墠鏀跺埌鐨勭綉鍏� + */ + void updateGatewayList(final List<GatewayBean> gatewayBeanList, GatewayBean gateway) { + boolean isFound = false;//鏄惁鍦ㄥ唴瀛樹腑鎵惧埌缃戝叧瀵硅薄 + //鎵惧嚭mac涓�鏍风殑缃戝叧鏇存柊鏈�鏂版暟鎹� + for (int i = 0; i < gatewayBeanList.size(); i++) { + if (gatewayBeanList.get(i).getOid().equals("")) + continue; + if (gatewayBeanList.get(i).getOid().equals(gateway.getOid())) { + isFound = true; + gatewayBeanList.set(i, gateway); +// break; + } + } + + //娓呴櫎oid涓�鏍凤紝mac涓嶄竴鏍风殑缃戝叧缂撳瓨銆備竴鑸槸鍦ㄧ綉鍏虫浛鎹㈢殑鎯呭喌绌洪棿鍑虹幇 + for (int i = 0; i < gatewayBeanList.size(); i++) { + if (gatewayBeanList.get(i).getOid().equals("")|| gatewayBeanList.get(i).getDevice_mac().equals("")) + continue; + if (gatewayBeanList.get(i).getOid().equals(gateway.getOid()) && !gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac()) + || gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac()) && !gatewayBeanList.get(i).getOid().equals(gateway.getOid())) { + gatewayBeanList.remove(i--); + } + } + + //娌℃湁鎵惧埌灏辨坊鍔� + if (!isFound) { + gatewayBeanList.add(gateway); + } + } + + /** + * 鑾峰彇缃戝叧瀵硅薄 + * + * @param linkResponse + * @return + */ + private GatewayBean getGatewayBeanByResponse(LinkResponse linkResponse) { + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + final BaseLocalResponse<GatewayBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewayBean>>() { + }.getType()); + return response.getObjects(); + } + return null; + } + + /* + * 缁戝畾缃戝叧 + * */ + public void bindGateway(String name, String mac, String homeId, String regionUrl, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_EDIT_REMOTE, mac); + + JsonObject jObject = new JsonObject(); + jObject.addProperty("homeId", homeId); + jObject.addProperty("server_addr", regionUrl); +// jObject.addProperty("device_name", name); + jObject.addProperty("remote", "true"); + + 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, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + } + }, true).send(); + } + + /* + * 鍒濆鍖栫綉鍏� + * */ + public void initializeGateway(String mac, String oid, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_INITIALIZE_REMOTE, oid); + + 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("device_mac", mac); + sendJsonObj.add("objects", jObject); + String sendStr = sendJsonObj.toString(); + + LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); + new HDLConnectHelper(ip, message, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + } + }, true).send(); + } + + /* + * 璁剧疆涓讳粠缃戝叧鏍囪 + * */ + public void setMasterGateway(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, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + } + }, true).send(); + } + + /** + * 璁剧疆缃戝叧鍏ョ綉浠庢満妯″紡 + */ + public void AuthGateway(String ip, String mac) { + 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("time", "120"); + sendJsonObj.add("objects", jObject); + + + String sendStr = sendJsonObj.toString(); + LinkRequest message = new LinkRequest(topic, sendStr, false); + new HDLConnectHelper(ip, message, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + } + + @Override + public void onFailure() { + } + }, true).send(); + } + + /* + * 鑾峰彇缃戝叧淇℃伅 + * */ + public void getGatewayInfo(String ip, String mac, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_GET, mac); + + JsonObject sendJsonObj = new JsonObject(); + 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, topic + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + } + }, true).send(); + } + + + + /** + * 鍙戦�佹暟鎹埌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); + System.out.print("sendDataToLinkGateway->"+sendPath+"->鏈湴鍙戦�乗r\n"+topicSend+"\r\n"+sendStr); + LinkRequest message = new LinkRequest(topicSend, sendStr, isEncrypt); + new HDLConnectHelper(ip, message, topicSend + "_reply", new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess(msg.toString()); + System.out.print("sendDataToLinkGateway->"+sendPath+"->鏈湴鎺ユ敹鏁版嵁\r\n"+msg.toString()); + } + + @Override + public void onFailure() { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_TIMEOUT_ERROR)); + System.out.print("sendDataToLinkGateway->"+sendPath+"->鏈湴鎺ユ敹鏁版嵁->澶辫触(-200)"); + } + }, true).send(); + } + + /** + * 缁勮闇�瑕佸彂閫佺殑鏁版嵁 + * + * @param jObject + * @return 璐熻浇鏁版嵁<娌℃湁濉玭ull> + */ + public String createSendData(Object jObject) { + //topic = String.format(TopicConstant.GATEWAY_EDIT_LOCAL, mac); + JsonObject sendJsonObj = new JsonObject(); + if (jObject != null) { + if (jObject instanceof JsonObject) { + sendJsonObj.add("objects", (JsonObject) jObject); + } else if (jObject instanceof JsonArray) { + sendJsonObj.add("objects", (JsonArray) jObject); + } + } + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + String sendStr = sendJsonObj.toString(); + return sendStr; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java new file mode 100644 index 0000000..f0a02e3 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java @@ -0,0 +1,10 @@ +package com.hdl.sdk.link.gateway.bean; + +import java.io.Serializable; + +/** + * Created by jlchen on 12/16/21. + */ +public class GatewaySearchBean implements Serializable { + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java new file mode 100644 index 0000000..5cb1b77 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java @@ -0,0 +1,18 @@ +package com.hdl.sdk.link.gateway.type; + + +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.SOURCE; + +/** + * Created by jlchen on 12/30/21. + */ +public class GatewayMasterType { + //涓荤綉鍏� + public final String MasterTrue = "true"; + //浠庣綉鍏� + public final String MasterFalse = "false"; + //鏈厤缃� + public final String NO_CONFIG = "no_config"; +} \ No newline at end of file diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketOptions.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java similarity index 89% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketOptions.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java index 429d646..d92529a 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketOptions.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java @@ -1,10 +1,9 @@ -package com.hdl.sdk.socket; +package com.hdl.sdk.link.socket; -import com.hdl.sdk.socket.codec.IHandleMessage; -import com.hdl.sdk.socket.listener.ConnectStatusListener; +import com.hdl.sdk.link.socket.codec.IHandleMessage; +import com.hdl.sdk.link.socket.listener.ConnectStatusListener; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketPool.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java similarity index 64% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketPool.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java index 41e2763..79e11f6 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketPool.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java @@ -1,6 +1,6 @@ -package com.hdl.sdk.socket; +package com.hdl.sdk.link.socket; -import com.hdl.sdk.socket.client.IClient; +import com.hdl.sdk.link.socket.client.IClient; import java.net.DatagramSocket; import java.net.InetSocketAddress; @@ -21,10 +21,13 @@ mUdpClientPool = new ConcurrentHashMap<>(); } - private static final SocketPool instance = new SocketPool(); + + private static class SingletonInstance { + private static final SocketPool INSTANCE = new SocketPool(); + } public static SocketPool getInstance() { - return instance; + return SingletonInstance.INSTANCE; } public void clear() { @@ -33,19 +36,19 @@ } public synchronized DatagramSocket getUdpSocket(InetSocketAddress address) throws SocketException { - DatagramSocket socket; - final String key = address.toString(); + DatagramSocket socket = null; + final String key = address.getPort() + ""; if (mUdpClientPool.containsKey(key)) { socket = mUdpClientPool.get(key); - if (socket != null && !socket.isClosed()) { - return socket; - } else { - socket = new DatagramSocket(address); + if (socket != null && socket.isClosed()) { + mUdpClientPool.remove(key); + socket = null; } - } else { - socket = new DatagramSocket(address); } - mUdpClientPool.put(address.toString(), socket); + if (socket == null) { + socket = new DatagramSocket(address); + mUdpClientPool.put(key, socket); + } return socket; } } diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketRequest.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java similarity index 93% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketRequest.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java index 924719e..d710ad6 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketRequest.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.socket; +package com.hdl.sdk.link.socket; import java.util.UUID; diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java similarity index 78% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java index 0965fc7..2c21959 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java @@ -1,14 +1,18 @@ -package com.hdl.sdk.socket; +package com.hdl.sdk.link.socket; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.socket.annotation.ConnectStatus; -import com.hdl.sdk.socket.client.IClient; -import com.hdl.sdk.socket.client.IHeartbeat; -import com.hdl.sdk.socket.listener.SendListener; +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.socket.client.IClient; +import com.hdl.sdk.link.socket.client.IHeartbeat; +import com.hdl.sdk.link.socket.listener.SendListener; +import com.hdl.sdk.link.socket.annotation.ConnectStatus; + +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; @@ -18,7 +22,7 @@ * Created by Tong on 2021/9/26. * Tcp/Udp 鍚姩鍣� */ -public class SocketBoot { +public class TcpSocketBoot { private ExecutorService connectThread; private ExecutorService sendThread; @@ -33,8 +37,7 @@ /** * 褰撳墠鎺ユ敹鍒版暟鎹殑鏃堕棿 */ - private static long time=System.currentTimeMillis(); - + private long time=System.currentTimeMillis(); /** * tcp鏄惁宸茬粡杩炴帴 */ @@ -48,12 +51,37 @@ private final Map<String, SendListener> sendMap = new HashMap<>(); - public SocketBoot(IClient client) { + public TcpSocketBoot(IClient client) { + TCP_SOCKET_BOOT_LIST.add(this); this.client = client; initConnectThread(); initReceiveThread(); initSendThread(); initHeartbeat(); + } + + /** + * 璁板綍鎵�鏈塖ocketBoot + */ + 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; + } + for(TcpSocketBoot tcpSocketBoot : TCP_SOCKET_BOOT_LIST){ + if(ipAddress.equals(tcpSocketBoot.getClient().getOptions().getIp())&& tcpSocketBoot.getClient().getOptions().getPort()==port) + { + return tcpSocketBoot; + } + } + return null; } /** @@ -63,13 +91,13 @@ try { LogUtils.i("TCP杩炴帴"); client.onConnectStatus(ConnectStatus.CONNECTING); - Thread.sleep(1000); +// Thread.sleep(700); client.connect(); - connected=true; LogUtils.i("TCP杩炴帴鎴愬姛"); + connected=true; client.onConnectStatus(ConnectStatus.CONNECTED); }catch(Exception e) { - LogUtils.e("杩炴帴寮傚父"+e.getMessage()); + LogUtils.e(e.getMessage()); } } @@ -85,9 +113,11 @@ public void run() { while (true) { try { + if(connected==false){ + Thread.sleep(100); + continue; + } SocketRequest socketRequest = mMessageQueue.take(); -// final String sendStr = new String(socketRequest.getData(), 0, socketRequest.getData().length); -// LogUtils.i("鍙戦�佹暟鎹細" + sendStr); final String action = socketRequest.getAction(); try { client.sendMsg(socketRequest.getData()); @@ -108,7 +138,7 @@ } } } catch (Exception e) { - + LogUtils.e("鍙戦�佸け璐�1:" + e.getMessage()); } } } @@ -163,9 +193,9 @@ if (!connected) { reconect(); } - Thread.sleep(3*1000); + Thread.sleep(5*1000); } catch (Exception e) { - LogUtils.e("瀹氭椂杩炴帴澶辫触:" + e.getMessage()); + } } } @@ -184,14 +214,14 @@ public void run() { while (true) { try { - //10绉� - if (connected && 10 * 1000 < (System.currentTimeMillis() - time)) { + //5绉� + if (connected && 5 * 1000 < (System.currentTimeMillis() - time)) { time = System.currentTimeMillis(); //蹇冭烦妫�娴� if (iHeartbeat != null) iHeartbeat.heartbeat(); } - Thread.sleep(1000); + Thread.sleep(10); } catch (Exception e) { LogUtils.e("瀹氭椂蹇冭烦妫�娴嬬綉鍏冲紓甯革細" + e.getMessage()); } @@ -200,8 +230,6 @@ }); } } - - /** * 閲嶆柊杩炴帴 */ @@ -230,7 +258,7 @@ } mMessageQueue.put(request); } catch (Exception e) { - LogUtils.e("鍙戦�佹暟鎹け璐ワ細" + e.getMessage()); + } } diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/annotation/ConnectStatus.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java similarity index 76% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/annotation/ConnectStatus.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java index 6bdd529..77e7fb5 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/annotation/ConnectStatus.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java @@ -1,5 +1,10 @@ -package com.hdl.sdk.socket.annotation; +package com.hdl.sdk.link.socket.annotation; + + +/** + * Created by Tong on 2021/9/22. + */ /** * Created by Tong on 2021/9/22. */ @@ -20,3 +25,4 @@ */ public static int DISCONNECT = 2; } + diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java new file mode 100644 index 0000000..cf27bb9 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java @@ -0,0 +1,58 @@ +package com.hdl.sdk.link.socket.bean; + +import java.net.Socket; +import java.net.SocketOption; + +/** + * Created by hxb on 2021/12/23. + */ +public class Packet { + private String ipAddress; + private byte []bytes; + private Socket socket; + + public Packet(String ipAddress, byte []bytes, Socket socket){ + this.ipAddress=ipAddress; + this.bytes=bytes; + this.socket=socket; + } + /** + * 鎺ユ敹鎴栬�呭彂閫佺殑IP鍦板潃 + * @return + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * 鎺ユ敹鎴栬�呭彂閫佺殑IP鍦板潃 + * @param ipAddress + */ + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + /** + * 鎺ユ敹鎴栬�呭彂閫佺殑鏁版嵁 + * @return + */ + public byte[] getBytes() { + return bytes; + } + + /** + * 鎺ユ敹鎴栬�呭彂閫佺殑鏁版嵁 + * @param bytes + */ + public void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + public Socket getSocket() { + return socket; + } + + public void setSocket(Socket socket) { + this.socket = socket; + } +} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IClient.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java similarity index 82% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IClient.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java index 3e6a6da..71293d7 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IClient.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java @@ -1,7 +1,7 @@ -package com.hdl.sdk.socket.client; +package com.hdl.sdk.link.socket.client; -import com.hdl.sdk.socket.SocketOptions; +import com.hdl.sdk.link.socket.SocketOptions; /** * Created by Tong on 2021/9/22. diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IHeartbeat.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java similarity index 70% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IHeartbeat.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java index a86a092..9a4e7a4 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IHeartbeat.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.socket.client; +package com.hdl.sdk.link.socket.client; /** * Created by hxb on 2022/2/16. diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IUdpClient.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java similarity index 74% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IUdpClient.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java index 0e6e5d6..7db851e 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/IUdpClient.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java @@ -1,10 +1,6 @@ -package com.hdl.sdk.socket.client; +package com.hdl.sdk.link.socket.client; -import com.hdl.sdk.socket.SocketOptions; -import com.hdl.sdk.socket.udp.UdpSocketOptions; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; +import com.hdl.sdk.link.socket.udp.UdpSocketOptions; /** * Created by hxb on 2021/12/12. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java new file mode 100644 index 0000000..02ff77f --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java @@ -0,0 +1,173 @@ +package com.hdl.sdk.link.socket.client; + + + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.socket.TcpSocketBoot; +import com.hdl.sdk.link.socket.SocketOptions; +import com.hdl.sdk.link.socket.annotation.ConnectStatus; +import com.hdl.sdk.link.socket.bean.Packet; +import com.hdl.sdk.link.socket.codec.IHandleMessage; +import com.hdl.sdk.link.socket.listener.ConnectStatusListener; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.List; + + +/** + * Created by Tong on 2021/9/15. + */ +public final class TcpClient implements IClient { + + + private SocketOptions socketOptions; + + private final String ip; + private final int port; + + private Socket mSocket; + + private byte[] readBuffer = new byte[4*1024]; + + private TcpClient(String ip, int port, SocketOptions socketOptions) { + this.socketOptions = socketOptions; + this.ip = ip; + this.port = port; + socketOptions.setIp(ip); + socketOptions.setPort(port); + } + + public static TcpSocketBoot init(String ip, int port, SocketOptions options) { + return new TcpSocketBoot(new TcpClient(ip, port, options)); + } + + + + + @Override + public void connect() throws Exception { + mSocket = getSocket(); + mSocket.connect(new InetSocketAddress(ip, port), 3 * 1000); + mSocket.setTcpNoDelay(true); + mSocket.setReuseAddress(true); +// mSocket.setKeepAlive(true); +// mSocket.setSoTimeout(12 * 1000); + } + + + + + @Override + public void disconnect() { + if (mSocket != null) { + try { + mSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public synchronized SocketOptions getOptions() { + if (socketOptions == null) { + socketOptions = new SocketOptions(); + } + return socketOptions; + } + + @Override + public void onHandleResponse() throws Exception { + final InputStream stream = getInputStream(); + if (stream != null && getOptions() != null) { + int len = 0; +// while ((len = getInputStream().read(readBuffer)) != -1) { + if ((len = getInputStream().read(readBuffer)) != -1) { + IHandleMessage handleMessage = getOptions().getHandleMessage(); + if (handleMessage != null) { + byte[] bytes = new byte[len]; + System.arraycopy(readBuffer, 0, bytes, 0, len); +// LogUtils.i("鎺ユ敹鍒癟CP鏁版嵁+" + new String(bytes)); + //瀹屾暣鐨勬暟鎹墠鍥炶皟 + handleMessage.read(new Packet(getOptions().getIp(), bytes, mSocket)); + } + } + } + } + + @Override + public synchronized void sendMsg(byte[] msg) throws Exception { + final OutputStream outputStream = getOutStream(); + if (outputStream != null && getOptions() != null) { + try { +// IHandleMessage handleMessage = getOptions().getHandleMessage(); +// handleMessage.write(handleMessage.write(msg)); + getOutStream().write(msg); + + }finally { + outputStream.flush(); + } + } + } + + + /** + * 澶勭悊杩炴帴鐘舵�� + */ + public void onConnectStatus(int status) { +// ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { +// @Override +// public void run() { + final List<ConnectStatusListener> list = getOptions().getConnectStatusListener(); + if (list != null && !list.isEmpty()) { + for (ConnectStatusListener listener : list) { + if (status == ConnectStatus + .CONNECTING) { + listener.onConnecting(); + } else if (status == ConnectStatus.CONNECTED) { + listener.onConnected(); + } else if (status == ConnectStatus + .DISCONNECT) { + listener.onConnectFailed(); + } + } + } +// } +// }); + } + + + private synchronized Socket getSocket() { + return new Socket(); + } + + private InputStream getInputStream() { + if (mSocket != null && mSocket.isConnected() && !mSocket.isClosed()) { + try { + return mSocket.getInputStream(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + + private OutputStream getOutStream() { + if (mSocket != null && mSocket.isConnected() && !mSocket.isClosed()) { + try { + return mSocket.getOutputStream(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + +} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/UdpClient.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java similarity index 67% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/UdpClient.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java index 6fdaabb..045bd84 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/UdpClient.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java @@ -1,22 +1,21 @@ -package com.hdl.sdk.socket.client; +package com.hdl.sdk.link.socket.client; -import com.hdl.sdk.common.utils.IpUtils; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.socket.SocketBoot; -import com.hdl.sdk.socket.SocketOptions; -import com.hdl.sdk.socket.SocketPool; -import com.hdl.sdk.socket.udp.UdpSocketBoot; -import com.hdl.sdk.socket.udp.UdpSocketOptions; -import com.hdl.sdk.socket.codec.IHandleMessage; + + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.socket.SocketPool; +import com.hdl.sdk.link.socket.bean.Packet; +import com.hdl.sdk.link.socket.udp.UdpSocketBoot; +import com.hdl.sdk.link.socket.udp.UdpSocketOptions; +import com.hdl.sdk.link.socket.codec.IHandleMessage; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.Inet4Address; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.atomic.AtomicBoolean; /** @@ -85,25 +84,27 @@ * @return */ public static UdpSocketBoot init(int port, UdpSocketOptions options) { - return init(null, port, options); + return init("0.0.0.0", port, options); } - @Override - public void bind() throws Exception { + public synchronized void bind() throws Exception { try { //宸茬粡缁戝畾杩囧氨涓嶇敤鍐嶇粦瀹� if (null != mSocket) { return; } + if (TextUtils.isEmpty(ipAddress)) { - mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(port)); + mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), port)); + } + else{ + mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(Inet4Address.getByName(ipAddress), port)); } mSocket.setBroadcast(true); - mSocket.setReuseAddress(true); +// mSocket.setReuseAddress(true); } catch (Exception e) { - LogUtils.e("鍒濆鍖朣ocket 澶辫触锛�" + e.getMessage()); throw e; } } @@ -131,19 +132,21 @@ } try { mSocket.receive(receivePacket); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + LogUtils.e("鎺ユ敹鍒癠dp鏁版嵁鍖呭紓甯革紝寮傚父淇℃伅锛�" + e.getMessage()); + return; } if (receivePacket.getLength() == 0) { + LogUtils.i("鎺ユ敹鍒癠dp鏁版嵁鍖咃紝鏁版嵁鍖呴暱搴︿负0锛�" + receivePacket.getAddress().getHostAddress() + ":" + receivePacket.getPort()); return; } //鎺掗櫎鑷繁鍙戝嚭鍘荤殑 - try { - if (IpUtils.isLocalIpAddress(receivePacket.getAddress().getHostAddress())) - return; - } catch (Exception ignored) { - - } +// try { +// if (IpUtils.isLocalIpAddress(receivePacket.getAddress().getHostAddress())) +// return; +// } catch (Exception ignored) { +// +// } try { LogUtils.i("鎺ユ敹鍒癠dp鏁版嵁鍖咃紝缃戠粶鍦板潃锛�" + receivePacket.getAddress().getHostAddress() + ":" + receivePacket.getPort()); @@ -152,11 +155,11 @@ if (handleMessage != null) { byte[] data = new byte[receivePacket.getLength()]; System.arraycopy(receivePacket.getData(), 0, data, 0, data.length); - handleMessage.read(data,receivePacket.getAddress().getHostAddress()); + handleMessage.read(new Packet(receivePacket.getAddress().getHostAddress(), data,null)); } } catch (Exception e) { - + LogUtils.i("鎺ユ敹鍒癠dp鏁版嵁鍖咃紝澶勭悊寮傚父锛�" + e.getMessage()); } } @@ -167,6 +170,12 @@ return; } final DatagramPacket sendPacket = new DatagramPacket(msg, msg.length, InetAddress.getByName(ipAddress), port); - mSocket.send(sendPacket); + if (mSocket != null) { + mSocket.send(sendPacket); + } else { + DatagramSocket datagramSocket = new DatagramSocket(); + datagramSocket.send(sendPacket); + datagramSocket.close(); + } } } diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java new file mode 100644 index 0000000..7f4bbab --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java @@ -0,0 +1,22 @@ +package com.hdl.sdk.link.socket.codec; + +import com.hdl.sdk.link.socket.bean.Packet; + +/** + * Created by Tong on 2021/9/22. + */ +public abstract class ByteToMessageDecoder<T> implements IHandleFlow<T> { + + protected abstract T decoder(Packet packet) + throws Exception; + + @Override + public final T read(Packet packet) throws Exception { + return decoder(packet); + } +// +// @Override +// public final byte[] write(Packet data) { +// return data; +// } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java new file mode 100644 index 0000000..3ce442f --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java @@ -0,0 +1,14 @@ +package com.hdl.sdk.link.socket.codec; + +import com.hdl.sdk.link.socket.bean.Packet; + +/** + * Created by Tong on 2021/9/23. + */ +public interface IHandleFlow<T> { + + T read(Packet packet) throws Exception; + +// byte[] write(Packet packet) throws Exception; + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java new file mode 100644 index 0000000..1c7a223 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.socket.codec; + +import com.hdl.sdk.link.socket.bean.Packet; + +/** + * Created by Tong on 2021/9/27. + */ +public interface IHandleMessage { + void read(Packet packet) throws Exception; + +// byte[] write(Packet packet) throws Exception; +} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IMessagePipeLine.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java similarity index 76% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IMessagePipeLine.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java index 5acb78a..41128df 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IMessagePipeLine.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.socket.codec; +package com.hdl.sdk.link.socket.codec; /** * Created by Tong on 2021/9/23. diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java new file mode 100644 index 0000000..3e09cc2 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java @@ -0,0 +1,45 @@ +package com.hdl.sdk.link.socket.codec; + +import com.hdl.sdk.link.socket.bean.Packet; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Tong on 2021/9/23. + */ +public class MessagePipeLine implements IMessagePipeLine, IHandleMessage { + + public final List<IHandleFlow> queue = new ArrayList<>(); + + @Override + public void add(IHandleFlow flow) { + queue.add(flow); + } + + @Override + public synchronized void clear() { + queue.clear(); + } + + @Override + public void read(Packet packet) throws Exception { + for (int i = 0; i < queue.size(); i++) { + IHandleFlow flow = queue.get(i); + Object read = flow.read(packet); +// try { +// out = Objects.requireNonNull(read); +// } catch (Exception ignored) { +// } + } + } + +// @Override +// public byte[] write(Packet packet) throws Exception { +// for (int i = 0; i < queue.size(); i++) { +// IHandleFlow flow = queue.get(i); +// byte[] write = flow.write(packet); +// } +// return new byte[0]; +// } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java new file mode 100644 index 0000000..e093590 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java @@ -0,0 +1,26 @@ +package com.hdl.sdk.link.socket.codec; + + +import com.hdl.sdk.link.socket.bean.Packet; + +/** + * Created by Tong on 2021/9/22. + */ +public abstract class MessageToByteEncoder implements IHandleFlow { + + + protected abstract Packet encode(Packet packet) + throws Exception; + + @Override + public final Object read(Packet packet) { + return packet; + } + +// @Override +// public byte[] write(Packet packet) throws Exception { +// return encode(packet); +// } + + +} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/ConnectStatusListener.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java similarity index 88% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/ConnectStatusListener.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java index 17ac30f..9efb726 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/ConnectStatusListener.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.socket.listener; +package com.hdl.sdk.link.socket.listener; /** * Created by Tong on 2021/9/22. diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/SendListener.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java similarity index 73% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/SendListener.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java index 9ecb288..e9a84f1 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/listener/SendListener.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java @@ -1,4 +1,4 @@ -package com.hdl.sdk.socket.listener; +package com.hdl.sdk.link.socket.listener; /** * Created by Tong on 2021/9/22. diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketBoot.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java similarity index 85% rename from HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketBoot.java rename to HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java index 5316f88..5f0e52d 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketBoot.java +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java @@ -1,11 +1,12 @@ -package com.hdl.sdk.socket.udp; +package com.hdl.sdk.link.socket.udp; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.socket.SocketRequest; -import com.hdl.sdk.socket.client.IUdpClient; -import com.hdl.sdk.socket.listener.SendListener; + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.TextUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.socket.listener.SendListener; +import com.hdl.sdk.link.socket.SocketRequest; +import com.hdl.sdk.link.socket.client.IUdpClient; import java.util.HashMap; import java.util.Map; @@ -103,10 +104,9 @@ if (listener != null && !TextUtils.isEmpty(request.getAction())) { sendMap.put(request.getAction(), listener); } - LogUtils.i("鍙戦�佺洰鏍嘔P鍜岀鍙�", ipAddress + ":" + port); - client.sendMsg(ipAddress, port, msg); + client.sendMsg(ipAddress,port, msg); } catch (Exception e) { - LogUtils.i("鍙戦�佸け璐�:" + e.getMessage()); + LogUtils.e("鍙戦�佸け璐�:" + e.getMessage()); } } diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java new file mode 100644 index 0000000..0d19482 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java @@ -0,0 +1,21 @@ +package com.hdl.sdk.link.socket.udp; + + +import com.hdl.sdk.link.socket.codec.IHandleMessage; + +/** + * Created by hxb on 2021/12/12. + */ +public class UdpSocketOptions { + + //澶勭悊鏁版嵁 + private IHandleMessage handleMessage; + + public IHandleMessage getHandleMessage() { + return handleMessage; + } + + public void setHandleMessage(IHandleMessage handleMessage) { + this.handleMessage = handleMessage; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java new file mode 100644 index 0000000..f2bfca1 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java @@ -0,0 +1,387 @@ +package com.hdl.sdk.link.zigbee; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.core.bean.ZigbeeResponse; +import com.hdl.sdk.link.core.callback.ZigbeeCallBack; +import com.hdl.sdk.link.core.connect.HDLZigbeeConnect; +import com.hdl.sdk.link.zigbee.bean.PanelVibrationBean; +import com.hdl.sdk.link.zigbee.bean.TimeDataBean; +import com.hdl.sdk.link.zigbee.bean.ZBBaseSendBean; +import com.hdl.sdk.link.zigbee.bean.ZBDeviceBean; +import com.hdl.sdk.link.zigbee.callback.ZBDeviceListCallBack; +import com.hdl.sdk.link.zigbee.config.ZigBee; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by jlchen on 12/16/21. + * ZigBee鍘熺敓鍗忚鐩稿叧 + */ +public class HDLLinkLocalZigBee { + private static final String Cluster_ID = "Cluster_ID"; + private static final String Command = "Command"; + //instance + private volatile static HDLLinkLocalZigBee instance; + + //getInstance + public static synchronized HDLLinkLocalZigBee getInstance() { + if (instance == null) { + synchronized (HDLLinkLocalZigBee.class) { + if (instance == null) { + instance = new HDLLinkLocalZigBee(); + } + } + } + return instance; + } + + + /** + * 鍙戦�佹秷鎭粰缃戝叧 + * + * @param gatewayOid + * @param replyTopic 鍥炲涓婚 + * @param payload + * @param callback + */ + public void sendData(String gatewayOid, String replyTopic, String payload, ZigbeeCallBack callback) { + //娉ㄦ剰 gatewayId鏄~瑕佽繛鎺ョ殑缃戝叧锛屽彲浠ユ槸涓荤綉鍏崇殑Id锛屼篃鍙互鏄粠缃戝叧鐨処d + HDLZigbeeConnect.getInstance().Send(gatewayOid, replyTopic, payload, callback); + } + + /********************************缃戝叧鐩稿叧********************************/ + /** + * 鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) + * + * @param gatewayOid 缃戝叧id + * @param callback + */ + public void locationGateway(String gatewayOid, ZigbeeCallBack callback) { + JsonObject jObject = new JsonObject(); + jObject.addProperty(Cluster_ID, 0); + jObject.addProperty(Command, ZigBee.CommandType.GwLinuxLocate); + sendData(gatewayOid, ZigBee.ReplyTopicType.GwLinuxLocate, jObject.toString(), callback); + } + + /********************************璁惧鐩稿叧********************************/ + /** + * 璁剧疆璁惧鍏ョ綉鏂瑰紡 + * 璁剧疆1娆′箣鍚庝繚鎸佽缃殑鏂瑰紡 + * 閲嶅惎鎭㈠榛樿鏂瑰紡 + * @param gatewayOid 缃戝叧oid + * @param deviceJoiningMode 0锛氶粯璁わ紱1锛氭柊鏂瑰紡锛堝揩閫熷叆缃戯級 + */ + public void setDeviceJoiningMode(String gatewayOid, int deviceJoiningMode,ZigbeeCallBack callback){ + JsonObject jObject = new JsonObject(); + jObject.addProperty("Cluster_ID", 0); + jObject.addProperty("Command", 180); + JsonObject data = new JsonObject(); + data.addProperty("mode", deviceJoiningMode); + jObject.add("Data", data); + sendData(gatewayOid, ZigBee.ReplyTopicType.SetJoiningModeRespon, jObject.toString(), callback); + } + + /** + * 璁剧疆鎼滅储鏂拌澶囧紑鍚垨鑰呭叧闂� + * + * @param gatewayOid 缃戝叧oid + * @param time 寮�鍚悳绱㈣澶囩殑鏃堕棿(鍗曚綅锛氱) 0:鍏抽棴鎼滅储 255锛氫竴鐩村紑鍚� + * @param callback + */ + public void sendSearchDevice(String gatewayOid, int time, ZigbeeCallBack callback) { + ZBBaseSendBean<TimeDataBean> baseSendBean = new ZBBaseSendBean(0, ZigBee.CommandType.SearchNewDevice, new TimeDataBean(time)); + sendData(gatewayOid, ZigBee.ReplyTopicType.SearchNewDevice, GsonConvert.getGson().toJson(baseSendBean), callback); + } + + /** + * 鎼滅储璁惧 + * + * @param gatewayOid + * @param callback + */ + public void startSearchDevice(String gatewayOid, ZigbeeCallBack callback) { + sendSearchDevice(gatewayOid, 255, callback); + } + + /** + * 鏆傚仠鎼滅储璁惧 + * + * @param gatewayOid + * @param callback + */ + public void stopSearchDevice(String gatewayOid, ZigbeeCallBack callback) { + sendSearchDevice(gatewayOid, 0, callback); + } + + /** + * 瀹氫綅璁惧 闂儊5绉� + * 璇ユ潯鎸囦护璁惧涓嶅洖澶嶏紝鎵�鏈夋病callBack + * 鍙戦�佽鍛戒护锛岃澶囨寚绀虹伅灏嗛棯鐑併�俢luster 鍒楄〃涓敮鎸� Identify 鍔熻兘锛屽嵆鍖呭惈 cluster=3 鐨勮 澶囧彲浠ヤ娇鐢ㄨ鎺ュ彛銆� + * + * @param gatewayOid + * @param deviceAddr 鍗曟挱鏃朵负璁惧鑺傜偣鐨� mac 鍦� 鍧� 绫诲瀷鏄瓧绗︼紙16 涓瓧绗︼級 缁勬挱鏃朵负缁� id 绫诲瀷鏄暟鍊� 骞挎挱鏃朵负 null + * @param epoint 璁惧绔彛鍙� 鍜� mac 鍦板潃鍏卞悓鏍囪瘑鍞竴鐨� zigbee 璁惧 鏁板�艰寖鍥� 0-255 + */ + public void locationDevice(String gatewayOid, String deviceAddr, int epoint) { + JsonObject jObject = new JsonObject(); + jObject.addProperty("DeviceAddr", deviceAddr); + jObject.addProperty("Epoint", epoint); + jObject.addProperty(Cluster_ID, 3); + jObject.addProperty(Command, 0); + jObject.addProperty("SendMode", 2);//鍙戦�佹ā寮� 缁勬挱: 1 鍗曟挱: 2 骞挎挱: 15 + JsonObject data = new JsonObject(); + data.addProperty("Time", 5);//闂儊鏃堕棿锛堢锛� + jObject.add("Data", data); + sendData(gatewayOid, ZigBee.ReplyTopicType.Identify, jObject.toString(), null); + } + + + /** + * 璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� + * 閫氳繃璇ユ寚浠ゅ彲浠ヤ娇璁惧鑴辩褰撳墠 zigbee 缃戠粶锛岃璁惧淇℃伅涔熷皢浼氬湪缃戝叧涓婂垹闄ゃ�� + * 娉ㄦ剰锛氬皢浼氬垹闄ゅ悓涓� MAC 鍦板潃涓嬫墍鏈変笉鍚岀鍙g殑璁惧锛屽涓�涓� 2 璺寜閿澶囷紝瀹冨叿鏈変袱涓� 鎸夐敭锛屽湪璁惧鍒楄〃涓婅繖涓や釜鎸夐敭鍏锋湁鐩稿悓鐨� mac锛屼絾绔彛鍙锋槸涓嶅悓鐨勩�備娇鐢ㄨ鎸囦护璁╀换鎰� 涓�涓寜閿缃戯紝鍙︿竴涓篃浼氱缃戙�� + * + * @param gatewayOid + * @param compelClear 0锛氫笉寮哄埗娓呴櫎銆傞渶瑕佽妭鐐硅澶� 鍙嶉绂荤綉纭淇℃伅鍚庢墠鑳藉垹闄よ 澶囦俊鎭�� + * 1锛氬己鍒舵竻闄ゃ�備笉闇�瑕佽妭鐐硅澶� 鍙嶉绂荤綉纭淇℃伅锛岀洿鎺ュ垹闄よ 澶囦俊鎭�� + */ + public void removeDevice(String gatewayOid, int compelClear, List<String> deviceAddrList, ZigbeeCallBack callback) { + if (deviceAddrList == null || deviceAddrList.size() == 0) { + LogUtils.e("娌℃湁瑕佸垹闄ゅ埌鏁版嵁"); + return; + } + JsonArray addrList = new JsonArray(); + for (String addr : deviceAddrList) { + JsonObject aObject = new JsonObject(); + aObject.addProperty("DeviceAddr", addr); + addrList.add(aObject); + } + JsonObject jObject = new JsonObject(); + jObject.addProperty(Cluster_ID, 0); + jObject.addProperty(Command, ZigBee.CommandType.RemoveDevice); + JsonObject data = new JsonObject(); + data.addProperty("CompelClear", compelClear); + data.add("DeviceAddrList", addrList); + jObject.add("Data", data); + sendData(gatewayOid, ZigBee.ReplyTopicType.RemoveDevice, jObject.toString(), callback); + } + + /** + * 璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 + * 锛堢綉鍏充竴涓竴涓繑鍥炵鐐硅澶囪缁嗕俊鎭級 + * + * @param gatewayOid + * @param callback + */ + public void getZigBeeDeviceList(String gatewayOid, ZBDeviceListCallBack callback) { + JsonObject jObject = new JsonObject(); + jObject.addProperty(Cluster_ID, 0); + jObject.addProperty(Command, ZigBee.CommandType.GetDeviceInfo); + //鏄惁鑾峰彇鍒楄〃鎴愬姛鏍囪 + AtomicBoolean isSuccess = new AtomicBoolean(false); + //鎼滅储5s绛夊緟鏍囪 + AtomicInteger timeOut = new AtomicInteger(0); + //璁惧鍒楄〃 + List<ZBDeviceBean> list = new ArrayList<>(); + //娉ㄥ唽鐩戝惉浜嬩欢 + EventListener zigBeeEventListener = new EventListener() { + @Override + public synchronized void onMessage(Object msg) { + if (msg instanceof ZigbeeResponse) { + ZigbeeResponse zigbeeResponse = (ZigbeeResponse) msg; + if (zigbeeResponse.getTopic().equals(ZigBee.ReplyTopicType.GetDeviceInfo)) { + + final ZBDeviceBean bean = GsonConvert.getGson().fromJson(zigbeeResponse.getData(), new TypeToken<ZBDeviceBean>() { + }.getType()); + + if (bean == null) { + LogUtils.i("鑾峰彇鍒扮殑Zigbee璁惧鍒楄〃鍙嶇郴鍒楀寲澶辫触:\r\n" + zigbeeResponse.getData()); + }else{ + bean.setGatewayMac(zigbeeResponse.getOid()); + LogUtils.i("zigbeeResponse ZBDeviceBean:" + bean.getDeviceAddr() + "锛�" + bean.getEpoint()); + if (bean.getData().getTotalNum() == 0) { + //鍥炲绌虹殑璁惧鍒楄〃 + list.clear(); + if (callback != null) { + callback.onSuccess(list); + } + HDLZigbeeConnect.getInstance().removeListener(this); + isSuccess.set(true); + } else { + list.add(bean); +// LogUtils.i("getZigBeeDeviceList 閲嶇疆鏃堕棿涓�0"); + timeOut.set(0);//鏀跺埌涓�涓澶囧垯閲嶇疆鏃堕棿 + //濡傛灉褰撳墠搴忓彿绛変簬鎬绘暟锛屼唬琛ㄦ槸鏈�鍚庝竴涓澶囦簡锛屽洖璋冩垚鍔� + if (bean.getData().getDeviceNum() == bean.getData().getTotalNum()) { + if (callback != null) { + callback.onSuccess(list); + } + HDLZigbeeConnect.getInstance().removeListener(this); + isSuccess.set(true); + LogUtils.i("getZigBeeDeviceList璇诲彇瀹屾垚"); + timeOut.set(6);//璁℃椂缁撴潫鏍囪 + } + + } + } + } + } + } + }; + HDLZigbeeConnect.getInstance().registerListener(zigBeeEventListener); + //鍙戦�佹暟鎹� + sendData(gatewayOid, "", jObject.toString(), null); + //5绉掑悗杩樻病鏈夋帴鏀跺埌鏁版嵁锛屽氨鍥炶皟澶辫触 + ScheduledExecutorService scheduledExecutorService = ThreadToolUtils.getInstance().newScheduledThreadPool(1); + scheduledExecutorService.schedule(new Runnable() { + @Override + public void run() { + while (timeOut.get() < 5) { + try { + timeOut.set(timeOut.get() + 1); + LogUtils.i("getZigBeeDeviceList 璁℃椂锛�" + timeOut.get() + "s"); + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + //绉婚櫎鐩戝惉浜嬩欢 + HDLZigbeeConnect.getInstance().removeListener(zigBeeEventListener); + if (!isSuccess.get()) { + if (null != callback) { + callback.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR)); + } + } + LogUtils.i("getZigBeeDeviceList 5s鍊掕鏃剁粨鏉�"); + scheduledExecutorService.shutdownNow(); + } + }, 1, TimeUnit.SECONDS); + + } + + /** + * 淇敼璁惧绔彛锛堟寜閿級鍚嶇О + * + * @param gatewayOid + * @param deviceAddr + * @param epoint + * @param deviceName + * @param callback + */ + public void renameDeviceName(String gatewayOid, String deviceAddr, int epoint, String deviceName, ZigbeeCallBack callback) { + JsonObject jObject = new JsonObject(); + jObject.addProperty("DeviceAddr", deviceAddr); + jObject.addProperty("Epoint", epoint); + jObject.addProperty(Cluster_ID, 0); + jObject.addProperty(Command, ZigBee.CommandType.DeviceRename); + JsonObject data = new JsonObject(); + data.addProperty("DeviceName", deviceName); + jObject.add("Data", data); + sendData(gatewayOid, ZigBee.ReplyTopicType.DeviceRename, jObject.toString(), callback); + } + + /** + * 瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃 onoffoutput 鍥炶矾,杩涜璁剧疆涓烘櫘閫氬紑鍏虫垨鎻掑骇鎴栫伅鍏� + * + * @param gatewayOid + * @param deviceAddr 璁惧鑺傜偣鐨� mac 鍦板潃 锛堟渶澶� 16 涓瓧绗︼級 + * @param epoint 璁惧绔彛鍙� 鍜� mac 鍦板潃鍏卞悓鏍囪瘑鍞竴鐨� zigbee 璁惧 鏁板�艰寖鍥� 0-255 + * @param functionType 鐢ㄦ潵琛ㄧず瀹為檯鍥炶矾鐢ㄤ簬浠�涔� 鍔熻兘锛屽彲鎵╁睍 0-缁х數鍣ㄦ帴鏅�氬紑鍏� 1-缁х數鍣ㄦ帴鐏厜 2-鎻掑骇 + * @param callback + */ + public void setEPDeviceFunctionType(String gatewayOid, String deviceAddr, int epoint, int functionType, ZigbeeCallBack callback) { + JsonObject jObject = new JsonObject(); + jObject.addProperty("DeviceAddr", deviceAddr); + jObject.addProperty("Epoint", epoint); + jObject.addProperty(Cluster_ID, 0); + jObject.addProperty(Command, ZigBee.CommandType.SetEPDeviceFunctionType); + JsonObject data = new JsonObject(); + data.addProperty("FunctionType", functionType); + jObject.add("Data", data); + sendData(gatewayOid, ZigBee.ReplyTopicType.SetEPDeviceFunctionType, jObject.toString(), callback); + } + + + + /********闈㈡澘闇囧姩鍔熻兘********/ + /** + * 鑾峰彇绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅 + */ + public void getPanelVibrationInfo(String gatewayOid, String deviceAddr, int epoint, String passData, ZigbeeCallBack callback) { +// //缁勮鍙戦�佹暟鎹� +// JsonObject jObject = new JsonObject(); +// jObject.addProperty("DeviceAddr", deviceAddr); +// jObject.addProperty("Epoint", 200); +// jObject.addProperty(Cluster_ID, 64513); +// jObject.addProperty(Command, 0); +// JsonObject data = new JsonObject(); +// data.addProperty("PassData", "050108110101"); +// jObject.add("Data", data); +// sendClientDataPassthrough(device, jObject.toString(), "0802", 18, 6, null, callback); +// sendClientDataPassthrough(gatewayOid,deviceAddr,epoint,passData,callback); + + } + + /** + * 璁剧疆绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅 + * + * @param device + * @param deviceAddr + * @param panelVibrationBean + * @param callback + */ + public void setPanelVibrationInfo(String device, String deviceAddr, PanelVibrationBean panelVibrationBean, ZigbeeCallBack callback) { +// String passData = "0800081104"; +// passData += panelVibrationBean.getIsEnable() ? "01" : "00"; +//// passData += Convert.ToString(panelVibrationBean.getStrength(), 16).PadLeft(2, '0'); +//// String time = Convert.ToString(panelVibrationBean.getTime(), 16).PadLeft(4, '0'); +//// //浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚� +//// passData += time.Substring(2, 2); +//// passData += time.Substring(0, 2); +// +//// var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; +//// var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } }; +//// jObject.Add("Data", data); +// +// JsonObject jObject = new JsonObject(); +// jObject.addProperty("DeviceAddr", deviceAddr); +// jObject.addProperty("Epoint", 200); +// jObject.addProperty(Cluster_ID, 64513); +// jObject.addProperty(Command, 0); +// JsonObject data = new JsonObject(); +// data.addProperty("PassData", passData); +// jObject.add("Data", data); +// +// sendClientDataPassthrough(device, jObject.toString(), "0002", 16, 6, null, callback); + } + + + /** + * 寮�鍏虫帶鍒�(浠呯敤浜巆luster=6鐨勮澶囷級 璁惧鏀寔cluster=6鐨勮澶囨墠鑳借皟鐢ㄨ鎺ュ彛 + * + * @param command 0:鍏抽棴 1:鎵撳紑 2:鍙栧弽 + */ + public void switchControl(String gatewayOid, int command, ZBDeviceBean deviceBean){ + JsonObject jObject = new JsonObject(); + jObject.addProperty("DeviceAddr", deviceBean.getDeviceAddr()); + jObject.addProperty("Epoint", deviceBean.getEpoint()); + jObject.addProperty(Cluster_ID, 6); + jObject.addProperty(Command, command); + jObject.addProperty("SendMode", 2); + sendData(gatewayOid, "", jObject.toString(), null); + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java new file mode 100644 index 0000000..11b6f86 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java @@ -0,0 +1,37 @@ +package com.hdl.sdk.link.zigbee.bean; + +import java.io.Serializable; + +/** + * Created by jlchen on 12/17/21. + */ +public class PanelVibrationBean implements Serializable { + + private Boolean isEnable;//闇囧姩浣胯兘 + private int strength;//闇囧姩寮哄害(鍗佽繘鍒�) + private int time;//闇囧姩鏃堕棿(鍗佽繘鍒�) + + public Boolean getIsEnable() { + return isEnable; + } + + public void setIsEnable(Boolean enable) { + isEnable = enable; + } + + public int getStrength() { + return strength; + } + + public void setStrength(int strength) { + this.strength = strength; + } + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java new file mode 100644 index 0000000..634c3ab --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java @@ -0,0 +1,21 @@ +package com.hdl.sdk.link.zigbee.bean; + +/** + * Created by jlchen on 12/16/21. + */ +public class TimeDataBean { + + private int time;//0-255 + + public TimeDataBean(int time) { + this.time = time; + } + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java new file mode 100644 index 0000000..814b610 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java @@ -0,0 +1,42 @@ +package com.hdl.sdk.link.zigbee.bean; + + +/** + * Created by jlchen on 12/16/21. + */ +public class ZBBaseSendBean<T> { + private int Cluster_ID;//绨� id + private int Command;//鎿嶄綔鐮� + private T data;//鏁版嵁 + + public ZBBaseSendBean(int cluster_ID, int command, T data) { + Cluster_ID = cluster_ID; + Command = command; + this.data = data; + } + + public int getCluster_ID() { + return Cluster_ID; + } + + public void setCluster_ID(int cluster_ID) { + Cluster_ID = cluster_ID; + } + + public int getCommand() { + return Command; + } + + public void setCommand(int command) { + Command = command; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java new file mode 100644 index 0000000..c89e3d9 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java @@ -0,0 +1,516 @@ +package com.hdl.sdk.link.zigbee.bean; + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by jlchen on 12/29/21. + * 鎼滅储ZigBee璁惧鍥炶矾鍥炲 + */ +public class ZBDeviceBean implements Serializable { + /// <summary> + /// 瀹為檯鐨勮澶噄d + /// <para>258:color dimmable light,璋冨叧鐏� </para> + /// <para>10:Door lock,闂ㄩ攣</para> + /// <para>514:Window covering device,绐楀笜</para> + /// <para>515:Window covering controller锛岀獥甯樻帶鍒跺櫒</para> + /// <para>769:Thermostat,鎭掓俯闈㈡澘/绌鸿皟</para> + /// <para>770:Temperature Sensor,娓╁害浼犳劅鍣�</para> + /// <para>775:Temperature Sensor,婀垮害浼犳劅鍣�</para> + /// <para>262:Light sensor,鍏夌収浼犳劅鍣�</para> + /// <para>1026:sensor,浼犳劅鍣紝鍏蜂綋绫诲瀷鐨勪紶鎰熷櫒DeviceType鏉ュ尯鍒�</para> + /// </summary> + private int Device_ID; + /// MAC鍦板潃 + private String DeviceAddr; + //璁惧绔彛鍙� + //鍜宮ac鍦板潃鍏卞悓鏍囪瘑鍞竴鐨剒igbee璁惧 + //鏁板�艰寖鍥�0-255 + //濡傛灉鏃犺澶囪瀛楁涓嶅瓨鍦� + private int Epoint; + //杩斿洖鍏ョ綉璁惧淇℃伅 + private int Data_ID; + //璁惧璇︾粏淇℃伅 + private ZBDataBean Data; + //鑷畾涔夋坊鍔犲瓧娈� 鍙兘鏄痮id锛屽彲鑳芥槸缃戝叧Id锛屽彲鑳芥槸mac + private String gatewayMac; + + /** + * 妯℃澘鍖归厤鏍囪 wxr 鑷畾涔� 2022-02-23 16:09:44 + */ + private boolean templateSettingFlag = false; + public boolean isTemplateSettingFlag() { + return templateSettingFlag; + } + + public void setTemplateSettingFlag(boolean templateSettingFlag) { + this.templateSettingFlag = templateSettingFlag; + } + private String templateAddr ; + + public String getTemplateAddr() { + return templateAddr == null ? "" : templateAddr; + } + + public void setTemplateAddr(String templateAddr) { + this.templateAddr = templateAddr; + } + + + public String getGatewayMac() { + return gatewayMac == null ? "" : gatewayMac; + } + + public void setGatewayMac( String gatewayMac) { + this.gatewayMac = gatewayMac; + } + + public int getDevice_ID() { + return Device_ID; + } + + public void setDevice_ID(int Device_ID) { + this.Device_ID = Device_ID; + } + + + public String getDeviceAddr() { + return DeviceAddr == null ? "" : DeviceAddr; + } + + public void setDeviceAddr( String DeviceAddr) { + this.DeviceAddr = DeviceAddr; + } + + public int getEpoint() { + return Epoint; + } + + public void setEpoint(int Epoint) { + this.Epoint = Epoint; + } + + public int getData_ID() { + return Data_ID; + } + + public void setData_ID(int Data_ID) { + this.Data_ID = Data_ID; + } + + public ZBDataBean getData() { + if(Data == null){ + Data = new ZBDataBean(); + } + return Data; + } + + public void setData(ZBDataBean Data) { + this.Data = Data; + } + + /** + * 璁惧璇︾粏淇℃伅 + */ + public static class ZBDataBean implements Serializable{ + private int TotalNum;//鍏ョ綉璁惧鎬绘暟銆傜瓑浜�0鏃讹紝琛ㄧず娌℃湁璁惧淇℃伅锛屼笅闈㈠瓧娈靛皢涓嶅瓨鍦ㄣ�� + private int DeviceNum;//鏍囪瘑褰撳墠璁惧鏄彂閫佺殑鏄鍑犱釜璁惧銆侱eviceNum浠�1寮�濮嬫瘡鍙戦�佷竴涓澶囦俊鎭紝涓嬩竴涓澶囦俊鎭殑DeviceNum灏嗗姞1銆傜洿鍒癉eviceNum绛変簬TotalNum璇存槑鎵�鏈夎澶囦俊鎭彂閫佸畬姣� + private int JoinTime;//鍏ョ綉鐨剈tc鏃堕棿鎴� + private int ZigbeeType;//1:璺敱鍣ㄨ澶� 2锛氱粓绔澶囷紝鐢垫睜璁惧 + private int NwkAddr;//璁惧缃戠粶鍦板潃 + private int DeviceType;//璇ュ瓧娈典富瑕侀拡瀵笽AS瀹夐槻璁惧璁剧珛銆傛墍鏈塈AS瀹夐槻璁惧鍏辩敤涓�涓狣eviceID涓�1026銆傛墍浠ヨ鍖哄垎瀛愯澶囩被鍨嬶紝闇�瑕佽瀛楁銆� + //鐢ㄤ簬鍒ゆ柇璁惧鐨剒igbee鍗忚鐗堟湰銆�49246锛歓LL1.0鏍囧噯璁惧銆�260锛� ZHA1.2鏍囧噯璁惧銆� Z3.0鏍囧噯璁惧銆� + // 41440锛歓GP3.0鏍囧噯璁惧銆�265锛歓SE1.4鏍囧噯璁惧銆� + private int Profile; + //璁惧mac鍚嶇О + private String MacName; + //璁惧鍚� + private String DeviceName; + //0锛氳澶囦笉鍦ㄧ嚎 1锛氳澶囧湪绾� + private int IsOnline; + //杈撳叆绨囧垪琛� + //绔偣鍥炶矾鑷韩鎷ユ湁澶氬皯鍔熻兘锛屽彲浠ヨ鎺у埗锛涜鎺у姛鑳� + //鍙傝�儂igbee鑱旂洘鏂囨。 + private List<InClusterListBean> InClusterList; + //杈撳嚭绨囧垪琛� + //绔偣鍥炶矾鍙互鎺у埗鍏朵粬璁惧澶氬皯鍔熻兘锛涙帶鍒跺姛鑳� + //鍙傝�儂igbee鑱旂洘鏂囨。 + private List<OutClusterListBean> OutClusterList; + //鐢ㄤ簬璁板綍璁惧鏈�鏂颁笂鎶ョ殑灞炴�х姸鎬佷俊鎭�傛渶澶ф敮鎸佽褰�16涓睘鎬х姸鎬侊紝涓斿彧璁板綍灞炴�у�奸暱搴︿笉澶т簬4瀛楄妭鐨勬暟鎹�� + private List<AttributeStatusBean> AttributeStatus; + //褰撳墠杩愯绋嬪簭鐗堟湰淇℃伅 + private int ImgVersion; + //褰撳墠闀滃儚绫诲瀷id + private int ImgTypeId; + //纭欢鐗堟湰 + private int HwVersion; + //椹卞姩浠g爜銆備负0鏃讹紝琛ㄧずzigbee鍗忚皟鍣ㄨ澶囥�傚叾浠栧�艰〃绀轰负铏氭嫙椹卞姩璁惧 + private int DriveCode; + //璁惧鎵�鍦ㄧ綉鍏崇殑缃戝叧id + private String GwId; + //鎵�鏈夋寚瀹歝luster鏄惁閮藉凡缁忔垚鍔熺粦瀹氬崗璋冨櫒 + //0锛氭湭瀹屽叏缁戝畾 + //1锛氬凡缁忕粦瀹� + private int ClusterBindZbSuccess; + //鏄惁鑾峰彇鎵�鏈夐粯璁ょ粦瀹氫俊鎭� + //0锛氬惁 + //1锛氭槸 + private int IsGetAllDefaultBind; + //鍒堕�犲晢鍚嶅瓧 + private String ManufacturerName; + //璁惧鍨嬪彿 + private String ModelIdentifier; + //浜у搧鐮� 搴忓垪鍙� + private String ProductCode; + //鐢ㄦ潵琛ㄧず瀹為檯鍥炶矾鐢ㄤ簬浠�涔堝姛鑳斤紝鍙墿灞� + //0-缁х數鍣ㄦ帴鏅�氬紑鍏� + //1-缁х數鍣ㄦ帴鐏厜 + //鎻掑骇 + private String FunctionType; + + public int getTotalNum() { + return TotalNum; + } + + public void setTotalNum(int TotalNum) { + this.TotalNum = TotalNum; + } + + public int getDeviceNum() { + return DeviceNum; + } + + public void setDeviceNum(int DeviceNum) { + this.DeviceNum = DeviceNum; + } + + public int getJoinTime() { + return JoinTime; + } + + public void setJoinTime(int JoinTime) { + this.JoinTime = JoinTime; + } + + public int getZigbeeType() { + return ZigbeeType; + } + + public void setZigbeeType(int ZigbeeType) { + this.ZigbeeType = ZigbeeType; + } + + public int getNwkAddr() { + return NwkAddr; + } + + public void setNwkAddr(int NwkAddr) { + this.NwkAddr = NwkAddr; + } + + public int getDeviceType() { + return DeviceType; + } + + public void setDeviceType(int DeviceType) { + this.DeviceType = DeviceType; + } + + public int getProfile() { + return Profile; + } + + public void setProfile(int Profile) { + this.Profile = Profile; + } + + + public String getMacName() { + return MacName == null ? "" : MacName; + } + + public void setMacName( String MacName) { + this.MacName = MacName; + } + + + public String getDeviceName() { + return DeviceName == null ? "" : DeviceName; + } + + public void setDeviceName( String DeviceName) { + this.DeviceName = DeviceName; + } + + public int getIsOnline() { + return IsOnline; + } + + public void setIsOnline(int IsOnline) { + this.IsOnline = IsOnline; + } + + + public List<InClusterListBean> getInClusterList() { + if (InClusterList == null) { + return new ArrayList<>(); + } + return InClusterList; + } + + public void setInClusterList( List<InClusterListBean> InClusterList) { + this.InClusterList = InClusterList; + } + + + public List<OutClusterListBean> getOutClusterList() { + if (OutClusterList == null) { + return new ArrayList<>(); + } + return OutClusterList; + } + + public void setOutClusterList( List<OutClusterListBean> OutClusterList) { + this.OutClusterList = OutClusterList; + } + + + public List<AttributeStatusBean> getAttributeStatus() { + if (AttributeStatus == null) { + return new ArrayList<>(); + } + return AttributeStatus; + } + + public void setAttributeStatus( List<AttributeStatusBean> AttributeStatus) { + this.AttributeStatus = AttributeStatus; + } + + public int getImgVersion() { + return ImgVersion; + } + + public void setImgVersion(int ImgVersion) { + this.ImgVersion = ImgVersion; + } + + public int getImgTypeId() { + return ImgTypeId; + } + + public void setImgTypeId(int ImgTypeId) { + this.ImgTypeId = ImgTypeId; + } + + public int getHwVersion() { + return HwVersion; + } + + public void setHwVersion(int HwVersion) { + this.HwVersion = HwVersion; + } + + public int getDriveCode() { + return DriveCode; + } + + public void setDriveCode(int DriveCode) { + this.DriveCode = DriveCode; + } + + + public String getGwId() { + return GwId == null ? "" : GwId; + } + + public void setGwId( String GwId) { + this.GwId = GwId; + } + + public int getClusterBindZbSuccess() { + return ClusterBindZbSuccess; + } + + public void setClusterBindZbSuccess(int ClusterBindZbSuccess) { + this.ClusterBindZbSuccess = ClusterBindZbSuccess; + } + + public int getIsGetAllDefaultBind() { + return IsGetAllDefaultBind; + } + + public void setIsGetAllDefaultBind(int IsGetAllDefaultBind) { + this.IsGetAllDefaultBind = IsGetAllDefaultBind; + } + + + public String getManufacturerName() { + return ManufacturerName == null ? "" : ManufacturerName; + } + + public void setManufacturerName( String ManufacturerName) { + this.ManufacturerName = ManufacturerName; + } + + + public String getModelIdentifier() { + return ModelIdentifier == null ? "" : ModelIdentifier; + } + + public void setModelIdentifier( String ModelIdentifier) { + this.ModelIdentifier = ModelIdentifier; + } + + + public String getProductCode() { + return ProductCode == null ? "" : ProductCode; + } + + public void setProductCode( String ProductCode) { + this.ProductCode = ProductCode; + } + + public String getFunctionType() { + return FunctionType; + } + + public void setFunctionType(String FunctionType) { + this.FunctionType = FunctionType; + } + + /** + * 杈撳叆绨� + */ + public static class InClusterListBean implements Serializable{ + /// <summary> + /// 璁惧鏀寔鐨勮緭鍏ュ姛鑳� + /// <para>0:Basic,璁惧鏀寔鈥滃熀纭�灞炴�р�� </para> + /// <para>3:Identify,璁惧鏀寔鈥滆瘑鍒姛鑳解��</para> + /// <para>4:Groups,璁惧鏀寔鈥滅粍鍔熻兘鈥�</para> + /// <para>5:Scenes,璁惧鏀寔鈥滃満鏅姛鑳解��</para> + /// <para>6:on/off,璁惧鏀寔鈥滃紑鍏冲姛鑳解��</para> + /// 寮�鍏冲姛鑳界殑璁惧濡傦細璋冨叧鐏�/缁х數鍣�/绐楀笜绛夈�傘�傘�� + /// <para>8:Level Control,璁惧鏀寔鈥滀寒搴﹁皟鑺傚姛鑳解��</para> + /// 浜害璋冭妭鍔熻兘鐨勮澶囧锛氳皟鍏崇伅銆傘�傘�� + /// <para>257:Door Lock,璁惧鏀寔鈥滈棬閿佸姛鑳解��</para> + /// 闂ㄩ攣鍔熻兘鐨勮澶囧锛氶棬閿併�傘�傘�� + /// <para>258:Window Covering,璁惧鏀寔鈥滅獥甯樻帶鍒跺姛鑳解��</para> + /// 绐楀笜鎺у埗鍔熻兘鐨勮澶囧锛氱獥甯�/寮�鍚堝笜/鍗峰笜銆傘�傘�� + /// <para>513:Thermostat,璁惧鏀寔鈥滄亽娓╁櫒鍔熻兘鈥�</para> + /// 鎭掓俯鍣ㄥ姛鑳界殑璁惧濡傦細绌鸿皟銆傘�傘�� + /// <para>768:Color Control,璁惧鏀寔鈥滈鑹茶皟鑺傚姛鑳解��</para> + /// 棰滆壊璋冭妭鍔熻兘鐨勮澶囧锛氳皟鍏夌伅銆傘�傘�� + /// <para>1026:Temperature Measurement,璁惧鏀寔鈥滄俯搴︽祴閲忓姛鑳解��</para> + /// 娓╁害娴嬮噺鍔熻兘鐨勮澶囧锛氭俯搴︿紶鎰熷櫒銆傘�傘�� + /// <para>1029:Relative Humidity Measurement,璁惧鏀寔鈥滄箍搴︽祴閲忓姛鑳解��</para> + /// 婀垮害娴嬮噺鍔熻兘鐨勮澶囧锛氭箍搴︿紶鎰熷櫒銆傘�傘�� + /// <para>1066:Pm2.5 Measurement,璁惧鏀寔鈥減m2.5娴嬮噺鍔熻兘鈥�</para> + /// Pm2.5娴嬮噺鍔熻兘鐨勮澶囧锛歅m2.5浼犳劅鍣ㄣ�傘�傘�� + /// </summary> + private int InCluster; + + public int getInCluster() { + return InCluster; + } + + public void setInCluster(int inCluster) { + this.InCluster = inCluster; + } + } + + /** + * 杈撳嚭绨� + */ + public static class OutClusterListBean implements Serializable{ + /// <summary> + /// 璁惧鏀寔鐨勮緭鍑哄姛鑳� + /// <para>0:Basic,璁惧鏀寔鈥滃熀纭�灞炴�р�� </para> + /// <para>3:Identify,璁惧鏀寔鈥滆瘑鍒姛鑳解��</para> + /// <para>4:Groups,璁惧鏀寔鈥滅粍鍔熻兘鈥�</para> + /// <para>5:Scenes,璁惧鏀寔鈥滃満鏅姛鑳解��</para> + /// <para>6:on/off,璁惧鏀寔鈥滃紑鍏冲姛鑳解��</para> + /// 寮�鍏冲姛鑳界殑璁惧濡傦細璋冨叧鐏�/缁х數鍣�/绐楀笜绛夈�傘�傘�� + /// <para>8:Level Control,璁惧鏀寔鈥滀寒搴﹁皟鑺傚姛鑳解��</para> + /// 浜害璋冭妭鍔熻兘鐨勮澶囧锛氳皟鍏崇伅銆傘�傘�� + /// <para>257:Door Lock,璁惧鏀寔鈥滈棬閿佸姛鑳解��</para> + /// 闂ㄩ攣鍔熻兘鐨勮澶囧锛氶棬閿併�傘�傘�� + /// <para>258:Window Covering,璁惧鏀寔鈥滅獥甯樻帶鍒跺姛鑳解��</para> + /// 绐楀笜鎺у埗鍔熻兘鐨勮澶囧锛氱獥甯�/寮�鍚堝笜/鍗峰笜銆傘�傘�� + /// <para>513:Thermostat,璁惧鏀寔鈥滄亽娓╁櫒鍔熻兘鈥�</para> + /// 鎭掓俯鍣ㄥ姛鑳界殑璁惧濡傦細绌鸿皟銆傘�傘�� + /// <para>768:Color Control,璁惧鏀寔鈥滈鑹茶皟鑺傚姛鑳解��</para> + /// 棰滆壊璋冭妭鍔熻兘鐨勮澶囧锛氳皟鍏夌伅銆傘�傘�� + /// <para>1026:Temperature Measurement,璁惧鏀寔鈥滄俯搴︽祴閲忓姛鑳解��</para> + /// 娓╁害娴嬮噺鍔熻兘鐨勮澶囧锛氭俯搴︿紶鎰熷櫒銆傘�傘�� + /// <para>1029:Relative Humidity Measurement,璁惧鏀寔鈥滄箍搴︽祴閲忓姛鑳解��</para> + /// 婀垮害娴嬮噺鍔熻兘鐨勮澶囧锛氭箍搴︿紶鎰熷櫒銆傘�傘�� + /// </summary> + private int OutCluster; + + public int getOutCluster() { + return OutCluster; + } + + public void setOutCluster(int outCluster) { + this.OutCluster = outCluster; + } + } + + /** + * 璁惧鏈�鏂颁笂鎶ョ殑灞炴�х姸鎬佷俊鎭� + */ + public static class AttributeStatusBean implements Serializable{ + + /// <summary> + /// 灞炴�х皣id + /// </summary> + private int ClusterId; + /// <summary> + /// 灞炴�d + /// </summary> + private int AttributeId; + /// <summary> + /// 灞炴�у�硷紝杩欎釜涓滆タ涓嶉渶瑕佷粈涔堥珮浣嶅湪鍚庝綆浣嶅湪鍓�,瀹冨凡缁忔槸杞负浜�10杩涘埗 + /// </summary> + private int AttributeData; + /// <summary> + /// 灞炴�х姸鎬佹渶鍚庢洿鏂扮殑utc鏃堕棿鎴� + /// </summary> + private int ReportTime; + + public int getClusterId() { + return ClusterId; + } + + public void setClusterId(int clusterId) { + this.ClusterId = ClusterId; + } + + public int getAttributeId() { + return AttributeId; + } + + public void setAttributeId(int AttributeId) { + this.AttributeId = AttributeId; + } + + public int getAttributeData() { + return AttributeData; + } + + public void setAttributeData(int attributeData) { + this.AttributeData = AttributeData; + } + + public int getReportTime() { + return ReportTime; + } + + public void setReportTime(int ReportTime) { + this.ReportTime = ReportTime; + } + } + } +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java new file mode 100644 index 0000000..13f3081 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java @@ -0,0 +1,32 @@ +//package com.hdl.sdk.link.zigbee.bean; +// +// +// +//import java.util.ArrayList; +//import java.util.List; +// +///** +// * Created by jlchen on 12/29/21. +// * 鍘熺敓ZigBee璁炬ā鍧� +// */ +//public class ZBDeviceModuleBean { +// +// //鍘熺敓ZigBee璁惧鍥炶矾鍒楄〃 +// private List<ZBDeviceBean> deviceLoopList = new ArrayList<>(); +// +// public ZBDeviceModuleBean(List<ZBDeviceBean> deviceLoopList) { +// this.deviceLoopList = deviceLoopList; +// } +// +// +// public List<ZBDeviceBean> getDeviceLoopList() { +// if (deviceLoopList == null) { +// return new ArrayList<>(); +// } +// return deviceLoopList; +// } +// +// public void setDeviceLoopList( List<ZBDeviceBean> deviceLoopList) { +// this.deviceLoopList = deviceLoopList; +// } +//} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java new file mode 100644 index 0000000..7c21660 --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.zigbee.callback; + +/** + * Created by jlchen on 12/16/21. + */ +public interface HDLZBCallBack { + + void onSuccess(String msg); + + void onError(String error); + +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java new file mode 100644 index 0000000..2bdec6b --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java @@ -0,0 +1,13 @@ +package com.hdl.sdk.link.zigbee.callback; + +import com.hdl.sdk.link.core.callback.BaseCallBack; +import com.hdl.sdk.link.zigbee.bean.ZBDeviceBean; + +import java.util.List; + +/** + * Created by jlchen on 12/29/21. + */ +public interface ZBDeviceListCallBack extends BaseCallBack { + void onSuccess(List<ZBDeviceBean> list); +} diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java new file mode 100644 index 0000000..4b7ca0c --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java @@ -0,0 +1,158 @@ +package com.hdl.sdk.link.zigbee.config; + +/** + * Created by jlchen on 12/29/21. + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * ZigBee璁惧绫诲瀷 + * device_ID 瀵瑰簲鐨勮澶囨灇涓� + */ +public class ZBDeviceType{ + public final int UnKown = 0x9999; + public final int ZbGateway = 0x9998; + /// <summary> + /// 骞茬粨鐐� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + public final int OnOffSwitch = 0; + /// <summary> + /// 浜害鎺у埗寮�鍏� + /// <para>璁惧ID涓�2</para> + /// <para>瀹氫箟瀵硅薄 LevelControlSwitch</para> + /// </summary> + public final int LevelControlSwitch = 1; + /// <summary> + /// 缁х數鍣� + /// <para>璁惧ID涓�2</para> + /// <para>瀹氫箟瀵硅薄锛歍oggleLight</para> + /// </summary> + public final int OnOffOutput = 2; + /// <summary> + /// 闂ㄩ攣 + /// <para>璁惧ID涓�10</para> + /// <para>瀹氫箟瀵硅薄锛欴oorLock</para> + /// </summary> + public final int DoorLock = 10; + /// <summary> + /// 璁惧ID涓�257鐨勮澶� + /// <para>璋冨厜鐏細鏀寔浜害</para> + /// <para>璋冨厜璁惧</para> + /// </summary> + public final int DimmableLight = 257; + /// <summary> + /// 璁惧ID涓�258鐨勮澶� + /// <para>鑹叉俯鐏�</para> + /// <para>瀹氫箟瀵硅薄锛欳olorTemperatureLight</para> + /// </summary> + public final int ColorTemperatureLight = 258; + /// <summary> + /// 璋冨厜鍣ㄦ帶鍒跺櫒 + /// <para>璁惧ID涓�260</para> + /// <para>瀹氫箟瀵硅薄 DimmerSwitch</para> + /// </summary> + public final int DimmerSwitch = 260; + /// <summary> + /// 棰滆壊璋冨厜鐏紑鍏� + /// <para>璁惧ID涓�261</para> + /// <para>瀹氫箟瀵硅薄 LevelControlSwitch</para> + /// </summary> + public final int ColorDimmerSwitch = 261; + /// <summary> + /// 绐楀笜璁惧ID + /// <para>Rollershade:鍗峰笜</para> + /// </summary> + public final int WindowCoveringDevice = 514; + /// <summary> + /// 绐楀笜鎺у埗鍣ㄨ澶嘔D + /// <para>CurtainController:绐楀笜鎺у埗鍣�</para> + /// </summary> + public final int WindowCoveringController = 515; + /// <summary> + /// 璁惧ID涓�528鐨勮澶� + /// <para>棰滆壊璋冨厜鐏細鏀寔浜害/鑹插害/楗卞拰搴�</para> + /// <para>璋冨厜璁惧</para> + /// <para>瀹氫箟瀵硅薄锛欳olorDimmableLight</para> + /// </summary> + public final int ColorDimmableLight = 528; + /// <summary> + /// 鎭掓俯鍣� + /// <para>璁惧ID涓�769</para> + /// <para>瀹氫箟瀵硅薄锛欰C</para> + /// </summary> + public final int Thermostat = 769; + /// <summary> + /// <para>娓╂箍搴︿紶鎰熷櫒</para> + /// <para>璁惧ID涓�770</para> + /// <para>瀹氫箟瀵硅薄锛歍emperatureSensor</para> + /// <para>娉ㄦ剰瀹冧笌HumiditySensor涓嶄竴鏍�;瀹冨叿浣撴槸娓╁害杩樻槸婀垮害;闇�瑕佸彂鍛戒护鍘昏鍙�</para> + /// </summary> + public final int TemperatureSensor = 770; + /// <summary> + /// <para>PM2.5浼犳劅鍣�</para> + /// <para>璁惧ID涓�777</para> + /// <para>瀹氫箟瀵硅薄锛歅MSensor</para> + /// </summary> + public final int PMSensor = 777; + /// <summary> + /// 瀹夐槻璁惧 + /// <para>璁惧ID涓�1026鐨勮澶�</para> + /// <para>瀹氫箟瀵硅薄锛欼ASZone</para> + /// </summary> + public final int IASZone = 1026; + /// <summary> + /// 铚傞福鍣� + /// <para>璁惧ID涓�1027鐨勮澶�</para> + /// <para>瀹氫箟瀵硅薄锛欱uzzer</para> + /// </summary> + public final int Buzzer = 1027; + /// <summary> + /// 鎺у埗婧愯澶� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + public final int OtaPanelDevice = 49152; + /// <summary> + /// 鎺у埗婧愯澶� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + public final int OtaDevice = 49153; + /// <summary> + /// 绌烘皵寮�鍏� + /// </summary> + public final int AirSwitch = 53249; + /// <summary> + /// 涓户鍣� + /// </summary> + public final int Repeater = 53250; + /// 杞崲鍣� + /// <para>璁惧ID涓�53251</para> + /// <para>瀹氫箟瀵硅薄锛歍ransverter</para> + /// </summary> + public final int Transverter = 0xD003; + /// <summary> + /// <para>鏅捐。鏋�</para> + /// <para>璁惧ID涓�0xD004 </para> + /// <para>瀹氫箟瀵硅薄锛欰irer</para> + /// </summary> + public final int Airer = 0xD004; + + /// 鏂伴 + /// <para>璁惧ID涓�53504</para> + /// <para>瀹氫箟瀵硅薄锛欶reshAirAC</para> + /// </summary> + public final int FreshAir = 0xD100; + + /// <summary> + /// <para>婀垮害浼犳劅鍣�</para> + /// <para>璁惧ID涓�53760</para> + /// <para>瀹氫箟瀵硅薄锛欻umiditySensor</para> + /// <para>娉ㄦ剰瀹冧笌TemperatureSensor涓嶄竴鏍�;杩欎釜id瀹氭浜嗗氨鏄箍搴︿紶鎰熷櫒</para> + /// </summary> + public final int HumiditySensor = 0xD200; +} \ No newline at end of file diff --git a/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java new file mode 100644 index 0000000..f1649ad --- /dev/null +++ b/HDLSDK/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java @@ -0,0 +1,83 @@ +package com.hdl.sdk.link.zigbee.config; + + + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Created by jlchen on 12/16/21. + * ZigBee鍘熺敓鍗忚鎺у埗鐮佺浉鍏� + */ +public class ZigBee { + + + +// /** +// * 涓婚 +// */ +// @StringDef({}) +// @Retention(RetentionPolicy.SOURCE) +// public @interface TopicType { +// //鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) +// String GwLinuxLocate = "GwLinuxLocate"; +// //璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 +// String GetDeviceInfo = "GetDeviceInfo"; +// //鑾峰彇鍏ョ綉璁惧 +// String SearchNewDevice = "SearchNewDevice"; +// //淇敼璁惧绔彛锛堟寜閿級鍚嶇О +// String DeviceRename = "DeviceRename"; +// //璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� +// String RemoveDevice = "RemoveDevice"; +// //璁惧鎺у埗-鏃� Id-3-identify 瀹氫綅鍔熻兘 +// String Identify = "Identify"; +// //瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃� +// String SetEPDeviceFunctionType = "Device/SetEPDeviceFunctionType"; +// +// } + + /** + * 鍥炲涓婚 + */ + public @interface ReplyTopicType { + //鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) + public final String GwLinuxLocate = "GwLinuxLocate_Respon"; + //璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 + public final String GetDeviceInfo = "DeviceInfoRespon"; + //鑾峰彇鍏ョ綉璁惧 + public final String SearchNewDevice = "Device/SearchNewDevice"; + //淇敼璁惧绔彛锛堟寜閿級鍚嶇О + public final String DeviceRename = "DeviceRenameRespon"; + //璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� + public final String RemoveDevice = "RemoveDeviceRespon"; + //璁惧鎺у埗-鏃� Id-3-identify 瀹氫綅鍔熻兘 + public final String Identify = "Identify"; + //瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃� + public final String SetEPDeviceFunctionType = "Device/SetEPDeviceFunctionType"; + //鏂拌澶囧叆缃� + public final String DeviceInComingRespon = "DeviceInComingRespon"; + //璁剧疆鍏ョ綉娴佺▼鏂瑰紡 + public final String SetJoiningModeRespon = "SetJoiningMode_Respon"; + + } + + /** + * 鎺у埗鐮� + */ + public class CommandType { + //鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) + public static final int GwLinuxLocate = 85; + //璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 + public static final int GetDeviceInfo = 93; + //鑾峰彇鍏ョ綉璁惧 + public static final int SearchNewDevice = 94; + //淇敼璁惧绔彛锛堟寜閿級鍚嶇О + public static final int DeviceRename = 96; + //璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� + public static final int RemoveDevice = 99; + //瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃� + public static final int SetEPDeviceFunctionType = 110; + + } + +} diff --git a/HDLSDK/app/build.gradle b/HDLSDK/app/build.gradle index f7edf1a..910ccfe 100644 --- a/HDLSDK/app/build.gradle +++ b/HDLSDK/app/build.gradle @@ -32,13 +32,13 @@ implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.1' - implementation files('libs\\gson-2.8.8.jar') - +// implementation files('libs\\gson-2.8.8.jar') + implementation 'com.google.code.gson:gson:2.8.8' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.6' - implementation project(path: ':hdl-connect') + implementation project(path: ':HDLLinkLocalSdk') } \ No newline at end of file diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/DemoAdapter.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/DemoAdapter.java index 18f6d76..99c6eb5 100644 --- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/DemoAdapter.java +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/DemoAdapter.java @@ -1,6 +1,6 @@ package com.hdl.hdlsdk; -import androidx.annotation.NonNull; + import androidx.annotation.Nullable; import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; @@ -20,7 +20,7 @@ } @Override - protected void convert(@NonNull BaseViewHolder baseViewHolder, DemoBean demoBean) { + protected void convert( BaseViewHolder baseViewHolder, DemoBean demoBean) { baseViewHolder.setText(R.id.tv_title,demoBean.getName()); } } diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java index f4a4071..c769935 100644 --- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java @@ -3,7 +3,7 @@ import androidx.activity.result.ActivityResultCallback; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; -import androidx.annotation.NonNull; + import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; @@ -21,22 +21,25 @@ import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemClickListener; import com.google.gson.reflect.TypeToken; -import com.hdl.sdk.common.config.TopicConstant; -import com.hdl.sdk.common.event.EventListener; -import com.hdl.sdk.common.exception.HDLLinkException; -import com.hdl.sdk.common.utils.IdUtils; -import com.hdl.sdk.common.utils.gson.GsonConvert; -import com.hdl.sdk.connect.HDLLink; -import com.hdl.sdk.connect.bean.LinkResponse; -import com.hdl.sdk.connect.bean.request.AuthenticateRequest; -import com.hdl.sdk.connect.bean.response.BaseLocalResponse; -import com.hdl.sdk.connect.bean.response.GatewaySearchBean; -import com.hdl.sdk.connect.callback.HDLLinkCallBack; -import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.connect.socket.HDLAuthSocket; -import com.hdl.sdk.connect.bean.request.DeviceControlRequest; -import com.hdl.sdk.socket.SocketBoot; +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.bean.LinkFunctionBean; +import com.hdl.sdk.link.bean.LinkSceneBean; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; +import com.hdl.sdk.link.core.bean.request.DeviceControlRequest; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.bean.response.GatewaySearchBean; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkTCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLUdpConnect; + import java.io.UnsupportedEncodingException; import java.security.MessageDigest; @@ -62,26 +65,31 @@ removeAllTopicsListener(); } - void init() { - HDLLinkConfig.getInstance().setLocalSecret("e186beeb7974998e"); - HDLLinkConfig.getInstance().setGatewayId("1519863101509361666"); + /** + * 鍒濆鍖朒DLSDK + */ + void initHDLSDK() { + HDLLinkLocalSdk.getInstance().init("1530018255883706369","735c1677504a7034"); + } + + /** + * 涓夋柟璁惧闆嗘垚鍒癏DL鏃讹紝闇�瑕佸垵濮嬪寲鐨勪俊鎭� + */ + void initThird(){ + initDeviceInfo();//鍒濆鍖栧熀鏈俊鎭紝闈炲父閲嶈锛岃璇佹椂瑕佺敤 + checkIfCertified();//妫�娴嬫槸鍚﹀凡缁忚璇佷簡锛岀敤浜庡垽鏂� } @RequiresApi(api = Build.VERSION_CODES.O) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - responseTv = findViewById(R.id.response_tv); - tv = findViewById(R.id.state_tv); - rv = findViewById(R.id.rv); - rv.setLayoutManager(new LinearLayoutManager(this)); -// init(); - checkIfCertified(); - initDeviceInfo();//鍒濆鍖栧熀鏈俊鎭紝闈炲父閲嶈锛岃璇佹椂瑕佺敤 - registerAllTopicsListener(); + initView(); + initHDLSDK();//杩欐姣旇緝閲嶈锛屽湪浣跨敤鍓嶈璁剧疆濂藉綋鍓嶇綉鍏矷d鍙婂姞瑙e瘑閽� +// initThird();//涓夋柟璁惧闆嗘垚鏃惰鍒濆鍖� + registerAllTopicsListener();//娉ㄥ唽鐩戝惉鎺ユ敹鎵�鏈変富棰樼殑鏁版嵁 ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { @Override @@ -89,7 +97,7 @@ } }); - + //鍒濆鍖栧畨鍗撴潈闄� launcher.launch(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}); final List<DemoBean> beans = new ArrayList<>(); @@ -110,15 +118,9 @@ rv.setAdapter(demoAdapter); -// final SocketOptions options = new SocketOptions(); -// -// MessagePipeLine pipeLine = new MessagePipeLine(); -// options.setHandleMessage(pipeLine); -// options.setEnabledHeartbeat(false); - demoAdapter.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) { + public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) { switch (position) { case 0: //鍏ョ綉璁よ瘉 @@ -176,6 +178,13 @@ } }); } + //鍒濆鍖栨帶浠� + void initView(){ + responseTv = findViewById(R.id.response_tv); + tv = findViewById(R.id.state_tv); + rv = findViewById(R.id.rv); + rv.setLayoutManager(new LinearLayoutManager(this)); + } public void showToast(String text) { @@ -186,11 +195,10 @@ * 妫�娴嬫槸鍚﹁璇佽繃 */ void checkIfCertified() { - boolean isCertified = HDLLink.getInstance().checkIfCertified(); + boolean isCertified = HDLLinkLocalSdk.getInstance().checkIfCertified(); String mes = isCertified ? "宸茬粡璁よ瘉杩�" : "鏈璇�"; showToast(mes); tv.setText(mes); - } /** @@ -204,7 +212,7 @@ handleLinkResponse(response); } }; - HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); + HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener); } /** @@ -225,7 +233,6 @@ } } else { //鍏跺畠涓婚 - } } @@ -247,7 +254,7 @@ * 绉婚櫎鎵�鏈変富棰樻暟鎹殑鐩戝惉 */ void removeAllTopicsListener() { - HDLLink.getInstance().removeAllTopicsListener(allTopicsListener); + HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); } void initDeviceInfo() { @@ -303,7 +310,7 @@ authbean.setRequest(requestBean); //HDLLinkConfig.getInstance().getDeviceInfoBean()杩欎釜鍒濆鍖栫殑鏃跺�欒鍏堣缃ソ AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean); - HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() { @Override public void onError(HDLLinkException e) { // tv.setText("璁よ瘉澶辫触"); @@ -348,19 +355,14 @@ */ void searchGatewayBroadcast() { tv.setText("鎼滅储缃戝叧涓�..."); - HDLLink.getInstance().searchGatewayBroadcast(new HDLAuthSocket.SearchGatewayCallBack() { + HDLLinkLocalSdk.getInstance().searchGatewayBroadcast(new HDLUdpConnect.SearchGatewayCallBack() { @Override - public void onError(HDLLinkException e) { -// tv.setText("缃戝叧涓嶅湪绾�"); -// responseTv.setText(e.getMsg()); - Log.i("TAG", "缃戝叧涓嶅湪绾�" + e.getMsg()); + public void onSuccess(GatewaySearchBean gatewaySearchBean) { } @Override - public void onSuccess(GatewaySearchBean gatewaySearchBean) { -// tv.setText("缃戝叧鍦ㄧ嚎"); -// responseTv.setText("鎼滅储鎴愬姛 缃戝叧id锛�" + gatewaySearchBean.getGatewayId()); - Log.i("TAG", "onSuccess: 鎼滅储鎴愬姛锛�"+gatewaySearchBean.getGatewayId()); + public void onError(HDLLinkException e) { + } }); } @@ -371,18 +373,15 @@ void getFunctionList() { tv.setText("鑾峰彇鍔熻兘鍒楄〃涓�..."); responseTv.setText(""); - HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().getFunctionList(new HDLLinkTCallBack<List<LinkFunctionBean>>() { @Override - public void onError(HDLLinkException error) { -// tv.setText(error.getMsg()); - Log.i("TAG", "onError 鑾峰彇鍔熻兘鍒楄〃澶辫触" + error.getMsg()); + public void onSuccess(List<LinkFunctionBean> data) { + } @Override - public void onSuccess(String data) { -// tv.setText("鑾峰彇鍔熻兘鍒楄〃鎴愬姛"); -// responseTv.setText(data); - Log.i("TAG", "onSuccess 鑾峰彇鍔熻兘鍒楄〃鎴愬姛" + data.toString()); + public void onError(HDLLinkException e) { + } }); } @@ -395,17 +394,16 @@ tv.setText("鍔熻兘灞炴�ц鍙�"); List<String> sids = new ArrayList<>(); sids.add(testLightSid); - HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { + + HDLLinkLocalSdk.getInstance().getFunctionAttribute(sids, new HDLLinkTCallBack<List<LinkFunctionBean>>() { @Override - public void onSuccess(String msg) { -// responseTv.setText(msg); - Log.i("TAG", "onSuccess 鍔熻兘灞炴�ц鍙栨垚鍔�" + msg.toString()); + public void onSuccess(List<LinkFunctionBean> data) { + } @Override public void onError(HDLLinkException e) { -// responseTv.setText(e.getMsg()); - Log.i("TAG", "onError 鑾峰彇鍔熻兘鍒楄〃澶辫触" + e.getMsg()); + } }); } @@ -418,19 +416,15 @@ tv.setText("璇诲彇鐘舵�佷腑..."); List<String> list = new ArrayList<>(); list.add(testLightSid);//瑕佽鍙栬澶囩殑sid - HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().propertyRead(list, new HDLLinkCallBack() { @Override - public void onSuccess(String data) { -// tv.setText("璇诲彇鎴愬姛"); -// responseTv.setText(data); - Log.i("TAG", "onSuccess 璇诲彇璁惧鐘舵�佹垚鍔�" + data.toString()); + public void onSuccess(String msg) { + } @Override public void onError(HDLLinkException e) { -// tv.setText("璇诲彇澶辫触"); -// responseTv.setText(e.getMsg()); - Log.i("TAG", "onError 璇诲彇璁惧鐘舵�佸け璐�" + e.getMsg()); + } }); } @@ -452,7 +446,7 @@ statusBeanList.add(bean); request.setStatus(statusBeanList); requestList.add(request); - HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().propertyDown(requestList, new HDLLinkCallBack() { @Override public void onSuccess(String data) { // responseTv.setText(data); @@ -472,17 +466,15 @@ */ void getSceneList() { tv.setText("璇诲彇鍦烘櫙鍒楄〃"); - HDLLink.getInstance().getSceneList(new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().getSceneList(new HDLLinkTCallBack<List<LinkSceneBean>>() { @Override - public void onSuccess(String msg) { -// responseTv.setText(msg); - Log.i("TAG", "onSuccess 鑾峰彇鍦烘櫙鍒楄〃鎴愬姛" + msg.toString()); + public void onSuccess(List<LinkSceneBean> data) { + } @Override public void onError(HDLLinkException e) { -// responseTv.setText(e.getMsg()); - Log.i("TAG", "onError 鑾峰彇鍦烘櫙鍒楄〃澶辫触" + e.getMsg()); + } }); } @@ -504,7 +496,7 @@ } else { sids.add("04010560D2C76E0A0A0100010000"); } - HDLLink.getInstance().controlScene(sids, new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().controlScene(sids, new HDLLinkCallBack() { @Override public void onSuccess(String msg) { // responseTv.setText(msg); @@ -532,7 +524,7 @@ tv.setText("TCP鍙戦�� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙�"); String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); String bodyStr = getPropertyDownBodyStr(); - HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); + HDLLinkLocalSdk.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); } /** @@ -542,7 +534,7 @@ tv.setText("UDP鍙戦�� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙�"); String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); String bodyStr = getPropertyDownBodyStr(); - HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr); + HDLLinkLocalSdk.getInstance().udpSendMsg(propertyDownTopic, bodyStr,null); } private String getPropertyDownBodyStr() { @@ -574,7 +566,7 @@ tv.setText("UDP鍙戦�侊紝鐩戝惉涓婚鍥炲锛屽甫閲嶅彂甯﹀洖璋�"); String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); String bodyStr = getPropertyDownBodyStr(); - HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr, new HDLLinkResponseCallBack() { + HDLLinkLocalSdk.getInstance().udpSendMsg(propertyDownTopic, bodyStr, new HDLLinkResponseCallBack() { @Override public void onSuccess(LinkResponse msg) { Log.i("TAG", "onSuccess UDP鍙戦�佹垚鍔�" + GsonConvert.getGson().toJson(msg)); @@ -596,7 +588,7 @@ tv.setText("TCP鍙戦�侊紝鐩戝惉涓婚鍥炲锛屽甫閲嶅彂甯﹀洖璋�"); String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); String bodyStr = getPropertyDownBodyStr(); - HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr, new HDLLinkCallBack() { + HDLLinkLocalSdk.getInstance().tcpSendMsg(propertyDownTopic, bodyStr, new HDLLinkCallBack() { @Override public void onSuccess(String msg) { Log.i("TAG", "onSuccess TCP鍙戦�佹垚鍔�" + msg); diff --git a/HDLSDK/build.gradle b/HDLSDK/build.gradle index 81b2e55..c861ea6 100644 --- a/HDLSDK/build.gradle +++ b/HDLSDK/build.gradle @@ -1,5 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. -apply from: "config.gradle" + buildscript { repositories { google() diff --git a/HDLSDK/com.hdl.sdk/.gitignore b/HDLSDK/com.hdl.sdk/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/HDLSDK/com.hdl.sdk/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/HDLSDK/com.hdl.sdk/build.gradle b/HDLSDK/com.hdl.sdk/build.gradle deleted file mode 100644 index e9a0572..0000000 --- a/HDLSDK/com.hdl.sdk/build.gradle +++ /dev/null @@ -1,60 +0,0 @@ -//鎵撳寘鐨� -//apply plugin: 'com.android.library' -//apply plugin:'com.kezong.fat-aar' -plugins { - id 'java-library' -} - -/*android { - compileSdkVersion rootProject.compileSdkVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - versionCode 2 - versionName "1.0.15" - } - buildTypes { - debug { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility 1.8 - targetCompatibility 1.8 - } - - //gradlew assembleRelease - //gradlew makeJar - -}*/ - -dependencies { - - implementation fileTree(include: ['*.jar'], dir: 'libs') - -// embed project(path: ':hdl-common', configuration:'default') -// embed project(path: ':hdl-connect', configuration:'default') -// embed project(path: ':hdl-socket', configuration:'default') - - implementation project(path: ':hdl-common') - implementation project(path: ':hdl-connect') - implementation project(path: ':hdl-socket') -} - -//鎵撳寘鐨� -/* -buildscript { - - repositories { - google() - jcenter() - maven {url "https://plugins.gradle.org/m2/"} - } - - dependencies { - classpath 'com.android.tools.build:gradle:3.6.3' - classpath 'com.kezong:fat-aar:1.2.16' - } -}*/ diff --git a/HDLSDK/com.hdl.sdk/gradlew b/HDLSDK/com.hdl.sdk/gradlew deleted file mode 100644 index cccdd3d..0000000 --- a/HDLSDK/com.hdl.sdk/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/HDLSDK/com.hdl.sdk/gradlew.bat b/HDLSDK/com.hdl.sdk/gradlew.bat deleted file mode 100644 index f955316..0000000 --- a/HDLSDK/com.hdl.sdk/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/HDLSDK/com.hdl.sdk/proguard-rules.pro b/HDLSDK/com.hdl.sdk/proguard-rules.pro deleted file mode 100644 index 112f107..0000000 --- a/HDLSDK/com.hdl.sdk/proguard-rules.pro +++ /dev/null @@ -1,107 +0,0 @@ -#*******************************************************************# -#********** 浠ヤ笅鏄痙emo涓嶈兘娣锋穯鐨勫唴瀹� *********# -#*******************************************************************# - --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep class * implements android.os.Parcelable - --dontwarn com.google.zxing.** --keep class com.google.zxing.** { *;} - --keep public class com.alibaba.android.arouter.routes.**{*;} --keep public class com.alibaba.android.arouter.facade.**{*;} --keep class * implements com.alibaba.android.arouter.facade.template.ISyringe{*;} -# If you use the byType method to obtain Service, add the following rules to protect the interface: --keep interface * implements com.alibaba.android.arouter.facade.template.IProvider -# If single-type injection is used, that is, no interface is defined to implement IProvider, the following rules need to be added to protect the implementation -# -keep class * implements com.alibaba.android.arouter.facade.template.IProvider - -#*******************************************************************# -#********** 浠ヤ笂鏄痙emo涓嶈兘娣锋穯鐨勫唴瀹� *********# -#*******************************************************************# - -#*******************************************************************# -#********** 浠ヤ笅鏄疭DK涓嶈兘娣锋穯鐨勫唴瀹� *********# -#*******************************************************************# - -#========SDK瀵瑰鎺ュ彛=======# --keep class com.ezviz.opensdk.** { *;} - -#========浠ヤ笅鏄痟ik浜屾柟搴�=======# --dontwarn com.ezviz.** --keep class com.ezviz.** { *;} - --dontwarn com.ez.** --keep class com.ez.** { *;} - --dontwarn com.hc.CASClient.** --keep class com.hc.CASClient.** { *;} - --dontwarn com.videogo.** --keep class com.videogo.** { *;} - --dontwarn com.hik.TTSClient.** --keep class com.hik.TTSClient.** { *;} - --dontwarn com.hik.stunclient.** --keep class com.hik.stunclient.** { *;} - --dontwarn com.hik.streamclient.** --keep class com.hik.streamclient.** { *;} - --dontwarn com.hikvision.sadp.** --keep class com.hikvision.sadp.** { *;} - --dontwarn com.hikvision.netsdk.** --keep class com.hikvision.netsdk.** { *;} - --dontwarn com.neutral.netsdk.** --keep class com.neutral.netsdk.** { *;} - --dontwarn com.hikvision.audio.** --keep class com.hikvision.audio.** { *;} - --dontwarn com.mediaplayer.audio.** --keep class com.mediaplayer.audio.** { *;} - --dontwarn com.hikvision.wifi.** --keep class com.hikvision.wifi.** { *;} - --dontwarn com.hikvision.keyprotect.** --keep class com.hikvision.keyprotect.** { *;} - --dontwarn com.hikvision.audio.** --keep class com.hikvision.audio.** { *;} - --dontwarn org.MediaPlayer.PlayM4.** --keep class org.MediaPlayer.PlayM4.** { *;} -#========浠ヤ笂鏄痟ik浜屾柟搴�=======# - -#========浠ヤ笅鏄涓夋柟寮�婧愬簱=======# -# JNA --dontwarn com.sun.jna.** --keep class com.sun.jna.** { *;} - -# Gson --keepattributes *Annotation* --keep class sun.misc.Unsafe { *; } --keep class com.idea.fifaalarmclock.entity.*** --keep class com.google.gson.stream.** { *; } - -# OkHttp -# JSR 305 annotations are for embedding nullability information. --dontwarn javax.annotation.** -# A resource is loaded with a relative path so the package of this class must be preserved. --keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase -# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java. --dontwarn org.codehaus.mojo.animal_sniffer.* -# OkHttp platform used only on JVM and when Conscrypt dependency is available. --dontwarn okhttp3.internal.platform.ConscryptPlatform -# 蹇呴』棰濆鍔犵殑锛屽惁鍒欑紪璇戞棤娉曢�氳繃 --dontwarn okio.** -#========浠ヤ笂鏄涓夋柟寮�婧愬簱=======# - diff --git a/HDLSDK/config.gradle b/HDLSDK/config.gradle deleted file mode 100644 index 51a8ae6..0000000 --- a/HDLSDK/config.gradle +++ /dev/null @@ -1,5 +0,0 @@ -ext { - minSdkVersion = 16 - targetSdkVersion = 31 - compileSdkVersion = 31 -} \ No newline at end of file diff --git a/HDLSDK/hdl-common/build.gradle b/HDLSDK/hdl-common/build.gradle deleted file mode 100644 index d49bcfe..0000000 --- a/HDLSDK/hdl-common/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -plugins { -// id 'com.android.library' - id 'java-library' -} - -/*android { - compileSdkVersion rootProject.compileSdkVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - versionCode 2 - - versionName "1.0.15" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -}*/ -java { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 -} - -dependencies { -// api 'com.google.code.gson:gson:2.8.8' - implementation files('libs\\gson-2.8.8.jar') -} \ No newline at end of file diff --git a/HDLSDK/hdl-common/consumer-rules.pro b/HDLSDK/hdl-common/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 --- a/HDLSDK/hdl-common/consumer-rules.pro +++ /dev/null diff --git a/HDLSDK/hdl-common/libs/gson-2.8.8.jar b/HDLSDK/hdl-common/libs/gson-2.8.8.jar deleted file mode 100644 index 4707d40..0000000 --- a/HDLSDK/hdl-common/libs/gson-2.8.8.jar +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-common/proguard-rules.pro b/HDLSDK/hdl-common/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/HDLSDK/hdl-common/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/HDLSDK/hdl-common/src/.DS_Store b/HDLSDK/hdl-common/src/.DS_Store deleted file mode 100644 index 0787fb7..0000000 --- a/HDLSDK/hdl-common/src/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/.DS_Store b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/.DS_Store deleted file mode 100644 index 45f4ec0..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/.DS_Store b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/.DS_Store deleted file mode 100644 index e90f688..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/HDLSdk.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/HDLSdk.java deleted file mode 100644 index b9a3bee..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/HDLSdk.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.hdl.sdk.common; - -import com.hdl.sdk.common.utils.LogUtils; - -/** - * Created by Tong on 2021/9/28. - * Modify by panlili on 5/7/22 - */ -public class HDLSdk { - -// private Context context; - - /** - * 鑾峰彇褰撳墠鐗堟湰 - * @return - */ - public String getVersion() { - return version; - } - - private String version="1.0.15"; - - private HDLSdk() { - } - - private static class SingletonInstance { - private static final HDLSdk INSTANCE = new HDLSdk(); - } - - public static HDLSdk getInstance() { - return SingletonInstance.INSTANCE; - } - -/* public void init(Context context) { - this.context = context.getApplicationContext(); - LogUtils.i("Version:" + version); - }*/ - -// public Context getContext() { -// return context; -// } - - /** - * 璁剧疆鎵撳嵃鏄惁寮�鍚� - * @param enable - */ - public void setLogEnabled(boolean enable){ - LogUtils.setEnabled(enable); - } -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/config/TopicConstant.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/config/TopicConstant.java deleted file mode 100644 index 4046a29..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/config/TopicConstant.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.hdl.sdk.common.config; - -/** - * Created by Tong on 2021/9/22. - */ -public class TopicConstant { - - //缃戝叧骞挎挱鍏ョ綉鎸囦护 - public static final String GATEWAY_AUTH_BROADCAST = "/user/all/custom/device/network_access/broadcast"; - - //璁惧鍏ョ綉鍜岃璇� - public static final String DEIVCE_AUTH_REQUEST = "/user/all/custom/device/network_access/request"; - - //璁惧鍏ョ綉鍜岃璇佸搷搴� - public static final String DEIVCE_AUTH_REQUEST_REPLY = "/user/all/custom/device/network_access/request_reply"; - - //鎼滅储缃戝叧 - public static final String GATEWAY_SEARCH = "/user/all/custom/gateway/search"; - - //鎼滅储缃戝叧鍝嶅簲 - public static final String GATEWAY_SEARCH_REPLY = "/user/all/custom/gateway/search_reply"; - - //缃戝叧璇︾粏淇℃伅鑾峰彇s=gw_id - public static final String GATEWAY_INFO = "/user/%s/custom/gateway/get"; - - //鑾峰彇鐗╃悊璁惧鍒楄〃 - public static final String GET_DEVICE_LIST = " /user/%s/custom/device/list/get"; - - //鑾峰彇鐗╃悊璁惧鍒楄〃鍝嶅簲 - public static final String GET_DEVICE_LIST_REPLY = " /user/%s/custom/device/list/get_reply"; - - //鑾峰彇鍔熻兘鍒楄〃 - public static final String GET_FUNCTION_LIST = "/user/%s/custom/function/list/get"; - - //鑾峰彇鍔熻兘鍝嶅簲 - public static final String GET_FUNCTION_LIST_REPLY = "/user/%s/custom/function/list/get_reply"; - - //鍔熻兘灞炴�ц鍙� - public static final String GET_FUNCTION_ATTRIBUTE = "/user/%s/custom/function/attribute/get"; - - //鍔熻兘灞炴�у搷搴� - public static final String GET_FUNCTION_ATTRIBUTE_REPLY = "/user/%s/custom/function/attribute/get_reply"; - - //鎺у埗 - public static final String PROPERTY_DOWN = "/base/%s/thing/property/down"; - - //鎺у埗鍝嶅簲 - public static final String PROPERTY_DOWN_REPLY = "/base/%s/thing/property/down_reply"; - - //鐘舵�佷笂鎶� - public static final String PROPERTY_UP = "/base/%s/thing/property/up"; - - //鐘舵�佷笂鎶ュ搷搴� - public static final String PROPERTY_UP_REPLY = "/base/%s/thing/property/up_reply"; - - //璇诲彇鐘舵�� - public static final String PROPERTY_READ = "/base/%s/thing/property/read"; - - //璇诲彇鐘舵�佸搷搴� - public static final String PROPERTY_READ_REPLY = "/base/%s/thing/property/read_reply"; - - //8.1鑾峰彇鍦烘櫙鍒楄〃 - public static final String SCENE_LIST_GET = "/user/%s/custom/scene/list/get"; - - //8.2鑾峰彇鍦烘櫙 - public static final String SCENE_GET = "/user/%s/custom/scene/get"; - - //8.3鎵ц鍦烘櫙 - public static final String SCENE_CONTROL = "/user/%s/custom/scene/execute"; - - //8.4鍦烘櫙澧炲姞 - public static final String SCENE_ADD = "/user/%s/custom/scene/add"; - - //8.5鍦烘櫙缂栬緫 - public static final String SCENE_EDIT = "/user/%s/custom/scene/edit"; - - //8.6鍦烘櫙鍒犻櫎 - public static final String SCENE_DELETE = "/user/%s/custom/scene/delete"; - - /** - * 璁惧杩炴帴TCP涔嬪墠骞挎挱 - */ - public static final String BROADCAST="/user/all/custom/gateway/broadcast"; - - /** - * 涓荤綉鍏冲洖澶� - */ - public static final String BROADCAST_REPLY="/user/all/custom/gateway/broadcast_reply"; - - /** - * 蹇冭烦妫�娴� - */ - public static final String HEARTBEAT="/user/%s/custom/gateway/heartbeat"; - /** - * 蹇冭烦妫�娴嬪洖澶� - */ - public static final String HEARTBEAT_REPLY="/user/%s/custom/gateway/heartbeat_reply"; -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventDispatcher.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventDispatcher.java deleted file mode 100644 index a80f45f..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/event/EventDispatcher.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.hdl.sdk.common.event; - -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ExecutorService; - - -/** - * Created by Tong on 2021/9/22. - * 浜嬩欢鍒嗗彂 - */ -public class EventDispatcher { - - private static final List<EventListener> ALL_TOPICS_EVENT = new ArrayList<>();//鎵�鏈変富棰樻秷鎭� - - private static final Map<Object, List<EventListener>> EVENT = new HashMap<>(); - - private static final Map<EventListener, Integer> TYPE = new HashMap<>(); - - private static final int MAIN_TYPE = 0; - private static final int IO_TYPE = 1; - - private static final ExecutorService ioThread = ThreadToolUtils.getInstance().newFixedThreadPool(3); - - - private EventDispatcher() { - } - - // private static class SingletonInstance { - private static final EventDispatcher instance = new EventDispatcher(); -// } - - public static EventDispatcher getInstance() { - return instance; - } - - public void register(Object tag, EventListener listener) { - synchronized (this) { - try { - LogUtils.i("娉ㄥ唽涓婚锛�" + tag); - if (tag == null) return; - if (!EVENT.containsKey(tag)) { - EVENT.put(tag, new ArrayList<>()); - } - if (listener == null) { - LogUtils.i("鐩戝惉浜嬩欢涓虹┖"); - return; - } - Objects.requireNonNull(EVENT.get(tag)).add(listener); - TYPE.put(listener, MAIN_TYPE); - } catch (Exception e) { - LogUtils.e("register锛�" + e.getMessage()); - } - } - } - - public void registerIo(Object tag, EventListener listener) { - synchronized (this) { - LogUtils.i("娉ㄥ唽涓婚锛�" + tag); - if (tag == null) return; - if (!EVENT.containsKey(tag)) { - EVENT.put(tag, new ArrayList<>()); - } - try { - if (listener == null) { - LogUtils.i("鐩戝惉浜嬩欢涓虹┖"); - return; - } - Objects.requireNonNull(EVENT.get(tag)).add(listener); - TYPE.put(listener, IO_TYPE); - } catch (Exception e) { - LogUtils.e("registerIo锛�" + e.getMessage()); - } - } - } - - public void remove(Object tag) { - synchronized (this) { - if (tag == null) { - return; - } - try { - if (EVENT.containsKey(tag)) { - LogUtils.i("绉婚櫎key锛�" + tag); - List<EventListener> list = EVENT.get(tag); - for (EventListener eventListener : list) { - if (eventListener == null) { - continue; - } - TYPE.remove(eventListener); - } - EVENT.remove(tag); - } - } catch (Exception ignored) { - LogUtils.e("绉婚櫎event寮傚父1锛�" + ignored.getMessage()); - } - } - } - - public void remove(Object tag, EventListener listener) { - synchronized (this) { - try { - if (tag == null || listener == null) { - return; - } - if (EVENT.containsKey(tag)) { - LogUtils.i("绉婚櫎key锛�" + tag); - List<EventListener> ev = EVENT.get(tag); - if (ev != null && !ev.isEmpty()) { - TYPE.remove(listener); - ev.remove(listener); - } - } - } catch (Exception ignored) { - LogUtils.e("绉婚櫎event寮傚父1锛�" + ignored.getMessage()); - } - } - } - - public synchronized void post(Object tag, Object o) { - if (tag == null) { - LogUtils.i("post tag涓虹┖"); - return; - } - try { - if (EVENT.containsKey(tag)) { - LogUtils.i("post锛�" + tag); - List<EventListener> list = EVENT.get(tag); - if (list != null && !list.isEmpty()) { - for (EventListener listener : list) { - if (listener == null) { - continue; - } - - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - try { - if (listener != null) { - listener.onMessage(o); - } - } catch (Exception e) { - LogUtils.e("post寮傚父1锛�" + e.getMessage()); - } - } - }); - } - } - } - //鎵�鏈変富棰樼殑Listener閫氱煡 - if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.isEmpty()) { - for (EventListener listener : ALL_TOPICS_EVENT) { - if (listener == null) { - continue; - } - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - try { - if (listener != null) { - listener.onMessage(o); - } - } catch (Exception e) { - } - } - }); - } - } - } catch (Exception e) { - LogUtils.e("post寮傚父2锛�" + e.getMessage()); - } - } - - /** - * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 - * - * @param listener - */ - public synchronized void registerAllTopicsListener(EventListener listener) { - if (listener == null) { - return; - } - try { - if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.contains(listener)) { - ALL_TOPICS_EVENT.add(listener); - } - TYPE.put(listener, MAIN_TYPE); - } catch (Exception e) { - LogUtils.e("registerAllTopicsListener锛�" + e.getMessage()); - } - } - - /** - * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 - * - * @param listener - */ - public synchronized void removeAllTopicsListener(EventListener listener) { - try { - ioThread.execute(new Runnable() { - @Override - public void run() { - try { - if (listener == null) { - return; - } - if (ALL_TOPICS_EVENT != null && !ALL_TOPICS_EVENT.isEmpty()) { - TYPE.remove(listener); - ALL_TOPICS_EVENT.remove(listener); - } - } catch (Exception ignored) { - LogUtils.e("绉婚櫎event寮傚父1锛�" + ignored.getMessage()); - } - - } - }); - } catch (Exception e) { - LogUtils.e("绉婚櫎event寮傚父2锛�" + e.getMessage()); - } - } - - public synchronized void clear() { - ALL_TOPICS_EVENT.clear(); - EVENT.clear(); - TYPE.clear(); - } - - public synchronized void release() { - clear(); - ioThread.shutdownNow(); - } -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkCode.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkCode.java deleted file mode 100644 index a5c9a5f..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkCode.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.hdl.sdk.common.exception; - -/** - * Created by jlchen on 11/15/21. - * - * @Description : HDLError - */ -public enum HDLLinkCode { - - HDL_DATA_ERROR(-2000,"鍙傛暟寮傚父"), - HDL_DATA_NULL_ERROR(-2001,"鍙傛暟涓嶈兘涓虹┖"), - HDL_AUTH_ERROR(-2002,"璁よ瘉澶辫触"), - HDL_SEND_ERROR(-2003,"鍙戦�佸け璐�"), - HDL_TIMEOUT_ERROR(-2004,"瓒呮椂"), - HDL_UNAUTHORIZED_ERROR(-2005,"鏈璇侊紝璇峰厛璁よ瘉"), - HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED(-2006,"璁よ瘉澶辫触锛岀綉鍏虫湭娉ㄥ唽鍒颁簯绔�"), - HDL_SEARCH_GATEWAY_TIMEOUT_ERROR(-2007,"鎼滅储缃戝叧澶辫触锛岃秴鏃�"), - HDL_AUTH_MAC_KEY_ERROR_(-2008,"璁よ瘉澶辫触锛岃MAC瀵瑰簲鐨勮澶囧瘑閽ヤ笉瀛樺湪"), - HDL_GET_DEVICE_LIST_ERROR(-2100,"鑾峰彇璁惧鍒楄〃澶辫触"), - HDL_GET_FUNCTION_LIST_ERROR(-2101,"鑾峰彇鍔熻兘鍒楄〃澶辫触"), - HDL_GET_FUNCTION_PROPERTIES_ERROR(-2102,"鑾峰彇鍔熻兘灞炴�уけ璐�"), - HDL_CONTROL_FAILURE_ERROR(-2103,"鎺у埗澶辫触"); - - private String msg; - private int code; - - private HDLLinkCode(int code, String msg) { - this.msg = msg; - this.code = code; - } - - public String getMsg() { - return msg; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ByteUtils.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ByteUtils.java deleted file mode 100644 index b893d1d..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/ByteUtils.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.hdl.sdk.common.utils; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Created by Tong on 2021/9/23. - */ -public class ByteUtils { - - public static byte[] toByteArray(List<Byte> list) { - Byte[] temps = list.toArray(new Byte[0]); - byte[] result = new byte[temps.length]; - for (int i = 0; i < result.length; i++) { - result[i] = temps[i]; - } - return result; - - } - - public static List<Byte> toByteList(byte[] bytes) { - final List<Byte> list = new ArrayList<>(); - for (byte aByte : bytes) { - list.add(aByte); - } - return list; - - } - - public static byte[] getRangeBytes(List<Byte> list, int start, int end) { - Byte[] temps = Arrays.copyOfRange(list.toArray(new Byte[0]), start, end); - byte[] result = new byte[temps.length]; - for (int i = 0; i < temps.length; i++) { - result[i] = temps[i]; - } - return result; - - } - - /** - * 鎷兼帴byte - */ - public static byte[] concatBytes(byte[] bt1, byte[] bt2) { - if (bt1 == null) { - return bt2; - } - if (bt2 == null) { - return bt1; - } - byte[] bt3 = new byte[bt1.length + bt2.length]; - System.arraycopy(bt1, 0, bt3, 0, bt1.length); - System.arraycopy(bt2, 0, bt3, bt1.length, bt2.length); - return bt3; - } - - - public boolean endWith(Byte[] src, byte[] target) { - if (src.length < target.length) { - return false; - } - for (int i = 0; i < target.length; i++) { - if (target[target.length - i - 1] != src[src.length - i - 1]) { - return false; - } - } - return true; - } - - - public static int byteIndexOf(byte[] searched, byte[] find, int start) { - boolean matched; - int end = find.length - 1; - int skip = 0; - for (int index = start; index <= searched.length - find.length; ++index) { - matched = true; - if (find[0] != searched[index] || find[end] != searched[index + end]) continue; - else skip++; - if (end > 10) - if (find[skip] != searched[index + skip] || find[end - skip] != searched[index + end - skip]) - continue; - else skip++; - for (int subIndex = skip; subIndex < find.length - skip; ++subIndex) { - if (find[subIndex] != searched[index + subIndex]) { - matched = false; - break; - } - } - if (matched) { - return index; - } - } - return -1; - - } - - public static int getByteIndexOf(byte[] sources, byte[] src) { - return getByteIndexOf(sources, src, 0, sources.length); - } - - //鍒ゆ柇涓�涓猙yte鏁板�煎湪鍙﹀涓�涓猙yte鏁扮粍涓搴旂殑娓告爣鍊� - public static int getByteIndexOf(byte[] sources, byte[] src, int startIndex) { - return getByteIndexOf(sources, src, startIndex, sources.length); - } - - - //鍒ゆ柇涓�涓猙yte鏁板�煎湪鍙﹀涓�涓猙yte鏁扮粍涓搴旂殑娓告爣鍊硷紝鎸囧畾寮�濮嬬殑娓告爣鍜岀粨鏉熺殑娓告爣浣嶇疆 - public static int getByteIndexOf(byte[] sources, byte[] src, int startIndex, int endIndex) { - - if (sources == null || src == null || sources.length == 0 || src.length == 0) { - return -1; - } - - if (endIndex > sources.length) { - endIndex = sources.length; - } - - int i, j; - for (i = startIndex; i < endIndex; i++) { - if (sources[i] == src[0] && i + src.length < endIndex) { - for (j = 1; j < src.length; j++) { - if (sources[i + j] != src[j]) { - break; - } - } - - if (j == src.length) { - return i; - } - } - } - return -1; - } - - /** - * 瀛楃涓瞭o Bytes - * @param str 瀛楃涓� - * @return - */ - public static byte[] stringToBytes(String str) { - try { - // 浣跨敤鎸囧畾鐨勫瓧绗﹂泦灏嗘瀛楃涓茬紪鐮佷负byte搴忓垪骞跺瓨鍒颁竴涓猙yte鏁扮粍涓� - return str.getBytes("utf-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return new byte[]{}; - } - -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IdUtils.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IdUtils.java deleted file mode 100644 index 97181a7..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IdUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hdl.sdk.common.utils; - -import java.util.UUID; - -/** - * Created by Tong on 2021/10/8. - */ -public class IdUtils { - public static String getUUId() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } -} diff --git a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java b/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java deleted file mode 100644 index 1c492fb..0000000 --- a/HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/utils/IpUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.hdl.sdk.common.utils; - -//import android.content.Context; -//import android.net.wifi.WifiInfo; -//import android.net.wifi.WifiManager; - -import java.net.InetAddress; -import java.net.InterfaceAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Enumeration; - -/** - * Created by Tong on 2021/9/27. - */ -public class IpUtils { - - /** - * @return 骞挎挱鍦板潃 - */ - public static String getBroadcastAddress() { - return "255.255.255.255"; - } - - public static boolean isLocalIpAddress(String ipAddress) { - try { - for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); - niEnum.hasMoreElements(); ) { - NetworkInterface ni = niEnum.nextElement(); - for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) { - if (ipAddress.equals(interfaceAddress.getAddress().getHostAddress())) { - return true; - } - } - } - } catch (SocketException e) { - e.printStackTrace(); - } - return false; - } - - /*public static String getIP(Context application) { - WifiManager wifiManager = (WifiManager) application.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - if (!wifiManager.isWifiEnabled()) { - try { - for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { - NetworkInterface intf = en.nextElement(); - for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { - InetAddress inetAddress = enumIpAddr.nextElement(); - if (!inetAddress.isLoopbackAddress()) { - return inetAddress.getHostAddress(); - } - } - } - } catch (SocketException e) { - e.printStackTrace(); - } - } else { - WifiInfo wifiInfo = wifiManager.getConnectionInfo(); - int ipAddress = wifiInfo.getIpAddress(); - return intToIp(ipAddress); - } - return null; - } -*/ - - private static String intToIp(int i) { - - return (i & 0xFF) + "." + - ((i >> 8) & 0xFF) + "." + - ((i >> 16) & 0xFF) + "." + - (i >> 24 & 0xFF); - } -} diff --git a/HDLSDK/hdl-connect/.gitignore b/HDLSDK/hdl-connect/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/HDLSDK/hdl-connect/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/HDLSDK/hdl-connect/build.gradle b/HDLSDK/hdl-connect/build.gradle deleted file mode 100644 index 5917d64..0000000 --- a/HDLSDK/hdl-connect/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -plugins { -// id 'com.android.library' - id 'java-library' -} - -/*android { - compileSdkVersion rootProject.compileSdkVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - versionCode 2 - versionName "1.0.15" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -}*/ -java { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 -} - -dependencies { - api project(path: ':hdl-socket') - implementation files('libs\\commons-lang3-3.12.0.jar') - implementation files('libs\\gson-2.8.8.jar') -} diff --git a/HDLSDK/hdl-connect/consumer-rules.pro b/HDLSDK/hdl-connect/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 --- a/HDLSDK/hdl-connect/consumer-rules.pro +++ /dev/null diff --git a/HDLSDK/hdl-connect/libs/commons-lang3-3.12.0.jar b/HDLSDK/hdl-connect/libs/commons-lang3-3.12.0.jar deleted file mode 100644 index 4d434a2..0000000 --- a/HDLSDK/hdl-connect/libs/commons-lang3-3.12.0.jar +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-connect/libs/gson-2.8.8.jar b/HDLSDK/hdl-connect/libs/gson-2.8.8.jar deleted file mode 100644 index 4707d40..0000000 --- a/HDLSDK/hdl-connect/libs/gson-2.8.8.jar +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-connect/proguard-rules.pro b/HDLSDK/hdl-connect/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/HDLSDK/hdl-connect/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/.DS_Store b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/.DS_Store deleted file mode 100644 index 9f83336..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/.DS_Store b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/.DS_Store deleted file mode 100644 index 4697092..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java deleted file mode 100644 index 3130eca..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java +++ /dev/null @@ -1,246 +0,0 @@ -package com.hdl.sdk.connect; - -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.connect.bean.request.DeviceControlRequest; -import com.hdl.sdk.connect.callback.HDLLinkCallBack; -import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.common.event.EventDispatcher; -import com.hdl.sdk.common.event.EventListener; -import com.hdl.sdk.connect.bean.request.AuthenticateRequest; -import com.hdl.sdk.connect.socket.HDLAuthSocket; -import com.hdl.sdk.connect.socket.HDLSocket; - -import java.util.List; - -/** - * Created by jlchen on 11/15/21. - * - * @Description : HDLLink - */ -public class HDLLink { - /** - * instance - */ - private static final HDLLink instance=new HDLLink(); - /** - * getInstance - * - * @return HDLLink - */ - public static HDLLink getInstance() { -// if (instance == null) { -// synchronized (HDLLink.class) { -// if (instance == null) { -// instance = new HDLLink(); -// } -// } -// } - return instance; - } - - /** - * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 - * @param listener - */ - public synchronized void registerAllTopicsListener(EventListener listener){ - EventDispatcher.getInstance().registerAllTopicsListener(listener); - } - /** - * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 - * @param listener - */ - public synchronized void removeAllTopicsListener(EventListener listener) { - if(listener == null) return; - EventDispatcher.getInstance().removeAllTopicsListener(listener); - } - - /***********************涓夋柟璁惧鍜岀綉鍏抽�氫俊涔嬪墠鐨勮璇佹祦绋�****************************/ - /** - * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 - * 璁よ瘉閫氳繃鎵嶈兘杩涜璁惧鎺у埗 - * @return - */ - public boolean checkIfCertified(){ - return HDLLinkConfig.getInstance().checkIfCertified(); - } - - /** - * 寮�濮嬬洃鍚拰鍙戣捣鍏ョ綉鍙婅璇佽姹� - * - * @param request 璁よ瘉璇锋眰淇℃伅 - * @param callBack 缁撴灉鍥炶皟 - */ - public void startAuthenticateRequest(AuthenticateRequest request, HDLLinkCallBack callBack) { - LogUtils.i("鍙戦�佽璇佽姹�"); - HDLAuthSocket.getInstance().startAuthenticateRequest(request,callBack); - } - - /** - * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 - * - * @param ip 缃戝叧IP - * @param request 璁よ瘉璇锋眰淇℃伅 - * @param callBack 缁撴灉鍥炶皟 - */ - public void sendAuthenticateRequest(String ip, AuthenticateRequest request, HDLLinkCallBack callBack) { - HDLAuthSocket.getInstance().sendAuthenticateRequest(ip, request, callBack); - } - - // /** -// * 寮�濮嬫悳绱㈡墍鏈夌綉鍏筹紝鏈夌綉鍏冲洖澶嶅氨鍥炶皟锛屼笂灞傝嚜宸卞仛鍘婚噸鍒ゆ柇 -// * -// * @param callBack 鍥炶皟 -// */ -// public void startSearchAllGateway(HDLAuthSocket.SearchGatewayCallBack callBack) { -// -// } -// -// /** -// * 鏆傚仠鎼滅储缃戝叧 -// */ -// public void endSearchAllGateway() { -// -// } - - /***********************涓夋柟璁惧璇峰厛璁よ瘉鎴愬姛 鍐嶈皟鐢ㄤ笅闈㈢殑鎺ュ彛鍜岀綉鍏抽�氫俊****************************/ - /** - * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 - * @param callBack 鍥炶皟 - */ - public void searchGatewayMulticast(HDLAuthSocket.SearchGatewayCallBack callBack) { - HDLAuthSocket.getInstance().searchGatewayMulticast(callBack); - } - - /** - * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 - * @param callBack 鍥炶皟 - */ - public void searchGatewayBroadcast(HDLAuthSocket.SearchGatewayCallBack callBack) { - HDLAuthSocket.getInstance().searchGatewayBroadcast(callBack); - } - - /** - * 鑾峰彇璁惧鍒楄〃 - */ - public void getDeviceList(HDLLinkCallBack callBack) { - HDLSocket.getInstance().getDeviceList(callBack); - } - - /** - * 鑾峰彇鍔熻兘鍒楄〃 - */ - public void getFunctionList(HDLLinkCallBack callBack) { - HDLSocket.getInstance().getFunctionList(callBack); - } - - /** - * 鑾峰彇鍔熻兘灞炴�� - * - * @param sids - * @param callBack - */ - public void getFunctionAttribute(List<String> sids, HDLLinkCallBack callBack) { - HDLSocket.getInstance().getFunctionAttribute(sids, callBack); - } - - /** - * 璁惧鎺у埗 - * @param request 鎺у埗鐘舵�佸弬鏁� - * @param callBack 缁撴灉鍥炶皟 - */ - public void propertyDown(List<DeviceControlRequest> request, HDLLinkCallBack callBack) { - HDLSocket.getInstance().propertyDown(request, callBack); - } - - /** - * 璇诲彇鐘舵�� - * @param sids 璇锋眰鍙傛暟 鎸囧畾璇诲彇鐨勮澶噑id鍒楄〃 - * @param callBack 鍥炶皟 - */ - public void propertyRead(List<String> sids, HDLLinkCallBack callBack) { - HDLSocket.getInstance().propertyRead(sids, callBack); - } - - /** - * 鑾峰彇鍦烘櫙鍒楄〃 - */ - public void getSceneList(HDLLinkCallBack callBack) { - HDLSocket.getInstance().getSceneList(callBack); - } - - /** - * 鍦烘櫙鎺у埗 - * @param sids 鍦烘櫙sid鍒楄〃 - * @param callBack 鍥炶皟 - */ - public void controlScene(List<String> sids, HDLLinkCallBack callBack) { - HDLSocket.getInstance().controlScene(sids, callBack); - } - - /** - * 閫氱敤UDP鍙戦�佹寚浠� - * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr body鍐呭 - * @param callBack 鍥炶皟 - */ - public void udpSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { - HDLAuthSocket.getInstance().udpSendMsg(topic, bodyStr,false, callBack); - } - - /** - * 閫氱敤骞挎挱UDP鍙戦�佹寚浠� - * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr body鍐呭 - * @param callBack 鍥炶皟 - */ - public void udpBroadcastSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { - HDLAuthSocket.getInstance().udpSendMsg(topic, bodyStr,true, callBack); - } - - /** - * 閫氱敤TCP鍙戦�佹寚浠� - * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr body鍐呭 - * @param callBack 鍥炶皟 - */ - public void tcpSendMsg(String topic, String bodyStr, HDLLinkCallBack callBack) { - HDLAuthSocket.getInstance();//閫氳繃杩欎釜鍙互鍏堝垵濮嬪寲UDP鐩戝惉浜嬩欢 - HDLSocket.getInstance().tcpSendMsg(topic, bodyStr, callBack); - } - - /** - * 閫氱敤鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� - */ - public void udpSendMsg(String topic, String bodyStr) { - HDLAuthSocket.getInstance().udpSendMsg(topic, bodyStr,false); - } - - /** - * 閫氱敤骞挎挱鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� - */ - public void udpBroadcastSendMsg(String topic, String bodyStr) { - HDLAuthSocket.getInstance().udpSendMsg(topic, bodyStr,true); - } - - /** - * 閫氱敤TCP鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� - */ - public void tcpSendMsg(String topic, String bodyStr) { - HDLAuthSocket.getInstance();//閫氳繃杩欎釜鍙互鍏堝垵濮嬪寲UDP鐩戝惉浜嬩欢 - HDLSocket.getInstance().tcpSendMsg(topic, bodyStr); - } -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java deleted file mode 100644 index e46cccb..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.hdl.sdk.connect.bean; - -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.common.utils.ByteUtils; -import com.hdl.sdk.connect.utils.AesUtil; - -/** - * Created by Tong on 2021/9/29. - */ -public class LinkRequest { - private String topic; - private String data; - - private int length; - - public LinkRequest() { - } - - public LinkRequest(String topic, String data) { - this.topic = topic; - setData(data); - } - - public String getTopic() { - return topic; - } - - public void setTopic(String topic) { - this.topic = topic; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - if (!TextUtils.isEmpty(data)) { - setLength(getBytesLength(data)); - } else { - setLength(0); - } - - } - - public int getLength() { - return length; - } - - private void setLength(int length) { - this.length = length; - } - - @Override - public String toString() { - return "Topic:" + - getTopic() + - "\r\n" + - "Length:" + - getLength() + - "\r\n\r\n" + - getData(); - } - - - private int getBytesLength(String str) { - return ByteUtils.stringToBytes(str).length; - } - - - /** - * 鑾峰彇鍙戦�佹暟鎹産yte - * - * @return - */ - public byte[] getSendBytes() { - try { - //鍒ゆ柇鏄惁闇�瑕佸姞瀵� - if (HDLLinkConfig.getInstance().ifNeedEncrypt(topic)) { - //闇�瑕佸姞瀵� - byte[] dataBytes = AesUtil.aesEncrypt(ByteUtils.stringToBytes(data), HDLLinkConfig.getInstance().getLocalSecret()); - String headString = "Topic:" + getTopic() + "\r\n" + "Length:" + dataBytes.length + "\r\n" + "\r\n"; - byte[] headBytes = headString.getBytes("utf-8"); - byte[] sendBytes = ByteUtils.concatBytes(headBytes, dataBytes); - LogUtils.i("鍙戦�佹暟鎹細\r\n" + headString + "\r\n" + data); - return sendBytes; - - } else { - String sendString = this.toString(); - LogUtils.i("鍙戦�佹暟鎹細\r\n" + sendString); - return sendString.getBytes("utf-8"); - } - - } catch (Exception e) { - return new byte[]{}; - } - } -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/BaseCallBack.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/BaseCallBack.java deleted file mode 100644 index 5110851..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/callback/BaseCallBack.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hdl.sdk.connect.callback; - -import com.hdl.sdk.common.exception.HDLLinkException; - -/** - * Created by Tong on 2021/11/11. - */ -public interface BaseCallBack { - - void onError(HDLLinkException e); - -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/config/HDLLinkConfig.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/config/HDLLinkConfig.java deleted file mode 100644 index bc00c48..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/config/HDLLinkConfig.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.hdl.sdk.connect.config; - -import com.hdl.sdk.common.config.TopicConstant; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.connect.bean.request.AuthenticateRequest; -import com.hdl.sdk.connect.bean.response.GatewaySearchBean; - - -/** - * Created by jlchen on 11/11/21. - * Modify by panlili on 5/7/22 - * - * @Description : HDLLinkConfig - */ -public class HDLLinkConfig { - private static String AUTHENTICATE_LS_KEY = ""; - private static String AUTHENTICATE_GATEWAYID_KEY = ""; - private static String AUTHENTICATE_IPADDRESS_KEY = ""; - - private String localSecret;//鏈湴鍔犲瘑瀵嗛挜 - private String gatewayId; - private String ipAddress; - private GatewaySearchBean currentGateway;//褰撳墠缃戝叧 - - private AuthenticateRequest.AuthenticateDeviceInfoBean deviceInfoBean;//褰撳墠璁惧鍩烘湰淇℃伅 - - /** - * instance - */ - private static final HDLLinkConfig instance = new HDLLinkConfig(); - - private HDLLinkConfig() { - loadConfig(); - } - - /** - * getInstance - * - * @return AuthenticateConfig - */ - public static HDLLinkConfig getInstance() { - return instance; - } - - /** - * 娓呯┖缂撳瓨 - */ - public void clearConfig() { - this.gatewayId = ""; - this.ipAddress = ""; - this.localSecret = ""; - } - - /** - * 鍔犺浇缂撳瓨 - */ - void loadConfig() { - localSecret = AUTHENTICATE_LS_KEY; - gatewayId = AUTHENTICATE_GATEWAYID_KEY; - ipAddress = AUTHENTICATE_IPADDRESS_KEY; - } - - /** - * 淇濆瓨閰嶇疆 - * - * @param localSecret - * @param gatewayId - * @param ipAddress - */ - public void saveConfig(String localSecret, String gatewayId, String ipAddress) { - this.localSecret = localSecret; - this.gatewayId = gatewayId; - this.ipAddress = ipAddress; - AUTHENTICATE_LS_KEY = localSecret; - AUTHENTICATE_GATEWAYID_KEY = gatewayId; - AUTHENTICATE_IPADDRESS_KEY = ipAddress; - } - - /** - * 閲嶆柊淇濆瓨 - */ - public void reSaveConfig() { - this.saveConfig(this.localSecret, this.gatewayId, this.ipAddress); - } - - /** - * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 - * - * @return - */ - public boolean checkIfCertified() { - //localSecret涓嶄负绌哄苟涓旈暱搴︾瓑浜�16 缃戝叧id涓嶈兘涓虹┖ - return !TextUtils.isEmpty(localSecret) - && localSecret.length() == 16 - && !TextUtils.isEmpty(gatewayId); - } - - public void setLocalSecret(String localSecret) { - this.localSecret = localSecret; - AUTHENTICATE_LS_KEY = localSecret; - } - - public String getLocalSecret() { - return localSecret; - } - - public String getGatewayId() { - return gatewayId; - } - - public void setGatewayId(String gatewayId) { - this.gatewayId = gatewayId; - } - - public String getIpAddress() { - return ipAddress; - } - - public void setIpAddress(String ipAddress) { - this.ipAddress = ipAddress; - } - - public GatewaySearchBean getCurrentGateway() { - return currentGateway; - } - - public void setCurrentGateway(GatewaySearchBean currentGateway) { - this.currentGateway = currentGateway; - if (this.currentGateway != null && !TextUtils.isEmpty(this.currentGateway.getIp_address())) { - if (!this.ipAddress.equals(this.currentGateway.getIp_address())) { - //濡傛灉IP鍦板潃鏈夊彉鍖栧垯鏇存柊 - this.ipAddress = this.currentGateway.getIp_address(); - AUTHENTICATE_IPADDRESS_KEY = ipAddress; - } - } - } - - /** - * 鍒ゆ柇褰撳墠涓婚鏁版嵁鏄惁闇�瑕佸姞瀵� - * - * @param topicStr 褰撳墠涓婚 - * @return - */ - public boolean ifNeedEncrypt(String topicStr) { - //杩囨护鐩稿叧闇�瑕佸姞瀵嗙殑涓婚 - return (!topicStr.contains(TopicConstant.GATEWAY_AUTH_BROADCAST) //缃戝叧骞挎挱鍏ョ綉鎸囦护 - && !topicStr.contains(TopicConstant.DEIVCE_AUTH_REQUEST) //鍏ョ綉璁よ瘉 - && !topicStr.contains(TopicConstant.GATEWAY_SEARCH) //鎼滅储缃戝叧涓婚 - && !topicStr.contains(TopicConstant.BROADCAST) - && !TextUtils.isEmpty(localSecret) //鏈夊瘑閽ュ氨鏄姞瀵� - ); - } - - /** - * 鎷兼帴缃戝叧ID鑾峰彇瀹屾暣鐨勪富棰� - * - * @param topicStr - * @return - */ - public String getFullTopic(String topicStr) { - return String.format(topicStr, gatewayId); - } - - public AuthenticateRequest.AuthenticateDeviceInfoBean getDeviceInfoBean() { - return deviceInfoBean; - } - - public void setDeviceInfoBean(AuthenticateRequest.AuthenticateDeviceInfoBean deviceInfoBean) { - this.deviceInfoBean = deviceInfoBean; - } -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java deleted file mode 100644 index 74fdc83..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageDecoder.java +++ /dev/null @@ -1,251 +0,0 @@ -package com.hdl.sdk.connect.protocol; - -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.common.event.EventDispatcher; -import com.hdl.sdk.common.utils.ByteUtils; -import com.hdl.sdk.connect.bean.LinkResponse; -import com.hdl.sdk.connect.utils.AesUtil; -import com.hdl.sdk.socket.codec.ByteToMessageDecoder; - -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; - -/** - * Created by Tong on 2021/9/22. - * link鍗忚绮樺寘鎷嗗寘 - */ -public class LinkMessageDecoder extends ByteToMessageDecoder<LinkResponse> { - - private final List<Byte> bytes; - - private final byte[] head = "Topic:".getBytes(); -// private final byte[] body = "\r\n\r\n".getBytes(); - - public LinkMessageDecoder() { - this.bytes = new ArrayList<>(); - } - - /// <summary> - /// 鑾峰彇鍐呭闀垮害 - /// </summary> - /// <param name="topMsgs"></param> - /// <returns></returns> - int getLenght(String[] topMsgs) { - for (int i = 0; i < topMsgs.length; i++) { - String topMsg = topMsgs[i].trim(); - if (topMsg.startsWith("Length:")) { - return Integer.parseInt(topMsg.replace("Length:", "")); - } - } - //鎵句笉鍒伴暱搴� - return -1; - } - - /// <summary> - /// 鑾峰彇涓婚 - /// </summary> - /// <param name="topMsgs"></param> - /// <returns></returns> - private String getTopic(String[] topMsgs) { - for (int i = 0; i < topMsgs.length; i++) { - String topMsg = topMsgs[i].trim(); - if (topMsg.startsWith("Topic:")) { - return topMsg.replace("Topic:", ""); - } - } - //鎵句笉鍒颁富棰� - return null; - } - - /** - * 鑾峰彇鏁版嵁鐨勫紑濮嬩綅缃� - * - * @param arrayList 鎺ユ敹鍒扮殑鎵�鏈夋暟鎹� - * @return 鏁版嵁浣嶇殑寮�濮嬬储寮� - */ - int getDataIndex(List<Byte> arrayList) { - byte r = (byte) '\r'; - byte n = (byte) '\n'; - for (int i = 0; i < arrayList.size(); i++) { - //鎵惧嚭鏁版嵁鍐呭鍓嶉潰鐨勪袱涓崲琛� - if (3 <= i && arrayList.get(i - 3) == r && arrayList.get(i - 2) == n && arrayList.get(i - 1) == r && arrayList.get(i) == n) { - //鍓╀綑鐨勬暟鎹� - return i + 1; - } - } - return -1; - } - - void initReceiveData(List<Byte> list) { - - int index = 0; - boolean isMatch = false; - for (; index < list.size() - head.length; index++) { - isMatch = true; - for (int j = 0, k = 0; j < head.length; j++, k++) { - if (head[j] != list.get(index + k)) { - isMatch = false; - break; - } - } - if (isMatch) { - break; - } - } - - if (0 < index && isMatch) { - List<Byte> tempList = new ArrayList<Byte>(); - for (int i = index; i < list.size(); i++) { - tempList.add(list.get(i)); - } - - list.clear(); - for(int i=0;i<tempList.size();i++){ - list.add(tempList.get(i)); - } - } - } - - - @Override - protected synchronized LinkResponse decoder(Object msg,String ipaddress) throws Exception { - if (msg instanceof byte[]) { - bytes.addAll(ByteUtils.toByteList((byte[]) msg)); - //濡傛灉澶氭潯鍛戒护鎵撳寘鍦ㄤ竴鏉℃暟鎹腑锛岄兘闇�瑕佸鐞嗗畬 - while (true) { - initReceiveData(bytes); - byte[] recevieBytes = ByteUtils.toByteArray(bytes); - String data = new String(recevieBytes); - - String[] topMsgs = data.split("\r\n"); - - String topic = getTopic(topMsgs); - if (topic == null) { - break; - } - - int lenght = getLenght(topMsgs); - - if (lenght <= 0) { - //澶撮儴鏁版嵁杩樻病鏈夋帴鏀跺畬鎴� - break; - } - //鏄惁宸茬粡鑾峰彇瀹屾暣鎵�鏈夌殑鏁版嵁 - byte[] body = new byte[lenght]; - int index = getDataIndex(bytes); - if (bytes.size() < index + lenght) { - //褰撳墠鏁版嵁杩樻病鏈夋帴鏀跺畬鎴� - break; - } - //澶嶅埗鍑篵ody鏁版嵁 - System.arraycopy(recevieBytes, index, body, 0, body.length); - - //淇濈暀鍓╀綑鐨勬暟鎹紝浠ユ鐢� - bytes.clear(); - for (int i = index + lenght; i < recevieBytes.length; i++) { - bytes.add(recevieBytes[i]); - } - LinkResponse response = new LinkResponse(); - response.setSource_ipAddress(ipaddress); - response.setTopic(topic); - if (HDLLinkConfig.getInstance().ifNeedEncrypt(response.getTopic())) { - //闇�瑕佽В瀵� - byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret()); - if (bodyBytes != null) { - body = bodyBytes; - } else { - try { - //涔嬪墠鐨勭増鏈繖鍧楁槸鏄庢枃鐨� - if (!topic.contains("heartbeat_reply")) { - /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + Base64.getEncoder().encodeToString(body)); - else { - LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + new String(body, "utf-8")); - }*/ - LogUtils.e("瑙e瘑澶辫触锛屾暟鎹唴瀹规槸锛歕r\n" + new String(body, "utf-8")); - } - } catch (Exception e) { - } - } - } - - String bodyString = new String(body, "utf-8"); - response.setData(bodyString); - LogUtils.i( "鎺ユ敹鍒版暟鎹�:" + response.getTopic() + "\r\n" + response.getData()); - //闈炴甯告暟鎹紝杩斿洖 - if (!((bodyString.startsWith("{") &&bodyString.endsWith("}")) - || (bodyString.startsWith("[")&&bodyString.endsWith("]")))) { - continue; - } - //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� - EventDispatcher.getInstance().post(response.getTopic(), response); - } - return null; - -// //瑙f瀽娴� -// byte[] data = (byte[]) msg; -// bytes.addAll(ByteUtils.toByteList(data)); -// -// byte[] byteArray = ByteUtils.toByteArray(bytes); -// int headIndex = ByteUtils.getByteIndexOf(byteArray, head); -// if (headIndex > 0) { -// //绉诲姩鍒癶ead 寮�濮嬩綅缃� -// bytes.subList(0, headIndex).clear(); -// byteArray = ByteUtils.toByteArray(bytes); -// } -// -// int bodyIndex = ByteUtils.getByteIndexOf(byteArray, body); -// if (bodyIndex < 0) { -// //澶撮儴鏈幏鍙栧畬鎴� -// return null; -// } -// int bodyStartIndex = bodyIndex + body.length; -// -// //瑙f瀽澶撮儴 -// ProtocolParse parse = new ProtocolParse(byteArray); -// response.setTopic(parse.getTopic()); -// -// int bodyLength = parse.getLength(); -// if (bodyLength > 0) { -// if (byteArray.length >= bodyLength + bodyStartIndex) { -// byte[] body = ByteUtils.getRangeBytes(bytes, bodyStartIndex, bodyStartIndex + bodyLength); -// -// if (HDLLinkConfig.getInstance().ifNeedEncrypt(response.getTopic())) { -// //闇�瑕佽В瀵� -// byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret()); -//// byte[] bodyBytes = AESUtils.decryptAES(body,AuthenticateConfig.getInstance().getLocalSecret()); -// if (bodyBytes != null) { -// response.setData(new String(bodyBytes, "utf-8")); -//// LogUtils.i("TAG", "瑙e瘑 涓婚锛�"+response.getTopic()+ " body: "+response.getData()); -// } else { -// //瑙e瘑澶辫触锛岃繑鍥炲師鏁版嵁 -// response.setData(new String(body, "utf-8")); -// } -// -// } else { -// response.setData(new String(body, "utf-8")); -// } -// -// if (byteArray.length >= bodyLength + bodyStartIndex) { -// //淇濆瓨浣欑暀 -// byte[] remaining = ByteUtils.getRangeBytes(bytes, bodyStartIndex + bodyLength, byteArray.length); -// bytes.clear(); -// for (byte b : remaining) { -// bytes.add(b); -// } -// } -// //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� -// EventDispatcher.getInstance().post(response.getTopic(), response); -// return response; -// } -// } else if (bodyLength == 0) { -// //body涓虹┖ -// return response; -// } - - } - return null; - } -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageEncoder.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageEncoder.java deleted file mode 100644 index 95191be..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/protocol/LinkMessageEncoder.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hdl.sdk.connect.protocol; - - -import com.hdl.sdk.socket.codec.MessageToByteEncoder; - -/** - * Created by Tong on 2021/9/22. - * link鍗忚鍚堝寘 - */ -public class LinkMessageEncoder extends MessageToByteEncoder { - - @Override - protected byte[] encode(byte[] data) throws Exception { - return data; - } - -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLSocket.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLSocket.java deleted file mode 100644 index d42d619..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLSocket.java +++ /dev/null @@ -1,691 +0,0 @@ -package com.hdl.sdk.connect.socket; - -import com.google.gson.JsonObject; -import com.hdl.sdk.common.config.TopicConstant; -import com.hdl.sdk.common.event.EventDispatcher; -import com.hdl.sdk.common.event.EventListener; -import com.hdl.sdk.common.exception.HDLLinkCode; -import com.hdl.sdk.common.exception.HDLLinkException; -import com.hdl.sdk.common.utils.IdUtils; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.common.utils.gson.GsonConvert; -import com.hdl.sdk.connect.bean.request.BroadcastRequest; -import com.hdl.sdk.connect.bean.response.BaseLocalResponse; -import com.hdl.sdk.connect.bean.request.DeviceControlRequest; -import com.hdl.sdk.connect.bean.request.FunctionAttributeRequest; -import com.hdl.sdk.connect.bean.LinkRequest; -import com.hdl.sdk.connect.bean.LinkResponse; -import com.hdl.sdk.connect.bean.request.PropertyReadRequest; -import com.hdl.sdk.connect.callback.HDLLinkCallBack; -import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; -import com.hdl.sdk.connect.config.HDLLinkConfig; -import com.hdl.sdk.connect.protocol.LinkMessageDecoder; -import com.hdl.sdk.connect.protocol.LinkMessageEncoder; -import com.hdl.sdk.socket.SocketBoot; -import com.hdl.sdk.socket.SocketOptions; -import com.hdl.sdk.socket.client.IHeartbeat; -import com.hdl.sdk.socket.client.TcpClient; -import com.hdl.sdk.socket.codec.MessagePipeLine; -import com.hdl.sdk.socket.listener.ConnectStatusListener; -import com.hdl.sdk.socket.listener.SendListener; - -import org.apache.commons.lang3.StringEscapeUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by Tong on 2021/9/26. - * 1銆侀�氳繃Udp 缁勬挱鎴栬�呭箍鎾悳绱㈢綉鍏� - * 2銆侀�氳繃Udp 鑾峰彇Tcp ip 绔彛缁熶竴8586 - */ -public class HDLSocket { - - /** - * tcp榛樿绔彛 - */ - private static final int TCP_PORT = 8586; - - private SocketBoot tcpBoot; - - private ConnectStatusListener statusListener; - - private HDLSocket() { - statusListener = new ConnectStatusListener() { - @Override - public void onConnecting() { - broadcastRequest(); - } - - @Override - public void onConnected() { - - } - - @Override - public void onConnectFailed() { - - } - }; - } - - /** - * 骞挎挱鑷韩淇℃伅缁欎富缃戝叧 - */ - private void broadcastRequest() { - new Thread(new Runnable() { - @Override - public void run() { - try { - LogUtils.i("骞挎挱璁惧鏈韩淇℃伅"); - - String time = String.valueOf(System.currentTimeMillis()); - if (null == HDLLinkConfig.getInstance().getDeviceInfoBean()) { - LogUtils.i("DeviceInfoBean涓虹┖锛岃璁剧疆褰撳墠瀵硅薄"); - return; - } - BroadcastRequest request = new BroadcastRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), "200"); - HDLAuthSocket.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true, new HDLLinkResponseCallBack() { - @Override - public void onSuccess(LinkResponse msg) { - LogUtils.i("骞挎挱淇℃伅缁欎富缃戝叧鎴愬姛锛�"); - } - - @Override - public void onError(HDLLinkException e) { - LogUtils.i("骞挎挱淇℃伅缁欎富缃戝叧澶辫触锛�"); - } - }); - HDLAuthSocket.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true); - HDLAuthSocket.getInstance().udpSendMsg(TopicConstant.BROADCAST, GsonConvert.getGson().toJson(request), true); - } catch (Exception e) { - LogUtils.e("骞挎挱璁惧鏈韩淇℃伅澶辫触锛屽け璐ヤ俊鎭細" + e.getMessage()); - } - } - }).start(); - } - - // private static class SingletonInstance { -// } - private static final HDLSocket instance = new HDLSocket(); - - public static HDLSocket getInstance() { - return instance; - } - - SocketOptions options; - - private SocketOptions getTcpOptions() { - if (null != options) { - return options; - } - options = new SocketOptions(); - final MessagePipeLine pipeLine = new MessagePipeLine(); - pipeLine.add(new LinkMessageDecoder()); - pipeLine.add(new LinkMessageEncoder()); - options.setHandleMessage(pipeLine); - options.addConnectStatusListener(statusListener); - return options; - } - - - public int getTcpPort() { - return TCP_PORT; - } - - public String getTcpIp() { - return HDLLinkConfig.getInstance().getIpAddress(); - } - - public String getGatewayId() { - return HDLLinkConfig.getInstance().getGatewayId(); - } - - /** - * 鑾峰彇璁惧鍒楄〃 - */ - public void getDeviceList(HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - String time = String.valueOf(System.currentTimeMillis()); - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("id", IdUtils.getUUId()); - jsonObject.addProperty("time_stamp", time); - - String topic = String.format(TopicConstant.GET_DEVICE_LIST, getGatewayId()); - - LinkRequest message = new LinkRequest(topic, - jsonObject.toString()); - - String replyTopic = String.format(TopicConstant.GET_DEVICE_LIST_REPLY, getGatewayId()); - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_DEVICE_LIST_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_DEVICE_LIST_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); - } - } - } - - - /** - * 鑾峰彇鍔熻兘鍒楄〃 - */ - public void getFunctionList(HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - String time = String.valueOf(System.currentTimeMillis()); - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("id", IdUtils.getUUId()); - jsonObject.addProperty("time_stamp", time); - - String topic = String.format(TopicConstant.GET_FUNCTION_LIST, getGatewayId()); - - LinkRequest message = new LinkRequest(topic, - jsonObject.toString()); - - String replyTopic = String.format(TopicConstant.GET_FUNCTION_LIST_REPLY, getGatewayId()); - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_LIST_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_LIST_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); - } - } - } - - - /** - * 鑾峰彇鍔熻兘灞炴�� - * - * @param sids - * @param callBack - */ - public void getFunctionAttribute(List<String> sids, HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - String time = String.valueOf(System.currentTimeMillis()); - - final BaseLocalResponse<List<FunctionAttributeRequest>> data = new BaseLocalResponse<>(); - data.setId(IdUtils.getUUId()); - - data.setTime_stamp(time); - List<FunctionAttributeRequest> list = new ArrayList<>(); - for (String s : sids) { - list.add(new FunctionAttributeRequest(s)); - } - data.setObjects(list); - - String topic = String.format(TopicConstant.GET_FUNCTION_ATTRIBUTE, getGatewayId()); - LinkRequest message = new LinkRequest(topic, - GsonConvert.getGson().toJson(data)); - - String replyTopic = String.format(TopicConstant.GET_FUNCTION_ATTRIBUTE_REPLY, getGatewayId()); - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_PROPERTIES_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_PROPERTIES_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); - } - } - } - - /** - * 璁惧鎺у埗 - */ - public void propertyDown(List<DeviceControlRequest> request, HDLLinkCallBack callBack) { - - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - String time = String.valueOf(System.currentTimeMillis()); - - final BaseLocalResponse<List<DeviceControlRequest>> data = new BaseLocalResponse<>(); - data.setId(IdUtils.getUUId()); - data.setTime_stamp(time); - data.setObjects(request); - - String topic = String.format(TopicConstant.PROPERTY_DOWN, getGatewayId()); - LinkRequest message = new LinkRequest(topic, - GsonConvert.getGson().toJson(data)); - - String replyTopic = String.format(TopicConstant.PROPERTY_DOWN_REPLY, getGatewayId()); - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - - } - -// /** -// * 鐘舵�佷笂鎶� -// */ -// public void propertyUp(List<PropertyUpRequest> request, CallBack callBack) { -// if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { -// String time = String.valueOf(System.currentTimeMillis()); -// -// final BaseLocalResponse<List<PropertyUpRequest>> data = new BaseLocalResponse<>(); -// data.setId(IdUtils.getUUId()); -// data.setTime_stamp(time); -// data.setObjects(request); -// -// -// String topic = String.format(TopicConstant.PROPERTY_UP, getGatewayId()); -// LinkRequest message = new LinkRequest(topic, -// GsonConvert.getGson().toJson(request)); -// -// String replyTopic = String.format(TopicConstant.PROPERTY_UP_REPLY, getGatewayId()); -// try { -// sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { -// @Override -// public void onSucceed() { -// -// } -// -// @Override -// public void onError() { -// if (callBack != null) { -// callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); -// } -// } -// }); -// } catch (Exception e) { -// if (callBack != null) { -// callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); -// } -// } -// } else { -// if (callBack != null) { -// callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); -// } -// } -// } - - /** - * 璇诲彇鐘舵�� - */ - public void propertyRead(List<String> sids, HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - 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, getGatewayId()); - LinkRequest message = new LinkRequest(topic, - GsonConvert.getGson().toJson(data)); - - String replyTopic = String.format(TopicConstant.PROPERTY_READ_REPLY, getGatewayId()); - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } - - public SocketBoot getTcp() throws RuntimeException { - if (TextUtils.isEmpty(getTcpIp())) { - LogUtils.e("璇锋悳绱㈢綉鍏�"); - throw new RuntimeException("璇锋悳绱㈢綉鍏�"); - } - //濡傛灉娌℃湁鍒濆鍖栵紝鎴栬�呯綉鍏矷P鏇存敼浜嗭紝灏遍噸鏂板垵濮嬪寲 - if (tcpBoot == null || !getTcpOptions().getIp().equals(getTcpIp())) { - tcpBoot = TcpClient.init(getTcpIp(), getTcpPort(), getTcpOptions()); - tcpBoot.SetHeartbeat(new IHeartbeat() { - @Override - public void heartbeat() { - - if (HDLLinkConfig.getInstance().getDeviceInfoBean() == null || HDLLinkConfig.getInstance().getDeviceInfoBean().getOID() == null) { - LogUtils.i("DeviceInfoBean涓虹┖锛岄渶瑕佽缃墠鑳芥甯稿績璺�"); - return; - } - - 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.HEARTBEAT, HDLLinkConfig.getInstance().getDeviceInfoBean().getOID()); - - LinkRequest message = new LinkRequest(topic, - jsonObject.toString()); - sendMsg(message.getSendBytes(), null, null, null); - } - }); - } - - return tcpBoot; - } - - /** - * 鑾峰彇鍦烘櫙鍒楄〃 - */ - public void getSceneList(HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - 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, getGatewayId()); - - LinkRequest message = new LinkRequest(topic, - jsonObject.toString()); - String replyTopic = topic + "_reply"; - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_LIST_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_FUNCTION_LIST_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); - } - } - } - - /** - * 鍦烘櫙鎺у埗 - * - * @param sids 鍦烘櫙sid鍒楄〃 - * @param callBack 鍥炶皟 - */ - public void controlScene(List<String> sids, HDLLinkCallBack callBack) { - if (!TextUtils.isEmpty(getGatewayId()) && !TextUtils.isEmpty(getTcpIp())) { - 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, getGatewayId()); - LinkRequest message = new LinkRequest(topic, - GsonConvert.getGson().toJson(data)); - - String replyTopic = topic + "_reply"; - try { - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } else { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } - -// /** -// * 娓呯┖缂撳瓨 -// */ -// public void clearCache() { -// SPUtils.remove(TCP_IP_KEY); -// SPUtils.remove(GATEWAY_KEY); -// } - - /** - * 閫氱敤TCP鍙戦�佹寚浠� - * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� - * @param callBack 鍥炶皟 - */ - public void tcpSendMsg(String topic, String bodyStr, HDLLinkCallBack callBack) { - try { - LinkRequest message = new LinkRequest(topic, bodyStr); - String replyTopic = topic + "_reply"; - sendMsg(message.getSendBytes(), replyTopic, callBack, new SendListener() { - @Override - public void onSucceed() { - - } - - @Override - public void onError() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - } catch (Exception e) { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - } - - /** - * 閫氱敤TCP鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� - * - * @param topic 鍙戦�佹暟鎹� - * @param bodyStr 鍥炲鐨勪富棰� - */ - public void tcpSendMsg(String topic, String bodyStr) { - try { - if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { - LogUtils.e("udpSendMsg", "鍙傛暟涓嶈兘涓虹┖"); - return; - } - LinkRequest message = new LinkRequest(topic, bodyStr); - getTcp().sendMsg(message.getSendBytes()); - } catch (Exception e) { - LogUtils.e("tcpSendMsg", "鍙戦�佸け璐� :" + e.getMessage()); - } - } - - /** - * 鍙戦�佹寚浠� - * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� - */ - public void sendMsg(byte[] data, String eventTag, HDLLinkCallBack callBack, SendListener sendListener) { - - try { - if (eventTag != null) { - final AtomicInteger sendCount = new AtomicInteger(0); - - final ScheduledExecutorService threadPool = ThreadToolUtils.getInstance().newScheduledThreadPool(1); - final EventListener eventListener = new EventListener() { - @Override - public void onMessage(Object msg) { - if (msg instanceof LinkResponse) { - LogUtils.i("sendMsg onSuccess" + StringEscapeUtils.unescapeJava(msg.toString())); -// LogUtils.i("sendMsg onSuccess" + msg); - threadPool.shutdownNow(); - LogUtils.i("sendMsg eventListener remove"); - EventDispatcher.getInstance().remove(eventTag, this); - if (callBack != null) { - callBack.onSuccess(StringEscapeUtils.unescapeJava(msg.toString())); -// callBack.onSuccess(msg.toString()); - } - } - } - }; - - threadPool.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - if (sendCount.get() < 3) { - sendCount.set(sendCount.get() + 1); - getTcp().sendMsg(data); - } else { - threadPool.shutdownNow(); - LogUtils.e("sendMsg eventListener remove"); - EventDispatcher.getInstance().remove(eventTag, eventListener); - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - LogUtils.i("HDLSocket sendMsg onError 鍙戦�佸け璐�"); - - } - } - }, 1000, 500, TimeUnit.MILLISECONDS); - EventDispatcher.getInstance().register(eventTag, eventListener); - } - //鍏堝彂閫佷竴娆� - getTcp().sendMsg(data, new SendListener() { - @Override - public void onSucceed() { - if (sendListener != null) { - sendListener.onSucceed(); - } - } - - @Override - public void onError() { - if (sendListener != null) { - sendListener.onError(); - } - } - }); - } catch (Exception e) { - e.printStackTrace(); - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - if (callBack != null) { - callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_SEND_ERROR)); - } - } - }); - LogUtils.i("HDLSocket sendMsg onError 鍙戦�佸け璐�"); - - } - - } - -} diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HdlSocketHelper.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HdlSocketHelper.java deleted file mode 100644 index 7314b78..0000000 --- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HdlSocketHelper.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.hdl.sdk.connect.socket; - -import com.hdl.sdk.common.event.EventDispatcher; -import com.hdl.sdk.common.event.EventListener; -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.TextUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.connect.bean.LinkRequest; -import com.hdl.sdk.socket.SocketBoot; -import com.hdl.sdk.socket.udp.UdpSocketBoot; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by Tong on 2021/11/11. - */ -public class HdlSocketHelper { - - private static final Long DEF_SEND_TIMEOUT = 1000L; - private static final int DEF_MAX_RETRY = 4; - private static final int DEF_SEND_ONE = 1; - - private final Long sendAwaitTime; - private final int maxRetry; - - private SocketBoot boot; - private UdpSocketBoot udpSocketBoot; - /** - * 鍙戦�佺殑鐩爣IP - */ - private String ipAddress; - /** - * 鍙戦�佺殑鐩爣鍦板潃 - */ - private int port; - private final LinkRequest linkRequest; - private final EventListener eventListener; - - private final AtomicInteger sendNumber; - - private final AtomicBoolean isSend = new AtomicBoolean(false); - - private HdlSocketListener listener; - - private ScheduledExecutorService sendThread; - - private String observeTopic; - - public interface HdlSocketListener { - void onSucceed(Object msg); - - void onFailure(); - } - - private HdlSocketHelper(Long sendAwaitTime, int maxRetry, UdpSocketBoot udpSocketBoot, - String ipAddress, int port, LinkRequest linkRequest, String observeTopic, HdlSocketListener listener) { - this.sendAwaitTime = sendAwaitTime; - this.maxRetry = maxRetry; - this.udpSocketBoot = udpSocketBoot; - this.ipAddress = ipAddress; - this.port = port; - this.linkRequest = linkRequest; - this.listener = listener; - this.observeTopic = observeTopic; - this.sendNumber = new AtomicInteger(0); - eventListener = new EventListener() { - @Override - public void onMessage(Object msg) { - isSend.set(true); - if (listener != null) { - listener.onSucceed(msg); - } - if (sendThread != null) { - sendThread.shutdownNow(); - } - //绉婚櫎鐩戝惉 - removeListener(); - } - }; - //娉ㄥ唽鐩戝惉 - registerListener(); - } - - - /** - * 娉ㄥ唽鐩戝惉 - */ - void registerListener() { - if (!TextUtils.isEmpty(observeTopic)) { - EventDispatcher.getInstance().register(observeTopic, eventListener); -// LogUtils.i("HdlSocketHelper", "register event"); - } - } - - /** - * 绉婚櫎鐩戝惉 - */ - void removeListener() { - if (!TextUtils.isEmpty(observeTopic)) { - EventDispatcher.getInstance().remove(observeTopic, eventListener); -// LogUtils.i("HdlSocketHelper", "remove event"); - } - } - - /** - * Udp鐨勫彂閫佹柟娉� - * - * @param udpSocketBoot Udp褰撳墠瀵规帴 - * @param ipAddress 鍙戦�佺殑鐩爣IP鍦板潃 - * @param port 鐩殑绔彛 - * @param linkRequest 鍙戦�佺殑鏁版嵁 - * @param observeTopic 鍙戦�佺殑涓婚 - * @param retry 閲嶅彂鏁版 - * @param listener 鍥炶皟 - */ - public static void sendUdp(UdpSocketBoot udpSocketBoot, String ipAddress, int port, LinkRequest linkRequest, String observeTopic, int retry, HdlSocketListener listener) { - if (TextUtils.isEmpty(observeTopic)) { - observeTopic = linkRequest.getTopic() + "_reply"; - } - HdlSocketHelper socketHelper = new HdlSocketHelper(DEF_SEND_TIMEOUT, retry, udpSocketBoot, ipAddress, port, linkRequest, observeTopic, listener); - socketHelper.send(); - } - - /** - * Udp鐨勫彂閫佹柟娉� - * - * @param udpSocketBoot Udp褰撳墠瀵规帴 - * @param ipAddress 鍙戦�佺殑鐩爣IP鍦板潃 - * @param port 鐩殑绔彛 - * @param linkRequest 鍙戦�佺殑鏁版嵁 - * @param listener 鍥炶皟 - */ - public static void sendUdp(UdpSocketBoot udpSocketBoot, String ipAddress, int port, LinkRequest linkRequest, HdlSocketListener listener) { - sendUdp(udpSocketBoot, ipAddress, port, linkRequest, "", DEF_MAX_RETRY, listener); - } - - - /** - * Udp鐨勫彂閫佹柟娉� - * - * @param udpSocketBoot Udp褰撳墠瀵规帴 - * @param ipAddress 鍙戦�佺殑鐩爣IP鍦板潃 - * @param port 鐩殑绔彛 - * @param linkRequest 鍙戦�佺殑鏁版嵁 - */ - public static void sendUdpOne(UdpSocketBoot udpSocketBoot, String ipAddress, int port, LinkRequest linkRequest) { - HdlSocketHelper socketHelper = new HdlSocketHelper(DEF_SEND_TIMEOUT, DEF_SEND_ONE, udpSocketBoot, ipAddress, port, linkRequest, null, null); - socketHelper.send(); - } - - private void send() { - getSendThread().scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - //鍙戦�佹鏁板皬浜庨噸鍙戞鏁� - if ((sendNumber.get() < maxRetry)) { - try { - //杩樻病鏈夋敹鍒板洖澶嶏紝鍐嶅彂閫� - if (!isSend.get()) { - sendNumber.set(sendNumber.get() + 1); - //濡傛槸tcp - if (boot != null) { - boot.sendMsg(linkRequest.getSendBytes()); - } - //濡傛灉鏄痷dp - if (null != udpSocketBoot) { - udpSocketBoot.sendMsg(ipAddress, port, linkRequest.getSendBytes()); - } - } - } catch (Exception e) { - LogUtils.e("鍙戦�佹暟鎹け璐�:" + e.getMessage()); - } - } else { - //瓒呭嚭閲嶅彂娆℃暟骞舵病鏈夋敹鍒板洖澶� - if (!isSend.get()) { - notifyFailure(); - } - } - } - }, 0, sendAwaitTime, TimeUnit.MILLISECONDS); - //initialdelay - 棣栨鎵ц鐨勫欢杩熸椂闂� 0 - //delay - 涓�娆℃墽琛岀粓姝㈠拰涓嬩竴娆℃墽琛屽紑濮嬩箣闂寸殑寤惰繜 - } - - /** - * 鑾峰彇鍙戦�佺嚎绋� - * - * @return 杩斿洖鑾峰彇鍒扮殑绾跨▼ - */ - private ScheduledExecutorService getSendThread() { - if (sendThread == null) { - sendThread = ThreadToolUtils.getInstance().newScheduledThreadPool(1); - } - return sendThread; - } - - - /** - * 鍙戦�佸け璐� - */ - private void notifyFailure() { - //绉婚櫎鐩戝惉 - removeListener(); - try { - if (sendThread != null) { - sendThread.shutdownNow(); - sendThread = null; - } - if (listener != null) { - listener.onFailure(); - listener = null; - } - } catch (Exception e) { - - } - } -} diff --git a/HDLSDK/hdl-socket/.gitignore b/HDLSDK/hdl-socket/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/HDLSDK/hdl-socket/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/HDLSDK/hdl-socket/README.md b/HDLSDK/hdl-socket/README.md deleted file mode 100644 index 40be08b..0000000 --- a/HDLSDK/hdl-socket/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# hdl-socket搴� - -##璇存槑 -tcp+udp 閫氱敤灏佽,瀹炵幇鍩烘湰杩炴帴 - -##鐢ㄦ硶 -1銆佸垱寤篢cp瀵硅薄 -2銆佸垱寤篣dp瀵硅薄 diff --git a/HDLSDK/hdl-socket/build.gradle b/HDLSDK/hdl-socket/build.gradle deleted file mode 100644 index 908bff6..0000000 --- a/HDLSDK/hdl-socket/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -plugins { -// id 'com.android.library' - id 'java-library' -} - -/*android { - compileSdkVersion rootProject.compileSdkVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - versionCode 2 - versionName "1.0.15" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - -}*/ -java { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 -} - -dependencies { - api project(path: ':hdl-common') -} \ No newline at end of file diff --git a/HDLSDK/hdl-socket/consumer-rules.pro b/HDLSDK/hdl-socket/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 --- a/HDLSDK/hdl-socket/consumer-rules.pro +++ /dev/null diff --git a/HDLSDK/hdl-socket/proguard-rules.pro b/HDLSDK/hdl-socket/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/HDLSDK/hdl-socket/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/HDLSDK/hdl-socket/src/main/AndroidManifest.xml b/HDLSDK/hdl-socket/src/main/AndroidManifest.xml deleted file mode 100644 index 92ea344..0000000 --- a/HDLSDK/hdl-socket/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.hdl.sdk.socket"> - -</manifest> \ No newline at end of file diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/.DS_Store b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/.DS_Store deleted file mode 100644 index 7062e40..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/.DS_Store +++ /dev/null Binary files differ diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/TcpClient.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/TcpClient.java deleted file mode 100644 index b4a7d3c..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/TcpClient.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.hdl.sdk.socket.client; - -import com.hdl.sdk.common.utils.LogUtils; -import com.hdl.sdk.common.utils.ThreadToolUtils; -import com.hdl.sdk.socket.SocketBoot; -import com.hdl.sdk.socket.SocketOptions; -import com.hdl.sdk.socket.annotation.ConnectStatus; -import com.hdl.sdk.socket.codec.IHandleMessage; -import com.hdl.sdk.socket.listener.ConnectStatusListener; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.StandardSocketOptions; -import java.util.ArrayList; -import java.util.List; - - -/** - * Created by Tong on 2021/9/15. - */ -public final class TcpClient implements IClient { - - - private SocketOptions socketOptions; - - private final String ip; - private final int port; - - private Socket mSocket; - - private final static List<TcpClient> tcpClientList = new ArrayList(); - - /** - * 浠庤繛鎺ユ睜涓壘鍑哄綋鍓岻P鍙婄鍙g殑杩炴帴瀹㈡埛绔� - * - * @param ipAdderss 杩炴帴IP鍦板潃 - * @param port 杩炴帴绔彛 - * @return - */ - public static TcpClient getTcpClientByIP(String ipAdderss, int port) { - for (TcpClient tcpClient : tcpClientList) { - if (tcpClient.ip.equals(ipAdderss) && tcpClient.port == port) { - return tcpClient; - } - } - return null; - } - - private byte[] readBuffer = new byte[4 * 1024]; - - private TcpClient(String ip, int port, SocketOptions socketOptions) { - this.socketOptions = socketOptions; - this.ip = ip; - this.port = port; - socketOptions.setIp(ip); - socketOptions.setPort(port); - } - - public static SocketBoot init(String ip, int port, SocketOptions options) { - return new SocketBoot(new TcpClient(ip, port, options)); - } - - - @Override - public void connect() throws Exception { - - mSocket = getSocket(); -// SocketOptions options = getOptions(); - mSocket.connect(new InetSocketAddress(ip, port), 3 * 1000); - mSocket.setTcpNoDelay(true); - mSocket.setReuseAddress(true); -// mSocket.setKeepAlive(true); - mSocket.setSoTimeout(25 * 1000); - - tcpClientList.add(this); - } - - - @Override - public void disconnect() { - if (mSocket != null) { - try { - mSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public synchronized SocketOptions getOptions() { - if (socketOptions == null) { - socketOptions = new SocketOptions(); - } - return socketOptions; - } - - @Override - public void onHandleResponse() throws Exception { - final InputStream stream = getInputStream(); - if (stream != null && getOptions() != null) { - while (true) { - int len = getInputStream().read(readBuffer); - if (len <= 0) { - throw new Exception("鎺ユ敹寮傚父锛屾帴鏀舵暟鎹暱搴en=" + len); - } - - IHandleMessage handleMessage = getOptions().getHandleMessage(); - if (handleMessage != null) { - byte[] bytes = new byte[len]; - System.arraycopy(readBuffer, 0, bytes, 0, len); - //瀹屾暣鐨勬暟鎹墠鍥炶皟 - handleMessage.read(bytes, ip); - } - } - } - } - - @Override - public void sendMsg(byte[] msg) throws Exception { - final OutputStream outputStream = getOutStream(); - if (outputStream != null && getOptions() != null) { - IHandleMessage handleMessage = getOptions().getHandleMessage(); - handleMessage.write(handleMessage.write(msg)); - outputStream.write(msg); - outputStream.flush(); - } - } - - - /** - * 澶勭悊杩炴帴鐘舵�� - */ - public void onConnectStatus(int status) { - - ThreadToolUtils.getInstance().runOnUiThread(new Runnable() { - @Override - public void run() { - final List<ConnectStatusListener> list = getOptions().getConnectStatusListener(); - if (list != null && !list.isEmpty()) { - for (ConnectStatusListener listener : list) { - switch (status) { - case 0: - listener.onConnecting(); - break; - case 1: - listener.onConnected(); - break; - case 2: - listener.onConnectFailed(); - break; - } - } - } - } - }); - - LogUtils.i("TcpClient onConnectStatus status:" + status); - - } - - - private synchronized Socket getSocket() { - return new Socket(); - } - - private InputStream getInputStream() { - if (mSocket != null && mSocket.isConnected() && !mSocket.isClosed()) { - try { - return mSocket.getInputStream(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return null; - } - - - private OutputStream getOutStream() { - if (mSocket != null && mSocket.isConnected() && !mSocket.isClosed()) { - try { - return mSocket.getOutputStream(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return null; - } - - -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/ByteToMessageDecoder.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/ByteToMessageDecoder.java deleted file mode 100644 index 2aba6c4..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/ByteToMessageDecoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.hdl.sdk.socket.codec; - -/** - * Created by Tong on 2021/9/22. - */ -public abstract class ByteToMessageDecoder<T> implements IHandleFlow<T> { - - protected abstract T decoder(Object msg,String ipaddress) - throws Exception; - - @Override - public final T read(Object data,String ipaddress) throws Exception { - return decoder(data,ipaddress); - } - - @Override - public final byte[] write(byte[] data) { - return data; - } -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleFlow.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleFlow.java deleted file mode 100644 index cccb161..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleFlow.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hdl.sdk.socket.codec; - -/** - * Created by Tong on 2021/9/23. - */ -public interface IHandleFlow<T> { - - T read(Object data,String ipaddress) throws Exception; - - byte[] write(byte[] data) throws Exception; - -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleMessage.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleMessage.java deleted file mode 100644 index caa6229..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/IHandleMessage.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.hdl.sdk.socket.codec; - -/** - * Created by Tong on 2021/9/27. - */ -public interface IHandleMessage { - void read(byte[] data,String ipaddress) throws Exception; - - byte[] write(byte[] data) throws Exception; -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessagePipeLine.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessagePipeLine.java deleted file mode 100644 index 1b785dd..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessagePipeLine.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.hdl.sdk.socket.codec; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Created by Tong on 2021/9/23. - */ -public class MessagePipeLine implements IMessagePipeLine, IHandleMessage { - - public final List<IHandleFlow> queue = new ArrayList<>(); - - @Override - public void add(IHandleFlow flow) { - queue.add(flow); - } - - @Override - public synchronized void clear() { - queue.clear(); - } - - @Override - public void read(byte[] data,String ipaddress) throws Exception { - Object out = data; - for (int i = 0; i < queue.size(); i++) { - IHandleFlow flow = queue.get(i); - Object read = flow.read(out,ipaddress); - try { - out = Objects.requireNonNull(read); - } catch (Exception ignored) { - } - } - } - - @Override - public byte[] write(byte[] data) throws Exception { - byte[] out = data; - for (int i = 0; i < queue.size(); i++) { - IHandleFlow flow = queue.get(i); - byte[] write = flow.write(out); - try { - out = Objects.requireNonNull(write); - } catch (Exception ignored) { - - } - } - return new byte[0]; - } -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessageToByteEncoder.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessageToByteEncoder.java deleted file mode 100644 index e70dc84..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/codec/MessageToByteEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.hdl.sdk.socket.codec; - - -/** - * Created by Tong on 2021/9/22. - */ -public abstract class MessageToByteEncoder implements IHandleFlow { - - - protected abstract byte[] encode(byte[] data) - throws Exception; - - @Override - public final Object read(Object data,String ipaddress) { - return data; - } - - @Override - public byte[] write(byte[] data) throws Exception { - return encode(data); - } - - -} diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketOptions.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketOptions.java deleted file mode 100644 index 42b89cc..0000000 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/udp/UdpSocketOptions.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hdl.sdk.socket.udp; - - -import com.hdl.sdk.socket.codec.IHandleMessage; -import com.hdl.sdk.socket.listener.ConnectStatusListener; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by hxb on 2021/12/12. - */ -public class UdpSocketOptions { - - //澶勭悊鏁版嵁 - private IHandleMessage handleMessage; - - public IHandleMessage getHandleMessage() { - return handleMessage; - } - - public void setHandleMessage(IHandleMessage handleMessage) { - this.handleMessage = handleMessage; - } -} diff --git a/HDLSDK/settings.gradle b/HDLSDK/settings.gradle index 45786a8..dab968b 100644 --- a/HDLSDK/settings.gradle +++ b/HDLSDK/settings.gradle @@ -1,7 +1,3 @@ include ':app' -include ':hdl-socket' -include ':hdl-connect' -include ':hdl-common' -include ':com.hdl.sdk' -include ':hdl-test' +include ':HDLLinkLocalSdk' -- Gitblit v1.8.0