gusimplewhiteboard
wb_sensors_torsojointsensors.c
Go to the documentation of this file.
1/*
2 * file wb_sensors_torsojointsensors.c
3 *
4 * This file was generated by classgenerator from SENSORS_TorsoJointSensors.txt.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty & Dimitri Joukoff. 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 & Dimitri Joukoff.
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
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_sensors_torsojointsensors_description(const struct wb_sensors_torsojointsensors* 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 len += snprintf(descString + len, bufferSize - len, "HeadYaw=%lf", (double) self->HeadYaw);
134 if (len >= bufferSize) {
135 return descString;
136 }
137 len = gu_strlcat(descString, ", ", bufferSize);
138 if (len >= bufferSize) {
139 return descString;
140 }
141 len += snprintf(descString + len, bufferSize - len, "HeadPitch=%lf", (double) self->HeadPitch);
142 if (len >= bufferSize) {
143 return descString;
144 }
145 len = gu_strlcat(descString, ", ", bufferSize);
146 if (len >= bufferSize) {
147 return descString;
148 }
149 len += snprintf(descString + len, bufferSize - len, "LShoulderPitch=%lf", (double) self->LShoulderPitch);
150 if (len >= bufferSize) {
151 return descString;
152 }
153 len = gu_strlcat(descString, ", ", bufferSize);
154 if (len >= bufferSize) {
155 return descString;
156 }
157 len += snprintf(descString + len, bufferSize - len, "LShoulderRoll=%lf", (double) self->LShoulderRoll);
158 if (len >= bufferSize) {
159 return descString;
160 }
161 len = gu_strlcat(descString, ", ", bufferSize);
162 if (len >= bufferSize) {
163 return descString;
164 }
165 len += snprintf(descString + len, bufferSize - len, "LElbowYaw=%lf", (double) self->LElbowYaw);
166 if (len >= bufferSize) {
167 return descString;
168 }
169 len = gu_strlcat(descString, ", ", bufferSize);
170 if (len >= bufferSize) {
171 return descString;
172 }
173 len += snprintf(descString + len, bufferSize - len, "LElbowRoll=%lf", (double) self->LElbowRoll);
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, "RShoulderPitch=%lf", (double) self->RShoulderPitch);
182 if (len >= bufferSize) {
183 return descString;
184 }
185 len = gu_strlcat(descString, ", ", bufferSize);
186 if (len >= bufferSize) {
187 return descString;
188 }
189 len += snprintf(descString + len, bufferSize - len, "RShoulderRoll=%lf", (double) self->RShoulderRoll);
190 if (len >= bufferSize) {
191 return descString;
192 }
193 len = gu_strlcat(descString, ", ", bufferSize);
194 if (len >= bufferSize) {
195 return descString;
196 }
197 len += snprintf(descString + len, bufferSize - len, "RElbowYaw=%lf", (double) self->RElbowYaw);
198 if (len >= bufferSize) {
199 return descString;
200 }
201 len = gu_strlcat(descString, ", ", bufferSize);
202 if (len >= bufferSize) {
203 return descString;
204 }
205 len += snprintf(descString + len, bufferSize - len, "RElbowRoll=%lf", (double) self->RElbowRoll);
206 if (len >= bufferSize) {
207 return descString;
208 }
209 len = gu_strlcat(descString, ", ", bufferSize);
210 if (len >= bufferSize) {
211 return descString;
212 }
213 len += snprintf(descString + len, bufferSize - len, "LWristYaw=%lf", (double) self->LWristYaw);
214 if (len >= bufferSize) {
215 return descString;
216 }
217 len = gu_strlcat(descString, ", ", bufferSize);
218 if (len >= bufferSize) {
219 return descString;
220 }
221 len += snprintf(descString + len, bufferSize - len, "RWristYaw=%lf", (double) self->RWristYaw);
222 return descString;
223#pragma clang diagnostic pop
224}
225
229const char* wb_sensors_torsojointsensors_to_string(const struct wb_sensors_torsojointsensors* self, char* toString, size_t bufferSize)
230{
231#pragma clang diagnostic push
232#pragma clang diagnostic ignored "-Wunused-variable"
233 size_t len = 0;
234 if (len >= bufferSize) {
235 return toString;
236 }
237 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->HeadYaw);
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, "%lf", (double) self->HeadPitch);
246 if (len >= bufferSize) {
247 return toString;
248 }
249 len = gu_strlcat(toString, ", ", bufferSize);
250 if (len >= bufferSize) {
251 return toString;
252 }
253 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->LShoulderPitch);
254 if (len >= bufferSize) {
255 return toString;
256 }
257 len = gu_strlcat(toString, ", ", bufferSize);
258 if (len >= bufferSize) {
259 return toString;
260 }
261 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->LShoulderRoll);
262 if (len >= bufferSize) {
263 return toString;
264 }
265 len = gu_strlcat(toString, ", ", bufferSize);
266 if (len >= bufferSize) {
267 return toString;
268 }
269 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->LElbowYaw);
270 if (len >= bufferSize) {
271 return toString;
272 }
273 len = gu_strlcat(toString, ", ", bufferSize);
274 if (len >= bufferSize) {
275 return toString;
276 }
277 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->LElbowRoll);
278 if (len >= bufferSize) {
279 return toString;
280 }
281 len = gu_strlcat(toString, ", ", bufferSize);
282 if (len >= bufferSize) {
283 return toString;
284 }
285 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RShoulderPitch);
286 if (len >= bufferSize) {
287 return toString;
288 }
289 len = gu_strlcat(toString, ", ", bufferSize);
290 if (len >= bufferSize) {
291 return toString;
292 }
293 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RShoulderRoll);
294 if (len >= bufferSize) {
295 return toString;
296 }
297 len = gu_strlcat(toString, ", ", bufferSize);
298 if (len >= bufferSize) {
299 return toString;
300 }
301 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RElbowYaw);
302 if (len >= bufferSize) {
303 return toString;
304 }
305 len = gu_strlcat(toString, ", ", bufferSize);
306 if (len >= bufferSize) {
307 return toString;
308 }
309 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RElbowRoll);
310 if (len >= bufferSize) {
311 return toString;
312 }
313 len = gu_strlcat(toString, ", ", bufferSize);
314 if (len >= bufferSize) {
315 return toString;
316 }
317 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->LWristYaw);
318 if (len >= bufferSize) {
319 return toString;
320 }
321 len = gu_strlcat(toString, ", ", bufferSize);
322 if (len >= bufferSize) {
323 return toString;
324 }
325 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RWristYaw);
326 return toString;
327#pragma clang diagnostic pop
328}
329
334{
335 size_t temp_length = strlen(str);
336 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
337 if (length < 1 || length > SENSORS_TORSOJOINTSENSORS_DESC_BUFFER_SIZE) {
338 return self;
339 }
340 char var_str_buffer[SENSORS_TORSOJOINTSENSORS_DESC_BUFFER_SIZE + 1];
341 char* var_str = &var_str_buffer[0];
342 char key_buffer[15];
343 char* key = &key_buffer[0];
344 int bracecount = 0;
345 int startVar = 0;
346 int index = 0;
347 int startKey = 0;
348 int endKey = -1;
349 int varIndex = 0;
350 if (index == 0 && str[0] == '{') {
351 index = 1;
352 }
353 startVar = index;
354 startKey = startVar;
355 do {
356 for (int i = index; i < length; i++) {
357 index = i + 1;
358 if (bracecount == 0 && str[i] == '=') {
359 endKey = i - 1;
360 startVar = index;
361 continue;
362 }
363 if (bracecount == 0 && isspace(str[i])) {
364 startVar = index;
365 if (endKey == -1) {
366 startKey = index;
367 }
368 continue;
369 }
370 if (bracecount == 0 && str[i] == ',') {
371 index = i - 1;
372 break;
373 }
374 if (str[i] == '{') {
375 bracecount++;
376 continue;
377 }
378 if (str[i] == '}') {
379 bracecount--;
380 if (bracecount < 0) {
381 index = i - 1;
382 break;
383 }
384 }
385 if (i == length - 1) {
386 index = i;
387 }
388 }
389 if (endKey >= startKey && endKey - startKey < length) {
390 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
391 key[(endKey - startKey) + 1] = 0;
392 } else {
393 key[0] = 0;
394 }
395 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
396 var_str[(index - startVar) + 1] = 0;
397 bracecount = 0;
398 index += 2;
399 startVar = index;
400 startKey = startVar;
401 endKey = -1;
402 if (strlen(key) > 0) {
403 if (0 == strcmp("HeadYaw", key)) {
404 varIndex = 0;
405 } else if (0 == strcmp("HeadPitch", key)) {
406 varIndex = 1;
407 } else if (0 == strcmp("LShoulderPitch", key)) {
408 varIndex = 2;
409 } else if (0 == strcmp("LShoulderRoll", key)) {
410 varIndex = 3;
411 } else if (0 == strcmp("LElbowYaw", key)) {
412 varIndex = 4;
413 } else if (0 == strcmp("LElbowRoll", key)) {
414 varIndex = 5;
415 } else if (0 == strcmp("RShoulderPitch", key)) {
416 varIndex = 6;
417 } else if (0 == strcmp("RShoulderRoll", key)) {
418 varIndex = 7;
419 } else if (0 == strcmp("RElbowYaw", key)) {
420 varIndex = 8;
421 } else if (0 == strcmp("RElbowRoll", key)) {
422 varIndex = 9;
423 } else if (0 == strcmp("LWristYaw", key)) {
424 varIndex = 10;
425 } else if (0 == strcmp("RWristYaw", key)) {
426 varIndex = 11;
427 } else {
428 varIndex = -1;
429 }
430 }
431 switch (varIndex) {
432 case -1: { break; }
433 case 0:
434 {
435 self->HeadYaw = ((float)atof(var_str));
436 break;
437 }
438 case 1:
439 {
440 self->HeadPitch = ((float)atof(var_str));
441 break;
442 }
443 case 2:
444 {
445 self->LShoulderPitch = ((float)atof(var_str));
446 break;
447 }
448 case 3:
449 {
450 self->LShoulderRoll = ((float)atof(var_str));
451 break;
452 }
453 case 4:
454 {
455 self->LElbowYaw = ((float)atof(var_str));
456 break;
457 }
458 case 5:
459 {
460 self->LElbowRoll = ((float)atof(var_str));
461 break;
462 }
463 case 6:
464 {
465 self->RShoulderPitch = ((float)atof(var_str));
466 break;
467 }
468 case 7:
469 {
470 self->RShoulderRoll = ((float)atof(var_str));
471 break;
472 }
473 case 8:
474 {
475 self->RElbowYaw = ((float)atof(var_str));
476 break;
477 }
478 case 9:
479 {
480 self->RElbowRoll = ((float)atof(var_str));
481 break;
482 }
483 case 10:
484 {
485 self->LWristYaw = ((float)atof(var_str));
486 break;
487 }
488 case 11:
489 {
490 self->RWristYaw = ((float)atof(var_str));
491 break;
492 }
493 }
494 if (varIndex >= 0) {
495 varIndex++;
496 }
497 } while(index < length);
498 return self;
499}
500
501/*#ifdef WHITEBOARD_SERIALISATION*/
502
507{
508 uint16_t bit_offset = 0;
509 //The class generator does not support float types for network conversion.
510
511 //The class generator does not support float types for network conversion.
512
513 //The class generator does not support float types for network conversion.
514
515 //The class generator does not support float types for network conversion.
516
517 //The class generator does not support float types for network conversion.
518
519 //The class generator does not support float types for network conversion.
520
521 //The class generator does not support float types for network conversion.
522
523 //The class generator does not support float types for network conversion.
524
525 //The class generator does not support float types for network conversion.
526
527 //The class generator does not support float types for network conversion.
528
529 //The class generator does not support float types for network conversion.
530
531 //The class generator does not support float types for network conversion.
532 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
533 (void)self;
534 (void)dst;
535 return bit_offset;
536}
537
542{
543 uint16_t bit_offset = 0;
544 //The class generator does not support float types for network conversion.
545
546 //The class generator does not support float types for network conversion.
547
548 //The class generator does not support float types for network conversion.
549
550 //The class generator does not support float types for network conversion.
551
552 //The class generator does not support float types for network conversion.
553
554 //The class generator does not support float types for network conversion.
555
556 //The class generator does not support float types for network conversion.
557
558 //The class generator does not support float types for network conversion.
559
560 //The class generator does not support float types for network conversion.
561
562 //The class generator does not support float types for network conversion.
563
564 //The class generator does not support float types for network conversion.
565
566 //The class generator does not support float types for network conversion.
567 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
568 (void)src;
569 (void)dst;
570 return bit_offset;
571}
572
573/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_sensors_torsojointsensors * wb_sensors_torsojointsensors_from_string(struct wb_sensors_torsojointsensors *self, const char *str)
Convert from a string.
size_t wb_sensors_torsojointsensors_to_network_serialised(const struct wb_sensors_torsojointsensors *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_sensors_torsojointsensors_to_string(const struct wb_sensors_torsojointsensors *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_sensors_torsojointsensors_description(const struct wb_sensors_torsojointsensors *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_sensors_torsojointsensors_from_network_serialised(const char *src, struct wb_sensors_torsojointsensors *dst)
Convert from a compressed, serialised, network byte order byte stream.
#define SENSORS_TORSOJOINTSENSORS_DESC_BUFFER_SIZE