Android nfcA.connect (), nfcA.transceive (), nfcA.setTimeout () and nfcA.getMaxTransceiveLength ()

I have a few NfcA questions for beginners. There seems to be no indication of this in the docs and elsewhere on the Internet, so I hope no one objects that I put a few basic questions together here ...

I use nfcA.transceive () to write data to the NTAG213 tag as follows:

    byte[] result = nfcA.transceive(new byte[] {
            (byte)0xA2,  // WRITE
            (byte)(pageNum & 0x0ff),
            myData[0], myData[1], myData[2], myData[3]
    });

1. An array resultis one byte of value 10. What does this mean and what other values ​​should I look for?

I also use the same method to read data from NTAG213 tags:

    byte[] result = nfcA.transceive(new byte[] {
            (byte)0x30,  // READ
            (byte)(pageNum & 0x0ff)
    });

2. I expected this to return 4 bytes of user data (ie 4 bytes that match my pageNum), but it returned 16 bytes. Why is this so?

3. nfcA.isConnected() nfcA.connect(), , , - ? ( , .)

4. nfcA.setTimeout() nfcA.connect()?

5. NTAG213 nfcA.getMaxTransceiveLength() 253. , 251 ( 2 ) , , (4 ) nfcA.transceive()?

+4
1

1. WRITE 10. ?

10 (Ah 1010b ) ACK, , , , .

, ACK, ACK NACK. NFC Forum NFC Forum Type 2.

  • , , ACK.
  • ACK 4- ( . NFC Forum ISO/IEC 14443-3) 1010b (Ah).
  • ACK , .
  • NACK 4- 0x0xb ( x 0 1).

NTAG213/215/216 NACK:

  • 0000b (0h) .
  • 0001b (1h) CRC.
  • 0100b (4h) .
  • 0101b (5h) EEPROM.

, NFC NACK . TagLostException, null. , (?) TagLostException, ACK.

, ( , , , ACK):

try {
   response = nfca.transceive(command);
   if (response == null) {
       // either communication to the tag was lost or a NACK was received
   } else if ((response.length == 1) && ((response[0] & 0x00A) != 0x00A)) {
       // NACK response according to Digital Protocol/T2TOP
   } else {
       // success: response contains ACK or actual data
   }
} catch (TagLostException e) {
   // either communication to the tag was lost or a NACK was received
}

2. , READ 4 (.. 4 , pageNum), 16 . ?

READ 4 , ( NFC Forum Type 2 Tag Operation). , READ 4, 4, 5, 6 7.

3. nfcA.isConnected() nfcA.connect(), , , - ?

Tag NFC ( NFC), . , Tag nfcA.connect(), , nfcA.isConnected() . , , isConnected() API- NFC. , , if - NfcA.

4. nfcA.setTimeout() nfcA.connect()?

. , - reset .

5. NTAG213 nfcA.getMaxTransceiveLength() 253. , 251 ( ) , , (4 ) nfcA.transceive()?

, . WRITE NTAG213, .

253 FAST_READ ( 62, 45 NTAG213) :

int firstBlockNum = 0;
int lastBlockNum = 42;
byte[] result = nfcA.transceive(new byte[] {
        (byte)0x3A,  // FAST_READ
        (byte)(firstBlockNum & 0x0ff),
        (byte)(lastBlockNum & 0x0ff),
});
+6

Source: https://habr.com/ru/post/1659087/


All Articles