+ bitCnt+=(pLen-1);
+ parityWd = 0;
+ }
+ // if we got here then all the parities passed
+ //return ID start index and size
+ return bitCnt;
+}
+
+// Ask/Biphase Demod then try to locate an ISO 11784/85 ID
+// BitStream must contain previously askrawdemod and biphasedemoded data
+int FDXBdemodBI(uint8_t *dest, size_t *size)
+{
+ //make sure buffer has enough data
+ if (*size < 128) return -1;
+
+ size_t startIdx = 0;
+ uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,1};
+
+ uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx);
+ if (errChk == 0) return -2; //preamble not found
+ return (int)startIdx;
+}
+
+// by marshmellow
+// FSK Demod then try to locate an AWID ID
+int AWIDdemodFSK(uint8_t *dest, size_t *size)
+{
+ //make sure buffer has enough data
+ if (*size < 96*50) return -1;
+
+ if (justNoise(dest, *size)) return -2;
+
+ // FSK demodulator
+ *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50
+ if (*size < 96) return -3; //did we get a good demod?
+
+ uint8_t preamble[] = {0,0,0,0,0,0,0,1};
+ size_t startIdx = 0;
+ uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx);
+ if (errChk == 0) return -4; //preamble not found
+ if (*size != 96) return -5;
+ return (int)startIdx;
+}
+
+// by marshmellow
+// FSK Demod then try to locate an Farpointe Data (pyramid) ID
+int PyramiddemodFSK(uint8_t *dest, size_t *size)
+{
+ //make sure buffer has data
+ if (*size < 128*50) return -5;
+
+ //test samples are not just noise
+ if (justNoise(dest, *size)) return -1;
+
+ // FSK demodulator
+ *size = fskdemod(dest, *size, 50, 1, 10, 8); // fsk2a RF/50
+ if (*size < 128) return -2; //did we get a good demod?
+
+ uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
+ size_t startIdx = 0;
+ uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx);
+ if (errChk == 0) return -4; //preamble not found
+ if (*size != 128) return -3;
+ return (int)startIdx;
+}
+
+// by marshmellow
+// to detect a wave that has heavily clipped (clean) samples
+uint8_t DetectCleanAskWave(uint8_t dest[], size_t size, uint8_t high, uint8_t low)
+{
+ uint16_t allPeaks=1;
+ uint16_t cntPeaks=0;
+ size_t loopEnd = 512+60;
+ if (loopEnd > size) loopEnd = size;
+ for (size_t i=60; i<loopEnd; i++){
+ if (dest[i]>low && dest[i]<high)
+ allPeaks=0;
+ else
+ cntPeaks++;
+ }
+ if (allPeaks == 0){
+ if (cntPeaks > 300) return 1;
+ }
+ return allPeaks;
+}
+
+// by marshmellow
+// to help detect clocks on heavily clipped samples
+// based on count of low to low
+int DetectStrongAskClock(uint8_t dest[], size_t size, uint8_t high, uint8_t low)
+{
+ uint8_t fndClk[] = {8,16,32,40,50,64,128};
+ size_t startwave;
+ size_t i = 0;
+ size_t minClk = 255;
+ // get to first full low to prime loop and skip incomplete first pulse
+ while ((dest[i] < high) && (i < size))
+ ++i;
+ while ((dest[i] > low) && (i < size))
+ ++i;
+
+ // loop through all samples
+ while (i < size) {
+ // measure from low to low
+ while ((dest[i] > low) && (i < size))
+ ++i;
+ startwave= i;
+ while ((dest[i] < high) && (i < size))
+ ++i;
+ while ((dest[i] > low) && (i < size))
+ ++i;
+ //get minimum measured distance
+ if (i-startwave < minClk && i < size)
+ minClk = i - startwave;
+ }
+ // set clock
+ for (uint8_t clkCnt = 0; clkCnt<7; clkCnt++) {
+ if (minClk >= fndClk[clkCnt]-(fndClk[clkCnt]/8) && minClk <= fndClk[clkCnt]+1)
+ return fndClk[clkCnt];