mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
解码器拆分
This commit is contained in:
@@ -186,6 +186,20 @@ public class CRC16Util {
|
||||
|
||||
/*以下方法得出的校验位:低位在前,高位在后*/
|
||||
|
||||
public static short calculateCrc(short serialNumber, byte encryptFlag, byte frameType, byte[] messageBody) {
|
||||
// short serialNumber 转byte[]
|
||||
byte[] serialNumberBytes = new byte[2];
|
||||
// byte encryptFlag 转byte[]
|
||||
byte[] encryptFlagBytes = new byte[1];
|
||||
// byte frameType 转byte[]
|
||||
byte[] frameTypeBytes = new byte[1];
|
||||
// byte[] messageBody 转byte[]
|
||||
// 序列号域+加密标志+帧类型标志+消息体
|
||||
byte[] data = Bytes.concat(serialNumberBytes, encryptFlagBytes, frameTypeBytes, messageBody);
|
||||
int i = calcCrc16(data);
|
||||
return (short) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data 需要计算的数组
|
||||
* @return CRC16校验值
|
||||
|
||||
Reference in New Issue
Block a user