Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NFCNDEFCapable.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef MBED_NFC_NDEF_CAPABLE_H 00018 #define MBED_NFC_NDEF_CAPABLE_H 00019 00020 #include <stdint.h> 00021 00022 #include "platform/Span.h" 00023 00024 #include "NFCDefinitions.h" 00025 00026 #include "nfc/stack/ndef/ndef.h" 00027 #include "nfc/acore/acore/ac_buffer.h" 00028 #include "nfc/acore/acore/ac_buffer_reader.h" 00029 #include "nfc/acore/acore/ac_buffer_builder.h" 00030 00031 namespace mbed { 00032 namespace nfc { 00033 00034 /** 00035 * @addtogroup nfc 00036 * @{ 00037 */ 00038 00039 /** 00040 * The base class for all endpoints that can support NDEF content. 00041 */ 00042 class NFCNDEFCapable { 00043 public: 00044 /** 00045 * Construct a NFCNDEFCapable instance. 00046 * @param[in] buffer a bytes array used to store NDEF messages 00047 */ 00048 NFCNDEFCapable(const Span<uint8_t> &buffer); 00049 00050 /** 00051 * Check if this instance actually supports NDEF content. 00052 * 00053 * @return whether NDEF content is supported 00054 */ 00055 virtual bool is_ndef_supported() const 00056 { 00057 return false; 00058 } 00059 00060 struct Delegate { 00061 /** 00062 * Parse a NDEF message. 00063 * 00064 * @param[in] buffer a buffer containing the message to parse 00065 */ 00066 virtual void parse_ndef_message(const Span<const uint8_t> &buffer) { } 00067 00068 /** 00069 * Build a NDEF message. 00070 * 00071 * @param[in] buffer a mutable buffer in which the message should be stored 00072 * 00073 * @return the number of bytes actually used 00074 */ 00075 virtual size_t build_ndef_message(const Span<uint8_t> &buffer) 00076 { 00077 return 0; 00078 } 00079 00080 protected: 00081 ~Delegate() {} 00082 }; 00083 00084 protected: 00085 /** 00086 * Parse a NDEF message. 00087 * 00088 * @param[in] buffer a buffer containing a NDEF message 00089 */ 00090 void parse_ndef_message(const ac_buffer_t &buffer); 00091 00092 /** 00093 * Build NDEF message. 00094 * 00095 * @param[in,out] buffer_builder a buffer builder in which to create the NDEF message. 00096 * The backing buffer is guaranteed to be continuous. 00097 */ 00098 void build_ndef_message(ac_buffer_builder_t &buffer_builder); 00099 00100 /** 00101 * Retrieve underlying NDEF message instance 00102 * @return pointer to NDEF message instance 00103 */ 00104 ndef_msg_t *ndef_message(); 00105 00106 private: 00107 /** 00108 * Get the delegate that will receive events generated by this class. 00109 * 00110 * @return the delegate instance to use 00111 */ 00112 virtual Delegate *ndef_capable_delegate(); 00113 00114 // Callbacks from NDEF stack 00115 static nfc_err_t s_ndef_encode(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData); 00116 static nfc_err_t s_ndef_decode(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData); 00117 nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr); 00118 nfc_err_t ndef_decode(ac_buffer_t *pBuffer); 00119 00120 ndef_msg_t _ndef_message; 00121 }; 00122 00123 /** 00124 * @} 00125 */ 00126 00127 } // namespace nfc 00128 } // namespace mbed 00129 00130 #endif
Generated on Tue Aug 9 2022 00:37:16 by
1.7.2