CUSTOMIZED FOR WATER MONITOR

Committer:
DuyLionTran
Date:
Thu Dec 07 17:07:22 2017 +0000
Revision:
0:51d7bdf88981
CUSTOMIZED FOR WATER MONITOR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DuyLionTran 0:51d7bdf88981 1 /**
DuyLionTran 0:51d7bdf88981 2 ******************************************************************************
DuyLionTran 0:51d7bdf88981 3 * @file RecordGEO.h
DuyLionTran 0:51d7bdf88981 4 * @author ST / Central Labs
DuyLionTran 0:51d7bdf88981 5 * @version V2.0.0
DuyLionTran 0:51d7bdf88981 6 * @date 28 Apr 2017
DuyLionTran 0:51d7bdf88981 7 * @brief Specialize the @{link RecordURI} to handle a location position, the location
DuyLionTran 0:51d7bdf88981 8 * is stored with latitude and longitude.
DuyLionTran 0:51d7bdf88981 9 ******************************************************************************
DuyLionTran 0:51d7bdf88981 10 * @attention
DuyLionTran 0:51d7bdf88981 11 *
DuyLionTran 0:51d7bdf88981 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
DuyLionTran 0:51d7bdf88981 13 *
DuyLionTran 0:51d7bdf88981 14 * Redistribution and use in source and binary forms, with or without modification,
DuyLionTran 0:51d7bdf88981 15 * are permitted provided that the following conditions are met:
DuyLionTran 0:51d7bdf88981 16 * 1. Redistributions of source code must retain the above copyright notice,
DuyLionTran 0:51d7bdf88981 17 * this list of conditions and the following disclaimer.
DuyLionTran 0:51d7bdf88981 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
DuyLionTran 0:51d7bdf88981 19 * this list of conditions and the following disclaimer in the documentation
DuyLionTran 0:51d7bdf88981 20 * and/or other materials provided with the distribution.
DuyLionTran 0:51d7bdf88981 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
DuyLionTran 0:51d7bdf88981 22 * may be used to endorse or promote products derived from this software
DuyLionTran 0:51d7bdf88981 23 * without specific prior written permission.
DuyLionTran 0:51d7bdf88981 24 *
DuyLionTran 0:51d7bdf88981 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
DuyLionTran 0:51d7bdf88981 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
DuyLionTran 0:51d7bdf88981 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DuyLionTran 0:51d7bdf88981 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
DuyLionTran 0:51d7bdf88981 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DuyLionTran 0:51d7bdf88981 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
DuyLionTran 0:51d7bdf88981 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
DuyLionTran 0:51d7bdf88981 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
DuyLionTran 0:51d7bdf88981 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
DuyLionTran 0:51d7bdf88981 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DuyLionTran 0:51d7bdf88981 35 *
DuyLionTran 0:51d7bdf88981 36 ******************************************************************************
DuyLionTran 0:51d7bdf88981 37 */
DuyLionTran 0:51d7bdf88981 38
DuyLionTran 0:51d7bdf88981 39 #ifndef NDEFLIB_RECORDTYPE_RECORDGEO_H_
DuyLionTran 0:51d7bdf88981 40 #define NDEFLIB_RECORDTYPE_RECORDGEO_H_
DuyLionTran 0:51d7bdf88981 41
DuyLionTran 0:51d7bdf88981 42 #include "RecordURI.h"
DuyLionTran 0:51d7bdf88981 43
DuyLionTran 0:51d7bdf88981 44 namespace NDefLib {
DuyLionTran 0:51d7bdf88981 45
DuyLionTran 0:51d7bdf88981 46 /**
DuyLionTran 0:51d7bdf88981 47 * Specialize the {@link RecordUri} to handle a location position, the location
DuyLionTran 0:51d7bdf88981 48 * is stored with latitude and longitude.
DuyLionTran 0:51d7bdf88981 49 * @par The coordinates are floats with 4 decimal positions.
DuyLionTran 0:51d7bdf88981 50 */
DuyLionTran 0:51d7bdf88981 51 class RecordGeo: public RecordURI {
DuyLionTran 0:51d7bdf88981 52 public:
DuyLionTran 0:51d7bdf88981 53
DuyLionTran 0:51d7bdf88981 54 /**
DuyLionTran 0:51d7bdf88981 55 * Create an RecordGeo reading the data from the buffer.
DuyLionTran 0:51d7bdf88981 56 * @param header Record header.
DuyLionTran 0:51d7bdf88981 57 * @param buffer Buffer to read the data from.
DuyLionTran 0:51d7bdf88981 58 * @return an object of type RecordGeo or NULL
DuyLionTran 0:51d7bdf88981 59 * @par User is in charge of freeing the pointer returned by this function.
DuyLionTran 0:51d7bdf88981 60 */
DuyLionTran 0:51d7bdf88981 61 static RecordGeo* parse(const RecordHeader &header,
DuyLionTran 0:51d7bdf88981 62 const uint8_t * const buffer);
DuyLionTran 0:51d7bdf88981 63
DuyLionTran 0:51d7bdf88981 64
DuyLionTran 0:51d7bdf88981 65 /**
DuyLionTran 0:51d7bdf88981 66 * Create a record that contains a gps coordinate.
DuyLionTran 0:51d7bdf88981 67 * @param lat Latitude.
DuyLionTran 0:51d7bdf88981 68 * @param lon Longitude.
DuyLionTran 0:51d7bdf88981 69 */
DuyLionTran 0:51d7bdf88981 70 RecordGeo(const float lat, const float lon);
DuyLionTran 0:51d7bdf88981 71
DuyLionTran 0:51d7bdf88981 72 virtual ~RecordGeo() { };
DuyLionTran 0:51d7bdf88981 73
DuyLionTran 0:51d7bdf88981 74 /**
DuyLionTran 0:51d7bdf88981 75 * Return the longitude coordinate
DuyLionTran 0:51d7bdf88981 76 * @return the longitude coordinate
DuyLionTran 0:51d7bdf88981 77 */
DuyLionTran 0:51d7bdf88981 78 float get_longitude()const {
DuyLionTran 0:51d7bdf88981 79 return mLongitude;
DuyLionTran 0:51d7bdf88981 80 }
DuyLionTran 0:51d7bdf88981 81
DuyLionTran 0:51d7bdf88981 82 /**
DuyLionTran 0:51d7bdf88981 83 * Return the latitude coordinate
DuyLionTran 0:51d7bdf88981 84 * @return the latitude coordinate
DuyLionTran 0:51d7bdf88981 85 */
DuyLionTran 0:51d7bdf88981 86 float get_latitude()const {
DuyLionTran 0:51d7bdf88981 87 return mLatitiude;
DuyLionTran 0:51d7bdf88981 88 }
DuyLionTran 0:51d7bdf88981 89
DuyLionTran 0:51d7bdf88981 90 /**
DuyLionTran 0:51d7bdf88981 91 * Change the latitude coordinate.
DuyLionTran 0:51d7bdf88981 92 * @param lat new latitude.
DuyLionTran 0:51d7bdf88981 93 */
DuyLionTran 0:51d7bdf88981 94 void set_latitude(const float lat){
DuyLionTran 0:51d7bdf88981 95 mContentIsChange=true;
DuyLionTran 0:51d7bdf88981 96 mLatitiude=lat;
DuyLionTran 0:51d7bdf88981 97 }
DuyLionTran 0:51d7bdf88981 98
DuyLionTran 0:51d7bdf88981 99 /**
DuyLionTran 0:51d7bdf88981 100 * Change the longitude coordinate.
DuyLionTran 0:51d7bdf88981 101 * @param lon new longitude
DuyLionTran 0:51d7bdf88981 102 */
DuyLionTran 0:51d7bdf88981 103 void set_longitude(const float lon){
DuyLionTran 0:51d7bdf88981 104 mContentIsChange=true;
DuyLionTran 0:51d7bdf88981 105 mLongitude=lon;
DuyLionTran 0:51d7bdf88981 106 }
DuyLionTran 0:51d7bdf88981 107
DuyLionTran 0:51d7bdf88981 108 /**
DuyLionTran 0:51d7bdf88981 109 * Get the record type.
DuyLionTran 0:51d7bdf88981 110 * @return TYPE_URI_GEOLOCATION
DuyLionTran 0:51d7bdf88981 111 */
DuyLionTran 0:51d7bdf88981 112 virtual RecordType_t get_type() const {
DuyLionTran 0:51d7bdf88981 113 return TYPE_URI_GEOLOCATION;
DuyLionTran 0:51d7bdf88981 114 } //getType
DuyLionTran 0:51d7bdf88981 115
DuyLionTran 0:51d7bdf88981 116 /**
DuyLionTran 0:51d7bdf88981 117 * Compare two RecordGeo tags.
DuyLionTran 0:51d7bdf88981 118 * @return true if the two tags have the same latitude and longitude
DuyLionTran 0:51d7bdf88981 119 */
DuyLionTran 0:51d7bdf88981 120 bool operator==(const RecordGeo &other) const {
DuyLionTran 0:51d7bdf88981 121 return (mLatitiude == other.mLatitiude) &&
DuyLionTran 0:51d7bdf88981 122 (mLongitude == other.mLongitude) ;
DuyLionTran 0:51d7bdf88981 123 }
DuyLionTran 0:51d7bdf88981 124
DuyLionTran 0:51d7bdf88981 125 protected:
DuyLionTran 0:51d7bdf88981 126
DuyLionTran 0:51d7bdf88981 127 /**
DuyLionTran 0:51d7bdf88981 128 * This function updates the uri message to write into the tag.
DuyLionTran 0:51d7bdf88981 129 */
DuyLionTran 0:51d7bdf88981 130 virtual void update_content();
DuyLionTran 0:51d7bdf88981 131
DuyLionTran 0:51d7bdf88981 132 private:
DuyLionTran 0:51d7bdf88981 133
DuyLionTran 0:51d7bdf88981 134 /**
DuyLionTran 0:51d7bdf88981 135 * Latitude information.
DuyLionTran 0:51d7bdf88981 136 */
DuyLionTran 0:51d7bdf88981 137 float mLatitiude;
DuyLionTran 0:51d7bdf88981 138
DuyLionTran 0:51d7bdf88981 139 /**
DuyLionTran 0:51d7bdf88981 140 * Longitude information.
DuyLionTran 0:51d7bdf88981 141 */
DuyLionTran 0:51d7bdf88981 142 float mLongitude;
DuyLionTran 0:51d7bdf88981 143
DuyLionTran 0:51d7bdf88981 144 /**
DuyLionTran 0:51d7bdf88981 145 * True if the user has updated the latitude or longitude.
DuyLionTran 0:51d7bdf88981 146 */
DuyLionTran 0:51d7bdf88981 147 bool mContentIsChange;
DuyLionTran 0:51d7bdf88981 148
DuyLionTran 0:51d7bdf88981 149 /**
DuyLionTran 0:51d7bdf88981 150 * Uri type to use for this record.
DuyLionTran 0:51d7bdf88981 151 */
DuyLionTran 0:51d7bdf88981 152 static const std::string sGeoTag;
DuyLionTran 0:51d7bdf88981 153 };
DuyLionTran 0:51d7bdf88981 154
DuyLionTran 0:51d7bdf88981 155 } /* namespace NDefLib */
DuyLionTran 0:51d7bdf88981 156
DuyLionTran 0:51d7bdf88981 157 #endif /* NDEFLIB_RECORDTYPE_RECORDGEO_H_ */