From d451118d4be05f180cfe1f99bc5904f74db8cc3f Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期四, 22 二月 2024 15:40:58 +0800
Subject: [PATCH] 引用线上库
---
HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 122 +++++++++++++++++++++++++++++++++-------
1 files changed, 100 insertions(+), 22 deletions(-)
diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
index 18967d5..5793c31 100644
--- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
+++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
@@ -12,6 +12,7 @@
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.ModbusResponse;
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;
@@ -20,6 +21,8 @@
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -113,21 +116,25 @@
*/
if (code == null || code.intValue() == 200 || code.intValue() == 0) {
notifySucceed(msg);
- }else {
+ } else {
notifyFailure(ErrorUtils.getByCode(code));
}
- }
- else if (msg instanceof ZigbeeResponse) {
+ } else if (msg instanceof ZigbeeResponse) {
ZigbeeResponse linkResponse = (ZigbeeResponse) msg;
//TODO 濡傛灉閰嶇疆浠庣綉鍏崇殑淇℃伅锛岄�氳繃涓荤綉鍏宠浆杈撅紝杩欓噷oid瑕佸垽鏂笅
if (replyTopic.equals(linkResponse.getTopic())) {
notifySucceed(linkResponse.getData());
- }
- else{
+ } else {
notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT);
}
- }
- else{
+ } else if (msg instanceof ModbusResponse) {
+ ModbusResponse response = (ModbusResponse) msg;
+ if (replyTopic.equals(response.getTopic())) {
+ notifySucceed(response.getData());
+ } else {
+ notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT);
+ }
+ } else {
notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_OBJECT_NOT_SUPPORT.getCode(), "Object Name:" + msg));
}
} catch (Exception e) {
@@ -152,8 +159,8 @@
* @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);
+ LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, String mac) {
+ this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp);
this.mac = mac;
}
@@ -236,10 +243,9 @@
* @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);
+ 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);
}
-
/**
@@ -260,10 +266,9 @@
* @param linkRequest 鍙戦�佸璞�
* @param isTcp 鏄惁TCP
*/
- public HDLConnectHelper(Long timeout,String ipAddress, LinkRequest linkRequest, boolean isTcp) {
+ public HDLConnectHelper(Long timeout, String ipAddress, LinkRequest linkRequest, boolean isTcp) {
this(timeout, DEF_SEND_ONE, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, null, isTcp);
}
-
/**
@@ -320,21 +325,32 @@
String requestTopic = linkRequest.getCloudTopic();
byte[] encryBytes = null;
GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
- if (gatewayBean != null && getGatewayTypeList().contains(gatewayBean.getGatewayType())) {
- //姣背娉㈣繙绋媘qtt绉橀挜涓嶄竴鏍�
+ if (gatewayBean != null && getNotGatewayTypeList().contains(gatewayBean.getGatewayType())) {
+ /**
+ * 姣背娉㈣繖杈硅幏鍙栨暟鎹殑鏃跺�� 宸茬粡璁剧疆浜嗕富浠庡瘑閽ヨ繘鍘讳簡 杩欒竟涓嶄綔澶勭悊
+ */
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);
+ if (HDLConnectHelper.isInverterTopic(linkRequest.getCloudTopic())) {
+ LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getCloudSendBytes())));
+ } else {
+ LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes()));
+ }
}
- LogUtils.i("杩滅▼鍙戦�佹暟鎹細" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes()));
}
//鏈湴TCP
else {
+ linkRequest.setEncrypt(false);// 2024骞�01鏈�31鏃�16:34:22 榛樿鏄庢枃閫氳,鍥犱负鍒涘缓鐢电珯,缁戝畾閫嗗彉鍣ㄦ椂锛岄渶瑕佽缃弬鏁扮粰閫嗗彉鍣�,杩欐椂鍊欒繕娌℃湁绉橀挜;
if (!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅
- LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes()));
+ if (HDLConnectHelper.isInverterTopic(linkRequest.getTopic())) {
+ LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getSendBytes())));
+ } else {
+ LogUtils.i("鏈湴鍙戦�佹暟鎹細\r\n" + new String(linkRequest.getSendBytes()));
+ }
}
HDLTcpConnect.getTcpSocketBoot(ipAddress).sendMsg(EncryptUtil.getEncryBytes(linkRequest));
}
@@ -405,15 +421,49 @@
}
}
+
+
+// /**
+// * 鏀寔姣背绫诲瀷
+// *
+// * @return 绫诲瀷鍒楄〃
+// */
+// public static List<String> getGatewayTypeList() {
+// List<String> typeList = new ArrayList<>();
+//// typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk
+//// typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk
+// typeList.add("energy.hdl_inverter");//閫嗗彉鍣╯pk
+// typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk
+// typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk
+// typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰
+// return typeList;
+// }
+//
+// public static List<String> getMillimeterTypeList() {
+// List<String> typeList = new ArrayList<>();
+//// typeList.add("AGATEWAY");//缃戝叧
+// typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk
+// typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk
+// typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰
+// return typeList;
+// }
+
/**
- * 鏀寔姣背绫诲瀷
- *
- * @return 绫诲瀷鍒楄〃
+ * 鑾峰彇闄や簡缃戝叧鐨勫叾瀹冪綉缁滆澶囷紝涓婇潰鍐欑殑閭d袱涓柟娉曚笉涓�鑷磄etGatewayTypeList锛実etMillimeterTypeList锛岀粺涓�浜嗕笅锛屼互鍏嶅悗鏈熷嚭闂
+ * @return
*/
- public static List<String> getGatewayTypeList() {
+ public static List<String> getNotGatewayTypeList(){
List<String> typeList = new ArrayList<>();
+ typeList.add("energy.hdl_inverter");//閫嗗彉鍣╯pk
typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk
typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk
+ typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰
+ return typeList;
+ }
+
+ public static List<String> getNewMillimeterTypeList() {
+ List<String> typeList = new ArrayList<>();
+ typeList.add("sensor.hdl_mmw_pose");//Wi-Fi姣背娉T鐗堟湰
return typeList;
}
@@ -429,4 +479,32 @@
listener = null;
}
}
+
+
+
+ public static boolean isInverterTopic(String topic) {
+ if (TextUtils.isEmpty(topic)) {
+ return false;
+ }
+ return topic.endsWith("custom/native/inverter/down_reply")
+ || topic.endsWith("custom/native/inverter/down")
+ || topic.endsWith("custom/native/inverter/up");
+ }
+
+ /**
+ * byte鏁扮粍杞崲鎴恑nt鏁扮粍(涓轰簡鎵撳嵃鍑烘棤绗﹀彿鐨刡tye鏁扮粍鏁版嵁)
+ *
+ * @param bytes 鏁扮粍
+ * @return
+ */
+ public static Integer[] byteArrayConvertIntArray(byte[] bytes) {
+ if (bytes == null || bytes.length == 0) {
+ return new Integer[]{};
+ }
+ Integer[] arr = new Integer[bytes.length];
+ for (int i = 0; i < bytes.length; i++) {
+ arr[i] = bytes[i] & 0xff;
+ }
+ return arr;
+ }
}
--
Gitblit v1.8.0