Android 的 Arduino PN532 卡仿真问题

如何解决Android 的 Arduino PN532 卡仿真问题

我想将我的 PN532 用作 NFC 标签,其中包含一些我的 Android 手机应用程序可以读取和保存的附加数据。不幸的是,android 无法识别模拟标签,如您所见。 我使用示例中的 emulate_tag_ndef。 这是我使用的确切示例:

#include "NdefMessage.h"
#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"
PN532_SPI pn532spi(SPI,10);
EmulateTag nfc(pn532spi);
uint8_t ndefBuf[120];
NdefMessage message;
int messageSize;
uint8_t uid[3] = { 0x12,0x34,0x56 };
void setup()
{
  Serial.begin(115200);
  Serial.println("------- Emulate Tag --------");
  message = NdefMessage();
  //message.addUriRecord("http://www.elechouse.com");
  message.addTextRecord("Hi");
  messageSize = message.getEncodedSize();
  if (messageSize > sizeof(ndefBuf)) {
      Serial.println("ndefBuf is too small");
      while (1) { }
  }  
  Serial.print("Ndef encoded message size: ");
  Serial.println(messageSize);
  message.encode(ndefBuf);  
  // comment out this command for no ndef message
  nfc.setNdefFile(ndefBuf,messageSize);  
  // uid must be 3 bytes!
  nfc.setUid(uid);  
  nfc.init();
}

void loop(){
    // uncomment for overriding ndef in case a write to this tag occured
    //nfc.setNdefFile(ndefBuf,messageSize);    
    // start emulation (blocks)
    nfc.emulate();        
    // or start emulation with timeout
    if(!nfc.emulate(1000)){ // timeout 1 second
      Serial.println("timed out");
    }    
    // deny writing to the tag
    // nfc.setTagWriteable(false);    
    if(nfc.writeOccured()){
       Serial.println("\nWrite occured !");
       uint8_t* tag_buf;
       uint16_t length;       
       nfc.getContent(&tag_buf,&length);
       NdefMessage msg = NdefMessage(tag_buf,length);
       msg.print();
    }
    delay(1000);

}

这是我在 emulatetag.cpp 中的数组

      PN532_COMMAND_TGINITASTARGET,0x0,// MODE: 0x04 = PICC only,0x01 = Passive only (0x02 = DEP only)

      // mifare ParaMS
      0x08,0x00,// SENS_RES (seeeds studio set it to 0x04,nxp to 0x08)
      0x00,// NFCID1t    (is set over sketch with setUID())
      0x60,// SEL_RES    (0x20=mifare DelFire,0x60=custom)

      // FELICA ParaMS
      0x01,0xFE,// NFCID2t (8 bytes)
      0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xFF,0xAA,0x99,0x88,//NFCID3t (10 bytes)
      0x77,0x66,0x55,0x44,0x33,0x22,0x11,// length of general bytes
      0x00  // length of historical bytes
  };

这是我使用带有 NFC 工具或 NXP Tag 信息应用程序的 Android 手机读取模拟卡时的串行输出

