Closed samamorgan closed 2 years ago
Hi @samamorgan ,
This library does not print the facility code and card code because there are many non standards out in the market. It only prints the 24 bit data after removing the first parity and last parity.
1392146
dec translate to
000101010011111000010010
binary
If you card has a 16 bit card code and 8 bit facility code, take the last 16 bit from above
0011111000010010
convert to dec you get
15890
and take the front 8 bit
00010101
convert to dec you get
21
So the result is correct. Facility code and card code is just a way a few manufacturers represent their data, anyone can implement their own code, for example 10 bit category code and 14 bit product code.
So ideally, the best is to use the raw captured data and write the decoding part that is suitable to your device.
Hope this helps.
Cheers, JP
That helps immensely! Thanks for explaining, I feel a bit stupid now for not realizing that. All of the shift bits in the code was messing with my head.
For anyone looking to decode facility code and card code data from a H10301 card, here's the code I used to get basic output:
void loop() {
if(wg.available()) {
unsigned long code = wg.getCode();
// Card data
if(code > 27) {
unsigned long facilityCode = (code & 0x1F0000) >> 16;
unsigned long cardCode = code & 0x3FFF;
Serial.println(String(facilityCode)+String(cardCode));
}
// Keypad data
else {
Serial.println(code);
}
}
}
Thanks @samamorgan will be helpful for someone with the same card.
I'm pretty new to bitwise calculations, and haven't been able to figure out why this isn't working for me. Trying to move to this library from my own code that works.
If I attach an interrupt to D0 and D1 that just prints a 0 or 1 respectively, and read a card with FC:21 and CC:15890 I get back the following bits:
10001010100111110000100100
Using an online Wiegand calculator (and my old code) this translates to:
2115890
With this library, using the example INO, I get this:
1392146
If I add "723744" to
wg.getCode();
I get the correct return value for all of the cards I try in this facility code set.If I just use the keypad, I get the correct return values, including the correct translated values given by
translateEnterEscapeKeyPress()
I have tried this with multiple readers and keypad readers, the results are consistently wrong.