Using the Seeed-Studio PN532 library, you shouldn't need to create your own commands within the library (ie. what you did with uint8_t PN532::APDU () {...}
.
Instead, you can use the methods that are already there. To establish a connection with a tag/contactless smartcard (or rather to enumerate the available tags/cards), you would start with inListPassiveTarget()
. If the tag/smartcard supports APDUs, it will later automatically be activated for APDU-based communcation. Then you can use inDataExchange()
to send and receive APDUs.
So, if you included the PN532 library like this:
PN532_xxx pn532hal(...);
PN532 nfc(pn532hal);
You could then use the library like this:
bool success = nfc.inListPassiveTarget();
if (success) {
uint8_t apdu = {
0x00, /* CLA */
0xA4, /* INS */
0x04, /* P1 */
0x00, /* P2 */
0x07, /* Lc */
0xF0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x00 /* Le */
};
uint8_t response[255];
uint8_t responseLength = 255;
success = nfc.inDataExchange(apdu, sizeof(apdu), response, &responseLength);
if (success) {
// response should now contain the R-APDU you received in response to the above C-APDU (responseLength data bytes)
}
}