gusimplewhiteboard
wb_vision_field_features.c
Go to the documentation of this file.
1/*
2 * file wb_vision_field_features.c
3 *
4 * This file was generated by classgenerator from vision_field_features.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Eugene Gilmore. 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 Eugene Gilmore.
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_vision_field_features_description(const struct wb_vision_field_features* 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 = gu_strlcat(descString, "fieldCorner={", bufferSize);
134 for (int fieldCorner_index = 0; fieldCorner_index < VISION_FIELD_FEATURES_FIELDCORNER_ARRAY_SIZE; fieldCorner_index++) {
135 if (len >= bufferSize) {
136 return descString;
137 }
138 if (fieldCorner_index > 0) {
139 len = gu_strlcat(descString, ", ", bufferSize);
140 }
141 len = gu_strlcat(descString, "{", bufferSize);
142 if (len >= bufferSize) {
143 return descString;
144 }
145 char fieldCorner_1_buffer[VISION_FIELD_FEATURE_DESC_BUFFER_SIZE];
146 char* fieldCorner_1_p = fieldCorner_1_buffer;
147 const char* fieldCorner_1_description = wb_vision_field_feature_description(&self->fieldCorner[fieldCorner_index], fieldCorner_1_p, VISION_FIELD_FEATURE_DESC_BUFFER_SIZE);
148 len = gu_strlcat(descString, fieldCorner_1_p, bufferSize);
149 if (len >= bufferSize) {
150 return descString;
151 }
152 len = gu_strlcat(descString, "}", bufferSize);
153 }
154 if (len >= bufferSize) {
155 return descString;
156 }
157 len = gu_strlcat(descString, "}", bufferSize);
158 if (len >= bufferSize) {
159 return descString;
160 }
161 len = gu_strlcat(descString, ", ", bufferSize);
162 if (len >= bufferSize) {
163 return descString;
164 }
165 len = gu_strlcat(descString, "fieldIntersection={", bufferSize);
166 for (int fieldIntersection_index = 0; fieldIntersection_index < VISION_FIELD_FEATURES_FIELDINTERSECTION_ARRAY_SIZE; fieldIntersection_index++) {
167 if (len >= bufferSize) {
168 return descString;
169 }
170 if (fieldIntersection_index > 0) {
171 len = gu_strlcat(descString, ", ", bufferSize);
172 }
173 len = gu_strlcat(descString, "{", bufferSize);
174 if (len >= bufferSize) {
175 return descString;
176 }
177 char fieldIntersection_1_buffer[VISION_FIELD_FEATURE_DESC_BUFFER_SIZE];
178 char* fieldIntersection_1_p = fieldIntersection_1_buffer;
179 const char* fieldIntersection_1_description = wb_vision_field_feature_description(&self->fieldIntersection[fieldIntersection_index], fieldIntersection_1_p, VISION_FIELD_FEATURE_DESC_BUFFER_SIZE);
180 len = gu_strlcat(descString, fieldIntersection_1_p, bufferSize);
181 if (len >= bufferSize) {
182 return descString;
183 }
184 len = gu_strlcat(descString, "}", bufferSize);
185 }
186 if (len >= bufferSize) {
187 return descString;
188 }
189 len = gu_strlcat(descString, "}", bufferSize);
190 if (len >= bufferSize) {
191 return descString;
192 }
193 len = gu_strlcat(descString, ", ", bufferSize);
194 if (len >= bufferSize) {
195 return descString;
196 }
197 len = gu_strlcat(descString, "fieldCrosses={", bufferSize);
198 for (int fieldCrosses_index = 0; fieldCrosses_index < VISION_FIELD_FEATURES_FIELDCROSSES_ARRAY_SIZE; fieldCrosses_index++) {
199 if (len >= bufferSize) {
200 return descString;
201 }
202 if (fieldCrosses_index > 0) {
203 len = gu_strlcat(descString, ", ", bufferSize);
204 }
205 len = gu_strlcat(descString, "{", bufferSize);
206 if (len >= bufferSize) {
207 return descString;
208 }
209 char fieldCrosses_1_buffer[VISION_FIELD_FEATURE_DESC_BUFFER_SIZE];
210 char* fieldCrosses_1_p = fieldCrosses_1_buffer;
211 const char* fieldCrosses_1_description = wb_vision_field_feature_description(&self->fieldCrosses[fieldCrosses_index], fieldCrosses_1_p, VISION_FIELD_FEATURE_DESC_BUFFER_SIZE);
212 len = gu_strlcat(descString, fieldCrosses_1_p, bufferSize);
213 if (len >= bufferSize) {
214 return descString;
215 }
216 len = gu_strlcat(descString, "}", bufferSize);
217 }
218 if (len >= bufferSize) {
219 return descString;
220 }
221 len = gu_strlcat(descString, "}", bufferSize);
222 if (len >= bufferSize) {
223 return descString;
224 }
225 len = gu_strlcat(descString, ", ", bufferSize);
226 if (len >= bufferSize) {
227 return descString;
228 }
229 len += snprintf(descString + len, bufferSize - len, "numCorners=%u", self->numCorners);
230 if (len >= bufferSize) {
231 return descString;
232 }
233 len = gu_strlcat(descString, ", ", bufferSize);
234 if (len >= bufferSize) {
235 return descString;
236 }
237 len += snprintf(descString + len, bufferSize - len, "numIntersections=%u", self->numIntersections);
238 if (len >= bufferSize) {
239 return descString;
240 }
241 len = gu_strlcat(descString, ", ", bufferSize);
242 if (len >= bufferSize) {
243 return descString;
244 }
245 len += snprintf(descString + len, bufferSize - len, "numCrosses=%u", self->numCrosses);
246 if (len >= bufferSize) {
247 return descString;
248 }
249 len = gu_strlcat(descString, ", ", bufferSize);
250 if (len >= bufferSize) {
251 return descString;
252 }
253 len += snprintf(descString + len, bufferSize - len, "res_width=%u", self->res_width);
254 if (len >= bufferSize) {
255 return descString;
256 }
257 len = gu_strlcat(descString, ", ", bufferSize);
258 if (len >= bufferSize) {
259 return descString;
260 }
261 len += snprintf(descString + len, bufferSize - len, "res_height=%u", self->res_height);
262 return descString;
263#pragma clang diagnostic pop
264}
265
269const char* wb_vision_field_features_to_string(const struct wb_vision_field_features* self, char* toString, size_t bufferSize)
270{
271#pragma clang diagnostic push
272#pragma clang diagnostic ignored "-Wunused-variable"
273 size_t len = 0;
274 if (len >= bufferSize) {
275 return toString;
276 }
277 len = gu_strlcat(toString, "{", bufferSize);
278 for (int fieldCorner_index = 0; fieldCorner_index < VISION_FIELD_FEATURES_FIELDCORNER_ARRAY_SIZE; fieldCorner_index++) {
279 if (len >= bufferSize) {
280 return toString;
281 }
282 if (fieldCorner_index > 0) {
283 len = gu_strlcat(toString, ", ", bufferSize);
284 }
285 len = gu_strlcat(toString, "{", bufferSize);
286 if (len >= bufferSize) {
287 return toString;
288 }
289 char fieldCorner_1_buffer[VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE];
290 char* fieldCorner_1_p = fieldCorner_1_buffer;
291 const char* fieldCorner_1_to_string = wb_vision_field_feature_to_string(&self->fieldCorner[fieldCorner_index], fieldCorner_1_p, VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE);
292 len = gu_strlcat(toString, fieldCorner_1_p, bufferSize);
293 if (len >= bufferSize) {
294 return toString;
295 }
296 len = gu_strlcat(toString, "}", bufferSize);
297 }
298 if (len >= bufferSize) {
299 return toString;
300 }
301 len = gu_strlcat(toString, "}", bufferSize);
302 if (len >= bufferSize) {
303 return toString;
304 }
305 len = gu_strlcat(toString, ", ", bufferSize);
306 if (len >= bufferSize) {
307 return toString;
308 }
309 len = gu_strlcat(toString, "{", bufferSize);
310 for (int fieldIntersection_index = 0; fieldIntersection_index < VISION_FIELD_FEATURES_FIELDINTERSECTION_ARRAY_SIZE; fieldIntersection_index++) {
311 if (len >= bufferSize) {
312 return toString;
313 }
314 if (fieldIntersection_index > 0) {
315 len = gu_strlcat(toString, ", ", bufferSize);
316 }
317 len = gu_strlcat(toString, "{", bufferSize);
318 if (len >= bufferSize) {
319 return toString;
320 }
321 char fieldIntersection_1_buffer[VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE];
322 char* fieldIntersection_1_p = fieldIntersection_1_buffer;
323 const char* fieldIntersection_1_to_string = wb_vision_field_feature_to_string(&self->fieldIntersection[fieldIntersection_index], fieldIntersection_1_p, VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE);
324 len = gu_strlcat(toString, fieldIntersection_1_p, bufferSize);
325 if (len >= bufferSize) {
326 return toString;
327 }
328 len = gu_strlcat(toString, "}", bufferSize);
329 }
330 if (len >= bufferSize) {
331 return toString;
332 }
333 len = gu_strlcat(toString, "}", bufferSize);
334 if (len >= bufferSize) {
335 return toString;
336 }
337 len = gu_strlcat(toString, ", ", bufferSize);
338 if (len >= bufferSize) {
339 return toString;
340 }
341 len = gu_strlcat(toString, "{", bufferSize);
342 for (int fieldCrosses_index = 0; fieldCrosses_index < VISION_FIELD_FEATURES_FIELDCROSSES_ARRAY_SIZE; fieldCrosses_index++) {
343 if (len >= bufferSize) {
344 return toString;
345 }
346 if (fieldCrosses_index > 0) {
347 len = gu_strlcat(toString, ", ", bufferSize);
348 }
349 len = gu_strlcat(toString, "{", bufferSize);
350 if (len >= bufferSize) {
351 return toString;
352 }
353 char fieldCrosses_1_buffer[VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE];
354 char* fieldCrosses_1_p = fieldCrosses_1_buffer;
355 const char* fieldCrosses_1_to_string = wb_vision_field_feature_to_string(&self->fieldCrosses[fieldCrosses_index], fieldCrosses_1_p, VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE);
356 len = gu_strlcat(toString, fieldCrosses_1_p, bufferSize);
357 if (len >= bufferSize) {
358 return toString;
359 }
360 len = gu_strlcat(toString, "}", bufferSize);
361 }
362 if (len >= bufferSize) {
363 return toString;
364 }
365 len = gu_strlcat(toString, "}", bufferSize);
366 if (len >= bufferSize) {
367 return toString;
368 }
369 len = gu_strlcat(toString, ", ", bufferSize);
370 if (len >= bufferSize) {
371 return toString;
372 }
373 len += snprintf(toString + len, bufferSize - len, "%u", self->numCorners);
374 if (len >= bufferSize) {
375 return toString;
376 }
377 len = gu_strlcat(toString, ", ", bufferSize);
378 if (len >= bufferSize) {
379 return toString;
380 }
381 len += snprintf(toString + len, bufferSize - len, "%u", self->numIntersections);
382 if (len >= bufferSize) {
383 return toString;
384 }
385 len = gu_strlcat(toString, ", ", bufferSize);
386 if (len >= bufferSize) {
387 return toString;
388 }
389 len += snprintf(toString + len, bufferSize - len, "%u", self->numCrosses);
390 if (len >= bufferSize) {
391 return toString;
392 }
393 len = gu_strlcat(toString, ", ", bufferSize);
394 if (len >= bufferSize) {
395 return toString;
396 }
397 len += snprintf(toString + len, bufferSize - len, "%u", self->res_width);
398 if (len >= bufferSize) {
399 return toString;
400 }
401 len = gu_strlcat(toString, ", ", bufferSize);
402 if (len >= bufferSize) {
403 return toString;
404 }
405 len += snprintf(toString + len, bufferSize - len, "%u", self->res_height);
406 return toString;
407#pragma clang diagnostic pop
408}
409
414{
415 size_t temp_length = strlen(str);
416 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
417 if (length < 1 || length > VISION_FIELD_FEATURES_DESC_BUFFER_SIZE) {
418 return self;
419 }
420 char var_str_buffer[VISION_FIELD_FEATURES_DESC_BUFFER_SIZE + 1];
421 char* var_str = &var_str_buffer[0];
422 char key_buffer[18];
423 char* key = &key_buffer[0];
424 int bracecount = 0;
425 int lastBrace = -1;
426 int startVar = 0;
427 int index = 0;
428 int startKey = 0;
429 int endKey = -1;
430 int varIndex = 0;
431 if (index == 0 && str[0] == '{') {
432 index = 1;
433 }
434 startVar = index;
435 startKey = startVar;
436 do {
437 for (int i = index; i < length; i++) {
438 index = i + 1;
439 if (bracecount == 0 && str[i] == '=') {
440 endKey = i - 1;
441 startVar = index;
442 continue;
443 }
444 if (bracecount == 0 && isspace(str[i])) {
445 startVar = index;
446 if (endKey == -1) {
447 startKey = index;
448 }
449 continue;
450 }
451 if (bracecount == 0 && str[i] == ',') {
452 index = i - 1;
453 break;
454 }
455 if (str[i] == '{') {
456 bracecount++;
457 if (bracecount == 1) {
458 lastBrace = i;
459 }
460 continue;
461 }
462 if (str[i] == '}') {
463 bracecount--;
464 if (bracecount < 0) {
465 index = i - 1;
466 break;
467 }
468 }
469 if (i == length - 1) {
470 index = i;
471 }
472 }
473 if (endKey >= startKey && endKey - startKey < length) {
474 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
475 key[(endKey - startKey) + 1] = 0;
476 } else {
477 key[0] = 0;
478 }
479 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
480 var_str[(index - startVar) + 1] = 0;
481 bracecount = 0;
482 index += 2;
483 startVar = index;
484 startKey = startVar;
485 endKey = -1;
486 if (strlen(key) > 0) {
487 if (0 == strcmp("fieldCorner", key)) {
488 varIndex = 0;
489 } else if (0 == strcmp("fieldIntersection", key)) {
490 varIndex = 1;
491 } else if (0 == strcmp("fieldCrosses", key)) {
492 varIndex = 2;
493 } else if (0 == strcmp("numCorners", key)) {
494 varIndex = 3;
495 } else if (0 == strcmp("numIntersections", key)) {
496 varIndex = 4;
497 } else if (0 == strcmp("numCrosses", key)) {
498 varIndex = 5;
499 } else if (0 == strcmp("res_width", key)) {
500 varIndex = 6;
501 } else if (0 == strcmp("res_height", key)) {
502 varIndex = 7;
503 } else {
504 varIndex = -1;
505 }
506 }
507 switch (varIndex) {
508 case -1: { break; }
509 case 0:
510 {
511 int restartIndex = index;
512 index = lastBrace + 1;
513 startVar = index;
514 startKey = startVar;
515 endKey = -1;
516 bracecount = 0;
517 for (int fieldCorner_0_index = 0; fieldCorner_0_index < VISION_FIELD_FEATURES_FIELDCORNER_ARRAY_SIZE; fieldCorner_0_index++) {
518 for (int i = index; i < length; i++) {
519 index = i + 1;
520 if (bracecount == 0 && str[i] == '=') {
521 endKey = i - 1;
522 startVar = index;
523 continue;
524 }
525 if (bracecount == 0 && isspace(str[i])) {
526 startVar = index;
527 if (endKey == -1) {
528 startKey = index;
529 }
530 continue;
531 }
532 if (bracecount == 0 && str[i] == ',') {
533 index = i - 1;
534 break;
535 }
536 if (str[i] == '{') {
537 bracecount++;
538 continue;
539 }
540 if (str[i] == '}') {
541 bracecount--;
542 if (bracecount < 0) {
543 index = i - 1;
544 break;
545 }
546 }
547 if (i == length - 1) {
548 index = i;
549 }
550 }
551 if (endKey >= startKey && endKey - startKey < length) {
552 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
553 key[(endKey - startKey) + 1] = 0;
554 } else {
555 key[0] = 0;
556 }
557 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
558 var_str[(index - startVar) + 1] = 0;
559 bracecount = 0;
560 index += 2;
561 startVar = index;
562 startKey = startVar;
563 endKey = -1;
564 struct wb_vision_field_feature fieldCorner_0 = {};
565 wb_vision_field_feature_from_string(&fieldCorner_0, var_str);
566 self->fieldCorner[fieldCorner_0_index] = fieldCorner_0;
567 }
568 index = restartIndex;
569 break;
570 }
571 case 1:
572 {
573 int restartIndex = index;
574 index = lastBrace + 1;
575 startVar = index;
576 startKey = startVar;
577 endKey = -1;
578 bracecount = 0;
579 for (int fieldIntersection_0_index = 0; fieldIntersection_0_index < VISION_FIELD_FEATURES_FIELDINTERSECTION_ARRAY_SIZE; fieldIntersection_0_index++) {
580 for (int i = index; i < length; i++) {
581 index = i + 1;
582 if (bracecount == 0 && str[i] == '=') {
583 endKey = i - 1;
584 startVar = index;
585 continue;
586 }
587 if (bracecount == 0 && isspace(str[i])) {
588 startVar = index;
589 if (endKey == -1) {
590 startKey = index;
591 }
592 continue;
593 }
594 if (bracecount == 0 && str[i] == ',') {
595 index = i - 1;
596 break;
597 }
598 if (str[i] == '{') {
599 bracecount++;
600 continue;
601 }
602 if (str[i] == '}') {
603 bracecount--;
604 if (bracecount < 0) {
605 index = i - 1;
606 break;
607 }
608 }
609 if (i == length - 1) {
610 index = i;
611 }
612 }
613 if (endKey >= startKey && endKey - startKey < length) {
614 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
615 key[(endKey - startKey) + 1] = 0;
616 } else {
617 key[0] = 0;
618 }
619 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
620 var_str[(index - startVar) + 1] = 0;
621 bracecount = 0;
622 index += 2;
623 startVar = index;
624 startKey = startVar;
625 endKey = -1;
626 struct wb_vision_field_feature fieldIntersection_0 = {};
627 wb_vision_field_feature_from_string(&fieldIntersection_0, var_str);
628 self->fieldIntersection[fieldIntersection_0_index] = fieldIntersection_0;
629 }
630 index = restartIndex;
631 break;
632 }
633 case 2:
634 {
635 int restartIndex = index;
636 index = lastBrace + 1;
637 startVar = index;
638 startKey = startVar;
639 endKey = -1;
640 bracecount = 0;
641 for (int fieldCrosses_0_index = 0; fieldCrosses_0_index < VISION_FIELD_FEATURES_FIELDCROSSES_ARRAY_SIZE; fieldCrosses_0_index++) {
642 for (int i = index; i < length; i++) {
643 index = i + 1;
644 if (bracecount == 0 && str[i] == '=') {
645 endKey = i - 1;
646 startVar = index;
647 continue;
648 }
649 if (bracecount == 0 && isspace(str[i])) {
650 startVar = index;
651 if (endKey == -1) {
652 startKey = index;
653 }
654 continue;
655 }
656 if (bracecount == 0 && str[i] == ',') {
657 index = i - 1;
658 break;
659 }
660 if (str[i] == '{') {
661 bracecount++;
662 continue;
663 }
664 if (str[i] == '}') {
665 bracecount--;
666 if (bracecount < 0) {
667 index = i - 1;
668 break;
669 }
670 }
671 if (i == length - 1) {
672 index = i;
673 }
674 }
675 if (endKey >= startKey && endKey - startKey < length) {
676 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
677 key[(endKey - startKey) + 1] = 0;
678 } else {
679 key[0] = 0;
680 }
681 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
682 var_str[(index - startVar) + 1] = 0;
683 bracecount = 0;
684 index += 2;
685 startVar = index;
686 startKey = startVar;
687 endKey = -1;
688 struct wb_vision_field_feature fieldCrosses_0 = {};
689 wb_vision_field_feature_from_string(&fieldCrosses_0, var_str);
690 self->fieldCrosses[fieldCrosses_0_index] = fieldCrosses_0;
691 }
692 index = restartIndex;
693 break;
694 }
695 case 3:
696 {
697 self->numCorners = ((uint8_t)atoi(var_str));
698 break;
699 }
700 case 4:
701 {
702 self->numIntersections = ((uint8_t)atoi(var_str));
703 break;
704 }
705 case 5:
706 {
707 self->numCrosses = ((uint8_t)atoi(var_str));
708 break;
709 }
710 case 6:
711 {
712 self->res_width = ((uint16_t)atoi(var_str));
713 break;
714 }
715 case 7:
716 {
717 self->res_height = ((uint16_t)atoi(var_str));
718 break;
719 }
720 }
721 if (varIndex >= 0) {
722 varIndex++;
723 }
724 } while(index < length);
725 return self;
726}
727
728/*#ifdef WHITEBOARD_SERIALISATION*/
729
734{
735 uint16_t bit_offset = 0;
736 //Class generator does not support array network compression.
737 //Copying into the buffer, uncompressed
738 do { //limit declaration scope
739 uint32_t len = 8;
740 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
741 const char *buf = (const char *)&self->fieldCorner[0];
742 uint32_t c;
743 int8_t b;
744 for (c = 0; c < bytes; c++) {
745 for (b = 7; b >= 0; b--) {
746 do {
747 uint16_t byte = bit_offset / 8;
748 uint16_t bit = 7 - (bit_offset % 8);
749 unsigned long newbit = !!((buf[c] >> b) & 1U);
750 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
751 bit_offset = bit_offset + 1;
752 } while(false);
753 }
754 }
755 } while(false);
756
757 //Class generator does not support array network compression.
758 //Copying into the buffer, uncompressed
759 do { //limit declaration scope
760 uint32_t len = 8;
761 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
762 const char *buf = (const char *)&self->fieldIntersection[0];
763 uint32_t c;
764 int8_t b;
765 for (c = 0; c < bytes; c++) {
766 for (b = 7; b >= 0; b--) {
767 do {
768 uint16_t byte = bit_offset / 8;
769 uint16_t bit = 7 - (bit_offset % 8);
770 unsigned long newbit = !!((buf[c] >> b) & 1U);
771 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
772 bit_offset = bit_offset + 1;
773 } while(false);
774 }
775 }
776 } while(false);
777
778 //Class generator does not support array network compression.
779 //Copying into the buffer, uncompressed
780 do { //limit declaration scope
781 uint32_t len = 3;
782 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
783 const char *buf = (const char *)&self->fieldCrosses[0];
784 uint32_t c;
785 int8_t b;
786 for (c = 0; c < bytes; c++) {
787 for (b = 7; b >= 0; b--) {
788 do {
789 uint16_t byte = bit_offset / 8;
790 uint16_t bit = 7 - (bit_offset % 8);
791 unsigned long newbit = !!((buf[c] >> b) & 1U);
792 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
793 bit_offset = bit_offset + 1;
794 } while(false);
795 }
796 }
797 } while(false);
798
799 uint8_t numCorners_nbo = (self->numCorners);
800 do {
801 int8_t b;
802 for (b = (8 - 1); b >= 0; b--) {
803 do {
804 uint16_t byte = bit_offset / 8;
805 uint16_t bit = 7 - (bit_offset % 8);
806 unsigned long newbit = !!((numCorners_nbo >> b) & 1U);
807 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
808 bit_offset = bit_offset + 1;
809 } while(false);
810 }
811 } while(false);
812
813 uint8_t numIntersections_nbo = (self->numIntersections);
814 do {
815 int8_t b;
816 for (b = (8 - 1); b >= 0; b--) {
817 do {
818 uint16_t byte = bit_offset / 8;
819 uint16_t bit = 7 - (bit_offset % 8);
820 unsigned long newbit = !!((numIntersections_nbo >> b) & 1U);
821 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
822 bit_offset = bit_offset + 1;
823 } while(false);
824 }
825 } while(false);
826
827 uint8_t numCrosses_nbo = (self->numCrosses);
828 do {
829 int8_t b;
830 for (b = (8 - 1); b >= 0; b--) {
831 do {
832 uint16_t byte = bit_offset / 8;
833 uint16_t bit = 7 - (bit_offset % 8);
834 unsigned long newbit = !!((numCrosses_nbo >> b) & 1U);
835 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
836 bit_offset = bit_offset + 1;
837 } while(false);
838 }
839 } while(false);
840
841 uint16_t res_width_nbo = htons(self->res_width);
842 do {
843 int8_t b;
844 for (b = (16 - 1); b >= 0; b--) {
845 do {
846 uint16_t byte = bit_offset / 8;
847 uint16_t bit = 7 - (bit_offset % 8);
848 unsigned long newbit = !!((res_width_nbo >> b) & 1U);
849 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
850 bit_offset = bit_offset + 1;
851 } while(false);
852 }
853 } while(false);
854
855 uint16_t res_height_nbo = htons(self->res_height);
856 do {
857 int8_t b;
858 for (b = (16 - 1); b >= 0; b--) {
859 do {
860 uint16_t byte = bit_offset / 8;
861 uint16_t bit = 7 - (bit_offset % 8);
862 unsigned long newbit = !!((res_height_nbo >> b) & 1U);
863 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
864 bit_offset = bit_offset + 1;
865 } while(false);
866 }
867 } while(false);
868 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
869 (void)self;
870 (void)dst;
871 return bit_offset;
872}
873
878{
879 uint16_t bit_offset = 0;
880 //Class generator does not support array network compression.
881 //Copying into the buffer, uncompressed
882 do { //limit declaration scope
883 uint32_t len = 8;
884 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
885 char *buf = (char *)malloc(bytes);
886 uint32_t c;
887 int8_t b;
888 for (c = 0; c < bytes; c++) {
889 for (b = 7; b >= 0; b--) {
890 do {
891 uint16_t byte = bit_offset / 8;
892 uint16_t bit = 7 - (bit_offset % 8);
893 char dataByte = src[byte];
894 unsigned char bitValue = (dataByte >> bit) & 1U;
895 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
896 bit_offset = bit_offset + 1;
897 } while(false);
898 }
899 }
900 memcpy(&dst->fieldCorner[0], &buf[0], bytes);
901 free(buf);
902 } while(false);
903
904 //Class generator does not support array network compression.
905 //Copying into the buffer, uncompressed
906 do { //limit declaration scope
907 uint32_t len = 8;
908 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
909 char *buf = (char *)malloc(bytes);
910 uint32_t c;
911 int8_t b;
912 for (c = 0; c < bytes; c++) {
913 for (b = 7; b >= 0; b--) {
914 do {
915 uint16_t byte = bit_offset / 8;
916 uint16_t bit = 7 - (bit_offset % 8);
917 char dataByte = src[byte];
918 unsigned char bitValue = (dataByte >> bit) & 1U;
919 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
920 bit_offset = bit_offset + 1;
921 } while(false);
922 }
923 }
924 memcpy(&dst->fieldIntersection[0], &buf[0], bytes);
925 free(buf);
926 } while(false);
927
928 //Class generator does not support array network compression.
929 //Copying into the buffer, uncompressed
930 do { //limit declaration scope
931 uint32_t len = 3;
932 uint32_t bytes = len * sizeof(struct wb_vision_field_feature);
933 char *buf = (char *)malloc(bytes);
934 uint32_t c;
935 int8_t b;
936 for (c = 0; c < bytes; c++) {
937 for (b = 7; b >= 0; b--) {
938 do {
939 uint16_t byte = bit_offset / 8;
940 uint16_t bit = 7 - (bit_offset % 8);
941 char dataByte = src[byte];
942 unsigned char bitValue = (dataByte >> bit) & 1U;
943 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
944 bit_offset = bit_offset + 1;
945 } while(false);
946 }
947 }
948 memcpy(&dst->fieldCrosses[0], &buf[0], bytes);
949 free(buf);
950 } while(false);
951
952 do {
953 int8_t b;
954 for (b = (8 - 1); b >= 0; b--) {
955 do {
956 uint16_t byte = bit_offset / 8;
957 uint16_t bit = 7 - (bit_offset % 8);
958 char dataByte = src[byte];
959 unsigned char bitValue = (dataByte >> bit) & 1U;
960 dst->numCorners ^= (-bitValue ^ dst->numCorners) & (1UL << b);
961 bit_offset = bit_offset + 1;
962 } while(false);
963 }
964 } while(false);
965 dst->numCorners = (dst->numCorners);
966
967 do {
968 int8_t b;
969 for (b = (8 - 1); b >= 0; b--) {
970 do {
971 uint16_t byte = bit_offset / 8;
972 uint16_t bit = 7 - (bit_offset % 8);
973 char dataByte = src[byte];
974 unsigned char bitValue = (dataByte >> bit) & 1U;
975 dst->numIntersections ^= (-bitValue ^ dst->numIntersections) & (1UL << b);
976 bit_offset = bit_offset + 1;
977 } while(false);
978 }
979 } while(false);
981
982 do {
983 int8_t b;
984 for (b = (8 - 1); b >= 0; b--) {
985 do {
986 uint16_t byte = bit_offset / 8;
987 uint16_t bit = 7 - (bit_offset % 8);
988 char dataByte = src[byte];
989 unsigned char bitValue = (dataByte >> bit) & 1U;
990 dst->numCrosses ^= (-bitValue ^ dst->numCrosses) & (1UL << b);
991 bit_offset = bit_offset + 1;
992 } while(false);
993 }
994 } while(false);
995 dst->numCrosses = (dst->numCrosses);
996
997 do {
998 int8_t b;
999 for (b = (16 - 1); b >= 0; b--) {
1000 do {
1001 uint16_t byte = bit_offset / 8;
1002 uint16_t bit = 7 - (bit_offset % 8);
1003 char dataByte = src[byte];
1004 unsigned char bitValue = (dataByte >> bit) & 1U;
1005 dst->res_width ^= (-bitValue ^ dst->res_width) & (1UL << b);
1006 bit_offset = bit_offset + 1;
1007 } while(false);
1008 }
1009 } while(false);
1010 dst->res_width = ntohs(dst->res_width);
1011
1012 do {
1013 int8_t b;
1014 for (b = (16 - 1); b >= 0; b--) {
1015 do {
1016 uint16_t byte = bit_offset / 8;
1017 uint16_t bit = 7 - (bit_offset % 8);
1018 char dataByte = src[byte];
1019 unsigned char bitValue = (dataByte >> bit) & 1U;
1020 dst->res_height ^= (-bitValue ^ dst->res_height) & (1UL << b);
1021 bit_offset = bit_offset + 1;
1022 } while(false);
1023 }
1024 } while(false);
1025 dst->res_height = ntohs(dst->res_height);
1026 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
1027 (void)src;
1028 (void)dst;
1029 return bit_offset;
1030}
1031
1032/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
Posting by Vision of the field corners, T-Intersections and crosses that have been seen.
uint8_t numCrosses
Numer of Crosses in this message.
uint8_t numCorners
Number of corners in this message.
uint16_t res_width
The resolution width.
struct wb_vision_field_feature fieldIntersection[8]
Location of T-Intersections on the field.
uint8_t numIntersections
Number of T-Intersections in this message.
struct wb_vision_field_feature fieldCorner[8]
Location of corners on the field.
uint16_t res_height
The resolution height.
struct wb_vision_field_feature fieldCrosses[3]
Location of T-Intersections on the field.
const char * wb_vision_field_feature_to_string(const struct wb_vision_field_feature *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_vision_field_feature_description(const struct wb_vision_field_feature *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_vision_field_feature * wb_vision_field_feature_from_string(struct wb_vision_field_feature *self, const char *str)
Convert from a string.
#define VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE
#define VISION_FIELD_FEATURE_DESC_BUFFER_SIZE
struct wb_vision_field_features * wb_vision_field_features_from_string(struct wb_vision_field_features *self, const char *str)
Convert from a string.
const char * wb_vision_field_features_to_string(const struct wb_vision_field_features *self, char *toString, size_t bufferSize)
Convert to a string.
#define htons(x)
size_t wb_vision_field_features_to_network_serialised(const struct wb_vision_field_features *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define ntohs(x)
size_t wb_vision_field_features_from_network_serialised(const char *src, struct wb_vision_field_features *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_vision_field_features_description(const struct wb_vision_field_features *self, char *descString, size_t bufferSize)
Convert to a description string.
#define VISION_FIELD_FEATURES_FIELDCORNER_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define VISION_FIELD_FEATURES_DESC_BUFFER_SIZE
#define VISION_FIELD_FEATURES_FIELDCROSSES_ARRAY_SIZE
#define VISION_FIELD_FEATURES_FIELDINTERSECTION_ARRAY_SIZE