fix leds. dbg msg

This commit is contained in:
iceman1001 2019-09-12 10:39:10 +02:00
commit d3b2f1f6d0

View file

@ -94,7 +94,10 @@ size_t DemodPCF7931(uint8_t **outBlocks) {
} else { } else {
// Error // Error
if (++warnings > 10) { if (++warnings > 10) {
if ( DBGLEVEL >= DBG_EXTENDED )
Dbprintf("Error: too many detection errors, aborting."); Dbprintf("Error: too many detection errors, aborting.");
return 0; return 0;
} }
} }
@ -135,12 +138,15 @@ bool IsBlock0PCF7931(uint8_t *block) {
// assuming all RFU bits are set to 0 // assuming all RFU bits are set to 0
// if PAC is enabled password is set to 0 // if PAC is enabled password is set to 0
if (block[7] == 0x01) { if (block[7] == 0x01) {
if (!memcmp(block, "\x00\x00\x00\x00\x00\x00\x00", 7) && !memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) if (!memcmp(block, "\x00\x00\x00\x00\x00\x00\x00", 7)
&& !memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) {
return true; return true;
}
} else if (block[7] == 0x00) { } else if (block[7] == 0x00) {
if (!memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) if (!memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) {
return true; return true;
} }
}
return false; return false;
} }
@ -196,13 +202,18 @@ void ReadPCF7931() {
// exit if no block is received // exit if no block is received
if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) { if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) {
Dbprintf("Error, no tag or bad tag");
if ( DBGLEVEL >= DBG_INFO )
Dbprintf("[!!] Error, no tag or bad tag");
return; return;
} }
// exit if too many errors during reading // exit if too many errors during reading
if (tries > 50 && (2 * errors > tries)) { if (tries > 50 && (2 * errors > tries)) {
Dbprintf("Error reading the tag");
Dbprintf("Here is the partial content"); if ( DBGLEVEL >= DBG_INFO )
Dbprintf("[!!] Error reading the tag, only partial content");
goto end; goto end;
} }
@ -231,7 +242,9 @@ void ReadPCF7931() {
continue; continue;
} }
if ( DBGLEVEL >= DBG_EXTENDED )
Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
print_result("got consecutive blocks", tmp_blocks[i], 16); print_result("got consecutive blocks", tmp_blocks[i], 16);
} }
@ -293,7 +306,9 @@ void ReadPCF7931() {
} }
++tries; ++tries;
if (BUTTON_PRESS()) { if (BUTTON_PRESS()) {
if ( DBGLEVEL >= DBG_EXTENDED)
Dbprintf("Button pressed, stopping."); Dbprintf("Button pressed, stopping.");
goto end; goto end;
} }
} while (found_blocks < max_blocks); } while (found_blocks < max_blocks);
@ -319,7 +334,7 @@ end:
Dbprintf("-----------------------------------------"); Dbprintf("-----------------------------------------");
} }
reply_old(CMD_ACK, 0, 0, 0, 0, 0); reply_mix(CMD_ACK, 0, 0, 0, 0, 0);
} }
static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
@ -405,8 +420,12 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3
@param data : data to write @param data : data to write
*/ */
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
if ( DBGLEVEL >= DBG_INFO ) {
Dbprintf("Initialization delay : %d us", init_delay); Dbprintf("Initialization delay : %d us", init_delay);
Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p); Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p);
}
Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7); Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7);
Dbprintf("Block address : %02x", address); Dbprintf("Block address : %02x", address);
Dbprintf("Byte address : %02x", byte); Dbprintf("Byte address : %02x", byte);
@ -425,7 +444,9 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui
void SendCmdPCF7931(uint32_t *tab) { void SendCmdPCF7931(uint32_t *tab) {
uint16_t u = 0, tempo = 0; uint16_t u = 0, tempo = 0;
if ( DBGLEVEL >= DBG_INFO ) {
Dbprintf("Sending data frame..."); Dbprintf("Sending data frame...");
}
FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125kHz FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125kHz
@ -468,7 +489,6 @@ void SendCmdPCF7931(uint32_t *tab) {
SpinDelay(200); SpinDelay(200);
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable
LED(0xFFFF, 1000);
} }
@ -482,13 +502,13 @@ bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) {
uint32_t u; uint32_t u;
for (u = 0; u < 8; ++u) { for (u = 0; u < 8; ++u) {
if (byte & (1 << u)) { //bit is 1 if (byte & (1 << u)) { //bit is 1
if (AddBitPCF7931(1, tab, l, p) == 1) return 1; if (AddBitPCF7931(1, tab, l, p) == 1) return true;
} else { //bit is 0 } else { //bit is 0
if (AddBitPCF7931(0, tab, l, p) == 1) return 1; if (AddBitPCF7931(0, tab, l, p) == 1) return true;
} }
} }
return 0; return false;
} }
/* Add a bits for building the data frame of PCF7931 tags /* Add a bits for building the data frame of PCF7931 tags
@ -501,7 +521,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) {
uint8_t u = 0; uint8_t u = 0;
//we put the cursor at the last value of the array //we put the cursor at the last value of the array
for (u = 0; tab[u] != 0; u += 3) { } for (u = 0; tab[u] != 0; u += 3) { };
if (b == 1) { //add a bit 1 if (b == 1) { //add a bit 1
if (u == 0) if (u == 0)
@ -511,7 +531,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) {
tab[u + 1] = 6 * T0_PCF + tab[u] + l; tab[u + 1] = 6 * T0_PCF + tab[u] + l;
tab[u + 2] = 88 * T0_PCF + tab[u + 1] - l - p; tab[u + 2] = 88 * T0_PCF + tab[u + 1] - l - p;
return 0; return false;
} else { //add a bit 0 } else { //add a bit 0
if (u == 0) if (u == 0)
@ -521,9 +541,9 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) {
tab[u + 1] = 6 * T0_PCF + tab[u] + l; tab[u + 1] = 6 * T0_PCF + tab[u] + l;
tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p; tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p;
return 0; return false;
} }
return 1; return true;
} }
/* Add a custom pattern in the data frame /* Add a custom pattern in the data frame
@ -540,5 +560,5 @@ bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab) {
tab[u + 1] = b + tab[u]; tab[u + 1] = b + tab[u];
tab[u + 2] = c + tab[u + 1]; tab[u + 2] = c + tab[u + 1];
return 0; return true;
} }