22:17:42.442 -> Ndef encoded message size: 9
22:17:42.442 -> SAMConfig
22:17:42.442 -> write:  14 01 14 01
22:17:42.475 -> read:   15
22:17:42.475 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:17:54.656 -> read:   8D 05 25 D4 00 6D 76 32 0D D3 9D 4B 72 23 C7 00 00 00 32 46 66 6D 01 01 12 02 02 07 FF 03 02 00 03 04 01 64 07 01 03
22:17:54.656 -> write:  86
22:17:54.689 -> read:   87 29
22:17:54.689 -> status is not ok
22:17:54.689 -> tgGetData Failed!
22:17:54.689 -> write:  52 00
22:17:54.689 -> read:   53 00
22:17:54.689 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:17:55.733 -> tgInitAsTarget timed out!timed out
22:17:56.716 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00`

如果我改变了

PN532_COMMAND_TGINITASTARGET,

PN532_COMMAND_TGINITASTARGET,0x04,

https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf 页中的内容 57 然后我的安卓手机没有反应,什么也没发生

Iphone XR 可搭配使用

PN532_COMMAND_TGINITASTARGET,
22:19:29.307 -> ------- Emulate Tag --------
22:19:29.307 -> Ndef encoded message size: 9
22:19:29.307 -> SAMConfig
22:19:29.307 -> write:  14 01 14 01
22:19:29.307 -> read:   15
22:19:29.307 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:19:35.770 -> read:   8D 08 E0 80
22:19:35.770 -> write:  86
22:19:35.770 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:19:35.804 -> write:  8E 90 00
22:19:35.804 -> read:   8F 00
22:19:35.804 -> write:  86
22:19:35.837 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:19:35.837 -> write:  8E 90 00
22:19:35.837 -> read:   8F 00
22:19:35.837 -> write:  86
22:19:35.871 -> read:   87 00 90 60 00 00 00
22:19:35.871 -> Command not supported! 60
22:19:35.871 -> write:  8E 6A 81
22:19:35.871 -> read:   8F 00
22:19:35.871 -> write:  86
22:19:35.871 -> read:   87 00 00 A4 04 00 10 A0 00 00 03 96 56 43 41 FF FF FF FF FF FF FF FF 00
22:19:35.904 -> function not supported
22:19:35.904 -> write:  8E 6A 81
22:19:35.904 -> read:   8F 00
22:19:35.904 -> write:  86
22:19:35.904 -> read:   87 00 90 60 00 00 00
22:19:35.904 -> Command not supported! 60
22:19:35.904 -> write:  8E 6A 81
22:19:35.938 -> read:   8F 00
22:19:35.938 -> write:  86
22:19:35.938 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 00 00
22:19:35.938 -> function not supported
22:19:35.938 -> write:  8E 6A 81
22:19:35.938 -> read:   8F 00
22:19:35.971 -> write:  86
22:19:35.971 -> read:   87 00 90 60 00 00 00
22:19:35.971 -> Command not supported! 60
22:19:35.971 -> write:  8E 6A 81
22:19:35.971 -> read:   8F 00
22:19:35.971 -> write:  86
22:19:36.005 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:19:36.005 -> write:  8E 90 00
22:19:36.005 -> read:   8F 00
22:19:36.005 -> write:  86
22:19:36.039 -> read:   87 00 00 A4 00 0C 02 E1 03
22:19:36.039 -> write:  8E 90 00
22:19:36.039 -> read:   8F 00
22:19:36.039 -> write:  86
22:19:36.039 -> read:   87 00 00 B0 00 00 0F
22:19:36.073 -> write:  8E 00 0F 20 00 54 00 FF 04 06 E1 04 00 80 00 00 90 00
22:19:36.073 -> read:   8F 00
22:19:36.073 -> write:  86
22:19:36.073 -> read:   87 00 00 A4 00 0C 02 E1 04
22:19:36.073 -> write:  8E 90 00
22:19:36.106 -> read:   8F 00
22:19:36.106 -> write:  86
22:19:36.106 -> read:   87 00 00 B0 00 00 02
22:19:36.106 -> write:  8E 00 09 90 00
22:19:36.106 -> read:   8F 00
22:19:36.106 -> write:  86
22:19:36.139 -> read:   87 00 00 A4 00 0C 02 E1 04
22:19:36.139 -> write:  8E 90 00
22:19:36.139 -> read:   8F 00
22:19:36.139 -> write:  86
22:19:36.139 -> read:   87 00 00 B0 00 00 09
22:19:36.174 -> write:  8E 00 09 D1 01 05 54 02 65 6E 90 00
22:19:36.174 -> read:   8F 00
22:19:36.174 -> write:  86
22:19:36.174 -> read:   87 00 00 B0 00 09 02
22:19:36.174 -> write:  8E 48 69 90 00
22:19:36.207 -> read:   8F 00
22:19:36.207 -> write:  86
22:19:36.241 -> read:   87 13
22:19:36.241 -> status is not ok
22:19:36.241 -> tgGetData Failed!
22:19:36.275 -> write:  52 00
22:19:36.275 -> read:   53 00
22:19:36.275 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:19:37.316 -> tgInitAsTarget timed out!timed out
22:19:38.325 -> write:  8C 00 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00

Iphone XR 也适用于 PN532_COMMAND_TGINITASTARGET, 0x04,https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf 页 57

中的内容
22:27:13.584 -> Ndef encoded message size: 9
22:27:13.584 -> SAMConfig
22:27:13.584 -> write:  14 01 14 01
22:27:13.584 -> read:   15
22:27:13.584 -> write:  8C 04 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:27:24.286 -> read:   8D 08 E0 80
22:27:24.286 -> write:  86
22:27:24.320 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:27:24.320 -> write:  8E 90 00
22:27:24.320 -> read:   8F 00
22:27:24.320 -> write:  86
22:27:24.353 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:27:24.353 -> write:  8E 90 00
22:27:24.353 -> read:   8F 00
22:27:24.353 -> write:  86
22:27:24.353 -> read:   87 00 90 60 00 00 00
22:27:24.353 -> Command not supported! 60
22:27:24.387 -> write:  8E 6A 81
22:27:24.387 -> read:   8F 00
22:27:24.387 -> write:  86
22:27:24.387 -> read:   87 00 00 A4 04 00 10 A0 00 00 03 96 56 43 41 FF FF FF FF FF FF FF FF 00
22:27:24.420 -> function not supported
22:27:24.420 -> write:  8E 6A 81
22:27:24.420 -> read:   8F 00
22:27:24.420 -> write:  86
22:27:24.420 -> read:   87 00 90 60 00 00 00
22:27:24.420 -> Command not supported! 60
22:27:24.420 -> write:  8E 6A 81
22:27:24.454 -> read:   8F 00
22:27:24.454 -> write:  86
22:27:24.454 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 00 00
22:27:24.454 -> function not supported
22:27:24.454 -> write:  8E 6A 81
22:27:24.454 -> read:   8F 00
22:27:24.488 -> write:  86
22:27:24.488 -> read:   87 00 90 60 00 00 00
22:27:24.488 -> Command not supported! 60
22:27:24.488 -> write:  8E 6A 81
22:27:24.488 -> read:   8F 00
22:27:24.488 -> write:  86
22:27:24.522 -> read:   87 00 00 A4 04 00 07 D2 76 00 00 85 01 01 00
22:27:24.522 -> write:  8E 90 00
22:27:24.522 -> read:   8F 00
22:27:24.522 -> write:  86
22:27:24.556 -> read:   87 00 00 A4 00 0C 02 E1 03
22:27:24.556 -> write:  8E 90 00
22:27:24.556 -> read:   8F 00
22:27:24.556 -> write:  86
22:27:24.556 -> read:   87 00 00 B0 00 00 0F
22:27:24.556 -> write:  8E 00 0F 20 00 54 00 FF 04 06 E1 04 00 80 00 00 90 00
22:27:24.589 -> read:   8F 00
22:27:24.589 -> write:  86
22:27:24.589 -> read:   87 00 00 A4 00 0C 02 E1 04
22:27:24.589 -> write:  8E 90 00
22:27:24.623 -> read:   8F 00
22:27:24.623 -> write:  86
22:27:24.623 -> read:   87 00 00 B0 00 00 02
22:27:24.623 -> write:  8E 00 09 90 00
22:27:24.623 -> read:   8F 00
22:27:24.623 -> write:  86
22:27:24.656 -> read:   87 00 00 A4 00 0C 02 E1 04
22:27:24.656 -> write:  8E 90 00
22:27:24.656 -> read:   8F 00
22:27:24.656 -> write:  86
22:27:24.656 -> read:   87 00 00 B0 00 00 09
22:27:24.656 -> write:  8E 00 09 D1 01 05 54 02 65 6E 90 00
22:27:24.690 -> read:   8F 00
22:27:24.690 -> write:  86
22:27:24.690 -> read:   87 00 00 B0 00 09 02
22:27:24.690 -> write:  8E 48 69 90 00
22:27:24.690 -> read:   8F 00
22:27:24.724 -> write:  86
22:27:24.724 -> read:   87 13
22:27:24.724 -> status is not ok
22:27:24.724 -> tgGetData Failed!
22:27:24.724 -> write:  52 00
22:27:24.759 -> read:   53 00
22:27:24.759 -> write:  8C 04 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00
22:27:25.770 -> tgInitAsTarget timed out!timed out
22:27:26.787 -> write:  8C 04 08 00 12 34 56 60 01 FE A2 A3 A4 A5 A6 A7 C0 C1 C2 C3 C4 C5 C6 C7 FF FF AA 99 88 77 66 55 44 33 22 11 00 00

所以我不知道我应该在这个数组里面写什么来让我的 android 读取它的内容。 这是认的:

      PN532_COMMAND_TGINITASTARGET,// NFCID2t (8 bytes) https://github.com/adafruit/Adafruit-PN532/blob/master/Adafruit_PN532.cpp FeliCa NEEDS TO BEGIN WITH 0x01 0xFE!
      0xA2,// length of general bytes
      0x00  // length of historical bytes
  };

如果我使用这个数组,我只能将 PN532 检测为标签

        PN532_COMMAND_TGINITASTARGET,0x05,// MODE: PICC only,Passive only

        0x04,// SENS_RES
        0x0,// NFCID1
        0x20,// SEL_RES

        0,// FeliCaParams
        0,// NFCID3t

        0,// length of general bytes
        0  // length of historical bytes
  };

然后这是我的串行输出

22:50:02.335 -> Ndef encoded message size: 9
22:50:02.335 -> SAMConfig
22:50:02.335 -> write:  14 01 14 01
22:50:02.335 -> read:   15
22:50:02.335 -> write:  8C 05 04 00 12 34 56 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

如你所见,什么都没有发生......

我还用 Android S8 尝试了整个过程,它的行为类似于 Andoird S20。 我希望有人可以帮助我。

非常感谢您提前提供帮助!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?