Skip to content

Commit

Permalink
fix: reset not working on type 4 tags
Browse files Browse the repository at this point in the history
- add stop discovery at the begining of the reset method
- update detect tags example
- add info properties getters
  • Loading branch information
DeimosHall committed Aug 14, 2023
1 parent 73baecf commit 24b8b82
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 56 deletions.
84 changes: 45 additions & 39 deletions examples/DetectTags/DetectTags.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,60 @@ void PrintBuf(const byte* data, const uint32_t numBytes) { // Print hex data bu
Serial.println();
}

String getHexRepresentation(const byte* data, const uint32_t numBytes) {
String hexString;
for (uint32_t szPos = 0; szPos < numBytes; szPos++) {
hexString += "0x";
if (data[szPos] <= 0xF)
hexString += "0";
hexString += String(data[szPos] & 0xFF, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1)) {
hexString += " ";
}
}
return hexString;
}

void displayCardInfo(RfIntf_t RfIntf) { // Funtion in charge to show the card/s in te field
char tmp[16];
int index = 0;
static String nfcID;

while (1) {
switch (RfIntf.Protocol) { // Indetify card protocol
case PROT_T1T:
case PROT_T2T:
case PROT_T3T:
case PROT_ISODEP:
switch (nfc.remoteDevice.getProtocol()) { // Indetify card protocol
case nfc.protocol.T1T:
case nfc.protocol.T2T:
case nfc.protocol.T3T:
case nfc.protocol.ISODEP:
Serial.print(" - POLL MODE: Remote activated tag type: ");
Serial.println(RfIntf.Protocol);
Serial.println(nfc.remoteDevice.getProtocol());
break;
case PROT_ISO15693:
case nfc.protocol.ISO15693:
Serial.println(" - POLL MODE: Remote ISO15693 card activated");
break;
case PROT_MIFARE:
case nfc.protocol.MIFARE:
Serial.println(" - POLL MODE: Remote MIFARE card activated");
break;
default:
Serial.println(" - POLL MODE: Undetermined target");
return;
}

switch (RfIntf.ModeTech) { // Indetify card technology
case (MODE_POLL | TECH_PASSIVE_NFCA):
switch (nfc.remoteDevice.getModeTech()) { // Indetify card technology
case (nfc.modeTech.POLL | nfc.tech.PASSIVE_NFCA):
Serial.print("\tSENS_RES = ");
sprintf(tmp, "0x%.2X", RfIntf.Info.NFC_APP.SensRes[0]);
sprintf(tmp, "0x%.2X", nfc.remoteDevice.getAPPSensRes(index));
Serial.print(tmp);
Serial.print(" ");
sprintf(tmp, "0x%.2X", RfIntf.Info.NFC_APP.SensRes[1]);
index++;
sprintf(tmp, "0x%.2X", nfc.remoteDevice.getAPPSensRes(index));
Serial.print(tmp);
Serial.println(" ");

Serial.print("\tNFCID = ");
PrintBuf(RfIntf.Info.NFC_APP.NfcId, RfIntf.Info.NFC_APP.NfcIdLen);
nfcID = getHexRepresentation(nfc.remoteDevice.getAPPID(), nfc.remoteDevice.getAPPIDLen());
// nfcID = getHexRepresentation(RfIntf.Info.NFC_APP.NfcId, RfIntf.Info.NFC_APP.NfcIdLen);
Serial.println(nfcID);

if (RfIntf.Info.NFC_APP.SelResLen != 0) {
Serial.print("\tSEL_RES = ");
Expand Down Expand Up @@ -146,35 +166,21 @@ void setup() {
}

void loop() {
if (!nfc.waitForDiscoveryNotification(&RfInterface)) { // Waiting to detect cards
if (!nfc.waitForDiscoveryNotification()) { // Waiting to detect cards
displayCardInfo(RfInterface);
switch (RfInterface.Protocol) {
case PROT_T1T:
case PROT_T2T:
case PROT_T3T:
case PROT_ISODEP:
nfc.processReaderMode(RfInterface, READ_NDEF);
break;

case PROT_ISO15693:
break;

case PROT_MIFARE:
nfc.processReaderMode(RfInterface, READ_NDEF);
break;

default:
break;
}

//* It can detect multiple cards at the same time if they use the same protocol
if (RfInterface.MoreTags) {
nfc.readerActivateNext(&RfInterface);
// It can detect multiple cards at the same time if they use the same protocol
if (nfc.remoteDevice.hasMoreTags()) {
nfc.activateNextTagDiscovery();
Serial.println("Multiple cards are detected!");
}
//* Wait for card removal
nfc.processReaderMode(RfInterface, PRESENCE_CHECK);
Serial.println("CARD REMOVED!");
Serial.println("Remove the Card");
nfc.waitForTagRemoval();
Serial.println("Card removed!");
}
nfc.reset();

Serial.println("Restarting...");
nfc.reset();
Serial.println("Waiting for a Card...");
delay(500);
}
6 changes: 5 additions & 1 deletion src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ void Electroniccats_PN7150::presenceCheck(RfIntf_t RfIntf) {
do {
delay(500);
for (i = 0; i < 8; i++) {
NCIPresCheckIso15693[i + 6] = remoteDevice.getVPPID(7 - i);
NCIPresCheckIso15693[i + 6] = remoteDevice.getVPPID()[7 - i];
}
(void)writeData(NCIPresCheckIso15693, sizeof(NCIPresCheckIso15693));
getMessage();
Expand Down Expand Up @@ -1693,6 +1693,10 @@ bool Electroniccats_PN7150::NxpNci_FactoryTest_RfOn() {
}

bool Electroniccats_PN7150::reset() {
if (Electroniccats_PN7150::stopDiscovery()) {
return false;
}

if (Electroniccats_PN7150::configMode()) {
return false;
}
Expand Down
17 changes: 14 additions & 3 deletions src/RemoteDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ bool RemoteDevice::hasMoreTags() const {
return this->remoteDeviceStruct.moreTagsAvailable;
}

// TODO: validate memory access
unsigned char RemoteDevice::getVPPID(int position) const {
return this->remoteDeviceStruct.info.nfcVPP.id[position];
unsigned char RemoteDevice::getAPPSensRes(int index) const {
return this->remoteDeviceStruct.info.nfcAPP.sensRes[index];
}

const unsigned char* RemoteDevice::getAPPID() const {
return this->remoteDeviceStruct.info.nfcAPP.nfcId;
}

unsigned char RemoteDevice::getAPPIDLen() const {
return this->remoteDeviceStruct.info.nfcAPP.nfcIdLen;
}

const unsigned char* RemoteDevice::getVPPID() const {
return this->remoteDeviceStruct.info.nfcVPP.id;
}

void RemoteDevice::setInterface(unsigned char interface) {
Expand Down
33 changes: 20 additions & 13 deletions src/RemoteDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,53 @@
/* POLL passive type A */
struct RfIntf_info_APP_t {
unsigned char SensRes[2];
unsigned char NfcIdLen;
unsigned char NfcId[10];
unsigned char SelResLen;
unsigned char NfcIdLen;
unsigned char SelRes[1];
unsigned char RatsLen;
unsigned char SelResLen;
unsigned char Rats[20];
unsigned char RatsLen;
};

/* POLL passive type A camelCase */
struct RfIntfInfoAppCC_t {
unsigned char sensRes[2];
unsigned char nfcIdLen;
unsigned char nfcId[10];
unsigned char selResLen;
unsigned char nfcIdLen;
unsigned char selRes[1];
unsigned char ratsLen;
unsigned char selResLen;
unsigned char rats[20];
unsigned char ratsLen;
};

/* POLL passive type B */
struct RfIntf_info_BPP_t {
unsigned char SensResLen;
unsigned char SensRes[12];
unsigned char AttribResLen;
unsigned char SensResLen;
unsigned char AttribRes[17];
unsigned char AttribResLen;
};

/* POLL passive type B camelCase */
struct RfIntfInfoBppCC_t {
unsigned char sensResLen;
unsigned char sensRes[12];
unsigned char attribResLen;
unsigned char sensResLen;
unsigned char attribRes[17];
unsigned char attribResLen;
};

/* POLL passive type F */
struct RfIntf_info_FPP_t {
unsigned char BitRate;
unsigned char SensResLen;
unsigned char SensRes[18];
unsigned char SensResLen;
};

/* POLL passive type F camelCase */
struct RfIntfInfoFppCC_t {
unsigned char bitRate;
unsigned char sensResLen;
unsigned char sensRes[18];
unsigned char sensResLen;
};

/* POLL passive type ISO15693 */
Expand Down Expand Up @@ -120,7 +120,14 @@ class RemoteDevice {
unsigned char getProtocol() const;
unsigned char getModeTech() const;
bool hasMoreTags() const;
unsigned char getVPPID(int position) const;
unsigned char getAPPSensRes(int index) const;
const unsigned char* getAPPID() const;
unsigned char getAPPIDLen() const;
unsigned char getAPPSelRes(int index) const;
unsigned char getAPPSelResLen() const;
unsigned char getAPPRats(int index) const;
unsigned char getAPPRatsLen() const;
const unsigned char* getVPPID() const;
void setInterface(unsigned char interface);
void setProtocol(unsigned char protocol);
void setModeTech(unsigned char modeTech);
Expand Down

0 comments on commit 24b8b82

Please sign in to comment.