From d736d220008f3ddaed44ac6bfa8a19eb8ca61e96 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期六, 12 十月 2024 14:09:39 +0800 Subject: [PATCH] 1、江海协议功能C2增加订单号数据项; 2、下行命令构造时标TP当月份大于等于10时有错,进行修改。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Up.java | 200 +++++++++++++++++++++---------------------------- 1 files changed, 85 insertions(+), 115 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Up.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Up.java index 296dc3c..b1d6fb2 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Up.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_83_Up.java @@ -3,6 +3,8 @@ 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.GlParse; +import com.dy.common.mw.protocol.p206V1_0_0.upVos.DataCd83CloseVo; +import com.dy.common.mw.protocol.p206V1_0_0.upVos.DataCd83OpenVo; import com.dy.common.util.ByteUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -28,7 +30,7 @@ para.upCode, para.data) ; } - log.info("鍒嗘瀽涓婅鏁版嵁<" + CodeV1_0_1.getCodeName(para.upCode) + " RTU鍦板潃=" + para.rtuAddr + ">:\n" + para.data.toString()); + log.info("\n鍒嗘瀽涓婅鏁版嵁<" + CodeV1_0_1.getCodeName(para.upCode) + " RTU鍦板潃=" + para.rtuAddr + ">:\n" + para.data.toString()); MidResultFromRtu midRs = new MidResultFromRtu() ; midRs.protocolName = para.protocolName ;//鍗忚鍚嶇О @@ -40,9 +42,10 @@ midRs.reportOrResponse_trueOrFalse = true ;//涓诲姩涓婃姤 - String confirmComCode = CodeV1_0_1.cd_C0 ; + String confirmComCode = para.upCode ; ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; downCpParams.setValue( + null, ProtocolConstantV206V1_0_0.protocolName, para.rtuAddr, Command.defaultId, @@ -57,12 +60,18 @@ confirmCommand.rtuAddr = para.rtuAddr ;//Rtu鍦板潃 confirmCommand.commandId = Command.defaultId ;//鍛戒护ID锛屽彂璧峰懡浠ょ殑瀹㈡埛绔�(web绔�)鐢熸垚锛屼互鍖归厤鍛戒护缁撴灉 confirmCommand.downCode = confirmComCode ;//涓嬭鍛戒护鍔熻兘鐮�; + confirmCommand.downCodeName = CodeV1_0_1.getCodeName(confirmComCode) ;//涓嬭鍛戒护鍔熻兘鐮佸悕绉�; confirmCommand.downBuffer = data ;//涓嬭鍛戒护鏁版嵁 confirmCommand.downBufHex = ByteUtil.bytes2Hex(data, true) ;//涓嬭鍛戒护鏁版嵁鍗佸叚杩涘埗褰㈠紡 confirmCommand.hasResponse = false ;//鏄惁鏈夊簲绛� confirmCommand.maxSendTimes = 1 ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�2娆�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 - confirmCommand.isSendFirst = true ;//纭鍛戒护锛屼紭鍏堝彂閫� confirmCommand.isCachForOffLine = false ;//RTU涓嶅湪绾匡紝鍛戒护鏄惁缂撳瓨 + + confirmCommand.isSendFirst = true ;//纭鍛戒护锛屼紭鍏堝彂閫� + if(isLowPower != null && isLowPower.booleanValue()){ + //浣庡姛鑰楁椂锛屽敖蹇彂閫� + confirmCommand.isQuickSend = true ; + } callback.callback(midRs.reportOrResponse_trueOrFalse); return new MidResult[]{midRs, confirmCommand} ; @@ -76,67 +85,46 @@ * @throws Exception 寮傚父 */ protected void doParse(byte[] bs, int bsLen, String dataCode, Data data) throws Exception { - short index = ProtocolConstantV206V1_0_0.dataIndex ; - byte opType = bs[ProtocolConstantV206V1_0_0.dataIndex]; - if(opType == 1 || opType == 3 || opType == 8){ + byte opType = (byte)ByteUtil.BCD2Int_LE(bs[ProtocolConstantV206V1_0_0.dataIndex]) ; + Boolean isCloseType = CommonV1_0_1.isCloseValveType(opType) ; + if(isCloseType != null && isCloseType.booleanValue()){ + this.doParseClose(opType, bs, bsLen, dataCode, data); + }else if(isCloseType != null && !isCloseType.booleanValue()){ this.doParseOpen(opType, bs, bsLen, dataCode, data); }else{ - this.doParseClose(opType, bs, bsLen, dataCode, data); + throw new Exception("寮�鍏抽榾绫诲瀷[" + ByteUtil.bytes2Hex(new byte[]{opType}, false) + "(hex)]涓嶅彲璇嗗埆" ) ; } } private void doParseOpen(byte opType, byte[] bs, int bsLen, String dataCode, Data data) throws Exception { DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; DataCd83OpenVo cdData = new DataCd83OpenVo() ; - dV1.dataCd83OpenVo = cdData ; + dV1.subData = cdData ; cdData.type = opType ; short index = ProtocolConstantV206V1_0_0.dataIndex + 1 ; - //绱娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999999999锛屽崟浣嶄负m3銆� - cdData.totalAmount = 0.0D ; - int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 10000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 1000000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 100000000.0 ; + //绱娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~99999999.99锛屽崟浣嶄负m3銆� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.totalAmount = tpInt/100.0 ; - //鐢ㄦ按鎴峰彿鏁版嵁鏍煎紡锛�5瀛楄妭BCD鐮佷綆浣嶅湪鍓嶉珮浣嶅湪鍚庛�� - cdData.clientNum = ByteUtil.BCD2String_LE(bs, index, index + 4) ; index += 5 ; + //鐢ㄦ按鎴峰彿鏁版嵁鏍煎紡锛�8瀛楄妭浣庝綅鍦ㄥ墠楂樹綅鍦ㄥ悗銆� + cdData.icCardNo = GlParse.parseIcCardNo(bs, index) ; + index += 8 ; //IC鍗″彿鏍煎紡锛�4瀛楄妭HEX鐮佷綆浣嶅湪鍓嶉珮浣嶅湪鍚庛�� - cdData.clientNum = ByteUtil.bytesToHex(bs, index, index + 3) ; + cdData.icCardAddr = ByteUtil.bytes2Hex_LE(bs, false, index, 4) ; + index += 4 ; - //鐢ㄦ按鎴蜂綑棰濓細鐢ㄦ埛浣欓4瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0.00~999999.99锛屽崟浣嶄负鍏冦�� - cdData.remainMoney = 0.0D ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt/100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt * 10000.0 ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; + cdData.remainMoney = tpInt/100.0 ; + index += 4 ; //鐢ㄦ按鎴风敤姘村紑濮嬫椂闂达細6瀛楄妭BCD鐮侊紝椤哄簭鏄勾鏈堟棩鏃跺垎绉掞紝鍏朵腑鍏厓骞�=2000+骞淬�� cdData.openDt = GlParse.parseTp(bs, index) ; - index += 6 ; + index += 6 ; //鎺у埗鍣ㄦ椂閽� cdData.rtuDt = GlParse.parseTp(bs, index) ; //index += 6 ; @@ -145,104 +133,86 @@ private void doParseClose(byte opType, byte[] bs, int bsLen, String dataCode, Data data) throws Exception { DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; DataCd83CloseVo cdData = new DataCd83CloseVo() ; - dV1.dataCd83CloseVo = cdData ; + dV1.subData = cdData ; cdData.type = opType ; short index = ProtocolConstantV206V1_0_0.dataIndex + 1 ; //绱娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999999999锛屽崟浣嶄负m3銆� - cdData.totalAmount = 0.0D ; - int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 10000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 1000000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.totalAmount += tpInt * 100000000.0 ; + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.totalAmount = tpInt/100.0 ; - //鐢ㄦ按鎴峰彿鏁版嵁鏍煎紡锛�5瀛楄妭BCD鐮佷綆浣嶅湪鍓嶉珮浣嶅湪鍚庛�� - cdData.clientNum = ByteUtil.BCD2String_LE(bs, index, index + 4) ; index += 5 ; + //鐢ㄦ按鎴峰彿鏁版嵁鏍煎紡锛�8瀛楄妭浣庝綅鍦ㄥ墠楂樹綅鍦ㄥ悗銆� + cdData.icCardNo = GlParse.parseIcCardNo(bs, index) ; + index += 8 ; //IC鍗″彿鏍煎紡锛�4瀛楄妭HEX鐮佷綆浣嶅湪鍓嶉珮浣嶅湪鍚庛�� - cdData.clientNum = ByteUtil.bytesToHex(bs, index, index + 3) ; + cdData.icCardAddr = ByteUtil.bytes2Hex_LE(bs, false, index, 4) ; + index += 4 ; - //鐢ㄦ按鎴蜂綑棰濓細鐢ㄦ埛浣欓4瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0.00~999999.99锛屽崟浣嶄负鍏冦�� - cdData.remainMoney = 0.0D ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt/100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.remainMoney += tpInt * 10000.0 ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; + cdData.remainMoney = tpInt/100.0 ; + index += 4 ; //鐢ㄦ按鎴风敤姘村紑濮嬫椂闂达細6瀛楄妭BCD鐮侊紝椤哄簭鏄勾鏈堟棩鏃跺垎绉掞紝鍏朵腑鍏厓骞�=2000+骞淬�� cdData.openDt = GlParse.parseTp(bs, index) ; - index += 6 ; + index += 6 ; //鐢ㄦ按鎴风敤姘寸粨鏉熸椂闂达細6瀛楄妭BCD鐮侊紝椤哄簭鏄勾鏈堟棩鏃跺垎绉掞紝鍏朵腑鍏厓骞�=2000+骞淬�� cdData.closeDt = GlParse.parseTp(bs, index) ; + index += 6 ; - //鐢ㄦ按鎴锋湰娆$敤姘撮噺锛氱疮璁℃祦閲�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999999999锛屽崟浣嶄负m3銆� - cdData.thisAmount = 0.0D ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisAmount += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisAmount += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisAmount += tpInt * 10000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisAmount += tpInt * 1000000.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisAmount += tpInt * 100000000.0 ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.thisAmount = tpInt/100.0 ; + index += 5 ; //鐢ㄦ按鎴锋湰娆℃秷璐归噾棰濓細鐢ㄦ埛浣欓4瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0.00~999999.99锛屽崟浣嶄负鍏冦�� - cdData.thisMoney = 0.0D ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisMoney += tpInt/100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisMoney += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisMoney += tpInt * 100.0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisMoney += tpInt * 10000.0 ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; + cdData.thisMoney = tpInt/100.0 ; + index += 4 ; //鐢ㄦ按鎴锋湰娆$敤姘存椂闀匡細鐢ㄦ按鏃堕暱2瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999锛屽崟浣嶄负鍒嗛挓銆� - cdData.thisTime = 0 ; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisTime += tpInt; - tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; - index++ ; - cdData.thisTime += tpInt * 100 ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; + cdData.thisTime = tpInt; + index += 2 ; + cdData.priceType = bs[index] ; + + index++ ; + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; + cdData.price = tpInt/100.0 ; + + index += 2 ; + cdData.cardType = bs[index] ; + + index++ ; //鎺у埗鍣ㄦ椂閽� cdData.rtuDt = GlParse.parseTp(bs, index) ; //index += 6 ; } + + public static void main(String[] args) throws Exception { + Cd_83_Up obj = new Cd_83_Up() ; + String hex = "683C68B08485353448830200000000001000282353FE739444000001000313000101211615000101210000000000000000000200019000011518000101210A7B16"; + byte[] bs = ByteUtil.hex2Bytes(hex) ; + + Data data = new Data() ; + data.setSubData(new DataV1_0_1()) ; + + int bsLen = new CommonV1_0_1().parseDataLen(bs) ; + if(bsLen > 0){ + try { + obj.doParse(bs, + bsLen, + "83", + data) ; + }catch (Exception e){ + e.printStackTrace(); + } + } + System.out.println("data = " + data); + } } -- Gitblit v1.8.0