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,
"direction=%d", self->direction);
134 if (len >= bufferSize) {
137 len = gu_strlcat(descString,
", ", bufferSize);
138 if (len >= bufferSize) {
141 len += snprintf(descString + len, bufferSize - len,
"distance=%u", self->distance);
142 if (len >= bufferSize) {
145 len = gu_strlcat(descString,
", ", bufferSize);
146 if (len >= bufferSize) {
149 switch (self->sightingType) {
152 len += snprintf(descString + len, bufferSize - len,
"sightingType=BallSightingType");
157 len += snprintf(descString + len, bufferSize - len,
"sightingType=CornerHorizonSightingType");
162 len += snprintf(descString + len, bufferSize - len,
"sightingType=CornerLineSightingType");
167 len += snprintf(descString + len, bufferSize - len,
"sightingType=CrossLineSightingType");
172 len += snprintf(descString + len, bufferSize - len,
"sightingType=GenericGoalPostSightingType");
177 len += snprintf(descString + len, bufferSize - len,
"sightingType=GoalLandmarkSightingType");
182 len += snprintf(descString + len, bufferSize - len,
"sightingType=LeftGoalPostSightingType");
187 len += snprintf(descString + len, bufferSize - len,
"sightingType=LineHorizonSightingType");
192 len += snprintf(descString + len, bufferSize - len,
"sightingType=RightGoalPostSightingType");
197 len += snprintf(descString + len, bufferSize - len,
"sightingType=StraightLineSightingType");
202 len += snprintf(descString + len, bufferSize - len,
"sightingType=TIntersectionLineSightingType");
207#pragma clang diagnostic pop
215#pragma clang diagnostic push
216#pragma clang diagnostic ignored "-Wunused-variable"
218 if (len >= bufferSize) {
221 len += snprintf(toString + len, bufferSize - len,
"%d", self->direction);
222 if (len >= bufferSize) {
225 len = gu_strlcat(toString,
", ", bufferSize);
226 if (len >= bufferSize) {
229 len += snprintf(toString + len, bufferSize - len,
"%u", self->distance);
230 if (len >= bufferSize) {
233 len = gu_strlcat(toString,
", ", bufferSize);
234 if (len >= bufferSize) {
237 switch (self->sightingType) {
240 len += snprintf(toString + len, bufferSize - len,
"BallSightingType");
245 len += snprintf(toString + len, bufferSize - len,
"CornerHorizonSightingType");
250 len += snprintf(toString + len, bufferSize - len,
"CornerLineSightingType");
255 len += snprintf(toString + len, bufferSize - len,
"CrossLineSightingType");
260 len += snprintf(toString + len, bufferSize - len,
"GenericGoalPostSightingType");
265 len += snprintf(toString + len, bufferSize - len,
"GoalLandmarkSightingType");
270 len += snprintf(toString + len, bufferSize - len,
"LeftGoalPostSightingType");
275 len += snprintf(toString + len, bufferSize - len,
"LineHorizonSightingType");
280 len += snprintf(toString + len, bufferSize - len,
"RightGoalPostSightingType");
285 len += snprintf(toString + len, bufferSize - len,
"StraightLineSightingType");
290 len += snprintf(toString + len, bufferSize - len,
"TIntersectionLineSightingType");
295#pragma clang diagnostic pop
303 size_t temp_length = strlen(str);
304 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
309 char* var_str = &var_str_buffer[0];
311 char* key = &key_buffer[0];
318 if (index == 0 && str[0] ==
'{') {
324 for (
int i = index; i < length; i++) {
326 if (bracecount == 0 && str[i] ==
'=') {
331 if (bracecount == 0 && isspace(str[i])) {
338 if (bracecount == 0 && str[i] ==
',') {
348 if (bracecount < 0) {
353 if (i == length - 1) {
357 if (endKey >= startKey && endKey - startKey < length) {
358 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
359 key[(endKey - startKey) + 1] = 0;
363 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
364 var_str[(index - startVar) + 1] = 0;
370 if (strlen(key) > 0) {
371 if (0 == strcmp(
"direction", key)) {
373 }
else if (0 == strcmp(
"distance", key)) {
375 }
else if (0 == strcmp(
"sightingType", key)) {
385 self->direction = ((int16_t)atoi(var_str));
390 self->distance = ((uint16_t)atoi(var_str));
395 if (strcmp(
"BallSightingType", var_str) == 0) {
396#pragma clang diagnostic push
397#pragma clang diagnostic ignored "-Wbad-function-cast"
399#pragma clang diagnostic pop
400 }
else if (strcmp(
"CornerHorizonSightingType", var_str) == 0) {
401#pragma clang diagnostic push
402#pragma clang diagnostic ignored "-Wbad-function-cast"
404#pragma clang diagnostic pop
405 }
else if (strcmp(
"CornerLineSightingType", var_str) == 0) {
406#pragma clang diagnostic push
407#pragma clang diagnostic ignored "-Wbad-function-cast"
409#pragma clang diagnostic pop
410 }
else if (strcmp(
"CrossLineSightingType", var_str) == 0) {
411#pragma clang diagnostic push
412#pragma clang diagnostic ignored "-Wbad-function-cast"
414#pragma clang diagnostic pop
415 }
else if (strcmp(
"GenericGoalPostSightingType", var_str) == 0) {
416#pragma clang diagnostic push
417#pragma clang diagnostic ignored "-Wbad-function-cast"
419#pragma clang diagnostic pop
420 }
else if (strcmp(
"GoalLandmarkSightingType", var_str) == 0) {
421#pragma clang diagnostic push
422#pragma clang diagnostic ignored "-Wbad-function-cast"
424#pragma clang diagnostic pop
425 }
else if (strcmp(
"LeftGoalPostSightingType", var_str) == 0) {
426#pragma clang diagnostic push
427#pragma clang diagnostic ignored "-Wbad-function-cast"
429#pragma clang diagnostic pop
430 }
else if (strcmp(
"LineHorizonSightingType", var_str) == 0) {
431#pragma clang diagnostic push
432#pragma clang diagnostic ignored "-Wbad-function-cast"
434#pragma clang diagnostic pop
435 }
else if (strcmp(
"RightGoalPostSightingType", var_str) == 0) {
436#pragma clang diagnostic push
437#pragma clang diagnostic ignored "-Wbad-function-cast"
439#pragma clang diagnostic pop
440 }
else if (strcmp(
"StraightLineSightingType", var_str) == 0) {
441#pragma clang diagnostic push
442#pragma clang diagnostic ignored "-Wbad-function-cast"
444#pragma clang diagnostic pop
445 }
else if (strcmp(
"TIntersectionLineSightingType", var_str) == 0) {
446#pragma clang diagnostic push
447#pragma clang diagnostic ignored "-Wbad-function-cast"
449#pragma clang diagnostic pop
451#pragma clang diagnostic push
452#pragma clang diagnostic ignored "-Wbad-function-cast"
454#pragma clang diagnostic pop
462 }
while(index < length);
473 uint16_t bit_offset = 0;
474 int16_t direction_nbo =
htons(self->direction);
477 for (b = (16 - 1); b >= 0; b--) {
479 uint16_t
byte = bit_offset / 8;
480 uint16_t bit = 7 - (bit_offset % 8);
481 unsigned long newbit = !!((direction_nbo >> b) & 1U);
482 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
483 bit_offset = bit_offset + 1;
488 uint16_t distance_nbo =
htons(self->distance);
491 for (b = (16 - 1); b >= 0; b--) {
493 uint16_t
byte = bit_offset / 8;
494 uint16_t bit = 7 - (bit_offset % 8);
495 unsigned long newbit = !!((distance_nbo >> b) & 1U);
496 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
497 bit_offset = bit_offset + 1;
505 for (b = (32 - 1); b >= 0; b--) {
507 uint16_t
byte = bit_offset / 8;
508 uint16_t bit = 7 - (bit_offset % 8);
509 unsigned long newbit = !!((sightingType_nbo >> b) & 1U);
510 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
511 bit_offset = bit_offset + 1;
526 uint16_t bit_offset = 0;
529 for (b = (16 - 1); b >= 0; b--) {
531 uint16_t
byte = bit_offset / 8;
532 uint16_t bit = 7 - (bit_offset % 8);
533 char dataByte = src[byte];
534 unsigned char bitValue = (dataByte >> bit) & 1U;
536 bit_offset = bit_offset + 1;
544 for (b = (16 - 1); b >= 0; b--) {
546 uint16_t
byte = bit_offset / 8;
547 uint16_t bit = 7 - (bit_offset % 8);
548 char dataByte = src[byte];
549 unsigned char bitValue = (dataByte >> bit) & 1U;
551 bit_offset = bit_offset + 1;
559 for (b = (32 - 1); b >= 0; b--) {
561 uint16_t
byte = bit_offset / 8;
562 uint16_t bit = 7 - (bit_offset % 8);
563 char dataByte = src[byte];
564 unsigned char bitValue = (dataByte >> bit) & 1U;
566 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t direction
degrees, relative to the center of the nao torso.
uint16_t distance
CM distance to the center point of the sighting.
enum LandmarkSightingType sightingType
The type of sighting.
const char * wb_landmark_sighting_description(const struct wb_landmark_sighting *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_landmark_sighting_to_network_serialised(const struct wb_landmark_sighting *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
size_t wb_landmark_sighting_from_network_serialised(const char *src, struct wb_landmark_sighting *dst)
Convert from a compressed, serialised, network byte order byte stream.
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
@ GenericGoalPostSightingType
@ StraightLineSightingType
@ LeftGoalPostSightingType
@ GoalLandmarkSightingType
@ TIntersectionLineSightingType
@ LineHorizonSightingType
@ CornerHorizonSightingType
@ RightGoalPostSightingType