mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-14 03:03:14 +08:00
minor askrawdemod adjustment if errors in demoding are found
if it can't find a demod position with no errors it will find the one with fewest errors and mark errors with 77.
This commit is contained in:
parent
2fc2150ea8
commit
cd48c19c31
1 changed files with 27 additions and 16 deletions
|
@ -302,13 +302,14 @@ int Cmdaskrawdemod(const char *Cmd)
|
||||||
//PrintAndLog("DEBUG - valid high: %d - valid low: %d",high,low);
|
//PrintAndLog("DEBUG - valid high: %d - valid low: %d",high,low);
|
||||||
int lastBit = 0; //set first clock check
|
int lastBit = 0; //set first clock check
|
||||||
uint32_t bitnum = 0; //output counter
|
uint32_t bitnum = 0; //output counter
|
||||||
uint8_t tol = clk; //clock tolerance adjust - waves will be accepted as within the clock if they fall + or - this value + clock from last valid wave
|
uint8_t tol = 0; //clock tolerance adjust - waves will be accepted as within the clock if they fall + or - this value + clock from last valid wave
|
||||||
//clock tolerance may not be needed anymore currently set to + or - 1 but could be increased for poor waves or removed entirely
|
if (clk==32)tol=1; //clock tolerance may not be needed anymore currently set to + or - 1 but could be increased for poor waves or removed entirely
|
||||||
uint32_t iii = 0;
|
uint32_t iii = 0;
|
||||||
uint32_t gLen = GraphTraceLen;
|
uint32_t gLen = GraphTraceLen;
|
||||||
if (gLen > 500) gLen=500;
|
if (gLen > 500) gLen=500;
|
||||||
uint8_t errCnt =0;
|
uint8_t errCnt =0;
|
||||||
|
uint32_t bestStart = GraphTraceLen;
|
||||||
|
uint32_t bestErrCnt = (GraphTraceLen/1000);
|
||||||
//PrintAndLog("DEBUG - lastbit - %d",lastBit);
|
//PrintAndLog("DEBUG - lastbit - %d",lastBit);
|
||||||
|
|
||||||
//loop to find first wave that works
|
//loop to find first wave that works
|
||||||
|
@ -317,32 +318,32 @@ int Cmdaskrawdemod(const char *Cmd)
|
||||||
lastBit=iii-clk;
|
lastBit=iii-clk;
|
||||||
//loop through to see if this start location works
|
//loop through to see if this start location works
|
||||||
for (i = iii; i < GraphTraceLen; ++i) {
|
for (i = iii; i < GraphTraceLen; ++i) {
|
||||||
if ((GraphBuffer[i] >= high) && ((i-lastBit)>(clk-((int)clk/tol)))) { // && GraphBuffer[i-1] < high
|
if ((GraphBuffer[i] >= high) && ((i-lastBit)>(clk-tol))){
|
||||||
lastBit+=clk;
|
lastBit+=clk;
|
||||||
BitStream[bitnum] = invert;
|
BitStream[bitnum] = invert;
|
||||||
bitnum++;
|
bitnum++;
|
||||||
} else if ((GraphBuffer[i] <= low) && ((i-lastBit)>(clk-((int)clk/tol)))){
|
} else if ((GraphBuffer[i] <= low) && ((i-lastBit)>(clk-tol))){
|
||||||
//low found and we are expecting a bar
|
//low found and we are expecting a bar
|
||||||
lastBit+=clk;
|
lastBit+=clk;
|
||||||
BitStream[bitnum] = 1-invert;
|
BitStream[bitnum] = 1-invert;
|
||||||
bitnum++;
|
bitnum++;
|
||||||
} else {
|
} else {
|
||||||
//mid value found or no bar supposed to be here
|
//mid value found or no bar supposed to be here
|
||||||
if ((i-lastBit)>(clk+((int)(clk/tol)))){
|
if ((i-lastBit)>(clk+tol)){
|
||||||
//should have hit a high or low based on clock!!
|
//should have hit a high or low based on clock!!
|
||||||
|
|
||||||
/*
|
|
||||||
//debug
|
//debug
|
||||||
PrintAndLog("DEBUG - no wave in expected area - location: %d, expected: %d-%d, lastBit: %d - resetting search",i,(lastBit+(clk-((int)(clk/tol)))),(lastBit+(clk+((int)(clk/tol)))),lastBit);
|
//PrintAndLog("DEBUG - no wave in expected area - location: %d, expected: %d-%d, lastBit: %d - resetting search",i,(lastBit+(clk-((int)(tol)))),(lastBit+(clk+((int)(tol)))),lastBit);
|
||||||
if (bitnum > 0){
|
if (bitnum > 0){
|
||||||
BitStream[bitnum]=77;
|
BitStream[bitnum]=77;
|
||||||
bitnum++;
|
bitnum++;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
errCnt++;
|
errCnt++;
|
||||||
lastBit+=clk;//skip over until hit too many errors
|
lastBit+=clk;//skip over until hit too many errors
|
||||||
if (errCnt>((GraphTraceLen/1000)*2)){ //allow 2 errors for every 1000 samples else start over
|
if (errCnt>((GraphTraceLen/1000))){ //allow 1 error for every 1000 samples else start over
|
||||||
errCnt=0;
|
errCnt=0;
|
||||||
bitnum=0;//start over
|
bitnum=0;//start over
|
||||||
break;
|
break;
|
||||||
|
@ -350,11 +351,21 @@ int Cmdaskrawdemod(const char *Cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//we got more than 64 good bits and not all errors
|
||||||
//debug
|
if ((bitnum > (64+errCnt)) && (errCnt<(GraphTraceLen/1000))) {
|
||||||
if ((bitnum>64) && (BitStream[bitnum-1]!=77)) break;
|
//possible good read
|
||||||
|
if (errCnt==0) break; //great read - finish
|
||||||
}
|
if (bestStart = iii) break; //if current run == bestErrCnt run (after exhausted testing) then finish
|
||||||
|
if (errCnt<bestErrCnt){ //set this as new best run
|
||||||
|
bestErrCnt=errCnt;
|
||||||
|
bestStart = iii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iii>=gLen){ //exhausted test
|
||||||
|
//if there was a ok test go back to that one and re-run the best run (then dump after that run)
|
||||||
|
if (bestErrCnt < (GraphTraceLen/1000)) iii=bestStart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (bitnum>16){
|
if (bitnum>16){
|
||||||
PrintAndLog("Data start pos:%d, lastBit:%d, stop pos:%d, numBits:%d",iii,lastBit,i,bitnum);
|
PrintAndLog("Data start pos:%d, lastBit:%d, stop pos:%d, numBits:%d",iii,lastBit,i,bitnum);
|
||||||
|
@ -367,7 +378,7 @@ int Cmdaskrawdemod(const char *Cmd)
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
//output
|
//output
|
||||||
if (errCnt>0){
|
if (errCnt>0){
|
||||||
PrintAndLog("# Errors during Demoding: %d",errCnt);
|
PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||||
}
|
}
|
||||||
PrintAndLog("ASK decoded bitstream:");
|
PrintAndLog("ASK decoded bitstream:");
|
||||||
// Now output the bitstream to the scrollback by line of 16 bits
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
|
|
Loading…
Reference in a new issue