From e407fcf19e50ed0972e7262d99da4b3a83d08706 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 11 十月 2024 17:08:23 +0800 Subject: [PATCH] 1、修改协议驱动RTU上行数据解析出错时,RTU上下行数据日志中的RTU地址不正确的bug; 2、83功能码上行数据测试main方法实现。 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java | 49 +++++++++++++++++++++++++++++++++++++------------ 1 files changed, 37 insertions(+), 12 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java index cfbc9e2..2484a8f 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/global/GlParse.java @@ -1,8 +1,9 @@ package com.dy.common.mw.protocol.p206V1_0_0.parse.global; -import com.dy.common.mw.protocol.p206V1_0_0.DataAlarmVo; -import com.dy.common.mw.protocol.p206V1_0_0.DataStateVo; +import com.dy.common.mw.protocol.p206V1_0_0.upVos.DataAlarmVo; +import com.dy.common.mw.protocol.p206V1_0_0.upVos.DataStateVo; import com.dy.common.util.ByteUtil; +import com.dy.common.util.ByteUtilUnsigned; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -11,28 +12,52 @@ private static final Logger log = LogManager.getLogger(GlParse.class); public static DataAlarmVo parseAlarm(byte[] bs, short index){ + /* + 11011111 (DF) + 11111001 (F9) + 鎶ヨ: + 钃勭數姹犵數鍘嬶細鎶ヨ + 婕忔崯锛氭姤璀� + 浠〃锛氭姤璀� + 闃�闂細鎶ヨ + */ DataAlarmVo avo = new DataAlarmVo() ; byte b = bs[index] ; - index++ ; - avo.batteryVolt = (byte)(b & 0x2 >> 1) ; - avo.loss = (byte)(b & 0x8 >> 3) ; - avo.meter = (byte)(b & 0x20 >> 5) ; + avo.batteryVolt = (byte)((b & 0x2) >> 1) ; + avo.meter = (byte)((b & 0x20) >> 5) ; - b = bs[index] ; - avo.valve = (byte)(b & 0x20 >> 5) ; + b = bs[index + 1] ; + avo.loss = (byte)((b & 0x2) >> 1) ; + avo.valve = (byte)((b & 0x4) >> 2) ; return avo ; } public static DataStateVo parseState(byte[] bs, short index){ DataStateVo avo = new DataStateVo() ; byte b = bs[index] ; - index++ ; - avo.icCard = (byte)(b & 0x4 >> 2) ; - avo.working = (byte)(b & 0x8 >> 3) ; - avo.valve = (byte)(b & 0x20 >> 5) ; + avo.icCard = (byte)((b & 0x4) >> 2) ; + avo.valveState = (byte)((b & 0x10) >> 4) ; + avo.powerType = (byte)((b & 0x40) >> 6) ; return avo ; } + /** + * 鍒嗘瀽IC鍗$紪鍙� + * @param bs 涓婅瀛楄妭鏁扮粍 + * @param index 鍚浣� + * @return 鎺у埗鍣ㄥ湴鍧� + * @throws Exception 寮傚父 + */ + public static String parseIcCardNo(byte[] bs, int index)throws Exception{ + String icNoStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, index) ; + String icNoBCD = "" + ByteUtil.BCD2Long_LE(bs, index + 2, index + 7) ; + while(icNoStr.length() < 5){ + icNoStr = "0" + icNoStr ; + } + return icNoBCD + icNoStr ; + } + + + public static String parseTp(byte[] bs, short index){ String dt = "" ; try{ -- Gitblit v1.8.0