我目前正在计划一个项目,需要从Nexus 4智能手机到PN532 NFC芯片通过NFC进行通信。我以前通过使用InListPassiveTarget读取了Mifare经典1k卡的内容。下一步是读取一个编程的RFID标签,我唯一能读到的内容是UID,ATQA和SAK。我无法读取我在标签上编程的数据,这些数据必须存储在更深的地方。
如何读取我编写的数据,我必须使用哪个命令?,我使用InListPassiveTarged命令接收UID、ATQA和SAK。
我现在的第二个问题是:我是否有可能编写一个将我的数据传输到PN532的安卓应用程序?如果是的话,我如何才能做到这一点?
首先,数据从Nexus 4发送到PN532是至关重要的。我使用的安卓应用程序是一个稍微修改过的AndroidBeamDemo版本(代码在上面)。我还阅读了这个应用程序提供的NDEF消息,并在从Google商店下载的另一部手机上安装了NDEF应用程序。我从这个教程中重新创建了这个场景。这里描述(4a),在初始化之后,正在使用InJumpForDEP命令。这是我陷入困境的时刻。我用正常模式初始化了PN532 (SAM,0xD40x140x01)。以前的测试表明,读取Mifare卡的UID (使用InListPassiveTarget命令)是没有问题的。从RFID标签中读出UID也是可能的。在执行来自turial (4a)的命令时,应用程序显示了“Tap”屏幕,并调用了createNdefMessage函数,但是onNdefPushComplete函数从未被调用,相反,LogCat显示了上面概述的输出。我希望我现在的情况更清楚了,谢谢你的帮助。
关于我的第二个问题,我现在几乎成功地在我的PN532突破板和我的Nexus 4之间建立了通信。在PN532初始化之后,我使用了InJumpForDEP命令。在那之后,我没有得到来自PN532的响应,并且有一些日志是用Logcat跟踪的。我希望你能帮我解决跟踪日志,并告诉我如何处理错误。
我在InJumpForDEP命令中发送的数据:
0xD4,0x56,0x01,0x02,0x04,0x46,0x66,0x6D,0x01,0x01,0x10,0x03,0x02,0x00,0x01,0x04,0x01,0x96
LogCat:
02-22 17:19:08.418: D/NfceeAccess(834): Granted NFCEE access to com.google.android.apps.walletnfcrel (wildcard)
02-22 17:19:08.648: D/NfcService(834): LLCP Activation message
02-22 17:19:08.648: I/NfcP2pLinkManager(834): LLCP activated
02-22 17:19:08.648: D/NfcP2pLinkManager(834): onP2pInRange()
02-22 17:19:08.648: D/audio_hw_primary(176): select_devices: out_snd_device(2: speaker) in_snd_device(0: )
02-22 17:19:08.648: D/ACDB-LOADER(176): ACDB -> send_afe_cal
02-22 17:19:08.668: I/NFC(5006): Create android.nfc.NfcEvent@42025c60
02-22 17:19:08.668: D/NfcP2pLinkManager(834): onP2pSendConfirmationRequested()
02-22 17:19:08.728: D/dalvikvm(834): GC_FOR_ALLOC freed 4322K, 27% free 12775K/17320K, paused 22ms, total 22ms
02-22 17:19:08.748: I/dalvikvm-heap(834): Grow heap (frag case) to 15.822MB for 3483664-byte allocation
02-22 17:19:08.758: D/dalvikvm(834): GC_CONCURRENT freed 11K, 22% free 16166K/20724K, paused 3ms+2ms, total 17ms
02-22 17:19:08.758: D/dalvikvm(834): WAIT_FOR_CONCURRENT_GC blocked 7ms
02-22 17:19:08.768: D/PhoneStatusBar(683): disable: < EXPAND* icons alerts ticker system_info back home recent clock search >
02-22 17:19:08.798: W/InputMethodManagerService(599): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4254ddf8 (uid=10128 pid=5006)
02-22 17:19:09.449: D/NfcP2pLinkManager(834): onP2pSendConfirmed()
02-22 17:19:09.639: E/BrcmNfcNfa(834): nfa_p2p_proc_llcp_disconnect_ind (): Link deactivated
02-22 17:19:09.639: E/BrcmNfcJni(834): PeerToPeer::disconnectConnOriented: can't find connection handle: 22
02-22 17:19:09.639: D/NdefPushClient(834): about to create socket
02-22 17:19:09.639: D/NdefPushClient(834): about to connect to service com.android.npp
02-22 17:19:09.649: D/NfcService(834): LLCP Link Deactivated message. Restart polling loop.
02-22 17:19:09.649: I/NfcP2pLinkManager(834): LLCP deactivated.
02-22 17:19:09.649: E/NfcP2pLinkManager(834): onP2pSendDebounce()
02-22 17:19:09.649: E/BrcmNfcNfa(834): NFA_P2pConnectByName (): MIU(128) must be between 128 and 2175 or LLCP link is not activated
02-22 17:19:09.649: E/BrcmNfcJni(834): PeerToPeer::createDataLinkConn: fail; error=0x3
02-22 17:19:09.649: E/BrcmNfcJni(834): PeerToPeer::disconnectConnOriented: can't find connection handle: 23
02-22 17:19:14.655: D/NfcP2pLinkManager(834): Debounce timeout
02-22 17:19:14.655: D/NfcP2pLinkManager(834): onP2pOutOfRange()Android应用程序的源代码:
package com.example.nfc_demo_ndef;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcAdapter.OnNdefPushCompleteCallback;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback
{
private NfcAdapter mNfcAdapter;
private static final int MESSAGE_SENT = 1;
/** This handler receives a message from onNdefPushComplete */
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_SENT:
Toast.makeText(getApplicationContext(), "Message sent!", Toast.LENGTH_LONG).show();
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null)
{
Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
// Register callback
mNfcAdapter.setNdefPushMessageCallback(this, this);
mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public NdefMessage createNdefMessage(NfcEvent event)
{
String text = ("aaaaaaaa");
NdefMessage msg = new NdefMessage(
new NdefRecord[] { NdefRecord.createMime(
"text/plain", text.getBytes())
/**
* The Android Application Record (AAR) is commented out. When a device
* receives a push with an AAR in it, the application specified in the AAR
* is guaranteed to run. The AAR overrides the tag dispatch system.
* You can add it back in to guarantee that this
* activity starts when receiving a beamed message. For now, this code
* uses the tag dispatch system.
*/
//,NdefRecord.createApplicationRecord("com.example.android.beam")
});
Log.i("NFC", "Create " + event.toString());
return msg;
}
@Override
public void onNdefPushComplete(NfcEvent event)
{
mHandler.obtainMessage(MESSAGE_SENT).sendToTarget();
Log.i("NFC", "Complete " + event.toString());
}
}发布于 2014-02-21 07:14:00
First应答:您需要使用InListPassiveTarget来获取MIFARE标记的UID。在此之后,您必须使用InDataExchange命令(使用身份验证过程)访问标记中的安全数据。
第二个答案是:是的,这绝对是可能的。我建议使用带有NFC屏蔽的阿迪诺板。然后,您可以使用P2P通信,使用NFC,也可以尝试在被动卡模拟模式下配置PN532,这样Nexus就可以看到一个普通的RFID标签。NFC屏蔽提供的代码很适合第一次使用。
在评估问题之前,有一些事情需要事先知道:
InJumpForDEP命令是唯一用于数据交换的命令(当然是在配置之后)吗?通常,实现从PN532到Nexus的推送(例如,URL)比较容易。如果PN532配置正确,则Android应该跳入前台。所以你可以先检查你的PN532是否正确,然后再继续你自己的应用程序。
发布于 2014-02-24 21:15:04
好的,这是我收到的InJumpForDEP的回应
0xD5 0x57 0x00 0x01 0x01 0xFE 0x95 0xCA 0x46 0x61 0xC5 0x38 0x00 0x00 0x00 0x00 0x00 0x07 0x32 0x46 0x66 0x6D 0x01 0x01 0x55 0x00 0x00 0x00 0x00 0xFF 0x03 0xFD 0xD4 0x14 0x01 0x17 0x00 0x00 0xFF 0xEE 0xD4 0x56 0x01 0x02 0x04 0x46 0x66 0x6D 0x01 0x01 0x10 0x03 0x02 0x00 0x01 0x04 0x01 0x96 0x03如您所见,最后一个字节0x46 0x66 0x6D 0x01 0x01 0x10 0x03 0x02 0x00 0x01 0x04 0x01 0x96是正确的,因为它们是用作参数的一般字节。但对于其他人来说,这是一个巨大的差异。
0x95 0xCA 0x46 0x61 0xC5 0x38部分不时发生变化。
https://stackoverflow.com/questions/21862784
复制相似问题