From 2ef075d66cf5bc95562f2e584ed6283776062f24 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 24 十一月 2023 10:25:38 +0800 Subject: [PATCH] 1、优化通信中间件代码; 2、实现功能码71协议(查询阀门状态) --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java | 53 ++++++++++++++++++----------------------------------- 1 files changed, 18 insertions(+), 35 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java index 9a28b35..5a6cb09 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_02_Down.java @@ -2,17 +2,15 @@ import com.dy.common.mw.protocol.*; import com.dy.common.mw.protocol.p206V1_0_0.*; +import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; import com.dy.common.util.ByteUtil; -import com.dy.common.util.ByteUtilUnsigned; -import com.dy.common.util.CRC8_for_2_0; -import com.dy.common.util.DateTime; @AnnotationCodeDown(ifAny={ - CodeV1_0_1.cd_06 + CodeV1_0_1.cd_02 }) public class Cd_02_Down implements CodeParse { - //private static Logger log = LogManager.getLogger(Cd_XY_Down.class); + //private static Logger log = LogManager.getLogger(Cd_02_Down.class); @Override public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { @@ -21,20 +19,18 @@ MidResultToRtu midRs = new MidResultToRtu() ; midRs.protocolName = para.protocolName ;//鍗忚鍚嶇О - midRs.rtuAddr = para.rtuAddr ;//IMEI鍙凤紙鐢典俊骞冲彴璁惧IMEI锛� + midRs.rtuAddr = para.rtuAddr ;//Rtu鍦板潃锛堢數淇″钩鍙拌澶嘔MEI锛� midRs.commandId = para.commandId ;//鍛戒护ID锛屽彂璧峰懡浠ょ殑瀹㈡埛绔�(web绔�)鐢熸垚锛屼互鍖归厤鍛戒护缁撴灉 midRs.downCode = para.commandCode ;//涓嬭鍛戒护鍔熻兘鐮�; midRs.downBuffer = bs ;//涓嬭鍛戒护鏁版嵁 midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//涓嬭鍛戒护鏁版嵁鍗佸叚杩涘埗褰㈠紡 - midRs.hasResponse = true ;//鏄惁鏈夊簲绛� - midRs.maxSendTimes = null ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 - midRs.isCachForOffLine = true ;//RTU涓嶅湪绾匡紝鍛戒护鏄惁缂撳瓨锛屼綆鍔熻�楁椂涓簍rue - - //瀵筊TU涓婅鏁版嵁鐨勫簲绛� midRs.hasResponse = false ;//鏄惁鏈夊簲绛� - midRs.maxSendTimes = 1 ;//瀵筊TU涓婅鏁版嵁搴旂瓟锛屾墍浠ュ彧闇�鍙戜竴娆� + midRs.maxSendTimes = 1 ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 + midRs.isCachForOffLine = false ;//RTU涓嶅湪绾匡紝鍛戒护鏄惁缂撳瓨锛屼綆鍔熻�楁椂涓簍rue + + midRs.isSendFirst = true ;//鍛戒护搴旂瓟锛岄鍏堝彂閫侊紝闃叉RTU閲嶆柊涓婃姤 if(isLowPower != null && isLowPower.booleanValue()){ - //浣庡姛鑰楁椂 + //浣庡姛鑰楁椂锛屽敖蹇彂閫� midRs.isQuickSend = true ; } @@ -42,9 +38,9 @@ } /** * 鏋勯�犱笅琛屾暟鎹� - * @param para - * @return - * @throws Exception + * @param para 鍙傛暟 + * @return 瀛楄妭鏁扮粍 + * @throws Exception 寮傚父 */ public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; @@ -62,34 +58,21 @@ index++ ; bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; - String rtuAddr = para.rtuAddr ; - String rtuAddr1 = rtuAddr.substring(0, 6) ; - String rtuAddr2 = rtuAddr.substring(6) ; - index++ ; - ByteUtil.string2BCD_BE(bsHead, rtuAddr1, index) ; - index += 3 ; - - Integer rtuAddr2Int = Integer.parseInt(rtuAddr2) ; - ByteUtilUnsigned.short2Bytes_BE(bsHead, rtuAddr2Int.shortValue(), index); - index += 2 ; + GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); + index += 5 ; ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; byte[] bs = new byte[7] ; - bs[0] = (byte)0xF2 ; - ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 1) ; + bs[0] = (byte)0xF2 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆� + GlCreate.createTp(bs, 1); bytes = ByteUtil.bytesMerge(bsHead, bs) ; - int len = bytes.length + ProtocolConstantV206V1_0_0.lenTail; - bytes[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; + GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑 - int crc = new CRC8_for_2_0().CRC8(bytes, ProtocolConstantV206V1_0_0.ctrlIndex, bytes.length -1) ; - bs = new byte[ProtocolConstantV206V1_0_0.lenTail] ; - bs[0] = (byte)crc ; - bs[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; - bytes = ByteUtil.bytesMerge(bytes, bs) ; + bytes = GlCreate.createCrcTail(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓� return bytes ; } -- Gitblit v1.8.0