bastien vincke
/
SmartCampus_Lorawan
First program for SmartCampus LoRaWan
SmartFormat.cpp@52:bfaf25ee5cd5, 2020-02-05 (annotated)
- Committer:
- bastienvincke
- Date:
- Wed Feb 05 13:17:21 2020 +0000
- Revision:
- 52:bfaf25ee5cd5
- Parent:
- 51:885c5ed083d1
bv
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bastienvincke | 51:885c5ed083d1 | 1 | #include "SmartFormat.h" |
bastienvincke | 51:885c5ed083d1 | 2 | |
bastienvincke | 51:885c5ed083d1 | 3 | SmartFormat::SmartFormat(uint8_t size, uint16_t id) : maxsize(size) { |
bastienvincke | 51:885c5ed083d1 | 4 | buffer = (uint8_t*) malloc(size); |
bastienvincke | 51:885c5ed083d1 | 5 | memcpy(buffer, &id, 2); // copie de l'identifiant du périphérique |
bastienvincke | 51:885c5ed083d1 | 6 | |
bastienvincke | 51:885c5ed083d1 | 7 | cursor = 2; |
bastienvincke | 51:885c5ed083d1 | 8 | } |
bastienvincke | 51:885c5ed083d1 | 9 | |
bastienvincke | 51:885c5ed083d1 | 10 | SmartFormat::~SmartFormat(void) { |
bastienvincke | 51:885c5ed083d1 | 11 | free(buffer); |
bastienvincke | 51:885c5ed083d1 | 12 | } |
bastienvincke | 51:885c5ed083d1 | 13 | |
bastienvincke | 51:885c5ed083d1 | 14 | void SmartFormat::reset(void) { |
bastienvincke | 51:885c5ed083d1 | 15 | cursor = 2; |
bastienvincke | 51:885c5ed083d1 | 16 | } |
bastienvincke | 51:885c5ed083d1 | 17 | |
bastienvincke | 51:885c5ed083d1 | 18 | uint8_t SmartFormat::getSize(void) { |
bastienvincke | 51:885c5ed083d1 | 19 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 20 | } |
bastienvincke | 51:885c5ed083d1 | 21 | |
bastienvincke | 51:885c5ed083d1 | 22 | uint8_t* SmartFormat::getBuffer(void) { |
bastienvincke | 51:885c5ed083d1 | 23 | return buffer; |
bastienvincke | 51:885c5ed083d1 | 24 | } |
bastienvincke | 51:885c5ed083d1 | 25 | |
bastienvincke | 51:885c5ed083d1 | 26 | uint8_t SmartFormat::copy(uint8_t* dst) { |
bastienvincke | 51:885c5ed083d1 | 27 | memcpy(dst, buffer, cursor); |
bastienvincke | 51:885c5ed083d1 | 28 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 29 | } |
bastienvincke | 51:885c5ed083d1 | 30 | |
bastienvincke | 51:885c5ed083d1 | 31 | uint8_t SmartFormat::add_Digital_Input(uint8_t value) { |
bastienvincke | 51:885c5ed083d1 | 32 | if ((cursor + SF_DIGITAL_INPUT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 33 | return 0; |
bastienvincke | 51:885c5ed083d1 | 34 | } |
bastienvincke | 51:885c5ed083d1 | 35 | memcpy(&buffer[cursor], &SF_DIGITAL_INPUT, 2); |
bastienvincke | 51:885c5ed083d1 | 36 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 37 | buffer[cursor++] = value; |
bastienvincke | 51:885c5ed083d1 | 38 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 39 | } |
bastienvincke | 51:885c5ed083d1 | 40 | |
bastienvincke | 51:885c5ed083d1 | 41 | uint8_t SmartFormat::add_Digital_Output(uint8_t value) { |
bastienvincke | 51:885c5ed083d1 | 42 | if ((cursor + SF_DIGITAL_OUTPUT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 43 | return 0; |
bastienvincke | 51:885c5ed083d1 | 44 | } |
bastienvincke | 51:885c5ed083d1 | 45 | memcpy(&buffer[cursor], &SF_DIGITAL_OUTPUT, 2); |
bastienvincke | 51:885c5ed083d1 | 46 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 47 | buffer[cursor++] = value; |
bastienvincke | 51:885c5ed083d1 | 48 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 49 | } |
bastienvincke | 51:885c5ed083d1 | 50 | |
bastienvincke | 51:885c5ed083d1 | 51 | uint8_t SmartFormat::add_Analog_Input(float value) { |
bastienvincke | 51:885c5ed083d1 | 52 | if ((cursor + SF_ANALOG_INPUT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 53 | return 0; |
bastienvincke | 51:885c5ed083d1 | 54 | } |
bastienvincke | 51:885c5ed083d1 | 55 | memcpy(&buffer[cursor], &SF_ANALOG_INPUT, 2); |
bastienvincke | 51:885c5ed083d1 | 56 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 57 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 58 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 59 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 60 | } |
bastienvincke | 51:885c5ed083d1 | 61 | |
bastienvincke | 51:885c5ed083d1 | 62 | uint8_t SmartFormat::add_Analog_Onput(float value) { |
bastienvincke | 51:885c5ed083d1 | 63 | if ((cursor + SF_ANALOG_OUTPUT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 64 | return 0; |
bastienvincke | 51:885c5ed083d1 | 65 | } |
bastienvincke | 51:885c5ed083d1 | 66 | memcpy(&buffer[cursor], &SF_ANALOG_OUTPUT, 2); |
bastienvincke | 51:885c5ed083d1 | 67 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 68 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 69 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 70 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 71 | } |
bastienvincke | 51:885c5ed083d1 | 72 | |
bastienvincke | 51:885c5ed083d1 | 73 | uint8_t SmartFormat::add_Generic_Sensor(float value) { |
bastienvincke | 51:885c5ed083d1 | 74 | if ((cursor + SF_ANALOG_OUTPUT) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 75 | return 0; |
bastienvincke | 51:885c5ed083d1 | 76 | } |
bastienvincke | 51:885c5ed083d1 | 77 | memcpy(&buffer[cursor], &SF_GENERIC_SENSOR, 2); |
bastienvincke | 51:885c5ed083d1 | 78 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 79 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 80 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 81 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 82 | } |
bastienvincke | 51:885c5ed083d1 | 83 | |
bastienvincke | 51:885c5ed083d1 | 84 | uint8_t SmartFormat::add_Illuminance(float value) { |
bastienvincke | 51:885c5ed083d1 | 85 | if ((cursor + SF_ILLUMINANCE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 86 | return 0; |
bastienvincke | 51:885c5ed083d1 | 87 | } |
bastienvincke | 51:885c5ed083d1 | 88 | memcpy(&buffer[cursor], &SF_ILLUMINANCE, 2); |
bastienvincke | 51:885c5ed083d1 | 89 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 90 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 91 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 92 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 93 | } |
bastienvincke | 51:885c5ed083d1 | 94 | |
bastienvincke | 51:885c5ed083d1 | 95 | uint8_t SmartFormat::add_Presence(int16_t value) { |
bastienvincke | 51:885c5ed083d1 | 96 | if ((cursor + SF_PRESENCE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 97 | return 0; |
bastienvincke | 51:885c5ed083d1 | 98 | } |
bastienvincke | 51:885c5ed083d1 | 99 | memcpy(&buffer[cursor], &SF_PRESENCE, 2); |
bastienvincke | 51:885c5ed083d1 | 100 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 101 | memcpy(&buffer[cursor], &value, 2); |
bastienvincke | 51:885c5ed083d1 | 102 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 103 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 104 | } |
bastienvincke | 51:885c5ed083d1 | 105 | |
bastienvincke | 51:885c5ed083d1 | 106 | uint8_t SmartFormat::add_Temperature(float value) { |
bastienvincke | 51:885c5ed083d1 | 107 | if ((cursor + SF_TEMPERATURE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 108 | return 0; |
bastienvincke | 51:885c5ed083d1 | 109 | } |
bastienvincke | 51:885c5ed083d1 | 110 | memcpy(&buffer[cursor], &SF_TEMPERATURE, 2); |
bastienvincke | 51:885c5ed083d1 | 111 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 112 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 113 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 114 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 115 | } |
bastienvincke | 51:885c5ed083d1 | 116 | |
bastienvincke | 51:885c5ed083d1 | 117 | uint8_t SmartFormat::add_Humidity(float value) { |
bastienvincke | 51:885c5ed083d1 | 118 | if ((cursor + SF_HUMIDITY_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 119 | return 0; |
bastienvincke | 51:885c5ed083d1 | 120 | } |
bastienvincke | 51:885c5ed083d1 | 121 | memcpy(&buffer[cursor], &SF_HUMIDITY, 2); |
bastienvincke | 51:885c5ed083d1 | 122 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 123 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 124 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 125 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 126 | } |
bastienvincke | 51:885c5ed083d1 | 127 | |
bastienvincke | 51:885c5ed083d1 | 128 | uint8_t SmartFormat::add_Power_Measurement(float value) { |
bastienvincke | 51:885c5ed083d1 | 129 | if ((cursor + SF_POWER_MEASUREMENT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 130 | return 0; |
bastienvincke | 51:885c5ed083d1 | 131 | } |
bastienvincke | 51:885c5ed083d1 | 132 | memcpy(&buffer[cursor], &SF_POWER_MEASUREMENT, 2); |
bastienvincke | 51:885c5ed083d1 | 133 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 134 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 135 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 136 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 137 | } |
bastienvincke | 51:885c5ed083d1 | 138 | |
bastienvincke | 51:885c5ed083d1 | 139 | uint8_t SmartFormat::add_Actuation(float value) { |
bastienvincke | 51:885c5ed083d1 | 140 | if ((cursor + SF_ACTUATION_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 141 | return 0; |
bastienvincke | 51:885c5ed083d1 | 142 | } |
bastienvincke | 51:885c5ed083d1 | 143 | memcpy(&buffer[cursor], &SF_ACTUATION, 2); |
bastienvincke | 51:885c5ed083d1 | 144 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 145 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 146 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 147 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 148 | } |
bastienvincke | 51:885c5ed083d1 | 149 | |
bastienvincke | 51:885c5ed083d1 | 150 | uint8_t SmartFormat::add_Set_Point(float value) { |
bastienvincke | 51:885c5ed083d1 | 151 | if ((cursor + SF_SET_POINT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 152 | return 0; |
bastienvincke | 51:885c5ed083d1 | 153 | } |
bastienvincke | 51:885c5ed083d1 | 154 | memcpy(&buffer[cursor], &SF_SET_POINT, 2); |
bastienvincke | 51:885c5ed083d1 | 155 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 156 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 157 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 158 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 159 | } |
bastienvincke | 51:885c5ed083d1 | 160 | |
bastienvincke | 51:885c5ed083d1 | 161 | uint8_t SmartFormat::add_Load_Control(uint8_t value) { |
bastienvincke | 51:885c5ed083d1 | 162 | if ((cursor + SF_LOAD_CONTROL_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 163 | return 0; |
bastienvincke | 51:885c5ed083d1 | 164 | } |
bastienvincke | 51:885c5ed083d1 | 165 | memcpy(&buffer[cursor], &SF_LOAD_CONTROL, 2); |
bastienvincke | 51:885c5ed083d1 | 166 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 167 | buffer[cursor++] = value; |
bastienvincke | 51:885c5ed083d1 | 168 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 169 | } |
bastienvincke | 51:885c5ed083d1 | 170 | |
bastienvincke | 51:885c5ed083d1 | 171 | uint8_t SmartFormat::add_Light_Control(uint8_t value) { |
bastienvincke | 51:885c5ed083d1 | 172 | if ((cursor + SF_LIGHT_CONTROL) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 173 | return 0; |
bastienvincke | 51:885c5ed083d1 | 174 | } |
bastienvincke | 51:885c5ed083d1 | 175 | memcpy(&buffer[cursor], &SF_DIGITAL_INPUT, 2); |
bastienvincke | 51:885c5ed083d1 | 176 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 177 | buffer[cursor++] = value; |
bastienvincke | 51:885c5ed083d1 | 178 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 179 | } |
bastienvincke | 51:885c5ed083d1 | 180 | |
bastienvincke | 51:885c5ed083d1 | 181 | uint8_t SmartFormat::add_Power_Control(float value) { |
bastienvincke | 51:885c5ed083d1 | 182 | if ((cursor + SF_POWER_CONTROL_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 183 | return 0; |
bastienvincke | 51:885c5ed083d1 | 184 | } |
bastienvincke | 51:885c5ed083d1 | 185 | memcpy(&buffer[cursor], &SF_POWER_CONTROL, 2); |
bastienvincke | 51:885c5ed083d1 | 186 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 187 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 188 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 189 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 190 | } |
bastienvincke | 51:885c5ed083d1 | 191 | |
bastienvincke | 51:885c5ed083d1 | 192 | uint8_t SmartFormat::add_Accelerometer(float value) { |
bastienvincke | 51:885c5ed083d1 | 193 | if ((cursor + SF_ACCELEROMETER_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 194 | return 0; |
bastienvincke | 51:885c5ed083d1 | 195 | } |
bastienvincke | 51:885c5ed083d1 | 196 | memcpy(&buffer[cursor], &SF_ACCELEROMETER, 2); |
bastienvincke | 51:885c5ed083d1 | 197 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 198 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 199 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 200 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 201 | } |
bastienvincke | 51:885c5ed083d1 | 202 | |
bastienvincke | 51:885c5ed083d1 | 203 | uint8_t SmartFormat::add_Magnetometer(float value) { |
bastienvincke | 51:885c5ed083d1 | 204 | if ((cursor + SF_MAGNETOMETER_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 205 | return 0; |
bastienvincke | 51:885c5ed083d1 | 206 | } |
bastienvincke | 51:885c5ed083d1 | 207 | memcpy(&buffer[cursor], &SF_MAGNETOMETER, 2); |
bastienvincke | 51:885c5ed083d1 | 208 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 209 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 210 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 211 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 212 | } |
bastienvincke | 51:885c5ed083d1 | 213 | |
bastienvincke | 51:885c5ed083d1 | 214 | uint8_t SmartFormat::add_Barometer(float value) { |
bastienvincke | 51:885c5ed083d1 | 215 | if ((cursor + SF_BAROMETER_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 216 | return 0; |
bastienvincke | 51:885c5ed083d1 | 217 | } |
bastienvincke | 51:885c5ed083d1 | 218 | memcpy(&buffer[cursor], &SF_BAROMETER, 2); |
bastienvincke | 51:885c5ed083d1 | 219 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 220 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 221 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 222 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 223 | } |
bastienvincke | 51:885c5ed083d1 | 224 | |
bastienvincke | 51:885c5ed083d1 | 225 | uint8_t SmartFormat::add_Voltage(float value) { |
bastienvincke | 51:885c5ed083d1 | 226 | if ((cursor + SF_VOLTAGE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 227 | return 0; |
bastienvincke | 51:885c5ed083d1 | 228 | } |
bastienvincke | 51:885c5ed083d1 | 229 | memcpy(&buffer[cursor], &SF_VOLTAGE, 2); |
bastienvincke | 51:885c5ed083d1 | 230 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 231 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 232 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 233 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 234 | } |
bastienvincke | 51:885c5ed083d1 | 235 | |
bastienvincke | 51:885c5ed083d1 | 236 | uint8_t SmartFormat::add_Current(float value) { |
bastienvincke | 51:885c5ed083d1 | 237 | if ((cursor + SF_CURRENT_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 238 | return 0; |
bastienvincke | 51:885c5ed083d1 | 239 | } |
bastienvincke | 51:885c5ed083d1 | 240 | memcpy(&buffer[cursor], &SF_CURRENT, 2); |
bastienvincke | 51:885c5ed083d1 | 241 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 242 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 243 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 244 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 245 | } |
bastienvincke | 51:885c5ed083d1 | 246 | |
bastienvincke | 51:885c5ed083d1 | 247 | uint8_t SmartFormat::add_Frequency(float value) { |
bastienvincke | 51:885c5ed083d1 | 248 | if ((cursor + SF_FREQUENCY_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 249 | return 0; |
bastienvincke | 51:885c5ed083d1 | 250 | } |
bastienvincke | 51:885c5ed083d1 | 251 | memcpy(&buffer[cursor], &SF_FREQUENCY, 2); |
bastienvincke | 51:885c5ed083d1 | 252 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 253 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 254 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 255 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 256 | } |
bastienvincke | 51:885c5ed083d1 | 257 | |
bastienvincke | 51:885c5ed083d1 | 258 | uint8_t SmartFormat::add_Depth(float value) { |
bastienvincke | 51:885c5ed083d1 | 259 | if ((cursor + SF_DEPTH_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 260 | return 0; |
bastienvincke | 51:885c5ed083d1 | 261 | } |
bastienvincke | 51:885c5ed083d1 | 262 | memcpy(&buffer[cursor], &SF_DEPTH, 2); |
bastienvincke | 51:885c5ed083d1 | 263 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 264 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 265 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 266 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 267 | } |
bastienvincke | 51:885c5ed083d1 | 268 | |
bastienvincke | 51:885c5ed083d1 | 269 | uint8_t SmartFormat::add_Percentage(float value) { |
bastienvincke | 51:885c5ed083d1 | 270 | if ((cursor + SF_PERCENTAGE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 271 | return 0; |
bastienvincke | 51:885c5ed083d1 | 272 | } |
bastienvincke | 51:885c5ed083d1 | 273 | memcpy(&buffer[cursor], &SF_PERCENTAGE, 2); |
bastienvincke | 51:885c5ed083d1 | 274 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 275 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 276 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 277 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 278 | } |
bastienvincke | 51:885c5ed083d1 | 279 | |
bastienvincke | 51:885c5ed083d1 | 280 | uint8_t SmartFormat::add_Altitude(float value) { |
bastienvincke | 51:885c5ed083d1 | 281 | if ((cursor + SF_ALTITUDE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 282 | return 0; |
bastienvincke | 51:885c5ed083d1 | 283 | } |
bastienvincke | 51:885c5ed083d1 | 284 | memcpy(&buffer[cursor], &SF_ALTITUDE, 2); |
bastienvincke | 51:885c5ed083d1 | 285 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 286 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 287 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 288 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 289 | } |
bastienvincke | 51:885c5ed083d1 | 290 | |
bastienvincke | 51:885c5ed083d1 | 291 | uint8_t SmartFormat::add_Load(float value) { |
bastienvincke | 51:885c5ed083d1 | 292 | if ((cursor + SF_LOAD_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 293 | return 0; |
bastienvincke | 51:885c5ed083d1 | 294 | } |
bastienvincke | 51:885c5ed083d1 | 295 | memcpy(&buffer[cursor], &SF_LOAD, 2); |
bastienvincke | 51:885c5ed083d1 | 296 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 297 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 298 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 299 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 300 | } |
bastienvincke | 51:885c5ed083d1 | 301 | |
bastienvincke | 51:885c5ed083d1 | 302 | uint8_t SmartFormat::add_Pressure(float value) { |
bastienvincke | 51:885c5ed083d1 | 303 | if ((cursor + SF_PRESSURE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 304 | return 0; |
bastienvincke | 51:885c5ed083d1 | 305 | } |
bastienvincke | 51:885c5ed083d1 | 306 | memcpy(&buffer[cursor], &SF_PRESSURE, 2); |
bastienvincke | 51:885c5ed083d1 | 307 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 308 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 309 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 310 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 311 | } |
bastienvincke | 51:885c5ed083d1 | 312 | |
bastienvincke | 51:885c5ed083d1 | 313 | uint8_t SmartFormat::add_Distance(float value) { |
bastienvincke | 51:885c5ed083d1 | 314 | if ((cursor + SF_DISTANCE_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 315 | return 0; |
bastienvincke | 51:885c5ed083d1 | 316 | } |
bastienvincke | 51:885c5ed083d1 | 317 | memcpy(&buffer[cursor], &SF_DISTANCE, 2); |
bastienvincke | 51:885c5ed083d1 | 318 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 319 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 320 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 321 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 322 | } |
bastienvincke | 51:885c5ed083d1 | 323 | |
bastienvincke | 51:885c5ed083d1 | 324 | uint8_t SmartFormat::add_Energy(float value) { |
bastienvincke | 51:885c5ed083d1 | 325 | if ((cursor + SF_ENERGY_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 326 | return 0; |
bastienvincke | 51:885c5ed083d1 | 327 | } |
bastienvincke | 51:885c5ed083d1 | 328 | memcpy(&buffer[cursor], &SF_ENERGY, 2); |
bastienvincke | 51:885c5ed083d1 | 329 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 330 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 331 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 332 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 333 | } |
bastienvincke | 51:885c5ed083d1 | 334 | |
bastienvincke | 51:885c5ed083d1 | 335 | uint8_t SmartFormat::add_Direction(float value) { |
bastienvincke | 51:885c5ed083d1 | 336 | if ((cursor + SF_DIRECTION_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 337 | return 0; |
bastienvincke | 51:885c5ed083d1 | 338 | } |
bastienvincke | 51:885c5ed083d1 | 339 | memcpy(&buffer[cursor], &SF_DIRECTION, 2); |
bastienvincke | 51:885c5ed083d1 | 340 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 341 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 342 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 343 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 344 | } |
bastienvincke | 51:885c5ed083d1 | 345 | |
bastienvincke | 51:885c5ed083d1 | 346 | uint8_t SmartFormat::add_Time(float value) { |
bastienvincke | 51:885c5ed083d1 | 347 | if ((cursor + SF_TIME_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 348 | return 0; |
bastienvincke | 51:885c5ed083d1 | 349 | } |
bastienvincke | 51:885c5ed083d1 | 350 | memcpy(&buffer[cursor], &SF_TIME, 2); |
bastienvincke | 51:885c5ed083d1 | 351 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 352 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 353 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 354 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 355 | } |
bastienvincke | 51:885c5ed083d1 | 356 | |
bastienvincke | 51:885c5ed083d1 | 357 | uint8_t SmartFormat::add_Gyrometer(float value) { |
bastienvincke | 51:885c5ed083d1 | 358 | if ((cursor + SF_GYROMETER_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 359 | return 0; |
bastienvincke | 51:885c5ed083d1 | 360 | } |
bastienvincke | 51:885c5ed083d1 | 361 | memcpy(&buffer[cursor], &SF_GYROMETER, 2); |
bastienvincke | 51:885c5ed083d1 | 362 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 363 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 364 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 365 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 366 | } |
bastienvincke | 51:885c5ed083d1 | 367 | |
bastienvincke | 51:885c5ed083d1 | 368 | uint8_t SmartFormat::add_Colour(int32_t value) { |
bastienvincke | 51:885c5ed083d1 | 369 | if ((cursor + SF_COLOUR_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 370 | return 0; |
bastienvincke | 51:885c5ed083d1 | 371 | } |
bastienvincke | 51:885c5ed083d1 | 372 | memcpy(&buffer[cursor], &SF_COLOUR, 2); |
bastienvincke | 51:885c5ed083d1 | 373 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 374 | memcpy(&buffer[cursor], &value, 4); |
bastienvincke | 51:885c5ed083d1 | 375 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 376 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 377 | } |
bastienvincke | 51:885c5ed083d1 | 378 | |
bastienvincke | 51:885c5ed083d1 | 379 | |
bastienvincke | 51:885c5ed083d1 | 380 | uint8_t SmartFormat::add_Location(float latitude, float longitude, float altitude) { |
bastienvincke | 51:885c5ed083d1 | 381 | if ((cursor + SF_LOCATION_SIZE) > maxsize) { |
bastienvincke | 51:885c5ed083d1 | 382 | return 0; |
bastienvincke | 51:885c5ed083d1 | 383 | } |
bastienvincke | 51:885c5ed083d1 | 384 | memcpy(&buffer[cursor], &SF_LOCATION, 2); |
bastienvincke | 51:885c5ed083d1 | 385 | cursor += 2; |
bastienvincke | 51:885c5ed083d1 | 386 | memcpy(&buffer[cursor], &latitude, 4); |
bastienvincke | 51:885c5ed083d1 | 387 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 388 | memcpy(&buffer[cursor], &longitude, 4); |
bastienvincke | 51:885c5ed083d1 | 389 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 390 | memcpy(&buffer[cursor], &altitude, 4); |
bastienvincke | 51:885c5ed083d1 | 391 | cursor += 4; |
bastienvincke | 51:885c5ed083d1 | 392 | return cursor; |
bastienvincke | 51:885c5ed083d1 | 393 | } |
bastienvincke | 51:885c5ed083d1 | 394 | |
bastienvincke | 51:885c5ed083d1 | 395 | |
bastienvincke | 51:885c5ed083d1 | 396 | |
bastienvincke | 51:885c5ed083d1 | 397 | |
bastienvincke | 51:885c5ed083d1 | 398 |