gusimplewhiteboard
DataLogger.hpp
Go to the documentation of this file.
1/*
2 * file DataLogger.hpp
3 *
4 * This file was generated by classgenerator from data_logger.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 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 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 guWhiteboard_DataLogger_h
61#define guWhiteboard_DataLogger_h
62
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
64#include <cstdlib>
65#include <string.h>
66#include <sstream>
67#endif
68
69#include <gu_util.h>
70#include "wb_data_logger.h"
71
72#undef guWhiteboard_DataLogger_DEFINED
73#define guWhiteboard_DataLogger_DEFINED
74
75#undef DataLogger_DEFINED
76#define DataLogger_DEFINED
77
78namespace guWhiteboard {
79
83 class DataLogger: public wb_data_logger {
84
85 private:
86
90 void init(std::string t_machineName = "", uint32_t t_currentState = 0, uint32_t t_currentSection = 0, uint8_t t_dataSet = 0, bool t_loggerRunning = false, bool t_shouldExit = false, std::string t_comment = "") {
91 gu_strlcpy(const_cast<char *>(this->machineName()), t_machineName.c_str(), 40);
92 set_currentState(t_currentState);
93 set_currentSection(t_currentSection);
94 set_dataSet(t_dataSet);
95 set_loggerRunning(t_loggerRunning);
96 set_shouldExit(t_shouldExit);
97 gu_strlcpy(const_cast<char *>(this->comment()), t_comment.c_str(), 30);
98 }
99
100 public:
101
105 DataLogger(std::string t_machineName = "", uint32_t t_currentState = 0, uint32_t t_currentSection = 0, uint8_t t_dataSet = 0, bool t_loggerRunning = false, bool t_shouldExit = false, std::string t_comment = "") {
106 this->init(t_machineName, t_currentState, t_currentSection, t_dataSet, t_loggerRunning, t_shouldExit, t_comment);
107 }
108
113 this->init(t_other.machineName(), t_other.currentState(), t_other.currentSection(), t_other.dataSet(), t_other.loggerRunning(), t_other.shouldExit(), t_other.comment());
114 }
115
119 DataLogger(const struct wb_data_logger &t_other): wb_data_logger() {
120 this->init(t_other.machineName, t_other.currentState, t_other.currentSection, t_other.dataSet, t_other.loggerRunning, t_other.shouldExit, t_other.comment);
121 }
122
127 this->init(t_other.machineName(), t_other.currentState(), t_other.currentSection(), t_other.dataSet(), t_other.loggerRunning(), t_other.shouldExit(), t_other.comment());
128 return *this;
129 }
130
134 DataLogger &operator = (const struct wb_data_logger &t_other) {
135 this->init(t_other.machineName, t_other.currentState, t_other.currentSection, t_other.dataSet, t_other.loggerRunning, t_other.shouldExit, t_other.comment);
136 return *this;
137 }
138
139 bool operator ==(const DataLogger &t_other) const
140 {
141 return 0 == strncmp(machineName(), t_other.machineName(), 40)
142 && currentState() == t_other.currentState()
143 && currentSection() == t_other.currentSection()
144 && dataSet() == t_other.dataSet()
145 && loggerRunning() == t_other.loggerRunning()
146 && shouldExit() == t_other.shouldExit()
147 && 0 == strncmp(comment(), t_other.comment(), 30);
148 }
149
150 bool operator !=(const DataLogger &t_other) const
151 {
152 return !(*this == t_other);
153 }
154
155 bool operator ==(const wb_data_logger &t_other) const
156 {
157 return *this == DataLogger(t_other);
158 }
159
160 bool operator !=(const wb_data_logger &t_other) const
161 {
162 return !(*this == t_other);
163 }
164
165 const char * machineName() const
166 {
167 return &(wb_data_logger::machineName[0]);
168 }
169
170 size_t machineName_size() const
171 {
172 return 40;
173 }
174
175 char & machineName(int t_i)
176 {
177 return wb_data_logger::machineName[t_i];
178 }
179
180 const char & machineName(int t_i) const
181 {
182 return wb_data_logger::machineName[t_i];
183 }
184
185 void set_machineName(const char *t_newValue)
186 {
187 strncpy(wb_data_logger::machineName, t_newValue, 40);
188 }
189
190 uint32_t & currentState()
191 {
193 }
194
195 const uint32_t & currentState() const
196 {
198 }
199
200 void set_currentState(const uint32_t &t_newValue)
201 {
202 wb_data_logger::currentState = t_newValue;
203 }
204
205 uint32_t & currentSection()
206 {
208 }
209
210 const uint32_t & currentSection() const
211 {
213 }
214
215 void set_currentSection(const uint32_t &t_newValue)
216 {
218 }
219
220 uint8_t & dataSet()
221 {
223 }
224
225 const uint8_t & dataSet() const
226 {
228 }
229
230 void set_dataSet(const uint8_t &t_newValue)
231 {
232 wb_data_logger::dataSet = t_newValue;
233 }
234
236 {
238 }
239
240 const bool & loggerRunning() const
241 {
243 }
244
245 void set_loggerRunning(const bool &t_newValue)
246 {
248 }
249
250 bool & shouldExit()
251 {
253 }
254
255 const bool & shouldExit() const
256 {
258 }
259
260 void set_shouldExit(const bool &t_newValue)
261 {
262 wb_data_logger::shouldExit = t_newValue;
263 }
264
265 const char * comment() const
266 {
267 return &(wb_data_logger::comment[0]);
268 }
269
270 size_t comment_size() const
271 {
272 return 30;
273 }
274
275 char & comment(int t_i)
276 {
277 return wb_data_logger::comment[t_i];
278 }
279
280 const char & comment(int t_i) const
281 {
282 return wb_data_logger::comment[t_i];
283 }
284
285 void set_comment(const char *t_newValue)
286 {
287 strncpy(wb_data_logger::comment, t_newValue, 30);
288 }
289
290#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
294 DataLogger(const std::string &t_str) {
295 this->init();
296 this->from_string(t_str);
297 }
298
299 std::string description() {
300#ifdef USE_WB_DATA_LOGGER_C_CONVERSION
301 char buffer[DATA_LOGGER_DESC_BUFFER_SIZE];
302 wb_data_logger_description(this, buffer, sizeof(buffer));
303 std::string descr = buffer;
304 return descr;
305#else
306 std::ostringstream ss;
307 if (0 == strncmp("", this->machineName(), 1)) {
308 ss << "machineName=" << "";
309 } else {
310 ss << "machineName=" << this->machineName();
311 }
312 ss << ", ";
313 ss << "currentState=" << static_cast<unsigned>(this->currentState());
314 ss << ", ";
315 ss << "currentSection=" << static_cast<unsigned>(this->currentSection());
316 ss << ", ";
317 ss << "dataSet=" << static_cast<unsigned>(this->dataSet());
318 ss << ", ";
319 ss << "loggerRunning=" << (this->loggerRunning() ? "true" : "false");
320 ss << ", ";
321 ss << "shouldExit=" << (this->shouldExit() ? "true" : "false");
322 ss << ", ";
323 if (0 == strncmp("", this->comment(), 1)) {
324 ss << "comment=" << "";
325 } else {
326 ss << "comment=" << this->comment();
327 }
328 return ss.str();
329#endif
330 }
331
332 std::string to_string() {
333#ifdef USE_WB_DATA_LOGGER_C_CONVERSION
335 wb_data_logger_to_string(this, buffer, sizeof(buffer));
336 std::string toString = buffer;
337 return toString;
338#else
339 std::ostringstream ss;
340 if (0 == strncmp("", this->machineName(), 1)) {
341 ss << "";
342 } else {
343 ss << this->machineName();
344 }
345 ss << ", ";
346 ss << static_cast<unsigned>(this->currentState());
347 ss << ", ";
348 ss << static_cast<unsigned>(this->currentSection());
349 ss << ", ";
350 ss << static_cast<unsigned>(this->dataSet());
351 ss << ", ";
352 ss << (this->loggerRunning() ? "true" : "false");
353 ss << ", ";
354 ss << (this->shouldExit() ? "true" : "false");
355 ss << ", ";
356 if (0 == strncmp("", this->comment(), 1)) {
357 ss << "";
358 } else {
359 ss << this->comment();
360 }
361 return ss.str();
362#endif
363 }
364
365#ifdef USE_WB_DATA_LOGGER_C_CONVERSION
366 void from_string(const std::string &t_str) {
367 wb_data_logger_from_string(this, t_str.c_str());
368#else
369 void from_string(const std::string &t_str) {
370 char * str_cstr = const_cast<char *>(t_str.c_str());
371 size_t temp_length = strlen(str_cstr);
372 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
373 if (length < 1 || length > DATA_LOGGER_DESC_BUFFER_SIZE) {
374 return;
375 }
376 char var_str_buffer[DATA_LOGGER_DESC_BUFFER_SIZE + 1];
377 char* var_str = &var_str_buffer[0];
378 char key_buffer[15];
379 char* key = &key_buffer[0];
380 int bracecount = 0;
381 int startVar = 0;
382 int index = 0;
383 int startKey = 0;
384 int endKey = -1;
385 int varIndex = 0;
386 if (index == 0 && str_cstr[0] == '{') {
387 index = 1;
388 }
389 startVar = index;
390 startKey = startVar;
391 do {
392 for (int i = index; i < length; i++) {
393 index = i + 1;
394 if (bracecount == 0 && str_cstr[i] == '=') {
395 endKey = i - 1;
396 startVar = index;
397 continue;
398 }
399 if (bracecount == 0 && isspace(str_cstr[i])) {
400 startVar = index;
401 if (endKey == -1) {
402 startKey = index;
403 }
404 continue;
405 }
406 if (bracecount == 0 && str_cstr[i] == ',') {
407 index = i - 1;
408 break;
409 }
410 if (str_cstr[i] == '{') {
411 bracecount++;
412 continue;
413 }
414 if (str_cstr[i] == '}') {
415 bracecount--;
416 if (bracecount < 0) {
417 index = i - 1;
418 break;
419 }
420 }
421 if (i == length - 1) {
422 index = i;
423 }
424 }
425 if (endKey >= startKey && endKey - startKey < length) {
426 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
427 key[(endKey - startKey) + 1] = 0;
428 } else {
429 key[0] = 0;
430 }
431 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
432 var_str[(index - startVar) + 1] = 0;
433 bracecount = 0;
434 index += 2;
435 startVar = index;
436 startKey = startVar;
437 endKey = -1;
438 if (strlen(key) > 0) {
439 if (0 == strcmp("machineName", key)) {
440 varIndex = 0;
441 } else if (0 == strcmp("currentState", key)) {
442 varIndex = 1;
443 } else if (0 == strcmp("currentSection", key)) {
444 varIndex = 2;
445 } else if (0 == strcmp("dataSet", key)) {
446 varIndex = 3;
447 } else if (0 == strcmp("loggerRunning", key)) {
448 varIndex = 4;
449 } else if (0 == strcmp("shouldExit", key)) {
450 varIndex = 5;
451 } else if (0 == strcmp("comment", key)) {
452 varIndex = 6;
453 } else {
454 varIndex = -1;
455 }
456 }
457 switch (varIndex) {
458 case -1: { break; }
459 case 0:
460 {
461 strncpy(wb_data_logger::machineName, var_str, 40);
462 break;
463 }
464 case 1:
465 {
466 this->set_currentState(static_cast<uint32_t>(atoi(var_str)));
467 break;
468 }
469 case 2:
470 {
471 this->set_currentSection(static_cast<uint32_t>(atoi(var_str)));
472 break;
473 }
474 case 3:
475 {
476 this->set_dataSet(static_cast<uint8_t>(atoi(var_str)));
477 break;
478 }
479 case 4:
480 {
481 this->set_loggerRunning(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
482 break;
483 }
484 case 5:
485 {
486 this->set_shouldExit(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
487 break;
488 }
489 case 6:
490 {
491 strncpy(wb_data_logger::comment, var_str, 30);
492 break;
493 }
494 }
495 if (varIndex >= 0) {
496 varIndex++;
497 }
498 } while(index < length);
499#endif
500 }
501#endif
502 };
503
504}
505
506#endif
Provides a C++ wrapper around wb_data_logger.
Definition: DataLogger.hpp:83
size_t comment_size() const
Definition: DataLogger.hpp:270
const uint32_t & currentSection() const
Definition: DataLogger.hpp:210
DataLogger & operator=(const DataLogger &t_other)
Copy Assignment Operator.
Definition: DataLogger.hpp:126
void set_machineName(const char *t_newValue)
Definition: DataLogger.hpp:185
DataLogger(std::string t_machineName="", uint32_t t_currentState=0, uint32_t t_currentSection=0, uint8_t t_dataSet=0, bool t_loggerRunning=false, bool t_shouldExit=false, std::string t_comment="")
Create a new DataLogger.
Definition: DataLogger.hpp:105
void set_shouldExit(const bool &t_newValue)
Definition: DataLogger.hpp:260
const char & comment(int t_i) const
Definition: DataLogger.hpp:280
const bool & loggerRunning() const
Definition: DataLogger.hpp:240
DataLogger(const struct wb_data_logger &t_other)
Copy Constructor.
Definition: DataLogger.hpp:119
std::string description()
Definition: DataLogger.hpp:299
void set_currentSection(const uint32_t &t_newValue)
Definition: DataLogger.hpp:215
void set_loggerRunning(const bool &t_newValue)
Definition: DataLogger.hpp:245
bool operator==(const DataLogger &t_other) const
Definition: DataLogger.hpp:139
const bool & shouldExit() const
Definition: DataLogger.hpp:255
const char * machineName() const
Definition: DataLogger.hpp:165
uint32_t & currentSection()
Definition: DataLogger.hpp:205
const uint8_t & dataSet() const
Definition: DataLogger.hpp:225
const char & machineName(int t_i) const
Definition: DataLogger.hpp:180
bool operator!=(const DataLogger &t_other) const
Definition: DataLogger.hpp:150
const uint32_t & currentState() const
Definition: DataLogger.hpp:195
DataLogger(const DataLogger &t_other)
Copy Constructor.
Definition: DataLogger.hpp:112
const char * comment() const
Definition: DataLogger.hpp:265
char & comment(int t_i)
Definition: DataLogger.hpp:275
void set_currentState(const uint32_t &t_newValue)
Definition: DataLogger.hpp:200
void set_dataSet(const uint8_t &t_newValue)
Definition: DataLogger.hpp:230
char & machineName(int t_i)
Definition: DataLogger.hpp:175
void set_comment(const char *t_newValue)
Definition: DataLogger.hpp:285
void from_string(const std::string &t_str)
Definition: DataLogger.hpp:369
DataLogger(const std::string &t_str)
String Constructor.
Definition: DataLogger.hpp:294
size_t machineName_size() const
Definition: DataLogger.hpp:170
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
uint8_t dataSet
Enables selection of a data set to be logged (default = 0, joints and sensors) (NYI)
bool shouldExit
Switch to cause DataLogger to exit.
bool loggerRunning
Starts/Stops logging.
char machineName[40]
Name of the machine being monitored, but could be anything.
uint32_t currentSection
Section within the state (e.g.
char comment[30]
Comment to be attached to the logged data (NYI)
uint32_t currentState
The machine's currently executing state (use integer rather than the state's name)
const char * wb_data_logger_description(const struct wb_data_logger *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_data_logger * wb_data_logger_from_string(struct wb_data_logger *self, const char *str)
Convert from a string.
const char * wb_data_logger_to_string(const struct wb_data_logger *self, char *toString, size_t bufferSize)
Convert to a string.
#define DATA_LOGGER_TO_STRING_BUFFER_SIZE
#define DATA_LOGGER_DESC_BUFFER_SIZE