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 |   59 ++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 23 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 257685c..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,12 +78,17 @@
 
     private String replyTopic;
 
-    private boolean useSubThread=false;
+    private boolean useSubThread = false;
 
     public interface HdlSocketListener {
         void onSucceed(Object msg);
 
         void onFailure(HDLLinkCode hdlLinkCode);
+    }
+
+    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);
     }
 
     /**
@@ -98,7 +103,7 @@
      * @param isTcp         鏄惁TCP
      */
     public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port,
-                            LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp) {
+                            LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, boolean useSubThread) {
         this.sendAwaitTime = sendAwaitTime;
         this.maxRetry = maxRetry;
         this.ipAddress = ipAddress;
@@ -107,6 +112,7 @@
         this.replyTopic = linkRequest.getReplyTopic();
         this.listener = listener;
         this.isTcp = isTcp;
+        this.useSubThread = useSubThread;
 
 
         eventListener = new EventListener() {
@@ -118,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");
                         }
@@ -137,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) {
@@ -167,7 +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);
+        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);
         this.mac = mac;
     }
 
@@ -283,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);
             }
@@ -315,7 +325,7 @@
 
     public void send() {
 
-        scheduledFuture= getSendThread().scheduleWithFixedDelay(new Runnable() {
+        scheduledFuture = getSendThread().scheduleWithFixedDelay(new Runnable() {
             @Override
             public void run() {
                 try {
@@ -329,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 {
@@ -402,7 +415,7 @@
                             }
                         }
                     }
-                }catch (Exception e){
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
@@ -429,7 +442,7 @@
     private void notifyFailure(HDLLinkCode hdlLinkCode) {
         //绉婚櫎鐩戝惉
         removeListener();
-        if(scheduledFuture!=null){
+        if (scheduledFuture != null) {
             scheduledFuture.cancel(false);
         }
 //        if (sendThread != null) {
@@ -443,7 +456,6 @@
     }
 
 
-
     //    /**
 //     * 鏀寔姣背绫诲瀷
 //     *
@@ -451,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
@@ -480,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() {
@@ -502,7 +516,7 @@
     private void notifySucceed(Object msg) {
         //绉婚櫎鐩戝惉
         removeListener();
-        if(scheduledFuture!=null){
+        if (scheduledFuture != null) {
             scheduledFuture.cancel(false);
         }
 //        if (sendThread != null) {
@@ -514,7 +528,6 @@
             listener = null;
         }
     }
-
 
 
     public static boolean isInverterTopic(String topic) {

--
Gitblit v1.8.0