- uint8_t wiegand[24];
- num_to_bytebits(fc, 8, wiegand);
- num_to_bytebits(cn, 16, wiegand+8);
-
- wiegand_add_parity(pre+8, wiegand, 24);
+ // add formatlength
+ num_to_bytebits(fmtlen, 8, pre);
+
+ // add facilitycode, cardnumber and wiegand parity bits
+ switch (fmtlen) {
+ case 26:{
+ uint8_t wiegand[24];
+ num_to_bytebits(fc, 8, wiegand);
+ num_to_bytebits(cn, 16, wiegand+8);
+ wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
+ break;
+ }
+ case 34:{
+ uint8_t wiegand[32];
+ num_to_bytebits(fc, 8, wiegand);
+ num_to_bytebits(cn, 24, wiegand+8);
+ wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
+ break;
+ }
+ case 37:{
+ uint8_t wiegand[31];
+ num_to_bytebits(fc, 13, wiegand);
+ num_to_bytebits(cn, 18, wiegand+13);
+ wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
+ break;
+ }
+ case 50: {
+ uint8_t wiegand[48];
+ num_to_bytebits(fc, 16, wiegand);
+ num_to_bytebits(cn, 32, wiegand+16);
+ wiegand_add_parity(pre+8, wiegand, sizeof(wiegand));
+ break;
+ }
+ }
+
+ // add AWID 4bit parity
+ size_t bitLen = addParity(pre, bits+8, 66, 4, 1);