- // Get 26 wiegand from FacilityCode, CardNumber
- uint8_t wiegand[24];
- memset(wiegand, 0x00, sizeof(wiegand));
- num_to_bytebits(fc, 8, wiegand);
- num_to_bytebits(cn, 16, wiegand+8);
-
- // add wiegand parity bits (dest, source, len)
- wiegand_add_parity(pre, wiegand, 24);
-
- // lets start. 12bytes of data to be produced.
- uint8_t rawbytes[12];
- memset(rawbytes, 0x00, sizeof(rawbytes));
+ // add format length (decimal)
+ switch (fmtlen) {
+ case 32: {
+ rawbytes[1] = (32 << 2);
+
+ break;
+ }
+ case 36: {
+ // FC = ((ByteStream[3] & 0x7F)<<7) | (ByteStream[4]>>1);
+ // Card = ((ByteStream[4]&1)<<19) | (ByteStream[5]<<11) | (ByteStream[6]<<3) | (ByteStream[7]>>5);
+ rawbytes[1] = (36 << 2);
+ // Get 26 wiegand from FacilityCode, CardNumber
+ uint8_t wiegand[34];
+ memset(wiegand, 0x00, sizeof(wiegand));
+ num_to_bytebits(fc, 8, wiegand);
+ num_to_bytebits(cn, 26, wiegand+8);
+
+ // add wiegand parity bits (dest, source, len)
+ wiegand_add_parity(pre, wiegand, 34);
+ break;
+ }
+ case 40: {
+ rawbytes[1] = (40 << 2);
+ break;
+ }
+ case 26:
+ default: {
+ rawbytes[1] = (26 << 2);
+ // Get 26 wiegand from FacilityCode, CardNumber
+ uint8_t wiegand[24];
+ memset(wiegand, 0x00, sizeof(wiegand));
+ num_to_bytebits(fc, 8, wiegand);
+ num_to_bytebits(cn, 16, wiegand+8);
+
+ // add wiegand parity bits (dest, source, len)
+ wiegand_add_parity(pre, wiegand, 24);
+ break;
+ }
+ }
+ // 2bit checksum, unknown today,
+ // these two bits are the last ones of rawbyte[1], hence the LSHIFT above.