From 34989a2d75cb6609f7cfbe2f005a474d3c5b6c6e Mon Sep 17 00:00:00 2001 From: deimos Date: Tue, 8 Aug 2023 11:07:53 -0600 Subject: [PATCH] refactor: reader activate next --- examples/DetectTags/DetectTags.ino | 4 +- .../ISO14443-3A_read_block.ino | 2 +- .../ISO14443-3A_write_block.ino | 2 +- .../ISO15693_read_block.ino | 2 +- .../ISO15693_write_block.ino | 2 +- .../MifareClassic_read_block.ino | 2 +- .../MifareClassic_write_block.ino | 2 +- examples/NDEFReceive/NDEFReceive.ino | 4 +- src/Electroniccats_PN7150.cpp | 109 +++++++++--------- src/Electroniccats_PN7150.h | 3 +- 10 files changed, 69 insertions(+), 63 deletions(-) diff --git a/examples/DetectTags/DetectTags.ino b/examples/DetectTags/DetectTags.ino index 3f3f61a..8e348f8 100644 --- a/examples/DetectTags/DetectTags.ino +++ b/examples/DetectTags/DetectTags.ino @@ -117,7 +117,7 @@ void displayCardInfo(RfIntf_t RfIntf){ //Funtion in charge to show the card/s in break; } if(RfIntf.MoreTags) { // It will try to identify more NFC cards if they are the same technology - if(nfc.ReaderActivateNext(&RfIntf) == NFC_ERROR) break; + if(nfc.readerActivateNext(&RfIntf) == NFC_ERROR) break; } else break; } @@ -171,7 +171,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino b/examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino index 5c76189..20a1028 100644 --- a/examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino +++ b/examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino @@ -124,7 +124,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino b/examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino index ed0ed6d..54232ff 100644 --- a/examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino +++ b/examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino @@ -140,7 +140,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/ISO15693_read_block/ISO15693_read_block.ino b/examples/ISO15693_read_block/ISO15693_read_block.ino index e0ff57d..f804a47 100644 --- a/examples/ISO15693_read_block/ISO15693_read_block.ino +++ b/examples/ISO15693_read_block/ISO15693_read_block.ino @@ -121,7 +121,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/ISO15693_write_block/ISO15693_write_block.ino b/examples/ISO15693_write_block/ISO15693_write_block.ino index 1fa4a08..bbb0a0d 100644 --- a/examples/ISO15693_write_block/ISO15693_write_block.ino +++ b/examples/ISO15693_write_block/ISO15693_write_block.ino @@ -134,7 +134,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/MifareClassic_read_block/MifareClassic_read_block.ino b/examples/MifareClassic_read_block/MifareClassic_read_block.ino index ce80aac..4ccaa1a 100644 --- a/examples/MifareClassic_read_block/MifareClassic_read_block.ino +++ b/examples/MifareClassic_read_block/MifareClassic_read_block.ino @@ -133,7 +133,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/MifareClassic_write_block/MifareClassic_write_block.ino b/examples/MifareClassic_write_block/MifareClassic_write_block.ino index 2d823ba..65ce76e 100644 --- a/examples/MifareClassic_write_block/MifareClassic_write_block.ino +++ b/examples/MifareClassic_write_block/MifareClassic_write_block.ino @@ -170,7 +170,7 @@ void loop(){ //* It can detect multiple cards at the same time if they use the same protocol if(RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/examples/NDEFReceive/NDEFReceive.ino b/examples/NDEFReceive/NDEFReceive.ino index fd7d51f..4d6794c 100644 --- a/examples/NDEFReceive/NDEFReceive.ino +++ b/examples/NDEFReceive/NDEFReceive.ino @@ -111,7 +111,7 @@ void displayCardInfo(RfIntf_t RfIntf) { // Funtion in charge to show the card/s break; } if (RfIntf.MoreTags) { // It will try to identify more NFC cards if they are the same technology - if (nfc.ReaderActivateNext(&RfIntf) == NFC_ERROR) break; + if (nfc.readerActivateNext(&RfIntf) == NFC_ERROR) break; } else break; } @@ -172,7 +172,7 @@ void loop() { //* It can detect multiple cards at the same time if they use the same protocol if (RfInterface.MoreTags) { - nfc.ReaderActivateNext(&RfInterface); + nfc.readerActivateNext(&RfInterface); } //* Wait for card removal nfc.processReaderMode(RfInterface, PRESENCE_CHECK); diff --git a/src/Electroniccats_PN7150.cpp b/src/Electroniccats_PN7150.cpp index fbc5dc0..a418c4f 100644 --- a/src/Electroniccats_PN7150.cpp +++ b/src/Electroniccats_PN7150.cpp @@ -949,6 +949,63 @@ bool Electroniccats_PN7150::ReaderReActivate(RfIntf_t *pRfIntf) { return Electroniccats_PN7150::readerReActivate(pRfIntf); } +bool Electroniccats_PN7150::readerActivateNext(RfIntf_t *pRfIntf) { + uint8_t NCIStopDiscovery[] = {0x21, 0x06, 0x01, 0x01}; + uint8_t NCIRfDiscoverSelect[] = {0x21, 0x04, 0x03, 0x02, PROT_ISODEP, INTF_ISODEP}; + + bool status = ERROR; + + pRfIntf->MoreTags = false; + + if (gNextTag_Protocol == PROT_UNDETERMINED) { + pRfIntf->Interface = INTF_UNDETERMINED; + pRfIntf->Protocol = PROT_UNDETERMINED; + return ERROR; + } + + /* First disconnect current tag */ + (void)writeData(NCIStopDiscovery, sizeof(NCIStopDiscovery)); + getMessage(); + + if ((rxBuffer[0] != 0x41) && (rxBuffer[1] != 0x06) && (rxBuffer[3] != 0x00)) + return ERROR; + getMessage(100); + + if ((rxBuffer[0] != 0x61) && (rxBuffer[1] != 0x06)) + return ERROR; + + NCIRfDiscoverSelect[4] = gNextTag_Protocol; + if (gNextTag_Protocol == PROT_ISODEP) + NCIRfDiscoverSelect[5] = INTF_ISODEP; + else if (gNextTag_Protocol == PROT_ISODEP) + NCIRfDiscoverSelect[5] = INTF_NFCDEP; + else if (gNextTag_Protocol == PROT_MIFARE) + NCIRfDiscoverSelect[5] = INTF_TAGCMD; + else + NCIRfDiscoverSelect[5] = INTF_FRAME; + + (void)writeData(NCIRfDiscoverSelect, sizeof(NCIRfDiscoverSelect)); + getMessage(); + + if ((rxBuffer[0] == 0x41) && (rxBuffer[1] == 0x04) && (rxBuffer[3] == 0x00)) { + getMessage(100); + if ((rxBuffer[0] == 0x61) || (rxBuffer[1] == 0x05)) { + pRfIntf->Interface = rxBuffer[4]; + pRfIntf->Protocol = rxBuffer[5]; + pRfIntf->ModeTech = rxBuffer[6]; + fillInterfaceInfo(pRfIntf, &rxBuffer[10]); + status = SUCCESS; + } + } + + return status; +} + +// Deprecated, use readerActivateNext() instead +bool Electroniccats_PN7150::ReaderActivateNext(RfIntf_t *pRfIntf) { + return Electroniccats_PN7150::readerActivateNext(pRfIntf); +} + void Electroniccats_PN7150::ReadNdef(RfIntf_t RfIntf) { uint8_t Cmd[MAX_NCI_FRAME_SIZE]; uint16_t CmdSize = 0; @@ -1013,58 +1070,6 @@ void Electroniccats_PN7150::WriteNdef(RfIntf_t RfIntf) { } } -bool Electroniccats_PN7150::ReaderActivateNext(RfIntf_t *pRfIntf) { - uint8_t NCIStopDiscovery[] = {0x21, 0x06, 0x01, 0x01}; - uint8_t NCIRfDiscoverSelect[] = {0x21, 0x04, 0x03, 0x02, PROT_ISODEP, INTF_ISODEP}; - - bool status = ERROR; - - pRfIntf->MoreTags = false; - - if (gNextTag_Protocol == PROT_UNDETERMINED) { - pRfIntf->Interface = INTF_UNDETERMINED; - pRfIntf->Protocol = PROT_UNDETERMINED; - return ERROR; - } - - /* First disconnect current tag */ - (void)writeData(NCIStopDiscovery, sizeof(NCIStopDiscovery)); - getMessage(); - - if ((rxBuffer[0] != 0x41) && (rxBuffer[1] != 0x06) && (rxBuffer[3] != 0x00)) - return ERROR; - getMessage(100); - - if ((rxBuffer[0] != 0x61) && (rxBuffer[1] != 0x06)) - return ERROR; - - NCIRfDiscoverSelect[4] = gNextTag_Protocol; - if (gNextTag_Protocol == PROT_ISODEP) - NCIRfDiscoverSelect[5] = INTF_ISODEP; - else if (gNextTag_Protocol == PROT_ISODEP) - NCIRfDiscoverSelect[5] = INTF_NFCDEP; - else if (gNextTag_Protocol == PROT_MIFARE) - NCIRfDiscoverSelect[5] = INTF_TAGCMD; - else - NCIRfDiscoverSelect[5] = INTF_FRAME; - - (void)writeData(NCIRfDiscoverSelect, sizeof(NCIRfDiscoverSelect)); - getMessage(); - - if ((rxBuffer[0] == 0x41) && (rxBuffer[1] == 0x04) && (rxBuffer[3] == 0x00)) { - getMessage(100); - if ((rxBuffer[0] == 0x61) || (rxBuffer[1] == 0x05)) { - pRfIntf->Interface = rxBuffer[4]; - pRfIntf->Protocol = rxBuffer[5]; - pRfIntf->ModeTech = rxBuffer[6]; - fillInterfaceInfo(pRfIntf, &rxBuffer[10]); - status = SUCCESS; - } - } - - return status; -} - bool Electroniccats_PN7150::ConfigureSettings(void) { #if NXP_CORE_CONF /* NCI standard dedicated settings diff --git a/src/Electroniccats_PN7150.h b/src/Electroniccats_PN7150.h index 2f54fbe..871ed5c 100644 --- a/src/Electroniccats_PN7150.h +++ b/src/Electroniccats_PN7150.h @@ -287,7 +287,8 @@ class Electroniccats_PN7150 { bool ReaderTagCmd(unsigned char *pCommand, unsigned char CommandSize, unsigned char *pAnswer, unsigned char *pAnswerSize); // Deprecated, use readerTagCmd() instead bool readerReActivate(RfIntf_t *pRfIntf); bool ReaderReActivate(RfIntf_t *pRfIntf); // Deprecated, use readerReActivate() instead - bool ReaderActivateNext(RfIntf_t *pRfIntf); + bool readerActivateNext(RfIntf_t *pRfIntf); + bool ReaderActivateNext(RfIntf_t *pRfIntf); // Deprecated, use readerActivateNext() instead bool ConfigureSettings(void); bool ConfigureSettings(uint8_t *nfcuid, uint8_t uidlen); void NdefPull_Cb(unsigned char *pNdefMessage, unsigned short NdefMessageSize);