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=FullPostSeen");
141 len += snprintf(descString + len, bufferSize - len,
"sightingType=NoPostDetected");
146 len += snprintf(descString + len, bufferSize - len,
"sightingType=PartialPostSeen");
150 if (len >= bufferSize) {
153 len = gu_strlcat(descString,
", ", bufferSize);
154 if (len >= bufferSize) {
157 switch (self->orientation) {
160 len += snprintf(descString + len, bufferSize - len,
"orientation=GenericPost");
165 len += snprintf(descString + len, bufferSize - len,
"orientation=LeftPost");
170 len += snprintf(descString + len, bufferSize - len,
"orientation=RightPost");
174 if (len >= bufferSize) {
177 len = gu_strlcat(descString,
", ", bufferSize);
178 if (len >= bufferSize) {
181 len = gu_strlcat(descString,
"topLeftCoordinate={", bufferSize);
182 if (len >= bufferSize) {
186 char* topLeftCoordinate_p = topLeftCoordinate_buffer;
188 len = gu_strlcat(descString, topLeftCoordinate_p, bufferSize);
189 if (len >= bufferSize) {
192 len = gu_strlcat(descString,
"}", bufferSize);
193 if (len >= bufferSize) {
196 len = gu_strlcat(descString,
", ", bufferSize);
197 if (len >= bufferSize) {
200 len = gu_strlcat(descString,
"topRightCoordinate={", bufferSize);
201 if (len >= bufferSize) {
205 char* topRightCoordinate_p = topRightCoordinate_buffer;
207 len = gu_strlcat(descString, topRightCoordinate_p, bufferSize);
208 if (len >= bufferSize) {
211 len = gu_strlcat(descString,
"}", bufferSize);
212 if (len >= bufferSize) {
215 len = gu_strlcat(descString,
", ", bufferSize);
216 if (len >= bufferSize) {
219 len = gu_strlcat(descString,
"bottomLeftCoordinate={", bufferSize);
220 if (len >= bufferSize) {
224 char* bottomLeftCoordinate_p = bottomLeftCoordinate_buffer;
226 len = gu_strlcat(descString, bottomLeftCoordinate_p, bufferSize);
227 if (len >= bufferSize) {
230 len = gu_strlcat(descString,
"}", bufferSize);
231 if (len >= bufferSize) {
234 len = gu_strlcat(descString,
", ", bufferSize);
235 if (len >= bufferSize) {
238 len = gu_strlcat(descString,
"bottomRightCoordinate={", bufferSize);
239 if (len >= bufferSize) {
243 char* bottomRightCoordinate_p = bottomRightCoordinate_buffer;
245 len = gu_strlcat(descString, bottomRightCoordinate_p, bufferSize);
246 if (len >= bufferSize) {
249 len = gu_strlcat(descString,
"}", bufferSize);
251#pragma clang diagnostic pop
259#pragma clang diagnostic push
260#pragma clang diagnostic ignored "-Wunused-variable"
262 if (len >= bufferSize) {
265 switch (self->sightingType) {
268 len += snprintf(toString + len, bufferSize - len,
"FullPostSeen");
273 len += snprintf(toString + len, bufferSize - len,
"NoPostDetected");
278 len += snprintf(toString + len, bufferSize - len,
"PartialPostSeen");
282 if (len >= bufferSize) {
285 len = gu_strlcat(toString,
", ", bufferSize);
286 if (len >= bufferSize) {
289 switch (self->orientation) {
292 len += snprintf(toString + len, bufferSize - len,
"GenericPost");
297 len += snprintf(toString + len, bufferSize - len,
"LeftPost");
302 len += snprintf(toString + len, bufferSize - len,
"RightPost");
306 if (len >= bufferSize) {
309 len = gu_strlcat(toString,
", ", bufferSize);
310 if (len >= bufferSize) {
313 len = gu_strlcat(toString,
"{", bufferSize);
314 if (len >= bufferSize) {
318 char* topLeftCoordinate_p = topLeftCoordinate_buffer;
320 len = gu_strlcat(toString, topLeftCoordinate_p, bufferSize);
321 if (len >= bufferSize) {
324 len = gu_strlcat(toString,
"}", bufferSize);
325 if (len >= bufferSize) {
328 len = gu_strlcat(toString,
", ", bufferSize);
329 if (len >= bufferSize) {
332 len = gu_strlcat(toString,
"{", bufferSize);
333 if (len >= bufferSize) {
337 char* topRightCoordinate_p = topRightCoordinate_buffer;
339 len = gu_strlcat(toString, topRightCoordinate_p, bufferSize);
340 if (len >= bufferSize) {
343 len = gu_strlcat(toString,
"}", bufferSize);
344 if (len >= bufferSize) {
347 len = gu_strlcat(toString,
", ", bufferSize);
348 if (len >= bufferSize) {
351 len = gu_strlcat(toString,
"{", bufferSize);
352 if (len >= bufferSize) {
356 char* bottomLeftCoordinate_p = bottomLeftCoordinate_buffer;
358 len = gu_strlcat(toString, bottomLeftCoordinate_p, bufferSize);
359 if (len >= bufferSize) {
362 len = gu_strlcat(toString,
"}", bufferSize);
363 if (len >= bufferSize) {
366 len = gu_strlcat(toString,
", ", bufferSize);
367 if (len >= bufferSize) {
370 len = gu_strlcat(toString,
"{", bufferSize);
371 if (len >= bufferSize) {
375 char* bottomRightCoordinate_p = bottomRightCoordinate_buffer;
377 len = gu_strlcat(toString, bottomRightCoordinate_p, bufferSize);
378 if (len >= bufferSize) {
381 len = gu_strlcat(toString,
"}", bufferSize);
383#pragma clang diagnostic pop
391 size_t temp_length = strlen(str);
392 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
397 char* var_str = &var_str_buffer[0];
399 char* key = &key_buffer[0];
406 if (index == 0 && str[0] ==
'{') {
412 for (
int i = index; i < length; i++) {
414 if (bracecount == 0 && str[i] ==
'=') {
419 if (bracecount == 0 && isspace(str[i])) {
426 if (bracecount == 0 && str[i] ==
',') {
436 if (bracecount < 0) {
441 if (i == length - 1) {
445 if (endKey >= startKey && endKey - startKey < length) {
446 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
447 key[(endKey - startKey) + 1] = 0;
451 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
452 var_str[(index - startVar) + 1] = 0;
458 if (strlen(key) > 0) {
459 if (0 == strcmp(
"sightingType", key)) {
461 }
else if (0 == strcmp(
"orientation", key)) {
463 }
else if (0 == strcmp(
"topLeftCoordinate", key)) {
465 }
else if (0 == strcmp(
"topRightCoordinate", key)) {
467 }
else if (0 == strcmp(
"bottomLeftCoordinate", key)) {
469 }
else if (0 == strcmp(
"bottomRightCoordinate", key)) {
479 if (strcmp(
"FullPostSeen", var_str) == 0) {
480#pragma clang diagnostic push
481#pragma clang diagnostic ignored "-Wbad-function-cast"
483#pragma clang diagnostic pop
484 }
else if (strcmp(
"NoPostDetected", var_str) == 0) {
485#pragma clang diagnostic push
486#pragma clang diagnostic ignored "-Wbad-function-cast"
488#pragma clang diagnostic pop
489 }
else if (strcmp(
"PartialPostSeen", var_str) == 0) {
490#pragma clang diagnostic push
491#pragma clang diagnostic ignored "-Wbad-function-cast"
493#pragma clang diagnostic pop
495#pragma clang diagnostic push
496#pragma clang diagnostic ignored "-Wbad-function-cast"
498#pragma clang diagnostic pop
504 if (strcmp(
"GenericPost", var_str) == 0) {
505#pragma clang diagnostic push
506#pragma clang diagnostic ignored "-Wbad-function-cast"
508#pragma clang diagnostic pop
509 }
else if (strcmp(
"LeftPost", var_str) == 0) {
510#pragma clang diagnostic push
511#pragma clang diagnostic ignored "-Wbad-function-cast"
513#pragma clang diagnostic pop
514 }
else if (strcmp(
"RightPost", var_str) == 0) {
515#pragma clang diagnostic push
516#pragma clang diagnostic ignored "-Wbad-function-cast"
518#pragma clang diagnostic pop
520#pragma clang diagnostic push
521#pragma clang diagnostic ignored "-Wbad-function-cast"
523#pragma clang diagnostic pop
551 }
while(index < length);
562 uint16_t bit_offset = 0;
566 for (b = (32 - 1); b >= 0; b--) {
568 uint16_t
byte = bit_offset / 8;
569 uint16_t bit = 7 - (bit_offset % 8);
570 unsigned long newbit = !!((sightingType_nbo >> b) & 1U);
571 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
572 bit_offset = bit_offset + 1;
580 for (b = (32 - 1); b >= 0; b--) {
582 uint16_t
byte = bit_offset / 8;
583 uint16_t bit = 7 - (bit_offset % 8);
584 unsigned long newbit = !!((orientation_nbo >> b) & 1U);
585 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
586 bit_offset = bit_offset + 1;
601 uint16_t bit_offset = 0;
604 for (b = (32 - 1); b >= 0; b--) {
606 uint16_t
byte = bit_offset / 8;
607 uint16_t bit = 7 - (bit_offset % 8);
608 char dataByte = src[byte];
609 unsigned char bitValue = (dataByte >> bit) & 1U;
611 bit_offset = bit_offset + 1;
619 for (b = (32 - 1); b >= 0; b--) {
621 uint16_t
byte = bit_offset / 8;
622 uint16_t bit = 7 - (bit_offset % 8);
623 char dataByte = src[byte];
624 unsigned char bitValue = (dataByte >> bit) & 1U;
626 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate topLeftCoordinate
The top left pixel coordinate.
enum GoalPostOptions sightingType
Goal post details.
enum GoalPostOrientation orientation
Goal post orientation.
struct wb_pixel_coordinate bottomRightCoordinate
The bottom right pixel coordinate.
struct wb_pixel_coordinate bottomLeftCoordinate
The bottom left pixel coordinate.
struct wb_pixel_coordinate topRightCoordinate
The top right pixel coordinate.
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_goal_post_from_network_serialised(const char *src, struct wb_vision_detection_goal_post *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_vision_detection_goal_post_to_string(const struct wb_vision_detection_goal_post *self, char *toString, size_t bufferSize)
Convert to a string.
gu_pixel_coordinate wb_vision_detection_goal_post_topRightCoordinate_px_coord(const struct wb_vision_detection_goal_post self, const uint16_t resWidth, const uint16_t resHeight)
gu_pixel_coordinate wb_vision_detection_goal_post_topLeftCoordinate_px_coord(const struct wb_vision_detection_goal_post self, const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
gu_pixel_coordinate wb_vision_detection_goal_post_bottomLeftCoordinate_px_coord(const struct wb_vision_detection_goal_post self, const uint16_t resWidth, const uint16_t resHeight)
gu_pixel_coordinate wb_vision_detection_goal_post_bottomRightCoordinate_px_coord(const struct wb_vision_detection_goal_post self, const uint16_t resWidth, const uint16_t resHeight)
struct wb_vision_detection_goal_post * wb_vision_detection_goal_post_from_string(struct wb_vision_detection_goal_post *self, const char *str)
Convert from a string.
size_t wb_vision_detection_goal_post_to_network_serialised(const struct wb_vision_detection_goal_post *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_vision_detection_goal_post_description(const struct wb_vision_detection_goal_post *self, char *descString, size_t bufferSize)
Convert to a description string.
@ FullPostSeen
Saw the entire post.
@ PartialPostSeen
Saw part of a post. Part in the image, part out.
@ NoPostDetected
Didn't see a post.
@ RightPost
This is the right post of a goal.
@ GenericPost
Could not determine post orientation.
@ LeftPost
This is the left post of a goal.
#define VISION_DETECTION_GOAL_POST_DESC_BUFFER_SIZE