| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
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.
uint8_t desc_buf[NFC_NDEF_PARSER_REQIRED_MEMO_SIZE_CALC(10)];
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)
{
app_trace_log("Error when parsing an NDEF message.\r\n");
}
// Print out the parsing results.
ndef_msg_printout((nfc_ndef_msg_desc_t *) desc_buf);

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