Mbed OS Reference
Loading...
Searching...
No Matches
Record.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NFC_NDEF_RECORD_H_
19#define NFC_NDEF_RECORD_H_
20
21#include <stdint.h>
22
23#include "platform/Span.h"
24
25namespace mbed {
26namespace nfc {
27namespace ndef {
28
29/**
30 * @addtogroup nfc
31 * @{
32 */
33
34
35/**
36 * Set of constants of a record header
37 */
38struct Header {
39 static const uint8_t message_begin_bit = (1 << 7);
40 static const uint8_t message_end_bit = (1 << 6);
41 static const uint8_t chunk_flag_bit = (1 << 5);
42 static const uint8_t short_record_bit = (1 << 4);
43 static const uint8_t id_length_bit = (1 << 3);
44 static const uint8_t tnf_bits = (1 << 0) | (1 << 1) | (1 << 2);
45};
46
47/**
48 * Encode a record type.
49 *
50 * A RecordType is composed of a type name format flag and an optional type
51 * value.
52 */
53struct RecordType {
54 /**
55 * Type name format of a record.
56 */
57 enum tnf_t {
58 /**
59 * empty type; value must be empty.
60 */
61 empty = 0x00, //!< empty
62
63 /**
64 * Type defined by the NFC forum; value must be defined.
65 */
66 well_known_type = 0x01,//!< well_known_type
67
68 /**
69 * Mime type; value must be defined.
70 */
71 media_type = 0x02, //!< media_type
72
73 /**
74 * Absolute URI; value must be defined.
75 */
76 absolute_uri = 0x03, //!< absolute_uri
77
78 /**
79 * Type defined by vendors; value must be defined.
80 */
81 external_type = 0x04, //!< external_type
82
83 /**
84 * Unknown type; value must be empty.
85 */
86 unknown = 0x05, //!< unknown
87
88 /**
89 * Use for middle and terminating chunk record.
90 * value must be empty.
91 */
92 unchanged = 0x06 //!< unchanged
93 };
94
95 /**
96 * Construct an unknown type.
97 */
99
100 /**
101 * Construct a type with no value.
102 *
103 * @note Valid tnf are: empty, unknown and unchanged.
104 *
105 * @param tnf The type name format of the type.
106 */
108 tnf(tnf), value()
109 { }
110
111 /**
112 * Construct a RecordType from a type name format and its associated value.
113 *
114 * @param tnf The type name format of the record type.
115 * @param value The value associated with the tnf.
116 */
118 tnf(tnf), value(value)
119 { }
120
121 /**
122 * Type name format of the record type.
123 */
125
126 /**
127 * Value associated with the record type. It can be empty.
128 */
130};
131
132/**
133 * Definition of a Record payload.
134 *
135 * @note A payload can be empty.
136 */
138
139/**
140 * Definition of a Record IR.
141 *
142 * @note ID's are optional and therefore it can be empty.
143 */
145
146/**
147 * Represent a record.
148 */
149struct Record {
150 /**
151 * Construct an empty record.
152 */
153 Record() : type(), payload(), id(), chunk(false), last_record(false) { }
154
155 /**
156 * Construct a record from its type, payload and id.
157 *
158 * The flags chunk and last_record can be added to indicate if the record
159 * is aprt of a chunk or the last one in a message.
160 *
161 * @param type The type of the record.
162 * @param payload The payload of the record.
163 * @param id The id associated with the record.
164 * @param chunk If true then this record is a chunk of a bigger record.
165 * @param last_record If true then this record is the last of the message
166 * containing it.
167 */
170 const RecordPayload &payload,
171 const RecordID &id,
172 bool chunk,
173 bool last_record
174 ) :
175 type(type),
177 id(id),
178 chunk(chunk),
180 { }
181
182 /**
183 * Type of the record.
184 */
186
187 /**
188 * Value of the payload.
189 */
191
192 /**
193 * ID of the record.
194 */
196
197 /**
198 * If true, this record is a chunked record.
199 */
200 bool chunk: 1;
201
202 /**
203 * If true, this record is the last one of the payload containing it.
204 */
205 bool last_record: 1;
206};
207
208
209/**
210 * @}
211 */
212
213} // namespace ndef
214} // namespace nfc
215} // namespace mbed
216
217#endif /* NFC_NDEF_RECORD_H_ */
Span< const uint8_t > RecordPayload
Definition of a Record payload.
Definition: Record.h:137
Span< const uint8_t > RecordID
Definition of a Record IR.
Definition: Record.h:144
Nonowning view to a sequence of contiguous elements.
Definition: Span.h:215
Set of constants of a record header.
Definition: Record.h:38
Represent a record.
Definition: Record.h:149
Record()
Construct an empty record.
Definition: Record.h:153
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:168
bool last_record
If true, this record is the last one of the payload containing it.
Definition: Record.h:205
RecordPayload payload
Value of the payload.
Definition: Record.h:190
RecordID id
ID of the record.
Definition: Record.h:195
RecordType type
Type of the record.
Definition: Record.h:185
bool chunk
If true, this record is a chunked record.
Definition: Record.h:200
Encode a record type.
Definition: Record.h:53
Span< const uint8_t > value
Value associated with the record type.
Definition: Record.h:129
RecordType(tnf_t tnf)
Construct a type with no value.
Definition: Record.h:107
tnf_t tnf
Type name format of the record type.
Definition: Record.h:124
RecordType()
Construct an unknown type.
Definition: Record.h:98
tnf_t
Type name format of a record.
Definition: Record.h:57
@ unchanged
Use for middle and terminating chunk record.
Definition: Record.h:92
@ unknown
Unknown type; value must be empty.
Definition: Record.h:86
@ well_known_type
Type defined by the NFC forum; value must be defined.
Definition: Record.h:66
@ media_type
Mime type; value must be defined.
Definition: Record.h:71
@ external_type
Type defined by vendors; value must be defined.
Definition: Record.h:81
@ absolute_uri
Absolute URI; value must be defined.
Definition: Record.h:76
@ empty
empty type; value must be empty.
Definition: Record.h:61
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:117