mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-02-19 08:16:35 +00:00
Factorise code.
Avoid redundant code in PN53x usb and uart drivers. Since it makes sense to report errors at the nfc_device_t level, pass it directly to pn53x_transceive(). Programs using the libnfc MAY use pn53x_transceive() to communicate with a NFC device, and SHALL not use anymore pnd->pdc->transceive(). Code in the library itself SHOULD avoid calling pnd->pdc->transceive(), so such construct have been updated accordingly.
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#include <nfc/nfc.h>
|
||||
#include <nfc/nfc-messages.h>
|
||||
#include "nfc-utils.h"
|
||||
#include "chips/pn53x.h"
|
||||
|
||||
#define MAX_FRAME_LEN 264
|
||||
#define TIMEOUT 60 // secs.
|
||||
@@ -80,7 +81,7 @@ bool sam_connection(nfc_device_t* pnd, int mode)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!pnd->pdc->transceive(pnd->nds,pncmd_sam_config,szCmd,abtRx,&szRxLen)) {
|
||||
if (!pn53x_transceive(pnd,pncmd_sam_config,szCmd,abtRx,&szRxLen)) {
|
||||
ERR("%s %d", "Unable to execute SAMConfiguration command with mode byte:", mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,19 +78,19 @@ int main(int argc, const char* argv[])
|
||||
|
||||
printf("NFC device [%s] connected.\n",pnd->acName);
|
||||
|
||||
result = pnd->pdc->transceive(pnd->nds,pncmd_diagnose_communication_line_test,sizeof(pncmd_diagnose_communication_line_test),abtRx,&szRxLen);
|
||||
result = pn53x_transceive(pnd,pncmd_diagnose_communication_line_test,sizeof(pncmd_diagnose_communication_line_test),abtRx,&szRxLen);
|
||||
if ( result ) {
|
||||
result = (memcmp(pncmd_diagnose_communication_line_test+2, abtRx, sizeof(pncmd_diagnose_communication_line_test)-2 ) == 0);
|
||||
}
|
||||
printf(" Communication line test: %s\n", result ? "OK" : "Failed");
|
||||
|
||||
result = pnd->pdc->transceive(pnd->nds,pncmd_diagnose_rom_test,sizeof(pncmd_diagnose_rom_test),abtRx,&szRxLen);
|
||||
result = pn53x_transceive(pnd,pncmd_diagnose_rom_test,sizeof(pncmd_diagnose_rom_test),abtRx,&szRxLen);
|
||||
if ( result ) {
|
||||
result = ((szRxLen == 1) && (abtRx[0] == 0x00));
|
||||
}
|
||||
printf(" ROM test: %s\n", result ? "OK" : "Failed");
|
||||
|
||||
result = pnd->pdc->transceive(pnd->nds,pncmd_diagnose_ram_test,sizeof(pncmd_diagnose_ram_test),abtRx,&szRxLen);
|
||||
result = pn53x_transceive(pnd,pncmd_diagnose_ram_test,sizeof(pncmd_diagnose_ram_test),abtRx,&szRxLen);
|
||||
if ( result ) {
|
||||
result = ((szRxLen == 1) && (abtRx[0] == 0x00));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user