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) {
134 len += snprintf(descString + len, bufferSize - len,
"frameNumber=%llu", self->frameNumber);
136 len += snprintf(descString + len, bufferSize - len,
"frameNumber=%lu", self->frameNumber);
138 if (len >= bufferSize) {
141 len = gu_strlcat(descString,
", ", bufferSize);
142 if (len >= bufferSize) {
145 len = gu_strlcat(descString,
"horizons={", bufferSize);
147 if (len >= bufferSize) {
150 if (horizons_index > 0) {
151 len = gu_strlcat(descString,
", ", bufferSize);
153 len = gu_strlcat(descString,
"{", bufferSize);
154 if (len >= bufferSize) {
158 char* horizons_1_p = horizons_1_buffer;
160 len = gu_strlcat(descString, horizons_1_p, bufferSize);
161 if (len >= bufferSize) {
164 len = gu_strlcat(descString,
"}", bufferSize);
166 if (len >= bufferSize) {
169 len = gu_strlcat(descString,
"}", bufferSize);
170 if (len >= bufferSize) {
173 len = gu_strlcat(descString,
", ", bufferSize);
174 if (len >= bufferSize) {
177 len += snprintf(descString + len, bufferSize - len,
"res_width=%u", self->res_width);
178 if (len >= bufferSize) {
181 len = gu_strlcat(descString,
", ", bufferSize);
182 if (len >= bufferSize) {
185 len += snprintf(descString + len, bufferSize - len,
"res_height=%u", self->res_height);
187#pragma clang diagnostic pop
195#pragma clang diagnostic push
196#pragma clang diagnostic ignored "-Wunused-variable"
198 if (len >= bufferSize) {
202 len += snprintf(toString + len, bufferSize - len,
"%llu", self->frameNumber);
204 len += snprintf(toString + len, bufferSize - len,
"%lu", self->frameNumber);
206 if (len >= bufferSize) {
209 len = gu_strlcat(toString,
", ", bufferSize);
210 if (len >= bufferSize) {
213 len = gu_strlcat(toString,
"{", bufferSize);
215 if (len >= bufferSize) {
218 if (horizons_index > 0) {
219 len = gu_strlcat(toString,
", ", bufferSize);
221 len = gu_strlcat(toString,
"{", bufferSize);
222 if (len >= bufferSize) {
226 char* horizons_1_p = horizons_1_buffer;
228 len = gu_strlcat(toString, horizons_1_p, bufferSize);
229 if (len >= bufferSize) {
232 len = gu_strlcat(toString,
"}", bufferSize);
234 if (len >= bufferSize) {
237 len = gu_strlcat(toString,
"}", bufferSize);
238 if (len >= bufferSize) {
241 len = gu_strlcat(toString,
", ", bufferSize);
242 if (len >= bufferSize) {
245 len += snprintf(toString + len, bufferSize - len,
"%u", self->res_width);
246 if (len >= bufferSize) {
249 len = gu_strlcat(toString,
", ", bufferSize);
250 if (len >= bufferSize) {
253 len += snprintf(toString + len, bufferSize - len,
"%u", self->res_height);
255#pragma clang diagnostic pop
263 size_t temp_length = strlen(str);
264 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
269 char* var_str = &var_str_buffer[0];
271 char* key = &key_buffer[0];
279 if (index == 0 && str[0] ==
'{') {
285 for (
int i = index; i < length; i++) {
287 if (bracecount == 0 && str[i] ==
'=') {
292 if (bracecount == 0 && isspace(str[i])) {
299 if (bracecount == 0 && str[i] ==
',') {
305 if (bracecount == 1) {
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(
"frameNumber", key)) {
337 }
else if (0 == strcmp(
"horizons", key)) {
339 }
else if (0 == strcmp(
"res_width", key)) {
341 }
else if (0 == strcmp(
"res_height", key)) {
352 self->frameNumber = ((uint64_t)atoll(var_str));
354 self->frameNumber = ((uint64_t)atol(var_str));
360 int restartIndex = index;
361 index = lastBrace + 1;
367 for (
int i = index; i < length; i++) {
369 if (bracecount == 0 && str[i] ==
'=') {
374 if (bracecount == 0 && isspace(str[i])) {
381 if (bracecount == 0 && str[i] ==
',') {
391 if (bracecount < 0) {
396 if (i == length - 1) {
400 if (endKey >= startKey && endKey - startKey < length) {
401 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
402 key[(endKey - startKey) + 1] = 0;
406 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
407 var_str[(index - startVar) + 1] = 0;
415 self->horizons[horizons_0_index] = horizons_0;
417 index = restartIndex;
422 self->res_width = ((uint16_t)atoi(var_str));
427 self->res_height = ((uint16_t)atoi(var_str));
434 }
while(index < length);
445 uint16_t bit_offset = 0;
446 uint64_t frameNumber_nbo =
htonll(self->frameNumber);
449 for (b = (64 - 1); b >= 0; b--) {
451 uint16_t
byte = bit_offset / 8;
452 uint16_t bit = 7 - (bit_offset % 8);
453 unsigned long newbit = !!((frameNumber_nbo >> b) & 1U);
454 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
455 bit_offset = bit_offset + 1;
465 const char *buf = (
const char *)&self->horizons[0];
468 for (c = 0; c < bytes; c++) {
469 for (b = 7; b >= 0; b--) {
471 uint16_t
byte = bit_offset / 8;
472 uint16_t bit = 7 - (bit_offset % 8);
473 unsigned long newbit = !!((buf[c] >> b) & 1U);
474 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
475 bit_offset = bit_offset + 1;
481 uint16_t res_width_nbo =
htons(self->res_width);
484 for (b = (16 - 1); b >= 0; b--) {
486 uint16_t
byte = bit_offset / 8;
487 uint16_t bit = 7 - (bit_offset % 8);
488 unsigned long newbit = !!((res_width_nbo >> b) & 1U);
489 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
490 bit_offset = bit_offset + 1;
495 uint16_t res_height_nbo =
htons(self->res_height);
498 for (b = (16 - 1); b >= 0; b--) {
500 uint16_t
byte = bit_offset / 8;
501 uint16_t bit = 7 - (bit_offset % 8);
502 unsigned long newbit = !!((res_height_nbo >> b) & 1U);
503 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
504 bit_offset = bit_offset + 1;
519 uint16_t bit_offset = 0;
522 for (b = (64 - 1); b >= 0; b--) {
524 uint16_t
byte = bit_offset / 8;
525 uint16_t bit = 7 - (bit_offset % 8);
526 char dataByte = src[byte];
527 unsigned char bitValue = (dataByte >> bit) & 1U;
529 bit_offset = bit_offset + 1;
540 char *buf = (
char *)malloc(bytes);
543 for (c = 0; c < bytes; c++) {
544 for (b = 7; 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;
550 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
551 bit_offset = bit_offset + 1;
555 memcpy(&dst->
horizons[0], &buf[0], bytes);
561 for (b = (16 - 1); b >= 0; b--) {
563 uint16_t
byte = bit_offset / 8;
564 uint16_t bit = 7 - (bit_offset % 8);
565 char dataByte = src[byte];
566 unsigned char bitValue = (dataByte >> bit) & 1U;
568 bit_offset = bit_offset + 1;
576 for (b = (16 - 1); b >= 0; b--) {
578 uint16_t
byte = bit_offset / 8;
579 uint16_t bit = 7 - (bit_offset % 8);
580 char dataByte = src[byte];
581 unsigned char bitValue = (dataByte >> bit) & 1U;
583 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
Array of fieldHorizons, one instance reported by each camera.
uint16_t res_width
The resolution width.
uint64_t frameNumber
visionFrameNumber
uint16_t res_height
The resolution height.
struct wb_vision_detection_horizon horizons[2]
horizon objects
const char * wb_vision_detection_horizon_to_string(const struct wb_vision_detection_horizon *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_horizon * wb_vision_detection_horizon_from_string(struct wb_vision_detection_horizon *self, const char *str)
Convert from a string.
const char * wb_vision_detection_horizon_description(const struct wb_vision_detection_horizon *self, char *descString, size_t bufferSize)
Convert to a description string.
#define VISION_DETECTION_HORIZON_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_HORIZON_DESC_BUFFER_SIZE
size_t wb_vision_detection_horizons_from_network_serialised(const char *src, struct wb_vision_detection_horizons *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_vision_detection_horizons_description(const struct wb_vision_detection_horizons *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_vision_detection_horizons_to_string(const struct wb_vision_detection_horizons *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_horizons * wb_vision_detection_horizons_from_string(struct wb_vision_detection_horizons *self, const char *str)
Convert from a string.
size_t wb_vision_detection_horizons_to_network_serialised(const struct wb_vision_detection_horizons *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define VISION_DETECTION_HORIZONS_HORIZONS_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define VISION_DETECTION_HORIZONS_DESC_BUFFER_SIZE