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
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.
RecordType/RecordMail.h@21:72c86cbd49be, 2017-08-21 (annotated)
- Committer:
- giovannivisentini
- Date:
- Mon Aug 21 12:02:31 2017 +0000
- Revision:
- 21:72c86cbd49be
- Parent:
- 19:13d84b136a62
change on_message_write callback; the message parameter was unused and it pointed to an invalid object
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 RecordMail.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 Class that specializes the {@link RecordUri} to store a mail content. |
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 | 1:a0eeb478a45a | 37 | #ifndef NDEFLIB_RECORDTYPE_RECORDMAIL_H_s |
giovannivisentini | 0:04b82ae7aa43 | 38 | #define NDEFLIB_RECORDTYPE_RECORDMAIL_H_ |
giovannivisentini | 0:04b82ae7aa43 | 39 | |
giovannivisentini | 1:a0eeb478a45a | 40 | #include "RecordURI.h" |
giovannivisentini | 0:04b82ae7aa43 | 41 | |
giovannivisentini | 0:04b82ae7aa43 | 42 | namespace NDefLib { |
giovannivisentini | 0:04b82ae7aa43 | 43 | |
giovannivisentini | 4:eaf6c49a86e4 | 44 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 45 | * Class that specializes the {@link RecordUri} to store a mail content. |
giovannivisentini | 4:eaf6c49a86e4 | 46 | */ |
giovannivisentini | 1:a0eeb478a45a | 47 | class RecordMail: public RecordURI { |
giovannivisentini | 1:a0eeb478a45a | 48 | |
giovannivisentini | 0:04b82ae7aa43 | 49 | public: |
giovannivisentini | 4:eaf6c49a86e4 | 50 | |
giovannivisentini | 4:eaf6c49a86e4 | 51 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 52 | * Create a RecordMail reading the data from the buffer. |
giovannivisentini | 12:ed4d9b8d1410 | 53 | * @param header Record header. |
giovannivisentini | 12:ed4d9b8d1410 | 54 | * @param buffer Buffer to read the data from. |
giovannivisentini | 4:eaf6c49a86e4 | 55 | * @return an object of type RecordMail or NULL |
giovannivisentini | 12:ed4d9b8d1410 | 56 | * @par User is in charge of freeing the pointer returned by this function. |
giovannivisentini | 4:eaf6c49a86e4 | 57 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 58 | static RecordMail* parse(const RecordHeader &header, |
giovannivisentini | 4:eaf6c49a86e4 | 59 | const uint8_t* buffer); |
giovannivisentini | 1:a0eeb478a45a | 60 | |
giovannivisentini | 4:eaf6c49a86e4 | 61 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 62 | * Create a mail. |
giovannivisentini | 12:ed4d9b8d1410 | 63 | * @param toAddress Mail recipient. |
giovannivisentini | 12:ed4d9b8d1410 | 64 | * @param subject Mail subject. |
giovannivisentini | 12:ed4d9b8d1410 | 65 | * @param msg Message. |
giovannivisentini | 4:eaf6c49a86e4 | 66 | */ |
giovannivisentini | 7:1ebd6049fa57 | 67 | RecordMail(const std::string &toAddress, const std::string &subject, |
giovannivisentini | 4:eaf6c49a86e4 | 68 | const std::string &msg) : |
giovannivisentini | 4:eaf6c49a86e4 | 69 | RecordURI(RecordURI::MAIL), mToAddress(toAddress), mSubject( |
giovannivisentini | 4:eaf6c49a86e4 | 70 | subject), mBody(msg),mContentIsChange(true) { } ; |
giovannivisentini | 0:04b82ae7aa43 | 71 | |
giovannivisentini | 4:eaf6c49a86e4 | 72 | virtual ~RecordMail() { }; |
giovannivisentini | 4:eaf6c49a86e4 | 73 | |
giovannivisentini | 9:689c1f56f359 | 74 | /** |
giovannivisentini | 9:689c1f56f359 | 75 | * @return the mail recipient address |
giovannivisentini | 9:689c1f56f359 | 76 | */ |
giovannivisentini | 19:13d84b136a62 | 77 | const std::string& get_to_address() const { |
giovannivisentini | 4:eaf6c49a86e4 | 78 | return mToAddress; |
giovannivisentini | 1:a0eeb478a45a | 79 | } |
giovannivisentini | 1:a0eeb478a45a | 80 | |
giovannivisentini | 9:689c1f56f359 | 81 | /** |
giovannivisentini | 9:689c1f56f359 | 82 | * @return the mail subject |
giovannivisentini | 9:689c1f56f359 | 83 | */ |
giovannivisentini | 19:13d84b136a62 | 84 | const std::string& get_subject() const { |
giovannivisentini | 1:a0eeb478a45a | 85 | return mSubject; |
giovannivisentini | 1:a0eeb478a45a | 86 | } |
giovannivisentini | 1:a0eeb478a45a | 87 | |
giovannivisentini | 9:689c1f56f359 | 88 | /** |
giovannivisentini | 9:689c1f56f359 | 89 | * @return the mail body |
giovannivisentini | 9:689c1f56f359 | 90 | */ |
giovannivisentini | 19:13d84b136a62 | 91 | const std::string& get_body() const { |
giovannivisentini | 1:a0eeb478a45a | 92 | return mBody; |
giovannivisentini | 1:a0eeb478a45a | 93 | } |
giovannivisentini | 1:a0eeb478a45a | 94 | |
giovannivisentini | 9:689c1f56f359 | 95 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 96 | * Change the mail recipient. |
giovannivisentini | 12:ed4d9b8d1410 | 97 | * @param dest Recipient address. |
giovannivisentini | 12:ed4d9b8d1410 | 98 | * @par The string is copied inside the class. |
giovannivisentini | 9:689c1f56f359 | 99 | */ |
giovannivisentini | 19:13d84b136a62 | 100 | void set_to_address(const std::string& dest){ |
giovannivisentini | 4:eaf6c49a86e4 | 101 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 102 | mToAddress=dest; |
giovannivisentini | 4:eaf6c49a86e4 | 103 | } |
giovannivisentini | 4:eaf6c49a86e4 | 104 | |
giovannivisentini | 9:689c1f56f359 | 105 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 106 | * Change the mail subject. |
giovannivisentini | 12:ed4d9b8d1410 | 107 | * @param subj New mail subject. |
giovannivisentini | 12:ed4d9b8d1410 | 108 | * @par The string is copied inside the class. |
giovannivisentini | 9:689c1f56f359 | 109 | */ |
giovannivisentini | 19:13d84b136a62 | 110 | void set_subject(const std::string& subj) { |
giovannivisentini | 4:eaf6c49a86e4 | 111 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 112 | mSubject=subj; |
giovannivisentini | 4:eaf6c49a86e4 | 113 | } |
giovannivisentini | 4:eaf6c49a86e4 | 114 | |
giovannivisentini | 9:689c1f56f359 | 115 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 116 | * Change the mail body. |
giovannivisentini | 12:ed4d9b8d1410 | 117 | * @param body New mail body. |
giovannivisentini | 12:ed4d9b8d1410 | 118 | * @par The string is copied inside the class. |
giovannivisentini | 9:689c1f56f359 | 119 | */ |
giovannivisentini | 19:13d84b136a62 | 120 | void set_body(const std::string& body) { |
giovannivisentini | 4:eaf6c49a86e4 | 121 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 122 | mBody=body; |
giovannivisentini | 4:eaf6c49a86e4 | 123 | } |
giovannivisentini | 4:eaf6c49a86e4 | 124 | |
giovannivisentini | 9:689c1f56f359 | 125 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 126 | * Get the record type. |
giovannivisentini | 9:689c1f56f359 | 127 | * @return TYPE_URI_MAIL |
giovannivisentini | 9:689c1f56f359 | 128 | */ |
giovannivisentini | 19:13d84b136a62 | 129 | virtual RecordType_t get_type() const { |
giovannivisentini | 1:a0eeb478a45a | 130 | return TYPE_URI_MAIL; |
giovannivisentini | 4:eaf6c49a86e4 | 131 | } //getType |
giovannivisentini | 4:eaf6c49a86e4 | 132 | |
giovannivisentini | 9:689c1f56f359 | 133 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 134 | * Compare 2 RecordMails. |
giovannivisentini | 19:13d84b136a62 | 135 | *Â @return true if both the tags have the same addresses,subjects and bodies |
giovannivisentini | 9:689c1f56f359 | 136 | */ |
giovannivisentini | 7:1ebd6049fa57 | 137 | bool operator==(const RecordMail& other)const{ |
giovannivisentini | 7:1ebd6049fa57 | 138 | return mToAddress == other.mToAddress && |
giovannivisentini | 7:1ebd6049fa57 | 139 | mSubject == other.mSubject && |
giovannivisentini | 7:1ebd6049fa57 | 140 | mBody == other.mBody; |
giovannivisentini | 7:1ebd6049fa57 | 141 | } |
giovannivisentini | 7:1ebd6049fa57 | 142 | |
giovannivisentini | 4:eaf6c49a86e4 | 143 | protected: |
giovannivisentini | 9:689c1f56f359 | 144 | |
giovannivisentini | 9:689c1f56f359 | 145 | /** |
giovannivisentini | 12:ed4d9b8d1410 | 146 | * Generate the uri content that encodes the mail content. |
giovannivisentini | 9:689c1f56f359 | 147 | * @see RecordUri#updateContent |
giovannivisentini | 9:689c1f56f359 | 148 | */ |
giovannivisentini | 19:13d84b136a62 | 149 | virtual void update_content(); |
giovannivisentini | 4:eaf6c49a86e4 | 150 | |
giovannivisentini | 0:04b82ae7aa43 | 151 | private: |
giovannivisentini | 0:04b82ae7aa43 | 152 | |
giovannivisentini | 12:ed4d9b8d1410 | 153 | std::string mToAddress; ///< Mail address. |
giovannivisentini | 12:ed4d9b8d1410 | 154 | std::string mSubject; ///< Mail subject. |
giovannivisentini | 12:ed4d9b8d1410 | 155 | std::string mBody; ///< Mail body. |
giovannivisentini | 12:ed4d9b8d1410 | 156 | bool mContentIsChange; ///< True if the use update some mail field. |
giovannivisentini | 1:a0eeb478a45a | 157 | |
giovannivisentini | 12:ed4d9b8d1410 | 158 | static const std::string sSubjectTag; ///< String to use bofore the subject. |
giovannivisentini | 12:ed4d9b8d1410 | 159 | static const std::string sBodyTag; ///< String to use before the mail body. |
giovannivisentini | 0:04b82ae7aa43 | 160 | }; |
giovannivisentini | 0:04b82ae7aa43 | 161 | |
giovannivisentini | 0:04b82ae7aa43 | 162 | } /* namespace NDefLib */ |
giovannivisentini | 0:04b82ae7aa43 | 163 | |
giovannivisentini | 0:04b82ae7aa43 | 164 | #endif /* NDEFLIB_RECORDTYPE_RECORDMAIL_H_ */ |