/**加密算法**/
private static short encryption(short msgId, short mesType) {
short y;
short desCode;
y = (short) ((msgId % 10 * 10 + msgId % 100 / 10 + mesType * 2) % 100);
System.out.println("y:" + y);
desCode = (short) BLE_Cipher[y];
return desCode;
}
/**
* CRC8校验码
* @param buffer
* @param key
* @return
*/
public static byte getCRCR8(byte[] buffer, short key) {
short i;
byte crc;
crc = 0;
int ptr = 0;
int len;
len = buffer.length;
while (len-- != 0) {
for (i = 0x80; i != 0; i >>= 1) {
if ((crc & 0x80) != 0) {
crc <<= 1;
crc ^= key;
} else {
crc <<= 1;
}
if ((buffer[ptr] & i) != 0) {
crc ^= key; /* 校验模数 */
}
}
ptr++;
}
return crc;
}