gusimplewhiteboard
wb_sensors_torsojointtemps.c
Go to the documentation of this file.
1/*
2 * file wb_sensors_torsojointtemps.c
3 *
4 * This file was generated by classgenerator from SENSORS_TorsoJointTemps.txt.
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
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_torsojointtemps_description(const struct wb_sensors_torsojointtemps* 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, "LHipYawPitch=%lf", (double) self->LHipYawPitch);
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, "LHipRoll=%lf", (double) self->LHipRoll);
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, "LHipPitch=%lf", (double) self->LHipPitch);
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, "RHipRoll=%lf", (double) self->RHipRoll);
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, "RHipPitch=%lf", (double) self->RHipPitch);
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, "RShoulderPitch=%lf", (double) self->RShoulderPitch);
222 if (len >= bufferSize) {
223 return descString;
224 }
225 len = gu_strlcat(descString, ", ", bufferSize);
226 if (len >= bufferSize) {
227 return descString;
228 }
229 len += snprintf(descString + len, bufferSize - len, "RShoulderRoll=%lf", (double) self->RShoulderRoll);
230 if (len >= bufferSize) {
231 return descString;
232 }
233 len = gu_strlcat(descString, ", ", bufferSize);
234 if (len >= bufferSize) {
235 return descString;
236 }
237 len += snprintf(descString + len, bufferSize - len, "RElbowYaw=%lf", (double) self->RElbowYaw);
238 if (len >= bufferSize) {
239 return descString;
240 }
241 len = gu_strlcat(descString, ", ", bufferSize);
242 if (len >= bufferSize) {
243 return descString;
244 }
245 len += snprintf(descString + len, bufferSize - len, "RElbowRoll=%lf", (double) self->RElbowRoll);
246 return descString;
247#pragma clang diagnostic pop
248}
249
253const char* wb_sensors_torsojointtemps_to_string(const struct wb_sensors_torsojointtemps* self, char* toString, size_t bufferSize)
254{
255#pragma clang diagnostic push
256#pragma clang diagnostic ignored "-Wunused-variable"
257 size_t len = 0;
258 if (len >= bufferSize) {
259 return toString;
260 }
261 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->HeadYaw);
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->HeadPitch);
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->LShoulderPitch);
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->LShoulderRoll);
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->LElbowYaw);
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->LElbowRoll);
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->LHipYawPitch);
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->LHipRoll);
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->LHipPitch);
326 if (len >= bufferSize) {
327 return toString;
328 }
329 len = gu_strlcat(toString, ", ", bufferSize);
330 if (len >= bufferSize) {
331 return toString;
332 }
333 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RHipRoll);
334 if (len >= bufferSize) {
335 return toString;
336 }
337 len = gu_strlcat(toString, ", ", bufferSize);
338 if (len >= bufferSize) {
339 return toString;
340 }
341 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RHipPitch);
342 if (len >= bufferSize) {
343 return toString;
344 }
345 len = gu_strlcat(toString, ", ", bufferSize);
346 if (len >= bufferSize) {
347 return toString;
348 }
349 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RShoulderPitch);
350 if (len >= bufferSize) {
351 return toString;
352 }
353 len = gu_strlcat(toString, ", ", bufferSize);
354 if (len >= bufferSize) {
355 return toString;
356 }
357 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RShoulderRoll);
358 if (len >= bufferSize) {
359 return toString;
360 }
361 len = gu_strlcat(toString, ", ", bufferSize);
362 if (len >= bufferSize) {
363 return toString;
364 }
365 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RElbowYaw);
366 if (len >= bufferSize) {
367 return toString;
368 }
369 len = gu_strlcat(toString, ", ", bufferSize);
370 if (len >= bufferSize) {
371 return toString;
372 }
373 len += snprintf(toString + len, bufferSize - len, "%lf", (double) self->RElbowRoll);
374 return toString;
375#pragma clang diagnostic pop
376}
377
382{
383 size_t temp_length = strlen(str);
384 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
385 if (length < 1 || length > SENSORS_TORSOJOINTTEMPS_DESC_BUFFER_SIZE) {
386 return self;
387 }
388 char var_str_buffer[SENSORS_TORSOJOINTTEMPS_DESC_BUFFER_SIZE + 1];
389 char* var_str = &var_str_buffer[0];
390 char key_buffer[15];
391 char* key = &key_buffer[0];
392 int bracecount = 0;
393 int startVar = 0;
394 int index = 0;
395 int startKey = 0;
396 int endKey = -1;
397 int varIndex = 0;
398 if (index == 0 && str[0] == '{') {
399 index = 1;
400 }
401 startVar = index;
402 startKey = startVar;
403 do {
404 for (int i = index; i < length; i++) {
405 index = i + 1;
406 if (bracecount == 0 && str[i] == '=') {
407 endKey = i - 1;
408 startVar = index;
409 continue;
410 }
411 if (bracecount == 0 && isspace(str[i])) {
412 startVar = index;
413 if (endKey == -1) {
414 startKey = index;
415 }
416 continue;
417 }
418 if (bracecount == 0 && str[i] == ',') {
419 index = i - 1;
420 break;
421 }
422 if (str[i] == '{') {
423 bracecount++;
424 continue;
425 }
426 if (str[i] == '}') {
427 bracecount--;
428 if (bracecount < 0) {
429 index = i - 1;
430 break;
431 }
432 }
433 if (i == length - 1) {
434 index = i;
435 }
436 }
437 if (endKey >= startKey && endKey - startKey < length) {
438 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
439 key[(endKey - startKey) + 1] = 0;
440 } else {
441 key[0] = 0;
442 }
443 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
444 var_str[(index - startVar) + 1] = 0;
445 bracecount = 0;
446 index += 2;
447 startVar = index;
448 startKey = startVar;
449 endKey = -1;
450 if (strlen(key) > 0) {
451 if (0 == strcmp("HeadYaw", key)) {
452 varIndex = 0;
453 } else if (0 == strcmp("HeadPitch", key)) {
454 varIndex = 1;
455 } else if (0 == strcmp("LShoulderPitch", key)) {
456 varIndex = 2;
457 } else if (0 == strcmp("LShoulderRoll", key)) {
458 varIndex = 3;
459 } else if (0 == strcmp("LElbowYaw", key)) {
460 varIndex = 4;
461 } else if (0 == strcmp("LElbowRoll", key)) {
462 varIndex = 5;
463 } else if (0 == strcmp("LHipYawPitch", key)) {
464 varIndex = 6;
465 } else if (0 == strcmp("LHipRoll", key)) {
466 varIndex = 7;
467 } else if (0 == strcmp("LHipPitch", key)) {
468 varIndex = 8;
469 } else if (0 == strcmp("RHipRoll", key)) {
470 varIndex = 9;
471 } else if (0 == strcmp("RHipPitch", key)) {
472 varIndex = 10;
473 } else if (0 == strcmp("RShoulderPitch", key)) {
474 varIndex = 11;
475 } else if (0 == strcmp("RShoulderRoll", key)) {
476 varIndex = 12;
477 } else if (0 == strcmp("RElbowYaw", key)) {
478 varIndex = 13;
479 } else if (0 == strcmp("RElbowRoll", key)) {
480 varIndex = 14;
481 } else {
482 varIndex = -1;
483 }
484 }
485 switch (varIndex) {
486 case -1: { break; }
487 case 0:
488 {
489 self->HeadYaw = ((float)atof(var_str));
490 break;
491 }
492 case 1:
493 {
494 self->HeadPitch = ((float)atof(var_str));
495 break;
496 }
497 case 2:
498 {
499 self->LShoulderPitch = ((float)atof(var_str));
500 break;
501 }
502 case 3:
503 {
504 self->LShoulderRoll = ((float)atof(var_str));
505 break;
506 }
507 case 4:
508 {
509 self->LElbowYaw = ((float)atof(var_str));
510 break;
511 }
512 case 5:
513 {
514 self->LElbowRoll = ((float)atof(var_str));
515 break;
516 }
517 case 6:
518 {
519 self->LHipYawPitch = ((float)atof(var_str));
520 break;
521 }
522 case 7:
523 {
524 self->LHipRoll = ((float)atof(var_str));
525 break;
526 }
527 case 8:
528 {
529 self->LHipPitch = ((float)atof(var_str));
530 break;
531 }
532 case 9:
533 {
534 self->RHipRoll = ((float)atof(var_str));
535 break;
536 }
537 case 10:
538 {
539 self->RHipPitch = ((float)atof(var_str));
540 break;
541 }
542 case 11:
543 {
544 self->RShoulderPitch = ((float)atof(var_str));
545 break;
546 }
547 case 12:
548 {
549 self->RShoulderRoll = ((float)atof(var_str));
550 break;
551 }
552 case 13:
553 {
554 self->RElbowYaw = ((float)atof(var_str));
555 break;
556 }
557 case 14:
558 {
559 self->RElbowRoll = ((float)atof(var_str));
560 break;
561 }
562 }
563 if (varIndex >= 0) {
564 varIndex++;
565 }
566 } while(index < length);
567 return self;
568}
569
570/*#ifdef WHITEBOARD_SERIALISATION*/
571
576{
577 uint16_t bit_offset = 0;
578 //The class generator does not support float types for network conversion.
579
580 //The class generator does not support float types for network conversion.
581
582 //The class generator does not support float types for network conversion.
583
584 //The class generator does not support float types for network conversion.
585
586 //The class generator does not support float types for network conversion.
587
588 //The class generator does not support float types for network conversion.
589
590 //The class generator does not support float types for network conversion.
591
592 //The class generator does not support float types for network conversion.
593
594 //The class generator does not support float types for network conversion.
595
596 //The class generator does not support float types for network conversion.
597
598 //The class generator does not support float types for network conversion.
599
600 //The class generator does not support float types for network conversion.
601
602 //The class generator does not support float types for network conversion.
603
604 //The class generator does not support float types for network conversion.
605
606 //The class generator does not support float types for network conversion.
607 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
608 (void)self;
609 (void)dst;
610 return bit_offset;
611}
612
617{
618 uint16_t bit_offset = 0;
619 //The class generator does not support float types for network conversion.
620
621 //The class generator does not support float types for network conversion.
622
623 //The class generator does not support float types for network conversion.
624
625 //The class generator does not support float types for network conversion.
626
627 //The class generator does not support float types for network conversion.
628
629 //The class generator does not support float types for network conversion.
630
631 //The class generator does not support float types for network conversion.
632
633 //The class generator does not support float types for network conversion.
634
635 //The class generator does not support float types for network conversion.
636
637 //The class generator does not support float types for network conversion.
638
639 //The class generator does not support float types for network conversion.
640
641 //The class generator does not support float types for network conversion.
642
643 //The class generator does not support float types for network conversion.
644
645 //The class generator does not support float types for network conversion.
646
647 //The class generator does not support float types for network conversion.
648 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
649 (void)src;
650 (void)dst;
651 return bit_offset;
652}
653
654/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
size_t wb_sensors_torsojointtemps_from_network_serialised(const char *src, struct wb_sensors_torsojointtemps *dst)
Convert from a compressed, serialised, network byte order byte stream.
struct wb_sensors_torsojointtemps * wb_sensors_torsojointtemps_from_string(struct wb_sensors_torsojointtemps *self, const char *str)
Convert from a string.
const char * wb_sensors_torsojointtemps_to_string(const struct wb_sensors_torsojointtemps *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_sensors_torsojointtemps_description(const struct wb_sensors_torsojointtemps *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_sensors_torsojointtemps_to_network_serialised(const struct wb_sensors_torsojointtemps *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define SENSORS_TORSOJOINTTEMPS_DESC_BUFFER_SIZE