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=DoublePostGoal");
141 len += snprintf(descString + len, bufferSize - len,
"sightingType=NoGoalDetected");
146 len += snprintf(descString + len, bufferSize - len,
"sightingType=SinglePostGoal");
150 if (len >= bufferSize) {
153 len = gu_strlcat(descString,
", ", bufferSize);
154 if (len >= bufferSize) {
157 len = gu_strlcat(descString,
"post1={", bufferSize);
158 if (len >= bufferSize) {
162 char* post1_p = post1_buffer;
164 len = gu_strlcat(descString, post1_p, bufferSize);
165 if (len >= bufferSize) {
168 len = gu_strlcat(descString,
"}", bufferSize);
169 if (len >= bufferSize) {
172 len = gu_strlcat(descString,
", ", bufferSize);
173 if (len >= bufferSize) {
176 len = gu_strlcat(descString,
"post2={", bufferSize);
177 if (len >= bufferSize) {
181 char* post2_p = post2_buffer;
183 len = gu_strlcat(descString, post2_p, bufferSize);
184 if (len >= bufferSize) {
187 len = gu_strlcat(descString,
"}", bufferSize);
189#pragma clang diagnostic pop
197#pragma clang diagnostic push
198#pragma clang diagnostic ignored "-Wunused-variable"
200 if (len >= bufferSize) {
203 switch (self->sightingType) {
206 len += snprintf(toString + len, bufferSize - len,
"DoublePostGoal");
211 len += snprintf(toString + len, bufferSize - len,
"NoGoalDetected");
216 len += snprintf(toString + len, bufferSize - len,
"SinglePostGoal");
220 if (len >= bufferSize) {
223 len = gu_strlcat(toString,
", ", bufferSize);
224 if (len >= bufferSize) {
227 len = gu_strlcat(toString,
"{", bufferSize);
228 if (len >= bufferSize) {
232 char* post1_p = post1_buffer;
234 len = gu_strlcat(toString, post1_p, bufferSize);
235 if (len >= bufferSize) {
238 len = gu_strlcat(toString,
"}", bufferSize);
239 if (len >= bufferSize) {
242 len = gu_strlcat(toString,
", ", bufferSize);
243 if (len >= bufferSize) {
246 len = gu_strlcat(toString,
"{", bufferSize);
247 if (len >= bufferSize) {
251 char* post2_p = post2_buffer;
253 len = gu_strlcat(toString, post2_p, bufferSize);
254 if (len >= bufferSize) {
257 len = gu_strlcat(toString,
"}", bufferSize);
259#pragma clang diagnostic pop
267 size_t temp_length = strlen(str);
268 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
273 char* var_str = &var_str_buffer[0];
275 char* key = &key_buffer[0];
282 if (index == 0 && str[0] ==
'{') {
288 for (
int i = index; i < length; i++) {
290 if (bracecount == 0 && str[i] ==
'=') {
295 if (bracecount == 0 && isspace(str[i])) {
302 if (bracecount == 0 && str[i] ==
',') {
312 if (bracecount < 0) {
317 if (i == length - 1) {
321 if (endKey >= startKey && endKey - startKey < length) {
322 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
323 key[(endKey - startKey) + 1] = 0;
327 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
328 var_str[(index - startVar) + 1] = 0;
334 if (strlen(key) > 0) {
335 if (0 == strcmp(
"sightingType", key)) {
337 }
else if (0 == strcmp(
"post1", key)) {
339 }
else if (0 == strcmp(
"post2", key)) {
349 if (strcmp(
"DoublePostGoal", var_str) == 0) {
350#pragma clang diagnostic push
351#pragma clang diagnostic ignored "-Wbad-function-cast"
353#pragma clang diagnostic pop
354 }
else if (strcmp(
"NoGoalDetected", var_str) == 0) {
355#pragma clang diagnostic push
356#pragma clang diagnostic ignored "-Wbad-function-cast"
358#pragma clang diagnostic pop
359 }
else if (strcmp(
"SinglePostGoal", var_str) == 0) {
360#pragma clang diagnostic push
361#pragma clang diagnostic ignored "-Wbad-function-cast"
363#pragma clang diagnostic pop
365#pragma clang diagnostic push
366#pragma clang diagnostic ignored "-Wbad-function-cast"
367 self->sightingType = ((
enum GoalOptions)atoi(var_str));
368#pragma clang diagnostic pop
386 }
while(index < length);
397 uint16_t bit_offset = 0;
401 for (b = (32 - 1); b >= 0; b--) {
403 uint16_t
byte = bit_offset / 8;
404 uint16_t bit = 7 - (bit_offset % 8);
405 unsigned long newbit = !!((sightingType_nbo >> b) & 1U);
406 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
407 bit_offset = bit_offset + 1;
422 uint16_t bit_offset = 0;
425 for (b = (32 - 1); b >= 0; b--) {
427 uint16_t
byte = bit_offset / 8;
428 uint16_t bit = 7 - (bit_offset % 8);
429 char dataByte = src[byte];
430 unsigned char bitValue = (dataByte >> bit) & 1U;
432 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
enum GoalOptions sightingType
Goal detection details.
const char * wb_vision_detection_goal_description(const struct wb_vision_detection_goal *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_vision_detection_goal_to_network_serialised(const struct wb_vision_detection_goal *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
size_t wb_vision_detection_goal_from_network_serialised(const char *src, struct wb_vision_detection_goal *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_vision_detection_goal_to_string(const struct wb_vision_detection_goal *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_goal * wb_vision_detection_goal_from_string(struct wb_vision_detection_goal *self, const char *str)
Convert from a string.
#define VISION_DETECTION_GOAL_DESC_BUFFER_SIZE
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.
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.
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.
#define VISION_DETECTION_GOAL_POST_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_GOAL_POST_DESC_BUFFER_SIZE