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,
"position={", bufferSize);
134 if (len >= bufferSize) {
138 char* position_p = position_buffer;
140 len = gu_strlcat(descString, position_p, bufferSize);
141 if (len >= bufferSize) {
144 len = gu_strlcat(descString,
"}", bufferSize);
145 if (len >= bufferSize) {
148 len = gu_strlcat(descString,
", ", bufferSize);
149 if (len >= bufferSize) {
152 len += snprintf(descString + len, bufferSize - len,
"headingInDegrees=%d", self->headingInDegrees);
153 if (len >= bufferSize) {
156 len = gu_strlcat(descString,
", ", bufferSize);
157 if (len >= bufferSize) {
160 len += snprintf(descString + len, bufferSize - len,
"confidence=%lf", (
double) self->confidence);
162#pragma clang diagnostic pop
170#pragma clang diagnostic push
171#pragma clang diagnostic ignored "-Wunused-variable"
173 if (len >= bufferSize) {
176 len = gu_strlcat(toString,
"{", bufferSize);
177 if (len >= bufferSize) {
181 char* position_p = position_buffer;
183 len = gu_strlcat(toString, position_p, bufferSize);
184 if (len >= bufferSize) {
187 len = gu_strlcat(toString,
"}", bufferSize);
188 if (len >= bufferSize) {
191 len = gu_strlcat(toString,
", ", bufferSize);
192 if (len >= bufferSize) {
195 len += snprintf(toString + len, bufferSize - len,
"%d", self->headingInDegrees);
196 if (len >= bufferSize) {
199 len = gu_strlcat(toString,
", ", bufferSize);
200 if (len >= bufferSize) {
203 len += snprintf(toString + len, bufferSize - len,
"%lf", (
double) self->confidence);
205#pragma clang diagnostic pop
213 size_t temp_length = strlen(str);
214 int length = (temp_length <= INT_MAX) ? ((
int)((ssize_t)temp_length)) : -1;
219 char* var_str = &var_str_buffer[0];
221 char* key = &key_buffer[0];
228 if (index == 0 && str[0] ==
'{') {
234 for (
int i = index; i < length; i++) {
236 if (bracecount == 0 && str[i] ==
'=') {
241 if (bracecount == 0 && isspace(str[i])) {
248 if (bracecount == 0 && str[i] ==
',') {
258 if (bracecount < 0) {
263 if (i == length - 1) {
267 if (endKey >= startKey && endKey - startKey < length) {
268 strncpy(key, str + startKey, ((
size_t)(endKey - startKey) + 1));
269 key[(endKey - startKey) + 1] = 0;
273 strncpy(var_str, str + startVar, ((
size_t)(index - startVar) + 1));
274 var_str[(index - startVar) + 1] = 0;
280 if (strlen(key) > 0) {
281 if (0 == strcmp(
"position", key)) {
283 }
else if (0 == strcmp(
"headingInDegrees", key)) {
285 }
else if (0 == strcmp(
"confidence", key)) {
300 self->headingInDegrees = ((int16_t)atoi(var_str));
305 self->confidence = ((float)atof(var_str));
312 }
while(index < length);
323 uint16_t bit_offset = 0;
324 int16_t headingInDegrees_nbo =
htons(self->headingInDegrees);
327 for (b = (16 - 1); b >= 0; b--) {
329 uint16_t
byte = bit_offset / 8;
330 uint16_t bit = 7 - (bit_offset % 8);
331 unsigned long newbit = !!((headingInDegrees_nbo >> b) & 1U);
332 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
333 bit_offset = bit_offset + 1;
350 uint16_t bit_offset = 0;
353 for (b = (16 - 1); b >= 0; b--) {
355 uint16_t
byte = bit_offset / 8;
356 uint16_t bit = 7 - (bit_offset % 8);
357 char dataByte = src[byte];
358 unsigned char bitValue = (dataByte >> bit) & 1U;
360 bit_offset = bit_offset + 1;
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t headingInDegrees
90 degrees is looking ahead into the oponetns goal.
const char * wb_particle_position_description(const struct wb_particle_position *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_particle_position_from_network_serialised(const char *src, struct wb_particle_position *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_particle_position_to_string(const struct wb_particle_position *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_particle_position_to_network_serialised(const struct wb_particle_position *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
struct wb_particle_position * wb_particle_position_from_string(struct wb_particle_position *self, const char *str)
Convert from a string.
#define PARTICLE_POSITION_DESC_BUFFER_SIZE
struct wb_point2d * wb_point2d_from_string(struct wb_point2d *self, const char *str)
Convert from a string.
const char * wb_point2d_description(const struct wb_point2d *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_point2d_to_string(const struct wb_point2d *self, char *toString, size_t bufferSize)
Convert to a string.
#define POINT2D_DESC_BUFFER_SIZE
#define POINT2D_TO_STRING_BUFFER_SIZE