Fork of PN532 by
Diff: PN532.cpp
- Revision:
- 7:a26fa6ef10eb
- Parent:
- 6:26c1b3b6c192
- Child:
- 8:30bba738e292
--- a/PN532.cpp Tue Mar 25 16:48:10 2014 +0000 +++ b/PN532.cpp Tue Feb 09 16:16:11 2016 +0000 @@ -12,6 +12,8 @@ #ifndef ARDUINO #include <stdio.h> +#include <stdlib.h> + #endif #define HAL(func) (_interface->func) @@ -325,7 +327,10 @@ DMSG("ATQA: 0x"); DMSG_HEX(sens_res); DMSG("SAK: 0x"); DMSG_HEX(pn532_packetbuffer[4]); DMSG("\n"); - + printf("ATQA: "); + for(int i = 0; i < 8; i++){ + printf("%02x ",pn532_packetbuffer[i]); + } /* Card appears to be Mifare Classic */ *uidLength = pn532_packetbuffer[5]; @@ -337,6 +342,72 @@ } +/***** ISO14443A Commands ******/ +// UPDATED FROM readPassiveTargetID with SAK bit +/**************************************************************************/ +/*! + Waits for an ISO14443A target to enter the field + + @param cardBaudRate Baud rate of the card + @param uid Pointer to the array that will be populated + with the card's UID (up to 7 bytes) + @param uidLength Pointer to the variable that will hold the + length of the card's UID. + @param sak Pointer to the variable that will hold the + SAK bit + + @returns 1 if everything executed properly, 0 for an error +*/ +/**************************************************************************/ +bool PN532::readPassiveTarget(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint8_t *sak, uint16_t timeout) +{ + pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET; + pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later) + pn532_packetbuffer[2] = cardbaudrate; + + if (HAL(writeCommand)(pn532_packetbuffer, 3)) { + return 0x0; // command failed + } + + // read data packet + if (HAL(readResponse)(pn532_packetbuffer, sizeof(pn532_packetbuffer), timeout) < 0) { + return 0x0; + } + + // check some basic stuff + /* ISO14443A card response should be in the following format: + + byte Description + ------------- ------------------------------------------ + b0 Tags Found + b1 Tag Number (only one used in this example) + b2..3 SENS_RES + b4 SEL_RES + b5 NFCID Length + b6..NFCIDLen NFCID + */ + + if (pn532_packetbuffer[0] != 1) + return 0; + + uint16_t sens_res = pn532_packetbuffer[2]; + sens_res <<= 8; + sens_res |= pn532_packetbuffer[3]; + + DMSG("ATQA: 0x"); DMSG_HEX(sens_res); + DMSG("SAK: 0x"); DMSG_HEX(pn532_packetbuffer[4]); + DMSG("\n"); + *sak = pn532_packetbuffer[4]; + /* Card appears to be Mifare Classic */ + *uidLength = pn532_packetbuffer[5]; + + for (uint8_t i = 0; i < pn532_packetbuffer[5]; i++) { + uid[i] = pn532_packetbuffer[6 + i]; + } + + return 1; +} + /***** Mifare Classic Functions ******/ /**************************************************************************/