From 14de918a79943e4961b09fa01ed320c6cad41f2e Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 28 六月 2023 17:14:51 +0800 Subject: [PATCH] Revert "Revert "Merge branch 'hxb' into wjc"" --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java | 50 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java | 93 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkIrDeviceBean.java | 81 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java | 11 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ErrorUtils.java | 30 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java | 49 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/AesUtil.java | 286 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyGetGateWayInfo.java | 11 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java | 22 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java | 18 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java | 21 HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml | 27 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java | 191 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java | 73 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java | 22 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java | 8 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java | 176 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java | 150 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java | 135 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 432 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java | 392 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java | 88 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java | 49 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java | 89 HDLLinkLocalSdk/.gitignore | 1 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/HexUtil.java | 449 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java | 27 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java | 102 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java | 150 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java | 67 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java | 11 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java | 134 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java | 42 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java | 103 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java | 74 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java | 45 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventIRCodeStudySuccessInfo.java | 36 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java | 34 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java | 37 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java | 26 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidNameBean.java | 33 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java | 412 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java | 13 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java | 20 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java | 10 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java | 312 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java | 36 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java | 54 app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 33 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java | 239 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java | 14 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java | 44 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java | 161 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java | 122 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java | 191 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java | 59 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java | 11 HDLLinkLocalSdk/consumer-rules.pro | 0 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java | 565 ++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java | 40 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java | 323 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java | 30 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java | 33 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/HouseIdSecretUtil.java | 30 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockArrayMap.java | 31 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java | 73 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventCloseSearchDeviceActivityInfo.java | 12 .idea/deploymentTargetDropDown.xml | 17 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java | 20 app/src/main/java/com/hdl/photovoltaic/HDLApp.java | 9 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java | 10 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java | 10 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java | 143 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java | 128 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java | 24 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalWithCodeResponse.java | 39 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java | 122 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java | 51 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LanguageUtils.java | 8 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java | 71 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneGroupInfo.java | 31 local.properties | 2 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java | 31 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java | 17 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java | 154 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyDebugModeInfo.java | 27 HDLLinkLocalSdk/build.gradle | 55 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java | 310 + app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 16 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java | 22 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java | 45 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java | 47 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java | 21 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java | 358 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java | 32 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyRefreshGatewayAesKeyInfo.java | 23 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java | 88 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java | 31 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java | 52 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOtaBean.java | 78 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java | 243 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java | 32 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java | 68 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java | 52 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java | 51 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java | 69 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java | 95 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java | 45 app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java | 1 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java | 45 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java | 31 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java | 13 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventMqttAesFailInfo.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java | 179 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java | 37 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneCanDeleteInfo.java | 33 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java | 211 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java | 349 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java | 46 HDLLinkLocalSdk/src/main/res/values/strings_code.xml | 27 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java | 40 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java | 174 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java | 799 ++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java | 159 .gitignore | 4 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java | 109 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java | 619 ++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java | 10 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java | 74 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java | 37 HDLLinkLocalSdk/src/main/AndroidManifest.xml | 5 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockList.java | 37 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java | 63 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/GatewayLocationBean.java | 31 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java | 50 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java | 36 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java | 38 HDLLinkLocalSdk/src/main/res/values/arrays-error.xml | 6 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java | 154 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java | 72 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java | 32 settings.gradle | 1 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java | 58 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventBindMiniRemoteSuccessInfo.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java | 47 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java | 51 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java | 54 HDLLinkLocalSdk/proguard-rules.pro | 21 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java | 12 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java | 281 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java | 2407 ++++++++ HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java | 64 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java | 30 156 files changed, 16,093 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b186b24..77bc4c1 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,6 @@ *.log .idea/libraries/Gradle__com_bulong_rudeness_rudeness_0_1_4_aar.xml .DS_Store -app/.DS_Store \ No newline at end of file +app/.DS_Store + +local.properties \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..39f0014 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="deploymentTargetDropDown"> + <runningDeviceTargetSelectedWithDropDown> + <Target> + <type value="RUNNING_DEVICE_TARGET" /> + <deviceKey> + <Key> + <type value="SERIAL_NUMBER" /> + <value value="M7BBB18B19152766" /> + </Key> + </deviceKey> + </Target> + </runningDeviceTargetSelectedWithDropDown> + <timeTargetWasSelectedWithDropDown value="2023-06-28T02:02:14.854309Z" /> + </component> +</project> \ No newline at end of file diff --git a/HDLLinkLocalSdk/.gitignore b/HDLLinkLocalSdk/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/HDLLinkLocalSdk/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/HDLLinkLocalSdk/build.gradle b/HDLLinkLocalSdk/build.gradle new file mode 100644 index 0000000..3fbd9cc --- /dev/null +++ b/HDLLinkLocalSdk/build.gradle @@ -0,0 +1,55 @@ +plugins { + id 'com.android.library' +} + +android { + compileSdkVersion 29 + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 29 + versionCode 102 + versionName "1.0.2" + + 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 + } + + /** + * 鎵撳寘鑷姩鍛藉悕 + */ + android.libraryVariants.all { variant -> + variant.outputs.all { + outputFileName = "hdl-link-V" + defaultConfig.versionName + ".aar" + } + } +} + +dependencies { + implementation 'com.google.code.gson:gson:2.8.8' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'com.alibaba:fastjson:1.2.66' + api 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0' + api 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' + implementation 'org.bouncycastle:bcpg-jdk16:1.46' + //浜嬩欢鎬荤嚎 Eventbus + api 'org.greenrobot:eventbus:3.2.0' + //HDLLinkPMSdk SDK +// api project(path: ':HDLLinkPMSdk') + +// //鍔犲瘑 +// implementation 'cn.hutool:hutool-all:5.6.5' +// implementation 'org.bouncycastle:bcprov-jdk15on:1.60' +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/consumer-rules.pro b/HDLLinkLocalSdk/consumer-rules.pro new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/HDLLinkLocalSdk/consumer-rules.pro diff --git a/HDLLinkLocalSdk/proguard-rules.pro b/HDLLinkLocalSdk/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/HDLLinkLocalSdk/proguard-rules.pro @@ -0,0 +1,21 @@ +# 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/HDLLinkLocalSdk/src/main/AndroidManifest.xml b/HDLLinkLocalSdk/src/main/AndroidManifest.xml new file mode 100644 index 0000000..71bb242 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.hdl.sdk.link"> + +</manifest> \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java new file mode 100644 index 0000000..f8d8c8c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java @@ -0,0 +1,2407 @@ +package com.hdl.sdk.link; + +import android.content.Context; +import android.text.TextUtils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.bean.GatewayLocationBean; +import com.hdl.sdk.link.bean.LinkIrDeviceBean; +import com.hdl.sdk.link.bean.LinkOtaBean; +import com.hdl.sdk.link.bean.LinkSidNameBean; +import com.hdl.sdk.link.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.ErrorUtils; +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.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.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.bean.scenebatch.SceneCanDeleteInfo; +import com.hdl.sdk.link.core.bean.scenebatch.SceneGroupInfo; +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.gateway.HDLLinkLocalGateway; + +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : HDLLink + */ +public class HDLLinkLocalSdk { + /** + * 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; + } + + private Context context; + + + public void init(Context context) { + this.context = context.getApplicationContext(); + + String[] gatewayErrors = context.getResources().getStringArray(R.array.gateway); + Map<String, String> codeAndMsgMap = new HashMap<>(); + for (String gatewayError : gatewayErrors) { + String codeMsg[] = gatewayError.split("="); + codeAndMsgMap.put(codeMsg[0], codeMsg[1]); + } + //鍒濆鍖栫姸鎬佺爜澶氳瑷�淇℃伅 + ErrorUtils.errorsMap.putAll(codeAndMsgMap); + } + + public Context getContext() { + return context; + } + + public boolean isZh() { + Locale locale = getContext().getResources().getConfiguration().locale; + String language = locale.getLanguage(); + if (language.endsWith("zh")) + return true; + else + return false; + } + + /** + * 璁剧疆鎵撳嵃鏄惁寮�鍚� + * + * @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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, 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(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹�/閬ユ帶鍣ㄥ畾浣� + */ + public void locationIr(String sid, HDLLinkTCallBack<String> 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.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("sid", sid); + jsonObject1.put("duration_time", "5"); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.IR_FIND_REMOTE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("locationIr onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濆垹闄わ紙閲囩敤link鍗忚閫氱煡鍒犻櫎骞堕��缃戝瓙璁惧鎷撴墤鍏崇郴锛� + */ + public void deleteLinkDevice(String oid, HDLLinkTCallBack<String> 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.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("oid", oid); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.DELETING_GATEWAY_SLAVE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteLinkDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 閬ユ帶鍣ㄥ垹闄わ紙閲囩敤link鍗忚閫氱煡鍒犻櫎骞堕��缃戝瓙璁惧鎷撴墤鍏崇郴锛� + */ + public void deleteIrControlDevice(String sid, HDLLinkTCallBack<String> 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.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("sid", sid); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.DELETING_GATEWAY_SLAVE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteIrControlDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁惧鎺у埗 + */ + public void controlDevice(Object object, HDLLinkTCallBack<String> 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.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<Object> stringList = new ArrayList<>(); + stringList.add(object); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("controlDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏇存敼涓荤綉鍏冲娉ㄥ悕 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("changeGWName onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏇存敼浠庣綉鍏冲娉ㄥ悕 + */ + public void changeCongGWName(String gateWayName, String gatewayId, String ipAddress, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + 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()); + request.setCloudTopic(String.format(TopicConstant.NATIVE_LINK_DOWN_SLAVE, HDLLinkConfig.getInstance().getGatewayId(), gatewayId)); + new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("changeCongGWName onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid鏇存敼鍚嶅瓧 + */ + public void sidNameChange(List<LinkSidNameBean> 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<LinkSidNameBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.EDIT_FUNCTION, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidNameChange onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidBindUid onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidDeleteUid onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒涘缓鍦烘櫙 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 鎵归噺澶勭悊缁� + */ + public void editSceneBatchGroup(List<SceneGroupInfo> 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<SceneGroupInfo>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSceneBatchGroup onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 鎵归噺澶勭悊鍒犻櫎 + */ + public void editSceneBatchDelete(List<SceneCanDeleteInfo> 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<SceneCanDeleteInfo>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSceneBatchDelete onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鍦烘櫙 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栧垪琛� + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getLogicList 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getLogicDetail 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(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓鑷姩鍖� + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("enableLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鑷姩鍖� + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊瘯鐮� + */ + public void irCodeTest(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_TEST, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeTest onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濇坊鍔犻仴鎺у櫒 + */ + public void irDeviceAdd(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_DEVICE_ADD, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊嚜瀛︾爜 + */ + public void irCodeStudy(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_STUDY, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeStudy onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊嚜瀛︾爜鍒犻櫎 + */ + public void irCodeRemove(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_REMOVE, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeRemove onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 绾㈠瀹濋仴鎺у櫒鍒楄〃鑾峰彇 + */ + public void irDeviceList(JSONObject content, HDLLinkTCallBack<List<LinkIrDeviceBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_DEVICE_LIST, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irDeviceList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkIrDeviceBean>>>() { + }.getType(); + List<LinkIrDeviceBean> response = LinkResponseUtils.convertLinkResponse(msg, type); + if (response == null) { + callBack.onSuccess(new ArrayList<>()); + } else { + callBack.onSuccess(response); + } + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鑾峰彇瀹夐槻鍒楄〃 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSecurityList 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSecurityDetail 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓瀹夐槻 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎瀹夐槻 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("enableSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鑾峰彇鍔熻兘鍒楄〃 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionList 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 妯℃嫙浜戠ota + */ + public void otaDeviceUpgradeDown(String oid, String module, HDLLinkTCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkOtaBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + List<LinkOtaBean> bean = new ArrayList<>(); + LinkOtaBean linkOtaBean = new LinkOtaBean(); + linkOtaBean.setOid(oid); + linkOtaBean.setModule(module); + linkOtaBean.setSize(291710); + linkOtaBean.setSign_method("md5"); + linkOtaBean.setSign("05afc42e715b724e01b4ecd0ee2bde5d"); + linkOtaBean.setUrl("https://hdl-hz-prod.oss-cn-hangzhou.aliyuncs.com/20/2023/05/37886160-375a-4bf0-8a32-4093dac38679.ota"); + linkOtaBean.setVersion("V02.04.16"); + bean.add(linkOtaBean); + data.setObjects(bean); + String topic = String.format(TopicConstant.OTA_UPGRADE_DOWN, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionList onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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_ATTRIBUTE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSidName onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("propertyDown onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("propertyRead onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙鍒楄〃 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkSceneBean>>>() { + }.getType(); + List<LinkSceneBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙璇︽儏 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneDetail onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("controlScene onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, 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(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, 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(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("coverAddRoomList onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鎴块棿缁戝畾鍏崇郴 + */ + public void 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()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, 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(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璇诲彇缃戝叧缁忕含搴� + */ + public void getGatewayLocation(String gatewayId, HDLLinkTCallBack<GatewayLocationBean> callBack) { + if (null == callBack) { + return; + } + 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.GATEWAY_LOCATION_GET, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getGatewayLocation onSuccess"); + Type type = new TypeToken<BaseLocalResponse<GatewayLocationBean>>() { + }.getType(); + GatewayLocationBean list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁剧疆缃戝叧缁忕含搴� + */ + public void gatewayLocation(GatewayBean bean, String longitude, String lat, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = bean.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); + JsonObject jsonObject1 = new JsonObject(); + jsonObject1.addProperty("longitude", longitude); + jsonObject1.addProperty("latitude", lat); + jsonObject.add("objects", jsonObject1); + String topic = String.format(TopicConstant.GATEWAY_LOCATION_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomBindList onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒氬垰缁戝畾缃戝叧鐨勬椂鍊欒缃綉鍏崇粡绾害 涓嶉渶瑕佸姞瀵� + */ + public void gatewayLocation(String mGatewayId, String longitude, String lat, boolean isEncrypt,HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = mGatewayId; + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + JsonObject jsonObject1 = new JsonObject(); + jsonObject1.addProperty("longitude", longitude); + jsonObject1.addProperty("latitude", lat); + jsonObject.add("objects", jsonObject1); + String topic = String.format(TopicConstant.GATEWAY_LOCATION_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), isEncrypt); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("gatewayLocation onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, 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()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, 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()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + linkRequest.setCloudTopic(String.format(TopicConstant.NATIVE_LINK_DOWN, HDLLinkConfig.getInstance().getGatewayId())); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, 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()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + new HDLConnectHelper(ipAddress, linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, true).send(); + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/GatewayLocationBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/GatewayLocationBean.java new file mode 100644 index 0000000..3e0d993 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/GatewayLocationBean.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2023/5/18 + * description: + */ +public class GatewayLocationBean implements Serializable { + private String longitude; + private String latitude; + + public String getLongitude() { + return longitude == null ? "" : longitude; + } + + public void setLongitude(@NonNull String longitude) { + this.longitude = longitude; + } + + public String getLatitude() { + return latitude == null ? "" : latitude; + } + + public void setLatitude(@NonNull String latitude) { + this.latitude = latitude; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java new file mode 100644 index 0000000..f233869 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkAttributesBean.java @@ -0,0 +1,68 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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(@NonNull 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; + } + + @NonNull + public String getKey() { + return key == null ? "" : key; + } + + public void setKey(@NonNull String key) { + this.key = key; + } + + @NonNull + public String getData_type() { + return data_type == null ? "" : data_type; + } + + public void setData_type(@NonNull String data_type) { + this.data_type = data_type; + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicBean.java new file mode 100644 index 0000000..204248f --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull NoticeConfigInfo noticeConfig) { + this.noticeConfig = noticeConfig; + } + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId(@NonNull String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus(@NonNull String status) { + this.status = status; + } + + public String getType() { + return type == null ? "" : type; + } + + public void setType(@NonNull String type) { + this.type = type; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getRelation() { + return relation == null ? "" : relation; + } + + public void setRelation(@NonNull String relation) { + this.relation = relation; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable(@NonNull String enable) { + this.enable = enable; + } + + public LinkCreateLogicCycleBean getCycle() { + return cycle; + } + + public void setCycle(@NonNull LinkCreateLogicCycleBean cycle) { + this.cycle = cycle; + } + + public List<LinkCreateLogicInputBean> getInput() { + if (input == null) { + return new ArrayList<>(); + } + return input; + } + + public void setInput(@NonNull List<LinkCreateLogicInputBean> input) { + this.input = input; + } + + public List<LinkCreateLogicOutputBean> getOutput() { + if (output == null) { + return new ArrayList<>(); + } + return output; + } + + public void setOutput(@NonNull List<LinkCreateLogicOutputBean> output) { + this.output = output; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicCycleBean.java new file mode 100644 index 0000000..869f035 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String type) { + this.type = type; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(@NonNull String desc) { + this.desc = desc; + } + + public List<String> getValue() { + if (value == null) { + return new ArrayList<>(); + } + return value; + } + + public void setValue(@NonNull List<String> value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputBean.java new file mode 100644 index 0000000..17b4870 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String bypass) { + this.bypass = bypass; + } + + public String getStatusDesc() { + return statusDesc == null ? "" : statusDesc; + } + + public void setStatusDesc(@NonNull String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose(@NonNull String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay(@NonNull String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull 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(@NonNull LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs(@NonNull LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getCondition_type() { + return condition_type == null ? "" : condition_type; + } + + public void setCondition_type(@NonNull String condition_type) { + this.condition_type = condition_type; + } + + public List<LinkCreateLogicInputConditionBean> getCondition() { + if (condition == null) { + return new ArrayList<>(); + } + return condition; + } + + public void setCondition(@NonNull List<LinkCreateLogicInputConditionBean> condition) { + this.condition = condition; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicInputConditionBean.java new file mode 100644 index 0000000..800a6f2 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String key) { + this.key = key; + } + + public String getComparator() { + return comparator == null ? "" : comparator; + } + + public void setComparator(@NonNull String comparator) { + this.comparator = comparator; + } + + public String getData_type() { + return data_type == null ? "" : data_type; + } + + public void setData_type(@NonNull String data_type) { + this.data_type = data_type; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue(@NonNull String value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputBean.java new file mode 100644 index 0000000..9b43655 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose(@NonNull String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull 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(@NonNull LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs(@NonNull LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public List<LinkCreateSceneBean> getDetailInfo() { + if (detailInfo == null) { + return new ArrayList<>(); + } + return detailInfo; + } + + public void setDetailInfo(@NonNull List<LinkCreateSceneBean> detailInfo) { + this.detailInfo = detailInfo; + } + + public String getTarget_type() { + return target_type == null ? "" : target_type; + } + + public void setTarget_type(@NonNull String target_type) { + this.target_type = target_type; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay(@NonNull String delay) { + this.delay = delay; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public List<LinkCreateLogicOutputStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkCreateLogicOutputStatusBean> status) { + this.status = status; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateLogicOutputStatusBean.java new file mode 100644 index 0000000..eff3608 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String attrName) { + this.attrName = attrName; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(@NonNull String desc) { + this.desc = desc; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey(@NonNull String key) { + this.key = key; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue(@NonNull String value) { + this.value = value; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java new file mode 100644 index 0000000..7b3bb69 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneBean.java @@ -0,0 +1,122 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2022/1/23 + * description: + */ +public class LinkCreateSceneBean implements Serializable { + private String delay; + private String name; + private String sid; + private String group; + 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(@NonNull String gatewayId) { + this.gatewayId = gatewayId; + } + + public String getImage() { + return image == null ? "" : image; + } + + public void setImage(@NonNull String image) { + this.image = image; + } + + public String getGroup() { + return group == null ? "" : group; + } + + public void setGroup(@NonNull String group) { + this.group = group; + } + + public List<LinkCreateSceneImageToCloudBean> getImageBeans() { + if (imageBeans == null) { + return imageBeans = new ArrayList<>(); + } + return imageBeans; + } + + public void setImageBeans(@NonNull List<LinkCreateSceneImageToCloudBean> imageBeans) { + this.imageBeans = imageBeans; + } + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId(@NonNull String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getCan_delete() { + return can_delete == null ? "" : can_delete; + } + + public void setCan_delete(@NonNull String can_delete) { + this.can_delete = can_delete; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay(@NonNull String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public List<String> getUids() { + if (uids == null) { + return new ArrayList<>(); + } + return uids; + } + + public void setUids(@NonNull List<String> uids) { + this.uids = uids; + } + + public List<LinkCreateSceneFunctionBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions(@NonNull List<LinkCreateSceneFunctionBean> functions) { + this.functions = functions; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java new file mode 100644 index 0000000..1d588dc --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionBean.java @@ -0,0 +1,159 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 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 String type; + 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 String getType() { + return type == null ? "" : type; + } + + public void setType(@NonNull String type) { + this.type = type; + } + + public void setSceneImage(@NonNull LinkCreateSceneImageBean sceneImage) { + this.sceneImage = sceneImage; + } + + public String getStatusDesc() { + return statusDesc == null ? "" : statusDesc; + } + + public void setStatusDesc(@NonNull String statusDesc) { + this.statusDesc = statusDesc; + } + + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + public String getChoose() { + return choose == null ? "" : choose; + } + + public void setChoose(@NonNull String choose) { + this.choose = choose; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay(@NonNull String delay) { + this.delay = delay; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull String online) { + this.online = online; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } + + public LinkCreateSceneFunctionControlAttrsBean getControlAttrs() { + return controlAttrs; + } + + public void setControlAttrs(@NonNull LinkCreateSceneFunctionControlAttrsBean controlAttrs) { + this.controlAttrs = controlAttrs; + } + + public List<LinkCreateSceneFunctionattributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkCreateSceneFunctionattributesBean> attributes) { + this.attributes = attributes; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java new file mode 100644 index 0000000..b57338c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionControlAttrsBean.java @@ -0,0 +1,45 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 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(@NonNull String delay1) { + this.delay1 = delay1; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public List<LinkCreateSceneFunctionStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkCreateSceneFunctionStatusBean> status) { + this.status = status; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java new file mode 100644 index 0000000..0e10c49 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionStatusBean.java @@ -0,0 +1,58 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String comparator) { + this.comparator = comparator; + } + + public String getValue() { + return value == null ? "" : value; + } + + public void setValue(@NonNull String value) { + this.value = value; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey(@NonNull String key) { + this.key = key; + } + + public String getAttrName() { + return attrName == null ? "" : attrName; + } + + public void setAttrName(@NonNull String attrName) { + this.attrName = attrName; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(@NonNull String desc) { + this.desc = desc; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java new file mode 100644 index 0000000..f4f46c1 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesBean.java @@ -0,0 +1,102 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 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(@NonNull String data_type) { + this.data_type = data_type; + } + + public String getAccessMode() { + return accessMode == null ? "" : accessMode; + } + + public void setAccessMode(@NonNull String accessMode) { + this.accessMode = accessMode; + } + + public String getKey() { + return key == null ? "" : key; + } + + public void setKey(@NonNull String key) { + this.key = key; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(@NonNull String desc) { + this.desc = desc; + } + + public String getMaxValue() { + return maxValue == null ? "" : maxValue; + } + + public void setMaxValue(@NonNull String maxValue) { + this.maxValue = maxValue; + } + + public String getMinValue() { + return minValue == null ? "" : minValue; + } + + public void setMinValue(@NonNull String minValue) { + this.minValue = minValue; + } + + public String getUnit() { + return unit == null ? "" : unit; + } + + public void setUnit(@NonNull String unit) { + this.unit = unit; + } + + public List<String> getValue() { + if (value == null) { + return new ArrayList<>(); + } + return value; + } + + public void setValue(@NonNull List<String> value) { + this.value = value; + } + + public List<LinkCreateSceneFunctionattributesEnumerationsBean> getEnumerations() { + if (enumerations == null) { + return new ArrayList<>(); + } + return enumerations; + } + + public void setEnumerations(@NonNull List<LinkCreateSceneFunctionattributesEnumerationsBean> enumerations) { + this.enumerations = enumerations; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java new file mode 100644 index 0000000..f73d61c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneFunctionattributesEnumerationsBean.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String value) { + this.value = value; + } + + public String getDesc() { + return desc == null ? "" : desc; + } + + public void setDesc(@NonNull String desc) { + this.desc = desc; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java new file mode 100644 index 0000000..8df6d7b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageBean.java @@ -0,0 +1,49 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String id) { + this.id = id; + } + + public String getUrl() { + return url == null ? "" : url; + } + + public void setUrl(@NonNull String url) { + this.url = url; + } + + public String getLocal() { + return local == null ? "" : local; + } + + public void setLocal(@NonNull String local) { + this.local = local; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java new file mode 100644 index 0000000..09e64db --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkCreateSceneImageToCloudBean.java @@ -0,0 +1,40 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String imageId) { + this.imageId = imageId; + } + + public String getCloudUrl() { + return cloudUrl == null ? "" : cloudUrl; + } + + public void setCloudUrl(@NonNull String cloudUrl) { + this.cloudUrl = cloudUrl; + } + + public String getLocalUrl() { + return localUrl == null ? "" : localUrl; + } + + public void setLocalUrl(@NonNull String localUrl) { + this.localUrl = localUrl; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableLogicBean.java new file mode 100644 index 0000000..cfb835e --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String sid) { + this.sid = sid; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable(@NonNull String enable) { + this.enable = enable; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkEnableSecurityBean.java new file mode 100644 index 0000000..3558569 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String sid) { + this.sid = sid; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus(@NonNull String status) { + this.status = status; + } + + public String getAlarm() { + return alarm == null ? "" : alarm; + } + + public void setAlarm(@NonNull String alarm) { + this.alarm = alarm; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java new file mode 100644 index 0000000..e7a86c8 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionBean.java @@ -0,0 +1,135 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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(@NonNull String show) { + this.show = show; + } + + + public boolean isTemplateFlag() { + return templateFlag; + } + + public void setTemplateFlag(boolean templateFlag) { + this.templateFlag = templateFlag; + } + + + @NonNull + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + @NonNull + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + @NonNull + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + @NonNull + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + @NonNull + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + @NonNull + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + @NonNull + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull String online) { + this.online = online; + } + + @NonNull + public List<LinkStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkStatusBean> status) { + this.status = status; + } + + @NonNull + public List<LinkAttributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkAttributesBean> attributes) { + this.attributes = attributes; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkFunctionWithRoomBean.java new file mode 100644 index 0000000..dfb6b22 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull boolean hasRoom) { + this.hasRoom = hasRoom; + } + + public String getRoomName() { + return roomName == null ? "" : roomName; + } + + public void setRoomName(@NonNull String roomName) { + this.roomName = roomName; + } + + public String getShow() { + return show == null ? "1" : show; + } + + public void setShow(@NonNull String show) { + this.show = show; + } + + + public boolean isTemplateFlag() { + return templateFlag; + } + + public void setTemplateFlag(boolean templateFlag) { + this.templateFlag = templateFlag; + } + + + @NonNull + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + @NonNull + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + @NonNull + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + @NonNull + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + @NonNull + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + @NonNull + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + @NonNull + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull String online) { + this.online = online; + } + + @NonNull + public List<LinkStatusBean> getStatus() { + if (status == null) { + return new ArrayList<>(); + } + return status; + } + + public void setStatus(@NonNull List<LinkStatusBean> status) { + this.status = status; + } + + @NonNull + public List<LinkAttributesBean> getAttributes() { + if (attributes == null) { + return new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkAttributesBean> attributes) { + this.attributes = attributes; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkIrDeviceBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkIrDeviceBean.java new file mode 100644 index 0000000..df0dd4e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkIrDeviceBean.java @@ -0,0 +1,81 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2023/3/13 + * description: + */ +public class LinkIrDeviceBean implements Serializable { + private String sid; + private String name; + private String spk; + private String oid; + private String omodel; + private String online; + private List<LinkAttributesBean> attributes = new ArrayList<>(); + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getSpk() { + return spk == null ? "" : spk; + } + + public void setSpk(@NonNull String spk) { + this.spk = spk; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + public String getOmodel() { + return omodel == null ? "" : omodel; + } + + public void setOmodel(@NonNull String omodel) { + this.omodel = omodel; + } + + public String getOnline() { + return online == null ? "" : online; + } + + public void setOnline(@NonNull String online) { + this.online = online; + } + + public List<LinkAttributesBean> getAttributes() { + if (attributes == null) { + return attributes = new ArrayList<>(); + } + return attributes; + } + + public void setAttributes(@NonNull List<LinkAttributesBean> attributes) { + this.attributes = attributes; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkLogicBean.java new file mode 100644 index 0000000..d0e6f69 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String gateWayId) { + this.gatewayId = gateWayId; + } + + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus(@NonNull String status) { + this.status = status; + } + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + public String getEnable() { + return enable == null ? "" : enable; + } + + public void setEnable(@NonNull String enable) { + this.enable = enable; + } + + public LinkCreateLogicBean getDetailInfo() { + return detailInfo; + } + + public void setDetailInfo(@NonNull LinkCreateLogicBean detailInfo) { + this.detailInfo = detailInfo; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java new file mode 100644 index 0000000..ecea4da --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOidBean.java @@ -0,0 +1,174 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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; +// } + @NonNull + public String getParentOid() { + return parentOid == null ? "" : parentOid; + } + + public void setParentOid(String parentOid) { + this.parentOid = parentOid; + } + + @NonNull + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + @NonNull + public String getDevice_name() { + return device_name == null ? "" : device_name; + } + + public void setDevice_name(@NonNull String device_name) { + this.device_name = device_name; + } + + @NonNull + public String getDevice_mac() { + return device_mac == null ? "" : device_mac; + } + + public void setDevice_mac(@NonNull String device_mac) { + this.device_mac = device_mac; + } + + @NonNull + public String getDevice_model() { + return device_model == null ? "" : device_model; + } + + public void setDevice_model(@NonNull String device_model) { + this.device_model = device_model; + } + + @NonNull + public String getAddresses() { + return addresses == null ? "" : addresses; + } + + public void setAddresses(@NonNull String addresses) { + this.addresses = addresses; + } + + @NonNull + public String getDriver_code() { + return driver_code == null ? "" : driver_code; + } + + public void setDriver_code(@NonNull String driver_code) { + this.driver_code = driver_code; + } + + @NonNull + public String getHw_version() { + return hw_version == null ? "" : hw_version; + } + + public void setHw_version(@NonNull String hw_version) { + this.hw_version = hw_version; + } + + @NonNull + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version(@NonNull String fw_version) { + this.fw_version = fw_version; + } + + @NonNull + public String getSrc() { + return src == null ? "" : src; + } + + public void setSrc(@NonNull String src) { + this.src = src; + } + + @NonNull + public String getFrom() { + return from == null ? "" : from; + } + + public void setFrom(@NonNull String from) { + this.from = from; + } + + @NonNull + public List<ImageInfoBean> getImage_info() { + if (image_info == null) { + return new ArrayList<>(); + } + return image_info; + } + + public void setImage_info(@NonNull List<ImageInfoBean> image_info) { + this.image_info = image_info; + } + + /** + * 鍥轰欢鍜岀‖浠剁増鏈� + */ + public static class ImageInfoBean implements Serializable { + private String imageId; + private String fw_version; + + @NonNull + public String getImageId() { + return imageId == null ? "" : imageId; + } + + public void setImageId(@NonNull String imageId) { + this.imageId = imageId; + } + + @NonNull + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version(@NonNull String fw_version) { + this.fw_version = fw_version; + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOtaBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOtaBean.java new file mode 100644 index 0000000..4e72b64 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkOtaBean.java @@ -0,0 +1,78 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by jlchen on 1/13/22. + * + */ +public class LinkOtaBean implements Serializable { + + private String oid; + private String module; + private long size; + private String version; + private String url; + private String sign_method; + private String sign; + + public String getSign_method() { + return sign_method == null ? "" : sign_method; + } + + public void setSign_method(@NonNull String sign_method) { + this.sign_method = sign_method; + } + + public String getSign() { + return sign == null ? "" : sign; + } + + public void setSign(@NonNull String sign) { + this.sign = sign; + } + + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + public String getModule() { + return module == null ? "" : module; + } + + public void setModule(@NonNull String module) { + this.module = module; + } + + public long getSize() { + return size; + } + + public void setSize(@NonNull long size) { + this.size = size; + } + + public String getVersion() { + return version == null ? "" : version; + } + + public void setVersion(@NonNull String version) { + this.version = version; + } + + public String getUrl() { + return url == null ? "" : url; + } + + public void setUrl(@NonNull String url) { + this.url = url; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java new file mode 100644 index 0000000..3e50f5c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkReNameGWBean.java @@ -0,0 +1,17 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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(@NonNull String device_name) { + this.device_name = device_name; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkResponseBean.java new file mode 100644 index 0000000..ef27efd --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String id) { + this.id = id; + } + + public String getCode() { + return code == null ? "" : code; + } + + public void setCode(@NonNull String code) { + this.code = code; + } + + public String getTime_stamp() { + return time_stamp == null ? "" : time_stamp; + } + + public void setTime_stamp(@NonNull String time_stamp) { + this.time_stamp = time_stamp; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java new file mode 100644 index 0000000..cec4779 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBean.java @@ -0,0 +1,71 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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() { + + } + + @NonNull + public String getUid() { + return uid == null ? "" : uid; + } + + public void setUid(@NonNull String uid) { + this.uid = uid; + } + + @NonNull + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + @NonNull + public String getRoomType() { + return roomType == null ? "" : roomType; + } + + public void setRoomType(@NonNull String roomType) { + this.roomType = roomType; + } + + @NonNull + public String getRoomImage() { + return roomImage == null ? "" : roomImage; + } + + public void setRoomImage(@NonNull String roomImage) { + this.roomImage = roomImage; + } + + @NonNull + public String getParentId() { + return parentId == null ? "" : parentId; + } + + public void setParentId(@NonNull String parentId) { + this.parentId = parentId; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java new file mode 100644 index 0000000..1d0dd28 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkRoomBindBean.java @@ -0,0 +1,51 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; + +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<>();//鍦烘櫙鍒楄〃鍒楄〃 + + @NonNull + public String getUid() { + return uid == null ? "" : uid; + } + + public void setUid(@NonNull String uid) { + this.uid = uid; + } + + @NonNull + public List<LinkSidStrBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions(@NonNull List<LinkSidStrBean> functions) { + this.functions = functions; + } + + @NonNull + public List<LinkSidStrBean> getScenes() { + if (scenes == null) { + return new ArrayList<>(); + } + return scenes; + } + + public void setScenes(@NonNull List<LinkSidStrBean> scenes) { + this.scenes = scenes; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java new file mode 100644 index 0000000..623f2f0 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSceneBean.java @@ -0,0 +1,103 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * 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();//璇︽儏 + /** + * 涓撻棬缁欏満鏅壒閲忔搷浣滃仛澶勭悊 + */ + private boolean isChoose = false; + + public boolean isChoose() { + return isChoose; + } + + public void setChoose(@NonNull boolean choose) { + isChoose = choose; + } + + public String getGateWayId() { + return gatewayId == null ? "" : gatewayId; + } + + public void setGateWayId(@NonNull String gateWayId) { + this.gatewayId = gateWayId; + } + + @NonNull + public LinkCreateSceneBean getDetailInfo() { + return detailInfo== null ? new LinkCreateSceneBean() : detailInfo; + } + + public void setDetailInfo(@NonNull LinkCreateSceneBean detailInfo) { + this.detailInfo = detailInfo; + } + + @NonNull + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + @NonNull + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } + + @NonNull + public String getStatus() { + return status == null ? "" : status; + } + + public void setStatus(@NonNull String status) { + this.status = status; + } + + @NonNull + public String getGroup() { + return group == null ? "" : group; + } + + public void setGroup(@NonNull String group) { + this.group = group; + } + + @NonNull + public String getDelay() { + return delay == null ? "" : delay; + } + + public void setDelay(@NonNull String delay) { + this.delay = delay; + } + + @NonNull + public String getModify_time() { + return modify_time == null ? "" : modify_time; + } + + public void setModify_time(@NonNull String modify_time) { + this.modify_time = modify_time; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidNameBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidNameBean.java new file mode 100644 index 0000000..666f534 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidNameBean.java @@ -0,0 +1,33 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2022/1/13 + * description: + */ +public class LinkSidNameBean implements Serializable { + private String sid; + private String name; + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getName() { + return name == null ? "" : name; + } + + public void setName(@NonNull String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java new file mode 100644 index 0000000..a6d99a5 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidStrBean.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.bean; + +import androidx.annotation.NonNull; +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; + } + + @NonNull + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkSidUidBean.java new file mode 100644 index 0000000..f52f858 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull String uid) { + this.uid = uid; + } + + public List<LinkSidStrBean> getFunctions() { + if (functions == null) { + return new ArrayList<>(); + } + return functions; + } + + public void setFunctions(@NonNull List<LinkSidStrBean> functions) { + this.functions = functions; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkStatusBean.java new file mode 100644 index 0000000..3528ea8 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * Created by jlchen on 1/13/22. + */ +public class LinkStatusBean implements Serializable { + + private String key; + private String value; + + @NonNull + public String getKey() { + return key == null ? "" : key; + } + + public void setKey(@NonNull String key) { + this.key = key; + } + + @NonNull + public String getValue() { + return value == null ? "" : value; + } + + public void setValue(@NonNull String value) { + this.value = value; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java new file mode 100644 index 0000000..4ab629e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/LinkUploadOidBean.java @@ -0,0 +1,95 @@ +package com.hdl.sdk.link.bean; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import androidx.annotation.NonNull; + +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; + + @NonNull + public String getOid() { + return oid == null ? "" : oid; + } + + public void setOid(@NonNull String oid) { + this.oid = oid; + } + + @NonNull + public String getDevice_name() { + return device_name == null ? "" : device_name; + } + + public void setDevice_name(@NonNull String device_name) { + this.device_name = device_name; + } + + @NonNull + public String getDevice_mac() { + return device_mac == null ? "" : device_mac; + } + + public void setDevice_mac(@NonNull String device_mac) { + this.device_mac = device_mac; + } + + @NonNull + public String getDevice_model() { + return device_model == null ? "" : device_model; + } + + public void setDevice_model(@NonNull String device_model) { + this.device_model = device_model; + } + + @NonNull + public String getAddresses() { + return addresses == null ? "" : addresses; + } + + public void setAddresses(@NonNull String addresses) { + this.addresses = addresses; + } + + @NonNull + public String getDriver_code() { + return driver_code == null ? "" : driver_code; + } + + public void setDriver_code(@NonNull String driver_code) { + this.driver_code = driver_code; + } + + @NonNull + public String getHw_version() { + return hw_version == null ? "" : hw_version; + } + + public void setHw_version(@NonNull String hw_version) { + this.hw_version = hw_version; + } + + @NonNull + public String getFw_version() { + return fw_version == null ? "" : fw_version; + } + + public void setFw_version(@NonNull String fw_version) { + this.fw_version = fw_version; + } + + + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/bean/NoticeConfigInfo.java new file mode 100644 index 0000000..8381b75 --- /dev/null +++ b/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; + +import androidx.annotation.NonNull; + +/** + * 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(@NonNull boolean enable) { + this.enable = enable; + } + + public String getNoticeContent() { + return noticeContent == null ? "" : noticeContent; + } + + public void setNoticeContent(@NonNull String noticeContent) { + this.noticeContent = noticeContent; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java new file mode 100644 index 0000000..2ba494a --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/IHDLClient.java @@ -0,0 +1,52 @@ +package com.hdl.sdk.link.common; + +/** + * Created by Tong on 2021/9/28. + * 鍖呭惈鎵�鏈夋搷浣� + */ +public interface IHDLClient { + + + /** + * 鎼滅储缃戝叧 + */ + void searchGateway(); + + + /** + * 鑾峰彇缃戝叧璇︾粏淇℃伅 + */ + void getGatewayInfo(); + + /** + * 鑾峰彇璁惧鍒楄〃 + */ + void getDeviceList(); + + /** + * 鑾峰彇鍔熻兘鍒楄〃 + */ + void getFunctionList(); + + /** + * 鑾峰彇鍔熻兘灞炴�� + */ + void getFunctionAttribute(); + + /** + * 璁惧鎺у埗 + */ + void deviceControl(); + + /** + * 鑾峰彇璁惧鐘舵�� + */ + void getDeviceStatus(); + + /** + * 鏀瑰彉璁惧鐘舵�� + */ + void changeDeviceStatus(); + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java new file mode 100644 index 0000000..e87278f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/config/TopicConstant.java @@ -0,0 +1,312 @@ +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_FIND_REMOTE = "/base/%s/thing/service/mmv_device_find/down"; + + /** + * 绾㈠瀹濈殑瀹氫綅 + */ + public static final String IR_FIND_REMOTE = "/base/%s/thing/service/irDeviceFind/down"; + /** + * 绾㈠瀹濊瘯鐮� + */ + public static final String IR_CODE_TEST = "/base/%s/thing/service/irCodeTest/down"; + /** + * 绾㈠瀹濋仴鎺у櫒娣诲姞 + */ + public static final String IR_DEVICE_ADD = "/base/%s/thing/service/irDeviceAdd/down"; + /** + * 绾㈠瀹濋仴鎺у櫒鍒楄〃鑾峰彇 + */ + public static final String IR_DEVICE_LIST = "/base/%s/thing/service/irDeviceListGet/down"; + /** + * 绾㈠瀹濊嚜瀛︾爜 + * */ + public static final String IR_CODE_STUDY = "/base/%s/thing/service/irCodeStudy/down"; + /** + * 绾㈠瀹濊嚜瀛︾爜鍒犻櫎 + * */ + public static final String IR_CODE_REMOVE = "/base/%s/thing/service/irCodeRemove/down"; + + + /* + * 缃戝叧缂栬緫鍛戒护 + * 涓庢湇鍔″櫒鏃犲叧鐨� + * */ + 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"; + + //妯℃嫙浜戠ota + public static final String OTA_UPGRADE_DOWN = "/base/%s/ota/device/upgrade/down"; + + /** + * 缂栬緫sid + */ + public static final String EDIT_FUNCTION = "/user/%s/custom/function/attribute/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 EDIT_FUNCTION_ATTRIBUTE = "/user/%s/custom/function/attribute/edit"; + + //鍔熻兘灞炴�у搷搴� + 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"; + + public static final String NATIVE_ZIGBEE_DOWN ="/user/%s/custom/native/zigbee/down"; + + public static final String NATIVE_ZIGBEE_DOWN_REPLY ="/user/%s/custom/native/zigbee/down_reply"; + + public static final String NATIVE_ZIGBEE_UP ="/user/%s/custom/native/zigbee/up"; + + public static final String NATIVE_ZIGBEE_DOWN_SLAVE ="/user/%s/custom/native/zigbee/down/slaveoid/%s"; + + public static final String NATIVE_ZIGBEE_DOWN_SLAVE_REPLY ="/user/%s/custom/native/zigbee/down_reply/slaveoid/%s"; + + public static final String NATIVE_ZIGBEE_UP_SLAVE ="/user/%s/custom/native/zigbee/up/slaveoid/%s"; + + public static final String NATIVE_LINK_DOWN ="/user/%s/custom/native/a/down"; + + public static final String NATIVE_LINK_DOWN_REPLY ="/user/%s/custom/native/a/down_reply"; + + public static final String NATIVE_LINK_UP ="/user/%s/custom/native/a/up"; + + public static final String NATIVE_LINK_DOWN_SLAVE ="/user/%s/custom/native/a/down/slaveoid/%s"; + + public static final String NATIVE_LINK_DOWN_SLAVE_REPLY ="/user/%s/custom/native/a/down_reply/slaveoid/%s"; + + public static final String NATIVE_LINK_UP_SLAVE ="/user/%s/custom/native/a/up/slaveoid/%s"; + + public static final String GATEWAY_LOCATION_EDIT ="/user/%s/custom/gateway/location/edit"; + + public static final String GATEWAY_LOCATION_GET ="/user/%s/custom/gateway/location/get"; + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java new file mode 100644 index 0000000..37f8b50 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventDispatcher.java @@ -0,0 +1,239 @@ +package com.hdl.sdk.link.common.event; + +import androidx.annotation.NonNull; +import androidx.collection.ArrayMap; + + +import com.hdl.sdk.link.common.utils.LockArrayMap; +import com.hdl.sdk.link.common.utils.LockList; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.ThreadToolUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; + + +/** + * Created by Tong on 2021/9/22. + * 浜嬩欢鍒嗗彂 + */ +public class EventDispatcher { + + private static final LockList<EventListener> ALL_TOPICS_EVENT = new LockList<EventListener>();//鎵�鏈変富棰樻秷鎭� + +// private static final ArrayMap<String, List<EventListener>> EVENT = new ArrayMap<>(); + private static final LockArrayMap<String, List<EventListener>> EVENT = new LockArrayMap<String, List<EventListener>>(); + + private static final ExecutorService ioThread = ThreadToolUtils.getInstance().newFixedThreadPool(2); + + 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) { + try { + 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())); + } + } catch (Exception e) { + LogUtils.e(e.getMessage()); + } + } + + public synchronized void registerIo(String tag, EventListener listener) { + try { + if (!EVENT.containsKey(tag)) { + EVENT.put(tag, new ArrayList<>()); + } + List<EventListener> events = EVENT.get(tag); + if (events != null && !events.contains(listener)) { + events.add(listener); + } + } catch (Exception e) { + LogUtils.e(e.getMessage()); + } + } + + 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 e) { + LogUtils.e(e.getMessage()); + } + + } + }); + } + + 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 e) { + LogUtils.e(e.getMessage()); + } + + } + }); + } + + /** + * 涓や釜涓婚鏄惁鍖归厤 + * @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("+"))) { + if (i != 2) { + //缃戝叧id涓嶅垽鏂紝鍙兘鏄疧id,涔熷彲鑳芥槸mac + return false; + } + } + } + return true; + } + + /** + * 浜嬩欢鍒嗗彂鍣紝鍒嗗彂鎵�鏈夊湪鎺ュ彛鍒楄〃涓殑浜嬩欢 + * @param topicTag + * @param o + */ + public synchronized void post(String topicTag, @NonNull Object o) { + try { + 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() { + try { + if (listener != null) { + listener.onMessage(o); + } + } catch (Exception e) { + LogUtils.e("post鏁版嵁寮傚父", o + " " + e.getMessage()); + } + } + }); + } + } + } + //鎵�鏈変富棰樼殑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); + } + } + }); + } + }catch (Exception e){ + LogUtils.e(e.getMessage()); + } + + } + + /** + * 鏂囦欢鍙戦�侀�氱煡 wxr 2022-03-08 15:38:59 + */ + public synchronized void filePost() { + //TODO + } + /** + * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * @param listener + */ + public synchronized void registerAllTopicsListener(EventListener listener) { + 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(e.getMessage()); + } + } + + /** + * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * @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 e) { + LogUtils.e(e.getMessage()); + } + } + }); + } + + public synchronized void clear() { + ALL_TOPICS_EVENT.clear(); + EVENT.clear(); +// TYPE.clear(); + } + + public synchronized void release() { + clear(); + ioThread.shutdownNow(); + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java new file mode 100644 index 0000000..e2b3cdf --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/event/EventListener.java @@ -0,0 +1,10 @@ +package com.hdl.sdk.link.common.event; + +/** + * Created by Tong on 2021/9/22. + */ +public interface EventListener { + + void onMessage(Object msg); + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java new file mode 100644 index 0000000..a041d71 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java @@ -0,0 +1,64 @@ +package com.hdl.sdk.link.common.exception; + +import android.annotation.SuppressLint; +import android.content.Context; + +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.R; + +import java.util.HashMap; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : HDLError + */ +public class HDLLinkCode { + public static final HDLLinkCode HDL_UNKOWN_CODE=new HDLLinkCode(-1000,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNKOWN_CODE)); + public static final HDLLinkCode HDL_DATA_ERROR =new HDLLinkCode(-2000, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_ERROR)) ; + public static final HDLLinkCode HDL_DATA_NULL_ERROR=new HDLLinkCode(-2001, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_NULL_ERROR)); + public static final HDLLinkCode HDL_AUTH_ERROR=new HDLLinkCode(2002,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR) ); + public static final HDLLinkCode HDL_SEND_ERROR=new HDLLinkCode(2003, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEND_ERROR)); + public static final HDLLinkCode HDL_TIMEOUT_ERROR=new HDLLinkCode(2004, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TIMEOUT_ERROR)); + public static final HDLLinkCode HDL_UNAUTHORIZED_ERROR=new HDLLinkCode(-2005,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_UNAUTHORIZED_ERROR)); + public static final HDLLinkCode HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED=new HDLLinkCode(-2006, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED)); + public static final HDLLinkCode HDL_SEARCH_GATEWAY_TIMEOUT_ERROR=new HDLLinkCode(-2007, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_SEARCH_GATEWAY_TIMEOUT_ERROR)); + public static final HDLLinkCode HDL_AUTH_MAC_KEY_ERROR=new HDLLinkCode(-2008, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_AUTH_MAC_KEY_ERROR)); + public static final HDLLinkCode HDL_DATA_PARSING_ERROR=new HDLLinkCode(-2009, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_DATA_PARSING_ERROR)); + public static final HDLLinkCode HDL_GET_DEVICE_LIST_ERROR=new HDLLinkCode(-2100, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_DEVICE_LIST_ERROR)); + public static final HDLLinkCode HDL_GET_FUNCTION_LIST_ERROR=new HDLLinkCode(-2101, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_LIST_ERROR)); + public static final HDLLinkCode HDL_GET_FUNCTION_PROPERTIES_ERROR=new HDLLinkCode(-2102, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_FUNCTION_PROPERTIES_ERROR)); + public static final HDLLinkCode HDL_CONTROL_FAILURE_ERROR=new HDLLinkCode(-2103, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_CONTROL_FAILURE_ERROR)); + public static final HDLLinkCode HDL_GET_GATEWAY_FAILURE_ERROR=new HDLLinkCode(-2104, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_GATEWAY_FAILURE_ERROR)); + public static final HDLLinkCode HDL_GET_Zigbee_FAILURE_ERROR=new HDLLinkCode(-2105, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_FAILURE_ERROR)); + public static final HDLLinkCode HDL_GATEWAY_NOT_EXIST=new HDLLinkCode(-2106,HDLLinkLocalSdk.getInstance().getContext().getString( R.string.HDL_GATEWAY_NOT_EXIST)); + public static final HDLLinkCode HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR=new HDLLinkCode(-2107, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR)); + public static final HDLLinkCode HDL_MILLIMETER_NOT_EXIST=new HDLLinkCode(-2108, HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_MILLIMETER_NOT_EXIST)); + public static final HDLLinkCode HDL_APPLICATION_CODE=new HDLLinkCode(-2109,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_APPLICATION_EXCEPTION)); + public static final HDLLinkCode HDL_TOPIC_NOT_RIGHT=new HDLLinkCode(-2110,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TOPIC_NOT_RIGHT)); + public static final HDLLinkCode HDL_OBJECT_NOT_SUPPORT=new HDLLinkCode(-2111,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_OBJECT_NOT_SUPPORT)); + public static final HDLLinkCode HDL_GATEWAY_REMOTE_NOT_RESPONSE=new HDLLinkCode(-2112,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_REMOTE_NOT_RESPONSE)); + + private String msg; + private int code; + + public 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java new file mode 100644 index 0000000..040ff3b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkException.java @@ -0,0 +1,67 @@ +package com.hdl.sdk.link.common.exception; + +import androidx.annotation.NonNull; + +/** + * Created by Tong on 2021/11/11. + */ +public class HDLLinkException extends RuntimeException { + + private int code = 0; + private String msg = ""; + private Throwable rawThrowable; + + public HDLLinkException() { + } + + public HDLLinkException(String msg) { + this.msg = msg; + } + + public HDLLinkException(int code, String msg) { + this.code = code; + this.msg = msg; + } + + public HDLLinkException(int code) { + this.code = code; + } + + public HDLLinkException(Throwable rawThrowable) { + this.rawThrowable = rawThrowable; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public @NonNull + String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public Throwable getRawThrowable() { + return rawThrowable; + } + + public void setRawThrowable(Throwable rawThrowable) { + this.rawThrowable = rawThrowable; + } + + public static HDLLinkException getErrorWithCode(HDLLinkCode code){ + return new HDLLinkException(code.getCode(), code.getMsg()); + } + + public static HDLLinkException getErrorWithCode(int code,String msg){ + return new HDLLinkException(code,msg); + } +} + diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ByteUtils.java new file mode 100644 index 0000000..e4f6a9d --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ErrorUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ErrorUtils.java new file mode 100644 index 0000000..52bc4cd --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ErrorUtils.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.common.utils; + +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.R; +import com.hdl.sdk.link.common.exception.HDLLinkCode; + +import java.util.HashMap; + +/** + * Created by hxb on 2023/4/22. + */ +public class ErrorUtils { + //閿�:code 鍊硷細涓嫳鏂囨弿杩� + public static final HashMap<String, String> errorsMap = new HashMap<>(); + + + + /** + * 閫氳繃鐘舵�佺爜鑾峰彇寮傚父瀵硅薄 + * @param code 鐘舵�佺爜 + * @return 寮傚父瀵硅薄 + */ + public static HDLLinkCode getByCode(int code) { + String msg = errorsMap.get(code + ""); + if (msg == null) { + msg = "unkown"; + } + return new HDLLinkCode(code, msg); + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IdUtils.java new file mode 100644 index 0000000..2b8e659 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java new file mode 100644 index 0000000..aadb63e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/IpUtils.java @@ -0,0 +1,89 @@ +package com.hdl.sdk.link.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() { + 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; + } + + 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockArrayMap.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockArrayMap.java new file mode 100644 index 0000000..aa75a6e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockArrayMap.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.common.utils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.collection.ArrayMap; + +/** + * Created by hxb on 2022/10/17. + */ +public class LockArrayMap<K,V> extends ArrayMap<K, V> { + @Nullable + @Override + public V put(K key, V value) { + synchronized (this) { + return super.put(key, value); + } + } + + @Override + public boolean remove(Object key, Object value) { + synchronized (this) { + return super.remove(key, value); + } + } + + @Override + public boolean containsKey(@Nullable Object key) { + synchronized (this) { + return super.containsKey(key); + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockList.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockList.java new file mode 100644 index 0000000..715d63d --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LockList.java @@ -0,0 +1,37 @@ +package com.hdl.sdk.link.common.utils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.collection.ArrayMap; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * Created by hxb on 2022/10/17. + */ +public class LockList<T> extends ArrayList<T> { + + @Override + public boolean add(T t) { + synchronized (this) { + return super.add(t); + } + } + + @Override + public T remove(int index) { + synchronized (this) { + return super.remove(index); + } + } + + @Override + public boolean contains(@Nullable Object o) { + synchronized (this) { + return super.contains(o); + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java new file mode 100644 index 0000000..1228aad --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/LogUtils.java @@ -0,0 +1,63 @@ +package com.hdl.sdk.link.common.utils; + +import android.util.Log; + +/** + * Created by Tong on 2021/9/23. + */ +public class LogUtils { + + private static final String TAG = "HDLSDK"; + + private static boolean isEnabled = true; + + public static boolean isEnabled() { + return isEnabled; + } + + public static void setEnabled(boolean enabled) { + isEnabled = enabled; + } + + public static void d(String tag, String msg) { + if (tag != null && msg != null && isEnabled) { + Log.d(TAG, tag + "-- " + msg); + } + } + + public static void e(String tag, String msg) { + if (tag != null && msg != null && isEnabled) { + Log.e(TAG, tag + "-- " + msg); + } + } + + public static void w(String tag, String msg) { + if (tag != null && msg != null && isEnabled) { + Log.w(TAG, tag + "-- " + msg); + } + } + + public static void v(String tag, String msg) { + if (tag != null && msg != null && isEnabled) { + Log.v(TAG, tag + "-- " + msg); + } + } + + public static void i(String tag, String msg) { + if (tag != null && msg != null && isEnabled) { + Log.i(TAG, tag + "-- " + msg); + } + } + + public static void i(String msg) { + if (msg != null && isEnabled) { + Log.i(TAG, msg); + } + } + + public static void e(String msg) { + if (msg != null && isEnabled) { + Log.e(TAG, msg); + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java new file mode 100644 index 0000000..f5b8810 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/SPUtils.java @@ -0,0 +1,154 @@ +package com.hdl.sdk.link.common.utils; + +import android.content.Context; +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; + + +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 SharedPreferences PREFERENCES = + HDLLinkLocalSdk.getInstance().getContext().getApplicationContext().getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); + + private static SharedPreferences getAppPreference() { + if (PREFERENCES == null) { + PREFERENCES = HDLLinkLocalSdk.getInstance().getContext().getApplicationContext().getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); + } + return PREFERENCES; + } + + + //======閫氱敤瀛樺偍======== + public static void put(@NonNull final String key, final String value) { + getAppPreference().edit().putString(key, value).apply(); + } + + + public static String getString(@NonNull final String key) { + return getString(key, ""); + } + + + public static String getString(@NonNull final String key, final String defaultValue) { + return getAppPreference().getString(key, defaultValue); + } + + + public static void put(@NonNull final String key, final int value) { + put(key, value, false); + } + + + public static void put(@NonNull final String key, final int value, final boolean isCommit) { + getAppPreference().edit().putInt(key, value).apply(); + } + + + public static int getInt(@NonNull final String key) { + return getInt(key, -1); + } + + + public static int getInt(@NonNull final String key, final int defaultValue) { + return getAppPreference().getInt(key, defaultValue); + } + + + public static void put(@NonNull final String key, final long value) { + getAppPreference().edit().putLong(key, value).apply(); + } + + + public static long getLong(@NonNull final String key) { + return getLong(key, -1L); + } + + + public static long getLong(@NonNull final String key, final long defaultValue) { + return getAppPreference().getLong(key, defaultValue); + } + + + public static void put(@NonNull final String key, final float value) { + getAppPreference().edit().putFloat(key, value).apply(); + } + + + public static float getFloat(@NonNull final String key) { + return getFloat(key, -1f); + } + + + public static float getFloat(@NonNull final String key, final float defaultValue) { + return getAppPreference().getFloat(key, defaultValue); + } + + + public static void put(@NonNull final String key, final boolean value) { + getAppPreference().edit().putBoolean(key, value).apply(); + } + + + public static boolean getBoolean(@NonNull final String key) { + return getBoolean(key, false); + } + + + public static boolean getBoolean(@NonNull final String key, final boolean defaultValue) { + return getAppPreference().getBoolean(key, defaultValue); + } + + + public static void put(@NonNull final String key, + final Set<String> value + ) { + + getAppPreference().edit().putStringSet(key, value).apply(); + + } + + + public static Set<String> getStringSet(@NonNull final String key) { + return getStringSet(key, Collections.<String>emptySet()); + } + + + public static Set<String> getStringSet(@NonNull final String key, + final Set<String> defaultValue) { + return getAppPreference().getStringSet(key, defaultValue); + } + + + public static Map<String, ?> getAll() { + return getAppPreference().getAll(); + } + + + public static boolean contains(@NonNull final String key) { + return getAppPreference().contains(key); + } + + + public static void remove(@NonNull final String key) { + getAppPreference().edit().remove(key).apply(); + } + + public static void clear() { + getAppPreference() + .edit() + .clear() + .apply(); + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java new file mode 100644 index 0000000..5110598 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/ThreadToolUtils.java @@ -0,0 +1,72 @@ +package com.hdl.sdk.link.common.utils; + +import android.os.Handler; +import android.os.Looper; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +/** + * Created by Tong on 2021/9/15. + */ +public class ThreadToolUtils { + + private final Handler uiHandler = new Handler(Looper.getMainLooper()); + + //cpu 鏈�澶х嚎绋嬪绾抽噺 + private final int coreSize = Runtime.getRuntime().availableProcessors() + 1; + + private ThreadToolUtils() { + } + + private static class SingletonInstance { + private static final ThreadToolUtils INSTANCE = new ThreadToolUtils(); + } + + public static ThreadToolUtils getInstance() { + return SingletonInstance.INSTANCE; + } + + + /** + * 绾跨▼鏁伴噺鍥哄畾鐨勭嚎绋嬫睜 + */ + public ExecutorService newFixedThreadPool(int size) { + if (size == 0 || coreSize < size) { + return Executors.newFixedThreadPool(coreSize); + } + return Executors.newFixedThreadPool(size); + } + + /** + * 瀹氭椂浠诲姟绾跨▼姹� + */ + public ScheduledExecutorService newScheduledThreadPool(int size) { + if (size == 0 || coreSize < size) { + return Executors.newScheduledThreadPool(coreSize); + } + return Executors.newScheduledThreadPool(size); + } + + /** + * 鍗曚竴绾跨▼ + */ + public ExecutorService newSingleThreadPool() { + return Executors.newSingleThreadExecutor(); + } + + + public ExecutorService newCachedThreadPool() { + return Executors.newCachedThreadPool(); + } + + /** + * 鍒囨崲鍥炰富绾跨▼ + */ + public void runOnUiThread(Runnable run) { + uiHandler.post(run); + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java new file mode 100644 index 0000000..4ba481b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/GsonConvert.java @@ -0,0 +1,59 @@ +package com.hdl.sdk.link.common.utils.gson; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * Created by Tong on 2021/9/8. + */ +public class GsonConvert { + + private static Gson gson = null; + + public static Gson getGson() { + if (gson == null) { + synchronized (GsonConvert.class) { + if (gson == null) { + gson = new GsonBuilder() + .setPrettyPrinting() + .disableHtmlEscaping() + .registerTypeAdapter(String.class, new StringTypeAdapter()) + .create(); + } + } + } + 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) + throws JsonParseException { + if (json instanceof JsonPrimitive) { + return json.getAsString(); + } else { + return json.toString(); + } + } + + @Override + public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src); + } + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java new file mode 100644 index 0000000..642c191 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/utils/gson/ParameterizedTypeImpl.java @@ -0,0 +1,46 @@ +package com.hdl.sdk.link.common.utils.gson; + + +import androidx.annotation.NonNull; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +/** + * Created by Tong on 2021/9/17. + */ +public class ParameterizedTypeImpl implements ParameterizedType { + + private final Type[] actualTypeArguments; + private final Type rawType; + private final Type ownerType; + + public ParameterizedTypeImpl(Type rawType, Type[] actualTypeArguments, Type ownerType) { + this.ownerType = ownerType; + this.rawType = rawType; + this.actualTypeArguments = actualTypeArguments; + } + + public static Type getType(Type rawType, Type[] actualTypeArguments) { + return new ParameterizedTypeImpl(rawType, actualTypeArguments, null); + } + + @NonNull + @Override + public Type[] getActualTypeArguments() { + return actualTypeArguments; + } + + + @NonNull + @Override + public Type getRawType() { + return rawType; + } + + + @Override + public Type getOwnerType() { + return ownerType; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/FileRequest.java new file mode 100644 index 0000000..03e7995 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java new file mode 100644 index 0000000..088f82f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkPacket.java @@ -0,0 +1,52 @@ +package com.hdl.sdk.link.core.bean; + +/** + * Created by hxb on 2022/8/4. + */ +public class LinkPacket { + /** + * 涓婚鍐呭 + */ + private String topic; + /** + * 鍘熷鎺ユ敹鐨勬暟鎹紝鍙兘闇�瑕佽В瀵� + */ + private byte []body; + + private boolean cloudPacket; + + public LinkPacket(String topic, byte[] body) { + this(topic,body,false); + } + + public LinkPacket(String topic, byte[] body,boolean cloudPacket) { + this.topic = topic; + this.body = body; + this.cloudPacket=cloudPacket; + } + + + 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 boolean isCloudPacket() { + return cloudPacket; + } + + public void setCloudPacket(boolean cloudPacket) { + this.cloudPacket = cloudPacket; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java new file mode 100644 index 0000000..2f8e8d7 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java @@ -0,0 +1,150 @@ +package com.hdl.sdk.link.core.bean; + +import android.text.TextUtils; + +import com.hdl.sdk.link.common.utils.ByteUtils; + + +/** + * Created by Tong on 2021/9/29. + */ +public class LinkRequest { + private String topic; + private String replyTopic; + protected byte []data; + private int length=0; + + private boolean encrypt; + + public String getCloudTopic() { + if(TextUtils.isEmpty(cloudTopic)){ + return topic; + } + return cloudTopic; + } + + /** + * 骞冲彴topic + * @param cloudTopic + */ + public void setCloudTopic(String cloudTopic) { + this.cloudTopic = cloudTopic; + } + + private String cloudTopic; + + + public LinkRequest(String topic,String replyTopic, String data, boolean encrypt) { + this.topic = topic; + this.replyTopic=replyTopic; + setData(data); + this.encrypt = encrypt; + } + + public LinkRequest(String topic, String data, boolean encrypt) { + this(topic,null,data,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 String getReplyTopic() { + if(TextUtils.isEmpty(replyTopic)){ + return topic+"_reply"; + } + return replyTopic; + } + + public void setReplyTopic(String replyTopic) { + this.replyTopic = replyTopic; + } + + 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[]{}; + } + } + + public byte [] getCloudSendBytes() { + try { + //link閫忎紶鍛戒护锛屽唴瀹归渶瑕佸寘鍚富棰橈紝闀垮害 + if(getCloudTopic().contains("/native/a/down/slaveoid/")){ + return getSendBytes(); + }else { + return getData(); + } + } catch (Exception e) { + return new byte[]{}; + } + } + + + private int getBytesLength(String str) { + return ByteUtils.stringToBytes(str).length; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java new file mode 100644 index 0000000..ad2f655 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java @@ -0,0 +1,93 @@ +package com.hdl.sdk.link.core.bean; + +import android.text.TextUtils; + +import androidx.annotation.NonNull; + +import com.hdl.sdk.link.common.utils.gson.GsonConvert; + +import java.io.Serializable; + +/** + * Created by Tong on 2021/9/27. + */ +public class LinkResponse implements Serializable { + + private String topic; + private String data; + private int length; + private byte []byteData; + private int code; + private int msg; + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getData() { + 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); + } + + } + + public int getLength() { + return length; + } + + private void setLength(int length) { + this.length = length; + } + + @NonNull + @Override + public String toString() { + return GsonConvert.getGson().toJson(this); + } + + /** + * 鍝嶅簲鐘舵�佺爜 + * @return + */ + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + /** + * 鍝嶅簲娑堟伅 + * @return + */ + public int getMsg() { + return msg; + } + + public void setMsg(int msg) { + this.msg = msg; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java new file mode 100644 index 0000000..718facb --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ZigbeeResponse.java @@ -0,0 +1,88 @@ +package com.hdl.sdk.link.core.bean; + +import androidx.annotation.NonNull; + +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; + } + + @NonNull + @Override + public String toString() { + return GsonConvert.getGson().toJson(this); + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventBindMiniRemoteSuccessInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventBindMiniRemoteSuccessInfo.java new file mode 100644 index 0000000..16817ea --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventBindMiniRemoteSuccessInfo.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +/** + * Created by Zoro + * Created on 2021/5/24 + * description: + */ +public class EventBindMiniRemoteSuccessInfo implements Serializable { + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventCloseSearchDeviceActivityInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventCloseSearchDeviceActivityInfo.java new file mode 100644 index 0000000..256df37 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventCloseSearchDeviceActivityInfo.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +/** + * Created by Zoro + * Created on 2021/5/24 + * description: + */ +public class EventCloseSearchDeviceActivityInfo implements Serializable { + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventIRCodeStudySuccessInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventIRCodeStudySuccessInfo.java new file mode 100644 index 0000000..bf18b72 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventIRCodeStudySuccessInfo.java @@ -0,0 +1,36 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2021/5/24 + * description: + */ +public class EventIRCodeStudySuccessInfo implements Serializable { + private String topic; + private String content; + + public EventIRCodeStudySuccessInfo(String topic, String content) { + this.topic = topic; + this.content = content; + } + + public String getTopic() { + return topic == null ? "" : topic; + } + + public void setTopic(@NonNull String topic) { + this.topic = topic; + } + + public String getContent() { + return content == null ? "" : content; + } + + public void setContent(@NonNull String content) { + this.content = content; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventMqttAesFailInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventMqttAesFailInfo.java new file mode 100644 index 0000000..868de85 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventMqttAesFailInfo.java @@ -0,0 +1,12 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +/** + * Created by Zoro + * Created on 2021/5/24 + * description: + */ +public class EventMqttAesFailInfo implements Serializable { + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyDebugModeInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyDebugModeInfo.java new file mode 100644 index 0000000..29839f4 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyDebugModeInfo.java @@ -0,0 +1,27 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2021/5/24 + * description: + */ +public class EventNotifyDebugModeInfo implements Serializable { + + private boolean isRemote; + + public boolean isRemote() { + return isRemote; + } + + public void setRemote(@NonNull boolean remote) { + isRemote = remote; + } + + public EventNotifyDebugModeInfo(boolean isRemote) { + this.isRemote = isRemote; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyGetGateWayInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyGetGateWayInfo.java new file mode 100644 index 0000000..5b06130 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyGetGateWayInfo.java @@ -0,0 +1,11 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +/** + * Created by Zoro + * Created on 2022/6/29 + * description: + */ +public class EventNotifyGetGateWayInfo implements Serializable { +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyRefreshGatewayAesKeyInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyRefreshGatewayAesKeyInfo.java new file mode 100644 index 0000000..3029952 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/eventbus/EventNotifyRefreshGatewayAesKeyInfo.java @@ -0,0 +1,23 @@ +package com.hdl.sdk.link.core.bean.eventbus; + +import java.io.Serializable; + +/** + * Created by Zoro + * Created on 2022/6/29 + * description: + */ +public class EventNotifyRefreshGatewayAesKeyInfo implements Serializable { + + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + private String gatewayId; + + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java new file mode 100644 index 0000000..df81b6b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java @@ -0,0 +1,349 @@ +package com.hdl.sdk.link.core.bean.gateway; + +import android.text.TextUtils; + +import androidx.annotation.NonNull; + +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; + + /** + * 浣跨敤mqtt鐨勬椂鍊欓渶瑕佽В瀵� + */ + private String aesKey; + private String deviceId; + + /** + * 姣背娉id + */ + private String sid; + + + /** + * 璁惧鏉ユ簮(鑷畾涔�:0=琛ㄧず缃戝叧;1=琛ㄧず骞冲彴) + */ + private String src; + + public String getSrc() { + return src==null?"":this.src; + } + + public void setSrc(String src) { + this.src = src; + } + + public String getAesKey() { + return aesKey == null ? "" : aesKey; + } + + public void setAesKey(@NonNull String aesKey) { + this.aesKey = aesKey; + } + + public String getDeviceId() { + return deviceId == null ? "" : deviceId; + } + + public void setDeviceId(@NonNull String deviceId) { + this.deviceId = deviceId; + } + + 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 + */ + @NonNull + public String getDevice_mac() { + return TextUtils.isEmpty(device_mac) ? "" : device_mac; + } + + /** + * 缃戝叧Mac + */ + public void setDevice_mac(String device_mac) { + this.device_mac = device_mac; + } + /** + * 缃戝叧Id + */ + @NonNull + public String getGatewayId() { + return TextUtils.isEmpty(gatewayId) ? getOid() : gatewayId; + } + + /** + * 缃戝叧Id + */ + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + /** + * 缃戝叧绫诲瀷 + */ + @NonNull + public String getGatewayType() { + return gatewayType == null ? "" : gatewayType; + } + + /** + * 缃戝叧绫诲瀷 + */ + public void setGatewayType(String gatewayType) { + this.gatewayType = gatewayType; + } + + @NonNull + public String getGateway_type() { + return gateway_type == null ? "" : gateway_type; + } + + public void setGateway_type(String gateway_type) { + this.gateway_type = gateway_type; + } + /** + * 缃戝叧Oid + */ + @NonNull + public String getOid() { + return TextUtils.isEmpty(oid) ? getDevice_mac() : oid; + } + + /** + * 缃戝叧Oid + */ + public void setOid(String oid) { + this.oid = oid; + } + /** + * IP鍦板潃 + */ + @NonNull + 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 + */ + @NonNull + 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 + */ + @NonNull + public String getHomeId() { + return homeId == null ? "" : homeId; + } + + /** + * 璁剧疆浣忓畢Id + */ + public void setHomeId(String homeId) { + this.homeId = homeId; + } + + /** + * 鑾峰彇姣背娉id + * @return sid + */ + public String getSid() { + return sid==null?"":this.sid; + } + /** + * 璁剧疆姣背娉id + */ + public void setSid(String sid) { + this.sid = sid; + } + /** + * 鏄惁鏈湴缃戝叧 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java new file mode 100644 index 0000000..a77548c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/AuthenticateRequest.java @@ -0,0 +1,310 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; + +/** + * Created by jlchen on 11/11/21. + * + * @Description : AuthenticateRequest + * 涓夋柟缃戠粶璁惧鍏ョ綉鍙婅璇� 璇锋眰鍙傛暟 + * 璇锋眰topic:/user/all/custom/deivce/network_access/request + */ +public class AuthenticateRequest implements Serializable { + private String id; + private String time_stamp; + private AuthenticateDeviceInfoBean objects;//褰撳墠璁惧鍩烘湰淇℃伅 + private AuthBean auth;//璁よ瘉淇℃伅 + + public String getID() { return id; } + public void setID(String value) { this.id = value; } + + public String getTimeStamp() { return time_stamp; } + public void setTimeStamp(String value) { this.time_stamp = value; } + + public AuthenticateDeviceInfoBean getObjects() { return objects; } + public void setObjects(AuthenticateDeviceInfoBean value) { this.objects = value; } + + public AuthBean getAuth() { return auth; } + public void setAuth(AuthBean value) { this.auth = value; } + + public AuthenticateRequest(String id, String time_stamp, AuthenticateDeviceInfoBean objects, AuthBean auth) { + this.id = id; + this.time_stamp = time_stamp; + this.objects = objects; + this.auth = auth; + } + + public static class AuthBean implements Serializable { + private String mac_key;//(mac+secret)鐨勪袱娆d5鍊� + private String spk; + private RequestBean request;//璁惧鐩稿叧淇℃伅 + + public String getMACKey() { return mac_key; } + public void setMACKey(String value) { this.mac_key = value; } + + public String getSpk() { return spk; } + public void setSpk(String value) { this.spk = value; } + + public RequestBean getRequest() { return request; } + public void setRequest(RequestBean value) { this.request = value; } + + public AuthBean() { + + } + public AuthBean(String mac_key, String spk, RequestBean request) { + this.mac_key = mac_key; + this.spk = spk; + this.request = request; + } + } + + public static class RequestBean implements Serializable{ + private String mac;//璁惧mac + private String supplier;//鍘傚 + private String hardware_model;//璁惧鍨嬪彿 + private String firmware_version;//绋嬪簭鐗堟湰 + public RequestBean(){}; + public RequestBean(String mac, String supplier, String hardware_model, String firmware_version) { + this.mac = mac; + this.supplier = supplier; + this.hardware_model = hardware_model; + this.firmware_version = firmware_version; + } + + public String getMAC() { return mac; } + public void setMAC(String value) { this.mac = value; } + + public String getSupplier() { return supplier; } + public void setSupplier(String value) { this.supplier = value; } + + public String getHardwareModel() { return hardware_model; } + public void setHardwareModel(String value) { this.hardware_model = value; } + + public String getFirmwareVersion() { return firmware_version; } + public void setFirmwareVersion(String value) { this.firmware_version = value; } + } + + public static class AuthenticateDeviceInfoBean implements Serializable{ + private String oid;//璁惧鐨凮id + private String device_mac;//璁惧鐨凪ac + private String device_name;// + private String device_model; + private String access_mode; + private String sid; + private String ip_mac; + private String ip_address; + private String netmask = "255.255.255.0"; + private String ip_gateway; + private String dns1 = "114.114.114.114"; + private String dns2 = "8.8.8.8"; + private String gateway_type; + private String hw_version; + private String fw_version; + + public String getOID() { return oid; } + + /** + * 璁惧Oid + * @param value + */ + public void setOID(String value) { this.oid = value; } + + public String getDeviceMAC() { return device_mac; } + + /** + * 璁惧Mac + * @param value + */ + public void setDeviceMAC(String value) { this.device_mac = value; } + + /** + * 璁惧鍚� + * @return + */ + public String getDeviceName() { return device_name; } + + /** + * 璁惧鍚� + * @param value + */ + public void setDeviceName(String value) { this.device_name = value; } + + /** + * 璁惧鍨嬪彿 + * @return + */ + public String getDeviceModel() { return device_model; } + + /** + * 璁惧鍨嬪彿 + * @param value + */ + public void setDeviceModel(String value) { this.device_model = value; } + + /** + * 杩炴帴绫诲瀷锛屾湁绾胯繕鏄棤绾� + * @return + */ + public String getAccessMode() { return access_mode; } + + /** + * 杩炴帴绫诲瀷锛屾湁绾胯繕鏄棤绾� + * @param value + */ + public void setAccessMode(String value) { this.access_mode = value; } + + /** + * 璁惧sid + * @return + */ + public String getSid() { return sid; } + + /** + * 璁惧sid + * @param value + */ + public void setSid(String value) { this.sid = value; } + + /** + * 璁惧IPMAC + * @return + */ + public String getIPMAC() { return ip_mac; } + + /** + * 璁惧IPMAC + * @param value + */ + public void setIPMAC(String value) { this.ip_mac = value; } + + /** + * 璁惧IP鍦板潃 + * @return + */ + public String getIPAddress() { return ip_address; } + + /** + * 璁惧IP鍦板潃 + * @param value + */ + public void setIPAddress(String value) { this.ip_address = value; } + + /** + * 瀛愮綉鎺╃爜 + * @return + */ + public String getNetmask() { return netmask; } + + /** + * 瀛愮綉鎺╃爜 + * @param value + */ + public void setNetmask(String value) { this.netmask = value; } + + /** + * 缃戝叧IP + * @return + */ + public String getIPGateway() { return ip_gateway; } + + /** + * 缃戝叧IP + * @param value + */ + public void setIPGateway(String value) { this.ip_gateway = value; } + + /** + * DNS1 + * @return + */ + public String getDns1() { return dns1; } + + /** + * DNS1 + * @param value + */ + public void setDns1(String value) { this.dns1 = value; } + + /** + * DNS2 + * @return + */ + public String getDns2() { return dns2; } + + /** + * DNS2 + * @param value + */ + public void setDns2(String value) { this.dns2 = value; } + + public VersionBean[] getVersions() {return null; } + public void setVersions(VersionBean[] value) { } + + /** + * 缃戝叧绫诲瀷 + * @return + */ + public String getGateway_type() { + return gateway_type; + } + + /** + * 缃戝叧绫诲瀷 + * @param gateway_type + */ + public void setGateway_type(String gateway_type) { + this.gateway_type = gateway_type; + } + + /** + * 纭欢鐗堟湰 + * @return + */ + public String getHw_version() { + return hw_version; + } + + /** + *纭欢鐗堟湰 + * @param + */ + public void setHw_version(String hw_version) { + this.hw_version = hw_version; + } + + + /** + * 鍥轰欢鐗堟湰 + * @return + */ + public String getFw_version() { + return fw_version; + } + + /** + * 鍥轰欢鐗堟湰 + * @param fw_version + */ + public void setFw_version(String fw_version) { + this.fw_version = fw_version; + } + } + + public static class VersionBean implements Serializable{ + private String module; + private String version; + + public VersionBean(String module, String version) { + this.module = module; + this.version = version; + } + + public String getModule() { + return module; + } + + public void setModule(String value) { + this.module = value; + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java new file mode 100644 index 0000000..44fcccf --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BaseLocalRequest.java @@ -0,0 +1,47 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; + +/** + * Created by Tong on 2021/9/29. + */ +public class BaseLocalRequest<T> implements Serializable { + + + private String id; + private String code; + private String time_stamp; + private T objects; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getTime_stamp() { + return time_stamp; + } + + public void setTime_stamp(String time_stamp) { + this.time_stamp = time_stamp; + } + + public T getObjects() { + return objects; + } + + public void setObjects(T objects) { + this.objects = objects; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java new file mode 100644 index 0000000..d760638 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/BroadcastRequest.java @@ -0,0 +1,54 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; + +/** + * Created by jlchen on 11/11/21. + * + * /user/all/custom/gateway/broadcast + */ +public class BroadcastRequest implements Serializable { + private String id; + private String time_stamp; + private AuthenticateRequest.AuthenticateDeviceInfoBean objects;//褰撳墠璁惧鍩烘湰淇℃伅 + private String code;// + + public BroadcastRequest(String id, String time_stamp, AuthenticateRequest.AuthenticateDeviceInfoBean objects, String code) { + this.id = id; + this.time_stamp = time_stamp; + this.objects = objects; + this.code = code; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTime_stamp() { + return time_stamp; + } + + public void setTime_stamp(String time_stamp) { + this.time_stamp = time_stamp; + } + + public AuthenticateRequest.AuthenticateDeviceInfoBean getObjects() { + return objects; + } + + public void setObjects(AuthenticateRequest.AuthenticateDeviceInfoBean objects) { + this.objects = objects; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java new file mode 100644 index 0000000..5c4c800 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/DeviceControlRequest.java @@ -0,0 +1,51 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; +import java.util.List; + +/** + * Created by Tong on 2021/10/8. + */ +public class DeviceControlRequest implements Serializable { + + private String sid; + private List<StatusBean> status; + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + + public List<StatusBean> getStatus() { + return status; + } + + public void setStatus(List<StatusBean> status) { + this.status = status; + } + + public static class StatusBean implements Serializable { + private String key; + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java new file mode 100644 index 0000000..b274fde --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/FunctionAttributeRequest.java @@ -0,0 +1,24 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; + +/** + * Created by Tong on 2021/10/8. + */ +public class FunctionAttributeRequest implements Serializable { + + private String sid; + + public FunctionAttributeRequest(String sid) { + this.sid = sid; + } + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java new file mode 100644 index 0000000..4136322 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyReadRequest.java @@ -0,0 +1,22 @@ +package com.hdl.sdk.link.core.bean.request; + +/** + * Created by Tong on 2021/10/8. + */ +public class PropertyReadRequest { + + private String sid; + + public PropertyReadRequest(String sid) { + this.sid = sid; + } + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java new file mode 100644 index 0000000..dfd46b4 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/request/PropertyUpRequest.java @@ -0,0 +1,50 @@ +package com.hdl.sdk.link.core.bean.request; + +import java.io.Serializable; +import java.util.List; + +/** + * Created by Tong on 2021/10/8. + */ +public class PropertyUpRequest implements Serializable { + + private String sid; + private List<StatusBean> status; + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + + public List<StatusBean> getStatus() { + return status; + } + + public void setStatus(List<StatusBean> status) { + this.status = status; + } + + public static class StatusBean implements Serializable{ + private String key; + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java new file mode 100644 index 0000000..ea7d429 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/AuthenticateResponse.java @@ -0,0 +1,47 @@ +package com.hdl.sdk.link.core.bean.response; + +import java.io.Serializable; + +/** + * Created by jlchen on 11/12/21. + * + * @Description : AuthenticateResponseBean + */ +public class AuthenticateResponse extends BaseResponse { + private String code; + private GatewayObjects objects; + private Auth auth; + + public String getCode() { return code; } + public void setCode(String value) { this.code = value; } + + public GatewayObjects getObjects() { return objects; } + public void setObjects(GatewayObjects value) { this.objects = value; } + + public Auth getAuth() { return auth; } + public void setAuth(Auth value) { this.auth = value; } + + public class Auth implements Serializable { + private String localSecret; + + public String getLocalSecret() { return localSecret; } + public void setLocalSecret(String value) { this.localSecret = value; } + } + + public class GatewayObjects implements Serializable { + private String ip_address; + private String gatewayId; + private String oid; + + public String getIPAddress() { return ip_address; } + public void setIPAddress(String value) { this.ip_address = value; } + + public String getGatewayID() { return gatewayId; } + public void setGatewayID(String value) { this.gatewayId = value; } + + public String getOID() { return oid; } + public void setOID(String value) { this.oid = value; } + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java new file mode 100644 index 0000000..2000807 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalResponse.java @@ -0,0 +1,37 @@ +package com.hdl.sdk.link.core.bean.response; + +import java.io.Serializable; + +/** + * Created by Tong on 2021/9/29. + */ +public class BaseLocalResponse<T> implements Serializable { + + private String id; + private String time_stamp; + private T objects; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTime_stamp() { + return time_stamp; + } + + public void setTime_stamp(String time_stamp) { + this.time_stamp = time_stamp; + } + + public T getObjects() { + return objects; + } + + public void setObjects(T objects) { + this.objects = objects; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalWithCodeResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalWithCodeResponse.java new file mode 100644 index 0000000..cfd555a --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseLocalWithCodeResponse.java @@ -0,0 +1,39 @@ +package com.hdl.sdk.link.core.bean.response; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Tong on 2021/9/29. + */ +public class BaseLocalWithCodeResponse<T> implements Serializable { + + private String id; + private String time_stamp; + private T code; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTime_stamp() { + return time_stamp; + } + + public void setTime_stamp(String time_stamp) { + this.time_stamp = time_stamp; + } + + public T getCode() { + return code; + } + + public void setCode(@NonNull T code) { + this.code = code; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java new file mode 100644 index 0000000..3337610 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/BaseResponse.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.core.bean.response; + +import java.io.Serializable; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : BaseResponse + */ +public class BaseResponse implements Serializable { + + private String id; + private String time_stamp; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTime_stamp() { + return time_stamp; + } + + public void setTime_stamp(String time_stamp) { + this.time_stamp = time_stamp; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java new file mode 100644 index 0000000..b574beb --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/GatewaySearchBean.java @@ -0,0 +1,109 @@ +package com.hdl.sdk.link.core.bean.response; + +import java.io.Serializable; + +/** + * Created by Tong on 2021/9/29. + * 缃戝叧鎼滅储 + */ +public class GatewaySearchBean implements Serializable { + private String device_model; + private String device_name; + private String device_mac; + private String gatewayId; + private String gatewayType; + private String gateway_type; + private String oid; + private String ip_address; + private String access_mode; + private String master; + private boolean isLocalEncrypt;//2021-11-11 鏂板 + + public String getDevice_model() { + return device_model; + } + + public void setDevice_model(String device_model) { + this.device_model = device_model; + } + + public String getDevice_name() { + return device_name; + } + + public void setDevice_name(String device_name) { + this.device_name = device_name; + } + + public String getDevice_mac() { + return device_mac; + } + + public void setDevice_mac(String device_mac) { + this.device_mac = device_mac; + } + + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + public String getGatewayType() { + return gatewayType; + } + + public void setGatewayType(String gatewayType) { + this.gatewayType = gatewayType; + } + + public String getGateway_type() { + return gateway_type; + } + + public void setGateway_type(String gateway_type) { + this.gateway_type = gateway_type; + } + + public String getOid() { + return oid; + } + + public void setOid(String oid) { + this.oid = oid; + } + + public String getIp_address() { + return ip_address; + } + + public void setIp_address(String ip_address) { + this.ip_address = ip_address; + } + + public String getAccess_mode() { + return access_mode; + } + + public void setAccess_mode(String access_mode) { + this.access_mode = access_mode; + } + + public String getMaster() { + return master; + } + + public void setMaster(String master) { + this.master = master; + } + + public boolean isLocalEncrypt() { + return isLocalEncrypt; + } + + public void setLocalEncrypt(boolean localEncrypt) { + isLocalEncrypt = localEncrypt; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java new file mode 100644 index 0000000..23a16c4 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/response/NetworkAccessBroadcastResponse.java @@ -0,0 +1,22 @@ +package com.hdl.sdk.link.core.bean.response; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : NetworkAccessBroadcastResponse + */ +public class NetworkAccessBroadcastResponse extends BaseResponse { + private String ip_address; + private String oid; + private String homeId; + + public String getIPAddress() { return ip_address; } + public void setIPAddress(String value) { this.ip_address = value; } + + public String getOID() { return oid; } + public void setOID(String value) { this.oid = value; } + + public String getHomeID() { return homeId; } + public void setHomeID(String value) { this.homeId = value; } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneCanDeleteInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneCanDeleteInfo.java new file mode 100644 index 0000000..ff13772 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneCanDeleteInfo.java @@ -0,0 +1,33 @@ +package com.hdl.sdk.link.core.bean.scenebatch; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2022/12/9 + * description: + */ +public class SceneCanDeleteInfo implements Serializable { + private String sid; + private String can_delete; + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getCan_delete() { + return can_delete == null ? "" : can_delete; + } + + public void setCan_delete(@NonNull String can_delete) { + this.can_delete = can_delete; + } + + +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneGroupInfo.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneGroupInfo.java new file mode 100644 index 0000000..cb7a93d --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/scenebatch/SceneGroupInfo.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.core.bean.scenebatch; + +import java.io.Serializable; + +import androidx.annotation.NonNull; + +/** + * Created by Zoro + * Created on 2022/12/9 + * description: + */ +public class SceneGroupInfo implements Serializable { + private String sid; + private String group; + + public String getSid() { + return sid == null ? "" : sid; + } + + public void setSid(@NonNull String sid) { + this.sid = sid; + } + + public String getGroup() { + return group == null ? "" : group; + } + + public void setGroup(@NonNull String group) { + this.group = group; + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/BaseCallBack.java new file mode 100644 index 0000000..88d979b --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/GatewayCallBack.java new file mode 100644 index 0000000..5299977 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java new file mode 100644 index 0000000..4bdf82f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkCallBack.java @@ -0,0 +1,10 @@ +package com.hdl.sdk.link.core.callback; + +/** + * Created by jlchen on 11/16/21. + * + * @Description : HDLLinkCallBack + */ +public interface HDLLinkCallBack extends BaseCallBack{ + void onSuccess(String msg); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java new file mode 100644 index 0000000..418152a --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkResponseCallBack.java @@ -0,0 +1,13 @@ +package com.hdl.sdk.link.core.callback; + + +import com.hdl.sdk.link.core.bean.LinkResponse; + +/** + * Created by jlchen on 11/16/21. + * + * @Description : HDLLinkResponseCallBack + */ +public interface HDLLinkResponseCallBack extends BaseCallBack{ + void onSuccess(LinkResponse msg); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/HDLLinkTCallBack.java new file mode 100644 index 0000000..dfa9885 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java new file mode 100644 index 0000000..5d29b40 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ZigbeeCallBack.java @@ -0,0 +1,10 @@ +package com.hdl.sdk.link.core.callback; + +import org.json.JSONException; + +/** + * Created by hxb on 2021/12/15. + */ +public interface ZigbeeCallBack extends BaseCallBack { + void onSuccess(String body); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java new file mode 100644 index 0000000..195ea25 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/config/HDLLinkConfig.java @@ -0,0 +1,211 @@ +package com.hdl.sdk.link.core.config; + +import com.hdl.sdk.link.common.utils.LogUtils; +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; + +import androidx.annotation.NonNull; + + +/** + * 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 AUTHENTICATE_IS_CLOUD_ENCRYPT_KEY = "cloud_isencrypt_key"; + private static final String AUTHENTICATE_CLOUD_ENCRYPT_KEY = "cloud_encrypt_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 String aesKey; + //浜戠缃戝叧鏄惁鍔犲瘑 + private boolean isCloudEncrypt = true; + + 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); + isCloudEncrypt = SPUtils.getBoolean(AUTHENTICATE_IS_CLOUD_ENCRYPT_KEY, false); + aesKey = SPUtils.getString(AUTHENTICATE_CLOUD_ENCRYPT_KEY, ""); + 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); + } + + public String getAesKey() { + return aesKey == null ? "" : aesKey; + } + + public void setAesKey(@NonNull String aesKey) { + this.aesKey = aesKey; + SPUtils.put(AUTHENTICATE_CLOUD_ENCRYPT_KEY, aesKey); + } + + + public boolean isCloudEncrypt() { + return isCloudEncrypt; + } + + public void setCloudEncrypt(@NonNull boolean cloudEncrypt) { + isCloudEncrypt = cloudEncrypt; + SPUtils.put(AUTHENTICATE_IS_CLOUD_ENCRYPT_KEY, cloudEncrypt); + } + + /** + * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 + * + * @return + */ + public boolean checkIfCertified() { + //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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java new file mode 100644 index 0000000..18967d5 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java @@ -0,0 +1,432 @@ +package com.hdl.sdk.link.core.connect; + +import android.text.TextUtils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +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.utils.ErrorUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +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.config.HDLLinkConfig; +import com.hdl.sdk.link.core.utils.EncryptUtil; +import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + +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 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; + /** + * 璁惧mac + */ + private String mac; + /** + * 鍙戦�佺殑鐩爣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 replyTopic; + + public interface HdlSocketListener { + void onSucceed(Object msg); + + void onFailure(HDLLinkCode hdlLinkCode); + } + + /** + * 鍙戦�乁DP鎴栬�匱CP鏁版嵁 + * + * @param sendAwaitTime 姣忔鍙戦�佺瓑寰呮椂闂� + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) { + this.sendAwaitTime = sendAwaitTime; + this.maxRetry = maxRetry; + this.ipAddress = ipAddress; + this.port = port; + this.linkRequest = linkRequest; + this.replyTopic = linkRequest.getReplyTopic(); + this.listener = listener; + this.isTcp = isTcp; + + + eventListener = new EventListener() { + @Override + public void onMessage(Object msg) { + isSend.set(true); + try { + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + JSONObject jsonObject = JSON.parseObject(linkResponse.getData()); + String id = jsonObject.getString("id"); + Integer code = jsonObject.getInteger("code"); + /** + * 鍙兘杩斿洖code灞炴�у彲鑳芥病鏈� 娌℃湁鐨勮瘽鐩存帴鎴愬姛 鏈夌殑璇濆彧鏈�200鎵嶄細鎴愬姛 + */ + if (code == null || code.intValue() == 200 || code.intValue() == 0) { + notifySucceed(msg); + }else { + notifyFailure(ErrorUtils.getByCode(code)); + } + } + else if (msg instanceof ZigbeeResponse) { + ZigbeeResponse linkResponse = (ZigbeeResponse) msg; + //TODO 濡傛灉閰嶇疆浠庣綉鍏崇殑淇℃伅锛岄�氳繃涓荤綉鍏宠浆杈撅紝杩欓噷oid瑕佸垽鏂笅 + if (replyTopic.equals(linkResponse.getTopic())) { + notifySucceed(linkResponse.getData()); + } + else{ + notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT); + } + } + else{ + notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_OBJECT_NOT_SUPPORT.getCode(), "Object Name:" + msg)); + } + } catch (Exception e) { + notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_APPLICATION_CODE.getCode(), e.getMessage())); + } + } + }; + //娉ㄥ唽鐩戝惉 + registerListener(); + } + + /** + * 鍙戦�乁DP鎴栬�匱CP鏁版嵁(鍙傛暟鏈塵ac) + * + * @param sendAwaitTime 姣忔鍙戦�佺瓑寰呮椂闂� + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + * @param mac 璁惧mac + */ + public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp,String mac) { + this(sendAwaitTime,maxRetry,ipAddress,port,linkRequest,listener,isTcp); + this.mac = mac; + } + + /** + * 鎸夌収鎸囧畾娆℃暟鍙戯紝鍥炶皟 + * + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(int maxRetry, String ipAddress, int port, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) { + this(DEF_SEND_TIMEOUT, maxRetry, ipAddress, port, linkRequest, listener, isTcp); + } + + /** + * 鎸夌収鎸囧畾娆℃暟鍙戯紝鍥炶皟 + * + * @param maxRetry 閲嶈瘯娆℃暟 + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(int maxRetry, String ipAddress, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) { + this(maxRetry, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, 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, isTcp); + } + + /** + * 鎸夌収榛樿閲嶅彂鏈哄埗鍙戦�� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param port 鍙戦�佺洰鏍囩鍙� + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(String ipAddress, int port, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) { + this(DEF_MAX_RETRY, ipAddress, port, linkRequest, listener, isTcp); + } + + /** + * 榛樿绔彛鍙戦�� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(String ipAddress, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) { + this(DEF_SEND_TIMEOUT, DEF_MAX_RETRY, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, listener, isTcp); + } + + /** + * 榛樿绔彛鍙戦��(鍙傛暟鏈塵ac) + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param listener 鍥炶皟 + * @param isTcp 鏄惁TCP + * @param mac 璁惧mac + */ + public HDLConnectHelper(String ipAddress, + LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp,String mac) { + this(DEF_SEND_TIMEOUT, DEF_MAX_RETRY, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, listener, isTcp,mac); + } + + + + /** + * 鍙戦�佷竴娆� + * + * @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, isTcp); + } + + /** + * 鍙戦�佷竴娆� + * + * @param ipAddress 鍙戦�佺洰鏍嘔P + * @param linkRequest 鍙戦�佸璞� + * @param isTcp 鏄惁TCP + */ + public HDLConnectHelper(Long timeout,String ipAddress, LinkRequest linkRequest, boolean isTcp) { + this(timeout, DEF_SEND_ONE, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, null, isTcp); + } + + + + /** + * 娉ㄥ唽鐩戝惉 + */ + private void registerListener() { + if (!TextUtils.isEmpty(replyTopic) && null != listener) { + EventDispatcher.getInstance().register(replyTopic, eventListener); + } + } + + /** + * 绉婚櫎鐩戝惉 + */ + private void removeListener() { + if (!TextUtils.isEmpty(replyTopic)) { + EventDispatcher.getInstance().remove(replyTopic, eventListener); + } + } + + public static boolean isLocal() { + String ip = HDLLinkConfig.getInstance().getIpAddress(); + if (ip == null) { + //濡傛槸鏈湴鏄彲浠ユ悳绱㈠埌ip鐨� + return false; + } + + //鏈湴鏄彲浠ヨ繙绋嬫垚鍔熺殑 + return HDLTcpConnect.getTcpSocketBoot(ip).isConnected(); + } + + public void send() { + + getSendThread().scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + //鍙戦�佹鏁板皬浜庨噸鍙戞鏁� + if ((sendNumber.get() < maxRetry)) { + try { + + //杩樻病鏈夋敹鍒板洖澶嶏紝鍐嶅彂閫� + if (!isSend.get()) { + sendNumber.set(sendNumber.get() + 1); + + //濡傛槸tcp鎴栬�卪qtt + if (isTcp) { + //mqtt + if (TextUtils.isEmpty(ipAddress) || !HDLTcpConnect.getTcpSocketBoot(ipAddress).isConnected()) { + if (!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅 + //LogUtils.i("蹇冭烦鍖呭彂閫佹暟鎹細\r\n" + new String(linkRequest.getCloudSendBytes())); + } else { + return;//浜戠鎯呭喌涓嬶紝蹇冭烦鍙互涓嶇敤 + } + String requestTopic = linkRequest.getCloudTopic(); + byte[] encryBytes = null; + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); + if (gatewayBean != null && getGatewayTypeList().contains(gatewayBean.getGatewayType())) { + //姣背娉㈣繙绋媘qtt绉橀挜涓嶄竴鏍� + encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), gatewayBean.getAesKey()); + } else { + encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), HDLLinkConfig.getInstance().getAesKey()); + } + if (MqttRecvClient.getInstance() != null) { + MqttRecvClient.getInstance().send(requestTopic, encryBytes); + } + LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes())); + } + //鏈湴TCP + else { + if (!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅 + LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes())); + } + HDLTcpConnect.getTcpSocketBoot(ipAddress).sendMsg(EncryptUtil.getEncryBytes(linkRequest)); + } + } else { + //濡傛灉鏄痷dp + LogUtils.i("鏈湴鍙戦�佹暟鎹甎DP锛�" + new String(linkRequest.getSendBytes())); + HDLUdpConnect.getInstance().getUdpBoot().sendMsg(ipAddress, port, EncryptUtil.getEncryBytes(linkRequest)); + } + } + } catch (Exception e) { + LogUtils.e("鏁版嵁鍙戦�佸紓甯革細", e.getMessage()); + } + } else { + //瓒呭嚭閲嶅彂娆℃暟骞舵病鏈夋敹鍒板洖澶� + if (!isSend.get()) { + if (linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鍏堜笉閫氱煡 + notifyFailure(null); + } else { + if (!TextUtils.isEmpty(replyTopic) && null != listener) {//闇�瑕佹墦鍗板嚭澶辫触鐨勬棩蹇� + LogUtils.e("鍙戦�佸け璐ユ暟鎹富棰�:" + linkRequest.getTopic()); + } + if (isTcp) { + //mqtt + if (TextUtils.isEmpty(ipAddress) || !HDLTcpConnect.getTcpSocketBoot(ipAddress).isConnected()) { + notifyFailure(HDLLinkCode.HDL_GATEWAY_REMOTE_NOT_RESPONSE); + } + //鏈湴TCP锛屽苟鏄繛鎺ョ姸鎬� + else { + notifyFailure(HDLLinkCode.HDL_TIMEOUT_ERROR); + } + } else { + notifyFailure(HDLLinkCode.HDL_TIMEOUT_ERROR); + } + } + } + } + } + }, 0, sendAwaitTime, TimeUnit.MILLISECONDS); + //initialdelay - 棣栨鎵ц鐨勫欢杩熸椂闂� 0 + //delay - 涓�娆℃墽琛岀粓姝㈠拰涓嬩竴娆℃墽琛屽紑濮嬩箣闂寸殑寤惰繜 + } + + /** + * 鑾峰彇鍙戦�佺嚎绋� + * + * @return 杩斿洖鑾峰彇鍒扮殑绾跨▼ + */ + private ScheduledExecutorService getSendThread() { + if (sendThread == null) { + sendThread = ThreadToolUtils.getInstance().newScheduledThreadPool(1); + } + return sendThread; + } + + /** + * 鍙戦�佸け璐� + */ + private void notifyFailure(HDLLinkCode hdlLinkCode) { + //绉婚櫎鐩戝惉 + removeListener(); + if (sendThread != null) { + sendThread.shutdownNow(); + sendThread = null; + } + if (listener != null && hdlLinkCode != null) { + listener.onFailure(hdlLinkCode); + listener = null; + } + } + + /** + * 鏀寔姣背绫诲瀷 + * + * @return 绫诲瀷鍒楄〃 + */ + public static List<String> getGatewayTypeList() { + List<String> typeList = new ArrayList<>(); + typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk + typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk + return typeList; + } + + private void notifySucceed(Object msg) { + //绉婚櫎鐩戝惉 + removeListener(); + if (sendThread != null) { + sendThread.shutdownNow(); + sendThread = null; + } + if (listener != null) { + listener.onSucceed(msg); + listener = null; + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java new file mode 100644 index 0000000..9ddf6ad --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLTcpConnect.java @@ -0,0 +1,143 @@ +package com.hdl.sdk.link.core.connect; + +import com.google.gson.JsonObject; +import com.hdl.sdk.link.common.config.TopicConstant; +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.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.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; + +/** + * 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, true).send(); + } + }); + } + return tcpSocketBoot; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java new file mode 100644 index 0000000..cff6a99 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLUdpConnect.java @@ -0,0 +1,619 @@ +package com.hdl.sdk.link.core.connect; + +import android.content.Context; +import android.content.Intent; +import android.net.wifi.WifiManager; +import android.text.TextUtils; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.HDLLinkLocalSdk; +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.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.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static com.hdl.sdk.link.common.config.TopicConstant.DEIVCE_AUTH_REQUEST; + +/** + * Created by jlchen on 11/11/21. + * + * @Description : HDLAuthSocket 鐢变簬鍓嶆湡宸茬粡鍛藉悕濂斤紝涓嶅仛鏇存敼锛屽彲鐢ㄤ綔Udp鏈嶅姟绔娇鐢� + */ +public class HDLUdpConnect { + private static final String TAG = "HDLAuth"; + /** + * udp榛樿绔彛 + */ + public static final int UDP_PORT = 8585; + /** + * 鍥犱负鑰冭檻鍒颁娇鐢ㄤ竴涓鍙o紝瑕佹敮鎸佹帴鏀跺缃戝叧鐨勬暟鎹紝鎵�浠ュ彧鍏佽浣跨敤涓�涓� + */ + private static UdpSocketBoot udpSocketBoot; + // private EventListener authEvent; + //鎼滅储缃戝叧 + private EventListener searchGatewayEvent; + /** + * udp榛樿缁勬挱ip + */ + private static final String UDP_GROUP_IP = "239.0.168.188"; + + private static boolean bindSuccess; + + public static boolean isBindSuccess() { + return bindSuccess; + } + + /** + * instance + */ + private volatile static HDLUdpConnect instance; + + private HDLUdpConnect() { + initListenerGatewayEvent(); + initSearchGatewayEvent(); + } + + /** + * getInstance + * + * @return HDLAuthSocket + */ + public static synchronized HDLUdpConnect getInstance() { + if (instance == null) { + synchronized (HDLLinkConfig.class) { + if (instance == null) { + instance = new HDLUdpConnect(); + } + } + } + return instance; + } + + private UdpSocketOptions getUdpOptions() { + final UdpSocketOptions options = new UdpSocketOptions(); + WifiManager manager = (WifiManager) HDLLinkLocalSdk.getInstance().getContext().getApplicationContext() + .getSystemService(Context.WIFI_SERVICE); + options.setWifiManager(manager); + final MessagePipeLine pipeLine = new MessagePipeLine(); + pipeLine.add(new LinkMessageDecoder()); + pipeLine.add(new LinkMessageEncoder()); + options.setHandleMessage(pipeLine); + return options; + } + + + /** + * 鑾峰彇褰撳墠udp瀵硅薄锛屽鏋滀笉瀛樺湪灏卞垱寤� + * + * @return 杩斿洖褰撳墠瀵硅薄 + */ + public synchronized UdpSocketBoot getUdpBoot() { + if (null == initUdp()) { + return null; + } + return udpSocketBoot; + } + + + /** + * 鍒濆鍖杣dp 鐩戝惉鍔熻兘 + * + * @return 杩斿洖褰撳墠瀵硅薄 + */ + public synchronized UdpSocketBoot initUdp() { + try { + if (udpSocketBoot == null) { + udpSocketBoot = UdpClient.init("0.0.0.0",UDP_PORT, getUdpOptions()); + udpSocketBoot.bind(); + bindSuccess=true; + } + } catch (Exception e) { + LogUtils.e("鍒濆鍖栫綉鍏冲け璐�:"+e.getMessage()); + return null; + } + + return udpSocketBoot; + } + + + /** + * 寮�濮嬬洃鍚拰鍙戣捣鍏ョ綉鍙婅璇佽姹� + * + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void startAuthenticateRequest(AuthenticateRequest request, HDLLinkCallBack callBack) { + HDLLinkConfig.getInstance().clearConfig(); + //1.鍚姩Socket 寮�鍚洃鍚� + getUdpBoot(); + //2.鏋勫缓鐩戝惉Listener +// authEvent = + //3.鐩戝惉缃戝叧骞挎挱鐨勫叆缃戞寚浠� + EventDispatcher.getInstance().register(TopicConstant.GATEWAY_AUTH_BROADCAST, new EventListener() { + @Override + public void onMessage(Object msg) { + NetworkAccessBroadcastResponse bean = getNetworkAccessBroadcastResponse(msg); + if (bean != null) { + 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"); + } + }); + } + + /** + * 缁撴潫鐩戝惉鍏ョ綉鍙婅璇佸箍鎾� + */ + public void endAuthenticateRequest() { + //绉婚櫎鐩戝惉 + EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); + } + + /** + * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 + * + * @param ip 缃戝叧IP + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void sendAuthenticateRequest(String ip, AuthenticateRequest request, HDLLinkCallBack callBack) { + if (request == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_NULL_ERROR)); + } + String topic = DEIVCE_AUTH_REQUEST; + Gson gs = new Gson(); + String requestStr = gs.toJson(request); + LinkRequest linkRequest = new LinkRequest(topic, requestStr, false); +// linkRequest.setReplyTopic(requestStr + "_reply"); + new HDLConnectHelper(ip, linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + try { + AuthenticateResponse bean = getAuthenticateResponseBean(msg); + if (bean != null) { + if (bean.getCode().equals("200")) { + String localSecret = ""; + String gatewayId = ""; + String ipAddress = ""; + if (bean.getAuth() != null) { + localSecret = bean.getAuth().getLocalSecret(); + } + if (bean.getObjects() != null) { + gatewayId = bean.getObjects().getGatewayID(); + ipAddress = bean.getObjects().getIPAddress(); + } + //鍒ゆ柇缃戝叧鏄惁宸茬粡娉ㄥ唽鍒颁簯绔� + if (TextUtils.isEmpty(localSecret) || TextUtils.isEmpty(gatewayId)) { + //璁よ瘉澶辫触锛岀綉鍏虫湭娉ㄥ唽鍒颁簯绔� + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED)); + } else { + HDLLinkConfig.getInstance().saveConfig(localSecret, gatewayId, ipAddress); + callBack.onSuccess("璁よ瘉鎴愬姛"); + } + } else if (bean.getCode().equals("14013")) { + //璁よ瘉澶辫触锛岃MAC瀵瑰簲鐨勮澶囧瘑閽ヤ笉瀛樺湪 + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_MAC_KEY_ERROR)); + } else { + //璁よ瘉澶辫触锛岄敊璇爜锛� + LogUtils.e("璁よ瘉澶辫触锛岄敊璇爜锛�" + bean.getCode()); + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR)); + } + } else { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR)); + } + } catch (Exception e) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR)); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + LogUtils.i(TAG, "onFailure: "); + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, false).send(); + } + +// /** +// * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 +// * +// * @param callBack 缁撴灉鍥炶皟 +// */ +// public void sendAuthenticateRequest(CallBack callBack) { +// String macStr = "AA000000000000BB"; +// String secret = "87ae414b7a853f65"; +// String mac_key = stringToMD5(stringToMD5(macStr + secret)); +// +// String versionString = "HDL_V1.0.1"; +// String time = String.valueOf(System.currentTimeMillis()); +// +// //1.璁剧疆璁よ瘉淇℃伅 +// AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean(); +// requestBean.setMAC(macStr); +// requestBean.setSupplier("HDL"); +// requestBean.setFirmwareVersion(versionString); +// requestBean.setHardwareModel("1956F"); +// AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean(); +// authbean.setSpk("ir.module"); +// authbean.setMACKey(mac_key); +// authbean.setRequest(requestBean); +// +// +// //2.璁剧疆璁惧淇℃伅 +// AuthenticateDeviceInfoBean infoBean = new AuthenticateDeviceInfoBean(); +// infoBean.setDeviceMAC(macStr); +// infoBean.setIPMAC(macStr); +// infoBean.setDeviceName("HDL闈㈡澘"); +// infoBean.setAccessMode("HDL"); +// infoBean.setOID(getOid()); +// infoBean.setSid(getSid()); +//// infoBean.set +// AuthenticateRequest.VersionBean[] versionBeans = new AuthenticateRequest.VersionBean[]{new AuthenticateRequest.VersionBean("FW", versionString), new AuthenticateRequest.VersionBean("HW", "1956F")}; +// infoBean.setVersions(versionBeans); +// AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, infoBean, authbean); +// +// String ip = IpUtils.getBroadcastAddress(); +// ip = "192.168.10.102"; +// sendAuthenticateRequest(ip, request, callBack); +// } + + public interface SearchGatewayCallBack extends BaseCallBack { + /** + * 鎼滅储缃戝叧鎴愬姛 + * + * @param gatewaySearchBean + */ + void onSuccess(GatewaySearchBean gatewaySearchBean); + } + + + /** + * 鏆傚仠鎼滅储缃戝叧 + */ + public void endSearchAllGateway() { + + } + + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayMulticast(SearchGatewayCallBack callBack) { + searchGateway(HDLLinkConfig.getInstance().getGatewayId(), UDP_GROUP_IP, UDP_PORT, callBack); + } + + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayBroadcast(SearchGatewayCallBack callBack) { + if (!HDLLinkConfig.getInstance().checkIfCertified()) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); + } + return; + } + String ip = IpUtils.getBroadcastAddress(); + searchGateway(HDLLinkConfig.getInstance().getGatewayId(), ip, UDP_PORT, callBack); + } + + /** + * 閫氱敤鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr 鍥炲鐨勪富棰� + * @param broadcast 鏄惁瑕佸箍鎾� + * @param 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)); + } + return; + } + + if (!HDLLinkConfig.getInstance().checkIfCertified()) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_UNAUTHORIZED_ERROR)); + } + return; + } + + LinkRequest message = new LinkRequest(topic, bodyStr, false); + String ip = HDLLinkConfig.getInstance().getIpAddress(); + if (broadcast) { + ip = IpUtils.getBroadcastAddress(); + } + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess((LinkResponse) msg); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + , false).send(); + } + + /** + * 閫氱敤鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr 鍥炲鐨勪富棰� + * @param broadcast 鏄惁骞挎挱 + */ + public void udpSendMsg(String topic, String bodyStr, boolean broadcast) { + if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) { + LogUtils.e("udpSendMsg", "鍙傛暟涓嶈兘涓虹┖"); + return; + } + if (!HDLLinkConfig.getInstance().checkIfCertified()) { + LogUtils.e("udpSendMsg", "鏈璇侊紝璇峰厛璁よ瘉"); + return; + } + LinkRequest message = new LinkRequest(topic, bodyStr, HDLLinkConfig.getInstance().isLocalEncrypt()); + String ip = HDLLinkConfig.getInstance().getIpAddress(); + if (broadcast) { + ip = IpUtils.getBroadcastAddress(); + } + new HDLConnectHelper(ip, message, false).send(); + } + + private GatewaySearchBean getGatewaySearchBean(Object msg) { + GatewaySearchBean searchBean = null; + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + final BaseLocalResponse<GatewaySearchBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() { + }.getType()); + searchBean = response.getObjects(); + } + } + return searchBean; + } + + private AuthenticateResponse getAuthenticateResponseBean(Object msg) { + AuthenticateResponse mBean = null; + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + AuthenticateResponse response = GsonConvert.getGson().fromJson(data, new TypeToken<AuthenticateResponse>() { + }.getType()); + mBean = response; + } + + } + return mBean; + } + + private NetworkAccessBroadcastResponse getNetworkAccessBroadcastResponse(Object msg) { + NetworkAccessBroadcastResponse mBean = null; + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + NetworkAccessBroadcastResponse response = GsonConvert.getGson().fromJson(data, new TypeToken<NetworkAccessBroadcastResponse>() { + }.getType()); + mBean = response; + } + + } + return mBean; + } + + /** + * 缃戝叧鎼滅储鐩稿叧 + */ + private static final int MAX_SEARCH_COUNT = 10;//鎬诲叡鎼滅储娴嬭瘯 + private final AtomicInteger searchGatewayCount = new AtomicInteger(0); + ; + private final AtomicBoolean isSearchGatewaySuccess = new AtomicBoolean(true); + private String searchGatewayId = ""; + private SearchGatewayCallBack mSearchGatewayCallBack; + + private void initSearchGatewayEvent() { + LogUtils.i("鎼滅储缃戝叧", "initSearchGatewayEvent"); + searchGatewayEvent = new EventListener() { + @Override + public void onMessage(Object msg) { + try { + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); + if (!TextUtils.isEmpty(data)) { + final BaseLocalResponse<GatewaySearchBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() { + }.getType()); + GatewaySearchBean searchBean = response.getObjects(); + if (searchBean != null && !TextUtils.isEmpty(searchBean.getGatewayId())) { + if (searchBean.getGatewayId().contains(searchGatewayId)) { + removeSearchGatewayEvent();//绉婚櫎鎼滅储缃戝叧鐩戝惉 + isSearchGatewaySuccess.set(true);//鎼滅储鎴愬姛鏍囪 + searchGatewayCount.set(11);//娆℃暟鏍囪 + HDLLinkConfig.getInstance().setLocalEncrypt(searchBean.isLocalEncrypt());//璁剧疆鏄惁鍔犲瘑 + if (mSearchGatewayCallBack != null) { + mSearchGatewayCallBack.onSuccess(searchBean); + } + } + } + } + } + } catch (Exception e) { + + } + } + }; + } + + private void initListenerGatewayEvent() { + LogUtils.i("鍒濆鍖栨案涔呯洃鍚綉鍏冲箍鎾簨浠讹紝涓嶇敤绉婚櫎姝や簨浠�"); + EventListener gatewayEvent = new EventListener() { + @Override + public void onMessage(Object msg) { + try { + if (msg instanceof LinkResponse) { + LinkResponse linkResponse = (LinkResponse) msg; + String data = linkResponse.getData(); +// LogUtils.i("鎺ユ敹鍒扮綉鍏充俊鎭細" + data); + if (!TextUtils.isEmpty(data)) { + final BaseLocalResponse<GatewayBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewayBean>>() { + }.getType()); + GatewayBean gateway = response.getObjects(); + if (gateway != null) { + if (!TextUtils.isEmpty(HDLLinkConfig.getInstance().getGatewayId()) + && !TextUtils.isEmpty(HDLLinkConfig.getInstance().getHomeId())) { + //涓荤綉鍏冲苟涓旀槸褰撳墠缁戝畾鐨勭綉鍏� + if ("true".equals(gateway.getMaster().toLowerCase())) { + if (gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId()) + || gateway.getDevice_mac().equals(HDLLinkConfig.getInstance().getGatewayId()) + || gateway.getOid().equals(HDLLinkConfig.getInstance().getGatewayId()) + || gateway.getHomeId().equals(HDLLinkConfig.getInstance().getHomeId())) { + HDLLinkConfig.getInstance().setLocalEncrypt(gateway.getIsLocalEncrypt());//璁剧疆鏄惁鍔犲瘑 + HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address()); + //鏇存柊褰撳墠缃戝叧鐨勪俊鎭� + HDLLinkConfig.getInstance().reSaveConfig(); + } + } + } + + if(TextUtils.isEmpty(gateway.getHomeId())||gateway.getHomeId().equals(HDLLinkConfig.getInstance().getHomeId())) { + HDLTcpConnect.initTcp(gateway.getIp_address());//鍒濆鍖朤CP杩炴帴 + } + } + } + } + } catch (Exception e) { + + } + } + }; + EventDispatcher.getInstance().registerIo(TopicConstant.GATEWAY_SEARCH_REPLY, gatewayEvent); + } + + /** + * 鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param gatewayId 缃戝叧id + * @param ipAddress 鐩爣鐨処P鍦板潃 + * @param port 鐩爣鐨勭鍙� + * @param callBack 鍥炶皟 + */ + public void searchGateway(String gatewayId, 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(), false); + //娉ㄥ唽鎼滅储缃戝叧鐩戝惉 + 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() + "娆�"); + new HDLConnectHelper(ipAddress, message, false).send(); + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + if (!isSearchGatewaySuccess.get()) { + //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃� + callBackSearchGatewayTimeout(); + LogUtils.e("鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�"); + } + } + }).start(); + } + + + /** + * 娉ㄥ唽鎼滅储缃戝叧鐩戝惉 + */ + private void registerSearchGatewayEvent() { + LogUtils.i("娉ㄥ唽鎼滅储缃戝叧鐩戝惉"); + EventDispatcher.getInstance().registerIo(TopicConstant.GATEWAY_SEARCH_REPLY, searchGatewayEvent); + } + + /** + * 绉婚櫎鎼滅储缃戝叧鐩戝惉 + */ + private void removeSearchGatewayEvent() { + LogUtils.i("鎼滅储缃戝叧", "绉婚櫎鎼滅储缃戝叧鐩戝惉"); + EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_SEARCH_REPLY, searchGatewayEvent); + } + + /** + * 鍥炶皟鎼滅储缃戝叧瓒呮椂 + */ + 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)); + } + } + }); + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java new file mode 100644 index 0000000..cf10133 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLZigbeeConnect.java @@ -0,0 +1,358 @@ +package com.hdl.sdk.link.core.connect; + + +import android.text.TextUtils; + +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.LogUtils; +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.core.config.HDLLinkConfig; +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 final String TAG="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("/")[8]; + } 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; + } + } + EventDispatcher.getInstance().post(zigbeeTopic, zigbeeResponse); + //鍙戝竷Zigbee鍘熺敓涓婚鍙婃暟鎹� + EventDispatcher.getInstance().post(zigbeeAllTopic, zigbeeResponse); + } + } catch (Exception e) { + LogUtils.e(TAG,"LinkResponse杞琙igbeeResponse寮傚父:"+ e.getMessage()); + } + } + }; + // + //娉ㄥ唽鐩存帴閫氳鐨勪富棰橈紝鍖呮嫭鐩存帴鍜屼富缃戝叧閫氳鎴栬�呯洿鎺ュ拰浠庣綉鍏抽�氳 +// registerListener(String.format(TopicConstant.NATIVE_ZIGBEE_DOWN_REPLY, "+"), eventListener); + + //娉ㄥ唽鐩存帴閫氳鐨勪富棰橈紝鍖呮嫭鐩存帴鍜屼富缃戝叧閫氳鎴栬�呯洿鎺ュ拰浠庣綉鍏抽�氳 + registerListener(String.format(TopicConstant.NATIVE_ZIGBEE_UP, "+"), eventListener); + + //娉ㄥ唽閫氳繃涓荤綉鍏抽�忎紶浠庣綉鍏崇殑涓婚 +// registerListener(String.format(TopicConstant.NATIVE_ZIGBEE_DOWN_SLAVE_REPLY, "+", "+"), eventListener); + + registerListener(String.format(TopicConstant.NATIVE_ZIGBEE_UP_SLAVE, "+", "+"), 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; + } + + String tempTopic = String.format(TopicConstant.NATIVE_ZIGBEE_DOWN, gatewayOidOrGatewayId); + LinkRequest request = new LinkRequest(tempTopic, payload, gatewayBean.getIsLocalEncrypt()); + + if ("true".equals(gatewayBean.getMaster())) { + request.setCloudTopic(String.format(TopicConstant.NATIVE_ZIGBEE_DOWN, HDLLinkConfig.getInstance().getGatewayId())); + } else { + request.setCloudTopic(String.format(TopicConstant.NATIVE_ZIGBEE_DOWN_SLAVE, HDLLinkConfig.getInstance().getGatewayId(), gatewayOidOrGatewayId)); + } + request.setReplyTopic(responeTopic); +// final boolean[] isCallBack = {false}; +// //閫忎紶鍛戒护涓婚澶勭悊 +// final EventListener eventListener = new EventListener() { +// @Override +// public void onMessage(Object msg) { +// if (msg instanceof ZigbeeResponse) { +// ZigbeeResponse linkResponse = (ZigbeeResponse) msg; +// //TODO 濡傛灉閰嶇疆浠庣綉鍏崇殑淇℃伅锛岄�氳繃涓荤綉鍏宠浆杈撅紝杩欓噷oid瑕佸垽鏂笅 +// if (responeTopic.equals(linkResponse.getTopic())) { +// isCallBack[0] = true; +// removeListener(zigbeeAllTopic, this); +// if (null != zigbeeCallBack) { +// zigbeeCallBack.onSuccess(linkResponse.getData()); +// } +// } +// } +// } +// }; +// //娉ㄥ唽鐩戝惉 +// registerListener(zigbeeAllTopic, eventListener); + + long timeout = 8 * 1000; + /** + * 闇�瑕佺壒娈婂鐞嗕竴浜涗富棰� 闇�瑕佸欢闀胯秴鏃舵椂闂� + */ + if (responeTopic.equals("Bind/SetBind_Respon") || responeTopic.equals("Bind/ClearBindInfo_Respon")) { + timeout = 20 * 1000; + } +// //涓�瀹氭椂闂村悗杩樻病鏈夋帴鏀跺埌鏁版嵁锛屽氨鍥炶皟澶辫触 +// ScheduledExecutorService scheduledExecutorService = ThreadToolUtils.getInstance().newScheduledThreadPool(1); +// scheduledExecutorService.schedule(new Runnable() { +// @Override +// public void run() { +// removeListener(zigbeeAllTopic, eventListener); +// scheduledExecutorService.shutdownNow(); +// if (!isCallBack[0]) { +// if (null != zigbeeCallBack) { +// zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_Zigbee_FAILURE_ERROR)); +// } +// } +// } +// }, timeout, TimeUnit.SECONDS); + new HDLConnectHelper(timeout, 1, gatewayBean.getIp_address(), 8586, request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof String) { + if (null != zigbeeCallBack) { + zigbeeCallBack.onSuccess(msg+""); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (null != zigbeeCallBack) { + zigbeeCallBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } + + + + /** + * 鍙戦�佸師鐢熼�忎紶鍛戒护鏁版嵁 + * + * @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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java new file mode 100644 index 0000000..aa07c9d --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageDecoder.java @@ -0,0 +1,323 @@ +package com.hdl.sdk.link.core.protocol; + + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.utils.ByteUtils; +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.gateway.HDLLinkLocalGateway; +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 static final String TAG=LinkMessageDecoder.class.getName(); + //instance + private volatile static LinkMessageDecoder instance; + + //getInstance + public static synchronized LinkMessageDecoder getInstance() { + if (instance == null) { + synchronized (LinkMessageDecoder.class) { + if (instance == null) { + instance = new LinkMessageDecoder(); + } + } + } + return instance; + } + + /** + * 鎺ユ敹鏁版嵁缂撳啿鍖� + */ + 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.clear(); + 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()); + } catch (Exception e) { + LogUtils.e("鎺ユ敹鍒版暟鎹紓甯�:\r\n" + e.getMessage()); + byteBuffer.flip(); + byteBuffer.clear(); + } + 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)); + } + } catch (Exception ee) { + LogUtils.e("澶勭悊鎺ユ敹鐨勬暟鎹紓甯�:\r\n" + ee.getMessage()); + } + return null; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/protocol/LinkMessageEncoder.java new file mode 100644 index 0000000..d09e37a --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java new file mode 100644 index 0000000..942e76e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/AesUtil.java @@ -0,0 +1,150 @@ +package com.hdl.sdk.link.core.utils; + + +import android.text.TextUtils; + +import com.hdl.sdk.link.common.utils.LogUtils; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +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; + +/** + * Aes 鍔犺В瀵嗗伐鍏风被 + * + * @author yangtao + * 2020骞�10鏈�29鏃� + */ +public class AesUtil { + + private static final String CIPHER_INSTANCE = "AES/CBC/PKCS7Padding"; + private static final String AES_ALGORITHM = "AES"; + +// static { +// //AES/CBC/PKCS7Padding 渚濊禆 +// Security.addProvider(new BouncyCastleProvider()); +// } + + /** + * AES鍔犲瘑 + * + * @param key + * @return + * @throws Exception + */ + public static byte[] aesEncrypt(byte[] content, String key) { + return encrypt(content, key.getBytes(), CIPHER_INSTANCE, true, null); + } + + /** + * AES瑙e瘑 + * + * @param key + * @return + * @throws Exception + */ + public static byte[] aesDecrypt(byte[] content, String key) { + if (content == null || TextUtils.isEmpty(key)) { + LogUtils.i("鏁版嵁瑙e瘑锛�","content锛�"+content+" key:"+key); + return null; + } + return decrypt(content, key.getBytes(), CIPHER_INSTANCE, true, null); + } + + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param keyByte aesKye鐨刪exStr + * @param cipherInstance AES绠楁硶濉厖鏂瑰紡 + * @param isIv 鏄惁浣跨敤鍋忕Щ閲� ECB妯″紡涓嶅彲鐢� + * @param iv 鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + * @return + */ + public static byte[] encrypt(byte[] content, byte[] keyByte, String cipherInstance, Boolean isIv, byte[] iv) { + try { + //KEY杞崲 + Key key = new SecretKeySpec(keyByte, AES_ALGORITHM); + //鍔犲瘑 + Cipher cipher = Cipher.getInstance(cipherInstance); + if (isIv != null && isIv) { + //鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + if (iv == null) { + iv = keyByte; + } + IvParameterSpec ivps = new IvParameterSpec(iv); + cipher.init(Cipher.ENCRYPT_MODE, key, ivps); + } else { + cipher.init(Cipher.ENCRYPT_MODE, key); + } + byte[] result = cipher.doFinal(content); + 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; + } + + /** + * 瑙e瘑 + * + * @param contentByte 寰呰В瀵嗗緟瀛楃涓瞙exStr + * @param contentByte 瀵嗛挜 + * @param cipherInstance AES绠楁硶濉厖鏂瑰紡 + * @param isIv 鏄惁浣跨敤鍋忕Щ閲� ECB妯″紡涓嶅彲鐢� + * @param iv 鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + * @return + */ + public static byte[] decrypt(byte[] contentByte, byte[] keyByte, String cipherInstance, Boolean isIv, byte[] iv) { + try { + //KEY杞崲 + Key key = new SecretKeySpec(keyByte, AES_ALGORITHM); + //瑙e瘑 + Cipher cipher = Cipher.getInstance(cipherInstance); + if (isIv != null && isIv) { + //鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + if (iv == null) { + iv = keyByte; + } + IvParameterSpec ivps = new IvParameterSpec(iv); + cipher.init(Cipher.DECRYPT_MODE, key, ivps); + } else { + cipher.init(Cipher.DECRYPT_MODE, key); + } + byte[] result = cipher.doFinal(contentByte); + return result; + } catch (NoSuchAlgorithmException e) { + LogUtils.e(e.getMessage()); + } catch (InvalidKeyException e) { + LogUtils.e(e.getMessage()); + } catch (NoSuchPaddingException e) { + LogUtils.e(e.getMessage()); + } catch (BadPaddingException e) { + LogUtils.e(e.getMessage()); + } catch (IllegalBlockSizeException e) { + LogUtils.e(e.getMessage()); + } catch (InvalidAlgorithmParameterException e) { + LogUtils.e(e.getMessage()); + } + return null; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteBufferUtils.java new file mode 100644 index 0000000..99e1e5d --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ByteUtils.java new file mode 100644 index 0000000..a2e095e --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java new file mode 100644 index 0000000..b12a06e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/EncryptUtil.java @@ -0,0 +1,69 @@ +package com.hdl.sdk.link.core.utils; + +import android.text.TextUtils; + +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.utils.ByteUtils; + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.config.HDLLinkConfig; + +import java.io.UnsupportedEncodingException; + +/** + * Created by hxb on 2021/12/23. + */ +public class EncryptUtil { + /** + * 鑾峰彇鍔犲瘑鏁版嵁 + * + * @param linkRequest 璇锋眰鏁版嵁 + * @return + */ + public static byte[] getEncryBytes(LinkRequest linkRequest) throws UnsupportedEncodingException { + //鍒ゆ柇鏄惁闇�瑕佸姞瀵� + 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(); + } + } + + /** + * 鍔犲瘑鏁版嵁 + * + * param bytes 闇�瑕佸姞瀵嗘暟鎹� + * @param secret 鍔犲瘑瀵嗛挜 + * @return + */ + public static byte[] encryBytes(byte []bytes,String secret) { + if(bytes==null|| TextUtils.isEmpty(secret)){ + LogUtils.i("浼犲叆鏁版嵁鍐呭涓虹┖鎴栬�呭瘑閽ヤ负绌�"); + return null; + } + return AesUtil.aesEncrypt(bytes, secret); + } + + /** + * 鍒ゆ柇褰撳墠涓婚鏁版嵁鏄惁闇�瑕佸姞瀵� + * + * @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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/HexUtil.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/HexUtil.java new file mode 100644 index 0000000..41373e0 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/HexUtil.java @@ -0,0 +1,449 @@ +package com.hdl.sdk.link.core.utils; + +import android.util.Log; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; + +/** + * Created by Zoro + * Created on 2021/9/17 + * description: + */ +public class HexUtil { + private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + public static char[] encodeHex(byte[] data) { + return encodeHex(data, true); + } + + public static char[] encodeHex(byte[] data, boolean toLowerCase) { + return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + + protected static char[] encodeHex(byte[] data, char[] toDigits) { + if (data == null) + return null; + int l = data.length; + char[] out = new char[l << 1]; + for (int i = 0, j = 0; i < l; i++) { + out[j++] = toDigits[(0xF0 & data[i]) >>> 4]; + out[j++] = toDigits[0x0F & data[i]]; + } + return out; + } + + + public static String encodeHexStr(byte[] data) { + return encodeHexStr(data, true); + } + + public static String encodeHexStr(byte[] data, boolean toLowerCase) { + return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + + + protected static String encodeHexStr(byte[] data, char[] toDigits) { + return new String(encodeHex(data, toDigits)); + } + + public static String formatHexString(byte[] data) { + return formatHexString(data, false); + } + + public static String formatHexString(byte[] data, boolean addSpace) { + if (data == null || data.length < 1) + return null; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < data.length; i++) { + String hex = Integer.toHexString(data[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sb.append(hex); + if (addSpace) + sb.append(" "); + } + return sb.toString().trim(); + } + + public static byte[] decodeHex(char[] data) { + + int len = data.length; + + if ((len & 0x01) != 0) { + throw new RuntimeException("Odd number of characters."); + } + + byte[] out = new byte[len >> 1]; + + // two characters form the hex value. + for (int i = 0, j = 0; j < len; i++) { + int f = toDigit(data[j], j) << 4; + j++; + f = f | toDigit(data[j], j); + j++; + out[i] = (byte) (f & 0xFF); + } + + return out; + } + + /** + * 灏嗗崄鍏繘鍒跺瓧绗︿覆瑙g爜涓篵yte[] + * + * @param hexStr 鍗佸叚杩涘埗String + * @return byte[] + */ + public static byte[] decodeHex(String hexStr) { + if ("".equals(hexStr)) { + return null; + } + hexStr = hexStr.replace(" ",""); + return decodeHex(hexStr.toCharArray()); + } + + public static byte[] addAll(byte[]... arrays) { + if (arrays.length == 1) { + return arrays[0]; + } + + // 璁$畻鎬婚暱搴� + int length = 0; + for (byte[] array : arrays) { + if (null != array) { + length += array.length; + } + } + + final byte[] result = new byte[length]; + length = 0; + for (byte[] array : arrays) { + if (null != array) { + System.arraycopy(array, 0, result, length, array.length); + length += array.length; + } + } + return result; + } + + + + protected static int toDigit(char ch, int index) { + int digit = Character.digit(ch, 16); + if (digit == -1) { + throw new RuntimeException("Illegal hexadecimal character " + ch + + " at index " + index); + } + return digit; + } + + + public static byte[] hexStringToBytes(String hexString) { + if (hexString == null || hexString.equals("")) { + return null; + } + hexString = hexString.toUpperCase(); + int length = hexString.length() / 2; + char[] hexChars = hexString.toCharArray(); + byte[] d = new byte[length]; + for (int i = 0; i < length; i++) { + int pos = i * 2; + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + } + return d; + } + + public static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + + public static String extractData(byte[] data, int position) { + return HexUtil.formatHexString(new byte[]{data[position]}); + } + + public static String bytesToHexString(byte[] data) { + String result = ""; + for (int i = 0; i < data.length; i++) { + String hexString = Integer.toHexString(data[i] & 0xFF); + if (hexString.length() == 1) { + hexString = '0' + hexString; + } + result += hexString.toUpperCase(); + } + return result; + } + + /** + * byte杞�16杩涘埗 + * + * @param b + * @return + */ + public static String binaryToHex(byte b) { + String str = byteToBit(b); + String hexStr = Integer.toHexString(Integer.parseInt(str, 2)); + StringBuffer stringBuffer = new StringBuffer(); + if (hexStr.length() == 1) { + stringBuffer.append("0"); + } + stringBuffer.append(hexStr); + return stringBuffer.toString().toUpperCase(); + } + + /** + * byte杞崄杩涘埗 + * + * @param b + * @return + */ + public static int binaryToDecimal(byte b) { + String str = byteToBit(b); + return Integer.parseInt(str, 2); + } + + /** + * Byte杞珺it + */ + public static String byteToBit(byte b) { + return "" + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) + + (byte) ((b >> 5) & 0x1) + (byte) ((b >> 4) & 0x1) + + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1) + + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); + } + + /** + * int杞琤yte + * + * @param res + * @return + */ + public static byte[] int2byte(int res) { + byte[] targets = new byte[2]; + + targets[1] = (byte) (res & 0xff);// 鏈�浣庝綅 + targets[0] = (byte) ((res >> 8) & 0xff);// 娆′綆浣� + /*targets[2] = (byte) ((res >> 16) & 0xff);// 娆¢珮浣� + targets[3] = (byte) (res >>> 24);// 鏈�楂樹綅,鏃犵鍙峰彸绉�*/ + return targets; + } + + /** + * Bit杞珺yte + */ + public static byte bitToByte(String byteStr) { + int re, len; + if (null == byteStr) { + return 0; + } + len = byteStr.length(); + if (len != 4 && len != 8) { + return 0; + } + if (len == 8) {// 8 bit澶勭悊 + if (byteStr.charAt(0) == '0') {// 姝f暟 + re = Integer.parseInt(byteStr, 2); + } else {// 璐熸暟 + re = Integer.parseInt(byteStr, 2) - 256; + } + } else {// 4 bit澶勭悊 + re = Integer.parseInt(byteStr, 2); + } + return (byte) re; + } + + /** + * 瑙f瀽浣撹剛鏁版嵁 + * + * @param first + * @param second + * @param b + * @return + */ + public static double getData(int first, int second, byte[] b) { + double data = ((b[first] & 0xFF) << 8) + (b[second] & 0xFF); + Log.e("", "data = " + data); + return data / 10; + } + + /** + * 瑙f瀽浣撹剛鏁版嵁 + * + * @param first + * @param second + * @param b + * @return + */ + public static int getDataInt(int first, int second, byte[] b) { + int data = ((b[first] & 0xFF) << 8) + (b[second] & 0xFF); + Log.e("", "getDataInt = " + data); + return data; + } + + + // 鑾峰彇绯荤粺鏃堕棿 + public static String getTime() { + SimpleDateFormat formatter = new SimpleDateFormat("HHmmss"); + Date curDate = new Date(System.currentTimeMillis()); + String str = formatter.format(curDate); + return str; + } + + // 鑾峰彇绯荤粺鏃ユ湡 + public static String getDate() { + SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd"); + Date curDate = new Date(System.currentTimeMillis()); + String str = formatter.format(curDate); + return str; + } + + /** + * 鑾峰彇褰撳墠绯荤粺鏃堕棿 + * + * @return + */ + public static String getCurrentTime() { + SimpleDateFormat formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); + Date curDate = new Date(System.currentTimeMillis()); + String str = formatter.format(curDate); + return str; + } + + /** + * 鍚堝苟鏁扮粍 + * + * @return + */ + public static byte[] concat(byte[] b, byte[] mByte) { + byte[] result = Arrays.copyOf(b, b.length + mByte.length); + System.arraycopy(mByte, 0, result, b.length, mByte.length); + return result; + } + + /** + * 瀛楃涓查暱搴︾瓑浜�1鐨勮瘽锛岃ˉ0 + * + * @param str + * @return + */ + public static String addZero(String str) { + //L.i(ParseData.class, "addZero"); + StringBuffer sBuffer = new StringBuffer(); + if (str.length() == 1) { + sBuffer.append("0"); + sBuffer.append(str); + return sBuffer.toString(); + } else { + return str; + } + } + + public static double getPercent(double d) { + if (d > 100) { + return 0.0; + } + return d; + } + + /** + * byte鏁扮粍杞瑂tr + * + * @param b + * @return + */ + public static String byteArr2Str(byte[] b) { + if (b.length != 0) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("["); + for (int i = 0; i < b.length; i++) { + stringBuffer.append(addZero(binaryToHex(b[i]))); + if (i < b.length - 1) { + stringBuffer.append(","); + } + } + stringBuffer.append("]"); + return stringBuffer.toString(); + } + return null; + } + + /** + * 淇濈暀灏忔暟鐐瑰悗count浣� + * + * @param d + * @param count + * @return + */ + public static double keepDecimal(double d, int count) { + BigDecimal decimal = new BigDecimal(d); + return decimal.setScale(count, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * kg杞琹b + * + * @param weight + * @return + */ + public static double kg2lb(double weight) { + return keepDecimal(weight * 2.2046226, 1); + } + + /** + * kg杞琷in + * + * @param weight + * @return + */ + public static double kg2jin(double weight) { + return keepDecimal(weight * 2, 1); + } + + /** + * kg杞瑂t + * + * @param weight + * @return + */ + public static String kg2st(double weight) { + double lbData = kg2lb(weight); + StringBuffer stringBuffer = new StringBuffer(); + int lb = (int) (lbData / 14); + int st = (int) lbData % 14; + stringBuffer.append(lb); + stringBuffer.append(":"); + stringBuffer.append(addZero(String.valueOf(st))); + return stringBuffer.toString(); + } + + public static String int2HexStr(int i) { + return binaryToHex(Integer.valueOf(i).byteValue()); + } + + public static byte[] hexStringToByte(String hex) { + int len = (hex.length() / 2); + byte[] result = new byte[len]; + char[] chars = hex.toCharArray(); + for (int i = 0; i < len; i++) { + int pos = i * 2; + result[i] = (byte) (toByte(chars[pos]) << 4 | toByte(chars[pos + 1])); + } + return result; + } + + private static byte toByte(char c) { + byte b = (byte) "0123456789ABCDEF".indexOf(c); + return b; + } + + public static String formatTo1(double f) { + BigDecimal bg = new BigDecimal(f); + return bg.setScale(1, BigDecimal.ROUND_HALF_UP).toString(); + } +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LanguageUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LanguageUtils.java new file mode 100644 index 0000000..70ba132 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LanguageUtils.java @@ -0,0 +1,8 @@ +package com.hdl.sdk.link.core.utils; + +/** + * Created by hxb on 2023/2/9. + */ +public class LanguageUtils { +// public static String +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java new file mode 100644 index 0000000..57ca709 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java @@ -0,0 +1,73 @@ +package com.hdl.sdk.link.core.utils; + +import android.text.TextUtils; + +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.common.utils.LogUtils; +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.bean.response.BaseLocalWithCodeResponse; + +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; + } + + /** + * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects 鍙湁杩斿洖code 鍒ゆ柇200鏄垚鍔� + * + * @param msg + * @return + */ + public static <T> T convertLinkWithCodeResponse(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 BaseLocalWithCodeResponse<T> response = GsonConvert.getGson().fromJson(data, type); + if (response != null) { + bean = response.getCode(); + } + } catch (Exception e) { + LogUtils.e("convertLinkResponse catch:" + e.getMessage()); + } + } + } + return bean; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java new file mode 100644 index 0000000..92a611b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java @@ -0,0 +1,74 @@ +package com.hdl.sdk.link.core.utils; + +import android.text.TextUtils; + +/** + * Created by Tong on 2021/9/22. + * 瑙f瀽Link鍗忚 + */ +public class ProtocolParse { + + private String topic; + private int length; + private int dataIndex; + + public ProtocolParse(byte[] bytes) { + parse(bytes); + } + + private void parse(byte[] bytes) { + try { + String[] split = new String(bytes, "utf-8").split("\r\n"); + setTopic(parseTopic(split)); + setLength(parseLength(split)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static String parseTopic(String[] bytes) { + try { + for (String s : bytes) { + if (s.startsWith("Topic:")) { + return s.replace("Topic:", ""); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static int parseLength(String[] bytes) { + try { + for (String s : bytes) { + if (!TextUtils.isEmpty(s) && s.startsWith("Length:")) { + return Integer.parseInt(s.replace("Length:", "")); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return -1; + } + + + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java new file mode 100644 index 0000000..2dda1ee --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java @@ -0,0 +1,134 @@ +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.core.bean.LinkPacket; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +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()); +// GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByIpAddress(linkPacket.isIpAddress()); +// boolean isEncrypt = false; +// if (gatewayBean != null) { +// isEncrypt = gatewayBean.getIsLocalEncrypt(); +// } +// if (EncryptUtil.ifNeedEncrypt(response.getTopic(), isEncrypt)) { +// if (gatewayBean != null && gatewayBean.getIsLocalEncrypt() && encrypt(linkPacket.getBody())) { + if (!linkPacket.isCloudPacket() && 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")); + } + if (HDLConnectHelper.isLocal()) { + 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/AesUtil.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/AesUtil.java new file mode 100644 index 0000000..01fbe3f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/AesUtil.java @@ -0,0 +1,286 @@ +package com.hdl.sdk.link.core.utils.mqtt; + + + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.core.utils.HexUtil; + +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.Security; + +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; + + +/** + * Aes 鍔犺В瀵嗗伐鍏风被 + * + * @author yangtao + * 2020骞�10鏈�29鏃� + */ +public class AesUtil { + + private static final String CIPHER_INSTANCE = "AES/ECB/PKCS5Padding"; + private static final String AES_ALGORITHM = "AES"; + + static { + //AES/CBC/PKCS7Padding 渚濊禆 + Security.addProvider(new BouncyCastleProvider()); + } + + /** + * AES鍔犲瘑 + * + * @param key + * @return + * @throws Exception + */ + public static byte[] aesEncrypt(byte[] content, String key) { + return encrypt(content, key.getBytes(), "AES/CBC/PKCS7Padding", true, null); + } + + /** + * AES瑙e瘑 + * + * @param key + * @return + * @throws Exception + */ + public static byte[] aesDecrypt(byte[] content, String key) { + return decrypt(content, key.getBytes(), "AES/CBC/PKCS7Padding", true, null); + } + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param keyHex aesKye鐨刪exStr + * @return + */ + public static String encrypt(String content, String keyHex) { + return HexUtil.encodeHexStr(encrypt(content.getBytes(), HexUtil.decodeHex(keyHex), CIPHER_INSTANCE, false, null)); + } + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param key 瀵嗛挜 + * @return + */ + public static String encrypt(String content, byte[] key) { + return HexUtil.encodeHexStr(encrypt(content.getBytes(), key, CIPHER_INSTANCE, false, null)); + } + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param keyHex aesKye鐨刪exStr + * @return + */ + public static byte[] encryptReturnByte(String content, String keyHex) { + return encrypt(content.getBytes(), HexUtil.decodeHex(keyHex), CIPHER_INSTANCE, false, null); + } + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param key 瀵嗛挜 + * @return + */ + public static byte[] encryptReturnByte(String content, byte[] key) { + return encrypt(content.getBytes(), key, CIPHER_INSTANCE, false, null); + } + + /** + * 鍔犲瘑 + * + * @param content 寰呭姞瀵嗗瓧绗︿覆 + * @param keyByte aesKye鐨刪exStr + * @param cipherInstance AES绠楁硶濉厖鏂瑰紡 + * @param isIv 鏄惁浣跨敤鍋忕Щ閲� ECB妯″紡涓嶅彲鐢� + * @param iv 鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + * @return + */ + public static byte[] encrypt(byte[] content, byte[] keyByte, String cipherInstance, Boolean isIv, byte[] iv) { + try { + //KEY杞崲 + Key key = new SecretKeySpec(keyByte, AES_ALGORITHM); + //鍔犲瘑 + Cipher cipher = Cipher.getInstance(cipherInstance); + if (isIv != null && isIv) { + //鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + if (iv == null) { + iv = keyByte; + } + IvParameterSpec ivps = new IvParameterSpec(iv); + cipher.init(Cipher.ENCRYPT_MODE, key, ivps); + } else { + cipher.init(Cipher.ENCRYPT_MODE, key); + } + byte[] result = cipher.doFinal(content); + 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; + } + + /** + * 瑙e瘑 + * + * @param contentHex 寰呰В瀵嗗緟瀛楃涓瞙exStr + * @param keyHex desKye鐨刪exStr + * @return + */ + public static String decrypt(String contentHex, String keyHex) { + return new String(decrypt(HexUtil.decodeHex(contentHex), HexUtil.decodeHex(keyHex), CIPHER_INSTANCE, false, null)); + } + + /** + * 瑙e瘑 + * + * @param contentHex 寰呰В瀵嗗緟瀛楃涓瞙exStr + * @param key 瀵嗛挜 + * @return + */ + public static String decrypt(String contentHex, byte[] key) { + return new String(decrypt(HexUtil.decodeHex(contentHex), key, CIPHER_INSTANCE, false, null)); + } + + /** + * 瑙e瘑 + * + * @param content 寰呰В瀵嗗緟鍐呭 + * @param keyHex 瀵嗛挜 + * @return + */ + public static String decrypt(byte[] content, String keyHex) { + return new String(decrypt(content, HexUtil.decodeHex(keyHex), CIPHER_INSTANCE, false, null)); + } + + /** + * 瑙e瘑 + * + * @param content 寰呰В瀵嗗緟鍐呭 + * @param key 瀵嗛挜 + * @return + */ + public static String decrypt(byte[] content, byte[] key) { + return new String(decrypt(content, key, CIPHER_INSTANCE, false, null)); + } + + + /** + * 瑙e瘑 + * + * @param contentByte 寰呰В瀵嗗緟瀛楃涓瞙exStr + * @param contentByte 瀵嗛挜 + * @param cipherInstance AES绠楁硶濉厖鏂瑰紡 + * @param isIv 鏄惁浣跨敤鍋忕Щ閲� ECB妯″紡涓嶅彲鐢� + * @param iv 鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + * @return + */ + public static byte[] decrypt(byte[] contentByte, byte[] keyByte, String cipherInstance, Boolean isIv, byte[] iv) { + try { + //KEY杞崲 + Key key = new SecretKeySpec(keyByte, AES_ALGORITHM); + //瑙e瘑 + Cipher cipher = Cipher.getInstance(cipherInstance); + if (isIv != null && isIv) { + //鍋忕Щ閲� 涓嶄紶榛樿瀵嗛挜 + if (iv == null) { + iv = keyByte; + } + IvParameterSpec ivps = new IvParameterSpec(iv); + cipher.init(Cipher.DECRYPT_MODE, key, ivps); + } else { + cipher.init(Cipher.DECRYPT_MODE, key); + } + 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; + } + + + public static void main(String[] args) { +// jiemi(); + //jiami(); + } + + public static void jiami() { + String key = "1f6714fc-fb9b-4a"; + String content = "{\"id\":\"123\",\"objects\":[{\"sid\":\"0001011565879801020200010101\",\"type\":\"PWD\",\"local_id\":\"2\"}],\"time_stamp\":\"1603281282000\"}"; + byte[] res = aesEncrypt(content.getBytes(), key); + System.out.println(HexUtil.encodeHexStr(res)); + } + + /** + * + * @param str + * @param houseId + * @return + */ + public static String jiemi(byte[] str, String houseId) { + byte[] rs = aesDecrypt(str, HouseIdSecretUtil.getSecret(houseId)); + String content = new String(rs); + return content; + } + +// public static void main(String[] args) { +// try { +// //绗竴姝ワ細 鐢熸垚KEY +// //KeyGenerator keyGenerator = KeyGenerator.getInstance(AES_ALGORITHM); +// //keyGenerator.init(256); +// //绗簩姝ワ細 浜х敓瀵嗛挜 +// //SecretKey secretKey = keyGenerator.generateKey(); +// //绗笁姝ワ細 鑾峰彇瀵嗛挜 +// //byte[] keyBytes = secretKey.getEncoded(); +// //System.out.println(byteArrayToHexStr(keyBytes)); +// String src = "aaaaaaaaaVVVVaaaAAAA鏃�"; +// String pwd = "41151AF257BFDB7859EEC62FB341EE95EE42E648FE24E1F8CE8DADE287CC1E5C"; +// String mw = encrypt(src,pwd); +// System.out.println("mw:"+mw); +// String jm = decrypt(mw,pwd); +// System.out.println("jm:"+jm); +// +// }catch (Exception e){ +// +// } +// +// } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/HouseIdSecretUtil.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/HouseIdSecretUtil.java new file mode 100644 index 0000000..bc2a93b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/HouseIdSecretUtil.java @@ -0,0 +1,30 @@ +package com.hdl.sdk.link.core.utils.mqtt; + +/** + * 浣忓畢瀵嗛挜鑾峰彇宸ュ叿绫� + * + * @author yangtao + * @date 2021.2.26 + */ +public class HouseIdSecretUtil { + + public static String getSecret(String homeId) { + String temp = new StringBuffer().append(homeId).reverse().toString(); + if (temp.length() > 16) { + return temp.substring(0, 16); + } + //闀垮害涓嶅16浣嶇敤0琛ラ綈 + for (int i = temp.length(); i < 16; i++) { + temp += "0"; + } + return temp; + } + + public static String getSecret(Long homeId) { + return getSecret(homeId.toString()); + } + + public static void main(String[] args) { + System.out.println(getSecret("1363358800782790658")); + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java new file mode 100644 index 0000000..6e8ef74 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java @@ -0,0 +1,412 @@ +package com.hdl.sdk.link.core.utils.mqtt; + +import android.content.Context; +import android.text.TextUtils; + +import com.alibaba.fastjson.JSON; + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.core.bean.LinkPacket; +import com.hdl.sdk.link.core.bean.eventbus.EventBindMiniRemoteSuccessInfo; +import com.hdl.sdk.link.core.bean.eventbus.EventNotifyRefreshGatewayAesKeyInfo; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; +import com.hdl.sdk.link.core.protocol.LinkMessageDecoder; +import com.hdl.sdk.link.core.utils.AesUtil; +import com.hdl.sdk.link.core.utils.QueueUtils; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; +import com.hdl.sdk.link.socket.bean.Packet; + +import org.eclipse.paho.client.mqttv3.IMqttActionListener; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.IMqttToken; +import org.eclipse.paho.client.mqttv3.MqttAsyncClient; +import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.greenrobot.eventbus.EventBus; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Zoro on 2018/8/1. + * desc:2019/7/24 杩炴帴鎴愬姛浠ュ悗鍐嶈闃� 涓嶉渶瑕佸彂閫佸績璺� 涓嶉渶瑕佽嚜宸卞鐞嗛噸杩� + */ + +public class MqttRecvClient { + private static String mBroker; + private MemoryPersistence persistence = new MemoryPersistence(); + private MqttAsyncClient sampleClient; + private MqttConnectOptions connOpts = new MqttConnectOptions(); + private MqttThread mqttThread; + private static volatile MqttRecvClient mqttRecvClient; + private final String TAG = "MqttRecvClient"; + private static final String[] ignoreTopics = new String[]{"/thing/topo/found", "/ota/device/progress/up"}; + /** + * 涓婃鐨勪富棰橀渶瑕佽褰� 鏇存敼涓婚鐨勬椂鍊欓渶瑕佸彇娑堣闃� + */ + private static List<String> lastTopicFilters = new ArrayList<>(); + private static String mClientId; + private static String mUserName; + private static String mPassWord; + private final int[] qos = {0}; + + private MqttRecvClient() { + if (mqttThread == null) { + mqttThread = new MqttThread(); + } + if (TextUtils.isEmpty(mUserName) || TextUtils.isEmpty(mPassWord)) { + return; + } + mqttThread.start(); + } + + public static void init(Context context, String broker1, String deviceId, String userName, String pwd) { + mClientId = deviceId; + mBroker = broker1; + mUserName = userName; + mPassWord = pwd; + MqttRecvClient.create(); + } + + public void send(String topic, byte[] bytes) { + try { + if (TextUtils.isEmpty(topic)) { + LogUtils.e("璇锋眰涓婚涓簄ull"); + return; + } + checkAndsubscribeAllTopics(topic); + publish(topic, bytes); + } catch (MqttException e) { + e.printStackTrace(); + } + } + + /** + * 鍙戝竷 + * + * @param topic 涓婚 + * @param bytes 鍐呭 + * @throws MqttException + */ + public void publish(String topic, byte[] bytes) throws MqttException { + //鍥炲鏃讹紝mqtt涓婚涓殑鏂瑰悜瑕佸彉鍖栵紝瑕佸仛鏂瑰悜鏇挎崲 + mqttRecvClient.sampleClient.publish(topic, bytes, 1, false, null, new IMqttActionListener() { + @Override + public void onSuccess(IMqttToken asyncActionToken) { + LogUtils.d(TAG, topic); + } + + @Override + public void onFailure(IMqttToken asyncActionToken, Throwable exception) { + } + }); + } + + public static void create() { + if (mqttRecvClient == null) { + mqttRecvClient = new MqttRecvClient(); + } + } + + /** + * 浣跨敤鐨勬椂鍊欓渶瑕佸垽鏂潪绌� + */ + public static MqttRecvClient getInstance() { + if (null == mqttRecvClient) { + synchronized (MqttRecvClient.class) { + if (null == mqttRecvClient) { + mqttRecvClient = new MqttRecvClient(); + } + return mqttRecvClient; + } + } + return mqttRecvClient; + } + + class MqttThread extends Thread { + @Override + public void run() { + super.run(); + connect(); + } + } + + private void connect() { + try { + if (sampleClient != null) { + sampleClient.close(); + } + sampleClient = new MqttAsyncClient(mBroker, mClientId, persistence); + connOpts.setUserName(mUserName); +// connOpts.setServerURIs(new String[]{mBroker}); + connOpts.setPassword(mPassWord.toCharArray()); + connOpts.setCleanSession(true); + connOpts.setKeepAliveInterval(10); + connOpts.setAutomaticReconnect(true); + connOpts.setConnectionTimeout(10); + connOpts.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); + sampleClient.setCallback(new MqttCallbackExtended() { + public void connectComplete(boolean reconnect, String serverURI) { + LogUtils.d(TAG, "connect success"); + checkAndsubscribeAllTopics(""); + } + + public void connectionLost(Throwable throwable) { + LogUtils.d(TAG, "杩炴帴鏂紑"); + lastTopicFilters.clear(); + } + + public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { + managerMqttMsg(topic, mqttMessage); + } + + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { + } + }); + sampleClient.connect(connOpts); + + } catch (Exception me) { + me.printStackTrace(); + } + } + + /** + * 澶勭悊鎺ユ敹鐨刴qtt鏁版嵁 + * + * @param topic 鎺ユ敹涓婚 + * @param mqttMessage 鎺ユ敹鏁版嵁 + * @throws Exception + */ + public void managerMqttMsg(String topic, MqttMessage mqttMessage) throws Exception { + LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲涓婚" + topic); + if (HDLConnectHelper.isLocal()) { + boolean needReturn = true; + //濡傛灉鏄湰鍦版ā寮忥紝浜戠涓嬫潵鐨勭綉鍏虫暟鎹儴鍒嗘暟鎹笉鎺ユ敹(濡傦細ota鍗囩骇鍙嶉杩涘害) + for (String ignoreTopic : ignoreTopics) { + if (topic.endsWith(ignoreTopic)) { + needReturn = false; + break; + } + } + if (needReturn) { + return; + } + } + if (topic.contains("/custom/mqtt/secret/change")) { + /** + * 缃戝叧閲嶈繛mqtt 闇�瑕佹洿鎹esKey 涓嶇劧缃戝叧鏃犳硶瑙e瘑 閫氱煡鍒锋柊缃戝叧鍒楄〃骞朵笖鏇存柊涓荤綉鍏崇殑aesKey + */ + String[] topics = topic.split("/"); + //闈炲綋鍓嶄綇瀹呯綉鍏崇殑鏁版嵁杩斿洖 + if (topics.length < 3) { + return; + } + LogUtils.d(TAG, "缃戝叧閲嶈繛mqtt绉橀挜鏇存柊閫氱煡->" + topic); + EventNotifyRefreshGatewayAesKeyInfo eventNotifyRefreshGatewayAesKeyInfo = new EventNotifyRefreshGatewayAesKeyInfo(); + eventNotifyRefreshGatewayAesKeyInfo.setGatewayId(topics[2]); + EventBus.getDefault().post(eventNotifyRefreshGatewayAesKeyInfo); + return; + } + + String[] topics = topic.split("/"); + //闈炲綋鍓嶄綇瀹呯綉鍏崇殑鏁版嵁杩斿洖 + if (topics.length < 3) { + return; + } + String aes = null; + String cloudsGatewayId = topics[2];//浜戠涓奊atewayId + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(cloudsGatewayId); + if (cloudsGatewayId.equals(HDLLinkConfig.getInstance().getHomeId())) { + aes = getHomeAES(); + } else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) { + //姣背娉qtt涓撶敤绉橀挜 + aes = gatewayBean.getAesKey(); + } else { + aes = HDLLinkConfig.getInstance().getAesKey(); + } + if (TextUtils.isEmpty(aes)) { + return; + } + + byte[] bytes = AesUtil.aesDecrypt(mqttMessage.getPayload(), aes); + if (null == bytes) { + LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲鏁版嵁 瀵嗛挜瑙e瘑澶辫触"); + return; + } + String bodyStr = new String(bytes); + LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲鏁版嵁" + bodyStr); + /** + * 绾㈠瀹濊澶囬�氳繃/thing/topo/found涓婚 涓婃姤绾㈠瀹濊澶囧凡缁忓叆缃戜簡 鐒跺悗鐩存帴return 涓嶉渶瑕佸啀涓嬭浜� + */ + if (topic.endsWith("/thing/topo/found")) { + /** + * {"id":"0000016E","time_stamp":"366574","objects":[{"sid":"010105D370451908110100000000", + * "name":"Mini鏅鸿兘閬ユ帶鍣�","spk":"ir.module","oid":"010105D370451908","omodel":"MIR01R-LK.10", + * "online":"true","attributes":[],"status":[],"from":"010105D370451908","src":"010105D370451908"}]} + */ + if (bodyStr.contains("ir.module")) { + EventBus.getDefault().post(new EventBindMiniRemoteSuccessInfo()); + return; + } + } + //Link浠庣綉鍏抽�忎紶鐗规畩澶勭悊 + if (topic.contains("/native/a/") && topic.contains("/slaveoid/")) { + LinkMessageDecoder.getInstance().read(new Packet(bytes)); + } else { + byte[] topBytes = new byte[3]; + if (bytes.length > 2) { + topBytes[0] = bytes[0]; + topBytes[1] = bytes[1]; + topBytes[2] = bytes[2]; + } + if (new String(topBytes).equals("hex")) {//link鍘熺敓鏁版嵁锛屽垽鏂槸鍚︽槸鏂囦欢澶勭悊閫氱煡 + LinkMessageDecoder.getInstance().read(new Packet(bytes)); + } else { + QueueUtils.getInstance().add(new LinkPacket(topic, bytes, true)); + } + } + } + + /** + * 妫�鏌ヤ富棰樻槸鍚﹀凡璁㈤槄锛屾病鏈夎闃呭氨璁㈤槄 + * + * @param sendTopic 璇锋眰涓婚 + */ + public synchronized void checkAndsubscribeAllTopics(String sendTopic) { + if (null != sampleClient && sampleClient.isConnected() == false) { + return; + } + try { + for (String topic : nativeAndLinkTopic(sendTopic)) { + if (lastTopicFilters.contains(topic)) { + continue; + } + LogUtils.d(TAG, "璁㈤槄涓婚" + topic); + + sampleClient.subscribe(topic, 0, null, new IMqttActionListener() { + @Override + public void onSuccess(IMqttToken asyncActionToken) { + if (!lastTopicFilters.contains(topic)) { + lastTopicFilters.add(topic); + } + } + + @Override + public void onFailure(IMqttToken asyncActionToken, Throwable exception) { + + } + }); + } + + } catch (MqttException e) { + e.printStackTrace(); + } + } + + /** + * 璁㈤槄骞冲彴涓嬫潵鐨勪富棰� + * + * @return string鏁扮粍 + */ + private String[] nativeAndLinkTopic(String sendTopic) { + String[] topicArray = sendTopic.split("/"); + //闈炲綋鍓嶄綇瀹呯綉鍏崇殑鏁版嵁杩斿洖 + if (topicArray.length < 3) { + return new String[]{ + String.format("/user/%s/#", HDLLinkConfig.getInstance().getGatewayId()), + String.format("/base/%s/#", HDLLinkConfig.getInstance().getGatewayId())}; + } + + String gatewayId = topicArray[2];//浜戠涓奊atewayId + String[] topics = { + String.format("/user/%s/#", HDLLinkConfig.getInstance().getGatewayId()), + String.format("/base/%s/#", HDLLinkConfig.getInstance().getGatewayId()), + String.format("/user/%s/#", gatewayId), + String.format("/base/%s/#", gatewayId), + }; + return topics; + } + + + /** + * APP璁㈤槄浜戠涓婚瑙e瘑瀵嗘枃鐨勭閽�(杩欎釜瀵嗛挜鍙兘鐢ㄤ簬璁㈤槄浜戠涓婚锛岃闃呯綉鍏充富棰樺彟澶栦竴涓瘑閽�) + * + * @return -杩斿洖瑙e瘑瀵嗘枃鐨勭閽� + */ + private String getHomeAES() { + String homeId = HDLLinkConfig.getInstance().getHomeId(); + if (TextUtils.isEmpty(homeId)) { + return null; + } + //瑙e瘑瀵嗛挜瑙勫垯锛氬凡鐜版湁鐨勪綇瀹匢D涓哄熀鍑�,浠庡彸杈逛竴涓�鑾峰彇鍊�,鏈�鍚庡鏋滀笉澶�16浣�,鍒欏線鍙宠ˉ闆� + StringBuilder aesKey = new StringBuilder(); + for (int i = homeId.length() - 1; i >= 0; i--) { + aesKey.append(homeId.charAt(i)); + if (aesKey.length() == 16) { + break; + } + } + return this.PadRight(aesKey.toString(), 16, "0"); + } + + /** + * 浠庡彸杈规坊鍔犵┖鏍兼垨鍏跺畠瀛楃 + * + * @param currentValueStr 褰撳墠鍊� + * @param count 鎬婚暱鏁� + * @param others 鍏跺畠瀛楃(鑷畾涔�) + * @return 鎬婚暱搴� + */ + private String PadRight(String currentValueStr, int count, String others) { + if (count > currentValueStr.length()) { + StringBuilder stringBuilder = new StringBuilder(); + int subLen = count - currentValueStr.length(); + for (int i = 0; i < subLen; i++) { + stringBuilder.append(others); + } + currentValueStr = currentValueStr + stringBuilder; + } + return currentValueStr; + + } + + /** + * 鍒囨崲浣忓畢鐨勬椂鍊欒闃呰鍏ㄩ儴鍙栨秷 + */ + public void removeAllTopic() { + if (null != sampleClient && sampleClient.isConnected() == false) { + return; + } + try { + if (lastTopicFilters.size() == 0) { + return; + } + LogUtils.d(TAG, "绉婚櫎涓婚:\r\n" + JSON.toJSONString(lastTopicFilters)); + sampleClient.unsubscribe(lastTopicFilters.toArray(new String[lastTopicFilters.size()])); + lastTopicFilters.clear(); + } catch (MqttException e) { + e.printStackTrace(); + } + } + + public void stop() { + if (mqttRecvClient != null) { + try { + if (mqttRecvClient.sampleClient != null) { + mqttRecvClient.sampleClient.disconnect(); + mqttRecvClient.sampleClient.close(); + mqttRecvClient = null; + } + } catch (MqttException e) { + e.printStackTrace(); + } + } + } + + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java new file mode 100644 index 0000000..d7b6668 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java @@ -0,0 +1,799 @@ +package com.hdl.sdk.link.gateway; + +import android.text.TextUtils; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.R; +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.LogUtils; +import com.hdl.sdk.link.common.utils.SPUtils; +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.callback.HDLLinkTCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +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鑾峰彇鍐呭瓨涓殑缃戝叧锛屾敞鎰忥紝濡傛灉鏄繙绋嬮�氳锛実atewayBeanList瑕佸钩鍙颁笂缁戝畾鐨勪富缃戝叧鍙婁粠缃戝叧杩涘幓锛岃涓嶈幏鍙栦笉鍒扮綉鍏充俊鎭� + * + * @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; + } + + /** + * 閫氳繃spk鑾峰彇缃戝叧锛岃繖涓篃鏀寔鑾峰彇姣背娉� + * + * @param spkList 闆嗗悎 + * @return 杩斿洖缃戝叧鍒楄〃 + */ + public List<GatewayBean> getGatewayBySpk(List<String> spkList) { + if (spkList.size() == 0) { + return this.getGatewayList(); + } + List<GatewayBean> gatewayBeanList = new ArrayList<>(); + for (GatewayBean gatewayBean : this.getGatewayList()) { + if (spkList.contains(gatewayBean.getGatewayType())) + gatewayBeanList.add(gatewayBean); + } + return gatewayBeanList; + } + + /** + * 鑾峰彇缃戝叧鍒楄〃 鍘绘帀绾㈠瀹濊繖绉嶈澶� + * + * @param spkList 闆嗗悎 + * @return 杩斿洖缃戝叧鍒楄〃 + */ + public List<GatewayBean> getGatewayByGatewayType(List<String> spkList) { + if (spkList.size() == 0) { + return this.getGatewayList(); + } + List<GatewayBean> gatewayBeanList = new ArrayList<>(); + for (GatewayBean gatewayBean : this.getGatewayList()) { + if (spkList.contains(gatewayBean.getGatewayType()) && !"MIR01R-LK.10".equals(gatewayBean.getDevice_model())) + gatewayBeanList.add(gatewayBean); + } + return gatewayBeanList; + } + + /** + * 鑾峰彇鏈湴缃戝叧瀵硅薄(鍖呮嫭姣背娉�) + * + * @param macAndSid 璁惧mac + * @return 鎵惧埌杩斿洖GatewayBean, 鏈壘鍒拌繑鍥瀗ull. + */ + public GatewayBean getLocalGateway(String macAndSid) { + if (TextUtils.isEmpty(macAndSid)) { + return null; + } + for (GatewayBean gatewayBean : this.getGatewayList()) { + if (macAndSid.equals(gatewayBean.getDevice_mac()) + || macAndSid.equals(gatewayBean.getSid())) { + return gatewayBean; + } + } + return null; + } + + /** + * 鑾峰彇褰撳墠浣忓畢鐨勪富缃戝叧; + * + * @param homeId 浣忓畢id + * @return 鎵惧埌杩斿洖GatewayBean, 鏈壘鍒拌繑鍥瀗ull. + */ + public GatewayBean findMainGateway(String homeId) { + for (GatewayBean gatewayBean : this.getGatewayList()) { + if (gatewayBean.getMaster().equals("true") + && gatewayBean.getHomeId().equals(homeId) + && gatewayBean.getGatewayType().equals("AGATEWAY")) { + 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, true, callBack); + } + + /** + * 鏍规嵁浣忓畢id鑾峰彇缃戝叧 + * + * @param homeId 杩囨护鐨勪綇瀹卛d + * @param needEmptyHomeIdGateway 缃戝叧鐨勪綇瀹卛d涓虹┖鏃讹紝鏄惁鍙互鍔犲叆缃戝叧鍒楄〃 + * @param callBack 鍥炶皟鏂规硶 + */ + public void refreshGatewayByHome(String homeId, boolean needEmptyHomeIdGateway, GatewayCallBack callBack) { + refreshGatewayByHomeIdAndSpk(homeId, this.getGatewayTypeList(), needEmptyHomeIdGateway, callBack); + } + + /** + * 鑾峰彇缃戠粶璁惧锛屽寘鎷綉鍏冲強姣背娉㈢瓑缃戠粶璁惧 + * + * @param homeId 浣忓畢Id + * @param spk 缃戠粶璁惧spk + * @param needEmptyHomeIdGateway 鏄惁闇�瑕佺┖浣忓畢Id璁惧 + * @param callBack 鍥炶皟 + */ + public void refreshGatewayByHomeIdAndSpk(String homeId, List<String> spk, boolean needEmptyHomeIdGateway, GatewayCallBack callBack) { + String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; + final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); + EventListener eventListener = getSearchGatewayEvent(homeId, spk, needEmptyHomeIdGateway, tempGatewayBeanList); + EventDispatcher.getInstance().register(topicReply, eventListener); + + ThreadToolUtils.getInstance().newFixedThreadPool(1).execute(new Runnable() { + @Override + public void run() { + int count = 5; + while (0 < count--) { + try { + //鎼滅储缃戝叧 + serchGatewayOneTime(); + Thread.sleep(300L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + //瓒呭嚭娆℃暟鍚庣Щ闄ょ洃鍚簨浠� + EventDispatcher.getInstance().remove(topicReply, eventListener); + if (callBack != null) { + if (tempGatewayBeanList.size() == 0) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GET_GATEWAY_FAILURE_ERROR)); + } else { + callBack.onSuccess(tempGatewayBeanList); + } + } + } + }); + } + + /** + * 鍒涙柊鎵�鏈夊湪绾跨殑缃戝叧锛屽寘鎷綋鍓嶄綇瀹呯殑鍙婃病鏈夌粦瀹氳繃鐨勭綉鍏� + * + * @param callBack 鍥炶皟 + */ + public void refreshGateway(GatewayCallBack callBack) { + String topicReply = TopicConstant.GATEWAY_SEARCH_REPLY; + final List<GatewayBean> tempGatewayBeanList = new ArrayList<>(); + EventListener eventListener = getSearchGatewayEvent(this.getGatewayTypeList(), 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 getSearchGatewayEvent(homeId,true,tempGatewayBeanList); +// } + + +// /** +// * 鑾峰彇鎼滅储缃戝叧浜嬩欢 +// * +// * @param homeId +// * @return +// */ +// private EventListener getSearchGatewayEvent(String homeId, boolean needEmptyHomeIdGateway, final List<GatewayBean> tempGatewayBeanList) { +// //娉ㄥ唽鎼滅储缃戝叧鐩戝惉 +// return new EventListener() { +// @Override +// public void onMessage(Object msg) { +// if (!(msg instanceof LinkResponse)) { +// return; +// } +// GatewayBean gateway = getGatewayBeanByResponse((LinkResponse) msg); +// if (gateway == null) { +// return; +// } +// gateway.setOnline(true); +// gateway.setIsLocalGateWay(true);//鏈湴鎼滅储鍒扮殑缃戝叧鏍囪瘑涓烘湰鍦扮綉鍏� +// +// //鍙姞杞戒綇瀹呬竴鏍风殑鎴栬�呯綉鍏宠繕娌℃湁閰嶇疆杩囩殑锛屾垨鑰呬笉闇�瑕佷綇瀹卛d涓虹┖鐨勭綉鍏� +// if (homeId.equals(gateway.getHomeId()) || (needEmptyHomeIdGateway == true && TextUtils.isEmpty(gateway.getHomeId()))) { +// //鏇存柊缂撳瓨缃戝叧锛屼細璁板綍鎵�鏈夋敹鍒扮殑缃戝叧锛屼互涓轰簡淇濆瓨缃戝叧鐨処P淇℃伅 +// updateGatewayList(gatewayBeanList, gateway); +// //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� +// updateGatewayList(tempGatewayBeanList, gateway); +// } +// } +// }; +// } + + /** + * 鑾峰彇鎼滅储缃戝叧浜嬩欢 + * + * @param homeId + * @return + */ + private EventListener getSearchGatewayEvent(String homeId, List<String> spk, boolean needEmptyHomeIdGateway, final List<GatewayBean> tempGatewayBeanList) { + //娉ㄥ唽鎼滅储缃戝叧鐩戝惉 + return new EventListener() { + @Override + public void onMessage(Object msg) { + if (!(msg instanceof LinkResponse)) { + return; + } + GatewayBean gateway = getGatewayBeanByResponse((LinkResponse) msg); + if (gateway == null) { + return; + } + gateway.setOnline(true); + gateway.setIsLocalGateWay(true);//鏈湴鎼滅储鍒扮殑缃戝叧鏍囪瘑涓烘湰鍦扮綉鍏� + //鍙姞杞戒綇瀹呬竴鏍风殑鎴栬�呯綉鍏宠繕娌℃湁閰嶇疆杩囩殑锛屾垨鑰呬笉闇�瑕佷綇瀹卛d涓虹┖鐨勭綉鍏� + if (homeId.equals(gateway.getHomeId()) || (needEmptyHomeIdGateway == true && TextUtils.isEmpty(gateway.getHomeId()))) { + //鏇存柊缂撳瓨缃戝叧锛屼細璁板綍鎵�鏈夋敹鍒扮殑缃戝叧锛屼互涓轰簡淇濆瓨缃戝叧鐨処P淇℃伅 + updateGatewayList(gatewayBeanList, gateway); + //闈炴悳绱㈢殑缃戝叧绫讳技杩斿洖 + if (spk.contains(gateway.getGatewayType())) { + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + updateGatewayList(tempGatewayBeanList, gateway); + } + } + } + }; + } + + /** + * 鑾峰彇鎼滅储缃戝叧浜嬩欢 杩欒竟涓嶈繃婊omeId + * + * @return + */ + private EventListener getSearchGatewayEvent(List<String> spk, 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); + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + if (spk.contains(gateway.getGatewayType())) { + //鏇存柊褰撳墠璇诲彇缃戝叧鐨勫垪琛紝杩欎釜鍒楄〃姣忔閮芥槸娓呯┖鍐嶈鍙� + updateGatewayList(tempGatewayBeanList, gateway); + } + } + }; + } + + /** + * 鏇存柊鏀跺埌鐨勭綉鍏冲埌鍒楄〃 + * + * @param gatewayBeanList + * @param gateway 褰撳墠鏀跺埌鐨勭綉鍏� + */ + void updateGatewayList(final List<GatewayBean> gatewayBeanList, GatewayBean gateway) { + + if (TextUtils.isEmpty(gateway.getOid()) || TextUtils.isEmpty(gateway.getDevice_mac())) { + LogUtils.e("缃戝叧Mac鎴栬�匫id涓虹┖锛屾棤鏁堢綉鍏�"); + return; + } + + boolean isFound = false;//鏄惁鍦ㄥ唴瀛樹腑鎵惧埌缃戝叧瀵硅薄 + //鎵惧嚭mac涓�鏍风殑缃戝叧鏇存柊鏈�鏂版暟鎹� + for (int i = 0; i < gatewayBeanList.size(); i++) { + if (gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac())) { + isFound = true; + gatewayBeanList.set(i, gateway); +// break; + } + } + + //娓呴櫎oid涓�鏍凤紝mac涓嶄竴鏍风殑缃戝叧缂撳瓨銆備竴鑸槸鍦ㄧ綉鍏虫浛鎹㈢殑鎯呭喌绌洪棿鍑虹幇 + for (int i = 0; i < gatewayBeanList.size(); i++) { + if (gatewayBeanList.get(i).getDevice_mac().equals(gateway.getDevice_mac()) && !gatewayBeanList.get(i).getOid().equals(gateway.getOid())) { + gatewayBeanList.remove(i--); + } + } + + //娌℃湁鎵惧埌灏辨坊鍔� + 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 SetGatewayRemoteInfo(String master, String mac, String regionUrl, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_EDIT_REMOTE, mac); + + JsonObject jObject = new JsonObject(); + if (master.equals("true")) { + jObject.addProperty("server_addr", regionUrl); + jObject.addProperty("remote", "true"); + } else { + jObject.addProperty("server_addr", ""); + jObject.addProperty("remote", "false"); + } + + JsonObject sendJsonObj = new JsonObject(); + sendJsonObj.add("objects", jObject); + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + String sendStr = sendJsonObj.toString(); + + LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + /* + * 缁戝畾缃戝叧 + * 缂栬緫homeId缁欑綉鍏� + * */ + public void bindGateway(String master, String mac, String homeId, String regionUrl, String ip, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_EDIT_REMOTE, mac); + + JsonObject jObject = new JsonObject(); + jObject.addProperty("homeId", homeId); +// if(master.equals("true")) { +// jObject.addProperty("server_addr", regionUrl); +// jObject.addProperty("remote", "true"); +// }else { +// jObject.addProperty("server_addr", ""); +// jObject.addProperty("remote", "false"); +// } + + JsonObject sendJsonObj = new JsonObject(); + sendJsonObj.add("objects", jObject); + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + String sendStr = sendJsonObj.toString(); + + LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + /* + * 鍒濆鍖栫綉鍏� + * */ + 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, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + /* + * 璁剧疆涓讳粠缃戝叧鏍囪 + * */ + public void setMasterGateway(String regionUrl, String ip, String mac, String master, boolean isEncrypt, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_EDIT_LOCAL, mac); + + JsonObject jObject = new JsonObject(); + jObject.addProperty("master", master); + + JsonObject sendJsonObj = new JsonObject(); + sendJsonObj.add("objects", jObject); + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + String sendStr = sendJsonObj.toString(); + + LinkRequest message = new LinkRequest(topic, sendStr, isEncrypt); + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if ("true".equals(master)) { + String longStr1 = SPUtils.getString("longitude"); + String latStr1 = SPUtils.getString("latitude"); + if (!TextUtils.isEmpty(longStr1) && !TextUtils.isEmpty(latStr1)) { + HDLLinkLocalSdk.getInstance().gatewayLocation(mac, longStr1, latStr1, isEncrypt, new HDLLinkTCallBack<String>() { + @Override + public void onSuccess(String data) { + } + + @Override + public void onError(HDLLinkException e) { + } + }); + } + } + if (callBack == null) return; + callBack.onSuccess("1"); + SetGatewayRemoteInfo(master, mac, regionUrl, ip, isEncrypt, new HDLLinkCallBack() { + @Override + public void onSuccess(String msg) { + + } + + @Override + public void onError(HDLLinkException e) { + + } + }); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + /** + * 璁剧疆缃戝叧鍏ョ綉浠庢満妯″紡 + */ + public void AuthGateway(String ip, String mac, HDLLinkCallBack callBack) { + String topic = String.format(TopicConstant.GATEWAY_AUTH, mac); + + JsonObject sendJsonObj = new JsonObject(); + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + JsonObject jObject = new JsonObject(); + jObject.addProperty("spk", "LINKDEVICE"); + jObject.addProperty("time", "120"); + sendJsonObj.add("objects", jObject); + + + String sendStr = sendJsonObj.toString(); + LinkRequest message = new LinkRequest(topic, sendStr, false); + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + callBack.onSuccess(""); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + /** + * 璁剧疆缃戝叧鍏ョ綉浠庢満妯″紡 + */ + 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, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + } + }, 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, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + callBack.onSuccess("1"); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + }, true).send(); + } + + + /** + * 鍙戦�佹暟鎹埌Link缃戝叧 + * + * @param ip 缃戝叧IP + * @param mac 缃戝叧mac + * @param isEncrypt 鏄惁鍔犲瘑 + * @param topic 璇锋眰涓婚 + * @param jObject 璐熻浇鏁版嵁<娌℃湁濉玭ull></> + * @param sendPath 鍙戦�佽矾寰�<绫诲悕+鏂规硶鍚�>class->methodName</> + */ + public void sendDataToLinkGateway(String ip, String mac, boolean isEncrypt, + String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { + String topicSend = topic.replace("%s", mac); + //缁勮闇�瑕佸彂閫佺殑鏁版嵁 + String sendStr = createSendData(jObject); +// LogUtils.i("sendDataToLinkGateway->" + sendPath + "->鏈湴鍙戦�乗r\n" + topicSend + "\r\n" + sendStr); + LinkRequest message = new LinkRequest(topicSend, sendStr, isEncrypt); + GatewayBean gatewayBean = this.getLocalGateway(mac); + if (gatewayBean != null) { + message.setCloudTopic(topic.replace("%s", gatewayBean.getGatewayId())); + } + new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (callBack == null) return; + try { + JSONObject jsonObject = new JSONObject(new Gson().toJson(msg)); + if (jsonObject.has("data")) { + callBack.onSuccess(jsonObject.getString("data")); + } + } catch (Exception e) { + callBack.onSuccess(e.getMessage()); + } +// LogUtils.i("sendDataToLinkGateway->"+sendPath+"->鏈湴鎺ユ敹鏁版嵁\r\n"+msg.toString()); + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack == null) return; + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); +// LogUtils.i("sendDataToLinkGateway->" + sendPath + "->鏈湴鎺ユ敹鏁版嵁->澶辫触(-200)"); + } + }, true, mac).send(); + } + + /** + * 缁勮闇�瑕佸彂閫佺殑鏁版嵁 + * + * @param jObject 璐熻浇鏁版嵁<娌℃湁濉玭ull> + * @return 杩斿洖json瀛楃涓� + */ + private 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); + } else if (jObject instanceof JSONArray) { + JsonArray array = GsonConvert.getGson().fromJson(jObject.toString(), new TypeToken<JsonArray>() { + }.getType()); + sendJsonObj.add("objects", array); + } + } + String time = String.valueOf(System.currentTimeMillis()); + sendJsonObj.addProperty("time_stamp", time); + sendJsonObj.addProperty("id", IdUtils.getUUId()); + return sendJsonObj.toString(); + } + + /** + * 鏀寔缃戝叧绫诲瀷 + * + * @return 绫诲瀷鍒楄〃 + */ + private List<String> getGatewayTypeList() { + List<String> typeList = new ArrayList<>(); + typeList.add("AGATEWAY");//缃戝叧 + typeList.add("sensor.mmv_sleep");//姣背娉pk + typeList.add("sensor.mmv_pose");//姣背娉pk + return typeList; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/bean/GatewaySearchBean.java new file mode 100644 index 0000000..f0a02e3 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java new file mode 100644 index 0000000..1ad5fa2 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/type/GatewayMasterType.java @@ -0,0 +1,21 @@ +package com.hdl.sdk.link.gateway.type; + +import androidx.annotation.StringDef; + +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.SOURCE; + +/** + * Created by jlchen on 12/30/21. + */ +@Retention(SOURCE) +@StringDef({GatewayMasterType.MasterTrue,GatewayMasterType.MasterFalse,GatewayMasterType.NO_CONFIG}) +public @interface GatewayMasterType { + //涓荤綉鍏� + String MasterTrue = "true"; + //浠庣綉鍏� + String MasterFalse = "false"; + //鏈厤缃� + String NO_CONFIG = "no_config"; +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java new file mode 100644 index 0000000..d92529a --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketOptions.java @@ -0,0 +1,74 @@ +package com.hdl.sdk.link.socket; + + +import com.hdl.sdk.link.socket.codec.IHandleMessage; +import com.hdl.sdk.link.socket.listener.ConnectStatusListener; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Tong on 2021/9/22. + * socket閰嶇疆 + */ +public class SocketOptions { + + //鍙戦�佺洰鏍囧湴鍧�IP + private String ip=""; + private int port; + + //澶勭悊鏁版嵁 + private IHandleMessage handleMessage; + + //鐩戝惉鐘舵�� + private List<ConnectStatusListener> mConnectStatusListener; + + + public String getIp() { + return ip; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public IHandleMessage getHandleMessage() { + return handleMessage; + } + + public void setHandleMessage(IHandleMessage handleMessage) { + this.handleMessage = handleMessage; + } + + public void clearConnectStatusListener() { + if (mConnectStatusListener != null && !mConnectStatusListener.isEmpty()) { + mConnectStatusListener.clear(); + } + } + + public void addConnectStatusListener(ConnectStatusListener connectStatusListener) { + if (mConnectStatusListener == null) { + mConnectStatusListener = new ArrayList<>(); + } + mConnectStatusListener.add(connectStatusListener); + } + + public void removeConnectStatusListener(ConnectStatusListener connectStatusListener) { + if (mConnectStatusListener != null) { + mConnectStatusListener.remove(connectStatusListener); + } + } + + public List<ConnectStatusListener> getConnectStatusListener() { + return mConnectStatusListener; + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java new file mode 100644 index 0000000..79e11f6 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketPool.java @@ -0,0 +1,54 @@ +package com.hdl.sdk.link.socket; + +import com.hdl.sdk.link.socket.client.IClient; + +import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by Tong on 2021/10/19. + * 璁″垝鍙傝�僩eneric-pool銆丆ommons Pool杩涜瀹屽杽 + */ +public class SocketPool { + + private final ConcurrentHashMap<String, IClient> mPool; + private final ConcurrentHashMap<String, DatagramSocket> mUdpClientPool; + + private SocketPool() { + mPool = new ConcurrentHashMap<>(); + mUdpClientPool = new ConcurrentHashMap<>(); + } + + + private static class SingletonInstance { + private static final SocketPool INSTANCE = new SocketPool(); + } + + public static SocketPool getInstance() { + return SingletonInstance.INSTANCE; + } + + public void clear() { + mPool.clear(); + mUdpClientPool.clear(); + } + + public synchronized DatagramSocket getUdpSocket(InetSocketAddress address) throws SocketException { + DatagramSocket socket = null; + final String key = address.getPort() + ""; + if (mUdpClientPool.containsKey(key)) { + socket = mUdpClientPool.get(key); + if (socket != null && socket.isClosed()) { + mUdpClientPool.remove(key); + socket = null; + } + } + if (socket == null) { + socket = new DatagramSocket(address); + mUdpClientPool.put(key, socket); + } + return socket; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java new file mode 100644 index 0000000..d710ad6 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/SocketRequest.java @@ -0,0 +1,34 @@ +package com.hdl.sdk.link.socket; + +import java.util.UUID; + +/** + * Created by Tong on 2021/9/22. + */ +public class SocketRequest { + + private String action; + + private byte[] data; + + public SocketRequest(byte[] data) { + this.data = data; + action = UUID.randomUUID().toString(); + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java new file mode 100644 index 0000000..5a098d9 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java @@ -0,0 +1,281 @@ +package com.hdl.sdk.link.socket; + +import android.text.TextUtils; + +import androidx.collection.ArrayMap; + +import com.hdl.sdk.link.common.utils.LogUtils; +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.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingDeque; + +/** + * Created by Tong on 2021/9/26. + * Tcp/Udp 鍚姩鍣� + */ +public class TcpSocketBoot { + + private ExecutorService connectThread; + private ExecutorService sendThread; + private ExecutorService receiveThread; + private ExecutorService heartbeatThread; + + private final IClient client; + private IHeartbeat iHeartbeat; + public void SetHeartbeat(IHeartbeat iHeartbeat){ + this.iHeartbeat=iHeartbeat; + } + /** + * 褰撳墠鎺ユ敹鍒版暟鎹殑鏃堕棿 + */ + private long time=System.currentTimeMillis(); + /** + * tcp鏄惁宸茬粡杩炴帴 + */ + private boolean connected=false; + + public IClient getClient() { + return client; + } + + public boolean isConnected() { + return connected; + } + + private final BlockingQueue<SocketRequest> mMessageQueue = new LinkedBlockingDeque<>(); + + private final ArrayMap<String, SendListener> sendMap = new ArrayMap<>(); + + 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; + } + + /** + * 杩炴帴tcp锛屽唴閮ㄧ淮鎶ゆ帀锛屽彲浠ヤ笉鐢ㄥ紑鏀惧閮紝鏍规嵁杩欎釜涓氬姟鎴戠壒鎬у鐞嗗ソ + */ + private synchronized void connect() { + try { + LogUtils.i("TCP杩炴帴锛�"+this.getClient().getOptions().getIp()); + client.onConnectStatus(ConnectStatus.CONNECTING); +// Thread.sleep(700); + client.connect(); + LogUtils.i("TCP杩炴帴鎴愬姛锛�"+this.getClient().getOptions().getIp()); + connected=true; + client.onConnectStatus(ConnectStatus.CONNECTED); + }catch(Exception e) { + LogUtils.e(e.getMessage()); + } + } + + + /** + * 鍒濆鍖栧彂閫佺嚎绋嬶紝鍙渶瑕佸垵濮嬪寲涓�娆� + */ + private void initSendThread() { + if (sendThread == null) { + sendThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); + sendThread.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + if(connected==false){ + Thread.sleep(100); + continue; + } + SocketRequest socketRequest = mMessageQueue.take(); + final String action = socketRequest.getAction(); + try { + client.sendMsg(socketRequest.getData()); + if (!TextUtils.isEmpty(action)) { + SendListener sendListener = sendMap.get(action); + if (sendListener != null) { + sendListener.onSucceed(); + } + } + } catch (Exception e) { + connected = false; + LogUtils.e("鍙戦�佸け璐�:" + e.getMessage()); + if (!TextUtils.isEmpty(action)) { + SendListener sendListener = sendMap.get(action); + if (sendListener != null) { + sendListener.onError(); + } + } + } + } catch (Exception e) { + LogUtils.e("鍙戦�佸け璐�1:" + e.getMessage()); + } + } + } + }); + } + } + + /** + * 鍒濆鍖栨帴鏀剁嚎绋嬶紝鍙渶瑕佸垵濮嬪寲涓�娆� + */ + public void initReceiveThread() { + if (receiveThread == null) { + receiveThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); + receiveThread.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (connected) { + //璇诲彇鏁版嵁 + client.onHandleResponse(); + time= System.currentTimeMillis(); + } else { + try { + Thread.sleep(1000); + } catch (Exception ee) { + + } + } + } catch (Exception e) { + connected = false; + LogUtils.e("鎺ユ敹鏁版嵁绾跨▼寮傚父" + e.getMessage()); + } + } + } + }); + } + } + + /** + * 鍒濆鍖栭噸鏂拌繛鎺ョ嚎绋� + */ + private void initConnectThread() { + if (connectThread == null) { + connectThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); + //涓�瀹氭椂闂存娴嬩竴娆¤繛鎺ユ儏鍐碉紝娌℃湁杩炴帴灏辨墽琛岃繛鎺ワ紝杩炴帴缁熶竴鐢辫繖閲岀淮鎶� + connectThread.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (!connected) { + reconect(); + } + Thread.sleep(5*1000); + } catch (Exception e) { + + LogUtils.e("瀹氭椂杩炴帴绾跨▼寮傚父:" + e.getMessage()); + } + } + } + }); + } + } + + /** + * 鍒濆鍖栭噸鏂板績璺崇嚎绋� + */ + private void initHeartbeat() { + if (heartbeatThread == null) { + heartbeatThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); + heartbeatThread.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + //5绉� + if (connected && 5 * 1000 < (System.currentTimeMillis() - time)) { + time = System.currentTimeMillis(); + //蹇冭烦妫�娴� + if (iHeartbeat != null) + iHeartbeat.heartbeat(); + } + Thread.sleep(10); + } catch (Exception e) { + LogUtils.e("瀹氭椂蹇冭烦妫�娴嬬綉鍏冲紓甯革細" + e.getMessage()); + } + } + } + }); + } + } + /** + * 閲嶆柊杩炴帴 + */ + private void reconect() { + disconnect(); + connect(); + } + + /** + * 鍙戦�佹棤闇�鍥炶皟 + * @param msg 鍙戦�佺殑鏁版嵁 + */ + public void sendMsg(byte[] msg) { + sendMsg(msg, null); + } + + + /** + * @param listener 涓�鑸儏鍐垫棤闇�鐩戝惉 + */ + public void sendMsg(byte[] msg, SendListener listener) { + try { + SocketRequest request = new SocketRequest(msg); + if (listener != null && !TextUtils.isEmpty(request.getAction())) { + sendMap.put(request.getAction(), listener); + } + mMessageQueue.put(request); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 鍏抽棴杩炴帴 + */ + private synchronized void disconnect() { + try { + client.disconnect(); + //鏂紑杩炴帴 + client.onConnectStatus(ConnectStatus.DISCONNECT); + } catch (Exception e) { + + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java new file mode 100644 index 0000000..9ecb29c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/annotation/ConnectStatus.java @@ -0,0 +1,31 @@ +package com.hdl.sdk.link.socket.annotation; + +import androidx.annotation.IntDef; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Created by Tong on 2021/9/22. + */ +@Target({ElementType.TYPE_PARAMETER, ElementType.PARAMETER}) +@IntDef({ConnectStatus.CONNECTING, + ConnectStatus.CONNECTED, + ConnectStatus.DISCONNECT}) +public @interface ConnectStatus { + + /** + * 杩炴帴涓� + */ + int CONNECTING = 0; + + /** + * 杩炴帴鎴愬姛 + */ + int CONNECTED = 1; + + /** + * 杩炴帴鍏抽棴 + */ + int DISCONNECT = 2; +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java new file mode 100644 index 0000000..e2558a8 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/bean/Packet.java @@ -0,0 +1,45 @@ +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 byte []bytes; + private Socket socket; + + public Packet( byte []bytes, Socket socket){ + this.bytes=bytes; + this.socket=socket; + } + public Packet(byte []bytes){ + this(bytes,null); + } + + + /** + * 鎺ユ敹鎴栬�呭彂閫佺殑鏁版嵁 + * @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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java new file mode 100644 index 0000000..71293d7 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IClient.java @@ -0,0 +1,32 @@ +package com.hdl.sdk.link.socket.client; + + +import com.hdl.sdk.link.socket.SocketOptions; + +/** + * Created by Tong on 2021/9/22. + */ +public interface IClient { + + void connect() throws Exception; + + void disconnect(); + + + SocketOptions getOptions(); + + /** + * 鐩戝惉鏁版嵁 + */ + void onHandleResponse() throws Exception; + + /** + * 鍙戦�佹秷鎭� + */ + void sendMsg(byte[] msg) throws Exception; + + /** + * 杩炴帴鐘舵�� + */ + void onConnectStatus(int status); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java new file mode 100644 index 0000000..9a4e7a4 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IHeartbeat.java @@ -0,0 +1,8 @@ +package com.hdl.sdk.link.socket.client; + +/** + * Created by hxb on 2022/2/16. + */ +public interface IHeartbeat { + void heartbeat(); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java new file mode 100644 index 0000000..7db851e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/IUdpClient.java @@ -0,0 +1,38 @@ +package com.hdl.sdk.link.socket.client; + +import com.hdl.sdk.link.socket.udp.UdpSocketOptions; + +/** + * Created by hxb on 2021/12/12. + */ +public interface IUdpClient { + + /** + * 缁戝畾绔彛 + */ + void bind() throws Exception; + + /** + * 鍏抽棴褰撳墠杩炴帴 + * @return + */ + boolean close(); + + + UdpSocketOptions getOptions(); + + /** + * 鐩戝惉鏁版嵁 + */ + void onHandleResponse() throws Exception; + + /** + * 鍙戦�佹暟鎹� + * @param ipAddress 鐩爣IP + * @param port 绔彛 + * @param msg 鍙戦�佹暟鎹� + * @throws Exception + */ + void sendMsg(String ipAddress,int port, byte[] msg) throws Exception; + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java new file mode 100644 index 0000000..d5e6f38 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/TcpClient.java @@ -0,0 +1,176 @@ +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.core.protocol.LinkMessageDecoder; +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; + + if ((len = stream.read(readBuffer)) == -1) { + throw new Exception("缃戝叧鏂紑"); + } + + byte[] bytes = new byte[len]; + System.arraycopy(readBuffer, 0, bytes, 0, len); + socketOptions.getHandleMessage().read(new Packet(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) { + switch (status) { + case ConnectStatus + .CONNECTING: + listener.onConnecting(); + break; + case ConnectStatus + .CONNECTED: + listener.onConnected(); + break; + case ConnectStatus + .DISCONNECT: + listener.onConnectFailed(); + break; + } + } + } + } + }); + } + + + 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java new file mode 100644 index 0000000..2e94009 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/client/UdpClient.java @@ -0,0 +1,191 @@ +package com.hdl.sdk.link.socket.client; + + +import android.net.wifi.WifiManager; +import android.text.TextUtils; + +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.core.protocol.LinkMessageDecoder; +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; + + +/** + * Created by hxb on 2021/12/12. + */ +public class UdpClient implements IUdpClient { + + /** + * 褰撳墠socket + */ + private DatagramSocket mSocket; + + /** + * 鎺ユ敹鏁版嵁鍖� + */ + private DatagramPacket receivePacket; + + /** + * 缂撳啿鍖哄ぇ灏� + */ + private final int BUFFER = 2 * 1024; + + /** + * 鏈湴鐩戝惉IP鍦板潃 + */ + private String ipAddress; + /** + * 鏈湴鐩戝惉绔彛 + */ + private int port; + + /** + * socket閰嶇疆淇℃伅 + */ + private UdpSocketOptions socketOptions; + + WifiManager.MulticastLock lock; + + /** + * 鍒濆鍖栧弬鏁� + * @param ipAddress 鏈湴鐩戝惉绔彛 + * @param port 鏈湴鐩戝惉绔彛 + * @param socketOptions + */ + public UdpClient(String ipAddress, int port, UdpSocketOptions socketOptions) { + this.ipAddress = ipAddress; + this.port = port; + this.socketOptions = socketOptions; + byte[] receiveByte = new byte[BUFFER]; + receivePacket = new DatagramPacket(receiveByte, receiveByte.length); + this.lock= socketOptions.getWifiManager().createMulticastLock("UDPwifi"); + } + + /** + * 鍒濆鍖栧弬鏁� + * @param ipAddress 鏈湴鐩戝惉IP鍦板潃 + * @param port 鏈湴鐩戝惉绔彛 + * @param options + * @return + */ + public static UdpSocketBoot init(String ipAddress, int port, UdpSocketOptions options) { + return new UdpSocketBoot(new UdpClient(ipAddress, port, options)); + } + + /** + * 鍒濆鍖栧弬鏁� + * @param port 鏈湴鐩戝惉绔彛 + * @param options + * @return + */ + public static UdpSocketBoot init(int port, UdpSocketOptions options) { + return init("0.0.0.0", port, options); + } + + @Override + public synchronized void bind() throws Exception { + try { + //宸茬粡缁戝畾杩囧氨涓嶇敤鍐嶇粦瀹� + if (null != mSocket) { + return; + } + + lock.acquire(); + if (TextUtils.isEmpty(ipAddress)) { + 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); + + } catch (Exception e) { + throw e; + } + } + + @Override + public boolean close() { + try { + mSocket.close(); + } catch (Exception e) { + + } + mSocket = null; + return true; + } + + @Override + public UdpSocketOptions getOptions() { + return this.socketOptions; + } + + @Override + public void onHandleResponse() throws Exception { + if (mSocket == null) { + return; + } + try { + mSocket.receive(receivePacket); + } 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 { + LogUtils.i("鎺ユ敹鍒癠dp鏁版嵁鍖咃紝缃戠粶鍦板潃锛�" + receivePacket.getAddress().getHostAddress() + ":" + receivePacket.getPort()); + +// IHandleMessage handleMessage = getOptions().getHandleMessage(); +// if (handleMessage != null) { +// byte[] data = new byte[receivePacket.getLength()]; +// System.arraycopy(receivePacket.getData(), 0, data, 0, data.length); +// handleMessage.read(new Packet(receivePacket.getAddress().getHostAddress(), data,null)); +// } + + byte[] data = new byte[receivePacket.getLength()]; + System.arraycopy(receivePacket.getData(), 0, data, 0, data.length); + socketOptions.getHandleMessage().read(new Packet(data)); + + } catch (Exception e) { + LogUtils.i("鎺ユ敹鍒癠dp鏁版嵁鍖咃紝澶勭悊寮傚父锛�" + e.getMessage()); + } + } + + + @Override + public void sendMsg(String ipAddress,int port, byte[] msg) throws Exception { + if (msg == null) { + return; + } + final DatagramPacket sendPacket = new DatagramPacket(msg, msg.length, InetAddress.getByName(ipAddress), port); + if (mSocket != null) { + mSocket.send(sendPacket); + } else { + DatagramSocket datagramSocket = new DatagramSocket(); + datagramSocket.send(sendPacket); + datagramSocket.close(); + } + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/ByteToMessageDecoder.java new file mode 100644 index 0000000..7f4bbab --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleFlow.java new file mode 100644 index 0000000..3ce442f --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IHandleMessage.java new file mode 100644 index 0000000..1c7a223 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java new file mode 100644 index 0000000..41128df --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/IMessagePipeLine.java @@ -0,0 +1,11 @@ +package com.hdl.sdk.link.socket.codec; + +/** + * Created by Tong on 2021/9/23. + */ +public interface IMessagePipeLine { + + void add(IHandleFlow flow); + + void clear(); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessagePipeLine.java new file mode 100644 index 0000000..3e09cc2 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/codec/MessageToByteEncoder.java new file mode 100644 index 0000000..e093590 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java new file mode 100644 index 0000000..9efb726 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/ConnectStatusListener.java @@ -0,0 +1,27 @@ +package com.hdl.sdk.link.socket.listener; + +/** + * Created by Tong on 2021/9/22. + * 杩炴帴鐘舵�� + */ +public interface ConnectStatusListener { + + /** + * 杩炴帴涓� + */ + default void onConnecting() { + } + + /** + * 杩炴帴鎴愬姛 + */ + default void onConnected() { + } + + /** + * 杩炴帴澶辫触 + */ + default void onConnectFailed() { + } + +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java new file mode 100644 index 0000000..e9a84f1 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/listener/SendListener.java @@ -0,0 +1,11 @@ +package com.hdl.sdk.link.socket.listener; + +/** + * Created by Tong on 2021/9/22. + */ +public interface SendListener { + + void onSucceed(); + + void onError(); +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java new file mode 100644 index 0000000..4e039f7 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketBoot.java @@ -0,0 +1,128 @@ +package com.hdl.sdk.link.socket.udp; + +import android.text.TextUtils; + +import androidx.collection.ArrayMap; + +import com.hdl.sdk.link.common.utils.LogUtils; +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.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by hxb on 2021/12/12. + */ +public class UdpSocketBoot { + + private final IUdpClient client; + + private final AtomicBoolean isOpenRetry = new AtomicBoolean(false); + + private final AtomicInteger resendCount = new AtomicInteger(0); + + private ExecutorService receiveThread; + + private final ArrayMap<String, SendListener> sendMap = new ArrayMap<>(); + + + public IUdpClient getClient() { + return client; + } + + public UdpSocketBoot(IUdpClient client) { + this.client = client; + } + + /** + * 缁戝畾 socket + * @throws Exception 鍙兘绔彛鍐茬獊 + */ + public void bind() throws Exception { + client.bind(); + initReceiveThread(); + } + + /** + * 鍒濆鍖栨帴鏀剁嚎绋� + */ + private void initReceiveThread() { + if(null!=receiveThread){ + return; + } + receiveThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); + receiveThread.execute(new Runnable() { + @Override + public void run() { + while (true) { + try { + client.onHandleResponse(); + } catch (Exception e) { + LogUtils.i("鎺ユ敹绾跨▼寮傚父锛�"+e.getMessage()); + } + } + } + }); + } + + + /** + * 鍙戦�佹暟鎹� + * @param ipAddress 鐩殑鐨処P鍦板潃 + * @param port 绔彛 + * @param msg 鍙戦�佹暟鎹� + * @param listener 鍙戦�佸洖璋� + */ + public void sendMsg(String ipAddress,int port,byte[] msg, SendListener listener) { + sendMsg(ipAddress,port, msg, true, listener); + } + + /** + * 鍙戦�佹暟鎹� + * @param ipAddress 鐩殑鐨処P鍦板潃 + * @param port 绔彛 + * @param msg 鍙戦�佹暟鎹� + */ + public void sendMsg(String ipAddress,int port,byte[] msg) { + sendMsg(ipAddress,port, msg, true, null); + } + + /** + * 鍙戦�佹暟鎹� + * @param ipAddress 鐩殑IP鍦板潃 + * @param port 绔彛 + * @param msg 鍙戦�佺殑鏁版嵁 + * @param isRefreshRetry 鏄惁瑕侀噸鍙� + * @param listener 鍙戦�佸洖璋� + */ + public void sendMsg(String ipAddress,int port, byte[] msg, boolean isRefreshRetry, SendListener listener) { + if (isRefreshRetry) { + //閲嶇疆杩炴帴娆℃暟 + resendCount.set(0); + } + try { + SocketRequest request = new SocketRequest(msg); + if (listener != null && !TextUtils.isEmpty(request.getAction())) { + sendMap.put(request.getAction(), listener); + } + client.sendMsg(ipAddress,port, msg); + } catch (Exception e) { + LogUtils.e("鍙戦�佸け璐�:" + e.getMessage()); + } + } + + /** + * 鍏抽棴褰撳墠socket + */ + public synchronized void close() { + isOpenRetry.set(false); + sendMap.clear(); + receiveThread.shutdown(); + receiveThread=null; + client.close(); + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java new file mode 100644 index 0000000..38ad296 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/udp/UdpSocketOptions.java @@ -0,0 +1,32 @@ +package com.hdl.sdk.link.socket.udp; + + +import android.net.wifi.WifiManager; + +import com.hdl.sdk.link.socket.codec.IHandleMessage; + +/** + * Created by hxb on 2021/12/12. + */ +public class UdpSocketOptions { + + //澶勭悊鏁版嵁 + private IHandleMessage handleMessage; + private WifiManager wifiManager; + + public IHandleMessage getHandleMessage() { + return handleMessage; + } + + public void setHandleMessage(IHandleMessage handleMessage) { + this.handleMessage = handleMessage; + } + + public WifiManager getWifiManager() { + return wifiManager; + } + + public void setWifiManager(WifiManager wifiManager) { + this.wifiManager = wifiManager; + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java new file mode 100644 index 0000000..957bac3 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/HDLLinkLocalZigBee.java @@ -0,0 +1,392 @@ +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 TAG = "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; + try { + 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);//璁℃椂缁撴潫鏍囪 + } + + } + } + } + } catch (Exception e) { + LogUtils.e(TAG, "鎺ユ敹鐨勬暟鎹唴瀹�:" + zigbeeResponse.getData() + " 寮傚父淇℃伅:" + e.getMessage()); + } + } + } + }; + 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/PanelVibrationBean.java new file mode 100644 index 0000000..11b6f86 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/TimeDataBean.java new file mode 100644 index 0000000..634c3ab --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBBaseSendBean.java new file mode 100644 index 0000000..814b610 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java new file mode 100644 index 0000000..1536506 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceBean.java @@ -0,0 +1,565 @@ +package com.hdl.sdk.link.zigbee.bean; + +import androidx.annotation.NonNull; +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 ; + + private String linkSid; + private String linkSpk; + private String linkOid; + private String linkName; + + public ZBDeviceBean() { + } + + public ZBDeviceBean(String linkSid, String linkSpk, String linkOid, String linkName) { + this.linkSid = linkSid; + this.linkSpk = linkSpk; + this.linkOid = linkOid; + this.linkName = linkName; + } + + public String getLinkSid() { + return linkSid == null ? "" : linkSid; + } + + public void setLinkSid(@NonNull String linkSid) { + this.linkSid = linkSid; + } + + public String getLinkSpk() { + return linkSpk == null ? "" : linkSpk; + } + + public void setLinkSpk(@NonNull String linkSpk) { + this.linkSpk = linkSpk; + } + + public String getLinkOid() { + return linkOid == null ? "" : linkOid; + } + + public void setLinkOid(@NonNull String linkOid) { + this.linkOid = linkOid; + } + + public String getLinkName() { + return linkName == null ? "" : linkName; + } + + public void setLinkName(@NonNull String linkName) { + this.linkName = linkName; + } + + public String getTemplateAddr() { + return templateAddr == null ? "" : templateAddr; + } + + public void setTemplateAddr(String templateAddr) { + this.templateAddr = templateAddr; + } + + @NonNull + public String getGatewayMac() { + return gatewayMac == null ? "" : gatewayMac; + } + + public void setGatewayMac(@NonNull String gatewayMac) { + this.gatewayMac = gatewayMac; + } + + public int getDevice_ID() { + return Device_ID; + } + + public void setDevice_ID(int Device_ID) { + this.Device_ID = Device_ID; + } + + @NonNull + public String getDeviceAddr() { + return DeviceAddr == null ? "" : DeviceAddr; + } + + public void setDeviceAddr(@NonNull 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; + } + + @NonNull + public String getMacName() { + return MacName == null ? "" : MacName; + } + + public void setMacName(@NonNull String MacName) { + this.MacName = MacName; + } + + @NonNull + public String getDeviceName() { + return DeviceName == null ? "" : DeviceName; + } + + public void setDeviceName(@NonNull String DeviceName) { + this.DeviceName = DeviceName; + } + + public int getIsOnline() { + return IsOnline; + } + + public void setIsOnline(int IsOnline) { + this.IsOnline = IsOnline; + } + + @NonNull + public List<InClusterListBean> getInClusterList() { + if (InClusterList == null) { + return new ArrayList<>(); + } + return InClusterList; + } + + public void setInClusterList(@NonNull List<InClusterListBean> InClusterList) { + this.InClusterList = InClusterList; + } + + @NonNull + public List<OutClusterListBean> getOutClusterList() { + if (OutClusterList == null) { + return new ArrayList<>(); + } + return OutClusterList; + } + + public void setOutClusterList(@NonNull List<OutClusterListBean> OutClusterList) { + this.OutClusterList = OutClusterList; + } + + @NonNull + public List<AttributeStatusBean> getAttributeStatus() { + if (AttributeStatus == null) { + return new ArrayList<>(); + } + return AttributeStatus; + } + + public void setAttributeStatus(@NonNull 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; + } + + @NonNull + public String getGwId() { + return GwId == null ? "" : GwId; + } + + public void setGwId(@NonNull 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; + } + + @NonNull + public String getManufacturerName() { + return ManufacturerName == null ? "" : ManufacturerName; + } + + public void setManufacturerName(@NonNull String ManufacturerName) { + this.ManufacturerName = ManufacturerName; + } + + @NonNull + public String getModelIdentifier() { + return ModelIdentifier == null ? "" : ModelIdentifier; + } + + public void setModelIdentifier(@NonNull String ModelIdentifier) { + this.ModelIdentifier = ModelIdentifier; + } + + @NonNull + public String getProductCode() { + return ProductCode == null ? "" : ProductCode; + } + + public void setProductCode(@NonNull 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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java new file mode 100644 index 0000000..ea4af5e --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/bean/ZBDeviceModuleBean.java @@ -0,0 +1,32 @@ +//package com.hdl.sdk.link.zigbee.bean; +// +//import androidx.annotation.NonNull; +// +//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; +// } +// +// @NonNull +// public List<ZBDeviceBean> getDeviceLoopList() { +// if (deviceLoopList == null) { +// return new ArrayList<>(); +// } +// return deviceLoopList; +// } +// +// public void setDeviceLoopList(@NonNull List<ZBDeviceBean> deviceLoopList) { +// this.deviceLoopList = deviceLoopList; +// } +//} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/HDLZBCallBack.java new file mode 100644 index 0000000..7c21660 --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/callback/ZBDeviceListCallBack.java new file mode 100644 index 0000000..2bdec6b --- /dev/null +++ b/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/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java new file mode 100644 index 0000000..2be9bda --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZBDeviceType.java @@ -0,0 +1,161 @@ +package com.hdl.sdk.link.zigbee.config; + +/** + * Created by jlchen on 12/29/21. + */ + +import androidx.annotation.IntDef; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * ZigBee璁惧绫诲瀷 + * device_ID 瀵瑰簲鐨勮澶囨灇涓� + */ +@IntDef({ZBDeviceType.UnKown}) +@Retention(RetentionPolicy.SOURCE) +public @interface ZBDeviceType{ + int UnKown = 0x9999; + int ZbGateway = 0x9998; + /// <summary> + /// 骞茬粨鐐� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + int OnOffSwitch = 0; + /// <summary> + /// 浜害鎺у埗寮�鍏� + /// <para>璁惧ID涓�2</para> + /// <para>瀹氫箟瀵硅薄 LevelControlSwitch</para> + /// </summary> + int LevelControlSwitch = 1; + /// <summary> + /// 缁х數鍣� + /// <para>璁惧ID涓�2</para> + /// <para>瀹氫箟瀵硅薄锛歍oggleLight</para> + /// </summary> + int OnOffOutput = 2; + /// <summary> + /// 闂ㄩ攣 + /// <para>璁惧ID涓�10</para> + /// <para>瀹氫箟瀵硅薄锛欴oorLock</para> + /// </summary> + int DoorLock = 10; + /// <summary> + /// 璁惧ID涓�257鐨勮澶� + /// <para>璋冨厜鐏細鏀寔浜害</para> + /// <para>璋冨厜璁惧</para> + /// </summary> + int DimmableLight = 257; + /// <summary> + /// 璁惧ID涓�258鐨勮澶� + /// <para>鑹叉俯鐏�</para> + /// <para>瀹氫箟瀵硅薄锛欳olorTemperatureLight</para> + /// </summary> + int ColorTemperatureLight = 258; + /// <summary> + /// 璋冨厜鍣ㄦ帶鍒跺櫒 + /// <para>璁惧ID涓�260</para> + /// <para>瀹氫箟瀵硅薄 DimmerSwitch</para> + /// </summary> + int DimmerSwitch = 260; + /// <summary> + /// 棰滆壊璋冨厜鐏紑鍏� + /// <para>璁惧ID涓�261</para> + /// <para>瀹氫箟瀵硅薄 LevelControlSwitch</para> + /// </summary> + int ColorDimmerSwitch = 261; + /// <summary> + /// 绐楀笜璁惧ID + /// <para>Rollershade:鍗峰笜</para> + /// </summary> + int WindowCoveringDevice = 514; + /// <summary> + /// 绐楀笜鎺у埗鍣ㄨ澶嘔D + /// <para>CurtainController:绐楀笜鎺у埗鍣�</para> + /// </summary> + int WindowCoveringController = 515; + /// <summary> + /// 璁惧ID涓�528鐨勮澶� + /// <para>棰滆壊璋冨厜鐏細鏀寔浜害/鑹插害/楗卞拰搴�</para> + /// <para>璋冨厜璁惧</para> + /// <para>瀹氫箟瀵硅薄锛欳olorDimmableLight</para> + /// </summary> + int ColorDimmableLight = 528; + /// <summary> + /// 鎭掓俯鍣� + /// <para>璁惧ID涓�769</para> + /// <para>瀹氫箟瀵硅薄锛欰C</para> + /// </summary> + int Thermostat = 769; + /// <summary> + /// <para>娓╂箍搴︿紶鎰熷櫒</para> + /// <para>璁惧ID涓�770</para> + /// <para>瀹氫箟瀵硅薄锛歍emperatureSensor</para> + /// <para>娉ㄦ剰瀹冧笌HumiditySensor涓嶄竴鏍�;瀹冨叿浣撴槸娓╁害杩樻槸婀垮害;闇�瑕佸彂鍛戒护鍘昏鍙�</para> + /// </summary> + int TemperatureSensor = 770; + /// <summary> + /// <para>PM2.5浼犳劅鍣�</para> + /// <para>璁惧ID涓�777</para> + /// <para>瀹氫箟瀵硅薄锛歅MSensor</para> + /// </summary> + int PMSensor = 777; + /// <summary> + /// 瀹夐槻璁惧 + /// <para>璁惧ID涓�1026鐨勮澶�</para> + /// <para>瀹氫箟瀵硅薄锛欼ASZone</para> + /// </summary> + int IASZone = 1026; + /// <summary> + /// 铚傞福鍣� + /// <para>璁惧ID涓�1027鐨勮澶�</para> + /// <para>瀹氫箟瀵硅薄锛欱uzzer</para> + /// </summary> + int Buzzer = 1027; + /// <summary> + /// 鎺у埗婧愯澶� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + int OtaPanelDevice = 49152; + /// <summary> + /// 鎺у埗婧愯澶� + /// <para>璁惧ID涓�0</para> + /// <para>瀹氫箟瀵硅薄锛歅anel</para> + /// </summary> + int OtaDevice = 49153; + /// <summary> + /// 绌烘皵寮�鍏� + /// </summary> + int AirSwitch = 53249; + /// <summary> + /// 涓户鍣� + /// </summary> + int Repeater = 53250; + /// 杞崲鍣� + /// <para>璁惧ID涓�53251</para> + /// <para>瀹氫箟瀵硅薄锛歍ransverter</para> + /// </summary> + int Transverter = 0xD003; + /// <summary> + /// <para>鏅捐。鏋�</para> + /// <para>璁惧ID涓�0xD004 </para> + /// <para>瀹氫箟瀵硅薄锛欰irer</para> + /// </summary> + int Airer = 0xD004; + + /// 鏂伴 + /// <para>璁惧ID涓�53504</para> + /// <para>瀹氫箟瀵硅薄锛欶reshAirAC</para> + /// </summary> + int FreshAir = 0xD100; + + /// <summary> + /// <para>婀垮害浼犳劅鍣�</para> + /// <para>璁惧ID涓�53760</para> + /// <para>瀹氫箟瀵硅薄锛欻umiditySensor</para> + /// <para>娉ㄦ剰瀹冧笌TemperatureSensor涓嶄竴鏍�;杩欎釜id瀹氭浜嗗氨鏄箍搴︿紶鎰熷櫒</para> + /// </summary> + int HumiditySensor = 0xD200; +} \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java new file mode 100644 index 0000000..b4426de --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/zigbee/config/ZigBee.java @@ -0,0 +1,88 @@ +package com.hdl.sdk.link.zigbee.config; + +import androidx.annotation.IntDef; +import androidx.annotation.StringDef; + +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"; +// +// } + + /** + * 鍥炲涓婚 + */ + @StringDef({}) + @Retention(RetentionPolicy.SOURCE) + public @interface ReplyTopicType { + //鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) + String GwLinuxLocate = "GwLinuxLocate_Respon"; + //璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 + String GetDeviceInfo = "DeviceInfoRespon"; + //鑾峰彇鍏ョ綉璁惧 + String SearchNewDevice = "Device/SearchNewDevice"; + //淇敼璁惧绔彛锛堟寜閿級鍚嶇О + String DeviceRename = "DeviceRenameRespon"; + //璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� + String RemoveDevice = "RemoveDeviceRespon"; + //璁惧鎺у埗-鏃� Id-3-identify 瀹氫綅鍔熻兘 + String Identify = "Identify"; + //瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃� + String SetEPDeviceFunctionType = "Device/SetEPDeviceFunctionType"; + //鏂拌澶囧叆缃� + String DeviceInComingRespon = "DeviceInComingRespon"; + //璁剧疆鍏ョ綉娴佺▼鏂瑰紡 + String SetJoiningModeRespon = "SetJoiningMode_Respon"; + + } + + /** + * 鎺у埗鐮� + */ + @IntDef({CommandType.SearchNewDevice}) + @Retention(RetentionPolicy.SOURCE) + public @interface CommandType { + //鍙戦�佹寚浠ゅ埌缃戝叧杩涜瀹氫綅(缃戝叧LED闂儊璇嗗埆) + int GwLinuxLocate = 85; + //璁惧鍒楄〃-鑾峰彇鏈湴缃戝叧璁惧 EPDeviceId 鍒楄〃 + int GetDeviceInfo = 93; + //鑾峰彇鍏ョ綉璁惧 + int SearchNewDevice = 94; + //淇敼璁惧绔彛锛堟寜閿級鍚嶇О + int DeviceRename = 96; + //璁惧鍒楄〃-璁惧鍒犻櫎锛堜娇璁惧绂荤綉锛� + int RemoveDevice = 99; + //瀵圭鐐瑰洖璺澶囧姛鑳界被鍨嬭繘琛岃缃� + int SetEPDeviceFunctionType = 110; + + } + +} diff --git a/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml b/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml new file mode 100644 index 0000000..25f17da --- /dev/null +++ b/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="HDL_DATA_ERROR">鍙傛暟寮傚父</string> + <string name="HDL_DATA_NULL_ERROR">鍙傛暟涓嶈兘涓虹┖</string> + <string name="HDL_AUTH_ERROR">璁よ瘉澶辫触</string> + <string name="HDL_SEND_ERROR">鍙戦�佸け璐�</string> + <string name="HDL_TIMEOUT_ERROR">瓒呮椂锛岀綉鍏虫棤鍥炲</string> + <string name="HDL_UNAUTHORIZED_ERROR">鏈璇侊紝璇峰厛璁よ瘉</string> + <string name="HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED">璁よ瘉澶辫触锛岀綉鍏虫湭娉ㄥ唽鍒颁簯绔�</string> + <string name="HDL_SEARCH_GATEWAY_TIMEOUT_ERROR">鎼滅储缃戝叧澶辫触锛岃秴鏃�</string> + <string name="HDL_AUTH_MAC_KEY_ERROR">璁よ瘉澶辫触锛岃MAC瀵瑰簲鐨勮澶囧瘑閽ヤ笉瀛樺湪</string> + <string name="HDL_DATA_PARSING_ERROR">鏁版嵁瑙f瀽寮傚父</string> + <string name="HDL_GET_DEVICE_LIST_ERROR">鑾峰彇璁惧鍒楄〃澶辫触</string> + <string name="HDL_GET_FUNCTION_LIST_ERROR">鑾峰彇鍔熻兘鍒楄〃澶辫触</string> + <string name="HDL_GET_FUNCTION_PROPERTIES_ERROR">鑾峰彇鍔熻兘灞炴�уけ璐�</string> + <string name="HDL_CONTROL_FAILURE_ERROR">鎺у埗澶辫触</string> + <string name="HDL_GET_GATEWAY_FAILURE_ERROR">鑾峰彇缃戝叧鍒楄〃澶辫触</string> + <string name="HDL_GET_Zigbee_FAILURE_ERROR">鍙戦�佽秴鏃讹紝缃戝叧鏃犲搷搴�</string> + <string name="HDL_GATEWAY_NOT_EXIST">缃戝叧涓嶅瓨鍦�</string> + <string name="HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR">鑾峰彇鍘熺敓璁惧鍒楄〃澶辫触</string> + <string name="HDL_MILLIMETER_NOT_EXIST">姣背娉笉瀛樺湪</string> + <string name="HDL_UNKOWN_CODE">鏈煡閿欒</string> + <string name="HDL_APPLICATION_EXCEPTION">绯荤粺寮傚父</string> + <string name="HDL_TOPIC_NOT_RIGHT">涓婚娌℃湁鍖归厤</string> + <string name="HDL_OBJECT_NOT_SUPPORT">瀵硅薄涓嶆敮鎸�</string> + <string name="HDL_GATEWAY_REMOTE_NOT_RESPONSE">缃戝叧鏈湴杩炴帴澶辫触锛岄�氳繃杩滅▼閫氳涓嶅洖澶�</string> +</resources> \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/res/values/arrays-error.xml b/HDLLinkLocalSdk/src/main/res/values/arrays-error.xml new file mode 100644 index 0000000..0260f1f --- /dev/null +++ b/HDLLinkLocalSdk/src/main/res/values/arrays-error.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="gateway"></string-array> + <string-array name="cloud"></string-array> + <string-array name="app"></string-array> +</resources> \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/res/values/strings_code.xml b/HDLLinkLocalSdk/src/main/res/values/strings_code.xml new file mode 100644 index 0000000..ca99860 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/res/values/strings_code.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> +<string name="HDL_DATA_ERROR">Parameter exception</string> +<string name="HDL_DATA_NULL_ERROR">Parameter cannot be empty</string> +<string name="HDL_AUTH_ERROR">Authentication failed</string> +<string name="HDL_SEND_ERROR">fail in send</string> +<string name="HDL_TIMEOUT_ERROR">timeout,gateway no response</string> +<string name="HDL_UNAUTHORIZED_ERROR">Not certified, please authenticate first</string> +<string name="HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED">Authentication failed. The gateway is not registered to the cloud</string> +<string name="HDL_SEARCH_GATEWAY_TIMEOUT_ERROR">Failed to search gateway, timeout</string> +<string name="HDL_AUTH_MAC_KEY_ERROR">Authentication failed. The device key corresponding to the MAC does not exist</string> +<string name="HDL_DATA_PARSING_ERROR">Data parsing error</string> +<string name="HDL_GET_DEVICE_LIST_ERROR">Failed to get device list</string> +<string name="HDL_GET_FUNCTION_LIST_ERROR">Failed to get function list</string> +<string name="HDL_GET_FUNCTION_PROPERTIES_ERROR">Failed to get function attribute</string> +<string name="HDL_CONTROL_FAILURE_ERROR">Control failure</string> +<string name="HDL_GET_GATEWAY_FAILURE_ERROR">Failed to get gateway list</string> +<string name="HDL_GET_Zigbee_FAILURE_ERROR">Sending timeout, no response from gateway</string> +<string name="HDL_GATEWAY_NOT_EXIST">Gateway does not exist</string> +<string name="HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR">Failed to get the device list</string> +<string name="HDL_MILLIMETER_NOT_EXIST">Millimeter does not exist</string> +<string name="HDL_UNKOWN_CODE">Unkown Error</string> +<string name="HDL_APPLICATION_EXCEPTION">System Exception</string> +<string name="HDL_TOPIC_NOT_RIGHT">Theme does not match</string> +<string name="HDL_OBJECT_NOT_SUPPORT">Object not supported</string> +<string name="HDL_GATEWAY_REMOTE_NOT_RESPONSE">Gateway local connection failed, unable to reply through remote communication</string> +</resources> \ No newline at end of file diff --git a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java index fb3a685..693ae32 100644 --- a/app/src/main/java/com/hdl/photovoltaic/HDLApp.java +++ b/app/src/main/java/com/hdl/photovoltaic/HDLApp.java @@ -13,6 +13,8 @@ import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; import com.hdl.photovoltaic.utils.PermissionUtils; import com.hdl.photovoltaic.utils.SharedPreUtils; +import com.hdl.sdk.link.core.connect.HDLUdpConnect; +import com.hdl.sdk.link.core.utils.QueueUtils; import java.util.HashMap; import java.util.Objects; @@ -90,6 +92,7 @@ // NetWorkUtil.init(this); // //10.鍒濆鍖栨瀬鍏夋帹閫� // initJPush(); + initSocket(); } /** @@ -99,6 +102,10 @@ HDLUniMPSDKManager.getInstance().initDCUniMPSDK(this); } - + //鍒濆鍖杝ocket鍙婂惎鍔ㄥ鐞嗘帴鏀跺埌鏁版嵁鐨勫鐞嗘柟娉� + private void initSocket() { + QueueUtils.getInstance().start(); + HDLUdpConnect.getInstance().initUdp(); + } } diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java index c16a5ad..da64b67 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java @@ -14,8 +14,15 @@ import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; import com.hdl.photovoltaic.ui.bean.InverterDeviceBean; import com.hdl.photovoltaic.ui.bean.OidBean; +import com.hdl.photovoltaic.uni.HDLUniMP; +import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; /** @@ -222,6 +229,15 @@ } } }); + } + + public void searchGateway(GatewayCallBack gatewayCallBack) + { + List<String> spks = new ArrayList<>(); + spks.add("energy.hdl_inverter"); + //缃戝叧鎼滅储 + HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); + } } diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java index 367cfb5..f362488 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -11,6 +11,13 @@ import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; import com.hdl.photovoltaic.utils.WifiUtils; +import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; @@ -57,8 +64,12 @@ } org.json.JSONObject jsonObject = getJSONObject(data); String type_value = ""; + String oid=""; if (jsonObject.has("type")) { type_value = jsonObject.getString("type"); + } + if (jsonObject.has("oid")) { + oid = jsonObject.getString("oid"); } if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) { @@ -90,10 +101,29 @@ } break; case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: { - //鑾峰彇璁惧鍒楄〃 + //缃戝叧鎼滅储 + HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { + @Override + public void onSuccess(List<GatewayBean> gatewayBeanList) { + HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); + callBackBaseBean.setTopic(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL); + callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST); + callBackBaseBean.setData(gatewayBeanList); + sendUni(callBackBaseBean); + } + + + @Override + public void onError(HDLLinkException e) { + //鍙戦�佸け璐� + } + }); } break; + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND:{ + //鍙戦�乵odbus鍗忚 + } } } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) { @@ -232,6 +262,7 @@ return new JSONObject(); } String json = new Gson().toJson(obj); + return new JSONObject(json); } catch (Exception e) { return new JSONObject(); diff --git a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java index ed79307..1bc3474 100644 --- a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java +++ b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java @@ -33,6 +33,7 @@ public final static String UNI_EVENT_REPLY_DEVICE_ADD = "add";//璁惧娣诲姞 public final static String UNI_EVENT_REPLY_DEVICE_DEL = "del";//璁惧鍒犻櫎 public final static String UNI_EVENT_REPLY_DEVICE_OID = "oid";//璁惧銆愬寘鎷笅鎸傝澶囥�憃id鍒楄〃 + public final static String UNI_EVENT_REPLY_DEVICE_MODBUS_SEND="modbus_send";//modbus鍗忚 /*********Wifi妯″潡*********/ //鍗敠瀹氫箟 public final static String UNI_EVENT_REPLY_WIFI_MODEL = "uni_wifi_model";//wifi妯″潡 diff --git a/local.properties b/local.properties index 1a98706..72f7e7a 100644 --- a/local.properties +++ b/local.properties @@ -7,4 +7,4 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -sdk.dir=/Users/wenjucheng/Library/Android/sdk \ No newline at end of file +sdk.dir=/Users/hdl/Library/Developer/Xamarin/android-sdk-macosx \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c8e8029..ed709be 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ rootProject.name = "PhotovoltaicDebug" include ':app' include ':third-zxing' +include ':HDLLinkLocalSdk' -- Gitblit v1.8.0