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.
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
NDEF NFC library
This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.
Implementations
At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.
Record.h@19:13d84b136a62, 2017-04-28 (annotated)
- Committer:
 - giovannivisentini
 - Date:
 - Fri Apr 28 12:13:51 2017 +0000
 - Revision:
 - 19:13d84b136a62
 - Parent:
 - 18:cf1dd5c931c2
 
Aligned to ARM mbed coding style.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| giovannivisentini | 6:739e3211749d | 1 | /** | 
| giovannivisentini | 6:739e3211749d | 2 | ****************************************************************************** | 
| giovannivisentini | 6:739e3211749d | 3 | * @file Record.h | 
| giovannivisentini | 8:473f6e0b03df | 4 | * @author ST / Central Labs | 
| giovannivisentini | 19:13d84b136a62 | 5 | * @version V2.0.0 | 
| giovannivisentini | 19:13d84b136a62 | 6 | * @date 28 Apr 2017 | 
| giovannivisentini | 12:ed4d9b8d1410 | 7 | * @brief Generic Record class | 
| giovannivisentini | 6:739e3211749d | 8 | ****************************************************************************** | 
| giovannivisentini | 6:739e3211749d | 9 | * @attention | 
| giovannivisentini | 6:739e3211749d | 10 | * | 
| giovannivisentini | 6:739e3211749d | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | 
| giovannivisentini | 0:04b82ae7aa43 | 12 | * | 
| giovannivisentini | 6:739e3211749d | 13 | * Redistribution and use in source and binary forms, with or without modification, | 
| giovannivisentini | 6:739e3211749d | 14 | * are permitted provided that the following conditions are met: | 
| giovannivisentini | 6:739e3211749d | 15 | * 1. Redistributions of source code must retain the above copyright notice, | 
| giovannivisentini | 6:739e3211749d | 16 | * this list of conditions and the following disclaimer. | 
| giovannivisentini | 6:739e3211749d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| giovannivisentini | 6:739e3211749d | 18 | * this list of conditions and the following disclaimer in the documentation | 
| giovannivisentini | 6:739e3211749d | 19 | * and/or other materials provided with the distribution. | 
| giovannivisentini | 6:739e3211749d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors | 
| giovannivisentini | 6:739e3211749d | 21 | * may be used to endorse or promote products derived from this software | 
| giovannivisentini | 6:739e3211749d | 22 | * without specific prior written permission. | 
| giovannivisentini | 6:739e3211749d | 23 | * | 
| giovannivisentini | 6:739e3211749d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| giovannivisentini | 6:739e3211749d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| giovannivisentini | 6:739e3211749d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| giovannivisentini | 6:739e3211749d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
| giovannivisentini | 6:739e3211749d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| giovannivisentini | 6:739e3211749d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
| giovannivisentini | 6:739e3211749d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| giovannivisentini | 6:739e3211749d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| giovannivisentini | 6:739e3211749d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| giovannivisentini | 6:739e3211749d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| giovannivisentini | 6:739e3211749d | 34 | * | 
| giovannivisentini | 6:739e3211749d | 35 | ****************************************************************************** | 
| giovannivisentini | 0:04b82ae7aa43 | 36 | */ | 
| giovannivisentini | 0:04b82ae7aa43 | 37 | |
| giovannivisentini | 0:04b82ae7aa43 | 38 | #ifndef NDEFLIB_RECORD_H_ | 
| giovannivisentini | 0:04b82ae7aa43 | 39 | #define NDEFLIB_RECORD_H_ | 
| giovannivisentini | 0:04b82ae7aa43 | 40 | #include <stdint.h> | 
| giovannivisentini | 0:04b82ae7aa43 | 41 | |
| giovannivisentini | 4:eaf6c49a86e4 | 42 | #include "RecordHeader.h" | 
| giovannivisentini | 4:eaf6c49a86e4 | 43 | |
| giovannivisentini | 0:04b82ae7aa43 | 44 | namespace NDefLib { | 
| giovannivisentini | 0:04b82ae7aa43 | 45 | |
| giovannivisentini | 4:eaf6c49a86e4 | 46 | /** | 
| giovannivisentini | 4:eaf6c49a86e4 | 47 | * Base class for a NDefRecord | 
| giovannivisentini | 4:eaf6c49a86e4 | 48 | * @see NFC Data Exchange Format (NDEF) Technical Specification NDEF 1.0 | 
| giovannivisentini | 4:eaf6c49a86e4 | 49 | */ | 
| giovannivisentini | 0:04b82ae7aa43 | 50 | class Record { | 
| giovannivisentini | 0:04b82ae7aa43 | 51 | public: | 
| giovannivisentini | 0:04b82ae7aa43 | 52 | |
| giovannivisentini | 4:eaf6c49a86e4 | 53 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 54 | * Enum used to identify the record type. | 
| giovannivisentini | 4:eaf6c49a86e4 | 55 | */ | 
| giovannivisentini | 4:eaf6c49a86e4 | 56 | typedef enum { | 
| giovannivisentini | 4:eaf6c49a86e4 | 57 | TYPE_UNKNOWN, //!< UNKNOWN record | 
| giovannivisentini | 4:eaf6c49a86e4 | 58 | TYPE_TEXT, //!< TEXT | 
| giovannivisentini | 4:eaf6c49a86e4 | 59 | TYPE_AAR, //!< Android Archive record | 
| giovannivisentini | 4:eaf6c49a86e4 | 60 | TYPE_MIME, //!< generic MIME type | 
| giovannivisentini | 4:eaf6c49a86e4 | 61 | TYPE_URI, //!< generic URI | 
| giovannivisentini | 4:eaf6c49a86e4 | 62 | TYPE_URI_MAIL, //!< Email URI record | 
| giovannivisentini | 4:eaf6c49a86e4 | 63 | TYPE_URI_SMS, //!< SMS URI record | 
| giovannivisentini | 4:eaf6c49a86e4 | 64 | TYPE_URI_GEOLOCATION,//!< position URI record | 
| giovannivisentini | 18:cf1dd5c931c2 | 65 | TYPE_MIME_VCARD, //!< VCard record | 
| giovannivisentini | 18:cf1dd5c931c2 | 66 | TYPE_WIFI_CONF //!< Wifi configuration | 
| giovannivisentini | 4:eaf6c49a86e4 | 67 | } RecordType_t; | 
| giovannivisentini | 0:04b82ae7aa43 | 68 | |
| giovannivisentini | 4:eaf6c49a86e4 | 69 | Record() { | 
| giovannivisentini | 4:eaf6c49a86e4 | 70 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 71 | |
| giovannivisentini | 4:eaf6c49a86e4 | 72 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 73 | * Set the record as the first record in the message. | 
| giovannivisentini | 4:eaf6c49a86e4 | 74 | */ | 
| giovannivisentini | 19:13d84b136a62 | 75 | void set_as_first_record() { | 
| giovannivisentini | 19:13d84b136a62 | 76 | mRecordHeader.set_MB(true); | 
| giovannivisentini | 0:04b82ae7aa43 | 77 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 78 | |
| giovannivisentini | 4:eaf6c49a86e4 | 79 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 80 | * Set the record as the last record in the message. | 
| giovannivisentini | 4:eaf6c49a86e4 | 81 | */ | 
| giovannivisentini | 19:13d84b136a62 | 82 | void set_as_last_record() { | 
| giovannivisentini | 19:13d84b136a62 | 83 | mRecordHeader.set_ME(true); | 
| giovannivisentini | 0:04b82ae7aa43 | 84 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 85 | |
| giovannivisentini | 4:eaf6c49a86e4 | 86 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 87 | * Check if it is the last record in the message. | 
| giovannivisentini | 4:eaf6c49a86e4 | 88 | * @return true if it is the last record in the message | 
| giovannivisentini | 4:eaf6c49a86e4 | 89 | */ | 
| giovannivisentini | 19:13d84b136a62 | 90 | bool is_last_record() const { | 
| giovannivisentini | 19:13d84b136a62 | 91 | return mRecordHeader.get_ME(); | 
| giovannivisentini | 0:04b82ae7aa43 | 92 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 93 | |
| giovannivisentini | 4:eaf6c49a86e4 | 94 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 95 | * Check if it is the first record in the message. | 
| giovannivisentini | 7:1ebd6049fa57 | 96 | * @return true if it is the fist record in the message | 
| giovannivisentini | 7:1ebd6049fa57 | 97 | */ | 
| giovannivisentini | 19:13d84b136a62 | 98 | bool is_first_record() const { | 
| giovannivisentini | 19:13d84b136a62 | 99 | return mRecordHeader.get_MB(); | 
| giovannivisentini | 7:1ebd6049fa57 | 100 | } | 
| giovannivisentini | 7:1ebd6049fa57 | 101 | |
| giovannivisentini | 7:1ebd6049fa57 | 102 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 103 | * Set the record as generic (not the first one and not the last one) | 
| giovannivisentini | 4:eaf6c49a86e4 | 104 | */ | 
| giovannivisentini | 19:13d84b136a62 | 105 | void set_as_middle_record() { | 
| giovannivisentini | 19:13d84b136a62 | 106 | mRecordHeader.set_MB(false); | 
| giovannivisentini | 19:13d84b136a62 | 107 | mRecordHeader.set_ME(false); | 
| giovannivisentini | 0:04b82ae7aa43 | 108 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 109 | |
| giovannivisentini | 10:9f34b0cfefe4 | 110 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 111 | * Check if the record is in the middle of a chain. | 
| giovannivisentini | 10:9f34b0cfefe4 | 112 | * @return true if is not the fist or the last one | 
| giovannivisentini | 10:9f34b0cfefe4 | 113 | */ | 
| giovannivisentini | 19:13d84b136a62 | 114 | bool is_middle_record() const{ | 
| giovannivisentini | 19:13d84b136a62 | 115 | return ! (mRecordHeader.get_MB() || mRecordHeader.get_ME()); | 
| giovannivisentini | 7:1ebd6049fa57 | 116 | } | 
| giovannivisentini | 7:1ebd6049fa57 | 117 | |
| giovannivisentini | 4:eaf6c49a86e4 | 118 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 119 | * Get tag type. | 
| giovannivisentini | 12:ed4d9b8d1410 | 120 | * @par This method should be overridden to return a valid type. | 
| giovannivisentini | 12:ed4d9b8d1410 | 121 | * @return tag type | 
| giovannivisentini | 4:eaf6c49a86e4 | 122 | */ | 
| giovannivisentini | 19:13d84b136a62 | 123 | virtual RecordType_t get_type() const { | 
| giovannivisentini | 1:a0eeb478a45a | 124 | return TYPE_UNKNOWN; | 
| giovannivisentini | 4:eaf6c49a86e4 | 125 | } //getType | 
| giovannivisentini | 1:a0eeb478a45a | 126 | |
| giovannivisentini | 7:1ebd6049fa57 | 127 | |
| giovannivisentini | 7:1ebd6049fa57 | 128 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 129 | * Get the record header. | 
| giovannivisentini | 12:ed4d9b8d1410 | 130 | * @return record header | 
| giovannivisentini | 7:1ebd6049fa57 | 131 | */ | 
| giovannivisentini | 19:13d84b136a62 | 132 | const RecordHeader& get_header() const{ | 
| giovannivisentini | 7:1ebd6049fa57 | 133 | return mRecordHeader; | 
| giovannivisentini | 7:1ebd6049fa57 | 134 | } | 
| giovannivisentini | 7:1ebd6049fa57 | 135 | |
| giovannivisentini | 4:eaf6c49a86e4 | 136 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 137 | * Number of bytes needed to store this record. | 
| giovannivisentini | 12:ed4d9b8d1410 | 138 | * @return size of the header + size of the record content | 
| giovannivisentini | 4:eaf6c49a86e4 | 139 | */ | 
| giovannivisentini | 19:13d84b136a62 | 140 | virtual uint16_t get_byte_length() { | 
| giovannivisentini | 19:13d84b136a62 | 141 | return mRecordHeader.get_record_length(); | 
| giovannivisentini | 0:04b82ae7aa43 | 142 | } | 
| giovannivisentini | 0:04b82ae7aa43 | 143 | |
| giovannivisentini | 4:eaf6c49a86e4 | 144 | /** | 
| giovannivisentini | 12:ed4d9b8d1410 | 145 | * Write the record content into a buffer. | 
| giovannivisentini | 12:ed4d9b8d1410 | 146 | * @param[out] buffer buffer to write the record content into, the buffer size | 
| giovannivisentini | 12:ed4d9b8d1410 | 147 | * must be almost {@link Record#getByteLength} bytes. | 
| giovannivisentini | 12:ed4d9b8d1410 | 148 | * @return number of written bytes | 
| giovannivisentini | 4:eaf6c49a86e4 | 149 | */ | 
| giovannivisentini | 0:04b82ae7aa43 | 150 | virtual uint16_t write(uint8_t *buffer)=0; | 
| giovannivisentini | 0:04b82ae7aa43 | 151 | |
| giovannivisentini | 4:eaf6c49a86e4 | 152 | virtual ~Record() { | 
| giovannivisentini | 4:eaf6c49a86e4 | 153 | }; | 
| giovannivisentini | 0:04b82ae7aa43 | 154 | |
| giovannivisentini | 0:04b82ae7aa43 | 155 | protected: | 
| giovannivisentini | 0:04b82ae7aa43 | 156 | RecordHeader mRecordHeader; | 
| giovannivisentini | 0:04b82ae7aa43 | 157 | }; | 
| giovannivisentini | 0:04b82ae7aa43 | 158 | |
| giovannivisentini | 0:04b82ae7aa43 | 159 | } /* namespace NDefLib */ | 
| giovannivisentini | 0:04b82ae7aa43 | 160 | |
| giovannivisentini | 0:04b82ae7aa43 | 161 | #endif /* NDEFLIB_RECORD_H_ */ | 
