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,
"x=%d", self->x);
134 if (len >= bufferSize) {
137 len = gu_strlcat(descString,
", ", bufferSize);
138 if (len >= bufferSize) {
141 len += snprintf(descString + len, bufferSize - len,
"y=%d", self->y);
142 if (len >= bufferSize) {
145 len = gu_strlcat(descString,
", ", bufferSize);
146 if (len >= bufferSize) {
149 len += snprintf(descString + len, bufferSize - len,
"pitchInDegrees=%d", self->pitchInDegrees);
150 if (len >= bufferSize) {
153 len = gu_strlcat(descString,
", ", bufferSize);
154 if (len >= bufferSize) {
157 len += snprintf(descString + len, bufferSize - len,
"yawInDegrees=%d", self->yawInDegrees);
158 if (len >= bufferSize) {
161 len = gu_strlcat(descString,
", ", bufferSize);
162 if (len >= bufferSize) {
165 len += snprintf(descString + len, bufferSize - len,
"rollInDegrees=%d", self->rollInDegrees);
166 if (len >= bufferSize) {
169 len = gu_strlcat(descString,
", ", bufferSize);
170 if (len >= bufferSize) {
173 len += snprintf(descString + len, bufferSize - len,
"confidence=%u", self->confidence);
175#pragma clang diagnostic pop
183#pragma clang diagnostic push
184#pragma clang diagnostic ignored "-Wunused-variable"
186 if (len >= bufferSize) {
189 len += snprintf(toString + len, bufferSize - len,
"%d", self->x);
190 if (len >= bufferSize) {
193 len = gu_strlcat(toString,
", ", bufferSize);
194 if (len >= bufferSize) {
197 len += snprintf(toString + len, bufferSize - len,
"%d", self->y);
198 if (len >= bufferSize) {
201 len = gu_strlcat(toString,
", ", bufferSize);
202 if (len >= bufferSize) {
205 len += snprintf(toString + len, bufferSize - len,
"%d", self->pitchInDegrees);
206 if (len >= bufferSize) {
209 len = gu_strlcat(toString,
", ", bufferSize);
210 if (len >= bufferSize) {
213 len += snprintf(toString + len, bufferSize - len,
"%d", self->yawInDegrees);
214 if (len >= bufferSize) {
217 len = gu_strlcat(toString,
", ", bufferSize);
218 if (len >= bufferSize) {
221 len += snprintf(toString + len, bufferSize - len,
"%d", self->rollInDegrees);
222 if (len >= bufferSize) {
225 len = gu_strlcat(toString,
", ", bufferSize);
226 if (len >= bufferSize) {
229 len += snprintf(toString + len, bufferSize - len,
"%u", self->confidence);
231#pragma clang diagnostic pop
239 size_t temp_length = strlen(str);
240 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
245 char* var_str = &var_str_buffer[0];
247 char* key = &key_buffer[0];
254 if (index == 0 && str[0] ==
'{') {
260 for (
int i = index; i < length; i++) {
262 if (bracecount == 0 && str[i] ==
'=') {
267 if (bracecount == 0 && isspace(str[i])) {
274 if (bracecount == 0 && str[i] ==
',') {
284 if (bracecount < 0) {
289 if (i == length - 1) {
293 if (endKey >= startKey && endKey - startKey < length) {
294 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
295 key[(endKey - startKey) + 1] = 0;
299 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
300 var_str[(index - startVar) + 1] = 0;
306 if (strlen(key) > 0) {
307 if (0 == strcmp(
"x", key)) {
309 }
else if (0 == strcmp(
"y", key)) {
311 }
else if (0 == strcmp(
"pitchInDegrees", key)) {
313 }
else if (0 == strcmp(
"yawInDegrees", key)) {
315 }
else if (0 == strcmp(
"rollInDegrees", key)) {
317 }
else if (0 == strcmp(
"confidence", key)) {
327 self->x = ((int16_t)atoi(var_str));
332 self->y = ((int16_t)atoi(var_str));
337 self->pitchInDegrees = ((int16_t)atoi(var_str));
342 self->yawInDegrees = ((int16_t)atoi(var_str));
347 self->rollInDegrees = ((int16_t)atoi(var_str));
352 self->confidence = ((uint8_t)atoi(var_str));
359 }
while(index < length);
370 uint16_t bit_offset = 0;
371 int16_t x_nbo =
htons(self->x);
374 for (b = (16 - 1); b >= 0; b--) {
376 uint16_t
byte = bit_offset / 8;
377 uint16_t bit = 7 - (bit_offset % 8);
378 unsigned long newbit = !!((x_nbo >> b) & 1U);
379 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
380 bit_offset = bit_offset + 1;
385 int16_t y_nbo =
htons(self->y);
388 for (b = (16 - 1); b >= 0; b--) {
390 uint16_t
byte = bit_offset / 8;
391 uint16_t bit = 7 - (bit_offset % 8);
392 unsigned long newbit = !!((y_nbo >> b) & 1U);
393 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
394 bit_offset = bit_offset + 1;
399 int16_t pitchInDegrees_nbo =
htons(self->pitchInDegrees);
402 for (b = (16 - 1); b >= 0; b--) {
404 uint16_t
byte = bit_offset / 8;
405 uint16_t bit = 7 - (bit_offset % 8);
406 unsigned long newbit = !!((pitchInDegrees_nbo >> b) & 1U);
407 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
408 bit_offset = bit_offset + 1;
413 int16_t yawInDegrees_nbo =
htons(self->yawInDegrees);
416 for (b = (16 - 1); b >= 0; b--) {
418 uint16_t
byte = bit_offset / 8;
419 uint16_t bit = 7 - (bit_offset % 8);
420 unsigned long newbit = !!((yawInDegrees_nbo >> b) & 1U);
421 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
422 bit_offset = bit_offset + 1;
427 int16_t rollInDegrees_nbo =
htons(self->rollInDegrees);
430 for (b = (16 - 1); b >= 0; b--) {
432 uint16_t
byte = bit_offset / 8;
433 uint16_t bit = 7 - (bit_offset % 8);
434 unsigned long newbit = !!((rollInDegrees_nbo >> b) & 1U);
435 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
436 bit_offset = bit_offset + 1;
441 uint8_t confidence_nbo = (
self->confidence);
444 for (b = (8 - 1); b >= 0; b--) {
446 uint16_t
byte = bit_offset / 8;
447 uint16_t bit = 7 - (bit_offset % 8);
448 unsigned long newbit = !!((confidence_nbo >> b) & 1U);
449 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
450 bit_offset = bit_offset + 1;
465 uint16_t bit_offset = 0;
468 for (b = (16 - 1); b >= 0; b--) {
470 uint16_t
byte = bit_offset / 8;
471 uint16_t bit = 7 - (bit_offset % 8);
472 char dataByte = src[byte];
473 unsigned char bitValue = (dataByte >> bit) & 1U;
474 dst->
x ^= (-bitValue ^ dst->
x) & (1UL << b);
475 bit_offset = bit_offset + 1;
483 for (b = (16 - 1); b >= 0; b--) {
485 uint16_t
byte = bit_offset / 8;
486 uint16_t bit = 7 - (bit_offset % 8);
487 char dataByte = src[byte];
488 unsigned char bitValue = (dataByte >> bit) & 1U;
489 dst->
y ^= (-bitValue ^ dst->
y) & (1UL << b);
490 bit_offset = bit_offset + 1;
498 for (b = (16 - 1); b >= 0; b--) {
500 uint16_t
byte = bit_offset / 8;
501 uint16_t bit = 7 - (bit_offset % 8);
502 char dataByte = src[byte];
503 unsigned char bitValue = (dataByte >> bit) & 1U;
505 bit_offset = bit_offset + 1;
513 for (b = (16 - 1); b >= 0; b--) {
515 uint16_t
byte = bit_offset / 8;
516 uint16_t bit = 7 - (bit_offset % 8);
517 char dataByte = src[byte];
518 unsigned char bitValue = (dataByte >> bit) & 1U;
520 bit_offset = bit_offset + 1;
528 for (b = (16 - 1); b >= 0; b--) {
530 uint16_t
byte = bit_offset / 8;
531 uint16_t bit = 7 - (bit_offset % 8);
532 char dataByte = src[byte];
533 unsigned char bitValue = (dataByte >> bit) & 1U;
535 bit_offset = bit_offset + 1;
543 for (b = (8 - 1); b >= 0; b--) {
545 uint16_t
byte = bit_offset / 8;
546 uint16_t bit = 7 - (bit_offset % 8);
547 char dataByte = src[byte];
548 unsigned char bitValue = (dataByte >> bit) & 1U;
550 bit_offset = bit_offset + 1;
575 return ((
double) (strct.
confidence - 0)) / ((double) (255 - 0));
591 strct->
confidence = ((uint8_t) (round(newValue * ((
double) (255 - 0))))) + 0;
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t x
The x coordinate.
uint8_t confidence
The confidence that the ball is at this position.
int16_t y
The y coordinate.
int16_t rollInDegrees
The roll orientation.
int16_t pitchInDegrees
The pitch orientation.
int16_t yawInDegrees
The yaw orientation.
const char * wb_ball_position_to_string(const struct wb_ball_position *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_ball_position_from_network_serialised(const char *src, struct wb_ball_position *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_ball_position_description(const struct wb_ball_position *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_ball_position * wb_ball_position_from_string(struct wb_ball_position *self, const char *str)
Convert from a string.
size_t wb_ball_position_to_network_serialised(const struct wb_ball_position *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
void wb_ball_position_set_confidence_percent(struct wb_ball_position *strct, const double newValue)
Converts and stores a percentage floating point value in wb_ball_position.confidence.
double wb_ball_position_confidence_percent(const struct wb_ball_position strct)
Converts wb_ball_position.confidence to its corresponding floating point percentage representation.
#define BALL_POSITION_DESC_BUFFER_SIZE