nRF5 SDK v17.1.0
Message and record parser

If you use the nRF5 SDK to implement an NFC polling device, you can use the NDEF message parser module to interpret the NDEF messages that are read from the NFC tag. See the documentation for the Type 2 Tag parser for information about how to read the content of the tag.

The NDEF message parser resolves NDEF messages to message descriptors (see nfc_ndef_msg_desc_t). The main module NDEF message parser provides functionality for parsing NDEF messages and printing out their content. It uses the Parser for NDEF records, which provides functionality for parsing NDEF records to record descriptors (see nfc_ndef_record_desc_t). The Parser for NDEF records can also be used to print out record contents.

When parsing a message, you must provide memory for the message descriptor instance, which holds pointers to the record descriptors. The record descriptors, in turn, point to the locations of the record fields, which are located in the NFC data that was parsed. These fields are not copied.

To calculate the buffer size that is required, use NFC_NDEF_PARSER_REQIRED_MEMO_SIZE_CALC. After parsing is completed successfully, the first address in the buffer is filled by the NDEF message descriptor, which provides a full description of the parsed NDEF message.

The following code example shows how to parse an NDEF message, after you have used the Type 2 Tag parser to read the NFC data:

uint32_t nfc_data_len = …; // Filled by the length of the NFC data.
uint8_t nfc_data[] = …; // Filled by the value of the NFC data.
// Buffer for parsing results that can hold an NDEF message descriptor with up to 10 records.
uint32_t desc_buf_len = sizeof(desc_buf);
ret_code = ndef_msg_parser(desc_buf,
&desc_buf_len,
nfc_data,
&nfc_data_len);
if (ret_code != NRF_SUCCESS)
{
NRF_LOG_ERROR("Error when parsing an NDEF message.");
}
// Print out the parsing results.

The Adafruit Tag Reader Example example shows how to use the library in an application.

The Experimental: BLE Heart Rate Collector Example with NFC Pairing example shows how to use this library with the NFC Connection Handover Message Parser to perform BLE NFC pairing.


Documentation feedback | Developer Zone | Subscribe | Updated