Build the even parity bit for EM4100 format of RFID
Developing the EM4100 protocol of RFID, we have to understand the means of EVEN PARITY BIT of the whole 64-byte data.
From http://www.priority1design.com.au/em4100_protocol.html , we know that we must calc 10 goups even parity bit, and 4 column party bits. But it is not Clear for the document to understand how to build even parity bit?
In our code, we just suppose the even parity rule as follow:
RULE: The Even Parity Bit SHOULD BE to add all data waiting to be read, then check the sum is whether even or odd. If sum is even, then data is ok. Or we should discard the wrong EM4100 format data.
The EM4100 format:
The even parity checking code as below:
// rfid_check_even_parity_bit: Suppose we had received whole EM4100 64-byte data
bool rfid_check_even_parity_bit(U8* buf)
{
// check 10 groups even parity bits
U32 sum = 0;
U32 i = 0, j = 0;
for(i=0; i<10; i++) {
sum = buf[9+5*i] + buf[10+5*i] + buf[11+5*i] + buf[12+5*i];
sum = sum & 0x01;
if(sum != buf[13+5*i]) { return FALSE; }
}
// check 4 column parity bits
for(i=0; i<4; i++) {
sum = 0;
for(j=0; j<10; j++)
sum += buf[9+5*j+i];
sum = sum & 0x01;
if(sum != buf[9+5*10+i]) { return FALSE; }
}
return TRUE;
}
Why build even parity bit here?
We suppose, there are 9's '1' bits as head. If the card data is 0xff. If we use odd parity bit here, then two 0xff will build new 9's '1' bits, whch perhaps will bring us a wrong head. Then the even parity will give '0' bit follow 4's '1' bits(0xff). So the 9's '1' will be the only head in the whole 64-byte EM4100 data.
Written by Allen Zhan
2011.09.02
Release on <EETC>
allen_zhan_752827529 2011-9-2 09:59
用户1602177 2011-9-2 09:50
allen_zhan_752827529 2011-9-2 09:30