gusimplewhiteboard
wb_nao_walk_status.c
Go to the documentation of this file.
1/*
2 * file wb_nao_walk_status.c
3 *
4 * This file was generated by classgenerator from naoWalkStatus.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Carl Lusty.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
62#endif // WHITEBOARD_POSTER_STRING_CONVERSION
63
64#include "wb_nao_walk_status.h"
65#include <stdio.h>
66#include <string.h>
67#include <stdlib.h>
68#include <ctype.h>
69#include <limits.h>
70
71/* Network byte order functions */
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
74#if defined(__linux)
75# include <endian.h>
76# include <byteswap.h>
77#elif defined(__APPLE__)
78# include <machine/endian.h> //Needed for __BYTE_ORDER
79# include <architecture/byte_order.h> //Needed for byte swap functions
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
83#elif defined(ESP8266)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
87#else
88 //Manually define swap macros?
89#endif
90
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)
95# endif
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
99# endif
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
103# endif
104#else
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
108# endif
109# if !defined(htonl) && !defined(ntohl)
110# define htonl(x) (x)
111# define ntohl(x) (x)
112# endif
113# if !defined(htons) && !defined(ntohs)
114# define htons(x) (x)
115# define ntohs(x) (x)
116# endif
117#endif
118#pragma clang diagnostic pop
119
120
121
125const char* wb_nao_walk_status_description(const struct wb_nao_walk_status* self, char* descString, size_t bufferSize)
126{
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
129 size_t len = 0;
130 if (len >= bufferSize) {
131 return descString;
132 }
133 switch (self->walkEngineState) {
134 case wes_Disconnected:
135 {
136 len += snprintf(descString + len, bufferSize - len, "walkEngineState=wes_Disconnected");
137 break;
138 }
139 case wes_StoppedReady:
140 {
141 len += snprintf(descString + len, bufferSize - len, "walkEngineState=wes_StoppedReady");
142 break;
143 }
145 {
146 len += snprintf(descString + len, bufferSize - len, "walkEngineState=wes_StoppedStanding");
147 break;
148 }
149 case wes_Walking:
150 {
151 len += snprintf(descString + len, bufferSize - len, "walkEngineState=wes_Walking");
152 break;
153 }
154 }
155 if (len >= bufferSize) {
156 return descString;
157 }
158 len = gu_strlcat(descString, ", ", bufferSize);
159 if (len >= bufferSize) {
160 return descString;
161 }
162 len = gu_strlcat(descString, "odometry={", bufferSize);
163 if (len >= bufferSize) {
164 return descString;
165 }
166 char odometry_buffer[ODOMETRY_DESC_BUFFER_SIZE];
167 char* odometry_p = odometry_buffer;
168 const char* odometry_description = wb_odometry_description(&self->odometry, odometry_p, ODOMETRY_DESC_BUFFER_SIZE);
169 len = gu_strlcat(descString, odometry_p, bufferSize);
170 if (len >= bufferSize) {
171 return descString;
172 }
173 len = gu_strlcat(descString, "}", bufferSize);
174 if (len >= bufferSize) {
175 return descString;
176 }
177 len = gu_strlcat(descString, ", ", bufferSize);
178 if (len >= bufferSize) {
179 return descString;
180 }
181 len += snprintf(descString + len, bufferSize - len, "odometryResetCounter=%u", self->odometryResetCounter);
182 return descString;
183#pragma clang diagnostic pop
184}
185
189const char* wb_nao_walk_status_to_string(const struct wb_nao_walk_status* self, char* toString, size_t bufferSize)
190{
191#pragma clang diagnostic push
192#pragma clang diagnostic ignored "-Wunused-variable"
193 size_t len = 0;
194 if (len >= bufferSize) {
195 return toString;
196 }
197 switch (self->walkEngineState) {
198 case wes_Disconnected:
199 {
200 len += snprintf(toString + len, bufferSize - len, "wes_Disconnected");
201 break;
202 }
203 case wes_StoppedReady:
204 {
205 len += snprintf(toString + len, bufferSize - len, "wes_StoppedReady");
206 break;
207 }
209 {
210 len += snprintf(toString + len, bufferSize - len, "wes_StoppedStanding");
211 break;
212 }
213 case wes_Walking:
214 {
215 len += snprintf(toString + len, bufferSize - len, "wes_Walking");
216 break;
217 }
218 }
219 if (len >= bufferSize) {
220 return toString;
221 }
222 len = gu_strlcat(toString, ", ", bufferSize);
223 if (len >= bufferSize) {
224 return toString;
225 }
226 len = gu_strlcat(toString, "{", bufferSize);
227 if (len >= bufferSize) {
228 return toString;
229 }
230 char odometry_buffer[ODOMETRY_TO_STRING_BUFFER_SIZE];
231 char* odometry_p = odometry_buffer;
232 const char* odometry_to_string = wb_odometry_to_string(&self->odometry, odometry_p, ODOMETRY_TO_STRING_BUFFER_SIZE);
233 len = gu_strlcat(toString, odometry_p, bufferSize);
234 if (len >= bufferSize) {
235 return toString;
236 }
237 len = gu_strlcat(toString, "}", bufferSize);
238 if (len >= bufferSize) {
239 return toString;
240 }
241 len = gu_strlcat(toString, ", ", bufferSize);
242 if (len >= bufferSize) {
243 return toString;
244 }
245 len += snprintf(toString + len, bufferSize - len, "%u", self->odometryResetCounter);
246 return toString;
247#pragma clang diagnostic pop
248}
249
254{
255 size_t temp_length = strlen(str);
256 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
257 if (length < 1 || length > NAOWALKSTATUS_DESC_BUFFER_SIZE) {
258 return self;
259 }
260 char var_str_buffer[NAOWALKSTATUS_DESC_BUFFER_SIZE + 1];
261 char* var_str = &var_str_buffer[0];
262 char key_buffer[21];
263 char* key = &key_buffer[0];
264 int bracecount = 0;
265 int startVar = 0;
266 int index = 0;
267 int startKey = 0;
268 int endKey = -1;
269 int varIndex = 0;
270 if (index == 0 && str[0] == '{') {
271 index = 1;
272 }
273 startVar = index;
274 startKey = startVar;
275 do {
276 for (int i = index; i < length; i++) {
277 index = i + 1;
278 if (bracecount == 0 && str[i] == '=') {
279 endKey = i - 1;
280 startVar = index;
281 continue;
282 }
283 if (bracecount == 0 && isspace(str[i])) {
284 startVar = index;
285 if (endKey == -1) {
286 startKey = index;
287 }
288 continue;
289 }
290 if (bracecount == 0 && str[i] == ',') {
291 index = i - 1;
292 break;
293 }
294 if (str[i] == '{') {
295 bracecount++;
296 continue;
297 }
298 if (str[i] == '}') {
299 bracecount--;
300 if (bracecount < 0) {
301 index = i - 1;
302 break;
303 }
304 }
305 if (i == length - 1) {
306 index = i;
307 }
308 }
309 if (endKey >= startKey && endKey - startKey < length) {
310 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
311 key[(endKey - startKey) + 1] = 0;
312 } else {
313 key[0] = 0;
314 }
315 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
316 var_str[(index - startVar) + 1] = 0;
317 bracecount = 0;
318 index += 2;
319 startVar = index;
320 startKey = startVar;
321 endKey = -1;
322 if (strlen(key) > 0) {
323 if (0 == strcmp("walkEngineState", key)) {
324 varIndex = 0;
325 } else if (0 == strcmp("odometry", key)) {
326 varIndex = 1;
327 } else if (0 == strcmp("odometryResetCounter", key)) {
328 varIndex = 2;
329 } else {
330 varIndex = -1;
331 }
332 }
333 switch (varIndex) {
334 case -1: { break; }
335 case 0:
336 {
337 if (strcmp("wes_Disconnected", var_str) == 0) {
338#pragma clang diagnostic push
339#pragma clang diagnostic ignored "-Wbad-function-cast"
340 self->walkEngineState = wes_Disconnected;
341#pragma clang diagnostic pop
342 } else if (strcmp("wes_StoppedReady", var_str) == 0) {
343#pragma clang diagnostic push
344#pragma clang diagnostic ignored "-Wbad-function-cast"
345 self->walkEngineState = wes_StoppedReady;
346#pragma clang diagnostic pop
347 } else if (strcmp("wes_StoppedStanding", var_str) == 0) {
348#pragma clang diagnostic push
349#pragma clang diagnostic ignored "-Wbad-function-cast"
350 self->walkEngineState = wes_StoppedStanding;
351#pragma clang diagnostic pop
352 } else if (strcmp("wes_Walking", var_str) == 0) {
353#pragma clang diagnostic push
354#pragma clang diagnostic ignored "-Wbad-function-cast"
355 self->walkEngineState = wes_Walking;
356#pragma clang diagnostic pop
357 } else {
358#pragma clang diagnostic push
359#pragma clang diagnostic ignored "-Wbad-function-cast"
360 self->walkEngineState = ((enum WalkEngineState)atoi(var_str));
361#pragma clang diagnostic pop
362 }
363 break;
364 }
365 case 1:
366 {
367 wb_odometry_from_string(&self->odometry, var_str);
368 break;
369 }
370 case 2:
371 {
372 self->odometryResetCounter = ((uint8_t)atoi(var_str));
373 break;
374 }
375 }
376 if (varIndex >= 0) {
377 varIndex++;
378 }
379 } while(index < length);
380 return self;
381}
382
383/*#ifdef WHITEBOARD_SERIALISATION*/
384
389{
390 uint16_t bit_offset = 0;
391 enum WalkEngineState walkEngineState_nbo = htonl(self->walkEngineState);
392 do {
393 int8_t b;
394 for (b = (32 - 1); b >= 0; b--) {
395 do {
396 uint16_t byte = bit_offset / 8;
397 uint16_t bit = 7 - (bit_offset % 8);
398 unsigned long newbit = !!((walkEngineState_nbo >> b) & 1U);
399 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
400 bit_offset = bit_offset + 1;
401 } while(false);
402 }
403 } while(false);
404
405 uint8_t odometryResetCounter_nbo = (self->odometryResetCounter);
406 do {
407 int8_t b;
408 for (b = (8 - 1); b >= 0; b--) {
409 do {
410 uint16_t byte = bit_offset / 8;
411 uint16_t bit = 7 - (bit_offset % 8);
412 unsigned long newbit = !!((odometryResetCounter_nbo >> b) & 1U);
413 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
414 bit_offset = bit_offset + 1;
415 } while(false);
416 }
417 } while(false);
418 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
419 (void)self;
420 (void)dst;
421 return bit_offset;
422}
423
428{
429 uint16_t bit_offset = 0;
430 do {
431 int8_t b;
432 for (b = (32 - 1); b >= 0; b--) {
433 do {
434 uint16_t byte = bit_offset / 8;
435 uint16_t bit = 7 - (bit_offset % 8);
436 char dataByte = src[byte];
437 unsigned char bitValue = (dataByte >> bit) & 1U;
438 dst->walkEngineState ^= (-bitValue ^ dst->walkEngineState) & (1UL << b);
439 bit_offset = bit_offset + 1;
440 } while(false);
441 }
442 } while(false);
444
445 do {
446 int8_t b;
447 for (b = (8 - 1); b >= 0; b--) {
448 do {
449 uint16_t byte = bit_offset / 8;
450 uint16_t bit = 7 - (bit_offset % 8);
451 char dataByte = src[byte];
452 unsigned char bitValue = (dataByte >> bit) & 1U;
453 dst->odometryResetCounter ^= (-bitValue ^ dst->odometryResetCounter) & (1UL << b);
454 bit_offset = bit_offset + 1;
455 } while(false);
456 }
457 } while(false);
459 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
460 (void)src;
461 (void)dst;
462 return bit_offset;
463}
464
465/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
enum WalkEngineState walkEngineState
The current state of the walk engine, see enum documentation.
uint8_t odometryResetCounter
A counter used to reset the odometry object, change this value and send it via NaoWalkCommand to trig...
const char * wb_nao_walk_status_description(const struct wb_nao_walk_status *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_nao_walk_status_from_network_serialised(const char *src, struct wb_nao_walk_status *dst)
Convert from a compressed, serialised, network byte order byte stream.
size_t wb_nao_walk_status_to_network_serialised(const struct wb_nao_walk_status *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_nao_walk_status_to_string(const struct wb_nao_walk_status *self, char *toString, size_t bufferSize)
Convert to a string.
#define ntohl(x)
struct wb_nao_walk_status * wb_nao_walk_status_from_string(struct wb_nao_walk_status *self, const char *str)
Convert from a string.
#define htonl(x)
#define NAOWALKSTATUS_DESC_BUFFER_SIZE
WalkEngineState
@ wes_StoppedReady
In the Crouched stance, ready to walk again straight away but not currently moving anywhere.
@ wes_StoppedStanding
In the Standing position, this position uses less power than Stopped / Crouched, it is a minimal stif...
@ wes_Walking
Walking around, includes stopping, kicking, transition from Standing etc... basically the walk engine...
@ wes_Disconnected
Not connected to the DCM, does not control any joints in this state.
const char * wb_odometry_to_string(const struct wb_odometry *self, char *toString, size_t bufferSize)
Convert to a string.
Definition: wb_odometry.c:157
const char * wb_odometry_description(const struct wb_odometry *self, char *descString, size_t bufferSize)
Convert to a description string.
Definition: wb_odometry.c:125
struct wb_odometry * wb_odometry_from_string(struct wb_odometry *self, const char *str)
Convert from a string.
Definition: wb_odometry.c:189
#define ODOMETRY_DESC_BUFFER_SIZE
Definition: wb_odometry.h:97
#define ODOMETRY_TO_STRING_BUFFER_SIZE
Definition: wb_odometry.h:98