gusimplewhiteboard
wb_machine_filtered_localisation_vision.c
Go to the documentation of this file.
1/*
2 * file wb_machine_filtered_localisation_vision.c
3 *
4 * This file was generated by classgenerator from machine_filtered_localisation_vision.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Callum McColl.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
62#endif // WHITEBOARD_POSTER_STRING_CONVERSION
63
65#include <stdio.h>
66#include <string.h>
67#include <stdlib.h>
68#include <ctype.h>
69#include <limits.h>
70
71/* Network byte order functions */
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
74#if defined(__linux)
75# include <endian.h>
76# include <byteswap.h>
77#elif defined(__APPLE__)
78# include <machine/endian.h> //Needed for __BYTE_ORDER
79# include <architecture/byte_order.h> //Needed for byte swap functions
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
83#elif defined(ESP8266)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
87#else
88 //Manually define swap macros?
89#endif
90
91#if (!defined(__BYTE_ORDER) && !defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
92# if !defined(htonll) && !defined(ntohll)
93# define htonll(x) bswap_64(x)
94# define ntohll(x) bswap_64(x)
95# endif
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
99# endif
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
103# endif
104#else
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
108# endif
109# if !defined(htonl) && !defined(ntohl)
110# define htonl(x) (x)
111# define ntohl(x) (x)
112# endif
113# if !defined(htons) && !defined(ntohs)
114# define htons(x) (x)
115# define ntohs(x) (x)
116# endif
117#endif
118#pragma clang diagnostic pop
119
120
121
125const char* wb_machine_filtered_localisation_vision_description(const struct wb_machine_filtered_localisation_vision* self, char* descString, size_t bufferSize)
126{
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
129 size_t len = 0;
130 if (len >= bufferSize) {
131 return descString;
132 }
133 len += snprintf(descString + len, bufferSize - len, "numberOfSightings=%u", self->numberOfSightings);
134 if (len >= bufferSize) {
135 return descString;
136 }
137 len = gu_strlcat(descString, ", ", bufferSize);
138 if (len >= bufferSize) {
139 return descString;
140 }
141 len = gu_strlcat(descString, "sightings={", bufferSize);
142 for (int sightings_index = 0; sightings_index < MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE; sightings_index++) {
143 if (len >= bufferSize) {
144 return descString;
145 }
146 if (sightings_index > 0) {
147 len = gu_strlcat(descString, ", ", bufferSize);
148 }
149 len = gu_strlcat(descString, "{", bufferSize);
150 if (len >= bufferSize) {
151 return descString;
152 }
153 char sightings_1_buffer[LANDMARK_SIGHTING_DESC_BUFFER_SIZE];
154 char* sightings_1_p = sightings_1_buffer;
155 const char* sightings_1_description = wb_landmark_sighting_description(&self->sightings[sightings_index], sightings_1_p, LANDMARK_SIGHTING_DESC_BUFFER_SIZE);
156 len = gu_strlcat(descString, sightings_1_p, bufferSize);
157 if (len >= bufferSize) {
158 return descString;
159 }
160 len = gu_strlcat(descString, "}", bufferSize);
161 }
162 if (len >= bufferSize) {
163 return descString;
164 }
165 len = gu_strlcat(descString, "}", bufferSize);
166 return descString;
167#pragma clang diagnostic pop
168}
169
173const char* wb_machine_filtered_localisation_vision_to_string(const struct wb_machine_filtered_localisation_vision* self, char* toString, size_t bufferSize)
174{
175#pragma clang diagnostic push
176#pragma clang diagnostic ignored "-Wunused-variable"
177 size_t len = 0;
178 if (len >= bufferSize) {
179 return toString;
180 }
181 len += snprintf(toString + len, bufferSize - len, "%u", self->numberOfSightings);
182 if (len >= bufferSize) {
183 return toString;
184 }
185 len = gu_strlcat(toString, ", ", bufferSize);
186 if (len >= bufferSize) {
187 return toString;
188 }
189 len = gu_strlcat(toString, "{", bufferSize);
190 for (int sightings_index = 0; sightings_index < MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE; sightings_index++) {
191 if (len >= bufferSize) {
192 return toString;
193 }
194 if (sightings_index > 0) {
195 len = gu_strlcat(toString, ", ", bufferSize);
196 }
197 len = gu_strlcat(toString, "{", bufferSize);
198 if (len >= bufferSize) {
199 return toString;
200 }
201 char sightings_1_buffer[LANDMARK_SIGHTING_TO_STRING_BUFFER_SIZE];
202 char* sightings_1_p = sightings_1_buffer;
203 const char* sightings_1_to_string = wb_landmark_sighting_to_string(&self->sightings[sightings_index], sightings_1_p, LANDMARK_SIGHTING_TO_STRING_BUFFER_SIZE);
204 len = gu_strlcat(toString, sightings_1_p, bufferSize);
205 if (len >= bufferSize) {
206 return toString;
207 }
208 len = gu_strlcat(toString, "}", bufferSize);
209 }
210 if (len >= bufferSize) {
211 return toString;
212 }
213 len = gu_strlcat(toString, "}", bufferSize);
214 return toString;
215#pragma clang diagnostic pop
216}
217
222{
223 size_t temp_length = strlen(str);
224 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
226 return self;
227 }
229 char* var_str = &var_str_buffer[0];
230 char key_buffer[18];
231 char* key = &key_buffer[0];
232 int bracecount = 0;
233 int lastBrace = -1;
234 int startVar = 0;
235 int index = 0;
236 int startKey = 0;
237 int endKey = -1;
238 int varIndex = 0;
239 if (index == 0 && str[0] == '{') {
240 index = 1;
241 }
242 startVar = index;
243 startKey = startVar;
244 do {
245 for (int i = index; i < length; i++) {
246 index = i + 1;
247 if (bracecount == 0 && str[i] == '=') {
248 endKey = i - 1;
249 startVar = index;
250 continue;
251 }
252 if (bracecount == 0 && isspace(str[i])) {
253 startVar = index;
254 if (endKey == -1) {
255 startKey = index;
256 }
257 continue;
258 }
259 if (bracecount == 0 && str[i] == ',') {
260 index = i - 1;
261 break;
262 }
263 if (str[i] == '{') {
264 bracecount++;
265 if (bracecount == 1) {
266 lastBrace = i;
267 }
268 continue;
269 }
270 if (str[i] == '}') {
271 bracecount--;
272 if (bracecount < 0) {
273 index = i - 1;
274 break;
275 }
276 }
277 if (i == length - 1) {
278 index = i;
279 }
280 }
281 if (endKey >= startKey && endKey - startKey < length) {
282 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
283 key[(endKey - startKey) + 1] = 0;
284 } else {
285 key[0] = 0;
286 }
287 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
288 var_str[(index - startVar) + 1] = 0;
289 bracecount = 0;
290 index += 2;
291 startVar = index;
292 startKey = startVar;
293 endKey = -1;
294 if (strlen(key) > 0) {
295 if (0 == strcmp("numberOfSightings", key)) {
296 varIndex = 0;
297 } else if (0 == strcmp("sightings", key)) {
298 varIndex = 1;
299 } else {
300 varIndex = -1;
301 }
302 }
303 switch (varIndex) {
304 case -1: { break; }
305 case 0:
306 {
307 self->numberOfSightings = ((uint8_t)atoi(var_str));
308 break;
309 }
310 case 1:
311 {
312 int restartIndex = index;
313 index = lastBrace + 1;
314 startVar = index;
315 startKey = startVar;
316 endKey = -1;
317 bracecount = 0;
318 for (int sightings_0_index = 0; sightings_0_index < MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE; sightings_0_index++) {
319 for (int i = index; i < length; i++) {
320 index = i + 1;
321 if (bracecount == 0 && str[i] == '=') {
322 endKey = i - 1;
323 startVar = index;
324 continue;
325 }
326 if (bracecount == 0 && isspace(str[i])) {
327 startVar = index;
328 if (endKey == -1) {
329 startKey = index;
330 }
331 continue;
332 }
333 if (bracecount == 0 && str[i] == ',') {
334 index = i - 1;
335 break;
336 }
337 if (str[i] == '{') {
338 bracecount++;
339 continue;
340 }
341 if (str[i] == '}') {
342 bracecount--;
343 if (bracecount < 0) {
344 index = i - 1;
345 break;
346 }
347 }
348 if (i == length - 1) {
349 index = i;
350 }
351 }
352 if (endKey >= startKey && endKey - startKey < length) {
353 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
354 key[(endKey - startKey) + 1] = 0;
355 } else {
356 key[0] = 0;
357 }
358 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
359 var_str[(index - startVar) + 1] = 0;
360 bracecount = 0;
361 index += 2;
362 startVar = index;
363 startKey = startVar;
364 endKey = -1;
365 struct wb_landmark_sighting sightings_0 = {};
366 wb_landmark_sighting_from_string(&sightings_0, var_str);
367 self->sightings[sightings_0_index] = sightings_0;
368 }
369 index = restartIndex;
370 break;
371 }
372 }
373 if (varIndex >= 0) {
374 varIndex++;
375 }
376 } while(index < length);
377 return self;
378}
379
380/*#ifdef WHITEBOARD_SERIALISATION*/
381
386{
387 uint16_t bit_offset = 0;
388 uint8_t numberOfSightings_nbo = (self->numberOfSightings);
389 do {
390 int8_t b;
391 for (b = (8 - 1); b >= 0; b--) {
392 do {
393 uint16_t byte = bit_offset / 8;
394 uint16_t bit = 7 - (bit_offset % 8);
395 unsigned long newbit = !!((numberOfSightings_nbo >> b) & 1U);
396 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
397 bit_offset = bit_offset + 1;
398 } while(false);
399 }
400 } while(false);
401
402 //Class generator does not support array network compression.
403 //Copying into the buffer, uncompressed
404 do { //limit declaration scope
405 uint32_t len = 12;
406 uint32_t bytes = len * sizeof(struct wb_landmark_sighting);
407 const char *buf = (const char *)&self->sightings[0];
408 uint32_t c;
409 int8_t b;
410 for (c = 0; c < bytes; c++) {
411 for (b = 7; b >= 0; b--) {
412 do {
413 uint16_t byte = bit_offset / 8;
414 uint16_t bit = 7 - (bit_offset % 8);
415 unsigned long newbit = !!((buf[c] >> b) & 1U);
416 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
417 bit_offset = bit_offset + 1;
418 } while(false);
419 }
420 }
421 } while(false);
422 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
423 (void)self;
424 (void)dst;
425 return bit_offset;
426}
427
432{
433 uint16_t bit_offset = 0;
434 do {
435 int8_t b;
436 for (b = (8 - 1); b >= 0; b--) {
437 do {
438 uint16_t byte = bit_offset / 8;
439 uint16_t bit = 7 - (bit_offset % 8);
440 char dataByte = src[byte];
441 unsigned char bitValue = (dataByte >> bit) & 1U;
442 dst->numberOfSightings ^= (-bitValue ^ dst->numberOfSightings) & (1UL << b);
443 bit_offset = bit_offset + 1;
444 } while(false);
445 }
446 } while(false);
448
449 //Class generator does not support array network compression.
450 //Copying into the buffer, uncompressed
451 do { //limit declaration scope
452 uint32_t len = 12;
453 uint32_t bytes = len * sizeof(struct wb_landmark_sighting);
454 char *buf = (char *)malloc(bytes);
455 uint32_t c;
456 int8_t b;
457 for (c = 0; c < bytes; c++) {
458 for (b = 7; b >= 0; b--) {
459 do {
460 uint16_t byte = bit_offset / 8;
461 uint16_t bit = 7 - (bit_offset % 8);
462 char dataByte = src[byte];
463 unsigned char bitValue = (dataByte >> bit) & 1U;
464 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
465 bit_offset = bit_offset + 1;
466 } while(false);
467 }
468 }
469 memcpy(&dst->sightings[0], &buf[0], bytes);
470 free(buf);
471 } while(false);
472 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
473 (void)src;
474 (void)dst;
475 return bit_offset;
476}
477
478/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
Results of the FSM (and sub machines) "SMFilterVision".
uint8_t numberOfSightings
The number of sightings in sightings.
struct wb_landmark_sighting sightings[12]
All sightings.
const char * wb_landmark_sighting_description(const struct wb_landmark_sighting *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_landmark_sighting_to_string(const struct wb_landmark_sighting *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_landmark_sighting * wb_landmark_sighting_from_string(struct wb_landmark_sighting *self, const char *str)
Convert from a string.
#define LANDMARK_SIGHTING_DESC_BUFFER_SIZE
#define LANDMARK_SIGHTING_TO_STRING_BUFFER_SIZE
size_t wb_machine_filtered_localisation_vision_to_network_serialised(const struct wb_machine_filtered_localisation_vision *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
struct wb_machine_filtered_localisation_vision * wb_machine_filtered_localisation_vision_from_string(struct wb_machine_filtered_localisation_vision *self, const char *str)
Convert from a string.
const char * wb_machine_filtered_localisation_vision_to_string(const struct wb_machine_filtered_localisation_vision *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_machine_filtered_localisation_vision_from_network_serialised(const char *src, struct wb_machine_filtered_localisation_vision *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_machine_filtered_localisation_vision_description(const struct wb_machine_filtered_localisation_vision *self, char *descString, size_t bufferSize)
Convert to a description string.
#define MACHINE_FILTERED_LOCALISATION_VISION_DESC_BUFFER_SIZE
#define MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.