Add a small example to diagnose basic elements (communication, rom and ram) of pn53x.

This commit is contained in:
Romuald Conty 2010-05-28 09:09:36 +00:00
parent ac663d02a1
commit 07a779c880
3 changed files with 105 additions and 2 deletions

View file

@ -1,4 +1,4 @@
bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator nfc-poll bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator nfc-poll pn53x-diagnose
# set the include path found by configure # set the include path found by configure
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS) INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)
@ -42,6 +42,10 @@ nfcip_target_LDADD = $(top_builddir)/libnfc/libnfc.la
nfcip_initiator_SOURCES = nfcip-initiator.c nfcip_initiator_SOURCES = nfcip-initiator.c
nfcip_initiator_LDADD = $(top_builddir)/libnfc/libnfc.la nfcip_initiator_LDADD = $(top_builddir)/libnfc/libnfc.la
pn53x_diagnose_SOURCES = pn53x-diagnose.c
pn53x_diagnose_LDADD = $(top_builddir)/libnfc/libnfc.la \
libnfcutils.la
dist_man_MANS = nfc-anticol.1 nfc-emulate.1 nfc-list.1 nfc-mfclassic.1 nfc-mfultralight.1 nfc-relay.1 dist_man_MANS = nfc-anticol.1 nfc-emulate.1 nfc-list.1 nfc-mfclassic.1 nfc-mfultralight.1 nfc-relay.1
EXTRA_DIST = CMakeLists.txt EXTRA_DIST = CMakeLists.txt

View file

@ -19,7 +19,7 @@
/** /**
* @file nfc-list.c * @file nfc-list.c
* @brief * @brief List the first target present of each founded device
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

99
examples/pn53x-diagnose.c Normal file
View file

@ -0,0 +1,99 @@
/*-
* Public platform independent Near Field Communication (NFC) library
*
* Copyright (C) 2010, Romuald Conty
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file pn53x-diagnose.c
* @brief Small application to diagnose PN53x using dedicated commands
*/
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <nfc/nfc.h>
#include <nfc/nfc-messages.h>
#include "nfc-utils.h"
#include "chips/pn53x.h"
#define MAX_DEVICE_COUNT 16
int main(int argc, const char* argv[])
{
size_t szFound;
size_t i;
nfc_device_t* pnd;
nfc_device_desc_t *pnddDevices;
const char* acLibnfcVersion;
bool result;
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
const byte_t pncmd_diagnose_communication_line_test[] = { 0xD4, 0x00, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' };
const byte_t pncmd_diagnose_rom_test[] = { 0xD4, 0x00, 0x01 };
const byte_t pncmd_diagnose_ram_test[] = { 0xD4, 0x00, 0x02 };
if (argc > 1) {
errx (1, "usage: %s", argv[0]);
}
// Display libnfc version
acLibnfcVersion = nfc_version();
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices)))) {
fprintf (stderr, "malloc() failed\n");
return EXIT_FAILURE;
}
nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound);
if (szFound == 0) {
INFO("%s", "No device found.");
}
for (i = 0; i < szFound; i++) {
pnd = nfc_connect(&(pnddDevices[i]));
if (pnd == NULL) {
ERR("%s", "Unable to connect to NFC device.");
return EXIT_FAILURE;
}
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);
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);
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);
if ( result ) {
result = ((szRxLen == 1) && (abtRx[0] == 0x00));
}
printf(" RAM test: %s\n", result ? "OK" : "Failed");
}
}