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 += snprintf(descString + len, bufferSize - len,
"numLines=%u", self->numLines);
134 if (len >= bufferSize) {
137 len = gu_strlcat(descString,
", ", bufferSize);
138 if (len >= bufferSize) {
141 len = gu_strlcat(descString,
"lines={", bufferSize);
143 if (len >= bufferSize) {
146 if (lines_index > 0) {
147 len = gu_strlcat(descString,
", ", bufferSize);
149 len = gu_strlcat(descString,
"{", bufferSize);
150 if (len >= bufferSize) {
154 char* lines_1_p = lines_1_buffer;
156 len = gu_strlcat(descString, lines_1_p, bufferSize);
157 if (len >= bufferSize) {
160 len = gu_strlcat(descString,
"}", bufferSize);
162 if (len >= bufferSize) {
165 len = gu_strlcat(descString,
"}", bufferSize);
167#pragma clang diagnostic pop
175#pragma clang diagnostic push
176#pragma clang diagnostic ignored "-Wunused-variable"
178 if (len >= bufferSize) {
181 len += snprintf(toString + len, bufferSize - len,
"%u", self->numLines);
182 if (len >= bufferSize) {
185 len = gu_strlcat(toString,
", ", bufferSize);
186 if (len >= bufferSize) {
189 len = gu_strlcat(toString,
"{", bufferSize);
191 if (len >= bufferSize) {
194 if (lines_index > 0) {
195 len = gu_strlcat(toString,
", ", bufferSize);
197 len = gu_strlcat(toString,
"{", bufferSize);
198 if (len >= bufferSize) {
202 char* lines_1_p = lines_1_buffer;
204 len = gu_strlcat(toString, lines_1_p, bufferSize);
205 if (len >= bufferSize) {
208 len = gu_strlcat(toString,
"}", bufferSize);
210 if (len >= bufferSize) {
213 len = gu_strlcat(toString,
"}", bufferSize);
215#pragma clang diagnostic pop
223 size_t temp_length = strlen(str);
224 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
229 char* var_str = &var_str_buffer[0];
231 char* key = &key_buffer[0];
239 if (index == 0 && str[0] ==
'{') {
245 for (
int i = index; i < length; i++) {
247 if (bracecount == 0 && str[i] ==
'=') {
252 if (bracecount == 0 && isspace(str[i])) {
259 if (bracecount == 0 && str[i] ==
',') {
265 if (bracecount == 1) {
272 if (bracecount < 0) {
277 if (i == length - 1) {
281 if (endKey >= startKey && endKey - startKey < length) {
282 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
283 key[(endKey - startKey) + 1] = 0;
287 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
288 var_str[(index - startVar) + 1] = 0;
294 if (strlen(key) > 0) {
295 if (0 == strcmp(
"numLines", key)) {
297 }
else if (0 == strcmp(
"lines", key)) {
307 self->numLines = ((uint8_t)atoi(var_str));
312 int restartIndex = index;
313 index = lastBrace + 1;
319 for (
int i = index; i < length; i++) {
321 if (bracecount == 0 && str[i] ==
'=') {
326 if (bracecount == 0 && isspace(str[i])) {
333 if (bracecount == 0 && str[i] ==
',') {
343 if (bracecount < 0) {
348 if (i == length - 1) {
352 if (endKey >= startKey && endKey - startKey < length) {
353 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
354 key[(endKey - startKey) + 1] = 0;
358 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
359 var_str[(index - startVar) + 1] = 0;
367 self->lines[lines_0_index] = lines_0;
369 index = restartIndex;
376 }
while(index < length);
387 uint16_t bit_offset = 0;
388 uint8_t numLines_nbo = (
self->numLines);
391 for (b = (8 - 1); b >= 0; b--) {
393 uint16_t
byte = bit_offset / 8;
394 uint16_t bit = 7 - (bit_offset % 8);
395 unsigned long newbit = !!((numLines_nbo >> b) & 1U);
396 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
397 bit_offset = bit_offset + 1;
407 const char *buf = (
const char *)&self->lines[0];
410 for (c = 0; c < bytes; c++) {
411 for (b = 7; b >= 0; b--) {
413 uint16_t
byte = bit_offset / 8;
414 uint16_t bit = 7 - (bit_offset % 8);
415 unsigned long newbit = !!((buf[c] >> b) & 1U);
416 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
417 bit_offset = bit_offset + 1;
433 uint16_t bit_offset = 0;
436 for (b = (8 - 1); b >= 0; b--) {
438 uint16_t
byte = bit_offset / 8;
439 uint16_t bit = 7 - (bit_offset % 8);
440 char dataByte = src[byte];
441 unsigned char bitValue = (dataByte >> bit) & 1U;
443 bit_offset = bit_offset + 1;
454 char *buf = (
char *)malloc(bytes);
457 for (c = 0; c < bytes; c++) {
458 for (b = 7; b >= 0; b--) {
460 uint16_t
byte = bit_offset / 8;
461 uint16_t bit = 7 - (bit_offset % 8);
462 char dataByte = src[byte];
463 unsigned char bitValue = (dataByte >> bit) & 1U;
464 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
465 bit_offset = bit_offset + 1;
469 memcpy(&dst->
lines[0], &buf[0], bytes);
WHITEBOARD_POSTER_STRING_CONVERSION.
Results for the Line Ray Tracer (guvision).
uint8_t numLines
The number of lines reported on the camera.
struct wb_pixel_coordinate_line lines[7]
Lines reported from the camera.
struct wb_pixel_coordinate_line * wb_pixel_coordinate_line_from_string(struct wb_pixel_coordinate_line *self, const char *str)
Convert from a string.
const char * wb_pixel_coordinate_line_to_string(const struct wb_pixel_coordinate_line *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_pixel_coordinate_line_description(const struct wb_pixel_coordinate_line *self, char *descString, size_t bufferSize)
Convert to a description string.
#define PIXEL_COORDINATE_LINE_TO_STRING_BUFFER_SIZE
#define PIXEL_COORDINATE_LINE_DESC_BUFFER_SIZE
const char * wb_vision_detection_line_array_description(const struct wb_vision_detection_line_array *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_vision_detection_line_array * wb_vision_detection_line_array_from_string(struct wb_vision_detection_line_array *self, const char *str)
Convert from a string.
size_t wb_vision_detection_line_array_from_network_serialised(const char *src, struct wb_vision_detection_line_array *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_vision_detection_line_array_to_string(const struct wb_vision_detection_line_array *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_vision_detection_line_array_to_network_serialised(const struct wb_vision_detection_line_array *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define VISION_DETECTION_LINE_ARRAY_DESC_BUFFER_SIZE
#define VISION_DETECTION_LINE_ARRAY_LINES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.