mfu read block: retry block with bad CRC

This commit is contained in:
James Chambers 2018-03-15 13:45:21 -04:00
commit 4601d0e77a

View file

@ -310,6 +310,8 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
}
}
#define MFU_MAX_CRC_RETRIES 5
unsigned int retries = 0;
for (int i = 0; i < blocks; i++){
if ((i*4) + 4 >= CARD_MEMORY_SIZE) {
Dbprintf("Data exceeds buffer!!");
@ -320,15 +322,22 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
if (len) {
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error",i);
// if no blocks read - error out
if (i==0){
OnError(2);
return;
if (retries >= MFU_MAX_CRC_RETRIES) {
// if no blocks read - error out
if (i==0) {
OnError(2);
return;
} else {
//stop at last successful read block and return what we got
break;
}
} else {
//stop at last successful read block and return what we got
break;
retries++;
i--;
}
} else {
retries = 0;
countblocks++;
}
}