From ac47ec165d87f505d80761ac92a0ece0ae84d215 Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期五, 26 七月 2024 14:49:15 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_C0_Up.java | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 174 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_C0_Up.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_C0_Up.java new file mode 100644 index 0000000..0116141 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_C0_Up.java @@ -0,0 +1,174 @@ +package com.dy.common.mw.protocol.p206V1_0_0.parse; + +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.DataCdC0Vo; +import com.dy.common.util.ByteUtil; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@AnnotationCodeUp(ifAny={ + CodeV1_0_1.cd_C0 +}) +@SuppressWarnings("unused") +public class Cd_C0_Up implements CodeParse { + + private static final Logger log = LogManager.getLogger(Cd_C0_Up.class); + + /** + * 鍒嗘瀽涓婅鏁版嵁 + */ + @Override + public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { + ParseParamsForUpV1_0_1 para = (ParseParamsForUpV1_0_1)params ; + int bsLen = new CommonV1_0_1().parseDataLen(para.upBuffer) ; + if(bsLen > 0){ + this.doParse(para.upBuffer, + bsLen, + para.upCode, + para.data) ; + } + log.info("鍒嗘瀽涓婅鏁版嵁<" + CodeV1_0_1.getCodeName(para.upCode) + " RTU鍦板潃=" + para.rtuAddr + ">:\n" + para.data.toString()); + + MidResultFromRtu midRs = new MidResultFromRtu() ; + midRs.protocolName = para.protocolName ;//鍗忚鍚嶇О + midRs.rtuAddr = para.rtuAddr ;//Rtu鍦板潃 + midRs.upCode = para.upCode ;//涓婅鏁版嵁涓殑鍔熻兘鐮� + midRs.upHex = para.upHex ;//涓婅鏁版嵁鍗佸叚杩涘埗褰㈠紡 + midRs.upBuffer = para.upBuffer ;//涓婅鏁版嵁瀛楄妭鏁扮粍 + midRs.data = para.data ;//瑙f瀽鍚庣殑鏁版嵁 + + midRs.reportOrResponse_trueOrFalse = true ;//涓诲姩涓婃姤 + + String confirmComCode = para.upCode ; + ParseParamsForDownV1_0_1 downCpParams = new ParseParamsForDownV1_0_1() ; + downCpParams.setValue( + null, + ProtocolConstantV206V1_0_0.protocolName, + para.rtuAddr, + Command.defaultId, + confirmComCode, + null, + null); + //鏋勯�犲簲绛� + byte[] data = new Cd_C0_Down().doParse(downCpParams) ; + + MidResultToRtu confirmCommand = new MidResultToRtu() ; + confirmCommand.protocolName = para.protocolName ;//鍗忚鍚嶇О + confirmCommand.rtuAddr = para.rtuAddr ;//Rtu鍦板潃 + confirmCommand.commandId = Command.defaultId ;//鍛戒护ID锛屽彂璧峰懡浠ょ殑瀹㈡埛绔�(web绔�)鐢熸垚锛屼互鍖归厤鍛戒护缁撴灉 + confirmCommand.downCode = confirmComCode ;//涓嬭鍛戒护鍔熻兘鐮�; + confirmCommand.downBuffer = data ;//涓嬭鍛戒护鏁版嵁 + confirmCommand.downBufHex = ByteUtil.bytes2Hex(data, true) ;//涓嬭鍛戒护鏁版嵁鍗佸叚杩涘埗褰㈠紡 + confirmCommand.hasResponse = false ;//鏄惁鏈夊簲绛� + confirmCommand.maxSendTimes = 1 ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�2娆�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 + 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} ; + } + /** + * 鎵ц鍒嗘瀽 + * @param bs 瀛楄妭鏁扮粍 + * @param bsLen 瀛楄妭闀垮害锛堟�诲寘闀匡紝鍖呮嫭鍖呭ご鍜屽寘灏撅級 + * @param dataCode 鍔熻兘鐮� + * @param data 鏁版嵁 + * @throws Exception 寮傚父 + */ + protected void doParse(byte[] bs, int bsLen, String dataCode, Data data) throws Exception { + DataV1_0_1 dV1 = (DataV1_0_1)data.getSubData() ; + DataCdC0Vo cdData = new DataCdC0Vo() ; + dV1.subData = cdData ; + + boolean hasWaterAmount = true ;//鏄惁鏈夋祦閲忔暟鎹� + boolean hasWaterPress = true ;//鏄惁鏈夋按鍘嬫暟鎹� + boolean hasEleVolt = true ;//鏄惁鏈夌數鍘嬫暟鎹� + boolean hasSignal = true ;//鏄惁鏈変俊鍙峰己搴︽暟鎹� + boolean hasAlarmStatus = true ;//鏄惁鏈夋暟鎹� + + short index = ProtocolConstantV206V1_0_0.dataIndex ; + + byte tmpBt1 = bs[index] ; + index++ ; + /* RTU瀹炵幇涓�瀹氭湁娴侀噺鏁版嵁 + if(((tmpBt1 & 4) >> 2) == 1){ + hasWaterAmount = true ; + } + */ + byte tmpBt2 = bs[index] ; + index++ ; + /*RTU瀹炵幇涓�瀹氭湁涓嬮潰鍚勯」鏁版嵁 + if(((tmpBt2 & 0x10) >> 4) == 1){ + hasAlarmStatus = true ; + } + if(((tmpBt2 & 0x20) >> 5) == 1){ + hasWaterPress = true ; + } + if(((tmpBt2 & 0x40) >> 6) == 1){ + hasEleVolt = true ; + } + if(((tmpBt2 & 0x80) >> 7) == 1){ + hasSignal = true ; + } + */ + if(hasWaterAmount){ + //鐬椂娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999999.999锛屽崟浣嶄负m3/h銆� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.instantAmount = tpInt/1000.0 ; + + index += 5 ; + //绱娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~99999999.99锛屽崟浣嶄负m3銆� + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.totalAmount = tpInt/100.0; + + index += 5 ; + //鎹熷け娴侀噺锛�5瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~9999999999锛屽崟浣嶄负m3銆� + tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; + cdData.lossAmount = tpInt/100.0; + + index += 5 ; + } + if(hasWaterPress){ + //姘村帇锛�4瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~999999.99锛屽崟浣嶄负KPa銆� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; + cdData.waterPress = tpInt/100.0 ; + index += 4 ; + } + if(hasEleVolt){ + //鐢垫睜鐢靛帇锛�2瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~99.99锛屽崟浣嶄负V銆� + //钃勭數姹犵數鍘� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; + cdData.batteryVolt = tpInt/100.0 ; + index += 2 ; + } + if(hasSignal){ + //淇″彿寮哄害锛�1瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~99銆� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index) ; + cdData.signalValue = tpInt ; + index++ ; + } + if(hasAlarmStatus){ + //鎶ヨ鏁版嵁 + cdData.alarmVo = GlParse.parseAlarm(bs, index) ; + index += 2 ; + //鐘舵�佹暟鎹� + cdData.stateVo = GlParse.parseState(bs, index) ; + index += 2 ; + } + + //姘翠环锛�2瀛楄妭BCD鐮侊紝鍙栧�艰寖鍥�0~99.99锛屽崟浣嶄负鍏冦�� + int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; + cdData.waterPrice = tpInt/100.0 ; + + index += 2 ; + cdData.rtuDt = GlParse.parseTp(bs, index) ; + + } +} -- Gitblit v1.8.0