add output SAK to dump functions

This commit is contained in:
Rotzbua
2016-02-15 16:25:48 +01:00
parent 543d08f5d8
commit fda5380a7a
4 changed files with 42 additions and 16 deletions

View File

@@ -1301,23 +1301,11 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
) { ) {
MIFARE_Key key; MIFARE_Key key;
// UID // Dump UID, SAK and Type
Serial.print(F("Card UID:")); PICC_DumpDetailsToSerial(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 contents // Dump contents
PICC_Type piccType = PICC_GetType(uid->sak);
switch (piccType) { switch (piccType) {
case PICC_TYPE_MIFARE_MINI: case PICC_TYPE_MIFARE_MINI:
case PICC_TYPE_MIFARE_1K: 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. PICC_HaltA(); // Already done if it was a MIFARE Classic PICC.
} // End PICC_DumpToSerial() } // 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. * Dumps memory contents of a MIFARE Classic PICC.
* On success the PICC is halted after dumping the data. * On success the PICC is halted after dumping the data.

View File

@@ -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 // 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); //const char *PICC_GetTypeName(byte type);
static const __FlashStringHelper *PICC_GetTypeName(PICC_Type type); static const __FlashStringHelper *PICC_GetTypeName(PICC_Type type);
// Support functions for debuging
void PCD_DumpVersionToSerial(); void PCD_DumpVersionToSerial();
void PICC_DumpToSerial(Uid *uid); void PICC_DumpToSerial(Uid *uid);
void PICC_DumpDetailsToSerial(Uid *uid);
void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key); void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key);
void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector); void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector);
void PICC_DumpMifareUltralightToSerial(); void PICC_DumpMifareUltralightToSerial();
// Advanced functions for MIFARE
void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3); void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3);
bool MIFARE_OpenUidBackdoor(bool logErrors); bool MIFARE_OpenUidBackdoor(bool logErrors);
bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors); bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors);

View File

@@ -47,7 +47,7 @@ void setup() {
SPI.begin(); // Init SPI bus SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details 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() { void loop() {

View File

@@ -64,11 +64,16 @@ PCD_MIFARE_Transceive KEYWORD2
GetStatusCodeName KEYWORD2 GetStatusCodeName KEYWORD2
PICC_GetType KEYWORD2 PICC_GetType KEYWORD2
PICC_GetTypeName KEYWORD2 PICC_GetTypeName KEYWORD2
# Support functions for debuging
PCD_DumpVersionToSerial KEYWORD2 PCD_DumpVersionToSerial KEYWORD2
PICC_DumpToSerial KEYWORD2 PICC_DumpToSerial KEYWORD2
PICC_DumpDetailsToSerial KEYWORD2
PICC_DumpMifareClassicToSerial KEYWORD2 PICC_DumpMifareClassicToSerial KEYWORD2
PICC_DumpMifareClassicSectorToSerial KEYWORD2 PICC_DumpMifareClassicSectorToSerial KEYWORD2
PICC_DumpMifareUltralightToSerial KEYWORD2 PICC_DumpMifareUltralightToSerial KEYWORD2
# Advanced functions for MIFARE
MIFARE_SetAccessBits KEYWORD2 MIFARE_SetAccessBits KEYWORD2
MIFARE_OpenUidBackdoor KEYWORD2 MIFARE_OpenUidBackdoor KEYWORD2
MIFARE_SetUid KEYWORD2 MIFARE_SetUid KEYWORD2