Skip to content

Commit

Permalink
refactor: process card mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 7, 2023
1 parent 0586fa7 commit efaf25b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
2 changes: 1 addition & 1 deletion examples/NDEFSend/NDEFSend.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void checkReaders() {
if ((CmdSize >= 2) && (Cmd[0] == 0x00)) { // Expect at least two bytes
if (Cmd[1] == 0xA4) {
Serial.println("\nReader detected!");
nfc.ProcessCardMode(RfInterface);
nfc.processCardMode(RfInterface);
}
nfc.cardModeSend(STATUSOK, sizeof(STATUSOK));
Serial.print("Waiting for an NDEF device");
Expand Down
104 changes: 54 additions & 50 deletions src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,58 @@ uint8_t Electroniccats_PN7150::wakeupNCI() { // the device has to wake up using
return SUCCESS;
}

void Electroniccats_PN7150::ProcessCardMode(RfIntf_t RfIntf) {
bool Electroniccats_PN7150::cardModeSend(unsigned char *pData, unsigned char DataSize) {
bool status;
uint8_t Cmd[MAX_NCI_FRAME_SIZE];

/* Compute and send DATA_PACKET */
Cmd[0] = 0x00;
Cmd[1] = 0x00;
Cmd[2] = DataSize;
memcpy(&Cmd[3], pData, DataSize);
(void)writeData(Cmd, DataSize + 3);
return status;
}

// Deprecated, use cardModeSend() instead
bool Electroniccats_PN7150::CardModeSend(unsigned char *pData, unsigned char DataSize) {
return Electroniccats_PN7150::cardModeSend(pData, DataSize);
}

bool Electroniccats_PN7150::cardModeReceive(unsigned char *pData, unsigned char *pDataSize) {
#ifdef DEBUG2
Serial.println("[DEBUG] cardModeReceive exec");
#endif
#ifdef DEBUG3
Serial.println("[DEBUG] cardModeReceive exec");
#endif

bool status = NFC_ERROR;
uint8_t Ans[MAX_NCI_FRAME_SIZE];

(void)writeData(Ans, 255);
getMessage(2000);

/* Is data packet ? */
if ((rxBuffer[0] == 0x00) && (rxBuffer[1] == 0x00)) {
#ifdef DEBUG2
Serial.println(rxBuffer[2]);
#endif
*pDataSize = rxBuffer[2];
memcpy(pData, &rxBuffer[3], *pDataSize);
status = NFC_SUCCESS;
} else {
status = NFC_ERROR;
}
return status;
}

// Deprecated, use cardModeReceive() instead
bool Electroniccats_PN7150::CardModeReceive(unsigned char *pData, unsigned char *pDataSize) {
return Electroniccats_PN7150::cardModeReceive(pData, pDataSize);
}

void Electroniccats_PN7150::processCardMode(RfIntf_t RfIntf) {
uint8_t Answer[MAX_NCI_FRAME_SIZE];

uint8_t NCIStopDiscovery[] = {0x21, 0x06, 0x01, 0x00};
Expand Down Expand Up @@ -570,55 +621,8 @@ void Electroniccats_PN7150::ProcessCardMode(RfIntf_t RfIntf) {
}
}

bool Electroniccats_PN7150::cardModeSend(unsigned char *pData, unsigned char DataSize) {
bool status;
uint8_t Cmd[MAX_NCI_FRAME_SIZE];

/* Compute and send DATA_PACKET */
Cmd[0] = 0x00;
Cmd[1] = 0x00;
Cmd[2] = DataSize;
memcpy(&Cmd[3], pData, DataSize);
(void)writeData(Cmd, DataSize + 3);
return status;
}

// Deprecated, use cardModeSend() instead
bool Electroniccats_PN7150::CardModeSend(unsigned char *pData, unsigned char DataSize) {
return Electroniccats_PN7150::cardModeSend(pData, DataSize);
}

bool Electroniccats_PN7150::cardModeReceive(unsigned char *pData, unsigned char *pDataSize) {
#ifdef DEBUG2
Serial.println("[DEBUG] cardModeReceive exec");
#endif
#ifdef DEBUG3
Serial.println("[DEBUG] cardModeReceive exec");
#endif

bool status = NFC_ERROR;
uint8_t Ans[MAX_NCI_FRAME_SIZE];

(void)writeData(Ans, 255);
getMessage(2000);

/* Is data packet ? */
if ((rxBuffer[0] == 0x00) && (rxBuffer[1] == 0x00)) {
#ifdef DEBUG2
Serial.println(rxBuffer[2]);
#endif
*pDataSize = rxBuffer[2];
memcpy(pData, &rxBuffer[3], *pDataSize);
status = NFC_SUCCESS;
} else {
status = NFC_ERROR;
}
return status;
}

// Deprecated, use cardModeReceive() instead
bool Electroniccats_PN7150::CardModeReceive(unsigned char *pData, unsigned char *pDataSize) {
return Electroniccats_PN7150::cardModeReceive(pData, pDataSize);
void Electroniccats_PN7150::ProcessCardMode(RfIntf_t RfIntf) {
Electroniccats_PN7150::processCardMode(RfIntf);
}

void Electroniccats_PN7150::FillInterfaceInfo(RfIntf_t *pRfIntf, uint8_t *pBuf) {
Expand Down
3 changes: 2 additions & 1 deletion src/Electroniccats_PN7150.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class Electroniccats_PN7150 {
bool CardModeSend(unsigned char *pData, unsigned char DataSize); // Deprecated, use cardModeSend() instead
bool cardModeReceive(unsigned char *pData, unsigned char *pDataSize);
bool CardModeReceive(unsigned char *pData, unsigned char *pDataSize); // Deprecated, use cardModeReceive() instead
void processCardMode(RfIntf_t RfIntf);
void ProcessCardMode(RfIntf_t RfIntf); // Deprecated, use processCardMode() instead
void FillInterfaceInfo(RfIntf_t *pRfIntf, uint8_t *pBuf);
bool ReaderTagCmd(unsigned char *pCommand, unsigned char CommandSize, unsigned char *pAnswer, unsigned char *pAnswerSize);
void ProcessReaderMode(RfIntf_t RfIntf, RW_Operation_t Operation);
Expand All @@ -288,7 +290,6 @@ class Electroniccats_PN7150 {
void ProcessP2pMode(RfIntf_t RfIntf);
void ReadNdef(RfIntf_t RfIntf);
void WriteNdef(RfIntf_t RfIntf);
void ProcessCardMode(RfIntf_t RfIntf);
};

#endif

0 comments on commit efaf25b

Please sign in to comment.