解码器拆分

This commit is contained in:
Guoqs
2024-11-27 14:32:51 +08:00
parent 9b95a07d8b
commit cd252d5ed1
8 changed files with 143 additions and 12 deletions

View File

@@ -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校验值