diff --git a/MFRC522.cpp b/MFRC522.cpp index 1d91670..422b509 100644 --- a/MFRC522.cpp +++ b/MFRC522.cpp @@ -1301,23 +1301,11 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro ) { MIFARE_Key key; - // UID - Serial.print(F("Card UID:")); - for (byte i = 0; i < uid->size; i++) { - if(uid->uidByte[i] < 0x10) - Serial.print(F(" 0")); - else - Serial.print(F(" ")); - Serial.print(uid->uidByte[i], HEX); - } - Serial.println(); - - // PICC type - PICC_Type piccType = PICC_GetType(uid->sak); - Serial.print(F("PICC type: ")); - Serial.println(PICC_GetTypeName(piccType)); + // Dump UID, SAK and Type + PICC_DumpDetailsToSerial(uid); // Dump contents + PICC_Type piccType = PICC_GetType(uid->sak); switch (piccType) { case PICC_TYPE_MIFARE_MINI: case PICC_TYPE_MIFARE_1K: @@ -1350,6 +1338,34 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro PICC_HaltA(); // Already done if it was a MIFARE Classic PICC. } // End PICC_DumpToSerial() +/** + * Dumps card info (UID,SAK,Type) about the selected PICC to Serial. + */ +void MFRC522::PICC_DumpDetailsToSerial(Uid *uid ///< Pointer to Uid struct returned from a successful PICC_Select(). + ) { + // UID + Serial.print(F("Card UID:")); + for (byte i = 0; i < uid->size; i++) { + if(uid->uidByte[i] < 0x10) + Serial.print(F(" 0")); + else + Serial.print(F(" ")); + Serial.print(uid->uidByte[i], HEX); + } + Serial.println(); + + // SAK + Serial.print(F("Card SAK: ")); + if(uid->sak < 0x10) + Serial.print(F("0")); + Serial.println(uid->sak, HEX); + + // (suggested) PICC type + PICC_Type piccType = PICC_GetType(uid->sak); + Serial.print(F("PICC type: ")); + Serial.println(PICC_GetTypeName(piccType)); +} // End PICC_DumpDetailsToSerial() + /** * Dumps memory contents of a MIFARE Classic PICC. * On success the PICC is halted after dumping the data. diff --git a/MFRC522.h b/MFRC522.h index ccaef0d..cb31bf3 100644 --- a/MFRC522.h +++ b/MFRC522.h @@ -386,11 +386,16 @@ public: // old function used too much memory, now name moved to flash; if you need char, copy from flash to memory //const char *PICC_GetTypeName(byte type); static const __FlashStringHelper *PICC_GetTypeName(PICC_Type type); + + // Support functions for debuging void PCD_DumpVersionToSerial(); void PICC_DumpToSerial(Uid *uid); + void PICC_DumpDetailsToSerial(Uid *uid); void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key); void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector); void PICC_DumpMifareUltralightToSerial(); + + // Advanced functions for MIFARE void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3); bool MIFARE_OpenUidBackdoor(bool logErrors); bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors); diff --git a/examples/DumpInfo/DumpInfo.ino b/examples/DumpInfo/DumpInfo.ino index a6345b1..325b7ca 100644 --- a/examples/DumpInfo/DumpInfo.ino +++ b/examples/DumpInfo/DumpInfo.ino @@ -47,7 +47,7 @@ void setup() { SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details - Serial.println(F("Scan PICC to see UID, type, and data blocks...")); + Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); } void loop() { diff --git a/keywords.txt b/keywords.txt index 07fea88..ae2a39e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -64,11 +64,16 @@ PCD_MIFARE_Transceive KEYWORD2 GetStatusCodeName KEYWORD2 PICC_GetType KEYWORD2 PICC_GetTypeName KEYWORD2 + +# Support functions for debuging PCD_DumpVersionToSerial KEYWORD2 PICC_DumpToSerial KEYWORD2 +PICC_DumpDetailsToSerial KEYWORD2 PICC_DumpMifareClassicToSerial KEYWORD2 PICC_DumpMifareClassicSectorToSerial KEYWORD2 PICC_DumpMifareUltralightToSerial KEYWORD2 + +# Advanced functions for MIFARE MIFARE_SetAccessBits KEYWORD2 MIFARE_OpenUidBackdoor KEYWORD2 MIFARE_SetUid KEYWORD2