examples/nfc-dep-*: disconnect from NFC device on error.
This commit is contained in:
parent
412c326c3a
commit
72422e819b
2 changed files with 8 additions and 5 deletions
|
@ -88,20 +88,22 @@ main (int argc, const char *argv[])
|
|||
|
||||
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt)) {
|
||||
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
||||
return EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
print_nfc_target (nt, false);
|
||||
|
||||
printf ("Sending: %s\n", abtTx);
|
||||
if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) {
|
||||
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
|
||||
return EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
|
||||
abtRx[szRx] = 0;
|
||||
printf ("Received: %s\n", abtRx);
|
||||
|
||||
nfc_initiator_deselect_target (pnd);
|
||||
|
||||
error:
|
||||
nfc_disconnect (pnd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -120,13 +120,13 @@ main (int argc, const char *argv[])
|
|||
printf ("Waiting for initiator request...\n");
|
||||
if(!nfc_target_init (pnd, &nt, abtRx, &szRx)) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
return EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
|
||||
printf("Initiator request received. Waiting for data...\n");
|
||||
if (!nfc_target_receive_bytes (pnd, abtRx, &szRx)) {
|
||||
nfc_perror(pnd, "nfc_target_receive_bytes");
|
||||
return EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
abtRx[szRx] = '\0';
|
||||
printf ("Received: %s\n", abtRx);
|
||||
|
@ -134,10 +134,11 @@ main (int argc, const char *argv[])
|
|||
printf ("Sending: %s\n", abtTx);
|
||||
if (!nfc_target_send_bytes (pnd, abtTx, sizeof(abtTx))) {
|
||||
nfc_perror(pnd, "nfc_target_send_bytes");
|
||||
return EXIT_FAILURE;
|
||||
goto error;
|
||||
}
|
||||
printf("Data sent.\n");
|
||||
|
||||
error:
|
||||
nfc_disconnect (pnd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue