iot_water_monitor_v2

Dependencies:   easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code

Committer:
DuyLionTran
Date:
Tue Apr 03 17:03:01 2018 +0000
Revision:
57:898fcb6692cd
Parent:
11:3802c82a5ae9
;   * version 2.9.8  	03-04-2018  Minor changes. Time frame updated to IBM Watson every 60s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DuyLionTran 11:3802c82a5ae9 1 /**
DuyLionTran 11:3802c82a5ae9 2 ******************************************************************************
DuyLionTran 11:3802c82a5ae9 3 * @file Message.h
DuyLionTran 11:3802c82a5ae9 4 * @author ST / Central Labs
DuyLionTran 11:3802c82a5ae9 5 * @version V2.0.0
DuyLionTran 11:3802c82a5ae9 6 * @date 28 Apr 2017
DuyLionTran 11:3802c82a5ae9 7 * @brief NDef Message class
DuyLionTran 11:3802c82a5ae9 8 ******************************************************************************
DuyLionTran 11:3802c82a5ae9 9 * @attention
DuyLionTran 11:3802c82a5ae9 10 *
DuyLionTran 11:3802c82a5ae9 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
DuyLionTran 11:3802c82a5ae9 12 *
DuyLionTran 11:3802c82a5ae9 13 * Redistribution and use in source and binary forms, with or without modification,
DuyLionTran 11:3802c82a5ae9 14 * are permitted provided that the following conditions are met:
DuyLionTran 11:3802c82a5ae9 15 * 1. Redistributions of source code must retain the above copyright notice,
DuyLionTran 11:3802c82a5ae9 16 * this list of conditions and the following disclaimer.
DuyLionTran 11:3802c82a5ae9 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
DuyLionTran 11:3802c82a5ae9 18 * this list of conditions and the following disclaimer in the documentation
DuyLionTran 11:3802c82a5ae9 19 * and/or other materials provided with the distribution.
DuyLionTran 11:3802c82a5ae9 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
DuyLionTran 11:3802c82a5ae9 21 * may be used to endorse or promote products derived from this software
DuyLionTran 11:3802c82a5ae9 22 * without specific prior written permission.
DuyLionTran 11:3802c82a5ae9 23 *
DuyLionTran 11:3802c82a5ae9 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
DuyLionTran 11:3802c82a5ae9 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
DuyLionTran 11:3802c82a5ae9 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DuyLionTran 11:3802c82a5ae9 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
DuyLionTran 11:3802c82a5ae9 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DuyLionTran 11:3802c82a5ae9 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
DuyLionTran 11:3802c82a5ae9 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
DuyLionTran 11:3802c82a5ae9 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
DuyLionTran 11:3802c82a5ae9 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
DuyLionTran 11:3802c82a5ae9 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DuyLionTran 11:3802c82a5ae9 34 *
DuyLionTran 11:3802c82a5ae9 35 ******************************************************************************
DuyLionTran 11:3802c82a5ae9 36 */
DuyLionTran 11:3802c82a5ae9 37
DuyLionTran 11:3802c82a5ae9 38 #ifndef NDEFLIB_MESSAGE_H_
DuyLionTran 11:3802c82a5ae9 39 #define NDEFLIB_MESSAGE_H_
DuyLionTran 11:3802c82a5ae9 40
DuyLionTran 11:3802c82a5ae9 41 #include <algorithm>
DuyLionTran 11:3802c82a5ae9 42 #include <vector>
DuyLionTran 11:3802c82a5ae9 43
DuyLionTran 11:3802c82a5ae9 44 #include "Record.h"
DuyLionTran 11:3802c82a5ae9 45
DuyLionTran 11:3802c82a5ae9 46 namespace NDefLib {
DuyLionTran 11:3802c82a5ae9 47
DuyLionTran 11:3802c82a5ae9 48 /**
DuyLionTran 11:3802c82a5ae9 49 * Class containing a list of {@link Record}
DuyLionTran 11:3802c82a5ae9 50 */
DuyLionTran 11:3802c82a5ae9 51 class Message {
DuyLionTran 11:3802c82a5ae9 52 public:
DuyLionTran 11:3802c82a5ae9 53
DuyLionTran 11:3802c82a5ae9 54 /**
DuyLionTran 11:3802c82a5ae9 55 * Add a ndef record to this message.
DuyLionTran 11:3802c82a5ae9 56 * @param r Record to add
DuyLionTran 11:3802c82a5ae9 57 */
DuyLionTran 11:3802c82a5ae9 58 void add_record(Record *r) {
DuyLionTran 11:3802c82a5ae9 59 mRecords.push_back(r);
DuyLionTran 11:3802c82a5ae9 60 }
DuyLionTran 11:3802c82a5ae9 61
DuyLionTran 11:3802c82a5ae9 62 /**
DuyLionTran 11:3802c82a5ae9 63 * Remove a ndef record to this message
DuyLionTran 11:3802c82a5ae9 64 * @param r record to remove
DuyLionTran 11:3802c82a5ae9 65 */
DuyLionTran 11:3802c82a5ae9 66 void remove_record(Record *r){
DuyLionTran 11:3802c82a5ae9 67 mRecords.erase( std::remove( mRecords.begin(), mRecords.end(), r ), mRecords.end() );
DuyLionTran 11:3802c82a5ae9 68 }
DuyLionTran 11:3802c82a5ae9 69
DuyLionTran 11:3802c82a5ae9 70
DuyLionTran 11:3802c82a5ae9 71 /**
DuyLionTran 11:3802c82a5ae9 72 * Add all the records in the list to this message.
DuyLionTran 11:3802c82a5ae9 73 * @param addList List of records to add.
DuyLionTran 11:3802c82a5ae9 74 */
DuyLionTran 11:3802c82a5ae9 75 void add_records(const std::vector<Record*> &addList) {
DuyLionTran 11:3802c82a5ae9 76 mRecords.insert(mRecords.end(), addList.begin(), addList.end());
DuyLionTran 11:3802c82a5ae9 77 }
DuyLionTran 11:3802c82a5ae9 78
DuyLionTran 11:3802c82a5ae9 79 /**
DuyLionTran 11:3802c82a5ae9 80 * Get the specific record contained by this message, NULL if not a valid index.
DuyLionTran 11:3802c82a5ae9 81 * @param index Record index.
DuyLionTran 11:3802c82a5ae9 82 * @return a Record object if present, otherwise NULL
DuyLionTran 11:3802c82a5ae9 83 */
DuyLionTran 11:3802c82a5ae9 84 Record* operator[](const uint32_t index)const{
DuyLionTran 11:3802c82a5ae9 85 if (index >= mRecords.size()) {
DuyLionTran 11:3802c82a5ae9 86 return NULL;
DuyLionTran 11:3802c82a5ae9 87 }
DuyLionTran 11:3802c82a5ae9 88
DuyLionTran 11:3802c82a5ae9 89 return mRecords[index];
DuyLionTran 11:3802c82a5ae9 90 }
DuyLionTran 11:3802c82a5ae9 91
DuyLionTran 11:3802c82a5ae9 92 /**
DuyLionTran 11:3802c82a5ae9 93 * Get the number of records in this message.
DuyLionTran 11:3802c82a5ae9 94 * @return number of records in this message
DuyLionTran 11:3802c82a5ae9 95 */
DuyLionTran 11:3802c82a5ae9 96 uint32_t get_N_records() const {
DuyLionTran 11:3802c82a5ae9 97 return mRecords.size();
DuyLionTran 11:3802c82a5ae9 98 }
DuyLionTran 11:3802c82a5ae9 99
DuyLionTran 11:3802c82a5ae9 100 /**
DuyLionTran 11:3802c82a5ae9 101 * Length in bytes needed to write this message.
DuyLionTran 11:3802c82a5ae9 102 * @return number of bytes needed to write this message
DuyLionTran 11:3802c82a5ae9 103 */
DuyLionTran 11:3802c82a5ae9 104 uint16_t get_byte_length() const;
DuyLionTran 11:3802c82a5ae9 105
DuyLionTran 11:3802c82a5ae9 106 /**
DuyLionTran 11:3802c82a5ae9 107 * Write message in the provided buffer
DuyLionTran 11:3802c82a5ae9 108 * @par The first 2 bytes contain the NDEF message length.
DuyLionTran 11:3802c82a5ae9 109 * @param[out] buffer Buffer the message must be written into.
DuyLionTran 11:3802c82a5ae9 110 * @return number of bytes written
DuyLionTran 11:3802c82a5ae9 111 */
DuyLionTran 11:3802c82a5ae9 112 uint16_t write(uint8_t *buffer) const;
DuyLionTran 11:3802c82a5ae9 113
DuyLionTran 11:3802c82a5ae9 114 /**
DuyLionTran 11:3802c82a5ae9 115 * Create a set of records from a raw buffer adding them to a message object.
DuyLionTran 11:3802c82a5ae9 116 * @par Message buffer must NOT contain the buffer length in the first two bytes.
DuyLionTran 11:3802c82a5ae9 117 * @param buffer Buffer containing the message record.
DuyLionTran 11:3802c82a5ae9 118 * @param bufferLength Buffer length.
DuyLionTran 11:3802c82a5ae9 119 * @param[in,out] Message message that will contain the new records.
DuyLionTran 11:3802c82a5ae9 120 */
DuyLionTran 11:3802c82a5ae9 121 static void parse_message(const uint8_t * const buffer,
DuyLionTran 11:3802c82a5ae9 122 const uint16_t bufferLength, Message *message);
DuyLionTran 11:3802c82a5ae9 123
DuyLionTran 11:3802c82a5ae9 124 /**
DuyLionTran 11:3802c82a5ae9 125 * Remove all the recrods from the mesasge and delete it
DuyLionTran 11:3802c82a5ae9 126 * @param msg Message with the records to delete
DuyLionTran 11:3802c82a5ae9 127 */
DuyLionTran 11:3802c82a5ae9 128 static void remove_and_delete_all_record(Message &msg);
DuyLionTran 11:3802c82a5ae9 129
DuyLionTran 11:3802c82a5ae9 130 virtual ~Message() {
DuyLionTran 11:3802c82a5ae9 131 }
DuyLionTran 11:3802c82a5ae9 132
DuyLionTran 11:3802c82a5ae9 133 private:
DuyLionTran 11:3802c82a5ae9 134 /**
DuyLionTran 11:3802c82a5ae9 135 * List of records contained by this message.
DuyLionTran 11:3802c82a5ae9 136 */
DuyLionTran 11:3802c82a5ae9 137 std::vector<Record*> mRecords;
DuyLionTran 11:3802c82a5ae9 138 };
DuyLionTran 11:3802c82a5ae9 139
DuyLionTran 11:3802c82a5ae9 140 } /* namespace NDefLib */
DuyLionTran 11:3802c82a5ae9 141
DuyLionTran 11:3802c82a5ae9 142 #endif /* NDEFLIB_MESSAGE_H_ */