打印
[STM32F1]

NFC P2P程序的问题

[复制链接]
1437|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zzz3535|  楼主 | 2015-11-26 14:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
p2p, NFC, ST, pnd, ce
在网上下载了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;
}


沙发
zzz3535|  楼主 | 2015-11-27 11:13 | 只看该作者
自己顶一下

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

62

主题

151

帖子

2

粉丝