Mistake on this page?
Report an issue in GitHub or email us
Record.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 NFC_NDEF_RECORD_H_
18 #define NFC_NDEF_RECORD_H_
19 
20 #include <stdint.h>
21 
22 #include "platform/Span.h"
23 
24 namespace mbed {
25 namespace nfc {
26 namespace ndef {
27 
28 /**
29  * @addtogroup nfc
30  * @{
31  */
32 
33 
34 /**
35  * Set of constants of a record header
36  */
37 struct Header {
38  static const uint8_t message_begin_bit = (1 << 7);
39  static const uint8_t message_end_bit = (1 << 6);
40  static const uint8_t chunk_flag_bit = (1 << 5);
41  static const uint8_t short_record_bit = (1 << 4);
42  static const uint8_t id_length_bit = (1 << 3);
43  static const uint8_t tnf_bits = (1 << 0) | (1 << 1) | (1 << 2);
44 };
45 
46 /**
47  * Encode a record type.
48  *
49  * A RecordType is composed of a type name format flag and an optional type
50  * value.
51  */
52 struct RecordType {
53  /**
54  * Type name format of a record.
55  */
56  enum tnf_t {
57  /**
58  * empty type; value must be empty.
59  */
60  empty = 0x00, //!< empty
61 
62  /**
63  * Type defined by the NFC forum; value must be defined.
64  */
65  well_known_type = 0x01,//!< well_known_type
66 
67  /**
68  * Mime type; value must be defined.
69  */
70  media_type = 0x02, //!< media_type
71 
72  /**
73  * Absolute URI; value must be defined.
74  */
75  absolute_uri = 0x03, //!< absolute_uri
76 
77  /**
78  * Type defined by vendors; value must be defined.
79  */
80  external_type = 0x04, //!< external_type
81 
82  /**
83  * Unknown type; value must be empty.
84  */
85  unknown = 0x05, //!< unknown
86 
87  /**
88  * Use for middle and terminating chunk record.
89  * value must be empty.
90  */
91  unchanged = 0x06 //!< unchanged
92  };
93 
94  /**
95  * Construct an unknown type.
96  */
97  RecordType() : tnf(unknown), value() { }
98 
99  /**
100  * Construct a type with no value.
101  *
102  * @note Valid tnf are: empty, unknown and unchanged.
103  *
104  * @param tnf The type name format of the type.
105  */
107  tnf(tnf), value()
108  { }
109 
110  /**
111  * Construct a RecordType from a type name format and its associated value.
112  *
113  * @param tnf The type name format of the record type.
114  * @param value The value associated with the tnf.
115  */
116  RecordType(tnf_t tnf, const Span<const uint8_t> &value) :
117  tnf(tnf), value(value)
118  { }
119 
120  /**
121  * Type name format of the record type.
122  */
124 
125  /**
126  * Value associated with the record type. It can be empty.
127  */
129 };
130 
131 /**
132  * Definition of a Record payload.
133  *
134  * @note A payload can be empty.
135  */
137 
138 /**
139  * Definition of a Record IR.
140  *
141  * @note ID's are optional and therefore it can be empty.
142  */
144 
145 /**
146  * Represent a record.
147  */
148 struct Record {
149  /**
150  * Construct an empty record.
151  */
152  Record() : type(), payload(), id(), chunk(false), last_record(false) { }
153 
154  /**
155  * Construct a record from its type, payload and id.
156  *
157  * The flags chunk and last_record can be added to indicate if the record
158  * is aprt of a chunk or the last one in a message.
159  *
160  * @param type The type of the record.
161  * @param payload The payload of the record.
162  * @param id The id associated with the record.
163  * @param chunk If true then this record is a chunk of a bigger record.
164  * @param last_record If true then this record is the last of the message
165  * containing it.
166  */
168  RecordType type,
169  const RecordPayload &payload,
170  const RecordID &id,
171  bool chunk,
172  bool last_record
173  ) :
174  type(type),
175  payload(payload),
176  id(id),
177  chunk(chunk),
178  last_record(last_record)
179  { }
180 
181  /**
182  * Type of the record.
183  */
185 
186  /**
187  * Value of the payload.
188  */
189  RecordPayload payload;
190 
191  /**
192  * ID of the record.
193  */
194  RecordID id;
195 
196  /**
197  * If true, this record is a chunked record.
198  */
199  bool chunk: 1;
200 
201  /**
202  * If true, this record is the last one of the payload containing it.
203  */
204  bool last_record: 1;
205 };
206 
207 
208 /**
209  * @}
210  */
211 
212 } // namespace ndef
213 } // namespace nfc
214 } // namespace mbed
215 
216 #endif /* NFC_NDEF_RECORD_H_ */
Record(RecordType type, const RecordPayload &payload, const RecordID &id, bool chunk, bool last_record)
Construct a record from its type, payload and id.
Definition: Record.h:167
RecordType type
Type of the record.
Definition: Record.h:184
Set of constants of a record header.
Definition: Record.h:37
RecordPayload payload
Value of the payload.
Definition: Record.h:189
tnf_t
Type name format of a record.
Definition: Record.h:56
RecordType(tnf_t tnf, const Span< const uint8_t > &value)
Construct a RecordType from a type name format and its associated value.
Definition: Record.h:116
Represent a record.
Definition: Record.h:148
Span< const uint8_t > RecordPayload
Definition of a Record payload.
Definition: Record.h:136
Span< const uint8_t > RecordID
Definition of a Record IR.
Definition: Record.h:143
RecordID id
ID of the record.
Definition: Record.h:194
Record()
Construct an empty record.
Definition: Record.h:152
Encode a record type.
Definition: Record.h:52
tnf_t tnf
Type name format of the record type.
Definition: Record.h:123
RecordType()
Construct an unknown type.
Definition: Record.h:97
Span< const uint8_t > value
Value associated with the record type.
Definition: Record.h:128
RecordType(tnf_t tnf)
Construct a type with no value.
Definition: Record.h:106
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.