From 67c9b8c40d8b89408e522bc6df7347992dcdd245 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期一, 02 十二月 2024 15:30:01 +0800 Subject: [PATCH] 修改升级协议中的bug,帧长度编码由BCD改为bin --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CRC16.java | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 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 61e9eca..741595c 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 @@ -1,6 +1,8 @@ package com.dy.common.util; +import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; + @SuppressWarnings("unused") public final class CRC16 { @@ -138,6 +140,33 @@ System.arraycopy(new byte[] {(byte)(c - ((c / 256) * 256)) }, 0, crc, 1, 1); return crc; } - + + public static void main(String[] args) throws Exception { + //String hex = "AA0024AA + // 16015301 + // 15059980 + // 00011000 + // 00014A00 + // 5D4D5D4D + // 00004000 + // AAC616" ; + String hex = "AA0024AA16015301150599800001100000014A005D4D5D4D00004000" ; + byte[] bs = ByteUtil.hex2Bytes(hex) ; +// for(int i = 0 ; i < bs.length - 2 ; i++){ +// short crc = new CRC16().CRC16_table(bs, i , bs.length - 1) ; +// byte[] bytes = new byte[ProtocolConstantV206V1.UG_lenTail] ; +// ByteUtil.short2Bytes_LE(bytes, crc, 0); +// bytes[2] = ProtocolConstantV206V1.P_Tail_Byte ; +// System.out.println(ByteUtil.bytes2Hex(bytes, true)) ; +// } + System.out.println("==============================") ; + for(int i = 4 ; i < bs.length ; i++){ + short crc = new CRC16().CRC16_table(bs, 0 , i) ; + byte[] bytes = new byte[ProtocolConstantV206V1.UG_lenTail] ; + ByteUtil.short2Bytes_LE(bytes, crc, 0); + bytes[2] = ProtocolConstantV206V1.P_Tail_Byte ; + System.out.println(ByteUtil.bytes2Hex(bytes, true)) ; + } + } } -- Gitblit v1.8.0