NTAG213的启用/禁用计数器 [英] Enable/Disable counter for NTAG213

查看:304
本文介绍了NTAG213的启用/禁用计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    MifareUltralight mifareUltralight = MifareUltralight.get(tag);
    byte[] toggleCounterCommand = new byte[]{(byte)0xA2, // NTAG213 command to write
                                    (byte)0x2A,  // page 42(dec) 2A(hex)    
                                     (byte)___};// not sure what to put here. 

NTAG213的数据表表明,第42页的第0个字节具有访问信息.

The data sheet for NTAG213 says that the 0th byte of page 42 has the access information.

第0个字节的结构如下:

The 0th byte is structured in the following way :

 7       6         5        *4*            3          2  1  0
PROT  CFGLCK   RFUI    *NFC_CNT_EN*  NFC_CNT_PWD_PROT   AUTHLIM

将第4位设置为0或1应该启用或禁用计数器.但是我不确定在写标签时如何设置第4位.

Setting the 4th bit to 0 or 1 should enable or disable the counter. But I'm not sure how to set the 4th bit while writing on the tag.

推荐答案

将来遇到此问题的人员的上下文:

Context for anyone coming to this in the future:

NTAG21x具有NFC计数器功能.此功能使NTAG21x能够 自动增加第一个有效值触发的24位计数器值

NTAG21x features a NFC counter function. This function enables NTAG21x to automatically increase the 24 bit counter value, triggered by the first valid

  • 读取命令或
  • 快速阅读命令

在NTAG21x标签由RF场供电之后. NFC计数器达到FF FF FF hex的最大值后,NFC计数器的值将不再更改.通过NFC_CNT_EN位(请参阅第8.5.7节)启用或禁用NFC计数器. http: //www.nxp.com/documents/data_sheet/NTAG213_215_216.pdf .

after the NTAG21x tag is powered by an RF field. Once the NFC counter has reached the maximum value of FF FF FF hex, the NFC counter value will not change any more. The NFC counter is enabled or disabled with the NFC_CNT_EN bit (see Section 8.5.7) http://www.nxp.com/documents/data_sheet/NTAG213_215_216.pdf.

我的理解是,您在写标签时处在正确的轨道上,您想使用transceive方法来更新该位,但是您不确定要写入什么数据才能实现此目的.请注意,MifraUltralight.transceieve(byte[])等效于通过NfcA连接到该标签并调用transceive(byte[]).

My understanding is that you're on the right track with writing to the tag, you want to use the transceive method to update that bit, but you're not sure what data to write in order to achieve this . Note that MifraUltralight.transceieve(byte[]) is equivalent to connecting to this tag via NfcA and calling transceive(byte[]).

要注意的重要一点是应用程序必须只发送完整字节的命令"(来自

An important thing to note is that "Applications must only send commands that are complete bytes" (from Android docs) so we must update that entire byte. However, we want to write to the tag, which only supports a payload of 4 bytes (1 page) so we will be rewriting the whole page.

这是我的经历开始崩溃的地方,但是我建议一种方法:

This is where my experience starts to break down a little bit, but I would suggest an approach of:

  1. 阅读第42页,将字节复制到缓冲区中
  2. 将那些复制的字节写到第42页,但先更新计数器位

执行步骤1:

NfcA transaction = NfcA.get(tag);
transaction.connect(); // error handle
byte cmdRead = (byte)0x30;
byte page = (byte)(0x42 & 0xff); // AND to make sure it is the correct size
byte[] command = new byte[] {cmdRead, page};
byte[] page42 = nfcAtransaction.transceive(command); // error handle

byte mask = 0b00010000; // 3rd bit, or should it be 4th?
byte newData = page42[0] | mask; 

执行步骤2:

byte cmdWrite = (byte)0xA2;
byte page = (byte)(42 & 0xff);
byte[] command = new byte[] { cmdWrite, page, newData, page42[1], page42[2], page42[3]};
byte[] result = nfcA.transceive(command); 

完全未经测试,但我希望这会有所帮助.

Completely untested, but I hope this helps.

这篇关于NTAG213的启用/禁用计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