Mistake on this page?
Report an issue in GitHub or email us
NFCNDEFCapable.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_NFC_NDEF_CAPABLE_H
18 #define MBED_NFC_NDEF_CAPABLE_H
19 
20 #include <stdint.h>
21 
22 #include "platform/Span.h"
23 
24 #include "NFCDefinitions.h"
25 
26 #include "nfc/stack/ndef/ndef.h"
30 
31 namespace mbed {
32 namespace nfc {
33 
34 /**
35  * @addtogroup nfc
36  * @{
37  */
38 
39 /**
40  * The base class for all endpoints that can support NDEF content.
41  */
43 public:
44  /**
45  * Construct a NFCNDEFCapable instance.
46  * @param[in] buffer a bytes array used to store NDEF messages
47  */
48  NFCNDEFCapable(const Span<uint8_t> &buffer);
49 
50  /**
51  * Check if this instance actually supports NDEF content.
52  *
53  * @return whether NDEF content is supported
54  */
55  virtual bool is_ndef_supported() const
56  {
57  return false;
58  }
59 
60  struct Delegate {
61  /**
62  * Parse a NDEF message.
63  *
64  * @param[in] buffer a buffer containing the message to parse
65  */
66  virtual void parse_ndef_message(const Span<const uint8_t> &buffer) { }
67 
68  /**
69  * Build a NDEF message.
70  *
71  * @param[in] buffer a mutable buffer in which the message should be stored
72  *
73  * @return the number of bytes actually used
74  */
75  virtual size_t build_ndef_message(const Span<uint8_t> &buffer)
76  {
77  return 0;
78  }
79 
80  protected:
81  ~Delegate() {}
82  };
83 
84 protected:
85  /**
86  * Parse a NDEF message.
87  *
88  * @param[in] buffer a buffer containing a NDEF message
89  */
90  void parse_ndef_message(const ac_buffer_t &buffer);
91 
92  /**
93  * Build NDEF message.
94  *
95  * @param[in,out] buffer_builder a buffer builder in which to create the NDEF message.
96  * The backing buffer is guaranteed to be continuous.
97  */
98  void build_ndef_message(ac_buffer_builder_t &buffer_builder);
99 
100  /**
101  * Retrieve underlying NDEF message instance
102  * @return pointer to NDEF message instance
103  */
104  ndef_msg_t *ndef_message();
105 
106 private:
107  /**
108  * Get the delegate that will receive events generated by this class.
109  *
110  * @return the delegate instance to use
111  */
112  virtual Delegate *ndef_capable_delegate();
113 
114  // Callbacks from NDEF stack
115  static nfc_err_t s_ndef_encode(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData);
116  static nfc_err_t s_ndef_decode(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData);
117  nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr);
118  nfc_err_t ndef_decode(ac_buffer_t *pBuffer);
119 
120  ndef_msg_t _ndef_message;
121 };
122 
123 /**
124  * @}
125  */
126 
127 } // namespace nfc
128 } // namespace mbed
129 
130 #endif
virtual size_t build_ndef_message(const Span< uint8_t > &buffer)
Build a NDEF message.
NFCNDEFCapable(const Span< uint8_t > &buffer)
Construct a NFCNDEFCapable instance.
ndef_msg_t * ndef_message()
Retrieve underlying NDEF message instance.
virtual bool is_ndef_supported() const
Check if this instance actually supports NDEF content.
The base class for all endpoints that can support NDEF content.
virtual void parse_ndef_message(const Span< const uint8_t > &buffer)
Parse a NDEF message.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.