我不是 NfcV 专家,但以下是我对标签和低级访问的了解
Flag 字节是什么意思? - 未知但http://www.ti.com/lit/an/sloa141/sloa141.pdf 第 4.1 节有 ISO 15693 标志含义的详细信息
但其中一个标志意味着使用寻址或未寻址模式,这会导致 UID
什么是UID 字节 - 大多数标签都有序列号或唯一标识符号
在寻址模式下,您必须提供正在读取或写入的卡的正确 UID 才能成功。这意味着您不会从错误的卡中写入或读取。有一个命令先从卡中读取 UID。
在未寻址模式下,UID 以零形式提供
您已经计算出第二个字节是0x21 用于写入命令。
0x20 用于读取命令
http://www.ti.com/lit/an/sloa141/sloa141.pdf 第 4.2 节有 ISO 15693 命令值的详细信息,如您所见,它们必须是 Optional 或 Custom 和支持以及它们的作用取决于芯片。
您所说的OFFSET 是与第一个块相比的内存块偏移量,或者更好地描述为内存地址(将其想象成书中的页码)。大多数芯片将内存分成设定大小的块。有些芯片使用单个字节作为内存地址,有些芯片使用 2 个字节。
每个块都是固定的字节数,通常是 4 字节,但我看过芯片规格,它是 128 字节。
您在问题中提供的数据结构通常用作您尝试与之通信的芯片的格式良好命令的模板。
您示例中的 DATA 4 个字节只是您要写入的实际数据的占位符,您应该在发送命令之前将您要写入的实际 4 个字节复制到模板中。
因此,当您使用它进行写入时,您必须将OFFSET/Memory Address 调整为“书的右页”并复制正确数量的可以在页面上写入的“字母”进入模板的DATA 部分
https://www.st.com/content/ccc/resource/technical/document/application_note/group0/76/0e/00/a0/1b/04/4c/f2/DM00103491/files/DM00103491.pdf/jcr:content/translations/en.DM00103491.pdf末尾处可以看到来自芯片制造商的一些用于Android的NfcV代码示例
那么最后一个问题Lets go suppose, i have a 4 bytes data myData = "ABCD", and i want to write this data to block 04 of my tag
构造命令示例
// Command Template
byte[] cmd = new byte[] {
(byte)0x20, //FLAG
(byte)0x21, //WRITE SINGLE BLOCK COMMAND
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, //UID
(byte)0x00, //OFFSET
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 //DATA
};
// The data to be written
String myData = "ABCD";
// Get the data as bytes
byte[] data = myData.getBytes();
// Change the "OFFSET" / "Block number" to the the fourth Block
// If that what was meant by "block 04"
// The addresses start at Zero and the byte array starts at zero
// So the "Block Number" is the 11th byte in the command
cmd[10] = (byte)((3) & 0x0ff);
// Copy in 4 bytes of data in to bytes 11 to 15
// Starting at byte 0 in the data array
System.arraycopy(data, 0, cmd, 11, 4);
供参考arraycopy参数https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#arraycopy(java.lang.Object,%20int,%20java.lang.Object,%20int,%20int)是什么