nfc_text_rec.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef NFC_TEXT_REC_H__
  13. #define NFC_TEXT_REC_H__
  14. /**@file
  15. *
  16. * @defgroup nfc_text_rec Text records
  17. * @{
  18. * @ingroup nfc_ndef_messages
  19. *
  20. * @brief Generation of NFC NDEF Text record descriptions.
  21. *
  22. */
  23. #include "nfc_ndef_record.h"
  24. /**
  25. * @brief Text record payload descriptor.
  26. */
  27. typedef struct
  28. {
  29. enum{
  30. UTF_8 = 0,
  31. UTF_16 = 1,
  32. } utf; ///< Type of the Unicode Transformation Format.
  33. uint8_t const * p_lang_code; ///< Pointer to the IANA language code.
  34. uint8_t lang_code_len; ///< Length of the IANA language code.
  35. uint8_t const * p_data; ///< Pointer to the user text.
  36. uint32_t data_len; ///< Length of the user text.
  37. } nfc_text_rec_payload_desc_t;
  38. /**
  39. * @brief Constructor for an NFC NDEF Text record payload.
  40. *
  41. * @param[in] p_nfc_rec_text_payload_desc Pointer to the Text record description.
  42. * @param[out] p_buff Pointer to the payload destination.
  43. *
  44. * @param[in,out] p_len Size of the available memory to write as input.
  45. * Size of the generated record payload as output.
  46. */
  47. ret_code_t nfc_text_rec_payload_constructor(nfc_text_rec_payload_desc_t * p_nfc_rec_text_payload_desc,
  48. uint8_t * p_buff,
  49. uint32_t * p_len);
  50. /**
  51. * @brief External reference to the type field of the Text record, defined in the
  52. * file @c nfc_text_rec.c. It is used in the @ref NFC_NDEF_TEXT_RECORD_DESC_DEF macro.
  53. */
  54. extern const uint8_t nfc_text_rec_type_field[];
  55. /**
  56. * @brief Size of the type field of the Text record, defined in the
  57. * file @c nfc_text_rec.c. It is used in the @ref NFC_NDEF_TEXT_RECORD_DESC_DEF macro.
  58. */
  59. #define NFC_TEXT_REC_TYPE_LENGTH 1
  60. /**
  61. *@brief Macro for creating and initializing an NFC NDEF record descriptor for an Text record.
  62. *
  63. * This macro creates and initializes a static instance of type @ref nfc_ndef_record_desc_t and
  64. * a static instance of type @ref nfc_text_rec_payload_desc_t, which together constitute
  65. * an instance of an Text record.
  66. *
  67. * Use the macro @ref NFC_NDEF_TEXT_RECORD_DESC to access the NDEF Text record descriptor instance.
  68. *
  69. * @param[in] NAME Name of the created record descriptor instance.
  70. * @param[in] UTF Unicode Transformation Format.
  71. * @param[in] P_LANG_CODE Pointer to the IANA language code.
  72. * @param[in] LANG_CODE_LEN Length of the IANA language code.
  73. * @param[in] P_DATA Pointer to the user text.
  74. * @param[in] DATA_LEN Length of the user text.
  75. */
  76. #define NFC_NDEF_TEXT_RECORD_DESC_DEF(NAME, \
  77. UTF, \
  78. P_LANG_CODE, \
  79. LANG_CODE_LEN, \
  80. P_DATA, \
  81. DATA_LEN) \
  82. static nfc_text_rec_payload_desc_t NAME##_nfc_text_rec_payload_desc; \
  83. NAME##_nfc_text_rec_payload_desc = (nfc_text_rec_payload_desc_t) \
  84. { \
  85. .utf = UTF, \
  86. .p_lang_code = P_LANG_CODE, \
  87. .lang_code_len = LANG_CODE_LEN, \
  88. .p_data = P_DATA, \
  89. .data_len = DATA_LEN, \
  90. }; \
  91. NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME, \
  92. TNF_WELL_KNOWN, \
  93. 0, \
  94. 0, \
  95. nfc_text_rec_type_field, \
  96. NFC_TEXT_REC_TYPE_LENGTH, \
  97. nfc_text_rec_payload_constructor, \
  98. &(NAME##_nfc_text_rec_payload_desc))
  99. /**
  100. * @brief Macro for accessing the NFC NDEF Text record descriptor
  101. * instance that was created with @ref NFC_NDEF_TEXT_RECORD_DESC_DEF.
  102. */
  103. #define NFC_NDEF_TEXT_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
  104. /** @} */
  105. #endif // NFC_TEXT_REC_H__