- size_t i=0, waveStart=1, waveEnd=0, firstFullWave=0, lastClkBit=0;
- uint16_t fc=0, fullWaveLen=0, tol=1;
- uint16_t errCnt=0, waveLenCnt=0, errCnt2=0;
- fc = countFC(dest, *size, 1);
- uint8_t fc2 = fc >> 8;
- if (fc2 == 10) return -1; //fsk found - quit
- fc = fc & 0xFF;
- if (fc!=2 && fc!=4 && fc!=8) return -1;
- //PrintAndLog("DEBUG: FC: %d",fc);
- *clock = DetectPSKClock(dest, *size, *clock);
- if (*clock == 0) return -1;
-
- //find start of modulating data in trace
- uint8_t threshold_value = 123; //-5
- i = findModStart(dest, *size, threshold_value, fc);
-
- //find first phase shift
- int avgWaveVal=0, lastAvgWaveVal=0;
- waveStart = i;
- for (; i<loopCnt; i++) {
- // find peak
- if (dest[i]+fc < dest[i+1] && dest[i+1] >= dest[i+2]){
- waveEnd = i+1;
- if (g_debugMode == 2) prnt("DEBUG PSK: waveEnd: %u, waveStart: %u",waveEnd, waveStart);
- waveLenCnt = waveEnd-waveStart;
- if (waveLenCnt > fc && waveStart > fc && !(waveLenCnt > fc+3)){ //not first peak and is a large wave but not out of whack
- lastAvgWaveVal = avgWaveVal/(waveLenCnt);
- firstFullWave = waveStart;
- fullWaveLen=waveLenCnt;
- //if average wave value is > graph 0 then it is an up wave or a 1 (could cause inverting)
- if (lastAvgWaveVal > threshold_value) curPhase ^= 1;
- break;
- }
-
- waveStart = i+1;
- avgWaveVal = 0;
- }
- avgWaveVal += dest[i+2];
- }
+ uint8_t fc=0;
+ size_t i=0, numBits=0, waveStart=1, waveEnd=0, firstFullWave=0, lastClkBit=0;
+ uint16_t fullWaveLen=0, waveLenCnt=0, avgWaveVal;
+ uint16_t errCnt=0, errCnt2=0;
+
+ *clock = DetectPSKClock(dest, *size, *clock, &firstFullWave, &curPhase, &fc);
+ if (*clock <= 0) return -1;
+ //if clock detect found firstfullwave...
+ uint16_t tol = fc/2;