package org.yzh.protocol.t808.T8900Lock; import io.github.yezhihao.protostar.annotation.Field; import lombok.Data; /** * 设置离线开锁密码 */ @Data public class T8900SetPassword { @Field(index = 0, length = 2, desc = "读锁ID命令") private byte[] lockId; @Field(index = 1, length = 1, desc = "命令类型") private byte commandType = 0x04; @Field(index = 2, length = 6, desc = "密码1") private byte[] password1; @Field(index = 3, length = 6, desc = "密码2") private byte[] password2; @Field(index = 4, length = 6, desc = "密码3") private byte[] password3; @Field(index = 5, length = 6, desc = "密码4") private byte[] password4; @Field(index = 6, length = 6, desc = "密码5") private byte[] password5; @Field(index = 7, length = 6, desc = "密码6") private byte[] password6; @Field(index = 8, length = 6, desc = "密码7") private byte[] password7; @Field(index = 9, length = 6, desc = "密码8") private byte[] password8; @Field(index = 10, length = 6, desc = "密码9") private byte[] password9; @Field(index = 11, length = 6, desc = "密码10") private byte[] password10; @Field(index = 12, length = 1, desc = "校验码") private byte checksum; /** * 和校验码计算(取低8位) * @param data 要校验的数据 * @return 校验码 * */ public byte calculateSUMChecksum(byte[] data) { int sum = 0; for (byte b : data) { sum += b & 0xFF; // 转换为无符号整数 } return (byte) (sum & 0xFF); // 取低8位 } }