From b397edee2be2dfcc3f28eeac50298b4de26b1afa Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 13 十二月 2024 16:53:45 +0800 Subject: [PATCH] 取水口日取水量表中,出现一些大数,明显不正确,发析系统日志,发现一些阀控器会上报一些累计流量为0的数据,且无规律,推测是其不能从水表读取到累计流量时会上报0值。如果间歇上报0值,间歇上报一些非0值,非0值减去0值,就会出现大数,一天中出现几次那么会大数进行累加,数值将更大。为此变更算法,规避这种情况,但也会丢失一些流量值。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/PrefixedDataAvailableV202404.java | 32 +++++++++++++++++++------------- 1 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/PrefixedDataAvailableV202404.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/PrefixedDataAvailableV202404.java index de21587..c2a258c 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/PrefixedDataAvailableV202404.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/PrefixedDataAvailableV202404.java @@ -8,10 +8,12 @@ import org.apache.logging.log4j.Logger; import org.apache.mina.core.buffer.BufferDataException; import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.session.IoSession; @AnnotationPrefixedDataAvailable( protocolName = ProtocolConstantV206V202404.protocolName, + protocolVersion = ProtocolConstantV206V202404.protocolVer, priority = ProtocolConstantV206V202404.priority, onLineDataMinLength = ProtocolConstantV206V202404.onLineDataMinLength, headMinLength = ProtocolConstantV206V202404.headMinLength) @@ -21,6 +23,7 @@ private static final Logger log = LogManager.getLogger(PrefixedDataAvailableV202404.class) ; private static final String protocolName = ProtocolConstantV206V202404.protocolName ; + private static final short protocolVersion = ProtocolConstantV206V202404.protocolVer ; /** @@ -32,10 +35,11 @@ * @return 涓嶆槸鏈崗璁暟鎹椂杩斿洖绌� * @throws Exception 寮傚父 */ - public PrefixedDataAvailableStatus forOnLine(IoBuffer in, - int remain, - int minDataLength, //瀵瑰簲ProtocolConstantV2_0.onLineDataMinLength - int maxDataLength //瀵瑰簲ProtocolConstant.errorMaxLength + public PrefixedDataAvailableStatus forOnLine(IoSession ioSession, + IoBuffer in, + int remain, + int minDataLength, //瀵瑰簲ProtocolConstantV2_0.onLineDataMinLength + int maxDataLength //瀵瑰簲ProtocolConstant.errorMaxLength ) throws Exception { int oldPosition = in.position() ; @@ -44,7 +48,7 @@ //in.position(0) ;//閿欒鐢ㄦ硶锛屽鏋滃彂鐢熺矘鍖呮暟鎹紝灏嗕細姝诲惊鐜� in.position(oldPosition) ; - return this.doForData(preByte, minDataLength, maxDataLength) ; + return this.doForData(ioSession, preByte, minDataLength, maxDataLength) ; } /** @@ -57,28 +61,30 @@ * @throws Exception 寮傚父 */ @Override - public PrefixedDataAvailableStatus forUpData(IoBuffer in, - int remain, - int minDataLength, - int maxDataLength) throws Exception { + public PrefixedDataAvailableStatus forUpData(IoSession ioSession, + IoBuffer in, + int remain, + int minDataLength, + int maxDataLength) throws Exception { int oldPosition = in.position() ; byte[] preByte = new byte[remain]; in.get(preByte) ; //in.position(0) ;//閿欒鐢ㄦ硶锛屽鏋滃彂鐢熺矘鍖呮暟鎹紝灏嗕細姝诲惊鐜� in.position(oldPosition) ; - return this.doForData(preByte, minDataLength, maxDataLength) ; + return this.doForData(ioSession, preByte, minDataLength, maxDataLength) ; } /** * 杩涜鍒ゆ柇 + * @param ioSession ioSession * @param preByte byte[] * @param minDataLength 鏈�灏忔暟鎹暱搴� * @param maxDataLength 鏈�澶ф暟鎹暱搴� * @return PrefixedDataAvailableStatus * @throws Exception 寮傚父 */ - private PrefixedDataAvailableStatus doForData(byte[] preByte, int minDataLength, int maxDataLength) throws Exception{ + private PrefixedDataAvailableStatus doForData(IoSession ioSession, byte[] preByte, int minDataLength, int maxDataLength) throws Exception{ int remain = preByte.length ; if (remain < minDataLength) { @@ -114,11 +120,11 @@ if(remain == frameLen){ //涓嶆柇涓嶇矘 - return new PrefixedDataAvailableStatus().completed(frameLen) ; + return new PrefixedDataAvailableStatus().completed(frameLen, protocolName, protocolVersion) ; }else if(remain > frameLen){ String headHex = ByteUtil.bytes2Hex(preByte, true) ; log.warn("鏀跺埌鏁版嵁涔嬪抚鍓嶉儴锛�" + headHex + "锛屼絾鍙戠敓绮樺寘鐜拌薄銆�") ; - return new PrefixedDataAvailableStatus().adjoined(frameLen) ; + return new PrefixedDataAvailableStatus().adjoined(frameLen, protocolName, protocolVersion) ; }else{ // remain < dataLen String headHex = ByteUtil.bytes2Hex(preByte, true) ; -- Gitblit v1.8.0