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.0)
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_GERNERATION is ON.
10
11// Generated on: Thu May 22 11:32:32 2025
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 return false;
150 }
151 if (paramName =="line_terminator_char2")
152 {
153 return false;
154 }
155
156 yError() <<"parameter '" << paramName << "' was not found";
157 return false;
158
159}
160
161
163{
164 //This is a sub-optimal solution.
165 //Ideally getConfiguration() should return all parameters but it is currently
166 //returning only user provided parameters (excluding default values)
167 //This behaviour will be fixed in the near future.
168 std::string s_cfg = m_provided_configuration;
169 return s_cfg;
170}
171
173{
174 //Check for --help option
175 if (config.check("help"))
176 {
177 yCInfo(FakeSerialPortParamsCOMPONENT) << getDocumentationOfDeviceParams();
178 }
179
182 //Parser of parameter comport
183 {
184 if (config.check("comport"))
185 {
186 m_comport = config.find("comport").asString();
187 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'comport' using value:" << m_comport;
188 }
189 else
190 {
191 yCError(FakeSerialPortParamsCOMPONENT) << "Mandatory parameter 'comport' not found!";
192 yCError(FakeSerialPortParamsCOMPONENT) << "Description of the parameter: name of the serial channel";
193 return false;
194 }
195 prop_check.unput("comport");
196 }
197
198 //Parser of parameter verbose
199 {
200 if (config.check("verbose"))
201 {
202 m_verbose = config.find("verbose").asInt64();
203 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'verbose' using value:" << m_verbose;
204 }
205 else
206 {
207 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'verbose' using DEFAULT value:" << m_verbose;
208 }
209 prop_check.unput("verbose");
210 }
211
212 //Parser of parameter baudrate
213 {
214 if (config.check("baudrate"))
215 {
216 m_baudrate = config.find("baudrate").asInt64();
217 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'baudrate' using value:" << m_baudrate;
218 }
219 else
220 {
221 yCError(FakeSerialPortParamsCOMPONENT) << "Mandatory parameter 'baudrate' not found!";
222 yCError(FakeSerialPortParamsCOMPONENT) << "Description of the parameter: Specifies the baudrate at which the communication port operates";
223 return false;
224 }
225 prop_check.unput("baudrate");
226 }
227
228 //Parser of parameter xonlim
229 {
230 if (config.check("xonlim"))
231 {
232 m_xonlim = config.find("xonlim").asInt64();
233 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xonlim' using value:" << m_xonlim;
234 }
235 else
236 {
237 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xonlim' using DEFAULT value:" << m_xonlim;
238 }
239 prop_check.unput("xonlim");
240 }
241
242 //Parser of parameter xofflim
243 {
244 if (config.check("xofflim"))
245 {
246 m_xofflim = config.find("xofflim").asInt64();
247 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xofflim' using value:" << m_xofflim;
248 }
249 else
250 {
251 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xofflim' using DEFAULT value:" << m_xofflim;
252 }
253 prop_check.unput("xofflim");
254 }
255
256 //Parser of parameter readmincharacters
257 {
258 if (config.check("readmincharacters"))
259 {
260 m_readmincharacters = config.find("readmincharacters").asInt64();
261 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readmincharacters' using value:" << m_readmincharacters;
262 }
263 else
264 {
265 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readmincharacters' using DEFAULT value:" << m_readmincharacters;
266 }
267 prop_check.unput("readmincharacters");
268 }
269
270 //Parser of parameter readtimeoutmsec
271 {
272 if (config.check("readtimeoutmsec"))
273 {
274 m_readtimeoutmsec = config.find("readtimeoutmsec").asInt64();
275 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readtimeoutmsec' using value:" << m_readtimeoutmsec;
276 }
277 else
278 {
279 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'readtimeoutmsec' using DEFAULT value:" << m_readtimeoutmsec;
280 }
281 prop_check.unput("readtimeoutmsec");
282 }
283
284 //Parser of parameter paritymode
285 {
286 if (config.check("paritymode"))
287 {
288 m_paritymode = config.find("paritymode").asString();
289 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'paritymode' using value:" << m_paritymode;
290 }
291 else
292 {
293 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'paritymode' using DEFAULT value:" << m_paritymode;
294 }
295 prop_check.unput("paritymode");
296 }
297
298 //Parser of parameter ctsenb
299 {
300 if (config.check("ctsenb"))
301 {
302 m_ctsenb = config.find("ctsenb").asInt64();
303 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'ctsenb' using value:" << m_ctsenb;
304 }
305 else
306 {
307 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'ctsenb' using DEFAULT value:" << m_ctsenb;
308 }
309 prop_check.unput("ctsenb");
310 }
311
312 //Parser of parameter rtsenb
313 {
314 if (config.check("rtsenb"))
315 {
316 m_rtsenb = config.find("rtsenb").asInt64();
317 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rtsenb' using value:" << m_rtsenb;
318 }
319 else
320 {
321 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rtsenb' using DEFAULT value:" << m_rtsenb;
322 }
323 prop_check.unput("rtsenb");
324 }
325
326 //Parser of parameter xinenb
327 {
328 if (config.check("xinenb"))
329 {
330 m_xinenb = config.find("xinenb").asInt64();
331 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xinenb' using value:" << m_xinenb;
332 }
333 else
334 {
335 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xinenb' using DEFAULT value:" << m_xinenb;
336 }
337 prop_check.unput("xinenb");
338 }
339
340 //Parser of parameter xoutenb
341 {
342 if (config.check("xoutenb"))
343 {
344 m_xoutenb = config.find("xoutenb").asInt64();
345 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xoutenb' using value:" << m_xoutenb;
346 }
347 else
348 {
349 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'xoutenb' using DEFAULT value:" << m_xoutenb;
350 }
351 prop_check.unput("xoutenb");
352 }
353
354 //Parser of parameter modem
355 {
356 if (config.check("modem"))
357 {
358 m_modem = config.find("modem").asInt64();
359 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'modem' using value:" << m_modem;
360 }
361 else
362 {
363 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'modem' using DEFAULT value:" << m_modem;
364 }
365 prop_check.unput("modem");
366 }
367
368 //Parser of parameter rcvenb
369 {
370 if (config.check("rcvenb"))
371 {
372 m_rcvenb = config.find("rcvenb").asInt64();
373 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rcvenb' using value:" << m_rcvenb;
374 }
375 else
376 {
377 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'rcvenb' using DEFAULT value:" << m_rcvenb;
378 }
379 prop_check.unput("rcvenb");
380 }
381
382 //Parser of parameter dsrenb
383 {
384 if (config.check("dsrenb"))
385 {
386 m_dsrenb = config.find("dsrenb").asInt64();
387 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dsrenb' using value:" << m_dsrenb;
388 }
389 else
390 {
391 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dsrenb' using DEFAULT value:" << m_dsrenb;
392 }
393 prop_check.unput("dsrenb");
394 }
395
396 //Parser of parameter dtrdisable
397 {
398 if (config.check("dtrdisable"))
399 {
400 m_dtrdisable = config.find("dtrdisable").asInt64();
401 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dtrdisable' using value:" << m_dtrdisable;
402 }
403 else
404 {
405 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'dtrdisable' using DEFAULT value:" << m_dtrdisable;
406 }
407 prop_check.unput("dtrdisable");
408 }
409
410 //Parser of parameter databits
411 {
412 if (config.check("databits"))
413 {
414 m_databits = config.find("databits").asInt64();
415 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'databits' using value:" << m_databits;
416 }
417 else
418 {
419 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'databits' using DEFAULT value:" << m_databits;
420 }
421 prop_check.unput("databits");
422 }
423
424 //Parser of parameter stopbits
425 {
426 if (config.check("stopbits"))
427 {
428 m_stopbits = config.find("stopbits").asInt64();
429 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'stopbits' using value:" << m_stopbits;
430 }
431 else
432 {
433 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'stopbits' using DEFAULT value:" << m_stopbits;
434 }
435 prop_check.unput("stopbits");
436 }
437
438 //Parser of parameter line_terminator_char1
439 {
440 if (config.check("line_terminator_char1"))
441 {
442 m_line_terminator_char1 = config.find("line_terminator_char1").asInt8();
443 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char1' using value:" << m_line_terminator_char1;
444 }
445 else
446 {
447 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char1' using DEFAULT value:" << m_line_terminator_char1;
448 }
449 prop_check.unput("line_terminator_char1");
450 }
451
452 //Parser of parameter line_terminator_char2
453 {
454 if (config.check("line_terminator_char2"))
455 {
456 m_line_terminator_char2 = config.find("line_terminator_char2").asInt8();
457 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char2' using value:" << m_line_terminator_char2;
458 }
459 else
460 {
461 yCInfo(FakeSerialPortParamsCOMPONENT) << "Parameter 'line_terminator_char2' using DEFAULT value:" << m_line_terminator_char2;
462 }
463 prop_check.unput("line_terminator_char2");
464 }
465
466 /*
467 //This code check if the user set some parameter which are not check by the parser
468 //If the parser is set in strict mode, this will generate an error
469 if (prop_check.size() > 0)
470 {
471 bool extra_params_found = false;
472 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
473 {
474 if (m_parser_is_strict)
475 {
476 yCError(FakeSerialPortParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
477 extra_params_found = true;
478 }
479 else
480 {
481 yCWarning(FakeSerialPortParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
482 }
483 }
484
485 if (m_parser_is_strict && extra_params_found)
486 {
487 return false;
488 }
489 }
490 */
491 return true;
492}
493
494
496{
497 std::string doc;
498 doc = doc + std::string("\n=============================================\n");
499 doc = doc + std::string("This is the help for device: FakeSerialPort\n");
500 doc = doc + std::string("\n");
501 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
502 doc = doc + std::string("'comport': name of the serial channel\n");
503 doc = doc + std::string("'verbose': Specifies if the device is in verbose mode (0/1)\n");
504 doc = doc + std::string("'baudrate': Specifies the baudrate at which the communication port operates\n");
505 doc = doc + std::string("'xonlim': Specifies the minimum number of bytes in input buffer before XON char is sent\n");
506 doc = doc + std::string("'xofflim': Specifies the maximum number of bytes in input buffer before XOFF char is sent\n");
507 doc = doc + std::string("'readmincharacters': Specifies the minimum number of characters for non-canonical read (POSIX)\n");
508 doc = doc + std::string("'readtimeoutmsec': Specifies the time to wait before returning from read. Negative value means infinite timeout\n");
509 doc = doc + std::string("'paritymode': Specifies the parity mode (EVEN, ODD, NONE\n");
510 doc = doc + std::string("'ctsenb': Enable & set CTS mode\n");
511 doc = doc + std::string("'rtsenb': Enable & set RTS mode\n");
512 doc = doc + std::string("'xinenb': Enable/disable software flow control on input\n");
513 doc = doc + std::string("'xoutenb': Enable/disable software flow control on output.\n");
514 doc = doc + std::string("'modem': Specifies if device is a modem (POSIX). If not set modem status lines are ignored.\n");
515 doc = doc + std::string("'rcvenb': Enable/disable receiver (POSIX).\n");
516 doc = doc + std::string("'dsrenb': Controls whether DSR is disabled or enabled (Win32).\n");
517 doc = doc + std::string("'dtrdisable': Controls whether DTR is disabled or enabled\n");
518 doc = doc + std::string("'databits': Data bits. Valid values 5, 6, 7 and 8 data bits. Additionally Win32 supports 4 data bits.\n");
519 doc = doc + std::string("'stopbits': Stop bits. Valid values are 1 and 2.\n");
520 doc = doc + std::string("'line_terminator_char1': line terminator character for receiveLine()\n");
521 doc = doc + std::string("'line_terminator_char2': line terminator character for receiveLine()\n");
522 doc = doc + std::string("\n");
523 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
524 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";
525 doc = doc + std::string("Using only mandatory params:\n");
526 doc = doc + " yarpdev --device fakeSerialPort --comport COM3 --baudrate 9600\n";
527 doc = doc + std::string("=============================================\n\n"); return doc;
528}
#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:33
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,...)