255バイトのデータに対するCRC16チェックサムの機能があります。
チェックサムは、最初のバイトから最後から3番目のバイトまで計算されます。これらのコード、特に「ekmCheckCrc」関数で何が起こっているのか教えていただけますか?以下は私が得た関数です。
public void tryMe(byte[] responseFromDevice)
{
byte[] c = new byte[2];
c[0] = a[253];
c[1] = a[254];
log("EKM CRC : " + Integer.toHexString(ekmCheckCrc(responseFromDevice)) +
" Device CRC : " + Integer.toHexString((int) (c[0])) + Integer.toHexString((int) (c[1])) );
}
public int ekmCheckCrc(byte[] dat) {
int crc = 0xffff;
for (int i = 1; i < dat.length-3; i++) {
crc = (crc >>> 8) ^ ekmCrcLut[(crc ^ dat[i]) & 0xff];
}
crc = (crc >>> 8) | (crc << 8);
crc = crc & 0x7f7f;
return crc;
}
static int[] ekmCrcLut = new int[]{
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
(EKM's LUT sits here, no point including the rest of it)
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
};