+// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
+size_t ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo)
+{
+
+ size_t idx=0, size2=*size;
+ // FSK demodulator
+
+ *size = fskdemod(dest, size2,50,1,10,8);
+
+ // final loop, go over previously decoded manchester data and decode into usable tag ID
+ // 00001111 bit pattern represent start of frame, 01 pattern represents a 1 and 10 represents a 0
+ uint8_t frame_marker_mask[] = {0,0,0,0,1,1,1,1};
+ uint16_t numshifts = 0;
+ idx = 0;
+ //one scan
+ while( idx + sizeof(frame_marker_mask) < *size) {
+ // search for a start of frame marker
+ if ( memcmp(dest+idx, frame_marker_mask, sizeof(frame_marker_mask)) == 0)
+ { // frame marker found
+ size2=idx;
+ idx+=sizeof(frame_marker_mask);
+ while(dest[idx] != dest[idx+1] && idx < *size-2)
+ {
+ // Keep going until next frame marker (or error)
+ // Shift in a bit. Start by shifting high registers
+ *hi2 = (*hi2<<1)|(*hi>>31);
+ *hi = (*hi<<1)|(*lo>>31);
+ //Then, shift in a 0 or one into low
+ if (dest[idx] && !dest[idx+1]) // 1 0
+ *lo=(*lo<<1)|1;
+ else // 0 1
+ *lo=(*lo<<1)|0;
+ numshifts++;
+ idx += 2;
+ }
+ // Hopefully, we read a tag and hit upon the next frame marker and got enough bits
+ if(idx + sizeof(frame_marker_mask) < *size && numshifts > 40)
+ {
+ if ( memcmp(dest+idx, frame_marker_mask, sizeof(frame_marker_mask)) == 0)
+ {
+ //good return - return start grid position and bits found
+ *size = ((numshifts*2)+8);
+ return size2;
+ }
+ }
+ // reset
+ *hi2 = *hi = *lo = 0;
+ numshifts = 0;
+ }else {
+ idx++;
+ }
+ }
+ return 0;
+}
+