gusimplewhiteboard
wb_teleoperation_control.c
Go to the documentation of this file.
1/*
2 * file wb_teleoperation_control.c
3 *
4 * This file was generated by classgenerator from teleoperationControl.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
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_teleoperation_control_description(const struct wb_teleoperation_control* 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, "ip=%u", self->ip);
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, "action=%d", self->action);
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, "stance=%d", self->stance);
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, "streamType=%d", self->streamType);
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, "selectedCamera=%d", self->selectedCamera);
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, "sayString=%s", self->sayString);
174 return descString;
175#pragma clang diagnostic pop
176}
177
181const char* wb_teleoperation_control_to_string(const struct wb_teleoperation_control* self, char* toString, size_t bufferSize)
182{
183#pragma clang diagnostic push
184#pragma clang diagnostic ignored "-Wunused-variable"
185 size_t len = 0;
186 if (len >= bufferSize) {
187 return toString;
188 }
189 len += snprintf(toString + len, bufferSize - len, "%u", self->ip);
190 if (len >= bufferSize) {
191 return toString;
192 }
193 len = gu_strlcat(toString, ", ", bufferSize);
194 if (len >= bufferSize) {
195 return toString;
196 }
197 len += snprintf(toString + len, bufferSize - len, "%d", self->action);
198 if (len >= bufferSize) {
199 return toString;
200 }
201 len = gu_strlcat(toString, ", ", bufferSize);
202 if (len >= bufferSize) {
203 return toString;
204 }
205 len += snprintf(toString + len, bufferSize - len, "%d", self->stance);
206 if (len >= bufferSize) {
207 return toString;
208 }
209 len = gu_strlcat(toString, ", ", bufferSize);
210 if (len >= bufferSize) {
211 return toString;
212 }
213 len += snprintf(toString + len, bufferSize - len, "%d", self->streamType);
214 if (len >= bufferSize) {
215 return toString;
216 }
217 len = gu_strlcat(toString, ", ", bufferSize);
218 if (len >= bufferSize) {
219 return toString;
220 }
221 len += snprintf(toString + len, bufferSize - len, "%d", self->selectedCamera);
222 if (len >= bufferSize) {
223 return toString;
224 }
225 len = gu_strlcat(toString, ", ", bufferSize);
226 if (len >= bufferSize) {
227 return toString;
228 }
229 len += snprintf(toString + len, bufferSize - len, "%s", self->sayString);
230 return toString;
231#pragma clang diagnostic pop
232}
233
238{
239 size_t temp_length = strlen(str);
240 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
241 if (length < 1 || length > TELEOPERATIONCONTROL_DESC_BUFFER_SIZE) {
242 return self;
243 }
244 char var_str_buffer[TELEOPERATIONCONTROL_DESC_BUFFER_SIZE + 1];
245 char* var_str = &var_str_buffer[0];
246 char key_buffer[15];
247 char* key = &key_buffer[0];
248 int bracecount = 0;
249 int startVar = 0;
250 int index = 0;
251 int startKey = 0;
252 int endKey = -1;
253 int varIndex = 0;
254 if (index == 0 && str[0] == '{') {
255 index = 1;
256 }
257 startVar = index;
258 startKey = startVar;
259 do {
260 for (int i = index; i < length; i++) {
261 index = i + 1;
262 if (bracecount == 0 && str[i] == '=') {
263 endKey = i - 1;
264 startVar = index;
265 continue;
266 }
267 if (bracecount == 0 && isspace(str[i])) {
268 startVar = index;
269 if (endKey == -1) {
270 startKey = index;
271 }
272 continue;
273 }
274 if (bracecount == 0 && str[i] == ',') {
275 index = i - 1;
276 break;
277 }
278 if (str[i] == '{') {
279 bracecount++;
280 continue;
281 }
282 if (str[i] == '}') {
283 bracecount--;
284 if (bracecount < 0) {
285 index = i - 1;
286 break;
287 }
288 }
289 if (i == length - 1) {
290 index = i;
291 }
292 }
293 if (endKey >= startKey && endKey - startKey < length) {
294 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
295 key[(endKey - startKey) + 1] = 0;
296 } else {
297 key[0] = 0;
298 }
299 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
300 var_str[(index - startVar) + 1] = 0;
301 bracecount = 0;
302 index += 2;
303 startVar = index;
304 startKey = startVar;
305 endKey = -1;
306 if (strlen(key) > 0) {
307 if (0 == strcmp("ip", key)) {
308 varIndex = 0;
309 } else if (0 == strcmp("action", key)) {
310 varIndex = 1;
311 } else if (0 == strcmp("stance", key)) {
312 varIndex = 2;
313 } else if (0 == strcmp("streamType", key)) {
314 varIndex = 3;
315 } else if (0 == strcmp("selectedCamera", key)) {
316 varIndex = 4;
317 } else if (0 == strcmp("sayString", key)) {
318 varIndex = 5;
319 } else {
320 varIndex = -1;
321 }
322 }
323 switch (varIndex) {
324 case -1: { break; }
325 case 0:
326 {
327 self->ip = ((uint8_t)atoi(var_str));
328 break;
329 }
330 case 1:
331 {
332 self->action = ((int32_t)atoi(var_str));
333 break;
334 }
335 case 2:
336 {
337 self->stance = ((int32_t)atoi(var_str));
338 break;
339 }
340 case 3:
341 {
342 self->streamType = ((int32_t)atoi(var_str));
343 break;
344 }
345 case 4:
346 {
347 self->selectedCamera = ((int32_t)atoi(var_str));
348 break;
349 }
350 case 5:
351 {
352 strncpy(self->sayString, var_str, 30);
353 break;
354 }
355 }
356 if (varIndex >= 0) {
357 varIndex++;
358 }
359 } while(index < length);
360 return self;
361}
362
363/*#ifdef WHITEBOARD_SERIALISATION*/
364
369{
370 uint16_t bit_offset = 0;
371 uint8_t ip_nbo = (self->ip);
372 do {
373 int8_t b;
374 for (b = (8 - 1); b >= 0; b--) {
375 do {
376 uint16_t byte = bit_offset / 8;
377 uint16_t bit = 7 - (bit_offset % 8);
378 unsigned long newbit = !!((ip_nbo >> b) & 1U);
379 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
380 bit_offset = bit_offset + 1;
381 } while(false);
382 }
383 } while(false);
384
385 int32_t action_nbo = htonl(self->action);
386 do {
387 int8_t b;
388 for (b = (32 - 1); b >= 0; b--) {
389 do {
390 uint16_t byte = bit_offset / 8;
391 uint16_t bit = 7 - (bit_offset % 8);
392 unsigned long newbit = !!((action_nbo >> b) & 1U);
393 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
394 bit_offset = bit_offset + 1;
395 } while(false);
396 }
397 } while(false);
398
399 int32_t stance_nbo = htonl(self->stance);
400 do {
401 int8_t b;
402 for (b = (32 - 1); b >= 0; b--) {
403 do {
404 uint16_t byte = bit_offset / 8;
405 uint16_t bit = 7 - (bit_offset % 8);
406 unsigned long newbit = !!((stance_nbo >> b) & 1U);
407 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
408 bit_offset = bit_offset + 1;
409 } while(false);
410 }
411 } while(false);
412
413 int32_t streamType_nbo = htonl(self->streamType);
414 do {
415 int8_t b;
416 for (b = (32 - 1); b >= 0; b--) {
417 do {
418 uint16_t byte = bit_offset / 8;
419 uint16_t bit = 7 - (bit_offset % 8);
420 unsigned long newbit = !!((streamType_nbo >> b) & 1U);
421 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
422 bit_offset = bit_offset + 1;
423 } while(false);
424 }
425 } while(false);
426
427 int32_t selectedCamera_nbo = htonl(self->selectedCamera);
428 do {
429 int8_t b;
430 for (b = (32 - 1); b >= 0; b--) {
431 do {
432 uint16_t byte = bit_offset / 8;
433 uint16_t bit = 7 - (bit_offset % 8);
434 unsigned long newbit = !!((selectedCamera_nbo >> b) & 1U);
435 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
436 bit_offset = bit_offset + 1;
437 } while(false);
438 }
439 } while(false);
440
441 do { //limit declaration scope
442 uint8_t len = (uint8_t) strlen(self->sayString);
443 int8_t b;
444 for (b = 7; b >= 0; b--) {
445 do {
446 uint16_t byte = bit_offset / 8;
447 uint16_t bit = 7 - (bit_offset % 8);
448 unsigned long newbit = !!((len >> b) & 1U);
449 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
450 bit_offset = bit_offset + 1;
451 } while(false);
452 }
453 uint8_t c;
454 for (c = 0; c < len; c++) {
455 for (b = 7; b >= 0; b--) {
456 do {
457 uint16_t byte = bit_offset / 8;
458 uint16_t bit = 7 - (bit_offset % 8);
459 unsigned long newbit = !!((self->sayString[c] >> b) & 1U);
460 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
461 bit_offset = bit_offset + 1;
462 } while(false);
463 }
464 }
465 } while(false);
466 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
467 (void)self;
468 (void)dst;
469 return bit_offset;
470}
471
476{
477 uint16_t bit_offset = 0;
478 do {
479 int8_t b;
480 for (b = (8 - 1); b >= 0; b--) {
481 do {
482 uint16_t byte = bit_offset / 8;
483 uint16_t bit = 7 - (bit_offset % 8);
484 char dataByte = src[byte];
485 unsigned char bitValue = (dataByte >> bit) & 1U;
486 dst->ip ^= (-bitValue ^ dst->ip) & (1UL << b);
487 bit_offset = bit_offset + 1;
488 } while(false);
489 }
490 } while(false);
491 dst->ip = (dst->ip);
492
493 do {
494 int8_t b;
495 for (b = (32 - 1); b >= 0; b--) {
496 do {
497 uint16_t byte = bit_offset / 8;
498 uint16_t bit = 7 - (bit_offset % 8);
499 char dataByte = src[byte];
500 unsigned char bitValue = (dataByte >> bit) & 1U;
501 dst->action ^= (-bitValue ^ dst->action) & (1UL << b);
502 bit_offset = bit_offset + 1;
503 } while(false);
504 }
505 } while(false);
506 dst->action = ntohl(dst->action);
507
508 do {
509 int8_t b;
510 for (b = (32 - 1); b >= 0; b--) {
511 do {
512 uint16_t byte = bit_offset / 8;
513 uint16_t bit = 7 - (bit_offset % 8);
514 char dataByte = src[byte];
515 unsigned char bitValue = (dataByte >> bit) & 1U;
516 dst->stance ^= (-bitValue ^ dst->stance) & (1UL << b);
517 bit_offset = bit_offset + 1;
518 } while(false);
519 }
520 } while(false);
521 dst->stance = ntohl(dst->stance);
522
523 do {
524 int8_t b;
525 for (b = (32 - 1); b >= 0; b--) {
526 do {
527 uint16_t byte = bit_offset / 8;
528 uint16_t bit = 7 - (bit_offset % 8);
529 char dataByte = src[byte];
530 unsigned char bitValue = (dataByte >> bit) & 1U;
531 dst->streamType ^= (-bitValue ^ dst->streamType) & (1UL << b);
532 bit_offset = bit_offset + 1;
533 } while(false);
534 }
535 } while(false);
536 dst->streamType = ntohl(dst->streamType);
537
538 do {
539 int8_t b;
540 for (b = (32 - 1); b >= 0; b--) {
541 do {
542 uint16_t byte = bit_offset / 8;
543 uint16_t bit = 7 - (bit_offset % 8);
544 char dataByte = src[byte];
545 unsigned char bitValue = (dataByte >> bit) & 1U;
546 dst->selectedCamera ^= (-bitValue ^ dst->selectedCamera) & (1UL << b);
547 bit_offset = bit_offset + 1;
548 } while(false);
549 }
550 } while(false);
552
553 do {
554 uint8_t len = 0;
555 int8_t b;
556 for (b = 7; b >= 0; b--) {
557 do {
558 uint16_t byte = bit_offset / 8;
559 uint16_t bit = 7 - (bit_offset % 8);
560 char dataByte = src[byte];
561 unsigned char bitValue = (dataByte >> bit) & 1U;
562 len ^= (-bitValue ^ len) & (1UL << b);
563 bit_offset = bit_offset + 1;
564 } while(false);
565 }
566 uint8_t c;
567 for (c = 0; c < len; c++) {
568 for (b = 7; b >= 0; b--) {
569 do {
570 uint16_t byte = bit_offset / 8;
571 uint16_t bit = 7 - (bit_offset % 8);
572 char dataByte = src[byte];
573 unsigned char bitValue = (dataByte >> bit) & 1U;
574 dst->sayString[c] ^= (-bitValue ^ dst->sayString[c]) & (1UL << b);
575 bit_offset = bit_offset + 1;
576 } while(false);
577 }
578 }
579 } while (false);
580 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
581 (void)src;
582 (void)dst;
583 return bit_offset;
584}
585
586/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
char sayString[30]
String passed to Say_t.
int32_t streamType
Use enum StreamingType (Vision_Control.h)
int32_t selectedCamera
VisionCamera.
int32_t action
Use guWhiteboard::Motions::action enum values!
uint8_t ip
Last octet of IP address.
int32_t stance
guWhiteboard::Motions::stance
size_t wb_teleoperation_control_from_network_serialised(const char *src, struct wb_teleoperation_control *dst)
Convert from a compressed, serialised, network byte order byte stream.
struct wb_teleoperation_control * wb_teleoperation_control_from_string(struct wb_teleoperation_control *self, const char *str)
Convert from a string.
#define ntohl(x)
const char * wb_teleoperation_control_description(const struct wb_teleoperation_control *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_teleoperation_control_to_string(const struct wb_teleoperation_control *self, char *toString, size_t bufferSize)
Convert to a string.
#define htonl(x)
size_t wb_teleoperation_control_to_network_serialised(const struct wb_teleoperation_control *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define TELEOPERATIONCONTROL_DESC_BUFFER_SIZE