wjc
2026-03-31 56f5de5eb6c1501175e7a36b10cf3d1b57284b47
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) {
                        //真实的link数据,不包含透传的原生数据
                        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或者mqtt
                                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");//睡眠毫米波spk
////        typeList.add("sensor.mmv_pose");//姿态毫米波spk
    /// /        typeList.add("sensor.mmv_sleep");//睡眠毫米波spk
    /// /        typeList.add("sensor.mmv_pose");//姿态毫米波spk
//        typeList.add("energy.hdl_inverter");//逆变器spk
//        typeList.add("sensor.mmv_sleep");//睡眠毫米波spk
//        typeList.add("sensor.mmv_pose");//姿态毫米波spk
@@ -480,16 +493,17 @@
    /**
     * 获取除了网关的其它网络设备,上面写的那两个方法不一致getGatewayTypeList,getMillimeterTypeList,统一了下,以免后期出问题
     *
     * @return
     */
    public static List<String> getNotGatewayTypeList(){
    public static List<String> getNotGatewayTypeList() {
        List<String> typeList = new ArrayList<>();
        typeList.add("energy.hdl_inverter");//逆变器spk
        typeList.add("sensor.mmv_sleep");//睡眠毫米波spk
        typeList.add("sensor.mmv_pose");//姿态毫米波spk
        typeList.add("sensor.hdl_mmw_pose");//Wi-Fi毫米波ZT版本
        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) {