examples/nfc-dep-*: add signal handler to use the abort mecanism.

This commit is contained in:
Romuald Conty 2011-04-27 15:10:14 +00:00
parent de9255eaea
commit 6974fb4562
2 changed files with 28 additions and 2 deletions

View file

@ -39,6 +39,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <nfc/nfc.h>
@ -46,6 +47,17 @@
#define MAX_FRAME_LEN 264
static nfc_device_t *pnd;
void stop_dep_communication (int sig)
{
(void) sig;
if (pnd)
nfc_abort_command (pnd);
else
exit (EXIT_FAILURE);
}
int
main (int argc, const char *argv[])
{
@ -53,7 +65,6 @@ main (int argc, const char *argv[])
size_t szRx = sizeof(abtRx);
size_t szDeviceFound;
byte_t abtTx[] = "Hello Mars!";
nfc_device_t *pnd;
#define MAX_DEVICE_COUNT 2
nfc_device_desc_t pnddDevices[MAX_DEVICE_COUNT];
nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szDeviceFound);
@ -101,6 +112,8 @@ main (int argc, const char *argv[])
}
printf ("Connected to NFC device: %s\n", pnd->acName);
signal (SIGINT, stop_dep_communication);
printf ("NFC device will now act as: ");
print_nfc_target (nt, false);