Utility library to read and write Ndef messages from/to a Type4 NFC tag

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of NDefLib by ST Expansion SW Team

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.

Committer:
giovannivisentini
Date:
Fri Jan 08 15:52:39 2016 +0000
Revision:
10:9f34b0cfefe4
Parent:
9:689c1f56f359
Child:
12:ed4d9b8d1410
update comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
giovannivisentini 6:739e3211749d 1 /**
giovannivisentini 6:739e3211749d 2 ******************************************************************************
giovannivisentini 6:739e3211749d 3 * @file RecordAAR.h
giovannivisentini 8:473f6e0b03df 4 * @author ST / Central Labs
giovannivisentini 6:739e3211749d 5 * @version V1.0.0
giovannivisentini 6:739e3211749d 6 * @date 6 Nov 2015
giovannivisentini 9:689c1f56f359 7 * @brief Create a Record that can start an application in an Android mobile
giovannivisentini 6:739e3211749d 8 ******************************************************************************
giovannivisentini 6:739e3211749d 9 * @attention
giovannivisentini 6:739e3211749d 10 *
giovannivisentini 6:739e3211749d 11 * <h2><center>&copy; 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_RECORDTYPE_RECORDAAR_H_
giovannivisentini 0:04b82ae7aa43 39 #define NDEFLIB_RECORDTYPE_RECORDAAR_H_
giovannivisentini 0:04b82ae7aa43 40
giovannivisentini 0:04b82ae7aa43 41 #include <string>
giovannivisentini 0:04b82ae7aa43 42
giovannivisentini 0:04b82ae7aa43 43 #include "NDefLib/Record.h"
giovannivisentini 4:eaf6c49a86e4 44
giovannivisentini 0:04b82ae7aa43 45 namespace NDefLib {
giovannivisentini 0:04b82ae7aa43 46
giovannivisentini 4:eaf6c49a86e4 47 /**
giovannivisentini 9:689c1f56f359 48 * create a Record that can start an application in an Android mobile,
giovannivisentini 9:689c1f56f359 49 * The package data are copied inside the class
giovannivisentini 4:eaf6c49a86e4 50 */
giovannivisentini 0:04b82ae7aa43 51 class RecordAAR: public Record {
giovannivisentini 0:04b82ae7aa43 52 public:
giovannivisentini 9:689c1f56f359 53
giovannivisentini 4:eaf6c49a86e4 54 /**
giovannivisentini 9:689c1f56f359 55 * Create an RecordAAR reading the data from the buffer
giovannivisentini 4:eaf6c49a86e4 56 * @param header record header already read
giovannivisentini 4:eaf6c49a86e4 57 * @param buffer buffer where read the data
giovannivisentini 4:eaf6c49a86e4 58 * @return an object of type recordAAR or NULL
giovannivisentini 4:eaf6c49a86e4 59 * @par free the pointer return by this function
giovannivisentini 4:eaf6c49a86e4 60 */
giovannivisentini 4:eaf6c49a86e4 61 static RecordAAR* parse(const RecordHeader &header,
giovannivisentini 4:eaf6c49a86e4 62 const uint8_t * const buffer);
giovannivisentini 1:a0eeb478a45a 63
giovannivisentini 4:eaf6c49a86e4 64 /**
giovannivisentini 4:eaf6c49a86e4 65 * build a new record
giovannivisentini 4:eaf6c49a86e4 66 * @param packageName package of the application to start
giovannivisentini 4:eaf6c49a86e4 67 */
giovannivisentini 5:f2b7efcc5b6e 68 explicit RecordAAR(const std::string &packageName);
giovannivisentini 1:a0eeb478a45a 69
giovannivisentini 0:04b82ae7aa43 70
giovannivisentini 9:689c1f56f359 71 /**
giovannivisentini 10:9f34b0cfefe4 72 * @see Record#write(uint8_t*)
giovannivisentini 9:689c1f56f359 73 */
giovannivisentini 0:04b82ae7aa43 74 virtual uint16_t write(uint8_t *buffer);
giovannivisentini 1:a0eeb478a45a 75
giovannivisentini 10:9f34b0cfefe4 76 /**
giovannivisentini 10:9f34b0cfefe4 77 * get the record type
giovannivisentini 10:9f34b0cfefe4 78 * @return TYPE_AAR
giovannivisentini 10:9f34b0cfefe4 79 */
giovannivisentini 4:eaf6c49a86e4 80 virtual RecordType_t getType() const {
giovannivisentini 1:a0eeb478a45a 81 return TYPE_AAR;
giovannivisentini 4:eaf6c49a86e4 82 } //getType
giovannivisentini 1:a0eeb478a45a 83
giovannivisentini 4:eaf6c49a86e4 84 /**
giovannivisentini 4:eaf6c49a86e4 85 * @return get the package inside this record
giovannivisentini 4:eaf6c49a86e4 86 */
giovannivisentini 4:eaf6c49a86e4 87 const std::string& getPackage() const {
giovannivisentini 1:a0eeb478a45a 88 return mPackageName;
giovannivisentini 1:a0eeb478a45a 89 }
giovannivisentini 1:a0eeb478a45a 90
giovannivisentini 4:eaf6c49a86e4 91 /**
giovannivisentini 4:eaf6c49a86e4 92 * change the package name of this record
giovannivisentini 4:eaf6c49a86e4 93 * @param package
giovannivisentini 4:eaf6c49a86e4 94 */
giovannivisentini 4:eaf6c49a86e4 95 void setPackage(const std::string& package){
giovannivisentini 4:eaf6c49a86e4 96 mPackageName=package;
giovannivisentini 7:1ebd6049fa57 97 mRecordHeader.setPayloadLength(mPackageName.size());
giovannivisentini 4:eaf6c49a86e4 98 }
giovannivisentini 4:eaf6c49a86e4 99
giovannivisentini 9:689c1f56f359 100 virtual ~RecordAAR() { };
giovannivisentini 0:04b82ae7aa43 101
giovannivisentini 9:689c1f56f359 102 /**
giovannivisentini 9:689c1f56f359 103 * compare two object,
giovannivisentini 9:689c1f56f359 104 * @return true if the records have the same package name
giovannivisentini 9:689c1f56f359 105 */
giovannivisentini 7:1ebd6049fa57 106 bool operator==(const RecordAAR &other) const{
giovannivisentini 7:1ebd6049fa57 107 return (mPackageName==other.mPackageName);
giovannivisentini 7:1ebd6049fa57 108 }
giovannivisentini 7:1ebd6049fa57 109
giovannivisentini 0:04b82ae7aa43 110 private:
giovannivisentini 9:689c1f56f359 111 /**
giovannivisentini 9:689c1f56f359 112 * application to start
giovannivisentini 9:689c1f56f359 113 */
giovannivisentini 4:eaf6c49a86e4 114 std::string mPackageName;
giovannivisentini 0:04b82ae7aa43 115
giovannivisentini 4:eaf6c49a86e4 116 /**
giovannivisentini 4:eaf6c49a86e4 117 * string to use as record type for this record
giovannivisentini 4:eaf6c49a86e4 118 */
giovannivisentini 1:a0eeb478a45a 119 static const char sRecordType[];
giovannivisentini 0:04b82ae7aa43 120 };
giovannivisentini 0:04b82ae7aa43 121
giovannivisentini 0:04b82ae7aa43 122 } /* namespace NDefLib */
giovannivisentini 0:04b82ae7aa43 123
giovannivisentini 0:04b82ae7aa43 124 #endif /* NDEFLIB_RECORDTYPE_RECORDAAR_H_ */