pn53x_initiator_poll_target() function returns now polled targets count on success.
This commit is contained in:
parent
340e80d7a8
commit
b864215d63
4 changed files with 15 additions and 16 deletions
|
@ -109,7 +109,7 @@ main (int argc, const char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
if (res > 0) {
|
||||
print_nfc_target ( nt, verbose );
|
||||
} else {
|
||||
printf ("No target found.\n");
|
||||
|
|
|
@ -1037,18 +1037,17 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
|||
}
|
||||
szTargetTypes++;
|
||||
}
|
||||
size_t szTargetFound = 0;
|
||||
nfc_target ntTargets[2];
|
||||
if ((res = pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0)) < 0)
|
||||
if ((res = pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, 0)) < 0)
|
||||
return res;
|
||||
switch (szTargetFound) {
|
||||
switch (res) {
|
||||
case 1:
|
||||
*pnt = ntTargets[0];
|
||||
return NFC_SUCCESS;
|
||||
return res;
|
||||
break;
|
||||
case 2:
|
||||
*pnt = ntTargets[1]; // We keep the selected one
|
||||
return NFC_SUCCESS;
|
||||
return res;
|
||||
break;
|
||||
default:
|
||||
return NFC_ECHIP;
|
||||
|
@ -1065,11 +1064,12 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
|||
prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData);
|
||||
const int timeout_ms = uiPeriod * 150;
|
||||
|
||||
if (pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms) < 0) {
|
||||
if (pnd->last_error != NFC_ETIMEOUT)
|
||||
if ((res = pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms)) < 0) {
|
||||
if (pnd->last_error != NFC_ETIMEOUT) {
|
||||
return pnd->last_error;
|
||||
}
|
||||
} else {
|
||||
return NFC_SUCCESS;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2182,9 +2182,9 @@ pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target)
|
|||
int
|
||||
pn53x_InAutoPoll (struct nfc_device *pnd,
|
||||
const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, size_t *pszTargetFound,
|
||||
const int timeout)
|
||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target * pntTargets, const int timeout)
|
||||
{
|
||||
size_t szTargetFound = 0;
|
||||
if (CHIP_DATA(pnd)->type != PN532) {
|
||||
// This function is not supported by pn531 neither pn533
|
||||
pnd->last_error = NFC_EDEVNOTSUPP;
|
||||
|
@ -2205,8 +2205,8 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
|
|||
if (res < 0) {
|
||||
return res;
|
||||
} else if (szRx > 0) {
|
||||
*pszTargetFound = abtRx[0];
|
||||
if (*pszTargetFound) {
|
||||
szTargetFound = abtRx[0];
|
||||
if (szTargetFound > 0) {
|
||||
uint8_t ln;
|
||||
uint8_t *pbt = abtRx + 1;
|
||||
/* 1st target */
|
||||
|
@ -2229,7 +2229,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
|
|||
}
|
||||
}
|
||||
}
|
||||
return NFC_SUCCESS;
|
||||
return szTargetFound;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -333,7 +333,6 @@ int pn53x_InDeselect (struct nfc_device *pnd, const uint8_t ui8Target);
|
|||
int pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target);
|
||||
int pn53x_InAutoPoll (struct nfc_device *pnd, const pn53x_target_type *ppttTargetTypes, const size_t szTargetTypes,
|
||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
||||
size_t *pszTargetFound,
|
||||
const int timeout);
|
||||
int pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||
|
|
|
@ -410,7 +410,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
|
||||
/**
|
||||
* @brief Polling for NFC targets
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value).
|
||||
* @return Returns polled targets count, otherwise returns libnfc's error code (negative value).
|
||||
*
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param ppttTargetTypes array of desired target types
|
||||
|
|
Loading…
Add table
Reference in a new issue