From 56f5de5eb6c1501175e7a36b10cf3d1b57284b47 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 31 三月 2026 17:13:26 +0800
Subject: [PATCH] 2026年03月31日17:12:34
---
sdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 56 +++++++++++++++++++++++++++++---------------------------
1 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/sdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/sdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
index bd41479..ac20edc 100644
--- a/sdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
+++ b/sdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
@@ -37,7 +37,7 @@
*/
public class HDLConnectHelper {
- private static final String TAG="HDLConnectHelper";
+ private static final String TAG = "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;
@@ -78,7 +78,7 @@
private String replyTopic;
- private boolean useSubThread=false;
+ private boolean useSubThread = false;
public interface HdlSocketListener {
void onSucceed(Object msg);
@@ -88,8 +88,9 @@
public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port,
LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) {
- this(sendAwaitTime,maxRetry,ipAddress,port,linkRequest,listener,isTcp,false);
+ this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp, false);
}
+
/**
* 鍙戦�乁DP鎴栬�匱CP鏁版嵁
*
@@ -102,7 +103,7 @@
* @param isTcp 鏄惁TCP
*/
public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port,
- LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp,boolean useSubThread) {
+ LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, boolean useSubThread) {
this.sendAwaitTime = sendAwaitTime;
this.maxRetry = maxRetry;
this.ipAddress = ipAddress;
@@ -111,7 +112,7 @@
this.replyTopic = linkRequest.getReplyTopic();
this.listener = listener;
this.isTcp = isTcp;
- this.useSubThread=useSubThread;
+ this.useSubThread = useSubThread;
eventListener = new EventListener() {
@@ -123,8 +124,8 @@
LinkResponse linkResponse = (LinkResponse) object;
JSONObject jsonObject = JSON.parseObject(linkResponse.getData());
String id = null;
- Integer code=null;
- if(jsonObject!=null) {
+ Integer code = null;
+ if (jsonObject != null) {
id = jsonObject.getString("id");
code = jsonObject.getInteger("code");
}
@@ -142,11 +143,10 @@
notifySucceed(object);
} else if (object instanceof BusProResponse) {
notifySucceed(object);
- } else if(object instanceof RealLinkResponse){
+ } else if (object instanceof RealLinkResponse) {
//鐪熷疄鐨刲ink鏁版嵁锛屼笉鍖呭惈閫忎紶鐨勫師鐢熸暟鎹�
notifySucceed(object);
- }
- else {
+ } else {
notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_OBJECT_NOT_SUPPORT.getCode(), "Object Name:" + object));
}
} catch (Exception e) {
@@ -172,13 +172,13 @@
*/
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,false);
+ this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp, false);
this.mac = mac;
}
public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port,
- LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, String mac,boolean subThread) {
- this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp,subThread);
+ LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, String mac, boolean subThread) {
+ this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp, subThread);
this.mac = mac;
}
@@ -294,10 +294,9 @@
*/
private void registerListener() {
if (!TextUtils.isEmpty(replyTopic) && null != listener) {
- if(useSubThread){//浣跨敤瀛愮嚎绋嬪洖璋�
+ if (useSubThread) {//浣跨敤瀛愮嚎绋嬪洖璋�
EventDispatcher.getInstance().asyncRegister(replyTopic, eventListener);
- }
- else {
+ } else {
//榛樿鐢ㄤ富绾跨▼
EventDispatcher.getInstance().register(replyTopic, eventListener);
}
@@ -326,7 +325,7 @@
public void send() {
- scheduledFuture= getSendThread().scheduleWithFixedDelay(new Runnable() {
+ scheduledFuture = getSendThread().scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
@@ -340,8 +339,11 @@
//濡傛槸tcp鎴栬�卪qtt
if (isTcp) {
+ //BMS璁惧鏀寔杩滅▼鍙戦�佸懡浠わ紝涓嶆敮鎸佹湰鍦板懡浠わ紝鍚鍚庨潰浼氳皟鏁翠篃鏄湰鍦板彂閫�
+ GatewayBean gateway = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
+ boolean isSupportLocalSendCommands = gateway != null && gateway.isSupportLocalSendCommands();
//mqtt
- if (TextUtils.isEmpty(ipAddress) || !HDLTcpConnect.getTcpSocketBoot(ipAddress).isConnected()) {
+ if (TextUtils.isEmpty(ipAddress) || !HDLTcpConnect.getTcpSocketBoot(ipAddress).isConnected() || !isSupportLocalSendCommands) {
if (!linkRequest.getTopic().endsWith("heartbeat")) {//蹇冭烦涓婚鏁版嵁杩囧锛岃繃婊や笅
//LogUtils.i("蹇冭烦鍖呭彂閫佹暟鎹細\r\n" + new String(linkRequest.getCloudSendBytes()));
} else {
@@ -413,7 +415,7 @@
}
}
}
- }catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -440,7 +442,7 @@
private void notifyFailure(HDLLinkCode hdlLinkCode) {
//绉婚櫎鐩戝惉
removeListener();
- if(scheduledFuture!=null){
+ if (scheduledFuture != null) {
scheduledFuture.cancel(false);
}
// if (sendThread != null) {
@@ -454,7 +456,6 @@
}
-
// /**
// * 鏀寔姣背绫诲瀷
// *
@@ -462,8 +463,9 @@
// */
// public static List<String> getGatewayTypeList() {
// List<String> typeList = new ArrayList<>();
-//// typeList.add("sensor.mmv_sleep");//鐫$湢姣背娉pk
-//// typeList.add("sensor.mmv_pose");//濮挎�佹绫虫尝spk
+
+ /// / 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
@@ -491,16 +493,17 @@
/**
* 鑾峰彇闄や簡缃戝叧鐨勫叾瀹冪綉缁滆澶囷紝涓婇潰鍐欑殑閭d袱涓柟娉曚笉涓�鑷磄etGatewayTypeList锛実etMillimeterTypeList锛岀粺涓�浜嗕笅锛屼互鍏嶅悗鏈熷嚭闂
+ *
* @return
*/
- public static List<String> getNotGatewayTypeList(){
+ 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鐗堟湰
typeList.add("sensor.hdl_mmw_sleep");//Wi-Fi姣背娉㈢潯鐪犵増
- return typeList;
+ return typeList;
}
public static List<String> getNewMillimeterTypeList() {
@@ -513,7 +516,7 @@
private void notifySucceed(Object msg) {
//绉婚櫎鐩戝惉
removeListener();
- if(scheduledFuture!=null){
+ if (scheduledFuture != null) {
scheduledFuture.cancel(false);
}
// if (sendThread != null) {
@@ -525,7 +528,6 @@
listener = null;
}
}
-
public static boolean isInverterTopic(String topic) {
--
Gitblit v1.8.0