gusimplewhiteboard
wb_gu_vr_teleop_vulkan_control.c
Go to the documentation of this file.
1/*
2 * file wb_gu_vr_teleop_vulkan_control.c
3 *
4 * This file was generated by classgenerator from gu_vr_teleop_vulkan_control.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_gu_vr_teleop_vulkan_control_description(const struct wb_gu_vr_teleop_vulkan_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 switch (self->movementOptions) {
134 case VRResting:
135 {
136 len += snprintf(descString + len, bufferSize - len, "movementOptions=VRResting");
137 break;
138 }
139 case VRStanding:
140 {
141 len += snprintf(descString + len, bufferSize - len, "movementOptions=VRStanding");
142 break;
143 }
144 case VRWalking:
145 {
146 len += snprintf(descString + len, bufferSize - len, "movementOptions=VRWalking");
147 break;
148 }
149 }
150 if (len >= bufferSize) {
151 return descString;
152 }
153 len = gu_strlcat(descString, ", ", bufferSize);
154 if (len >= bufferSize) {
155 return descString;
156 }
157 switch (self->walkingOptions) {
159 {
160 len += snprintf(descString + len, bufferSize - len, "walkingOptions=NUM_VR_CONTROL_WALKING_OPTIONS");
161 break;
162 }
163 case VRMovementBack:
164 {
165 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementBack");
166 break;
167 }
169 {
170 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementForward");
171 break;
172 }
173 case VRMovementLeft:
174 {
175 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementLeft");
176 break;
177 }
178 case VRMovementRight:
179 {
180 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementRight");
181 break;
182 }
184 {
185 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementRotateLeft");
186 break;
187 }
189 {
190 len += snprintf(descString + len, bufferSize - len, "walkingOptions=VRMovementRotateRight");
191 break;
192 }
193 }
194 return descString;
195#pragma clang diagnostic pop
196}
197
201const char* wb_gu_vr_teleop_vulkan_control_to_string(const struct wb_gu_vr_teleop_vulkan_control* self, char* toString, size_t bufferSize)
202{
203#pragma clang diagnostic push
204#pragma clang diagnostic ignored "-Wunused-variable"
205 size_t len = 0;
206 if (len >= bufferSize) {
207 return toString;
208 }
209 switch (self->movementOptions) {
210 case VRResting:
211 {
212 len += snprintf(toString + len, bufferSize - len, "VRResting");
213 break;
214 }
215 case VRStanding:
216 {
217 len += snprintf(toString + len, bufferSize - len, "VRStanding");
218 break;
219 }
220 case VRWalking:
221 {
222 len += snprintf(toString + len, bufferSize - len, "VRWalking");
223 break;
224 }
225 }
226 if (len >= bufferSize) {
227 return toString;
228 }
229 len = gu_strlcat(toString, ", ", bufferSize);
230 if (len >= bufferSize) {
231 return toString;
232 }
233 switch (self->walkingOptions) {
235 {
236 len += snprintf(toString + len, bufferSize - len, "NUM_VR_CONTROL_WALKING_OPTIONS");
237 break;
238 }
239 case VRMovementBack:
240 {
241 len += snprintf(toString + len, bufferSize - len, "VRMovementBack");
242 break;
243 }
245 {
246 len += snprintf(toString + len, bufferSize - len, "VRMovementForward");
247 break;
248 }
249 case VRMovementLeft:
250 {
251 len += snprintf(toString + len, bufferSize - len, "VRMovementLeft");
252 break;
253 }
254 case VRMovementRight:
255 {
256 len += snprintf(toString + len, bufferSize - len, "VRMovementRight");
257 break;
258 }
260 {
261 len += snprintf(toString + len, bufferSize - len, "VRMovementRotateLeft");
262 break;
263 }
265 {
266 len += snprintf(toString + len, bufferSize - len, "VRMovementRotateRight");
267 break;
268 }
269 }
270 return toString;
271#pragma clang diagnostic pop
272}
273
278{
279 size_t temp_length = strlen(str);
280 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
281 if (length < 1 || length > GU_VR_TELEOP_VULKAN_CONTROL_DESC_BUFFER_SIZE) {
282 return self;
283 }
284 char var_str_buffer[GU_VR_TELEOP_VULKAN_CONTROL_DESC_BUFFER_SIZE + 1];
285 char* var_str = &var_str_buffer[0];
286 char key_buffer[16];
287 char* key = &key_buffer[0];
288 int bracecount = 0;
289 int startVar = 0;
290 int index = 0;
291 int startKey = 0;
292 int endKey = -1;
293 int varIndex = 0;
294 if (index == 0 && str[0] == '{') {
295 index = 1;
296 }
297 startVar = index;
298 startKey = startVar;
299 do {
300 for (int i = index; i < length; i++) {
301 index = i + 1;
302 if (bracecount == 0 && str[i] == '=') {
303 endKey = i - 1;
304 startVar = index;
305 continue;
306 }
307 if (bracecount == 0 && isspace(str[i])) {
308 startVar = index;
309 if (endKey == -1) {
310 startKey = index;
311 }
312 continue;
313 }
314 if (bracecount == 0 && str[i] == ',') {
315 index = i - 1;
316 break;
317 }
318 if (str[i] == '{') {
319 bracecount++;
320 continue;
321 }
322 if (str[i] == '}') {
323 bracecount--;
324 if (bracecount < 0) {
325 index = i - 1;
326 break;
327 }
328 }
329 if (i == length - 1) {
330 index = i;
331 }
332 }
333 if (endKey >= startKey && endKey - startKey < length) {
334 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
335 key[(endKey - startKey) + 1] = 0;
336 } else {
337 key[0] = 0;
338 }
339 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
340 var_str[(index - startVar) + 1] = 0;
341 bracecount = 0;
342 index += 2;
343 startVar = index;
344 startKey = startVar;
345 endKey = -1;
346 if (strlen(key) > 0) {
347 if (0 == strcmp("movementOptions", key)) {
348 varIndex = 0;
349 } else if (0 == strcmp("walkingOptions", key)) {
350 varIndex = 1;
351 } else {
352 varIndex = -1;
353 }
354 }
355 switch (varIndex) {
356 case -1: { break; }
357 case 0:
358 {
359 if (strcmp("VRResting", var_str) == 0) {
360#pragma clang diagnostic push
361#pragma clang diagnostic ignored "-Wbad-function-cast"
362 self->movementOptions = VRResting;
363#pragma clang diagnostic pop
364 } else if (strcmp("VRStanding", var_str) == 0) {
365#pragma clang diagnostic push
366#pragma clang diagnostic ignored "-Wbad-function-cast"
367 self->movementOptions = VRStanding;
368#pragma clang diagnostic pop
369 } else if (strcmp("VRWalking", var_str) == 0) {
370#pragma clang diagnostic push
371#pragma clang diagnostic ignored "-Wbad-function-cast"
372 self->movementOptions = VRWalking;
373#pragma clang diagnostic pop
374 } else {
375#pragma clang diagnostic push
376#pragma clang diagnostic ignored "-Wbad-function-cast"
377 self->movementOptions = ((enum VRControlMovementOptions)atoi(var_str));
378#pragma clang diagnostic pop
379 }
380 break;
381 }
382 case 1:
383 {
384 if (strcmp("NUM_VR_CONTROL_WALKING_OPTIONS", var_str) == 0) {
385#pragma clang diagnostic push
386#pragma clang diagnostic ignored "-Wbad-function-cast"
387 self->walkingOptions = NUM_VR_CONTROL_WALKING_OPTIONS;
388#pragma clang diagnostic pop
389 } else if (strcmp("VRMovementBack", var_str) == 0) {
390#pragma clang diagnostic push
391#pragma clang diagnostic ignored "-Wbad-function-cast"
392 self->walkingOptions = VRMovementBack;
393#pragma clang diagnostic pop
394 } else if (strcmp("VRMovementForward", var_str) == 0) {
395#pragma clang diagnostic push
396#pragma clang diagnostic ignored "-Wbad-function-cast"
397 self->walkingOptions = VRMovementForward;
398#pragma clang diagnostic pop
399 } else if (strcmp("VRMovementLeft", var_str) == 0) {
400#pragma clang diagnostic push
401#pragma clang diagnostic ignored "-Wbad-function-cast"
402 self->walkingOptions = VRMovementLeft;
403#pragma clang diagnostic pop
404 } else if (strcmp("VRMovementRight", var_str) == 0) {
405#pragma clang diagnostic push
406#pragma clang diagnostic ignored "-Wbad-function-cast"
407 self->walkingOptions = VRMovementRight;
408#pragma clang diagnostic pop
409 } else if (strcmp("VRMovementRotateLeft", var_str) == 0) {
410#pragma clang diagnostic push
411#pragma clang diagnostic ignored "-Wbad-function-cast"
412 self->walkingOptions = VRMovementRotateLeft;
413#pragma clang diagnostic pop
414 } else if (strcmp("VRMovementRotateRight", var_str) == 0) {
415#pragma clang diagnostic push
416#pragma clang diagnostic ignored "-Wbad-function-cast"
417 self->walkingOptions = VRMovementRotateRight;
418#pragma clang diagnostic pop
419 } else {
420#pragma clang diagnostic push
421#pragma clang diagnostic ignored "-Wbad-function-cast"
422 self->walkingOptions = ((enum VRControlWalkingOptions)atoi(var_str));
423#pragma clang diagnostic pop
424 }
425 break;
426 }
427 }
428 if (varIndex >= 0) {
429 varIndex++;
430 }
431 } while(index < length);
432 return self;
433}
434
435/*#ifdef WHITEBOARD_SERIALISATION*/
436
441{
442 uint16_t bit_offset = 0;
443 enum VRControlMovementOptions movementOptions_nbo = htonl(self->movementOptions);
444 do {
445 int8_t b;
446 for (b = (32 - 1); b >= 0; b--) {
447 do {
448 uint16_t byte = bit_offset / 8;
449 uint16_t bit = 7 - (bit_offset % 8);
450 unsigned long newbit = !!((movementOptions_nbo >> b) & 1U);
451 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
452 bit_offset = bit_offset + 1;
453 } while(false);
454 }
455 } while(false);
456
457 enum VRControlWalkingOptions walkingOptions_nbo = htonl(self->walkingOptions);
458 do {
459 int8_t b;
460 for (b = (32 - 1); b >= 0; b--) {
461 do {
462 uint16_t byte = bit_offset / 8;
463 uint16_t bit = 7 - (bit_offset % 8);
464 unsigned long newbit = !!((walkingOptions_nbo >> b) & 1U);
465 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
466 bit_offset = bit_offset + 1;
467 } while(false);
468 }
469 } while(false);
470 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
471 (void)self;
472 (void)dst;
473 return bit_offset;
474}
475
480{
481 uint16_t bit_offset = 0;
482 do {
483 int8_t b;
484 for (b = (32 - 1); b >= 0; b--) {
485 do {
486 uint16_t byte = bit_offset / 8;
487 uint16_t bit = 7 - (bit_offset % 8);
488 char dataByte = src[byte];
489 unsigned char bitValue = (dataByte >> bit) & 1U;
490 dst->movementOptions ^= (-bitValue ^ dst->movementOptions) & (1UL << b);
491 bit_offset = bit_offset + 1;
492 } while(false);
493 }
494 } while(false);
496
497 do {
498 int8_t b;
499 for (b = (32 - 1); b >= 0; b--) {
500 do {
501 uint16_t byte = bit_offset / 8;
502 uint16_t bit = 7 - (bit_offset % 8);
503 char dataByte = src[byte];
504 unsigned char bitValue = (dataByte >> bit) & 1U;
505 dst->walkingOptions ^= (-bitValue ^ dst->walkingOptions) & (1UL << b);
506 bit_offset = bit_offset + 1;
507 } while(false);
508 }
509 } while(false);
511 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
512 (void)src;
513 (void)dst;
514 return bit_offset;
515}
516
517/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
enum VRControlMovementOptions movementOptions
controls the robots movement
enum VRControlWalkingOptions walkingOptions
controls the direction of high-level walk commands
const char * wb_gu_vr_teleop_vulkan_control_description(const struct wb_gu_vr_teleop_vulkan_control *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_gu_vr_teleop_vulkan_control_from_network_serialised(const char *src, struct wb_gu_vr_teleop_vulkan_control *dst)
Convert from a compressed, serialised, network byte order byte stream.
size_t wb_gu_vr_teleop_vulkan_control_to_network_serialised(const struct wb_gu_vr_teleop_vulkan_control *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
struct wb_gu_vr_teleop_vulkan_control * wb_gu_vr_teleop_vulkan_control_from_string(struct wb_gu_vr_teleop_vulkan_control *self, const char *str)
Convert from a string.
#define ntohl(x)
const char * wb_gu_vr_teleop_vulkan_control_to_string(const struct wb_gu_vr_teleop_vulkan_control *self, char *toString, size_t bufferSize)
Convert to a string.
#define htonl(x)
#define GU_VR_TELEOP_VULKAN_CONTROL_DESC_BUFFER_SIZE
@ NUM_VR_CONTROL_WALKING_OPTIONS