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 = gu_strlcat(descString,
"lines={", bufferSize);
135 if (len >= bufferSize) {
138 if (lines_index > 0) {
139 len = gu_strlcat(descString,
", ", bufferSize);
141 len = gu_strlcat(descString,
"{", bufferSize);
142 if (len >= bufferSize) {
146 char* lines_1_p = lines_1_buffer;
148 len = gu_strlcat(descString, lines_1_p, bufferSize);
149 if (len >= bufferSize) {
152 len = gu_strlcat(descString,
"}", bufferSize);
154 if (len >= bufferSize) {
157 len = gu_strlcat(descString,
"}", bufferSize);
158 if (len >= bufferSize) {
161 len = gu_strlcat(descString,
", ", bufferSize);
162 if (len >= bufferSize) {
165 len += snprintf(descString + len, bufferSize - len,
"numLines=%u", self->numLines);
166 if (len >= bufferSize) {
169 len = gu_strlcat(descString,
", ", bufferSize);
170 if (len >= bufferSize) {
174 len += snprintf(descString + len, bufferSize - len,
"frameNumber=%llu", self->frameNumber);
176 len += snprintf(descString + len, bufferSize - len,
"frameNumber=%lu", self->frameNumber);
178 if (len >= bufferSize) {
181 len = gu_strlcat(descString,
", ", bufferSize);
182 if (len >= bufferSize) {
185 len += snprintf(descString + len, bufferSize - len,
"res_width=%u", self->res_width);
186 if (len >= bufferSize) {
189 len = gu_strlcat(descString,
", ", bufferSize);
190 if (len >= bufferSize) {
193 len += snprintf(descString + len, bufferSize - len,
"res_height=%u", self->res_height);
195#pragma clang diagnostic pop
203#pragma clang diagnostic push
204#pragma clang diagnostic ignored "-Wunused-variable"
206 if (len >= bufferSize) {
209 len = gu_strlcat(toString,
"{", bufferSize);
211 if (len >= bufferSize) {
214 if (lines_index > 0) {
215 len = gu_strlcat(toString,
", ", bufferSize);
217 len = gu_strlcat(toString,
"{", bufferSize);
218 if (len >= bufferSize) {
222 char* lines_1_p = lines_1_buffer;
224 len = gu_strlcat(toString, lines_1_p, bufferSize);
225 if (len >= bufferSize) {
228 len = gu_strlcat(toString,
"}", bufferSize);
230 if (len >= bufferSize) {
233 len = gu_strlcat(toString,
"}", bufferSize);
234 if (len >= bufferSize) {
237 len = gu_strlcat(toString,
", ", bufferSize);
238 if (len >= bufferSize) {
241 len += snprintf(toString + len, bufferSize - len,
"%u", self->numLines);
242 if (len >= bufferSize) {
245 len = gu_strlcat(toString,
", ", bufferSize);
246 if (len >= bufferSize) {
250 len += snprintf(toString + len, bufferSize - len,
"%llu", self->frameNumber);
252 len += snprintf(toString + len, bufferSize - len,
"%lu", self->frameNumber);
254 if (len >= bufferSize) {
257 len = gu_strlcat(toString,
", ", bufferSize);
258 if (len >= bufferSize) {
261 len += snprintf(toString + len, bufferSize - len,
"%u", self->res_width);
262 if (len >= bufferSize) {
265 len = gu_strlcat(toString,
", ", bufferSize);
266 if (len >= bufferSize) {
269 len += snprintf(toString + len, bufferSize - len,
"%u", self->res_height);
271#pragma clang diagnostic pop
279 size_t temp_length = strlen(str);
280 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
285 char* var_str = &var_str_buffer[0];
287 char* key = &key_buffer[0];
295 if (index == 0 && str[0] ==
'{') {
301 for (
int i = index; i < length; i++) {
303 if (bracecount == 0 && str[i] ==
'=') {
308 if (bracecount == 0 && isspace(str[i])) {
315 if (bracecount == 0 && str[i] ==
',') {
321 if (bracecount == 1) {
328 if (bracecount < 0) {
333 if (i == length - 1) {
337 if (endKey >= startKey && endKey - startKey < length) {
338 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
339 key[(endKey - startKey) + 1] = 0;
343 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
344 var_str[(index - startVar) + 1] = 0;
350 if (strlen(key) > 0) {
351 if (0 == strcmp(
"lines", key)) {
353 }
else if (0 == strcmp(
"numLines", key)) {
355 }
else if (0 == strcmp(
"frameNumber", key)) {
357 }
else if (0 == strcmp(
"res_width", key)) {
359 }
else if (0 == strcmp(
"res_height", key)) {
369 int restartIndex = index;
370 index = lastBrace + 1;
376 for (
int i = index; i < length; i++) {
378 if (bracecount == 0 && str[i] ==
'=') {
383 if (bracecount == 0 && isspace(str[i])) {
390 if (bracecount == 0 && str[i] ==
',') {
400 if (bracecount < 0) {
405 if (i == length - 1) {
409 if (endKey >= startKey && endKey - startKey < length) {
410 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
411 key[(endKey - startKey) + 1] = 0;
415 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
416 var_str[(index - startVar) + 1] = 0;
424 self->lines[lines_0_index] = lines_0;
426 index = restartIndex;
431 self->numLines = ((uint8_t)atoi(var_str));
437 self->frameNumber = ((uint64_t)atoll(var_str));
439 self->frameNumber = ((uint64_t)atol(var_str));
445 self->res_width = ((uint16_t)atoi(var_str));
450 self->res_height = ((uint16_t)atoi(var_str));
457 }
while(index < length);
468 uint16_t bit_offset = 0;
474 const char *buf = (
const char *)&self->lines[0];
477 for (c = 0; c < bytes; c++) {
478 for (b = 7; b >= 0; b--) {
480 uint16_t
byte = bit_offset / 8;
481 uint16_t bit = 7 - (bit_offset % 8);
482 unsigned long newbit = !!((buf[c] >> b) & 1U);
483 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
484 bit_offset = bit_offset + 1;
490 uint8_t numLines_nbo = (
self->numLines);
493 for (b = (8 - 1); b >= 0; b--) {
495 uint16_t
byte = bit_offset / 8;
496 uint16_t bit = 7 - (bit_offset % 8);
497 unsigned long newbit = !!((numLines_nbo >> b) & 1U);
498 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
499 bit_offset = bit_offset + 1;
504 uint64_t frameNumber_nbo =
htonll(self->frameNumber);
507 for (b = (64 - 1); b >= 0; b--) {
509 uint16_t
byte = bit_offset / 8;
510 uint16_t bit = 7 - (bit_offset % 8);
511 unsigned long newbit = !!((frameNumber_nbo >> b) & 1U);
512 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
513 bit_offset = bit_offset + 1;
518 uint16_t res_width_nbo =
htons(self->res_width);
521 for (b = (16 - 1); b >= 0; b--) {
523 uint16_t
byte = bit_offset / 8;
524 uint16_t bit = 7 - (bit_offset % 8);
525 unsigned long newbit = !!((res_width_nbo >> b) & 1U);
526 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
527 bit_offset = bit_offset + 1;
532 uint16_t res_height_nbo =
htons(self->res_height);
535 for (b = (16 - 1); b >= 0; b--) {
537 uint16_t
byte = bit_offset / 8;
538 uint16_t bit = 7 - (bit_offset % 8);
539 unsigned long newbit = !!((res_height_nbo >> b) & 1U);
540 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
541 bit_offset = bit_offset + 1;
556 uint16_t bit_offset = 0;
562 char *buf = (
char *)malloc(bytes);
565 for (c = 0; c < bytes; c++) {
566 for (b = 7; b >= 0; b--) {
568 uint16_t
byte = bit_offset / 8;
569 uint16_t bit = 7 - (bit_offset % 8);
570 char dataByte = src[byte];
571 unsigned char bitValue = (dataByte >> bit) & 1U;
572 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
573 bit_offset = bit_offset + 1;
577 memcpy(&dst->
lines[0], &buf[0], bytes);
583 for (b = (8 - 1); b >= 0; b--) {
585 uint16_t
byte = bit_offset / 8;
586 uint16_t bit = 7 - (bit_offset % 8);
587 char dataByte = src[byte];
588 unsigned char bitValue = (dataByte >> bit) & 1U;
590 bit_offset = bit_offset + 1;
598 for (b = (64 - 1); b >= 0; b--) {
600 uint16_t
byte = bit_offset / 8;
601 uint16_t bit = 7 - (bit_offset % 8);
602 char dataByte = src[byte];
603 unsigned char bitValue = (dataByte >> bit) & 1U;
605 bit_offset = bit_offset + 1;
613 for (b = (16 - 1); b >= 0; b--) {
615 uint16_t
byte = bit_offset / 8;
616 uint16_t bit = 7 - (bit_offset % 8);
617 char dataByte = src[byte];
618 unsigned char bitValue = (dataByte >> bit) & 1U;
620 bit_offset = bit_offset + 1;
628 for (b = (16 - 1); b >= 0; b--) {
630 uint16_t
byte = bit_offset / 8;
631 uint16_t bit = 7 - (bit_offset % 8);
632 char dataByte = src[byte];
633 unsigned char bitValue = (dataByte >> bit) & 1U;
635 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
Class use to represent lines detected by vision for a single camera and posted to the whiteboard.
uint8_t numLines
The number of lines reported on the camera.
uint16_t res_width
The resolution width.
uint64_t frameNumber
The frame number that these lines were seen in.
struct wb_vision_line lines[7]
Lines reported from the camera.
uint16_t res_height
The resolution height.
const char * wb_vision_line_description(const struct wb_vision_line *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_vision_line_to_string(const struct wb_vision_line *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_line * wb_vision_line_from_string(struct wb_vision_line *self, const char *str)
Convert from a string.
#define VISION_LINE_DESC_BUFFER_SIZE
#define VISION_LINE_TO_STRING_BUFFER_SIZE
const char * wb_vision_lines_description(const struct wb_vision_lines *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_vision_lines * wb_vision_lines_from_string(struct wb_vision_lines *self, const char *str)
Convert from a string.
const char * wb_vision_lines_to_string(const struct wb_vision_lines *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_vision_lines_to_network_serialised(const struct wb_vision_lines *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
size_t wb_vision_lines_from_network_serialised(const char *src, struct wb_vision_lines *dst)
Convert from a compressed, serialised, network byte order byte stream.
#define VISION_LINES_DESC_BUFFER_SIZE
#define VISION_LINES_LINES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.