mac
2024-01-18 9efc5cef6ff75da58fe450add20ffab044e74b54
HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java
@@ -79,7 +79,7 @@
                try {
                    if (msg instanceof LinkResponse) {
                        LinkResponse linkResponse = (LinkResponse) msg;
                        if (linkResponse.getTopic() == null || !linkResponse.getTopic().contains("custom/native/inverter/")) {
                        if (linkResponse.getTopic() == null || !linkResponse.getTopic().contains("custom/native/inverter/up")) {
                            return;
                        }
                        byte[] data = linkResponse.getByteData();
@@ -102,6 +102,7 @@
                                break;
                            }
                        }
                        EventDispatcher.getInstance().post(topic, modbusResponse);
                        //发布Zigbee原生主题及数据
//                        EventDispatcher.getInstance().post(allTopic, modbusResponse);
@@ -117,6 +118,7 @@
        //registerListener(String.format(TopicConstant.NATIVE_ZIGBEE_UP_SLAVE, "+", "+"), eventListener);
    }
    /**
     * 发送原生数据
     *
@@ -125,6 +127,25 @@
     * @param baseCallBack          结果回调
     */
    public void Send(String gatewayOidOrGatewayId, byte[] payload, final ModbusCallBack baseCallBack) {
        Send(gatewayOidOrGatewayId, payload, 5, baseCallBack);
    }
    /**
     * 发送原生数据
     *
     * @param gatewayOidOrGatewayId 目标网关的oid或者网关Id
     * @param payload               发送数据
     * @param timeout               超时时间(s)
     * @param baseCallBack          结果回调
     */
    public void Send(String gatewayOidOrGatewayId, byte[] payload, int timeout, final ModbusCallBack baseCallBack) {
        if (payload == null || payload.length == 0) {
            if (baseCallBack != null) {
                baseCallBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_NULL_ERROR));
                System.out.println("发送数据时负载数据时空的--->");
            }
            return;
        }
        //如果本地有链接这个网关,则用本地连接
        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(gatewayOidOrGatewayId);
        if (null == gatewayBean) {
@@ -144,14 +165,14 @@
//            request.setCloudTopic(String.format(TopicConstant.NATIVE_MODBUS_DOWN_SLAVE, HDLLinkConfig.getInstance().getGatewayId(), gatewayOidOrGatewayId));
//        }
        request.setReplyTopic("Modbus" + payload[0] + payload[1]);
        long timeout = 2 * 1000;
        long awaitTime = timeout * 1000L;
        new HDLConnectHelper(timeout, 1, gatewayBean.getIp_address(), 8586, request, new HDLConnectHelper.HdlSocketListener() {
        new HDLConnectHelper(awaitTime, 1, gatewayBean.getIp_address(), 8586, request, new HDLConnectHelper.HdlSocketListener() {
            @Override
            public void onSucceed(Object msg) {
                if (msg instanceof byte[]) {
                if (msg instanceof int[]) {
                    if (null != baseCallBack) {
                        baseCallBack.onSuccess((byte[]) msg);
                        baseCallBack.onSuccess((int[]) msg);
                    }
                } else {
                    LogUtils.e("发送Modbus回调对象类型非数组类型,类型是" + msg.getClass());