mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -35,4 +35,26 @@ public class YouDianUtils {
|
||||
log.info("计算的校验值:{}, 接收到的校验值:{}", calculatedChecksum, receivedChecksum);
|
||||
return calculatedChecksum == receivedChecksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算校验字段
|
||||
*/
|
||||
public static int calculateCheckField(byte[] bytes) {
|
||||
// 计算累加和
|
||||
int sum = 0;
|
||||
for (int i = 0; i < bytes.length - 2; i++) {
|
||||
sum += (bytes[i] & 0xFF); // 将每个字节视为无符号值进行累加
|
||||
}
|
||||
|
||||
// 取累加和的低 2 字节(16 位)
|
||||
return sum & 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取校验字段byte数组
|
||||
*/
|
||||
public static byte[] getCheckFieldBytes(byte[] bytes) {
|
||||
int calculatedChecksum = calculateCheckField(bytes);
|
||||
return BytesUtil.intToBytesLittle(calculatedChecksum);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,10 @@ public class EBikeDataProtocol {
|
||||
* @return 报文
|
||||
*/
|
||||
public String getHEXString() {
|
||||
byte[] bytes = Bytes.concat(this.head, this.length, this.physicalId, this.messageId, this.command, this.msgBody, this.checksum);
|
||||
return BytesUtil.binary(bytes, 16);
|
||||
return BytesUtil.binary(this.getBytes(), 16);
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return Bytes.concat(this.head, this.length, this.physicalId, this.messageId, this.command, this.msgBody, this.checksum);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user