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,
"direction=%d", self->direction);
134 if (len >= bufferSize) {
137 len = gu_strlcat(descString,
", ", bufferSize);
138 if (len >= bufferSize) {
141 len += snprintf(descString + len, bufferSize - len,
"distance=%u", self->distance);
142 if (len >= bufferSize) {
145 len = gu_strlcat(descString,
", ", bufferSize);
146 if (len >= bufferSize) {
149 len += snprintf(descString + len, bufferSize - len,
"confidence=%u", self->confidence);
150 if (len >= bufferSize) {
153 len = gu_strlcat(descString,
", ", bufferSize);
154 if (len >= bufferSize) {
157 len += snprintf(descString + len, bufferSize - len,
"distanceVariance=%u", self->distanceVariance);
158 if (len >= bufferSize) {
161 len = gu_strlcat(descString,
", ", bufferSize);
162 if (len >= bufferSize) {
165 len += snprintf(descString + len, bufferSize - len,
"directionVariance=%u", self->directionVariance);
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,
"%d", self->direction);
182 if (len >= bufferSize) {
185 len = gu_strlcat(toString,
", ", bufferSize);
186 if (len >= bufferSize) {
189 len += snprintf(toString + len, bufferSize - len,
"%u", self->distance);
190 if (len >= bufferSize) {
193 len = gu_strlcat(toString,
", ", bufferSize);
194 if (len >= bufferSize) {
197 len += snprintf(toString + len, bufferSize - len,
"%u", self->confidence);
198 if (len >= bufferSize) {
201 len = gu_strlcat(toString,
", ", bufferSize);
202 if (len >= bufferSize) {
205 len += snprintf(toString + len, bufferSize - len,
"%u", self->distanceVariance);
206 if (len >= bufferSize) {
209 len = gu_strlcat(toString,
", ", bufferSize);
210 if (len >= bufferSize) {
213 len += snprintf(toString + len, bufferSize - len,
"%u", self->directionVariance);
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];
238 if (index == 0 && str[0] ==
'{') {
244 for (
int i = index; i < length; i++) {
246 if (bracecount == 0 && str[i] ==
'=') {
251 if (bracecount == 0 && isspace(str[i])) {
258 if (bracecount == 0 && str[i] ==
',') {
268 if (bracecount < 0) {
273 if (i == length - 1) {
277 if (endKey >= startKey && endKey - startKey < length) {
278 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
279 key[(endKey - startKey) + 1] = 0;
283 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
284 var_str[(index - startVar) + 1] = 0;
290 if (strlen(key) > 0) {
291 if (0 == strcmp(
"direction", key)) {
293 }
else if (0 == strcmp(
"distance", key)) {
295 }
else if (0 == strcmp(
"confidence", key)) {
297 }
else if (0 == strcmp(
"distanceVariance", key)) {
299 }
else if (0 == strcmp(
"directionVariance", key)) {
309 self->direction = ((int16_t)atoi(var_str));
314 self->distance = ((uint16_t)atoi(var_str));
319 self->confidence = ((uint8_t)atoi(var_str));
324 self->distanceVariance = ((uint32_t)atoi(var_str));
329 self->directionVariance = ((uint32_t)atoi(var_str));
336 }
while(index < length);
347 uint16_t bit_offset = 0;
348 int16_t direction_nbo =
htons(self->direction);
351 for (b = (16 - 1); b >= 0; b--) {
353 uint16_t
byte = bit_offset / 8;
354 uint16_t bit = 7 - (bit_offset % 8);
355 unsigned long newbit = !!((direction_nbo >> b) & 1U);
356 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
357 bit_offset = bit_offset + 1;
362 uint16_t distance_nbo =
htons(self->distance);
365 for (b = (16 - 1); b >= 0; b--) {
367 uint16_t
byte = bit_offset / 8;
368 uint16_t bit = 7 - (bit_offset % 8);
369 unsigned long newbit = !!((distance_nbo >> b) & 1U);
370 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
371 bit_offset = bit_offset + 1;
376 uint8_t confidence_nbo = (
self->confidence);
379 for (b = (8 - 1); b >= 0; b--) {
381 uint16_t
byte = bit_offset / 8;
382 uint16_t bit = 7 - (bit_offset % 8);
383 unsigned long newbit = !!((confidence_nbo >> b) & 1U);
384 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
385 bit_offset = bit_offset + 1;
390 uint32_t distanceVariance_nbo =
htonl(self->distanceVariance);
393 for (b = (32 - 1); b >= 0; b--) {
395 uint16_t
byte = bit_offset / 8;
396 uint16_t bit = 7 - (bit_offset % 8);
397 unsigned long newbit = !!((distanceVariance_nbo >> b) & 1U);
398 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
399 bit_offset = bit_offset + 1;
404 uint32_t directionVariance_nbo =
htonl(self->directionVariance);
407 for (b = (32 - 1); b >= 0; b--) {
409 uint16_t
byte = bit_offset / 8;
410 uint16_t bit = 7 - (bit_offset % 8);
411 unsigned long newbit = !!((directionVariance_nbo >> b) & 1U);
412 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
413 bit_offset = bit_offset + 1;
428 uint16_t bit_offset = 0;
431 for (b = (16 - 1); b >= 0; b--) {
433 uint16_t
byte = bit_offset / 8;
434 uint16_t bit = 7 - (bit_offset % 8);
435 char dataByte = src[byte];
436 unsigned char bitValue = (dataByte >> bit) & 1U;
438 bit_offset = bit_offset + 1;
446 for (b = (16 - 1); b >= 0; b--) {
448 uint16_t
byte = bit_offset / 8;
449 uint16_t bit = 7 - (bit_offset % 8);
450 char dataByte = src[byte];
451 unsigned char bitValue = (dataByte >> bit) & 1U;
453 bit_offset = bit_offset + 1;
461 for (b = (8 - 1); b >= 0; b--) {
463 uint16_t
byte = bit_offset / 8;
464 uint16_t bit = 7 - (bit_offset % 8);
465 char dataByte = src[byte];
466 unsigned char bitValue = (dataByte >> bit) & 1U;
468 bit_offset = bit_offset + 1;
476 for (b = (32 - 1); b >= 0; b--) {
478 uint16_t
byte = bit_offset / 8;
479 uint16_t bit = 7 - (bit_offset % 8);
480 char dataByte = src[byte];
481 unsigned char bitValue = (dataByte >> bit) & 1U;
483 bit_offset = bit_offset + 1;
491 for (b = (32 - 1); b >= 0; b--) {
493 uint16_t
byte = bit_offset / 8;
494 uint16_t bit = 7 - (bit_offset % 8);
495 char dataByte = src[byte];
496 unsigned char bitValue = (dataByte >> bit) & 1U;
498 bit_offset = bit_offset + 1;
514 deg_d_to_i16(coord.direction),
515 cm_u_to_u16(mm_u_to_cm_u(coord.distance)),
525 const gu_relative_coordinate out = {
526 i16_to_deg_d(location.direction),
527 cm_u_to_mm_u(u16_to_cm_u(location.distance))
534 const gu_optional_relative_coordinate out = {
535 location.confidence >= confidence,
WHITEBOARD_POSTER_STRING_CONVERSION.
uint32_t distanceVariance
The variance of the distance.
uint32_t directionVariance
The variance of the direction.
int16_t direction
degrees, relative to the center of the nao torso.
uint8_t confidence
The type of sighting.
uint16_t distance
CM distance to the center point of the sighting.
size_t wb_location_to_network_serialised(const struct wb_location *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_location_description(const struct wb_location *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_location_to_string(const struct wb_location *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_location rr_coord_to_wb_location(const gu_relative_coordinate coord, const uint8_t confidence, const uint32_t distanceVariance, const uint32_t directionVariance)
WHITEBOARD_POSTER_STRING_CONVERSION.
struct gu_optional_relative_coordinate wb_location_to_opt_rr_coord(const struct wb_location location, const uint8_t confidence)
Converts a wb_location to a gu_optional_relative_coordinate.
struct wb_location * wb_location_from_string(struct wb_location *self, const char *str)
Convert from a string.
struct gu_relative_coordinate wb_location_to_rr_coord(const struct wb_location location)
Converts a wb_location to a gu_relative_coordinate.
size_t wb_location_from_network_serialised(const char *src, struct wb_location *dst)
Convert from a compressed, serialised, network byte order byte stream.
#define LOCATION_DESC_BUFFER_SIZE