From 5b89937212db0c507145187313eb5b326220f47b Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 21 一月 2025 10:18:43 +0800
Subject: [PATCH] 修改RTU升级文件CRC16计算的bug

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java
index d641b85..157257f 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java
@@ -94,7 +94,6 @@
 	 * @param endIndex 鎴涓嬫爣
 	 * @return CRC
 	 */
-	@SuppressWarnings("unused")
 	public int CRC16_table(byte[] bs, int startIndex, int endIndex) {
 		int x ;
 		int crc = 0xffff;
@@ -106,18 +105,20 @@
 		}
 		return crc ;
 	}
+
 	/**
-	 * 16浣嶇殑CRC鍊� 锛屾煡琛ㄦ硶
+	 * 16浣嶇殑CRC鍊兼槸鏃犵鍙蜂袱瀛楄妭鏁存暟锛�
+	 * @param len 鏁扮粍闀垮害
 	 * @param bs 瀛楄妭鏁扮粍
+	 * @param crc 鍘熷crc鍊�
 	 * @return CRC
 	 */
-	public short CRC16_table(byte[] bs) {
-		short x ;
-		short crc = (short)0xffff;
-		if(bs != null && bs.length > 0){
-			for(byte b : bs){
-				x = (short)(crc ^ b) ;
-				crc = (short)((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ;
+	public int CRC16_table(int len, byte[] bs, int crc) {
+		int x ;
+		if(bs != null){
+			for (int i = 0 ; i < len; i++){
+				x =  (crc ^ bs[i]) ;
+				crc =  ((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ;
 			}
 		}
 		return crc ;

--
Gitblit v1.8.0