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.
Record.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 NFC_NDEF_RECORD_H_ 00018 #define NFC_NDEF_RECORD_H_ 00019 00020 #include <stdint.h> 00021 00022 #include "platform/Span.h" 00023 00024 namespace mbed { 00025 namespace nfc { 00026 namespace ndef { 00027 00028 /** 00029 * @addtogroup nfc 00030 * @{ 00031 */ 00032 00033 00034 /** 00035 * Set of constants of a record header 00036 */ 00037 struct Header { 00038 static const uint8_t message_begin_bit = (1 << 7); 00039 static const uint8_t message_end_bit = (1 << 6); 00040 static const uint8_t chunk_flag_bit = (1 << 5); 00041 static const uint8_t short_record_bit = (1 << 4); 00042 static const uint8_t id_length_bit = (1 << 3); 00043 static const uint8_t tnf_bits = (1 << 0) | (1 << 1) | (1 << 2); 00044 }; 00045 00046 /** 00047 * Encode a record type. 00048 * 00049 * A RecordType is composed of a type name format flag and an optional type 00050 * value. 00051 */ 00052 struct RecordType { 00053 /** 00054 * Type name format of a record. 00055 */ 00056 enum tnf_t { 00057 /** 00058 * empty type; value must be empty. 00059 */ 00060 empty = 0x00, //!< empty 00061 00062 /** 00063 * Type defined by the NFC forum; value must be defined. 00064 */ 00065 well_known_type = 0x01,//!< well_known_type 00066 00067 /** 00068 * Mime type; value must be defined. 00069 */ 00070 media_type = 0x02, //!< media_type 00071 00072 /** 00073 * Absolute URI; value must be defined. 00074 */ 00075 absolute_uri = 0x03, //!< absolute_uri 00076 00077 /** 00078 * Type defined by vendors; value must be defined. 00079 */ 00080 external_type = 0x04, //!< external_type 00081 00082 /** 00083 * Unknown type; value must be empty. 00084 */ 00085 unknown = 0x05, //!< unknown 00086 00087 /** 00088 * Use for middle and terminating chunk record. 00089 * value must be empty. 00090 */ 00091 unchanged = 0x06 //!< unchanged 00092 }; 00093 00094 /** 00095 * Construct an unknown type. 00096 */ 00097 RecordType() : tnf(unknown), value() { } 00098 00099 /** 00100 * Construct a type with no value. 00101 * 00102 * @note Valid tnf are: empty, unknown and unchanged. 00103 * 00104 * @param tnf The type name format of the type. 00105 */ 00106 RecordType(tnf_t tnf) : 00107 tnf(tnf), value() 00108 { } 00109 00110 /** 00111 * Construct a RecordType from a type name format and its associated value. 00112 * 00113 * @param tnf The type name format of the record type. 00114 * @param value The value associated with the tnf. 00115 */ 00116 RecordType(tnf_t tnf, const Span<const uint8_t> &value) : 00117 tnf(tnf), value(value) 00118 { } 00119 00120 /** 00121 * Type name format of the record type. 00122 */ 00123 tnf_t tnf; 00124 00125 /** 00126 * Value associated with the record type. It can be empty. 00127 */ 00128 Span<const uint8_t> value; 00129 }; 00130 00131 /** 00132 * Definition of a Record payload. 00133 * 00134 * @note A payload can be empty. 00135 */ 00136 typedef Span<const uint8_t> RecordPayload; 00137 00138 /** 00139 * Definition of a Record IR. 00140 * 00141 * @note ID's are optional and therefore it can be empty. 00142 */ 00143 typedef Span<const uint8_t> RecordID; 00144 00145 /** 00146 * Represent a record. 00147 */ 00148 struct Record { 00149 /** 00150 * Construct an empty record. 00151 */ 00152 Record() : type(), payload(), id(), chunk(false), last_record(false) { } 00153 00154 /** 00155 * Construct a record from its type, payload and id. 00156 * 00157 * The flags chunk and last_record can be added to indicate if the record 00158 * is aprt of a chunk or the last one in a message. 00159 * 00160 * @param type The type of the record. 00161 * @param payload The payload of the record. 00162 * @param id The id associated with the record. 00163 * @param chunk If true then this record is a chunk of a bigger record. 00164 * @param last_record If true then this record is the last of the message 00165 * containing it. 00166 */ 00167 Record( 00168 RecordType type, 00169 const RecordPayload &payload, 00170 const RecordID &id, 00171 bool chunk, 00172 bool last_record 00173 ) : 00174 type(type), 00175 payload(payload), 00176 id(id), 00177 chunk(chunk), 00178 last_record(last_record) 00179 { } 00180 00181 /** 00182 * Type of the record. 00183 */ 00184 RecordType type; 00185 00186 /** 00187 * Value of the payload. 00188 */ 00189 RecordPayload payload; 00190 00191 /** 00192 * ID of the record. 00193 */ 00194 RecordID id; 00195 00196 /** 00197 * If true, this record is a chunked record. 00198 */ 00199 bool chunk: 1; 00200 00201 /** 00202 * If true, this record is the last one of the payload containing it. 00203 */ 00204 bool last_record: 1; 00205 }; 00206 00207 00208 /** 00209 * @} 00210 */ 00211 00212 } // namespace ndef 00213 } // namespace nfc 00214 } // namespace mbed 00215 00216 #endif /* NFC_NDEF_RECORD_H_ */
Generated on Tue Aug 9 2022 00:37:18 by
1.7.2