Skip to content

Commit

Permalink
refactor: reader activate next
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 8, 2023
1 parent bca4d4a commit 34989a2
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 63 deletions.
4 changes: 2 additions & 2 deletions examples/DetectTags/DetectTags.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/ISO15693_read_block/ISO15693_read_block.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/ISO15693_write_block/ISO15693_write_block.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/NDEFReceive/NDEFReceive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
109 changes: 57 additions & 52 deletions src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Electroniccats_PN7150.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 34989a2

Please sign in to comment.