From b3b17b231e2f2840332ce6eb96f791865fdec6d5 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 14 四月 2025 16:38:16 +0800
Subject: [PATCH] 代码优化
---
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