Removed Serial.* logging

This commit is contained in:
2021-04-21 21:50:16 +02:00
parent b7b3373aad
commit 9a2f54203d

View File

@@ -8,7 +8,7 @@
#include <MFRC522_I2C.h> #include <MFRC522_I2C.h>
#include <HardwareSerial.h> //#include <HardwareSerial.h>
#include <Wire.h> #include <Wire.h>
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
@@ -1223,20 +1223,20 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
MIFARE_Key key; MIFARE_Key key;
// UID // UID
Serial.print("Card UID:"); // Serial.print("Card UID:");
for (uint8_t i = 0; i < uid->size; i++) { // for (uint8_t i = 0; i < uid->size; i++) {
if(uid->uidByte[i] < 0x10) // if(uid->uidByte[i] < 0x10)
Serial.print(" 0"); // Serial.print(" 0");
else // else
Serial.print(" "); // Serial.print(" ");
Serial.print(uid->uidByte[i], HEX); // Serial.print(uid->uidByte[i], HEX);
} // }
Serial.println(); // Serial.println();
// PICC type // PICC type
uint8_t piccType = PICC_GetType(uid->sak); uint8_t piccType = PICC_GetType(uid->sak);
Serial.print("PICC type: "); // Serial.print("PICC type: ");
Serial.println(PICC_GetTypeName(piccType)); // Serial.println(PICC_GetTypeName(piccType));
// Dump contents // Dump contents
switch (piccType) { switch (piccType) {
@@ -1258,7 +1258,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
case PICC_TYPE_ISO_18092: case PICC_TYPE_ISO_18092:
case PICC_TYPE_MIFARE_PLUS: case PICC_TYPE_MIFARE_PLUS:
case PICC_TYPE_TNP3XXX: case PICC_TYPE_TNP3XXX:
Serial.println("Dumping memory contents not implemented for that PICC type."); // Serial.println("Dumping memory contents not implemented for that PICC type.");
break; break;
case PICC_TYPE_UNKNOWN: case PICC_TYPE_UNKNOWN:
@@ -1267,7 +1267,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
break; // No memory dump here break; // No memory dump here
} }
Serial.println(); // Serial.println();
PICC_HaltA(); // Already done if it was a MIFARE Classic PICC. PICC_HaltA(); // Already done if it was a MIFARE Classic PICC.
} // End PICC_DumpToSerial() } // End PICC_DumpToSerial()
@@ -1302,7 +1302,7 @@ void MFRC522::PICC_DumpMifareClassicToSerial( Uid *uid, ///< Pointer to Uid str
// Dump sectors, highest address first. // Dump sectors, highest address first.
if (no_of_sectors) { if (no_of_sectors) {
Serial.println("Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits"); // Serial.println("Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits");
for (int8_t i = no_of_sectors - 1; i >= 0; i--) { for (int8_t i = no_of_sectors - 1; i >= 0; i--) {
PICC_DumpMifareClassicSectorToSerial(uid, key, i); PICC_DumpMifareClassicSectorToSerial(uid, key, i);
} }
@@ -1335,10 +1335,10 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
// The four CX bits are stored together in a nible cx and an inverted nible cx_. // The four CX bits are stored together in a nible cx and an inverted nible cx_.
uint8_t c1, c2, c3; // Nibbles uint8_t c1, c2, c3; // Nibbles
uint8_t c1_, c2_, c3_; // Inverted nibbles uint8_t c1_, c2_, c3_; // Inverted nibbles
bool invertedError; // True if one of the inverted nibbles did not match bool invertedError; // True if one of the inverted nibbles did not match
uint8_t g[4]; // Access bits for each of the four groups. uint8_t g[4]; // Access bits for each of the four groups.
uint8_t group; // 0-3 - active group for access bits uint8_t group; // 0-3 - active group for access bits
bool firstInGroup; // True for the first block dumped in the group bool firstInGroup; // True for the first block dumped in the group
// Determine position and size of sector. // Determine position and size of sector.
if (sector < 32) { // Sectors 0..31 has 4 blocks each if (sector < 32) { // Sectors 0..31 has 4 blocks each
@@ -1361,34 +1361,34 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
for (int8_t blockOffset = no_of_blocks - 1; blockOffset >= 0; blockOffset--) { for (int8_t blockOffset = no_of_blocks - 1; blockOffset >= 0; blockOffset--) {
blockAddr = firstBlock + blockOffset; blockAddr = firstBlock + blockOffset;
// Sector number - only on first line // Sector number - only on first line
if (isSectorTrailer) { // if (isSectorTrailer) {
if(sector < 10) // if(sector < 10)
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
else // else
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
Serial.print(sector); // Serial.print(sector);
Serial.print(" "); // Serial.print(" ");
} // }
else { // else {
Serial.print(" "); // Serial.print(" ");
} // }
// Block number // Block number
if(blockAddr < 10) // if(blockAddr < 10)
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
else { // else {
if(blockAddr < 100) // if(blockAddr < 100)
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
else // else
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
} // }
Serial.print(blockAddr); // Serial.print(blockAddr);
Serial.print(" "); // Serial.print(" ");
// Establish encrypted communications before reading the first block // Establish encrypted communications before reading the first block
if (isSectorTrailer) { if (isSectorTrailer) {
status = PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid); status = PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("PCD_Authenticate() failed: "); // Serial.print("PCD_Authenticate() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
return; return;
} }
} }
@@ -1396,21 +1396,21 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
byteCount = sizeof(buffer); byteCount = sizeof(buffer);
status = MIFARE_Read(blockAddr, buffer, &byteCount); status = MIFARE_Read(blockAddr, buffer, &byteCount);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("MIFARE_Read() failed: "); // Serial.print("MIFARE_Read() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
continue; continue;
} }
// Dump data // Dump data
for (uint8_t index = 0; index < 16; index++) { // for (uint8_t index = 0; index < 16; index++) {
if(buffer[index] < 0x10) // if(buffer[index] < 0x10)
Serial.print(" 0"); // Serial.print(" 0");
else // else
Serial.print(" "); // Serial.print(" ");
Serial.print(buffer[index], HEX); // Serial.print(buffer[index], HEX);
if ((index % 4) == 3) { // if ((index % 4) == 3) {
Serial.print(" "); // Serial.print(" ");
} // }
} // }
// Parse sector trailer data // Parse sector trailer data
if (isSectorTrailer) { if (isSectorTrailer) {
c1 = buffer[7] >> 4; c1 = buffer[7] >> 4;
@@ -1437,24 +1437,24 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
firstInGroup = (group == 3) || (group != (blockOffset + 1) / 5); firstInGroup = (group == 3) || (group != (blockOffset + 1) / 5);
} }
if (firstInGroup) { // if (firstInGroup) {
// Print access bits // // Print access bits
Serial.print(" [ "); // Serial.print(" [ ");
Serial.print((g[group] >> 2) & 1, DEC); Serial.print(" "); // Serial.print((g[group] >> 2) & 1, DEC); Serial.print(" ");
Serial.print((g[group] >> 1) & 1, DEC); Serial.print(" "); // Serial.print((g[group] >> 1) & 1, DEC); Serial.print(" ");
Serial.print((g[group] >> 0) & 1, DEC); // Serial.print((g[group] >> 0) & 1, DEC);
Serial.print(" ] "); // Serial.print(" ] ");
if (invertedError) { // if (invertedError) {
Serial.print(" Inverted access bits did not match! "); // Serial.print(" Inverted access bits did not match! ");
} // }
} // }
if (group != 3 && (g[group] == 1 || g[group] == 6)) { // Not a sector trailer, a value block // if (group != 3 && (g[group] == 1 || g[group] == 6)) { // Not a sector trailer, a value block
long value = (long(buffer[3])<<24) | (long(buffer[2])<<16) | (long(buffer[1])<<8) | long(buffer[0]); // long value = (long(buffer[3])<<24) | (long(buffer[2])<<16) | (long(buffer[1])<<8) | long(buffer[0]);
Serial.print(" Value=0x"); Serial.print(value, HEX); // Serial.print(" Value=0x"); Serial.print(value, HEX);
Serial.print(" Adr=0x"); Serial.print(buffer[12], HEX); // Serial.print(" Adr=0x"); Serial.print(buffer[12], HEX);
} // }
Serial.println(); // Serial.println();
} }
return; return;
@@ -1467,38 +1467,38 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() {
uint8_t status; uint8_t status;
uint8_t byteCount; uint8_t byteCount;
uint8_t buffer[18]; uint8_t buffer[18];
uint8_t i; // uint8_t i;
Serial.println("Page 0 1 2 3"); // Serial.println("Page 0 1 2 3");
// Try the mpages of the original Ultralight. Ultralight C has more pages. // Try the mpages of the original Ultralight. Ultralight C has more pages.
for (uint8_t page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time. for (uint8_t page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time.
// Read pages // Read pages
byteCount = sizeof(buffer); byteCount = sizeof(buffer);
status = MIFARE_Read(page, buffer, &byteCount); status = MIFARE_Read(page, buffer, &byteCount);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("MIFARE_Read() failed: "); // Serial.print("MIFARE_Read() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
break; break;
} }
// Dump data // Dump data
for (uint8_t offset = 0; offset < 4; offset++) { // for (uint8_t offset = 0; offset < 4; offset++) {
i = page + offset; // i = page + offset;
if(i < 10) // if(i < 10)
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
else // else
Serial.print(" "); // Pad with spaces // Serial.print(" "); // Pad with spaces
Serial.print(i); // Serial.print(i);
Serial.print(" "); // Serial.print(" ");
for (uint8_t index = 0; index < 4; index++) { // for (uint8_t index = 0; index < 4; index++) {
i = 4 * offset + index; // i = 4 * offset + index;
if(buffer[i] < 0x10) // if(buffer[i] < 0x10)
Serial.print(" 0"); // Serial.print(" 0");
else // else
Serial.print(" "); // Serial.print(" ");
Serial.print(buffer[i], HEX); // Serial.print(buffer[i], HEX);
} // }
Serial.println(); // Serial.println();
} // }
} }
} // End PICC_DumpMifareUltralightToSerial() } // End PICC_DumpMifareUltralightToSerial()
@@ -1550,21 +1550,21 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) {
uint8_t received; uint8_t received;
uint8_t status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 40 uint8_t status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 40
if(status != STATUS_OK) { if(status != STATUS_OK) {
if(logErrors) { // if(logErrors) {
Serial.println("Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?"); // Serial.println("Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?");
Serial.print("Error name: "); // Serial.print("Error name: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
if (received != 1 || response[0] != 0x0A) { if (received != 1 || response[0] != 0x0A) {
if (logErrors) { // if (logErrors) {
Serial.print("Got bad response on backdoor 0x40 command: "); // Serial.print("Got bad response on backdoor 0x40 command: ");
Serial.print(response[0], HEX); // Serial.print(response[0], HEX);
Serial.print(" ("); // Serial.print(" (");
Serial.print(validBits); // Serial.print(validBits);
Serial.print(" valid bits)\r\n"); // Serial.print(" valid bits)\r\n");
} // }
return false; return false;
} }
@@ -1572,21 +1572,21 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) {
validBits = 8; validBits = 8;
status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 43 status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 43
if(status != STATUS_OK) { if(status != STATUS_OK) {
if(logErrors) { // if(logErrors) {
Serial.println("Error in communication at command 0x43, after successfully executing 0x40"); // Serial.println("Error in communication at command 0x43, after successfully executing 0x40");
Serial.print("Error name: "); // Serial.print("Error name: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
if (received != 1 || response[0] != 0x0A) { if (received != 1 || response[0] != 0x0A) {
if (logErrors) { // if (logErrors) {
Serial.print("Got bad response on backdoor 0x43 command: "); // Serial.print("Got bad response on backdoor 0x43 command: ");
Serial.print(response[0], HEX); // Serial.print(response[0], HEX);
Serial.print(" ("); // Serial.print(" (");
Serial.print(validBits); // Serial.print(validBits);
Serial.print(" valid bits)\r\n"); // Serial.print(" valid bits)\r\n");
} // }
return false; return false;
} }
@@ -1606,9 +1606,9 @@ bool MFRC522::MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors) {
// UID + BCC byte can not be larger than 16 together // UID + BCC byte can not be larger than 16 together
if (!newUid || !uidSize || uidSize > 15) { if (!newUid || !uidSize || uidSize > 15) {
if (logErrors) { // if (logErrors) {
Serial.println("New UID buffer empty, size 0, or size > 15 given"); // Serial.println("New UID buffer empty, size 0, or size > 15 given");
} // }
return false; return false;
} }
@@ -1626,25 +1626,25 @@ bool MFRC522::MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors) {
// PICC_WakeupA(atqa_answer, &atqa_size); // PICC_WakeupA(atqa_answer, &atqa_size);
if (!PICC_IsNewCardPresent() || !PICC_ReadCardSerial()) { if (!PICC_IsNewCardPresent() || !PICC_ReadCardSerial()) {
Serial.println("No card was previously selected, and none are available. Failed to set UID."); // Serial.println("No card was previously selected, and none are available. Failed to set UID.");
return false; return false;
} }
status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (uint8_t)1, &key, &uid); status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (uint8_t)1, &key, &uid);
if (status != STATUS_OK) { if (status != STATUS_OK) {
// We tried, time to give up // We tried, time to give up
if (logErrors) { // if (logErrors) {
Serial.println("Failed to authenticate to card for reading, could not set UID: "); // Serial.println("Failed to authenticate to card for reading, could not set UID: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
} }
else { else {
if (logErrors) { // if (logErrors) {
Serial.print("PCD_Authenticate() failed: "); // Serial.print("PCD_Authenticate() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
} }
@@ -1654,11 +1654,11 @@ bool MFRC522::MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors) {
uint8_t byteCount = sizeof(block0_buffer); uint8_t byteCount = sizeof(block0_buffer);
status = MIFARE_Read((uint8_t)0, block0_buffer, &byteCount); status = MIFARE_Read((uint8_t)0, block0_buffer, &byteCount);
if (status != STATUS_OK) { if (status != STATUS_OK) {
if (logErrors) { // if (logErrors) {
Serial.print("MIFARE_Read() failed: "); // Serial.print("MIFARE_Read() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
Serial.println("Are you sure your KEY A for sector 0 is 0xFFFFFFFFFFFF?"); // Serial.println("Are you sure your KEY A for sector 0 is 0xFFFFFFFFFFFF?");
} // }
return false; return false;
} }
@@ -1677,19 +1677,19 @@ bool MFRC522::MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors) {
// Activate UID backdoor // Activate UID backdoor
if (!MIFARE_OpenUidBackdoor(logErrors)) { if (!MIFARE_OpenUidBackdoor(logErrors)) {
if (logErrors) { // if (logErrors) {
Serial.println("Activating the UID backdoor failed."); // Serial.println("Activating the UID backdoor failed.");
} // }
return false; return false;
} }
// Write modified block 0 back to card // Write modified block 0 back to card
status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16); status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16);
if (status != STATUS_OK) { if (status != STATUS_OK) {
if (logErrors) { // if (logErrors) {
Serial.print("MIFARE_Write() failed: "); // Serial.print("MIFARE_Write() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
@@ -1712,10 +1712,10 @@ bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
// Write modified block 0 back to card // Write modified block 0 back to card
uint8_t status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16); uint8_t status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16);
if (status != STATUS_OK) { if (status != STATUS_OK) {
if (logErrors) { // if (logErrors) {
Serial.print("MIFARE_Write() failed: "); // Serial.print("MIFARE_Write() failed: ");
Serial.println(GetStatusCodeName(status)); // Serial.println(GetStatusCodeName(status));
} // }
return false; return false;
} }
return true; return true;