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 switch (self->sightingType) {
136 len += snprintf(descString + len, bufferSize - len,
"sightingType=BallDetected");
141 len += snprintf(descString + len, bufferSize - len,
"sightingType=NoBallDetected");
145 if (len >= bufferSize) {
148 len = gu_strlcat(descString,
", ", bufferSize);
149 if (len >= bufferSize) {
152 len = gu_strlcat(descString,
"coordinate={", bufferSize);
153 if (len >= bufferSize) {
157 char* coordinate_p = coordinate_buffer;
159 len = gu_strlcat(descString, coordinate_p, bufferSize);
160 if (len >= bufferSize) {
163 len = gu_strlcat(descString,
"}", bufferSize);
164 if (len >= bufferSize) {
167 len = gu_strlcat(descString,
", ", bufferSize);
168 if (len >= bufferSize) {
171 len += snprintf(descString + len, bufferSize - len,
"verticalRadius=%u", self->verticalRadius);
172 if (len >= bufferSize) {
175 len = gu_strlcat(descString,
", ", bufferSize);
176 if (len >= bufferSize) {
179 len += snprintf(descString + len, bufferSize - len,
"horizontalRadius=%u", self->horizontalRadius);
181#pragma clang diagnostic pop
189#pragma clang diagnostic push
190#pragma clang diagnostic ignored "-Wunused-variable"
192 if (len >= bufferSize) {
195 switch (self->sightingType) {
198 len += snprintf(toString + len, bufferSize - len,
"BallDetected");
203 len += snprintf(toString + len, bufferSize - len,
"NoBallDetected");
207 if (len >= bufferSize) {
210 len = gu_strlcat(toString,
", ", bufferSize);
211 if (len >= bufferSize) {
214 len = gu_strlcat(toString,
"{", bufferSize);
215 if (len >= bufferSize) {
219 char* coordinate_p = coordinate_buffer;
221 len = gu_strlcat(toString, coordinate_p, bufferSize);
222 if (len >= bufferSize) {
225 len = gu_strlcat(toString,
"}", bufferSize);
226 if (len >= bufferSize) {
229 len = gu_strlcat(toString,
", ", bufferSize);
230 if (len >= bufferSize) {
233 len += snprintf(toString + len, bufferSize - len,
"%u", self->verticalRadius);
234 if (len >= bufferSize) {
237 len = gu_strlcat(toString,
", ", bufferSize);
238 if (len >= bufferSize) {
241 len += snprintf(toString + len, bufferSize - len,
"%u", self->horizontalRadius);
243#pragma clang diagnostic pop
251 size_t temp_length = strlen(str);
252 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
257 char* var_str = &var_str_buffer[0];
259 char* key = &key_buffer[0];
266 if (index == 0 && str[0] ==
'{') {
272 for (
int i = index; i < length; i++) {
274 if (bracecount == 0 && str[i] ==
'=') {
279 if (bracecount == 0 && isspace(str[i])) {
286 if (bracecount == 0 && str[i] ==
',') {
296 if (bracecount < 0) {
301 if (i == length - 1) {
305 if (endKey >= startKey && endKey - startKey < length) {
306 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
307 key[(endKey - startKey) + 1] = 0;
311 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
312 var_str[(index - startVar) + 1] = 0;
318 if (strlen(key) > 0) {
319 if (0 == strcmp(
"sightingType", key)) {
321 }
else if (0 == strcmp(
"coordinate", key)) {
323 }
else if (0 == strcmp(
"verticalRadius", key)) {
325 }
else if (0 == strcmp(
"horizontalRadius", key)) {
335 if (strcmp(
"BallDetected", var_str) == 0) {
336#pragma clang diagnostic push
337#pragma clang diagnostic ignored "-Wbad-function-cast"
339#pragma clang diagnostic pop
340 }
else if (strcmp(
"NoBallDetected", var_str) == 0) {
341#pragma clang diagnostic push
342#pragma clang diagnostic ignored "-Wbad-function-cast"
344#pragma clang diagnostic pop
346#pragma clang diagnostic push
347#pragma clang diagnostic ignored "-Wbad-function-cast"
348 self->sightingType = ((
enum BallOptions)atoi(var_str));
349#pragma clang diagnostic pop
360 self->verticalRadius = ((uint16_t)atoi(var_str));
365 self->horizontalRadius = ((uint16_t)atoi(var_str));
372 }
while(index < length);
383 uint16_t bit_offset = 0;
387 for (b = (32 - 1); b >= 0; b--) {
389 uint16_t
byte = bit_offset / 8;
390 uint16_t bit = 7 - (bit_offset % 8);
391 unsigned long newbit = !!((sightingType_nbo >> b) & 1U);
392 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
393 bit_offset = bit_offset + 1;
398 uint16_t verticalRadius_nbo =
htons(self->verticalRadius);
401 for (b = (16 - 1); b >= 0; b--) {
403 uint16_t
byte = bit_offset / 8;
404 uint16_t bit = 7 - (bit_offset % 8);
405 unsigned long newbit = !!((verticalRadius_nbo >> b) & 1U);
406 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
407 bit_offset = bit_offset + 1;
412 uint16_t horizontalRadius_nbo =
htons(self->horizontalRadius);
415 for (b = (16 - 1); b >= 0; b--) {
417 uint16_t
byte = bit_offset / 8;
418 uint16_t bit = 7 - (bit_offset % 8);
419 unsigned long newbit = !!((horizontalRadius_nbo >> b) & 1U);
420 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
421 bit_offset = bit_offset + 1;
436 uint16_t bit_offset = 0;
439 for (b = (32 - 1); b >= 0; b--) {
441 uint16_t
byte = bit_offset / 8;
442 uint16_t bit = 7 - (bit_offset % 8);
443 char dataByte = src[byte];
444 unsigned char bitValue = (dataByte >> bit) & 1U;
446 bit_offset = bit_offset + 1;
454 for (b = (16 - 1); b >= 0; b--) {
456 uint16_t
byte = bit_offset / 8;
457 uint16_t bit = 7 - (bit_offset % 8);
458 char dataByte = src[byte];
459 unsigned char bitValue = (dataByte >> bit) & 1U;
461 bit_offset = bit_offset + 1;
469 for (b = (16 - 1); b >= 0; b--) {
471 uint16_t
byte = bit_offset / 8;
472 uint16_t bit = 7 - (bit_offset % 8);
473 char dataByte = src[byte];
474 unsigned char bitValue = (dataByte >> bit) & 1U;
476 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate coordinate
The pixel coordinate.
uint16_t verticalRadius
The vertical radius in pixels.
enum BallOptions sightingType
Ball detection details.
uint16_t horizontalRadius
The horizontal radius in pixels.
const char * wb_pixel_coordinate_description(const struct wb_pixel_coordinate *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_pixel_coordinate * wb_pixel_coordinate_from_string(struct wb_pixel_coordinate *self, const char *str)
Convert from a string.
const char * wb_pixel_coordinate_to_string(const struct wb_pixel_coordinate *self, char *toString, size_t bufferSize)
Convert to a string.
gu_pixel_coordinate wb_px_coord_to_px_coord(const struct wb_pixel_coordinate coord, const uint16_t resWidth, const uint16_t resHeight)
#define PIXEL_COORDINATE_DESC_BUFFER_SIZE
#define PIXEL_COORDINATE_TO_STRING_BUFFER_SIZE
size_t wb_vision_detection_ball_to_network_serialised(const struct wb_vision_detection_ball *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
size_t wb_vision_detection_ball_from_network_serialised(const char *src, struct wb_vision_detection_ball *dst)
Convert from a compressed, serialised, network byte order byte stream.
struct wb_vision_detection_ball * wb_vision_detection_ball_from_string(struct wb_vision_detection_ball *self, const char *str)
Convert from a string.
const char * wb_vision_detection_ball_to_string(const struct wb_vision_detection_ball *self, char *toString, size_t bufferSize)
Convert to a string.
gu_pixel_coordinate wb_vision_detection_ball_coordinate_px_coord(const struct wb_vision_detection_ball self, const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
const char * wb_vision_detection_ball_description(const struct wb_vision_detection_ball *self, char *descString, size_t bufferSize)
Convert to a description string.
@ BallDetected
Ball Found.
@ NoBallDetected
No Ball Found.
#define VISION_DETECTION_BALL_DESC_BUFFER_SIZE