Add new example to show how to use new polling function.
This commit is contained in:
parent
40f230d6f0
commit
2714180227
2 changed files with 130 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator
|
bin_PROGRAMS = nfc-anticol nfc-list nfc-mfclassic nfc-mfultralight nfc-relay nfc-emulate nfcip-target nfcip-initiator nfc-poll
|
||||||
|
|
||||||
# set the include path found by configure
|
# set the include path found by configure
|
||||||
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)
|
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)
|
||||||
|
|
@ -8,6 +8,9 @@ nfcincludedir = $(includedir)/nfc
|
||||||
|
|
||||||
AM_CFLAGS = -I$(top_srcdir)/libnfc
|
AM_CFLAGS = -I$(top_srcdir)/libnfc
|
||||||
|
|
||||||
|
nfc_poll_SOURCES = nfc-poll.c
|
||||||
|
nfc_poll_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||||
|
|
||||||
nfc_anticol_SOURCES = nfc-anticol.c
|
nfc_anticol_SOURCES = nfc-anticol.c
|
||||||
nfc_anticol_LDADD = $(top_builddir)/libnfc/libnfc.la
|
nfc_anticol_LDADD = $(top_builddir)/libnfc/libnfc.la
|
||||||
|
|
||||||
|
|
|
||||||
126
examples/nfc-poll.c
Normal file
126
examples/nfc-poll.c
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
/*-
|
||||||
|
* 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 nfc-poll
|
||||||
|
* @brief Polling example
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <nfc/nfc.h>
|
||||||
|
#include <nfc/nfc-types.h>
|
||||||
|
#include <nfc/nfc-messages.h>
|
||||||
|
#include "bitutils.h"
|
||||||
|
|
||||||
|
#define MAX_DEVICE_COUNT 16
|
||||||
|
|
||||||
|
static nfc_device_t* pnd;
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[])
|
||||||
|
{
|
||||||
|
size_t szFound;
|
||||||
|
size_t i;
|
||||||
|
nfc_target_info_t nti;
|
||||||
|
nfc_device_desc_t *pnddDevices;
|
||||||
|
|
||||||
|
// Display libnfc version
|
||||||
|
const char* 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 1;
|
||||||
|
}
|
||||||
|
nfc_initiator_init(pnd);
|
||||||
|
|
||||||
|
// Drop the field for a while
|
||||||
|
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
||||||
|
|
||||||
|
// Let the reader only try once to find a tag
|
||||||
|
nfc_configure(pnd,NDO_INFINITE_SELECT,false);
|
||||||
|
|
||||||
|
// Configure the CRC and Parity settings
|
||||||
|
nfc_configure(pnd,NDO_HANDLE_CRC,true);
|
||||||
|
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
|
||||||
|
|
||||||
|
// Enable field so more power consuming cards can power themselves up
|
||||||
|
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
|
||||||
|
|
||||||
|
printf("Connected to NFC reader: %s\n",pnd->acName);
|
||||||
|
|
||||||
|
// NOTE we can't use pn53x_transceive() because rx[0] is not status byte (0x00 != status OK)
|
||||||
|
// bool pn53x_transceive(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||||
|
// bool res = pn53x_transceive(pnd, abtTx, szTxLen, abtRx, &szRxLen);
|
||||||
|
|
||||||
|
// bool (*transceive)(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||||
|
|
||||||
|
const byte_t btPollNr = 0x0a;
|
||||||
|
const byte_t btPeriod = 0x01;
|
||||||
|
const nfc_target_type_t nttMifare = NTT_MIFARE;
|
||||||
|
const size_t szTargetTypes = 1;
|
||||||
|
|
||||||
|
nfc_target_t antTargets[2];
|
||||||
|
size_t szTargetFound;
|
||||||
|
|
||||||
|
printf("PN53x will poll during %d ms\n", btPollNr * szTargetTypes * btPeriod * 150);
|
||||||
|
bool res = nfc_initiator_poll_targets(pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
|
||||||
|
if( res ) {
|
||||||
|
printf("%d target(s) have been found.\n", szTargetFound);
|
||||||
|
for(uint8_t n=0; n<szTargetFound; n++) {
|
||||||
|
printf("T%d: targetType=%02x, ", n+1, antTargets[n].ntt);
|
||||||
|
printf("targetData:\n"); print_nfc_iso14443a_info(antTargets[n].nti.nai);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ERR("%s", "Polling failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_disconnect(pnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
free (pnddDevices);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue