The Cayenne MQTT mbed Library provides functions to easily connect to the Cayenne IoT project builder.

Dependents:   Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more

Committer:
jburhenn
Date:
Wed Oct 26 16:33:46 2016 -0600
Revision:
8:aec9cfdd4c8e
Parent:
6:82e142a864ad
Child:
15:1f4d5dbf1928
Updated credential ordering to match dashboard. Added init function to set the credentials. Added setDefaultMessageHandler override so member functions can be used for message handling. Updated namesspace name to be more specific.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jburhenn 0:09ef59d2d0f7 1 /*
jburhenn 0:09ef59d2d0f7 2 The MIT License(MIT)
jburhenn 0:09ef59d2d0f7 3
jburhenn 0:09ef59d2d0f7 4 Cayenne MQTT Client Library
jburhenn 0:09ef59d2d0f7 5 Copyright (c) 2016 myDevices
jburhenn 0:09ef59d2d0f7 6
jburhenn 0:09ef59d2d0f7 7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
jburhenn 0:09ef59d2d0f7 8 documentation files(the "Software"), to deal in the Software without restriction, including without limitation
jburhenn 0:09ef59d2d0f7 9 the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software,
jburhenn 0:09ef59d2d0f7 10 and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
jburhenn 0:09ef59d2d0f7 11 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
jburhenn 0:09ef59d2d0f7 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
jburhenn 0:09ef59d2d0f7 13 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
jburhenn 0:09ef59d2d0f7 14 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
jburhenn 0:09ef59d2d0f7 15 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jburhenn 0:09ef59d2d0f7 16 */
jburhenn 0:09ef59d2d0f7 17
jburhenn 0:09ef59d2d0f7 18 #ifndef _CAYENNEDATAARRAY_h
jburhenn 0:09ef59d2d0f7 19 #define _CAYENNEDATAARRAY_h
jburhenn 0:09ef59d2d0f7 20
jburhenn 0:09ef59d2d0f7 21 #include "CayenneUtils.h"
jburhenn 0:09ef59d2d0f7 22
jburhenn 0:09ef59d2d0f7 23 #if defined(__cplusplus)
jburhenn 0:09ef59d2d0f7 24
jburhenn 0:09ef59d2d0f7 25 // C++ version of the data array. This is defined here so it requires no source file.
jburhenn 0:09ef59d2d0f7 26
jburhenn 8:aec9cfdd4c8e 27 namespace CayenneMQTT
jburhenn 0:09ef59d2d0f7 28 {
jburhenn 1:90dccf306268 29 /**
jburhenn 1:90dccf306268 30 * @class DataArray
jburhenn 1:90dccf306268 31 * Class for manipulating a data array of unit/value pairs.
jburhenn 1:90dccf306268 32 * @param BUFFER_SIZE Maximum buffer size to use for data array, in bytes.
jburhenn 1:90dccf306268 33 * @param MAX_VALUES Maximum number of unit/value pairs in the array.
jburhenn 1:90dccf306268 34 */
jburhenn 0:09ef59d2d0f7 35 template<int BUFFER_SIZE = CAYENNE_MAX_MESSAGE_SIZE, int MAX_VALUES = CAYENNE_MAX_MESSAGE_VALUES>
jburhenn 0:09ef59d2d0f7 36 class DataArray
jburhenn 0:09ef59d2d0f7 37 {
jburhenn 0:09ef59d2d0f7 38 public:
jburhenn 1:90dccf306268 39 /**
jburhenn 1:90dccf306268 40 * Construct an empty array.
jburhenn 1:90dccf306268 41 */
jburhenn 0:09ef59d2d0f7 42 DataArray() {
jburhenn 0:09ef59d2d0f7 43 clear();
jburhenn 0:09ef59d2d0f7 44 }
jburhenn 0:09ef59d2d0f7 45
jburhenn 1:90dccf306268 46 /**
jburhenn 1:90dccf306268 47 * Clear the array.
jburhenn 1:90dccf306268 48 */
jburhenn 0:09ef59d2d0f7 49 void clear() {
jburhenn 0:09ef59d2d0f7 50 for (int i = 0; i < CAYENNE_MAX_MESSAGE_VALUES; ++i) {
jburhenn 0:09ef59d2d0f7 51 _values[i].unit = NULL;
jburhenn 0:09ef59d2d0f7 52 _values[i].value = NULL;
jburhenn 0:09ef59d2d0f7 53 }
jburhenn 0:09ef59d2d0f7 54 _valueCount = 0;
jburhenn 0:09ef59d2d0f7 55 _index = 0;
jburhenn 0:09ef59d2d0f7 56 }
jburhenn 0:09ef59d2d0f7 57
jburhenn 1:90dccf306268 58 /**
jburhenn 1:90dccf306268 59 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 60 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 61 * @param[in] value The value to add.
jburhenn 1:90dccf306268 62 * @param[in] unitInFlash If true the unit string is in flash memory, otherwise false.
jburhenn 1:90dccf306268 63 * @param[in] valueInFlash If true the value string is in flash memory, otherwise false.
jburhenn 1:90dccf306268 64 */
jburhenn 0:09ef59d2d0f7 65 void add(const char* unit, const char* value, bool unitInFlash = false, bool valueInFlash = false) {
jburhenn 0:09ef59d2d0f7 66 if (_valueCount >= CAYENNE_MAX_MESSAGE_VALUES)
jburhenn 0:09ef59d2d0f7 67 return;
jburhenn 0:09ef59d2d0f7 68
jburhenn 0:09ef59d2d0f7 69 size_t unitLength = 0;
jburhenn 0:09ef59d2d0f7 70 if (unit) {
jburhenn 0:09ef59d2d0f7 71 unitLength = (unitInFlash ? CAYENNE_STRLEN(unit) : strlen(unit)) + 1;
jburhenn 0:09ef59d2d0f7 72 }
jburhenn 0:09ef59d2d0f7 73 size_t valueLength = 0;
jburhenn 0:09ef59d2d0f7 74 if (value) {
jburhenn 0:09ef59d2d0f7 75 valueLength = (valueInFlash ? CAYENNE_STRLEN(value) : strlen(value)) + 1;
jburhenn 0:09ef59d2d0f7 76 }
jburhenn 0:09ef59d2d0f7 77 if (_index + unitLength + valueLength > BUFFER_SIZE)
jburhenn 0:09ef59d2d0f7 78 return;
jburhenn 0:09ef59d2d0f7 79
jburhenn 0:09ef59d2d0f7 80 if (unit) {
jburhenn 0:09ef59d2d0f7 81 unitInFlash ? CAYENNE_MEMCPY(_buffer + _index, unit, unitLength) : memcpy(_buffer + _index, unit, unitLength);
jburhenn 0:09ef59d2d0f7 82 _values[_valueCount].unit = _buffer + _index;
jburhenn 0:09ef59d2d0f7 83 _index += unitLength;
jburhenn 0:09ef59d2d0f7 84 }
jburhenn 0:09ef59d2d0f7 85 else {
jburhenn 0:09ef59d2d0f7 86 _values[_valueCount].unit = NULL;
jburhenn 0:09ef59d2d0f7 87 }
jburhenn 0:09ef59d2d0f7 88
jburhenn 0:09ef59d2d0f7 89 if (value) {
jburhenn 0:09ef59d2d0f7 90 valueInFlash ? CAYENNE_MEMCPY(_buffer + _index, value, valueLength) : memcpy(_buffer + _index, value, valueLength);
jburhenn 0:09ef59d2d0f7 91 _values[_valueCount].value = _buffer + _index;
jburhenn 0:09ef59d2d0f7 92 _index += valueLength;
jburhenn 0:09ef59d2d0f7 93 }
jburhenn 0:09ef59d2d0f7 94 else {
jburhenn 0:09ef59d2d0f7 95 _values[_valueCount].value = NULL;
jburhenn 0:09ef59d2d0f7 96 }
jburhenn 0:09ef59d2d0f7 97
jburhenn 0:09ef59d2d0f7 98 _valueCount++;
jburhenn 0:09ef59d2d0f7 99 }
jburhenn 0:09ef59d2d0f7 100
jburhenn 1:90dccf306268 101 /**
jburhenn 1:90dccf306268 102 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 103 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 104 * @param[in] value The value to add.
jburhenn 1:90dccf306268 105 */
jburhenn 0:09ef59d2d0f7 106 inline void add(const char* unit, const int value) {
jburhenn 0:09ef59d2d0f7 107 char str[2 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 108 #if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
jburhenn 0:09ef59d2d0f7 109 itoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 110 #else
jburhenn 0:09ef59d2d0f7 111 snprintf(str, sizeof(str), "%d", value);
jburhenn 0:09ef59d2d0f7 112 #endif
jburhenn 0:09ef59d2d0f7 113 add(unit, str);
jburhenn 0:09ef59d2d0f7 114 }
jburhenn 0:09ef59d2d0f7 115
jburhenn 1:90dccf306268 116 /**
jburhenn 1:90dccf306268 117 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 118 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 119 * @param[in] value The value to add.
jburhenn 1:90dccf306268 120 */
jburhenn 0:09ef59d2d0f7 121 inline void add(const char* unit, const unsigned int value) {
jburhenn 0:09ef59d2d0f7 122 char str[1 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 123 #if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
jburhenn 0:09ef59d2d0f7 124 utoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 125 #else
jburhenn 0:09ef59d2d0f7 126 snprintf(str, sizeof(str), "%u", value);
jburhenn 0:09ef59d2d0f7 127 #endif
jburhenn 0:09ef59d2d0f7 128 add(unit, str);
jburhenn 0:09ef59d2d0f7 129 }
jburhenn 0:09ef59d2d0f7 130
jburhenn 1:90dccf306268 131 /**
jburhenn 1:90dccf306268 132 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 133 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 134 * @param[in] value The value to add.
jburhenn 1:90dccf306268 135 */
jburhenn 0:09ef59d2d0f7 136 inline void add(const char* unit, const long value) {
jburhenn 0:09ef59d2d0f7 137 char str[2 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 138 #if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
jburhenn 0:09ef59d2d0f7 139 ltoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 140 #else
jburhenn 0:09ef59d2d0f7 141 snprintf(str, sizeof(str), "%ld", value);
jburhenn 0:09ef59d2d0f7 142 #endif
jburhenn 0:09ef59d2d0f7 143 add(unit, str);
jburhenn 0:09ef59d2d0f7 144 }
jburhenn 0:09ef59d2d0f7 145
jburhenn 1:90dccf306268 146 /**
jburhenn 1:90dccf306268 147 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 148 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 149 * @param[in] value The value to add.
jburhenn 1:90dccf306268 150 */
jburhenn 0:09ef59d2d0f7 151 inline void add(const char* unit, const unsigned long value) {
jburhenn 0:09ef59d2d0f7 152 char str[1 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 153 #if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
jburhenn 0:09ef59d2d0f7 154 ultoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 155 #else
jburhenn 0:09ef59d2d0f7 156 snprintf(str, sizeof(str), "%lu", value);
jburhenn 0:09ef59d2d0f7 157 #endif
jburhenn 0:09ef59d2d0f7 158 add(unit, str);
jburhenn 0:09ef59d2d0f7 159 }
jburhenn 0:09ef59d2d0f7 160
jburhenn 0:09ef59d2d0f7 161 #if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
jburhenn 1:90dccf306268 162 /**
jburhenn 1:90dccf306268 163 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 164 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 165 * @param[in] value The value to add.
jburhenn 1:90dccf306268 166 */
jburhenn 0:09ef59d2d0f7 167 inline void add(const char* unit, const float value) {
jburhenn 0:09ef59d2d0f7 168 char str[33];
jburhenn 0:09ef59d2d0f7 169 dtostrf(value, 5, 3, str);
jburhenn 0:09ef59d2d0f7 170 add(unit, str);
jburhenn 0:09ef59d2d0f7 171 }
jburhenn 0:09ef59d2d0f7 172
jburhenn 1:90dccf306268 173 /**
jburhenn 1:90dccf306268 174 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 175 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 176 * @param[in] value The value to add.
jburhenn 1:90dccf306268 177 */
jburhenn 0:09ef59d2d0f7 178 inline void add(const char* unit, const double value) {
jburhenn 0:09ef59d2d0f7 179 char str[33];
jburhenn 0:09ef59d2d0f7 180 dtostrf(value, 5, 3, str);
jburhenn 0:09ef59d2d0f7 181 add(unit, str);
jburhenn 0:09ef59d2d0f7 182 }
jburhenn 0:09ef59d2d0f7 183
jburhenn 0:09ef59d2d0f7 184 #else
jburhenn 1:90dccf306268 185 /**
jburhenn 1:90dccf306268 186 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 187 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 188 * @param[in] value The value to add.
jburhenn 1:90dccf306268 189 */
jburhenn 0:09ef59d2d0f7 190 inline void add(const char* unit, const float value) {
jburhenn 0:09ef59d2d0f7 191 char str[33];
jburhenn 0:09ef59d2d0f7 192 snprintf(str, 33, "%2.3f", value);
jburhenn 0:09ef59d2d0f7 193 add(unit, str);
jburhenn 0:09ef59d2d0f7 194 }
jburhenn 0:09ef59d2d0f7 195
jburhenn 1:90dccf306268 196 /**
jburhenn 1:90dccf306268 197 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 198 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 199 * @param[in] value The value to add.
jburhenn 1:90dccf306268 200 */
jburhenn 0:09ef59d2d0f7 201 inline void add(const char* unit, const double value) {
jburhenn 0:09ef59d2d0f7 202 char str[33];
jburhenn 0:09ef59d2d0f7 203 snprintf(str, 33, "%2.3f", value);
jburhenn 0:09ef59d2d0f7 204 add(unit, str);
jburhenn 0:09ef59d2d0f7 205 }
jburhenn 0:09ef59d2d0f7 206
jburhenn 0:09ef59d2d0f7 207 #endif
jburhenn 0:09ef59d2d0f7 208
jburhenn 0:09ef59d2d0f7 209 #ifdef CAYENNE_USING_PROGMEM
jburhenn 1:90dccf306268 210 /**
jburhenn 1:90dccf306268 211 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 212 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 213 * @param[in] value The value to add.
jburhenn 1:90dccf306268 214 */
jburhenn 0:09ef59d2d0f7 215 void add(const char* unit, const __FlashStringHelper* value) {
jburhenn 0:09ef59d2d0f7 216 const char* valueString = reinterpret_cast<const char *>(value);
jburhenn 0:09ef59d2d0f7 217 add(unit, valueString, false, true);
jburhenn 0:09ef59d2d0f7 218 }
jburhenn 0:09ef59d2d0f7 219
jburhenn 1:90dccf306268 220 /**
jburhenn 1:90dccf306268 221 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 222 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 223 * @param[in] value The value to add.
jburhenn 1:90dccf306268 224 */
jburhenn 0:09ef59d2d0f7 225 void add(const __FlashStringHelper* unit, const char* value) {
jburhenn 0:09ef59d2d0f7 226 const char* unitString = reinterpret_cast<const char *>(unit);
jburhenn 0:09ef59d2d0f7 227 add(unitString, value, true, false);
jburhenn 0:09ef59d2d0f7 228 }
jburhenn 1:90dccf306268 229
jburhenn 1:90dccf306268 230 /**
jburhenn 1:90dccf306268 231 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 232 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 233 * @param[in] value The value to add.
jburhenn 1:90dccf306268 234 */
jburhenn 0:09ef59d2d0f7 235 void add(const __FlashStringHelper* unit, const __FlashStringHelper* value) {
jburhenn 0:09ef59d2d0f7 236 const char* unitString = reinterpret_cast<const char *>(unit);
jburhenn 0:09ef59d2d0f7 237 const char* valueString = reinterpret_cast<const char *>(value);
jburhenn 0:09ef59d2d0f7 238 add(unitString, valueString, true, true);
jburhenn 0:09ef59d2d0f7 239 }
jburhenn 0:09ef59d2d0f7 240
jburhenn 1:90dccf306268 241 /**
jburhenn 1:90dccf306268 242 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 243 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 244 * @param[in] value The value to add.
jburhenn 1:90dccf306268 245 */
jburhenn 0:09ef59d2d0f7 246 inline void add(const __FlashStringHelper* unit, const int value) {
jburhenn 0:09ef59d2d0f7 247 char str[2 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 248 itoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 249 add(unit, str);
jburhenn 0:09ef59d2d0f7 250 }
jburhenn 0:09ef59d2d0f7 251
jburhenn 1:90dccf306268 252 /**
jburhenn 1:90dccf306268 253 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 254 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 255 * @param[in] value The value to add.
jburhenn 1:90dccf306268 256 */
jburhenn 0:09ef59d2d0f7 257 inline void add(const __FlashStringHelper* unit, const unsigned int value) {
jburhenn 0:09ef59d2d0f7 258 char str[1 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 259 utoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 260 add(unit, str);
jburhenn 0:09ef59d2d0f7 261 }
jburhenn 0:09ef59d2d0f7 262
jburhenn 1:90dccf306268 263 /**
jburhenn 1:90dccf306268 264 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 265 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 266 * @param[in] value The value to add.
jburhenn 1:90dccf306268 267 */
jburhenn 0:09ef59d2d0f7 268 inline void add(const __FlashStringHelper* unit, const long value) {
jburhenn 0:09ef59d2d0f7 269 char str[2 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 270 ltoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 271 add(unit, str);
jburhenn 0:09ef59d2d0f7 272 }
jburhenn 1:90dccf306268 273
jburhenn 1:90dccf306268 274 /**
jburhenn 1:90dccf306268 275 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 276 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 277 * @param[in] value The value to add.
jburhenn 1:90dccf306268 278 */
jburhenn 0:09ef59d2d0f7 279 inline void add(const __FlashStringHelper* unit, const unsigned long value) {
jburhenn 0:09ef59d2d0f7 280 char str[1 + 8 * sizeof(value)];
jburhenn 0:09ef59d2d0f7 281 ultoa(value, str, 10);
jburhenn 0:09ef59d2d0f7 282 add(unit, str);
jburhenn 0:09ef59d2d0f7 283 }
jburhenn 0:09ef59d2d0f7 284
jburhenn 1:90dccf306268 285 /**
jburhenn 1:90dccf306268 286 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 287 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 288 * @param[in] value The value to add.
jburhenn 1:90dccf306268 289 */
jburhenn 0:09ef59d2d0f7 290 inline void add(const __FlashStringHelper* unit, const float value) {
jburhenn 0:09ef59d2d0f7 291 char str[33];
jburhenn 8:aec9cfdd4c8e 292 dtostrf(value, 5, 3, str);
jburhenn 0:09ef59d2d0f7 293 add(unit, str);
jburhenn 0:09ef59d2d0f7 294 }
jburhenn 0:09ef59d2d0f7 295
jburhenn 1:90dccf306268 296 /**
jburhenn 1:90dccf306268 297 * Add the specified unit/value pair to the array.
jburhenn 1:90dccf306268 298 * @param[in] unit The unit to add.
jburhenn 1:90dccf306268 299 * @param[in] value The value to add.
jburhenn 1:90dccf306268 300 */
jburhenn 0:09ef59d2d0f7 301 inline void add(const __FlashStringHelper* unit, const double value) {
jburhenn 0:09ef59d2d0f7 302 char str[33];
jburhenn 8:aec9cfdd4c8e 303 dtostrf(value, 5, 3, str);
jburhenn 0:09ef59d2d0f7 304 add(unit, str);
jburhenn 0:09ef59d2d0f7 305 }
jburhenn 0:09ef59d2d0f7 306
jburhenn 0:09ef59d2d0f7 307 #endif
jburhenn 1:90dccf306268 308 /**
jburhenn 1:90dccf306268 309 * Get the unit/value pair array.
jburhenn 1:90dccf306268 310 * @return Pointer to the array.
jburhenn 1:90dccf306268 311 */
jburhenn 0:09ef59d2d0f7 312 const CayenneValuePair* getArray() const {
jburhenn 0:09ef59d2d0f7 313 return _values;
jburhenn 0:09ef59d2d0f7 314 }
jburhenn 0:09ef59d2d0f7 315
jburhenn 1:90dccf306268 316 /**
jburhenn 1:90dccf306268 317 * Get the number of items in the unit/value pair array.
jburhenn 1:90dccf306268 318 * @return Count of items.
jburhenn 1:90dccf306268 319 */
jburhenn 0:09ef59d2d0f7 320 size_t getCount() const {
jburhenn 0:09ef59d2d0f7 321 return _valueCount;
jburhenn 0:09ef59d2d0f7 322 }
jburhenn 0:09ef59d2d0f7 323
jburhenn 0:09ef59d2d0f7 324 private:
jburhenn 0:09ef59d2d0f7 325 CayenneValuePair _values[MAX_VALUES];
jburhenn 0:09ef59d2d0f7 326 size_t _valueCount;
jburhenn 0:09ef59d2d0f7 327 char _buffer[BUFFER_SIZE];
jburhenn 0:09ef59d2d0f7 328 size_t _index;
jburhenn 0:09ef59d2d0f7 329 };
jburhenn 0:09ef59d2d0f7 330 }
jburhenn 0:09ef59d2d0f7 331
jburhenn 8:aec9cfdd4c8e 332 typedef CayenneMQTT::DataArray<> CayenneDataArray;
jburhenn 0:09ef59d2d0f7 333
jburhenn 0:09ef59d2d0f7 334 #else
jburhenn 0:09ef59d2d0f7 335
jburhenn 0:09ef59d2d0f7 336 // C version of the data array. Requires source file to be compiled and linked.
jburhenn 0:09ef59d2d0f7 337
jburhenn 0:09ef59d2d0f7 338 typedef struct CayenneDataArray
jburhenn 0:09ef59d2d0f7 339 {
jburhenn 0:09ef59d2d0f7 340 CayenneValuePair values[CAYENNE_MAX_MESSAGE_VALUES];
jburhenn 0:09ef59d2d0f7 341 unsigned int valueCount;
jburhenn 0:09ef59d2d0f7 342 char* buffer;
jburhenn 0:09ef59d2d0f7 343 unsigned int bufferSize;
jburhenn 0:09ef59d2d0f7 344 unsigned int bufferIndex;
jburhenn 0:09ef59d2d0f7 345 } CayenneDataArray;
jburhenn 0:09ef59d2d0f7 346
jburhenn 0:09ef59d2d0f7 347 /**
jburhenn 0:09ef59d2d0f7 348 * Initialize a data array of unit/value pairs.
jburhenn 0:09ef59d2d0f7 349 * @param[out] dataArray The initialized data array
jburhenn 0:09ef59d2d0f7 350 * @param[in] buffer Buffer for storing unit/value pairs. This buffer should be available for as long as the data array is used.
jburhenn 0:09ef59d2d0f7 351 * @param[in] bufferSize Size of the buffer
jburhenn 0:09ef59d2d0f7 352 */
jburhenn 0:09ef59d2d0f7 353 DLLExport void CayenneDataArrayInit(CayenneDataArray* dataArray, char* buffer, unsigned int bufferSize);
jburhenn 0:09ef59d2d0f7 354
jburhenn 0:09ef59d2d0f7 355 /**
jburhenn 0:09ef59d2d0f7 356 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 357 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 358 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 359 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 360 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 361 */
jburhenn 0:09ef59d2d0f7 362 DLLExport int CayenneDataArrayAdd(CayenneDataArray* dataArray, const char* unit, const char* value);
jburhenn 0:09ef59d2d0f7 363
jburhenn 0:09ef59d2d0f7 364 /**
jburhenn 0:09ef59d2d0f7 365 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 366 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 367 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 368 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 369 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 370 */
jburhenn 0:09ef59d2d0f7 371 DLLExport int CayenneDataArrayAddInt(CayenneDataArray* dataArray, const char* unit, int value);
jburhenn 0:09ef59d2d0f7 372
jburhenn 0:09ef59d2d0f7 373 /**
jburhenn 0:09ef59d2d0f7 374 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 375 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 376 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 377 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 378 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 379 */
jburhenn 0:09ef59d2d0f7 380 DLLExport int CayenneDataArrayAddUInt(CayenneDataArray* dataArray, const char* unit, unsigned int value);
jburhenn 0:09ef59d2d0f7 381
jburhenn 0:09ef59d2d0f7 382 /**
jburhenn 0:09ef59d2d0f7 383 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 384 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 385 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 386 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 387 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 388 */
jburhenn 0:09ef59d2d0f7 389 DLLExport int CayenneDataArrayAddLong(CayenneDataArray* dataArray, const char* unit, long value);
jburhenn 0:09ef59d2d0f7 390
jburhenn 0:09ef59d2d0f7 391 /**
jburhenn 0:09ef59d2d0f7 392 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 393 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 394 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 395 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 396 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 397 */
jburhenn 0:09ef59d2d0f7 398 DLLExport int CayenneDataArrayAddULong(CayenneDataArray* dataArray, const char* unit, unsigned long value);
jburhenn 0:09ef59d2d0f7 399
jburhenn 0:09ef59d2d0f7 400 /**
jburhenn 0:09ef59d2d0f7 401 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 402 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 403 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 404 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 405 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 406 */
jburhenn 0:09ef59d2d0f7 407 DLLExport int CayenneDataArrayAddDouble(CayenneDataArray* dataArray, const char* unit, double value);
jburhenn 0:09ef59d2d0f7 408
jburhenn 0:09ef59d2d0f7 409 /**
jburhenn 0:09ef59d2d0f7 410 * Add the specified unit/value pair to the array.
jburhenn 0:09ef59d2d0f7 411 * @param[in] dataArray The data array to add values to
jburhenn 0:09ef59d2d0f7 412 * @param[in] unit The unit to add
jburhenn 0:09ef59d2d0f7 413 * @param[in] value The value to add
jburhenn 0:09ef59d2d0f7 414 * @return CAYENNE_SUCCESS if unit/value pair was add, CAYENNE_FAILURE otherwise
jburhenn 0:09ef59d2d0f7 415 */
jburhenn 0:09ef59d2d0f7 416 DLLExport int CayenneDataArrayAddFloat(CayenneDataArray* dataArray, const char* unit, float value);
jburhenn 0:09ef59d2d0f7 417
jburhenn 0:09ef59d2d0f7 418 /**
jburhenn 0:09ef59d2d0f7 419 * Clear the data array.
jburhenn 0:09ef59d2d0f7 420 * @param[in] dataArray The data array to clear
jburhenn 0:09ef59d2d0f7 421 */
jburhenn 0:09ef59d2d0f7 422 DLLExport void CayenneDataArrayClear(CayenneDataArray* dataArray);
jburhenn 0:09ef59d2d0f7 423
jburhenn 0:09ef59d2d0f7 424 #endif
jburhenn 0:09ef59d2d0f7 425
jburhenn 0:09ef59d2d0f7 426 #endif