Android RPi上的PN532和Nexus电话之间的点对点

Android RPi上的PN532和Nexus电话之间的点对点,android,raspberry-pi,nfc,nfc-p2p,Android,Raspberry Pi,Nfc,Nfc P2p,我试图在Nexus3手机和带有adafruit NFC breakboard(PN532芯片)的覆盆子Pi之间创建一个简单的消息交换。 我已经编译了最新的libnfc1.71库,并运行了以下示例: pi@raspberrypi ~/libnfc1.7/libnfc-1.7.1/examples $ ./nfc-dep-initiator NFC device: pn532_uart:/dev/ttyAMA0 openedD.E.P. (212 kbpspassive mode) target:

我试图在Nexus3手机和带有adafruit NFC breakboard(PN532芯片)的覆盆子Pi之间创建一个简单的消息交换。 我已经编译了最新的libnfc1.71库,并运行了以下示例:

pi@raspberrypi ~/libnfc1.7/libnfc-1.7.1/examples $ ./nfc-dep-initiator
NFC device: pn532_uart:/dev/ttyAMA0
 openedD.E.P. (212 kbpspassive mode) target:
       NFCID3: 01  fe  ec  d8  f7  03  c5  2d  00  00
           BS: 00
           BR: 00
           TO: 08
           PP: 32
General Bytes: 46  66  6d  01  01  11  03  02  00  13  04  01  96
Sending: Hello World!
nfc_initiator_transceive_bytes: RF Transmission Error
当我将手机从NFC板上卸下时会抛出错误,否则它什么也不做

pi@raspberrypi ~/libnfc1.7/libnfc-1.7.1/examples $ ./nfc-dep-target
NFC device: pn532_uart:/dev/ttyAMA0 opened
NFC device will now act as: D.E.P. (undefined baud ratepassive mode) target:
       NFCID3: 12  34  56  78  9a  bc  de  ff  00  00
           BS: 00
           BR: 00
           TO: 00
           PP: 01
General Bytes: 12  34  56  78
Waiting for initiator request...
Initiator request received. Waiting for data...

nfc_target_receive_bytes: Target Released
来自android设备的代码:

MainActivity extends ActionBarActivity   implements NfcAdapter.CreateNdefMessageCallback, NfcAdapter.OnNdefPushCompleteCallback{
    private NfcAdapter mNfcAdapter = null;
    @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;
        }


        mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback()
        {
            @Override
            public NdefMessage createNdefMessage(NfcEvent event)
            {
                String text = ("Beam me up, Android!\n\n" +
                        "Beam Time: " + System.currentTimeMillis());
                NdefMessage msg = new NdefMessage(
                        new NdefRecord[] { createMime(
                                "application/vnd.com.example.android.beam", text.getBytes())
                        });
                return msg;
            }

        }, this, this);


      //  mNfcAdapter.setNdefPushMessageCallback(this, this);
        mNfcAdapter.setOnNdefPushCompleteCallback(this,this);
    }



@Override
public void onResume() {
    super.onResume();

    // Check to see that the Activity started due to an Android Beam
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        processIntent(getIntent());
    }
}

@Override
public void onNewIntent(Intent intent) {
    // onResume gets called after this to handle the intent
    setIntent(intent);
}

/**
 * Parses the NDEF Message from the intent and prints to the TextView
 */
void processIntent(Intent intent) {
    EditText textView = (EditText) findViewById(R.id.editText);
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
            NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message sent during the beam
    NdefMessage msg = (NdefMessage) rawMsgs[0];
    // record 0 contains the MIME type, record 1 is the AAR, if present
    textView.setText(new String(msg.getRecords()[0].getPayload()));
}

public void CloseApp(View view) {
    this.finish();
}

@Override
public void onNdefPushComplete(NfcEvent nfcEvent) {
    EditText editText = (EditText) findViewById(R.id.editText);
    editText.setText("onNdefPushComplete");
}

processIntent
永远不会被调用,无论是
onNdefPushComplete
还是
createNdefMessage
您使用的对等示例都是在NFCIP-1(NFC-DEP)层传输数据。Android设备仅支持通过SNEP/NPP交换NDEF消息,因此您需要实现NFC-DEP和SNEP之间缺少的层,以便与运行的Android设备进行P2P通信。图层如下所示(您可以从以下位置获取所有规格:

因此,您必须添加LLCP、SNEP和NDEF层

+------------------------------------------------+
|        NFC Data Exchange Format (NDEF)         |
+------------------------------------------------+
|     Simple NDEF Exchange Protocol (SNEP)       |
+------------------------------------------------+
|    NFC Logical Link Control Protocol (LLCP)    |
+------------------------------------------------+
|  NFC Data Exchange Protocol (NFC-DEP/NFCIP-1)  |
+------------------------------------------------+