Re-ident examples/nfc-poll.c using "indent -br -ce --line-length120 -nut -i2 -ppi 2 " command line.

This commit is contained in:
Romuald Conty 2010-06-07 09:51:31 +00:00
parent 3c1a61349f
commit d171562002

View file

@ -23,7 +23,7 @@
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" # include "config.h"
#endif // HAVE_CONFIG_H #endif // HAVE_CONFIG_H
#include <err.h> #include <err.h>
@ -39,62 +39,59 @@
#define MAX_DEVICE_COUNT 16 #define MAX_DEVICE_COUNT 16
static nfc_device_t* pnd; static nfc_device_t *pnd;
int main(int argc, const char* argv[]) int
main (int argc, const char *argv[])
{ {
size_t szFound; size_t szFound;
size_t i; size_t i;
nfc_device_desc_t *pnddDevices; nfc_device_desc_t *pnddDevices;
// Display libnfc version // Display libnfc version
const char* acLibnfcVersion = nfc_version(); const char *acLibnfcVersion = nfc_version ();
if (argc > 1) { if (argc > 1) {
errx (1, "usage: %s", argv[0]); errx (1, "usage: %s", argv[0]);
} }
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion); printf ("%s use libnfc %s\n", argv[0], acLibnfcVersion);
if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices)))) if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices)))) {
{
fprintf (stderr, "malloc() failed\n"); fprintf (stderr, "malloc() failed\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound); nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound);
if (szFound == 0) if (szFound == 0) {
{ INFO ("%s", "No device found.");
INFO("%s", "No device found.");
} }
for (i = 0; i < szFound; i++) for (i = 0; i < szFound; i++) {
{ pnd = nfc_connect (&(pnddDevices[i]));
pnd = nfc_connect(&(pnddDevices[i]));
if (pnd == NULL) if (pnd == NULL) {
{ ERR ("%s", "Unable to connect to NFC device.");
ERR("%s", "Unable to connect to NFC device.");
return 1; return 1;
} }
nfc_initiator_init(pnd); nfc_initiator_init (pnd);
// Drop the field for a while // Drop the field for a while
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false); nfc_configure (pnd, NDO_ACTIVATE_FIELD, false);
// Let the reader only try once to find a tag // Let the reader only try once to find a tag
nfc_configure(pnd,NDO_INFINITE_SELECT,false); nfc_configure (pnd, NDO_INFINITE_SELECT, false);
// Configure the CRC and Parity settings // Configure the CRC and Parity settings
nfc_configure(pnd,NDO_HANDLE_CRC,true); nfc_configure (pnd, NDO_HANDLE_CRC, true);
nfc_configure(pnd,NDO_HANDLE_PARITY,true); nfc_configure (pnd, NDO_HANDLE_PARITY, true);
// Enable field so more power consuming cards can power themselves up // Enable field so more power consuming cards can power themselves up
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true); nfc_configure (pnd, NDO_ACTIVATE_FIELD, true);
printf("Connected to NFC reader: %s\n",pnd->acName); 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) // 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 pn53x_transceive(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
@ -110,27 +107,27 @@ int main(int argc, const char* argv[])
nfc_target_t antTargets[2]; nfc_target_t antTargets[2];
size_t szTargetFound; size_t szTargetFound;
if(pnd->nc == NC_PN531) { if (pnd->nc == NC_PN531) {
// PN531 doesn't support hardware polling (InAutoPoll) // PN531 doesn't support hardware polling (InAutoPoll)
WARN("%s", "PN531 doesn't support hardware polling."); WARN ("%s", "PN531 doesn't support hardware polling.");
continue; continue;
} }
printf("PN53x will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150); printf ("PN53x will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150);
bool res = nfc_initiator_poll_targets(pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound); bool res = nfc_initiator_poll_targets (pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
if( res ) { if (res) {
printf("%ld target(s) have been found.\n", (unsigned long) szTargetFound); printf ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
for(uint8_t n=0; n<szTargetFound; n++) { for (uint8_t n = 0; n < szTargetFound; n++) {
printf("T%d: targetType=%02x, ", n+1, antTargets[n].ntt); printf ("T%d: targetType=%02x, ", n + 1, antTargets[n].ntt);
printf("targetData:\n"); print_nfc_iso14443a_info(antTargets[n].nti.nai); printf ("targetData:\n");
print_nfc_iso14443a_info (antTargets[n].nti.nai);
} }
} else { } else {
ERR("%s", "Polling failed."); ERR ("%s", "Polling failed.");
} }
nfc_disconnect(pnd); nfc_disconnect (pnd);
} }
free (pnddDevices); free (pnddDevices);
return 0; return 0;
} }