60#ifndef WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
77#elif defined(__APPLE__)
78# include <machine/endian.h>
79# include <architecture/byte_order.h>
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
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)
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
109# if !defined(htonl) && !defined(ntohl)
113# if !defined(htons) && !defined(ntohs)
118#pragma clang diagnostic pop
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
130 if (len >= bufferSize) {
133 len += snprintf(descString + len, bufferSize - len,
"ball_direction=%d", self->ball_direction);
134 if (len >= bufferSize) {
137 len = gu_strlcat(descString,
", ", bufferSize);
138 if (len >= bufferSize) {
141 len += snprintf(descString + len, bufferSize - len,
"ball_distance=%u", self->ball_distance);
142 if (len >= bufferSize) {
145 len = gu_strlcat(descString,
", ", bufferSize);
146 if (len >= bufferSize) {
149 len = gu_strlcat(descString, self->ball_visible ?
"ball_visible=true" :
"ball_visible=false", bufferSize);
150 if (len >= bufferSize) {
153 len = gu_strlcat(descString,
", ", bufferSize);
154 if (len >= bufferSize) {
157 len += snprintf(descString + len, bufferSize - len,
"goal_direction=%d", self->goal_direction);
158 if (len >= bufferSize) {
161 len = gu_strlcat(descString,
", ", bufferSize);
162 if (len >= bufferSize) {
165 len += snprintf(descString + len, bufferSize - len,
"goal_distance=%u", self->goal_distance);
166 if (len >= bufferSize) {
169 len = gu_strlcat(descString,
", ", bufferSize);
170 if (len >= bufferSize) {
173 len = gu_strlcat(descString, self->goal_visible ?
"goal_visible=true" :
"goal_visible=false", bufferSize);
174 if (len >= bufferSize) {
177 len = gu_strlcat(descString,
", ", bufferSize);
178 if (len >= bufferSize) {
181 switch (self->goal_sightingType) {
184 len += snprintf(descString + len, bufferSize - len,
"goal_sightingType=GoalSightingType");
189 len += snprintf(descString + len, bufferSize - len,
"goal_sightingType=LeftPostSightingType");
194 len += snprintf(descString + len, bufferSize - len,
"goal_sightingType=NoSightingType");
199 len += snprintf(descString + len, bufferSize - len,
"goal_sightingType=RightPostSightingType");
204#pragma clang diagnostic pop
212#pragma clang diagnostic push
213#pragma clang diagnostic ignored "-Wunused-variable"
215 if (len >= bufferSize) {
218 len += snprintf(toString + len, bufferSize - len,
"%d", self->ball_direction);
219 if (len >= bufferSize) {
222 len = gu_strlcat(toString,
", ", bufferSize);
223 if (len >= bufferSize) {
226 len += snprintf(toString + len, bufferSize - len,
"%u", self->ball_distance);
227 if (len >= bufferSize) {
230 len = gu_strlcat(toString,
", ", bufferSize);
231 if (len >= bufferSize) {
234 len = gu_strlcat(toString, self->ball_visible ?
"true" :
"false", bufferSize);
235 if (len >= bufferSize) {
238 len = gu_strlcat(toString,
", ", bufferSize);
239 if (len >= bufferSize) {
242 len += snprintf(toString + len, bufferSize - len,
"%d", self->goal_direction);
243 if (len >= bufferSize) {
246 len = gu_strlcat(toString,
", ", bufferSize);
247 if (len >= bufferSize) {
250 len += snprintf(toString + len, bufferSize - len,
"%u", self->goal_distance);
251 if (len >= bufferSize) {
254 len = gu_strlcat(toString,
", ", bufferSize);
255 if (len >= bufferSize) {
258 len = gu_strlcat(toString, self->goal_visible ?
"true" :
"false", bufferSize);
259 if (len >= bufferSize) {
262 len = gu_strlcat(toString,
", ", bufferSize);
263 if (len >= bufferSize) {
266 switch (self->goal_sightingType) {
269 len += snprintf(toString + len, bufferSize - len,
"GoalSightingType");
274 len += snprintf(toString + len, bufferSize - len,
"LeftPostSightingType");
279 len += snprintf(toString + len, bufferSize - len,
"NoSightingType");
284 len += snprintf(toString + len, bufferSize - len,
"RightPostSightingType");
289#pragma clang diagnostic pop
297 size_t temp_length = strlen(str);
298 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
303 char* var_str = &var_str_buffer[0];
305 char* key = &key_buffer[0];
312 if (index == 0 && str[0] ==
'{') {
318 for (
int i = index; i < length; i++) {
320 if (bracecount == 0 && str[i] ==
'=') {
325 if (bracecount == 0 && isspace(str[i])) {
332 if (bracecount == 0 && str[i] ==
',') {
342 if (bracecount < 0) {
347 if (i == length - 1) {
351 if (endKey >= startKey && endKey - startKey < length) {
352 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
353 key[(endKey - startKey) + 1] = 0;
357 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
358 var_str[(index - startVar) + 1] = 0;
364 if (strlen(key) > 0) {
365 if (0 == strcmp(
"ball_direction", key)) {
367 }
else if (0 == strcmp(
"ball_distance", key)) {
369 }
else if (0 == strcmp(
"ball_visible", key)) {
371 }
else if (0 == strcmp(
"goal_direction", key)) {
373 }
else if (0 == strcmp(
"goal_distance", key)) {
375 }
else if (0 == strcmp(
"goal_visible", key)) {
377 }
else if (0 == strcmp(
"goal_sightingType", key)) {
387 self->ball_direction = ((int8_t)atoi(var_str));
392 self->ball_distance = ((uint16_t)atoi(var_str));
397 self->ball_visible = strcmp(var_str,
"true") == 0 || strcmp(var_str,
"1") == 0;
402 self->goal_direction = ((int8_t)atoi(var_str));
407 self->goal_distance = ((uint16_t)atoi(var_str));
412 self->goal_visible = strcmp(var_str,
"true") == 0 || strcmp(var_str,
"1") == 0;
417 if (strcmp(
"GoalSightingType", var_str) == 0) {
418#pragma clang diagnostic push
419#pragma clang diagnostic ignored "-Wbad-function-cast"
421#pragma clang diagnostic pop
422 }
else if (strcmp(
"LeftPostSightingType", var_str) == 0) {
423#pragma clang diagnostic push
424#pragma clang diagnostic ignored "-Wbad-function-cast"
426#pragma clang diagnostic pop
427 }
else if (strcmp(
"NoSightingType", var_str) == 0) {
428#pragma clang diagnostic push
429#pragma clang diagnostic ignored "-Wbad-function-cast"
431#pragma clang diagnostic pop
432 }
else if (strcmp(
"RightPostSightingType", var_str) == 0) {
433#pragma clang diagnostic push
434#pragma clang diagnostic ignored "-Wbad-function-cast"
436#pragma clang diagnostic pop
438#pragma clang diagnostic push
439#pragma clang diagnostic ignored "-Wbad-function-cast"
441#pragma clang diagnostic pop
449 }
while(index < length);
460 uint16_t bit_offset = 0;
461 int8_t ball_direction_nbo = (
self->ball_direction);
464 for (b = (8 - 1); b >= 0; b--) {
466 uint16_t
byte = bit_offset / 8;
467 uint16_t bit = 7 - (bit_offset % 8);
468 unsigned long newbit = !!((ball_direction_nbo >> b) & 1U);
469 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
470 bit_offset = bit_offset + 1;
475 uint16_t ball_distance_nbo =
htons(self->ball_distance);
478 for (b = (16 - 1); b >= 0; b--) {
480 uint16_t
byte = bit_offset / 8;
481 uint16_t bit = 7 - (bit_offset % 8);
482 unsigned long newbit = !!((ball_distance_nbo >> b) & 1U);
483 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
484 bit_offset = bit_offset + 1;
490 uint16_t
byte = bit_offset / 8;
491 uint16_t bit = 7 - (bit_offset % 8);
492 unsigned long newbit = !!(
self->ball_visible ? 1U : 0U);
493 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
494 bit_offset = bit_offset + 1;
497 int8_t goal_direction_nbo = (
self->goal_direction);
500 for (b = (8 - 1); b >= 0; b--) {
502 uint16_t
byte = bit_offset / 8;
503 uint16_t bit = 7 - (bit_offset % 8);
504 unsigned long newbit = !!((goal_direction_nbo >> b) & 1U);
505 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
506 bit_offset = bit_offset + 1;
511 uint16_t goal_distance_nbo =
htons(self->goal_distance);
514 for (b = (16 - 1); b >= 0; b--) {
516 uint16_t
byte = bit_offset / 8;
517 uint16_t bit = 7 - (bit_offset % 8);
518 unsigned long newbit = !!((goal_distance_nbo >> b) & 1U);
519 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
520 bit_offset = bit_offset + 1;
526 uint16_t
byte = bit_offset / 8;
527 uint16_t bit = 7 - (bit_offset % 8);
528 unsigned long newbit = !!(
self->goal_visible ? 1U : 0U);
529 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
530 bit_offset = bit_offset + 1;
536 for (b = (32 - 1); b >= 0; b--) {
538 uint16_t
byte = bit_offset / 8;
539 uint16_t bit = 7 - (bit_offset % 8);
540 unsigned long newbit = !!((goal_sightingType_nbo >> b) & 1U);
541 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
542 bit_offset = bit_offset + 1;
557 uint16_t bit_offset = 0;
560 for (b = (8 - 1); b >= 0; b--) {
562 uint16_t
byte = bit_offset / 8;
563 uint16_t bit = 7 - (bit_offset % 8);
564 char dataByte = src[byte];
565 unsigned char bitValue = (dataByte >> bit) & 1U;
567 bit_offset = bit_offset + 1;
575 for (b = (16 - 1); b >= 0; b--) {
577 uint16_t
byte = bit_offset / 8;
578 uint16_t bit = 7 - (bit_offset % 8);
579 char dataByte = src[byte];
580 unsigned char bitValue = (dataByte >> bit) & 1U;
582 bit_offset = bit_offset + 1;
589 uint16_t
byte = bit_offset / 8;
590 uint16_t bit = 7 - (bit_offset % 8);
591 char dataByte = src[byte];
592 unsigned char bitValue = (dataByte >> bit) & 1U;
594 bit_offset = bit_offset + 1;
599 for (b = (8 - 1); b >= 0; b--) {
601 uint16_t
byte = bit_offset / 8;
602 uint16_t bit = 7 - (bit_offset % 8);
603 char dataByte = src[byte];
604 unsigned char bitValue = (dataByte >> bit) & 1U;
606 bit_offset = bit_offset + 1;
614 for (b = (16 - 1); b >= 0; b--) {
616 uint16_t
byte = bit_offset / 8;
617 uint16_t bit = 7 - (bit_offset % 8);
618 char dataByte = src[byte];
619 unsigned char bitValue = (dataByte >> bit) & 1U;
621 bit_offset = bit_offset + 1;
628 uint16_t
byte = bit_offset / 8;
629 uint16_t bit = 7 - (bit_offset % 8);
630 char dataByte = src[byte];
631 unsigned char bitValue = (dataByte >> bit) & 1U;
633 bit_offset = bit_offset + 1;
638 for (b = (32 - 1); b >= 0; b--) {
640 uint16_t
byte = bit_offset / 8;
641 uint16_t bit = 7 - (bit_offset % 8);
642 char dataByte = src[byte];
643 unsigned char bitValue = (dataByte >> bit) & 1U;
645 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
uint16_t goal_distance
CM distance to the ball.
enum GoalSightingType goal_sightingType
The type of the goal sighting.
bool ball_visible
has the ball been seen enough by vision to be considered actually 'visible'.
bool goal_visible
has the ball been seen enough by vision to be considered actually 'visible'.
uint16_t ball_distance
CM distance to the ball.
int8_t goal_direction
degrees, relative to the center of the nao torso.
int8_t ball_direction
degrees, relative to the center of the nao torso.
size_t wb_machine_filtered_vision_to_network_serialised(const struct wb_machine_filtered_vision *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_machine_filtered_vision_to_string(const struct wb_machine_filtered_vision *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_machine_filtered_vision * wb_machine_filtered_vision_from_string(struct wb_machine_filtered_vision *self, const char *str)
Convert from a string.
size_t wb_machine_filtered_vision_from_network_serialised(const char *src, struct wb_machine_filtered_vision *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_machine_filtered_vision_description(const struct wb_machine_filtered_vision *self, char *descString, size_t bufferSize)
Convert to a description string.
#define MACHINE_FILTERED_VISION_DESC_BUFFER_SIZE