vince
2024-01-16 5f92b2034f84caeab9cb6efc61ecbe22407935b4
src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java
@@ -64,6 +64,13 @@
            // 生成粮情信息
            String  hexStr = "";
            InvokeResult message;
            Channel channel = ClientEngine.getChannel();
            if (null == channel) {
                ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort());
                clientEngine.start();
                Thread.sleep(1000);
                channel = clientEngine.getChannel();
            }
            for (int i = 1; i <= cableX; i++) {
                if (1 == i) {
                    start = 255;
@@ -73,13 +80,7 @@
                hexStr = buildGrainCmd(device, i, start, length);
                // 发送命令 TODO----->>>暂时调整为每次创建一个新连接
                //Channel channel = ClientEngine.getChannel(device.getIp());
                Channel channel = null;
                if (null == channel) {
                    ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort());
                    clientEngine.start();
                    Thread.sleep(300);
                    channel = clientEngine.getChannel();
                }
                message = ClientEngine.send2(hexStr, channel);
                log.error("平台------>>>>主控:发送粮情检测命令-{}---{}", message,hexStr);
@@ -90,7 +91,7 @@
                    resp.setCode(500);
                    resp.setMsg("平台------>>>>控制柜:发送粮情检测命令-失败:" + message.getMessage());
                }
                Thread.sleep(500);
                Thread.sleep(3000);
            }
        } catch (Exception e) {
            log.error("粮情检测异常:{}", e);
@@ -155,14 +156,36 @@
        String start = "7e";
        //测温命令--7e 01 00 00 01 00 00 02 00 01 a0 ff ff 66 ff 05 3a 59 7e
        String content = "{id}0000{id}{msgId}000200{id}a0ffff{funId}{start}{length}";
        //7e 0f 00 00 10 5f 00 03 00 0f 10 a0 ff ff 66 ff 05 9e 43 7e
        //7e 06 00 00 06 29 00 02 00 06 a0 ff ff 66 1a 05 58 0f 7e
        String content = "{depotId}0000{id1}{msgId}00{type}00{id2}a0ffff{funId}{start}{length}";
        String type = "02";
        //开始封装消息体-主机ID
        String deviceSn = device.getDeviceSn();
        String depotId = device.getDepotIdSys();
        deviceSn = BytesUtil.intToHexStr1(Integer.valueOf(deviceSn));
        content = content.replace("{id}", deviceSn);
        content = content.replace("{id}", deviceSn);
        content = content.replace("{id}", deviceSn);
        depotId = BytesUtil.intToHexStr1(Integer.valueOf(depotId));
        if(!depotId.equals(deviceSn)){
            type = "03";
            content = content.replace("{depotId}", depotId);
            content = content.replace("{id1}", deviceSn);
            if(deviceSn.toLowerCase().equals("0e".toLowerCase())){
                content = content.replace("{id2}", depotId +"13"+ deviceSn);
                type = "04";
            }else{
                content = content.replace("{id2}", depotId + deviceSn);
            }
            content = content.replace("{type}", type);
        }else{
            content = content.replace("{type}", type);
            content = content.replace("{depotId}", depotId);
            content = content.replace("{id1}", deviceSn);
            content = content.replace("{id2}", deviceSn);
        }
        //命令ID
        String msgIdHex = BytesUtil.intToHexStr1(cur);
        content = content.replace("{msgId}", msgIdHex);
@@ -189,14 +212,34 @@
        String start = "7e";
        //测温命令--7e 01 00 00 01 06 00 02 00 01 a0 ff ff 68 1a 05 88 5c 7e
        String content = "{id}0000{id}{msgId}000200{id}a0ffff{funId}{start}{length}";
        //                {depotId}0000{id1}{msgId}00{type}00{id2}
        String content = "{depotId}0000{id1}{msgId}00{type}00{id2}a0ffff{funId}{start}{length}";
        String type = "02";
        //开始封装消息体-主机ID
        String deviceSn = device.getDeviceSn();
        String depotId = device.getDepotIdSys();
        deviceSn = BytesUtil.intToHexStr1(Integer.valueOf(deviceSn));
        content = content.replace("{id}", deviceSn);
        content = content.replace("{id}", deviceSn);
        content = content.replace("{id}", deviceSn);
        depotId = BytesUtil.intToHexStr1(Integer.valueOf(depotId));
        if(!depotId.equals(deviceSn)){
            type = "03";
            content = content.replace("{depotId}", depotId);
            content = content.replace("{id1}", deviceSn);
            if(deviceSn.toLowerCase().equals("0e".toLowerCase())){
                content = content.replace("{id2}", depotId +"13"+ deviceSn);
                type = "04";
            }else{
                content = content.replace("{id2}", depotId + deviceSn);
            }
            content = content.replace("{type}", type);
        }else{
            content = content.replace("{type}", type);
            content = content.replace("{depotId}", depotId);
            content = content.replace("{id1}", deviceSn);
            content = content.replace("{id2}", deviceSn);
        }
        //命令ID
        String msgIdHex = BytesUtil.intToHexStr1(20);
        content = content.replace("{msgId}", msgIdHex);