From 69cbf8a2fe6c8735f234c7819af9112d72f24dc9 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期六, 13 九月 2025 10:39:42 +0800
Subject: [PATCH] 优化代码

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/CommonV2.java |   45 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/CommonV2.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/CommonV2.java
index ebcaacf..cae3753 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/CommonV2.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/CommonV2.java
@@ -3,10 +3,11 @@
 import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1;
 import com.dy.common.util.ByteUtil;
 import com.dy.common.util.ByteUtilUnsigned;
+import com.dy.common.util.CRC16;
 import com.dy.common.util.CRC8_for_2_0;
 
-
 public class CommonV2 {
+
 	/**
 	 * 妫�鏌ュご
 	 * @param bs 涓婅瀛楄妭鏁扮粍
@@ -20,7 +21,7 @@
 				&& bs[ProtocolConstantV206V2.headFlag1Index] == ProtocolConstantV206V2.P_Head_Byte
 				&& bs[ProtocolConstantV206V2.headFlag2Index] == ProtocolConstantV206V2.P_Head_Byte){
 			Short vs = this.parseVersion(bs) ;
-			if(vs.shortValue() == ProtocolConstantV206V2.protocolVer.shortValue()){
+			if(vs.shortValue() == ProtocolConstantV206V2.protocolVer){
 				return new Boolean[]{true, true};
 			}else{
 				return new Boolean[]{false, true};
@@ -159,6 +160,19 @@
 	}
 
 	/**
+	 * 鍒嗘瀽鍔熻兘鐮�
+	 * @param bs 涓婅瀛楄妭鏁扮粍
+	 * @return 鍔熻兘鐮�
+	 */
+	public String parseCode(byte[] bs, boolean p206TrueUgFalse){
+		if(p206TrueUgFalse) {
+			return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.codeIndex, 1);
+		}else{
+			return ByteUtil.bytes2Hex(bs, false, ProtocolConstantV206V1.UG_codeIndex, 2);
+		}
+	}
+
+	/**
 	 * 鏍¢獙鍜屾鏌�
 	 * @param bs  涓婅瀛楄妭鏁扮粍
 	 * @return 閫氳繃null锛屾湭閫氳繃杩斿洖鍘熷洜
@@ -175,6 +189,33 @@
 	}
 
 
+	/**
+	 * 鏍¢獙鍜屾鏌�
+	 * @param bs  涓婅瀛楄妭鏁扮粍
+	 * @param p206TrueUgFalse 206鍗忚涓簍rue锛屽崌绾у崗璁负false
+	 * @return 閫氳繃null锛屾湭閫氳繃杩斿洖鍘熷洜
+	 * @throws Exception 寮傚父
+	 */
+	public String checkCrc_str(byte[] bs, boolean p206TrueUgFalse) throws Exception {
+		if(p206TrueUgFalse){
+			byte crcCompute = (byte)new CRC8_for_2_0().CRC8(bs, ProtocolConstantV206V1.ctrlIndex, bs.length - 3) ;
+			byte crcInBs = bs[bs.length - 2] ;
+			if(crcCompute == crcInBs){
+				return null ;
+			}else{
+				return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+			}
+		}else{
+			short crcCompute = new CRC16().CRC(bs, 0, bs.length - 4) ;
+			short crcInBs = ByteUtil.bytes2Short_BE(bs,bs.length - 3) ;
+			//int crcInBs = ByteUtilUnsigned.bytes2Short_BE(bs, bs.length - 3) ;
+			if(crcCompute == crcInBs){
+				return null ;
+			}else{
+				return "璁$畻CRC鏄�:" + crcCompute + "锛屼笂浼燙RC鏄�" + crcInBs ;
+			}
+		}
+	}
 	/*
 	鏋勯�犳帶鍒跺煙
 	D7                  D6                  D5锝濪4            D3锝濪0

--
Gitblit v1.8.0