mac
2023-10-11 907f9314657fd0554fecda06e919b98768b0aeea
HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
@@ -21,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;
@@ -112,7 +114,7 @@
                        /**
                         * 可能返回code属性可能没有   没有的话直接成功  有的话只有200才会成功
                         */
                        if (code == null || code.intValue() == 200 || code.intValue() == 0) {
                        if (code == null || code == 200 || code == 0) {
                            notifySucceed(msg);
                        } else {
                            notifyFailure(ErrorUtils.getByCode(code));
@@ -332,12 +334,20 @@
                                    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()));
                                    }
                                }
                                //本地TCP
                                else {
                                    if (!linkRequest.getTopic().endsWith("heartbeat")) {//心跳主题数据过多,过滤下
                                        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));
                                }
@@ -408,6 +418,7 @@
        }
    }
    /**
     * 支持毫米类型
     *
@@ -433,4 +444,31 @@
            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数组转换成int数组(为了打印出无符号的btye数组数据)
     *
     * @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;
    }
}