+ size_t startIdx = 0;
+ uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,1};
+ uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), &size, &startIdx);
+ if (errChk == 0) return -4; //preamble not found
+
+ if (!dest[startIdx+8] && dest[startIdx+17]==1 && dest[startIdx+26]==1 && dest[startIdx+35]==1 && dest[startIdx+44]==1 && dest[startIdx+53]==1){
+ //confirmed proper separator bits found
+ //return start position
+ return (int) startIdx;
+ }
+ return -5;
+}
+
+// by marshmellow
+// takes a array of binary values, start position, length of bits per parity (includes parity bit),
+// Parity Type (1 for odd 0 for even), and binary Length (length to run)
+size_t removeParity(uint8_t *BitStream, size_t startIdx, uint8_t pLen, uint8_t pType, size_t bLen)
+{
+ uint32_t parityWd = 0;
+ size_t j = 0, bitCnt = 0;
+ for (int word = 0; word < (bLen); word+=pLen){
+ for (int bit=0; bit < pLen; bit++){
+ parityWd = (parityWd << 1) | BitStream[startIdx+word+bit];
+ BitStream[j++] = (BitStream[startIdx+word+bit]);
+ }
+ j--;
+ // if parity fails then return 0
+ if (parityTest(parityWd, pLen, pType) == 0) return -1;
+ bitCnt+=(pLen-1);
+ parityWd = 0;
+ }
+ // if we got here then all the parities passed
+ //return ID start index and size
+ return bitCnt;
+}
+
+// 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;
+}
+
+
+uint8_t DetectCleanAskWave(uint8_t dest[], size_t size, int high, int low)
+{
+ uint16_t allPeaks=1;
+ uint16_t cntPeaks=0;
+ size_t loopEnd = 572;
+ 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 counts between zero crossings
+int DetectStrongAskClock(uint8_t dest[], size_t size)
+{
+ int clk[]={0,8,16,32,40,50,64,100,128};
+ size_t idx = 40;
+ uint8_t high=0;
+ size_t cnt = 0;
+ size_t highCnt = 0;
+ size_t highCnt2 = 0;
+ for (;idx < size; idx++){
+ if (dest[idx]>128) {
+ if (!high){
+ high=1;
+ if (cnt > highCnt){
+ if (highCnt != 0) highCnt2 = highCnt;
+ highCnt = cnt;
+ } else if (cnt > highCnt2) {
+ highCnt2 = cnt;
+ }
+ cnt=1;
+ } else {
+ cnt++;
+ }
+ } else if (dest[idx] <= 128){
+ if (high) {
+ high=0;
+ if (cnt > highCnt) {
+ if (highCnt != 0) highCnt2 = highCnt;
+ highCnt = cnt;
+ } else if (cnt > highCnt2) {
+ highCnt2 = cnt;
+ }
+ cnt=1;
+ } else {
+ cnt++;