mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 03:55:17 +08:00
update 修改crc校验方法
This commit is contained in:
@@ -49,12 +49,17 @@ public class YKCUtils {
|
||||
String sourceCRC = String.format("%04x", BytesUtil.bytesToInt(crcByte, 0));
|
||||
String targetCRC = String.format("%04x", CRC16Util.calcCrc16(data));
|
||||
String oldTargetCRC = String.format("%04x", CRC16Util.calcCrc16Old(data));
|
||||
if (!sourceCRC.equalsIgnoreCase(targetCRC)) {
|
||||
log.error("CRC校验不通过, 源crc:{}, 计算得出crc:{}, 老crc计算:{}, 帧类型:{}, 报文:{}, msg:{}"
|
||||
, sourceCRC, targetCRC, oldTargetCRC, YKCUtils.frameType2Str(frameType), BytesUtil.binary(msg, 16), Arrays.toString(msg));
|
||||
return false;
|
||||
// 将高低位位置反转,得出新的crc
|
||||
String lowString = StringUtils.substring(targetCRC, 0, 2);
|
||||
String highString = StringUtils.substring(targetCRC, 2, 4);
|
||||
String crc = highString + lowString;
|
||||
// 若目标crc和高低位反转前/后的crc都不一致,则校验不通过
|
||||
if (sourceCRC.equalsIgnoreCase(targetCRC) || sourceCRC.equalsIgnoreCase(crc)) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
log.error("CRC校验不通过, 源crc:{}, 计算得出crc:{}, 老crc计算:{}, 高低位反转后crc:{}, 帧类型:{}, 报文:{}, msg:{}"
|
||||
, sourceCRC, targetCRC, oldTargetCRC, crc, YKCUtils.frameType2Str(frameType), BytesUtil.binary(msg, 16), Arrays.toString(msg));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,6 +132,11 @@ public class YKCUtils {
|
||||
// System.out.println(binary);
|
||||
// System.out.println(aaa);
|
||||
|
||||
String targetCRC = "0abb";
|
||||
String substring = StringUtils.substring(targetCRC, 0, 2);
|
||||
String substring1 = StringUtils.substring(targetCRC, 2, 4);
|
||||
String crc = substring1 + substring;
|
||||
|
||||
String hexString = "4f";
|
||||
byte[] bytes = new byte[]{0x4f};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user