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->horizonType) {
136 len += snprintf(descString + len, bufferSize - len,
"horizonType=CornerHorizon");
141 len += snprintf(descString + len, bufferSize - len,
"horizonType=HorizonFailed");
146 len += snprintf(descString + len, bufferSize - len,
"horizonType=OnlyField");
151 len += snprintf(descString + len, bufferSize - len,
"horizonType=SingleHorizon");
155 if (len >= bufferSize) {
158 len = gu_strlcat(descString,
", ", bufferSize);
159 if (len >= bufferSize) {
162 len = gu_strlcat(descString,
"leftCoordinate={", bufferSize);
163 if (len >= bufferSize) {
167 char* leftCoordinate_p = leftCoordinate_buffer;
169 len = gu_strlcat(descString, leftCoordinate_p, bufferSize);
170 if (len >= bufferSize) {
173 len = gu_strlcat(descString,
"}", bufferSize);
174 if (len >= bufferSize) {
177 len = gu_strlcat(descString,
", ", bufferSize);
178 if (len >= bufferSize) {
181 len = gu_strlcat(descString,
"centerCoordinate={", bufferSize);
182 if (len >= bufferSize) {
186 char* centerCoordinate_p = centerCoordinate_buffer;
188 len = gu_strlcat(descString, centerCoordinate_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,
"rightCoordinate={", bufferSize);
201 if (len >= bufferSize) {
205 char* rightCoordinate_p = rightCoordinate_buffer;
207 len = gu_strlcat(descString, rightCoordinate_p, bufferSize);
208 if (len >= bufferSize) {
211 len = gu_strlcat(descString,
"}", bufferSize);
213#pragma clang diagnostic pop
221#pragma clang diagnostic push
222#pragma clang diagnostic ignored "-Wunused-variable"
224 if (len >= bufferSize) {
227 switch (self->horizonType) {
230 len += snprintf(toString + len, bufferSize - len,
"CornerHorizon");
235 len += snprintf(toString + len, bufferSize - len,
"HorizonFailed");
240 len += snprintf(toString + len, bufferSize - len,
"OnlyField");
245 len += snprintf(toString + len, bufferSize - len,
"SingleHorizon");
249 if (len >= bufferSize) {
252 len = gu_strlcat(toString,
", ", bufferSize);
253 if (len >= bufferSize) {
256 len = gu_strlcat(toString,
"{", bufferSize);
257 if (len >= bufferSize) {
261 char* leftCoordinate_p = leftCoordinate_buffer;
263 len = gu_strlcat(toString, leftCoordinate_p, bufferSize);
264 if (len >= bufferSize) {
267 len = gu_strlcat(toString,
"}", bufferSize);
268 if (len >= bufferSize) {
271 len = gu_strlcat(toString,
", ", bufferSize);
272 if (len >= bufferSize) {
275 len = gu_strlcat(toString,
"{", bufferSize);
276 if (len >= bufferSize) {
280 char* centerCoordinate_p = centerCoordinate_buffer;
282 len = gu_strlcat(toString, centerCoordinate_p, bufferSize);
283 if (len >= bufferSize) {
286 len = gu_strlcat(toString,
"}", bufferSize);
287 if (len >= bufferSize) {
290 len = gu_strlcat(toString,
", ", bufferSize);
291 if (len >= bufferSize) {
294 len = gu_strlcat(toString,
"{", bufferSize);
295 if (len >= bufferSize) {
299 char* rightCoordinate_p = rightCoordinate_buffer;
301 len = gu_strlcat(toString, rightCoordinate_p, bufferSize);
302 if (len >= bufferSize) {
305 len = gu_strlcat(toString,
"}", bufferSize);
307#pragma clang diagnostic pop
315 size_t temp_length = strlen(str);
316 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
321 char* var_str = &var_str_buffer[0];
323 char* key = &key_buffer[0];
330 if (index == 0 && str[0] ==
'{') {
336 for (
int i = index; i < length; i++) {
338 if (bracecount == 0 && str[i] ==
'=') {
343 if (bracecount == 0 && isspace(str[i])) {
350 if (bracecount == 0 && str[i] ==
',') {
360 if (bracecount < 0) {
365 if (i == length - 1) {
369 if (endKey >= startKey && endKey - startKey < length) {
370 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
371 key[(endKey - startKey) + 1] = 0;
375 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
376 var_str[(index - startVar) + 1] = 0;
382 if (strlen(key) > 0) {
383 if (0 == strcmp(
"horizonType", key)) {
385 }
else if (0 == strcmp(
"leftCoordinate", key)) {
387 }
else if (0 == strcmp(
"centerCoordinate", key)) {
389 }
else if (0 == strcmp(
"rightCoordinate", key)) {
399 if (strcmp(
"CornerHorizon", var_str) == 0) {
400#pragma clang diagnostic push
401#pragma clang diagnostic ignored "-Wbad-function-cast"
403#pragma clang diagnostic pop
404 }
else if (strcmp(
"HorizonFailed", var_str) == 0) {
405#pragma clang diagnostic push
406#pragma clang diagnostic ignored "-Wbad-function-cast"
408#pragma clang diagnostic pop
409 }
else if (strcmp(
"OnlyField", var_str) == 0) {
410#pragma clang diagnostic push
411#pragma clang diagnostic ignored "-Wbad-function-cast"
413#pragma clang diagnostic pop
414 }
else if (strcmp(
"SingleHorizon", var_str) == 0) {
415#pragma clang diagnostic push
416#pragma clang diagnostic ignored "-Wbad-function-cast"
418#pragma clang diagnostic pop
420#pragma clang diagnostic push
421#pragma clang diagnostic ignored "-Wbad-function-cast"
423#pragma clang diagnostic pop
446 }
while(index < length);
457 uint16_t bit_offset = 0;
461 for (b = (32 - 1); b >= 0; b--) {
463 uint16_t
byte = bit_offset / 8;
464 uint16_t bit = 7 - (bit_offset % 8);
465 unsigned long newbit = !!((horizonType_nbo >> b) & 1U);
466 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
467 bit_offset = bit_offset + 1;
482 uint16_t bit_offset = 0;
485 for (b = (32 - 1); b >= 0; b--) {
487 uint16_t
byte = bit_offset / 8;
488 uint16_t bit = 7 - (bit_offset % 8);
489 char dataByte = src[byte];
490 unsigned char bitValue = (dataByte >> bit) & 1U;
492 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
enum HorizonOptions horizonType
Type of Horizon.
struct wb_pixel_coordinate leftCoordinate
Left horizon point pixel coordinate.
struct wb_pixel_coordinate rightCoordinate
Right horizon point pixel coordinate.
struct wb_pixel_coordinate centerCoordinate
Center horizon point 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_horizon_from_network_serialised(const char *src, struct wb_vision_detection_horizon *dst)
Convert from a compressed, serialised, network byte order byte stream.
gu_pixel_coordinate wb_vision_detection_horizon_leftCoordinate_px_coord(const struct wb_vision_detection_horizon self, const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
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.
gu_pixel_coordinate wb_vision_detection_horizon_rightCoordinate_px_coord(const struct wb_vision_detection_horizon self, const uint16_t resWidth, const uint16_t resHeight)
const char * wb_vision_detection_horizon_description(const struct wb_vision_detection_horizon *self, char *descString, size_t bufferSize)
Convert to a description string.
gu_pixel_coordinate wb_vision_detection_horizon_centerCoordinate_px_coord(const struct wb_vision_detection_horizon self, const uint16_t resWidth, const uint16_t resHeight)
size_t wb_vision_detection_horizon_to_network_serialised(const struct wb_vision_detection_horizon *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define VISION_DETECTION_HORIZON_DESC_BUFFER_SIZE