iot_water_monitor_v2
Dependencies: easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code
Message.h
00001 /** 00002 ****************************************************************************** 00003 * @file Message.h 00004 * @author ST / Central Labs 00005 * @version V2.0.0 00006 * @date 28 Apr 2017 00007 * @brief NDef Message class 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 #ifndef NDEFLIB_MESSAGE_H_ 00039 #define NDEFLIB_MESSAGE_H_ 00040 00041 #include <algorithm> 00042 #include <vector> 00043 00044 #include "Record.h" 00045 00046 namespace NDefLib { 00047 00048 /** 00049 * Class containing a list of {@link Record} 00050 */ 00051 class Message { 00052 public: 00053 00054 /** 00055 * Add a ndef record to this message. 00056 * @param r Record to add 00057 */ 00058 void add_record(Record *r) { 00059 mRecords.push_back(r); 00060 } 00061 00062 /** 00063 * Remove a ndef record to this message 00064 * @param r record to remove 00065 */ 00066 void remove_record(Record *r){ 00067 mRecords.erase( std::remove( mRecords.begin(), mRecords.end(), r ), mRecords.end() ); 00068 } 00069 00070 00071 /** 00072 * Add all the records in the list to this message. 00073 * @param addList List of records to add. 00074 */ 00075 void add_records(const std::vector<Record*> &addList) { 00076 mRecords.insert(mRecords.end(), addList.begin(), addList.end()); 00077 } 00078 00079 /** 00080 * Get the specific record contained by this message, NULL if not a valid index. 00081 * @param index Record index. 00082 * @return a Record object if present, otherwise NULL 00083 */ 00084 Record* operator[](const uint32_t index)const{ 00085 if (index >= mRecords.size()) { 00086 return NULL; 00087 } 00088 00089 return mRecords[index]; 00090 } 00091 00092 /** 00093 * Get the number of records in this message. 00094 * @return number of records in this message 00095 */ 00096 uint32_t get_N_records() const { 00097 return mRecords.size(); 00098 } 00099 00100 /** 00101 * Length in bytes needed to write this message. 00102 * @return number of bytes needed to write this message 00103 */ 00104 uint16_t get_byte_length() const; 00105 00106 /** 00107 * Write message in the provided buffer 00108 * @par The first 2 bytes contain the NDEF message length. 00109 * @param[out] buffer Buffer the message must be written into. 00110 * @return number of bytes written 00111 */ 00112 uint16_t write(uint8_t *buffer) const; 00113 00114 /** 00115 * Create a set of records from a raw buffer adding them to a message object. 00116 * @par Message buffer must NOT contain the buffer length in the first two bytes. 00117 * @param buffer Buffer containing the message record. 00118 * @param bufferLength Buffer length. 00119 * @param[in,out] Message message that will contain the new records. 00120 */ 00121 static void parse_message(const uint8_t * const buffer, 00122 const uint16_t bufferLength, Message *message); 00123 00124 /** 00125 * Remove all the recrods from the mesasge and delete it 00126 * @param msg Message with the records to delete 00127 */ 00128 static void remove_and_delete_all_record(Message &msg); 00129 00130 virtual ~Message() { 00131 } 00132 00133 private: 00134 /** 00135 * List of records contained by this message. 00136 */ 00137 std::vector<Record*> mRecords; 00138 }; 00139 00140 } /* namespace NDefLib */ 00141 00142 #endif /* NDEFLIB_MESSAGE_H_ */
Generated on Tue Jul 12 2022 20:06:04 by 1.7.2