gusimplewhiteboard
wb_teleoperation_status.c
Go to the documentation of this file.
1/*
2 * file wb_teleoperation_status.c
3 *
4 * This file was generated by classgenerator from teleoperationStatus.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_status_description(const struct wb_teleoperation_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 len += snprintf(descString + len, bufferSize - len, "sayString=%s", self->sayString);
134 return descString;
135#pragma clang diagnostic pop
136}
137
141const char* wb_teleoperation_status_to_string(const struct wb_teleoperation_status* self, char* toString, size_t bufferSize)
142{
143#pragma clang diagnostic push
144#pragma clang diagnostic ignored "-Wunused-variable"
145 size_t len = 0;
146 if (len >= bufferSize) {
147 return toString;
148 }
149 len += snprintf(toString + len, bufferSize - len, "%s", self->sayString);
150 return toString;
151#pragma clang diagnostic pop
152}
153
158{
159 size_t temp_length = strlen(str);
160 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
161 if (length < 1 || length > TELEOPERATIONSTATUS_DESC_BUFFER_SIZE) {
162 return self;
163 }
164 char var_str_buffer[TELEOPERATIONSTATUS_DESC_BUFFER_SIZE + 1];
165 char* var_str = &var_str_buffer[0];
166 char key_buffer[10];
167 char* key = &key_buffer[0];
168 int bracecount = 0;
169 int startVar = 0;
170 int index = 0;
171 int startKey = 0;
172 int endKey = -1;
173 int varIndex = 0;
174 if (index == 0 && str[0] == '{') {
175 index = 1;
176 }
177 startVar = index;
178 startKey = startVar;
179 do {
180 for (int i = index; i < length; i++) {
181 index = i + 1;
182 if (bracecount == 0 && str[i] == '=') {
183 endKey = i - 1;
184 startVar = index;
185 continue;
186 }
187 if (bracecount == 0 && isspace(str[i])) {
188 startVar = index;
189 if (endKey == -1) {
190 startKey = index;
191 }
192 continue;
193 }
194 if (bracecount == 0 && str[i] == ',') {
195 index = i - 1;
196 break;
197 }
198 if (str[i] == '{') {
199 bracecount++;
200 continue;
201 }
202 if (str[i] == '}') {
203 bracecount--;
204 if (bracecount < 0) {
205 index = i - 1;
206 break;
207 }
208 }
209 if (i == length - 1) {
210 index = i;
211 }
212 }
213 if (endKey >= startKey && endKey - startKey < length) {
214 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
215 key[(endKey - startKey) + 1] = 0;
216 } else {
217 key[0] = 0;
218 }
219 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
220 var_str[(index - startVar) + 1] = 0;
221 bracecount = 0;
222 index += 2;
223 startVar = index;
224 startKey = startVar;
225 endKey = -1;
226 if (strlen(key) > 0) {
227 if (0 == strcmp("sayString", key)) {
228 varIndex = 0;
229 } else {
230 varIndex = -1;
231 }
232 }
233 switch (varIndex) {
234 case -1: { break; }
235 case 0:
236 {
237 strncpy(self->sayString, var_str, 30);
238 break;
239 }
240 }
241 if (varIndex >= 0) {
242 varIndex++;
243 }
244 } while(index < length);
245 return self;
246}
247
248/*#ifdef WHITEBOARD_SERIALISATION*/
249
254{
255 uint16_t bit_offset = 0;
256 do { //limit declaration scope
257 uint8_t len = (uint8_t) strlen(self->sayString);
258 int8_t b;
259 for (b = 7; b >= 0; b--) {
260 do {
261 uint16_t byte = bit_offset / 8;
262 uint16_t bit = 7 - (bit_offset % 8);
263 unsigned long newbit = !!((len >> b) & 1U);
264 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
265 bit_offset = bit_offset + 1;
266 } while(false);
267 }
268 uint8_t c;
269 for (c = 0; c < len; c++) {
270 for (b = 7; b >= 0; b--) {
271 do {
272 uint16_t byte = bit_offset / 8;
273 uint16_t bit = 7 - (bit_offset % 8);
274 unsigned long newbit = !!((self->sayString[c] >> b) & 1U);
275 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
276 bit_offset = bit_offset + 1;
277 } while(false);
278 }
279 }
280 } while(false);
281 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
282 (void)self;
283 (void)dst;
284 return bit_offset;
285}
286
291{
292 uint16_t bit_offset = 0;
293 do {
294 uint8_t len = 0;
295 int8_t b;
296 for (b = 7; b >= 0; b--) {
297 do {
298 uint16_t byte = bit_offset / 8;
299 uint16_t bit = 7 - (bit_offset % 8);
300 char dataByte = src[byte];
301 unsigned char bitValue = (dataByte >> bit) & 1U;
302 len ^= (-bitValue ^ len) & (1UL << b);
303 bit_offset = bit_offset + 1;
304 } while(false);
305 }
306 uint8_t c;
307 for (c = 0; c < len; c++) {
308 for (b = 7; b >= 0; b--) {
309 do {
310 uint16_t byte = bit_offset / 8;
311 uint16_t bit = 7 - (bit_offset % 8);
312 char dataByte = src[byte];
313 unsigned char bitValue = (dataByte >> bit) & 1U;
314 dst->sayString[c] ^= (-bitValue ^ dst->sayString[c]) & (1UL << b);
315 bit_offset = bit_offset + 1;
316 } while(false);
317 }
318 }
319 } while (false);
320 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
321 (void)src;
322 (void)dst;
323 return bit_offset;
324}
325
326/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
char sayString[30]
String passed to Say_t.
const char * wb_teleoperation_status_description(const struct wb_teleoperation_status *self, char *descString, size_t bufferSize)
Convert to a description string.
size_t wb_teleoperation_status_to_network_serialised(const struct wb_teleoperation_status *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
size_t wb_teleoperation_status_from_network_serialised(const char *src, struct wb_teleoperation_status *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_teleoperation_status_to_string(const struct wb_teleoperation_status *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_teleoperation_status * wb_teleoperation_status_from_string(struct wb_teleoperation_status *self, const char *str)
Convert from a string.
#define TELEOPERATIONSTATUS_DESC_BUFFER_SIZE