X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/11081e0459f303518350b195b9d1c54b415eb6d7..e74fc2ecbab43a083766502610efb7b36dfac5c4:/common/lfdemod.c?ds=inline diff --git a/common/lfdemod.c b/common/lfdemod.c index 144cb327..db945d0a 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -1094,11 +1094,9 @@ void psk1TOpsk2(uint8_t *BitStream, size_t size) // from only transition waves are 1s to phase shifts change bit void psk2TOpsk1(uint8_t *BitStream, size_t size) { - size_t i; - uint8_t phase=BitStream[0]; - //uint8_t lastBit=BitStream[0]; - for (i=1; i= dest[i+2]){ - if (waveStart == 0) { - waveStart = i+1; - avgWaveVal=dest[i+1]; - //PrintAndLog("DEBUG: waveStart: %d",waveStart); - } else { - waveEnd = i+1; - //PrintAndLog("DEBUG: waveEnd: %d",waveEnd); - waveLenCnt = waveEnd-waveStart; - lastAvgWaveVal = avgWaveVal/waveLenCnt; - if (waveLenCnt > fc){ - firstFullWave = waveStart; - fullWaveLen=waveLenCnt; - //if average wave value is > graph 0 then it is an up wave or a 1 - if (lastAvgWaveVal > 128) curPhase^=1; - break; - } - waveStart=0; - avgWaveVal=0; - } + waveEnd = i+1; + //PrintAndLog("DEBUG: waveEnd: %d",waveEnd); + waveLenCnt = waveEnd-waveStart; + if (waveLenCnt > fc && waveStart > fc){ //not first peak and is a large wave + lastAvgWaveVal = avgWaveVal/(waveLenCnt); + firstFullWave = waveStart; + fullWaveLen=waveLenCnt; + //if average wave value is > graph 0 then it is an up wave or a 1 + if (lastAvgWaveVal > 123) curPhase^=1; //fudge graph 0 a little 123 vs 128 + break; + } + waveStart = i+1; + avgWaveVal = 0; } - avgWaveVal+=dest[i+1]; + avgWaveVal+=dest[i+2]; } //PrintAndLog("DEBUG: firstFullWave: %d, waveLen: %d",firstFullWave,fullWaveLen); lastClkBit = firstFullWave; //set start of wave as clock align @@ -1631,7 +1623,7 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) errCnt=0; size_t numBits=0; //PrintAndLog("DEBUG: clk: %d, lastClkBit: %d", *clock, lastClkBit); - + dest[numBits++] = curPhase; //set first read bit for (i = firstFullWave+fullWaveLen-1; i < *size-3; i++){ //top edge of wave = start of new wave if (dest[i]+fc < dest[i+1] && dest[i+1] >= dest[i+2]){ @@ -1643,26 +1635,23 @@ int pskRawDemod(uint8_t dest[], size_t *size, int *clock, int *invert) waveEnd = i+1; waveLenCnt = waveEnd-waveStart; lastAvgWaveVal = avgWaveVal/waveLenCnt; - if (waveLenCnt > fc){ + if (waveLenCnt > fc){ //PrintAndLog("DEBUG: avgWaveVal: %d, waveSum: %d",lastAvgWaveVal,avgWaveVal); //if this wave is a phase shift //PrintAndLog("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d",waveStart,waveLenCnt,lastClkBit+*clock-tol,i+1,fc); if (i+1 >= lastClkBit + *clock - tol){ //should be a clock bit curPhase^=1; - dest[numBits] = curPhase; - numBits++; + dest[numBits++] = curPhase; lastClkBit += *clock; - } else if (i lastClkBit + *clock + tol + fc){ lastClkBit += *clock; //no phase shift but clock bit - dest[numBits] = curPhase; - numBits++; + dest[numBits++] = curPhase; } avgWaveVal=0; waveStart=i+1;