-
-//by marshmellow
-//takes 1s and 0s and searches for EM410x format - output EM ID
-uint64_t Em410xDecodeOld(uint8_t *BitStream, size_t *size, size_t *startIdx)
-{
- //no arguments needed - built this way in case we want this to be a direct call from "data " cmds in the future
- // otherwise could be a void with no arguments
- //set defaults
- uint64_t lo=0;
- uint32_t i = 0;
- if (BitStream[1]>1){ //allow only 1s and 0s
- // PrintAndLog("no data found");
- return 0;
- }
- // 111111111 bit pattern represent start of frame
- uint8_t preamble[] = {1,1,1,1,1,1,1,1,1};
- uint32_t idx = 0;
- uint32_t parityBits = 0;
- uint8_t errChk = 0;
- *startIdx = 0;
- for (uint8_t extraBitChk=0; extraBitChk<5; extraBitChk++){
- errChk = preambleSearch(BitStream+extraBitChk+*startIdx, preamble, sizeof(preamble), size, startIdx);
- if (errChk == 0) return 0;
- idx = *startIdx + 9;
- for (i=0; i<10;i++){ //loop through 10 sets of 5 bits (50-10p = 40 bits)
- parityBits = bytebits_to_byte(BitStream+(i*5)+idx,5);
- //check even parity
- if (parityTest(parityBits, 5, 0) == 0){
- //parity failed try next bit (in the case of 1111111111) but last 9 = preamble
- startIdx++;
- errChk = 0;
- break;
- }
- //set uint64 with ID from BitStream
- for (uint8_t ii=0; ii<4; ii++){
- lo = (lo << 1LL) | (BitStream[(i*5)+ii+idx]);
- }
- }
- if (errChk != 0) return lo;
- //skip last 5 bit parity test for simplicity.
- // *size = 64;
- }
- return 0;
-}
-