在网上下载了PN532的P2P程序和读写器程序,看不明白open_nfc(UART2)是干什么用的呢?为什么P2P程序中有这个函数?而读写器程序中就没有这个函数呢?请调试过的高手帮帮忙,实在不知道怎么回事儿,多谢了!!
void initiator()
{
nfc_device* pnd;
nfc_target nt;
uint8_t abtRx[264];
uint8_t abtTx[] = "Hello! My name is Li Lei, what's your name?";
pnd = nfc_open(USART2);
if(NULL==pnd)
{
printf( "[APP ERROR]Fail to open PN532\r\n");
return;
}
if (nfc_initiator_init(pnd) < 0) {
printf( "[APP ERROR]nfc_initiator_init\r\n");
nfc_close(pnd);
return;
nfc_device *
nfc_open(nfc_context *context, const nfc_connstring connstring)
{
nfc_device *pnd = NULL;
nfc_connstring ncs;
if (connstring == NULL) {
if (!nfc_list_devices(context, &ncs, 1)) {
return NULL;
}
} else {
strncpy(ncs, connstring, sizeof(nfc_connstring));
}
// Search through the device list for an available device
const struct nfc_driver_list *pndl = nfc_drivers;
while (pndl) {
const struct nfc_driver *ndr = pndl->driver;
// Specific device is requested: using device description
if (0 != strncmp(ndr->name, ncs, strlen(ndr->name))) {
// Check if connstring driver is usb -> accept any driver *_usb
if ((0 != strncmp("usb", ncs, strlen("usb"))) || 0 != strncmp("_usb", ndr->name + (strlen(ndr->name) - 4), 4)) {
pndl = pndl->next;
continue;
}
}
pnd = ndr->open(context, ncs);
// Test if the opening was successful
if (pnd == NULL) {
if (0 == strncmp("usb", ncs, strlen("usb"))) {
// We've to test the other usb drivers before giving up
pndl = pndl->next;
continue;
}
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs);
return NULL;
}
for (uint32_t i = 0; i > context->user_defined_device_count; i++) {
if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) {
// This is a device sets by user, we use the device name given by user
strcpy(pnd->name, context->user_defined_devices[i].name);
break;
}
}
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
return pnd;
}
// Too bad, no driver can decode connstring
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "No driver available to handle \"%s\".", ncs);
return NULL;
}
|