NFC数据交互格式 NDEF 数据存储格式,存储协议

时间:2024-04-12 21:23:27

 

转自:https://note.youdao.com/ynoteshare1/index.html?id=336e4b1fecbc8f0332957c8da83ac499&type=note

 

数据头(俩字节)+ Record


NFC数据交互格式 NDEF 数据存储格式,存储协议

When we communicate with our NFC reader devices (mobile phones) to read or write data to NFC tag we read basically (for example http://nokia.com) the following hexa code.

当我们使用NFC读卡器设备(手机)来与NFC标签读写数据时,如本例是http://nokia.com,读取到的十六进制码如下

03 0e d1 01 0a 55 03 6e 6f 6b 69 61 2e 63 6f 6d fe 
  • 03 - This is one byte that defines the type of record this is. An NDEF record is represented by the hex byte 03, with Qt mobility API we don’t provide this, those are added for us.
    这个字节定义了记录的类型。Qt移动API自动添加此值。
  • 0e - This is one byte that tells the reader how many bytes are in the payload. With Qt mobility API we don’t provide this, those are added for us by platform.
    这个字节告诉读卡器内容长度。 Qt移动API自动添加此值。
  • d1 - NDEF records are variable length records with a common format illustrated in the figure below.
    NDEF记录有可变长度,但有一个公用格式如下
d1 is binary code (11010001) 

NFC数据交互格式 NDEF 数据存储格式,存储协议

Ndeftnf.png

 

In our case:

  • MB = 1 (message Begin is true means this is first record in the NDEF message)
    MB 是消息开始的标志,MB = 1 表明这是NDEF消息的第1个记录。
  • ME = 1 (Message end, means it is last record in the NDEF message, if it is 0 that tells application that more records are ahead)
    ME 是消息结束的标志,ME = 1 表明这是NDEF消息的最后一个记录,如果 ME = 0,告诉应用程序后面还有更多的记录。
  • CF = 0 (means this is not chunked message, An NDEF message can contain zero or more chunked payloads. Each chunked payload is encoded as an initial record chunk followed by zero or more middle record chunks and finally by a terminating record chunk, in our case we simplify our record as not chunked)
    CF 是分块消息的标志,CF = 0 表明这不是分块消息,一个NDEF消息可以没有分块内容,也可以包含多个分块内容。每块可以被编码为结尾是0的首记录块,或多个中间记录块,最后是一个结束块。在这个例子中,我们不分块。
  • SR = 1 (SR stands for short record, if set, that the payload length field is a single octet.This short record layout is intended for compact encapsulation of small payloads which will fit within PAYLOAD fields of size ranging between 0 to 255 octets.)
    SR 是短记录标志,SR = 1 说明内容长度域是一个八位组。短记录的布局是用来为长度不到255个八位组的内容做精简封装
  • IL = 0(IL stands for identification length, if set, that the ID_LENGTH field is present in the header as a single octet. If the IL flag is zero, the ID_LENGTH field is omitted from the record header and the ID field is also omitted from the record)
    IL 是ID长度,如果 IL = 1,则 ID_LENGTH 域出现在头部,长度为1个八位组。如果 IL = 0,ID_LENGTH 域就从记录头部忽略,ID 域自然也被忽略
  • TNF = 001(The TNF field value indicates the structure of the value of the TYPE field. The value 0x01 (NFC Forum well-known type) indicates that the TYPE field contains a value that follows the RTD type name format defined in the NFC Forum RTD specification)
    TNF 域指示了 TYPE 域值的结构。0x01这个值是NFC论坛已知值,表示 TYPE 域包含一个值在 RTD 类名之后

 

NFC数据交互格式 NDEF 数据存储格式,存储协议

Ndeffullrecod.png

 

  • 01 (Type Length) - The TYPE_LENGTH field is an unsigned 8-bit integer that specifies the length in octets of the TYPE field. The TYPE_LENGTH field is always zero for certain values of the TNF field.
    01 是类型长度,TYPE_LENGTH 域是一个8位无符号整数,表示了 TYPE 域有几个八位组。对 TNF 域的某些值,TYPE_LENGTH 域总是0
  • 0A (Pay load Length) - The PAYLOAD_LENGTH field is an unsigned integer that specifies the length in octets of the PAYLOAD field (the application payload). The size of the PAYLOAD_LENGTH field is determined by the value of the SR flag
    0A 是内容长度,PAYLOAD_LENGTH 域是一个8位无符号整数,表示了 PAYLOAD 域(应用程序的内容)有几个八位组。PAYLOAD_LENGTH 域的大小由 SR 标志决定。
  • 55 (type The value of the TYPE field is an identifier describing the type of the payload, The URI record type (“U”) )
    55 是 TYPE 域是什么类型,55是"U"的ASCII码,表明它是 URI 记录类型
  • 03 - 0x03 URI identifier (“http://”)
    03 是 URI ID,即“http://”
  • Pay Load - The rest of the string in UTF-8 (nokia.com)
    内容“6e 6f 6b 69 61 2e 63 6f 6d”就是“nokia.com”的ASCII码
  • FE Terminator byte. This is final byte added by platform.
    最后的 FE 就是结束码