YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeSerialPort_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.2)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GENERATION is ON.
10
11// Generated on: Tue Jul 28 23:33:19 2026
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(FakeSerialPortParamsCOMPONENT, "yarp.device.FakeSerialPort")
20}
21
22
26
27
28std::vector<std::string> FakeSerialPort_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("comport");
32 params.push_back("verbose");
33 params.push_back("baudrate");
34 params.push_back("xonlim");
35 params.push_back("xofflim");
36 params.push_back("readmincharacters");
37 params.push_back("readtimeoutmsec");
38 params.push_back("paritymode");
39 params.push_back("ctsenb");
40 params.push_back("rtsenb");
41 params.push_back("xinenb");
42 params.push_back("xoutenb");
43 params.push_back("modem");
44 params.push_back("rcvenb");
45 params.push_back("dsrenb");
46 params.push_back("dtrdisable");
47 params.push_back("databits");
48 params.push_back("stopbits");
49 params.push_back("line_terminator_char1");
50 params.push_back("line_terminator_char2");
51 return params;
52}
53
54
55bool FakeSerialPort_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
56{
57 if (paramName =="comport")
58 {
59 paramValue = m_comport;
60 return true;
61 }
62 if (paramName =="verbose")
63 {
64 paramValue = std::to_string(m_verbose);
65 return true;
66 }
67 if (paramName =="baudrate")
68 {
69 paramValue = std::to_string(m_baudrate);
70 return true;
71 }
72 if (paramName =="xonlim")
73 {
74 paramValue = std::to_string(m_xonlim);
75 return true;
76 }
77 if (paramName =="xofflim")
78 {
79 paramValue = std::to_string(m_xofflim);
80 return true;
81 }
82 if (paramName =="readmincharacters")
83 {
84 paramValue = std::to_string(m_readmincharacters);
85 return true;
86 }
87 if (paramName =="readtimeoutmsec")
88 {
89 paramValue = std::to_string(m_readtimeoutmsec);
90 return true;
91 }
92 if (paramName =="paritymode")
93 {
94 paramValue = m_paritymode;
95 return true;
96 }
97 if (paramName =="ctsenb")
98 {
99 paramValue = std::to_string(m_ctsenb);
100 return true;
101 }
102 if (paramName =="rtsenb")
103 {
104 paramValue = std::to_string(m_rtsenb);
105 return true;
106 }
107 if (paramName =="xinenb")
108 {
109 paramValue = std::to_string(m_xinenb);
110 return true;
111 }
112 if (paramName =="xoutenb")
113 {
114 paramValue = std::to_string(m_xoutenb);
115 return true;
116 }
117 if (paramName =="modem")
118 {
119 paramValue = std::to_string(m_modem);
120 return true;
121 }
122 if (paramName =="rcvenb")
123 {
124 paramValue = std::to_string(m_rcvenb);
125 return true;
126 }
127 if (paramName =="dsrenb")
128 {
129 paramValue = std::to_string(m_dsrenb);
130 return true;
131 }
132 if (paramName =="dtrdisable")
133 {
134 paramValue = std::to_string(m_dtrdisable);
135 return true;
136 }
137 if (paramName =="databits")
138 {
139 paramValue = std::to_string(m_databits);
140 return true;
141 }
142 if (paramName =="stopbits")
143 {
144 paramValue = std::to_string(m_stopbits);
145 return true;
146 }
147 if (paramName =="line_terminator_char1")
148 {
149 paramValue = std::string(1, m_line_terminator_char1);
150 return true;
151 }
152 if (paramName =="line_terminator_char2")
153 {
154 paramValue = std::string(1, m_line_terminator_char2);
155 return true;
156 }
157
158 yError() <<"parameter '" << paramName << "' was not found";
159 return false;
160
161}
162
163
165{
166 //This is a sub-optimal solution.
167 //Ideally getConfiguration() should return all parameters but it is currently
168 //returning only user provided parameters (excluding default values)
169 //This behaviour will be fixed in the near future.
170 std::string s_cfg = m_provided_configuration;
171 return s_cfg;
172}
173
175{
176 //Check for --help option
177 if (config.check("help"))
178 {
179 yCInfo(FakeSerialPortParamsCOMPONENT) << getDocumentationOfDeviceParams();
180 }
181
184 //Parser of parameter comport
185 {
186 if (config.check("comport"))
187 {
188 m_comport = config.find("comport").asString();
189 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'comport' using value:" << m_comport;
190 }
191 else
192 {
193 yCError(FakeSerialPortParamsCOMPONENT) << "Mandatory parameter 'comport' not found!";
194 yCError(FakeSerialPortParamsCOMPONENT) << "Description of the parameter: name of the serial channel";
195 return false;
196 }
197 prop_check.unput("comport");
198 }
199
200 //Parser of parameter verbose
201 {
202 if (config.check("verbose"))
203 {
204 m_verbose = config.find("verbose").asInt64();
205 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'verbose' using value:" << m_verbose;
206 }
207 else
208 {
209 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'verbose' using DEFAULT value:" << m_verbose;
210 }
211 prop_check.unput("verbose");
212 }
213
214 //Parser of parameter baudrate
215 {
216 if (config.check("baudrate"))
217 {
218 m_baudrate = config.find("baudrate").asInt64();
219 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'baudrate' using value:" << m_baudrate;
220 }
221 else
222 {
223 yCError(FakeSerialPortParamsCOMPONENT) << "Mandatory parameter 'baudrate' not found!";
224 yCError(FakeSerialPortParamsCOMPONENT) << "Description of the parameter: Specifies the baudrate at which the communication port operates";
225 return false;
226 }
227 prop_check.unput("baudrate");
228 }
229
230 //Parser of parameter xonlim
231 {
232 if (config.check("xonlim"))
233 {
234 m_xonlim = config.find("xonlim").asInt64();
235 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xonlim' using value:" << m_xonlim;
236 }
237 else
238 {
239 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xonlim' using DEFAULT value:" << m_xonlim;
240 }
241 prop_check.unput("xonlim");
242 }
243
244 //Parser of parameter xofflim
245 {
246 if (config.check("xofflim"))
247 {
248 m_xofflim = config.find("xofflim").asInt64();
249 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xofflim' using value:" << m_xofflim;
250 }
251 else
252 {
253 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xofflim' using DEFAULT value:" << m_xofflim;
254 }
255 prop_check.unput("xofflim");
256 }
257
258 //Parser of parameter readmincharacters
259 {
260 if (config.check("readmincharacters"))
261 {
262 m_readmincharacters = config.find("readmincharacters").asInt64();
263 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readmincharacters' using value:" << m_readmincharacters;
264 }
265 else
266 {
267 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readmincharacters' using DEFAULT value:" << m_readmincharacters;
268 }
269 prop_check.unput("readmincharacters");
270 }
271
272 //Parser of parameter readtimeoutmsec
273 {
274 if (config.check("readtimeoutmsec"))
275 {
276 m_readtimeoutmsec = config.find("readtimeoutmsec").asInt64();
277 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readtimeoutmsec' using value:" << m_readtimeoutmsec;
278 }
279 else
280 {
281 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readtimeoutmsec' using DEFAULT value:" << m_readtimeoutmsec;
282 }
283 prop_check.unput("readtimeoutmsec");
284 }
285
286 //Parser of parameter paritymode
287 {
288 if (config.check("paritymode"))
289 {
290 m_paritymode = config.find("paritymode").asString();
291 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'paritymode' using value:" << m_paritymode;
292 }
293 else
294 {
295 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'paritymode' using DEFAULT value:" << m_paritymode;
296 }
297 prop_check.unput("paritymode");
298 }
299
300 //Parser of parameter ctsenb
301 {
302 if (config.check("ctsenb"))
303 {
304 m_ctsenb = config.find("ctsenb").asInt64();
305 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'ctsenb' using value:" << m_ctsenb;
306 }
307 else
308 {
309 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'ctsenb' using DEFAULT value:" << m_ctsenb;
310 }
311 prop_check.unput("ctsenb");
312 }
313
314 //Parser of parameter rtsenb
315 {
316 if (config.check("rtsenb"))
317 {
318 m_rtsenb = config.find("rtsenb").asInt64();
319 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rtsenb' using value:" << m_rtsenb;
320 }
321 else
322 {
323 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rtsenb' using DEFAULT value:" << m_rtsenb;
324 }
325 prop_check.unput("rtsenb");
326 }
327
328 //Parser of parameter xinenb
329 {
330 if (config.check("xinenb"))
331 {
332 m_xinenb = config.find("xinenb").asInt64();
333 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xinenb' using value:" << m_xinenb;
334 }
335 else
336 {
337 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xinenb' using DEFAULT value:" << m_xinenb;
338 }
339 prop_check.unput("xinenb");
340 }
341
342 //Parser of parameter xoutenb
343 {
344 if (config.check("xoutenb"))
345 {
346 m_xoutenb = config.find("xoutenb").asInt64();
347 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xoutenb' using value:" << m_xoutenb;
348 }
349 else
350 {
351 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xoutenb' using DEFAULT value:" << m_xoutenb;
352 }
353 prop_check.unput("xoutenb");
354 }
355
356 //Parser of parameter modem
357 {
358 if (config.check("modem"))
359 {
360 m_modem = config.find("modem").asInt64();
361 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'modem' using value:" << m_modem;
362 }
363 else
364 {
365 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'modem' using DEFAULT value:" << m_modem;
366 }
367 prop_check.unput("modem");
368 }
369
370 //Parser of parameter rcvenb
371 {
372 if (config.check("rcvenb"))
373 {
374 m_rcvenb = config.find("rcvenb").asInt64();
375 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rcvenb' using value:" << m_rcvenb;
376 }
377 else
378 {
379 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rcvenb' using DEFAULT value:" << m_rcvenb;
380 }
381 prop_check.unput("rcvenb");
382 }
383
384 //Parser of parameter dsrenb
385 {
386 if (config.check("dsrenb"))
387 {
388 m_dsrenb = config.find("dsrenb").asInt64();
389 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dsrenb' using value:" << m_dsrenb;
390 }
391 else
392 {
393 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dsrenb' using DEFAULT value:" << m_dsrenb;
394 }
395 prop_check.unput("dsrenb");
396 }
397
398 //Parser of parameter dtrdisable
399 {
400 if (config.check("dtrdisable"))
401 {
402 m_dtrdisable = config.find("dtrdisable").asInt64();
403 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dtrdisable' using value:" << m_dtrdisable;
404 }
405 else
406 {
407 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dtrdisable' using DEFAULT value:" << m_dtrdisable;
408 }
409 prop_check.unput("dtrdisable");
410 }
411
412 //Parser of parameter databits
413 {
414 if (config.check("databits"))
415 {
416 m_databits = config.find("databits").asInt64();
417 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'databits' using value:" << m_databits;
418 }
419 else
420 {
421 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'databits' using DEFAULT value:" << m_databits;
422 }
423 prop_check.unput("databits");
424 }
425
426 //Parser of parameter stopbits
427 {
428 if (config.check("stopbits"))
429 {
430 m_stopbits = config.find("stopbits").asInt64();
431 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'stopbits' using value:" << m_stopbits;
432 }
433 else
434 {
435 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'stopbits' using DEFAULT value:" << m_stopbits;
436 }
437 prop_check.unput("stopbits");
438 }
439
440 //Parser of parameter line_terminator_char1
441 {
442 if (config.check("line_terminator_char1"))
443 {
444 m_line_terminator_char1 = config.find("line_terminator_char1").asInt8();
445 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char1' using value:" << m_line_terminator_char1;
446 }
447 else
448 {
449 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char1' using DEFAULT value:" << m_line_terminator_char1;
450 }
451 prop_check.unput("line_terminator_char1");
452 }
453
454 //Parser of parameter line_terminator_char2
455 {
456 if (config.check("line_terminator_char2"))
457 {
458 m_line_terminator_char2 = config.find("line_terminator_char2").asInt8();
459 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char2' using value:" << m_line_terminator_char2;
460 }
461 else
462 {
463 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char2' using DEFAULT value:" << m_line_terminator_char2;
464 }
465 prop_check.unput("line_terminator_char2");
466 }
467
468 /*
469 //This code check if the user set some parameter which are not check by the parser
470 //If the parser is set in strict mode, this will generate an error
471 if (prop_check.size() > 0)
472 {
473 bool extra_params_found = false;
474 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
475 {
476 if (m_parser_is_strict)
477 {
478 yCError(FakeSerialPortParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
479 extra_params_found = true;
480 }
481 else
482 {
483 yCWarning(FakeSerialPortParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
484 }
485 }
486
487 if (m_parser_is_strict && extra_params_found)
488 {
489 return false;
490 }
491 }
492 */
493 return true;
494}
495
496
498{
499 std::string doc;
500 doc = doc + std::string("\n=============================================\n");
501 doc = doc + std::string("This is the help for device: FakeSerialPort\n");
502 doc = doc + std::string("\n");
503 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
504 doc = doc + std::string("'comport': name of the serial channel\n");
505 doc = doc + std::string("'verbose': Specifies if the device is in verbose mode (0/1)\n");
506 doc = doc + std::string("'baudrate': Specifies the baudrate at which the communication port operates\n");
507 doc = doc + std::string("'xonlim': Specifies the minimum number of bytes in input buffer before XON char is sent\n");
508 doc = doc + std::string("'xofflim': Specifies the maximum number of bytes in input buffer before XOFF char is sent\n");
509 doc = doc + std::string("'readmincharacters': Specifies the minimum number of characters for non-canonical read (POSIX)\n");
510 doc = doc + std::string("'readtimeoutmsec': Specifies the time to wait before returning from read. Negative value means infinite timeout\n");
511 doc = doc + std::string("'paritymode': Specifies the parity mode (EVEN, ODD, NONE\n");
512 doc = doc + std::string("'ctsenb': Enable & set CTS mode\n");
513 doc = doc + std::string("'rtsenb': Enable & set RTS mode\n");
514 doc = doc + std::string("'xinenb': Enable/disable software flow control on input\n");
515 doc = doc + std::string("'xoutenb': Enable/disable software flow control on output.\n");
516 doc = doc + std::string("'modem': Specifies if device is a modem (POSIX). If not set modem status lines are ignored.\n");
517 doc = doc + std::string("'rcvenb': Enable/disable receiver (POSIX).\n");
518 doc = doc + std::string("'dsrenb': Controls whether DSR is disabled or enabled (Win32).\n");
519 doc = doc + std::string("'dtrdisable': Controls whether DTR is disabled or enabled\n");
520 doc = doc + std::string("'databits': Data bits. Valid values 5, 6, 7 and 8 data bits. Additionally Win32 supports 4 data bits.\n");
521 doc = doc + std::string("'stopbits': Stop bits. Valid values are 1 and 2.\n");
522 doc = doc + std::string("'line_terminator_char1': line terminator character for receiveLine()\n");
523 doc = doc + std::string("'line_terminator_char2': line terminator character for receiveLine()\n");
524 doc = doc + std::string("\n");
525 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
526 doc = doc + " yarpdev --device fakeSerialPort --comport COM3 --verbose 1 --baudrate 9600 --xonlim 0 --xofflim 0 --readmincharacters 1 --readtimeoutmsec 100 --paritymode EVEN --ctsenb 0 --rtsenb 0 --xinenb 0 --xoutenb 0 --modem 0 --rcvenb 0 --dsrenb 0 --dtrdisable 0 --databits 7 --stopbits 1 --line_terminator_char1 '\r' --line_terminator_char2 '\n'\n";
527 doc = doc + std::string("Using only mandatory params:\n");
528 doc = doc + " yarpdev --device fakeSerialPort --comport COM3 --baudrate 9600\n";
529 doc = doc + std::string("=============================================\n\n"); return doc;
530}
#define yError(...)
Definition Log.h:361
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getConfiguration() const override
Return the configuration of the device.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
A class for storing options and configuration information.
Definition Property.h:32
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)