From 5f92b2034f84caeab9cb6efc61ecbe22407935b4 Mon Sep 17 00:00:00 2001 From: vince <757871790@qq.com> Date: 星期二, 16 一月 2024 12:14:03 +0800 Subject: [PATCH] 优化主库协议,支持路由 --- src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java | 77 ++++++++++++++++++++++++++++++-------- 1 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java b/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java index 0495501..f0f8637 100644 --- a/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java +++ b/src/main/java/com/fzzy/protocol/youxian0/service/Youxian0GatewayGrainService.java @@ -38,7 +38,7 @@ * @return */ @Override - public synchronized BaseResp syncGrain(BaseReqData reqData) { + public synchronized BaseResp syncGrain(BaseReqData reqData) { BaseResp resp = new BaseResp(); @@ -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); -- Gitblit v1.9.3