From 81595647d67e87ad2e89580da66a62cf8738a9cc Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Mon, 4 Mar 2024 21:33:15 +0100 Subject: [PATCH 1/2] all network wrappers are now using the generated params parser some files renamed (capital first letter) --- .../JoypadControlClient/CMakeLists.txt | 3 + .../JoypadControlClient.cpp | 23 +- .../JoypadControlClient/JoypadControlClient.h | 14 +- .../JoypadControlClient_ParamsParser.cpp | 123 +++++++ .../JoypadControlClient_ParamsParser.h | 72 ++++ .../JoypadControlClient_params.md | 2 + .../JoypadControlServer/CMakeLists.txt | 3 + .../JoypadControlServer.cpp | 75 +--- .../JoypadControlServer/JoypadControlServer.h | 20 +- .../JoypadControlServer_ParamsParser.cpp | 153 ++++++++ .../JoypadControlServer_ParamsParser.h | 78 ++++ .../JoypadControlServer_params.md | 4 + .../tests/joypadControlServer_test.cpp | 1 - .../LLM_nwc_yarp/CMakeLists.txt | 3 + .../LLM_nwc_yarp/LLM_nwc_yarp.cpp | 21 +- .../LLM_nwc_yarp/LLM_nwc_yarp.h | 12 +- .../LLM_nwc_yarp_ParamsParser.cpp | 123 +++++++ .../LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.h | 72 ++++ .../LLM_nwc_yarp/LLM_nwc_yarp_params.md | 2 + .../LLM_nwc_yarp/tests/LLM_nwc_yarp_test.cpp | 6 +- .../LLM_nws_yarp/CMakeLists.txt | 3 + .../LLM_nws_yarp/LLM_nws_yarp.cpp | 39 +- .../LLM_nws_yarp/LLM_nws_yarp.h | 14 +- .../LLM_nws_yarp_ParamsParser.cpp | 105 ++++++ .../LLM_nws_yarp/LLM_nws_yarp_ParamsParser.h | 69 ++++ .../LLM_nws_yarp/LLM_nws_yarp_params.md | 1 + .../LLM_nws_yarp/tests/LLM_nws_yarp_test.cpp | 4 +- .../RGBDSensorClient/CMakeLists.txt | 3 + .../RGBDSensorClient/RGBDSensorClient.cpp | 166 +-------- .../RGBDSensorClient/RGBDSensorClient.h | 77 +--- .../RGBDSensorClient_ParamsParser.cpp | 243 ++++++++++++ .../RGBDSensorClient_ParamsParser.h | 93 +++++ .../RGBDSensorClient_params.md | 9 + .../RGBDSensor_nws_yarp/CMakeLists.txt | 3 + .../RgbdSensor_nws_yarp.cpp | 96 ++--- .../RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.h | 27 +- .../RgbdSensor_nws_yarp_ParamsParser.cpp | 121 ++++++ .../RgbdSensor_nws_yarp_ParamsParser.h | 72 ++++ .../RgbdSensor_nws_yarp_params.md | 2 + .../Rangefinder2DClient.cpp | 2 + .../Rangefinder2D_nwc_yarp/CMakeLists.txt | 3 + .../Rangefinder2D_nwc_yarp.cpp | 33 +- .../Rangefinder2D_nwc_yarp.h | 16 +- .../Rangefinder2D_nwc_yarp_ParamsParser.cpp | 139 +++++++ .../Rangefinder2D_nwc_yarp_ParamsParser.h | 75 ++++ .../Rangefinder2D_nwc_yarp_params.md | 3 + .../Rangefinder2D_nws_yarp/CMakeLists.txt | 3 + .../Rangefinder2D_nws_yarp.cpp | 53 +-- .../Rangefinder2D_nws_yarp.h | 31 +- .../Rangefinder2D_nws_yarp_ParamsParser.cpp | 137 +++++++ .../Rangefinder2D_nws_yarp_ParamsParser.h | 75 ++++ .../Rangefinder2D_nws_yarp_params.md | 3 + .../RemoteControlBoard/CMakeLists.txt | 3 + .../RemoteControlBoard/RemoteControlBoard.cpp | 129 +++---- .../RemoteControlBoard/RemoteControlBoard.h | 15 +- .../RemoteControlBoard_ParamsParser.cpp | 347 ++++++++++++++++++ .../RemoteControlBoard_ParamsParser.h | 111 ++++++ .../RemoteControlBoard_params.md | 15 + .../RobotDescriptionClient/CMakeLists.txt | 3 + .../RobotDescriptionClient.cpp | 31 +- .../RobotDescriptionClient.h | 13 +- .../RobotDescriptionClient_ParamsParser.cpp | 123 +++++++ .../RobotDescriptionClient_ParamsParser.h | 72 ++++ .../RobotDescriptionClient_params.md | 2 + .../RobotDescriptionServer/CMakeLists.txt | 3 + .../RobotDescriptionServer.cpp | 16 +- .../RobotDescriptionServer.h | 13 +- .../RobotDescriptionServer_ParamsParser.cpp | 105 ++++++ .../RobotDescriptionServer_ParamsParser.h | 69 ++++ .../RobotDescriptionServer_params.md | 1 + .../audioPlayerWrapper/AudioPlayerWrapper.cpp | 70 +--- .../audioPlayerWrapper/AudioPlayerWrapper.h | 24 +- .../AudioPlayerWrapper_ParamsParser.cpp | 167 +++++++++ .../AudioPlayerWrapper_ParamsParser.h | 81 ++++ .../AudioPlayerWrapper_params.md | 5 + .../audioPlayerWrapper/CMakeLists.txt | 3 + ...wc_yarp.cpp => AudioRecorder_nwc_yarp.cpp} | 37 +- ...er_nwc_yarp.h => AudioRecorder_nwc_yarp.h} | 14 +- .../AudioRecorder_nwc_yarp_ParamsParser.cpp | 155 ++++++++ .../AudioRecorder_nwc_yarp_ParamsParser.h | 78 ++++ .../AudioRecorder_nwc_yarp_params.md | 4 + .../audioRecorder_nwc_yarp/CMakeLists.txt | 9 +- .../AudioRecorder_nws_yarp.cpp | 64 +--- .../AudioRecorder_nws_yarp.h | 26 +- .../AudioRecorder_nws_yarp_ParamsParser.cpp | 215 +++++++++++ .../AudioRecorder_nws_yarp_ParamsParser.h | 90 +++++ .../AudioRecorder_nws_yarp_params.md | 8 + .../audioRecorder_nws_yarp/CMakeLists.txt | 3 + ...tery_nwc_yarp.cpp => Battery_nwc_yarp.cpp} | 28 +- ...{battery_nwc_yarp.h => Battery_nwc_yarp.h} | 16 +- .../Battery_nwc_yarp_ParamsParser.cpp | 139 +++++++ .../Battery_nwc_yarp_ParamsParser.h | 75 ++++ .../Battery_nwc_yarp_params.md | 3 + .../battery_nwc_yarp/CMakeLists.txt | 9 +- ...tery_nws_yarp.cpp => Battery_nws_yarp.cpp} | 38 +- ...{battery_nws_yarp.h => Battery_nws_yarp.h} | 43 +-- .../Battery_nws_yarp_ParamsParser.cpp | 169 +++++++++ .../Battery_nws_yarp_ParamsParser.h | 81 ++++ .../Battery_nws_yarp_params.md | 5 + .../battery_nws_yarp/CMakeLists.txt | 9 +- .../chatBot_nwc_yarp/CMakeLists.txt | 3 + .../chatBot_nwc_yarp/ChatBot_nwc_yarp.cpp | 21 +- .../chatBot_nwc_yarp/ChatBot_nwc_yarp.h | 11 +- .../ChatBot_nwc_yarp_ParamsParser.cpp | 123 +++++++ .../ChatBot_nwc_yarp_ParamsParser.h | 72 ++++ .../ChatBot_nwc_yarp_params.md | 2 + .../chatBot_nws_yarp/CMakeLists.txt | 3 + .../chatBot_nws_yarp/ChatBot_nws_yarp.cpp | 16 +- .../chatBot_nws_yarp/ChatBot_nws_yarp.h | 12 +- .../ChatBot_nws_yarp_ParamsParser.cpp | 119 ++++++ .../ChatBot_nws_yarp_ParamsParser.h | 72 ++++ .../ChatBot_nws_yarp_params.md | 2 + .../controlBoard_nws_yarp/CMakeLists.txt | 3 + .../ControlBoard_nws_yarp.cpp | 69 +--- .../ControlBoard_nws_yarp.h | 14 +- .../ControlBoard_nws_yarp_ParamsParser.cpp | 121 ++++++ .../ControlBoard_nws_yarp_ParamsParser.h | 72 ++++ .../ControlBoard_nws_yarp_params.md | 2 + .../frameGrabber_nwc_yarp/CMakeLists.txt | 11 +- .../FrameGrabber_nwc_yarp.cpp | 20 +- .../FrameGrabber_nwc_yarp.h | 14 +- .../FrameGrabber_nwc_yarp_ParamsParser.cpp | 155 ++++++++ .../FrameGrabber_nwc_yarp_ParamsParser.h | 78 ++++ .../FrameGrabber_nwc_yarp_params.md | 4 + .../frameGrabber_nws_yarp/CMakeLists.txt | 7 +- .../FrameGrabber_nws_yarp.cpp | 61 +-- .../FrameGrabber_nws_yarp.h | 56 +-- .../FrameGrabber_nws_yarp_ParamsParser.cpp | 151 ++++++++ .../FrameGrabber_nws_yarp_ParamsParser.h | 78 ++++ .../FrameGrabber_nws_yarp_params.md | 4 + .../localization2D_nwc_yarp/CMakeLists.txt | 3 + .../Localization2D_nwc_yarp.cpp | 26 +- .../Localization2D_nwc_yarp.h | 13 +- .../Localization2D_nwc_yarp_ParamsParser.cpp | 123 +++++++ .../Localization2D_nwc_yarp_ParamsParser.h | 72 ++++ .../Localization2D_nwc_yarp_params.md | 2 + .../localization2D_nws_yarp/CMakeLists.txt | 3 + .../Localization2D_nws_yarp.cpp | 69 +--- .../Localization2D_nws_yarp.h | 17 +- .../Localization2D_nws_yarp_ParamsParser.cpp | 177 +++++++++ .../Localization2D_nws_yarp_ParamsParser.h | 81 ++++ .../Localization2D_nws_yarp_params.md | 5 + .../map2D_nwc_yarp/CMakeLists.txt | 3 + .../map2D_nwc_yarp/Map2D_nwc_yarp.cpp | 22 +- .../map2D_nwc_yarp/Map2D_nwc_yarp.h | 16 +- .../Map2D_nwc_yarp_ParamsParser.cpp | 139 +++++++ .../Map2D_nwc_yarp_ParamsParser.h | 75 ++++ .../map2D_nwc_yarp/Map2D_nwc_yarp_params.md | 3 + .../map2D_nws_yarp/CMakeLists.txt | 3 + .../map2D_nws_yarp/Map2D_nws_yarp.cpp | 16 +- .../map2D_nws_yarp/Map2D_nws_yarp.h | 12 +- .../Map2D_nws_yarp_ParamsParser.cpp | 103 ++++++ .../Map2D_nws_yarp_ParamsParser.h | 69 ++++ .../map2D_nws_yarp/Map2D_nws_yarp_params.md | 1 + .../CMakeLists.txt | 3 + .../MobileBaseVelocityControl_nwc_yarp.cpp | 26 +- .../MobileBaseVelocityControl_nwc_yarp.h | 15 +- ...eVelocityControl_nwc_yarp_ParamsParser.cpp | 139 +++++++ ...aseVelocityControl_nwc_yarp_ParamsParser.h | 75 ++++ ...bileBaseVelocityControl_nwc_yarp_params.md | 3 + .../CMakeLists.txt | 3 + .../MobileBaseVelocityControl_nws_yarp.cpp | 13 +- .../MobileBaseVelocityControl_nws_yarp.h | 36 +- ...eVelocityControl_nws_yarp_ParamsParser.cpp | 105 ++++++ ...aseVelocityControl_nws_yarp_ParamsParser.h | 69 ++++ ...bileBaseVelocityControl_nws_yarp_params.md | 1 + .../CMakeLists.txt | 3 + .../MultipleAnalogSensorsClient.cpp | 66 +--- .../MultipleAnalogSensorsClient.h | 26 +- ...ltipleAnalogSensorsClient_ParamsParser.cpp | 171 +++++++++ ...MultipleAnalogSensorsClient_ParamsParser.h | 81 ++++ .../MultipleAnalogSensorsClient_params.md | 5 + .../CMakeLists.txt | 3 + .../MultipleAnalogSensorsServer.cpp | 28 +- .../MultipleAnalogSensorsServer.h | 14 +- ...ltipleAnalogSensorsServer_ParamsParser.cpp | 124 +++++++ ...MultipleAnalogSensorsServer_ParamsParser.h | 72 ++++ .../MultipleAnalogSensorsServer_params.md | 2 + .../navigation2D_nwc_yarp/CMakeLists.txt | 3 + .../Navigation2D_nwc_yarp.cpp | 65 +--- .../Navigation2D_nwc_yarp.h | 17 +- .../Navigation2D_nwc_yarp_ParamsParser.cpp | 159 ++++++++ .../Navigation2D_nwc_yarp_ParamsParser.h | 78 ++++ .../Navigation2D_nwc_yarp_params.md | 4 + .../navigation2D_nws_yarp/CMakeLists.txt | 11 +- ...nws_yarp.cpp => Navigation2D_nws_yarp.cpp} | 58 +-- ...n2D_nws_yarp.h => Navigation2D_nws_yarp.h} | 17 +- .../Navigation2D_nws_yarp_ParamsParser.cpp | 123 +++++++ .../Navigation2D_nws_yarp_ParamsParser.h | 72 ++++ .../Navigation2D_nws_yarp_params.md | 2 + .../odometry2D_nws_yarp/CMakeLists.txt | 3 + .../Odometry2D_nws_yarp.cpp | 28 +- .../odometry2D_nws_yarp/Odometry2D_nws_yarp.h | 53 +-- .../Odometry2D_nws_yarp_ParamsParser.cpp | 119 ++++++ .../Odometry2D_nws_yarp_ParamsParser.h | 72 ++++ .../Odometry2D_nws_yarp_params.md | 2 + .../serialPort_nwc_yarp/CMakeLists.txt | 9 +- ...t_nwc_yarp.cpp => SerialPort_nwc_yarp.cpp} | 14 +- ...lPort_nwc_yarp.h => SerialPort_nwc_yarp.h} | 6 +- .../SerialPort_nwc_yarp_ParamsParser.cpp | 123 +++++++ .../SerialPort_nwc_yarp_ParamsParser.h | 72 ++++ .../SerialPort_nwc_yarp_params.md | 2 + .../serialPort_nws_yarp/CMakeLists.txt | 9 +- ...t_nws_yarp.cpp => SerialPort_nws_yarp.cpp} | 10 +- ...lPort_nws_yarp.h => SerialPort_nws_yarp.h} | 7 +- .../SerialPort_nws_yarp_ParamsParser.cpp | 137 +++++++ .../SerialPort_nws_yarp_ParamsParser.h | 75 ++++ .../SerialPort_nws_yarp_params.md | 3 + .../speechSynthesizer_nwc_yarp/CMakeLists.txt | 3 + .../SpeechSynthesizer_nwc_yarp.cpp | 23 +- .../SpeechSynthesizer_nwc_yarp.h | 14 +- ...peechSynthesizer_nwc_yarp_ParamsParser.cpp | 123 +++++++ .../SpeechSynthesizer_nwc_yarp_ParamsParser.h | 72 ++++ .../SpeechSynthesizer_nwc_yarp_params.md | 2 + .../speechSynthesizer_nws_yarp/CMakeLists.txt | 9 +- ...arp.cpp => SpeechSynthesizer_nws_yarp.cpp} | 14 +- ...ws_yarp.h => SpeechSynthesizer_nws_yarp.h} | 9 +- ...peechSynthesizer_nws_yarp_ParamsParser.cpp | 103 ++++++ .../SpeechSynthesizer_nws_yarp_ParamsParser.h | 69 ++++ .../SpeechSynthesizer_nws_yarp_params.md | 1 + .../CMakeLists.txt | 3 + .../SpeechTranscription_nwc_yarp.cpp | 23 +- .../SpeechTranscription_nwc_yarp.h | 13 +- ...echTranscription_nwc_yarp_ParamsParser.cpp | 123 +++++++ ...peechTranscription_nwc_yarp_ParamsParser.h | 72 ++++ .../SpeechTranscription_nwc_yarp_params.md | 2 + .../CMakeLists.txt | 9 +- ...p.cpp => SpeechTranscription_nws_yarp.cpp} | 14 +- ..._yarp.h => SpeechTranscription_nws_yarp.h} | 10 +- ...echTranscription_nws_yarp_ParamsParser.cpp | 103 ++++++ ...peechTranscription_nws_yarp_ParamsParser.h | 69 ++++ .../SpeechTranscription_nws_yarp_params.md | 1 + 232 files changed, 9147 insertions(+), 1871 deletions(-) create mode 100644 src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.h create mode 100644 src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_params.md create mode 100644 src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.h create mode 100644 src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_params.md create mode 100644 src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.h create mode 100644 src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_params.md create mode 100644 src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.h create mode 100644 src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_params.md create mode 100644 src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.h create mode 100644 src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_params.md create mode 100644 src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.h create mode 100644 src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_params.md create mode 100644 src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.h create mode 100644 src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_params.md rename src/devices/networkWrappers/audioRecorder_nwc_yarp/{audioRecorder_nwc_yarp.cpp => AudioRecorder_nwc_yarp.cpp} (82%) rename src/devices/networkWrappers/audioRecorder_nwc_yarp/{audioRecorder_nwc_yarp.h => AudioRecorder_nwc_yarp.h} (68%) create mode 100644 src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_params.md rename src/devices/networkWrappers/battery_nwc_yarp/{battery_nwc_yarp.cpp => Battery_nwc_yarp.cpp} (87%) rename src/devices/networkWrappers/battery_nwc_yarp/{battery_nwc_yarp.h => Battery_nwc_yarp.h} (75%) create mode 100644 src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_params.md rename src/devices/networkWrappers/battery_nws_yarp/{battery_nws_yarp.cpp => Battery_nws_yarp.cpp} (88%) rename src/devices/networkWrappers/battery_nws_yarp/{battery_nws_yarp.h => Battery_nws_yarp.h} (54%) create mode 100644 src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_params.md create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.h create mode 100644 src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_params.md create mode 100644 src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.h create mode 100644 src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_params.md create mode 100644 src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_params.md rename src/devices/networkWrappers/navigation2D_nws_yarp/{navigation2D_nws_yarp.cpp => Navigation2D_nws_yarp.cpp} (72%) rename src/devices/networkWrappers/navigation2D_nws_yarp/{navigation2D_nws_yarp.h => Navigation2D_nws_yarp.h} (69%) create mode 100644 src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_params.md rename src/devices/networkWrappers/serialPort_nwc_yarp/{serialPort_nwc_yarp.cpp => SerialPort_nwc_yarp.cpp} (85%) rename src/devices/networkWrappers/serialPort_nwc_yarp/{serialPort_nwc_yarp.h => SerialPort_nwc_yarp.h} (89%) create mode 100644 src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_params.md rename src/devices/networkWrappers/serialPort_nws_yarp/{serialPort_nws_yarp.cpp => SerialPort_nws_yarp.cpp} (95%) rename src/devices/networkWrappers/serialPort_nws_yarp/{serialPort_nws_yarp.h => SerialPort_nws_yarp.h} (93%) create mode 100644 src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_params.md rename src/devices/networkWrappers/speechSynthesizer_nws_yarp/{speechSynthesizer_nws_yarp.cpp => SpeechSynthesizer_nws_yarp.cpp} (94%) rename src/devices/networkWrappers/speechSynthesizer_nws_yarp/{speechSynthesizer_nws_yarp.h => SpeechSynthesizer_nws_yarp.h} (84%) create mode 100644 src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_params.md create mode 100644 src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_params.md rename src/devices/networkWrappers/speechTranscription_nws_yarp/{speechTranscription_nws_yarp.cpp => SpeechTranscription_nws_yarp.cpp} (92%) rename src/devices/networkWrappers/speechTranscription_nws_yarp/{speechTranscription_nws_yarp.h => SpeechTranscription_nws_yarp.h} (83%) create mode 100644 src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.cpp create mode 100644 src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.h create mode 100644 src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_params.md diff --git a/src/devices/networkWrappers/JoypadControlClient/CMakeLists.txt b/src/devices/networkWrappers/JoypadControlClient/CMakeLists.txt index cdd46894729..da983f9c6e1 100644 --- a/src/devices/networkWrappers/JoypadControlClient/CMakeLists.txt +++ b/src/devices/networkWrappers/JoypadControlClient/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(JoypadControlClient EXTRA_CONFIG WRAPPER=JoypadControlClient DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_JoypadControlClient) @@ -17,6 +18,8 @@ if(NOT SKIP_JoypadControlClient) PRIVATE JoypadControlClient.cpp JoypadControlClient.h + JoypadControlClient_ParamsParser.cpp + JoypadControlClient_ParamsParser.h ) target_sources(yarp_JoypadControlClient PRIVATE $) diff --git a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.cpp b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.cpp index 44be2072e2a..75bed1342e3 100644 --- a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.cpp +++ b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.cpp @@ -94,36 +94,15 @@ bool JoypadControlClient::getJoypadInfo() bool JoypadControlClient::open(yarp::os::Searchable& config) { - if(config.check("help")) - { - yCInfo(JOYPADCONTROLCLIENT) << "Parameter:\n\n" << - "local - prefix of the local port\n" << - "remote - prefix of the port provided to and opened by JoypadControlServer\n"; - } - if(!config.check("local")) - { - yCError(JOYPADCONTROLCLIENT) << "Unable to 'local' parameter. check configuration file"; - return false; - } - - m_local = config.find("local").asString(); + if (!parseParams(config)) { return false; } if(!m_rpcPort.open(m_local + "/rpc:o")) { yCError(JOYPADCONTROLCLIENT) << "Unable to open rpc port."; return false; } - yCInfo(JOYPADCONTROLCLIENT) << "rpc port opened. starting the handshake"; - if(!config.check("remote")) - { - yCError(JOYPADCONTROLCLIENT) << "Unable to find the 'remote' parameter. check configuration file"; - return false; - } - - m_remote = config.find("remote").asString(); - if(!yarp::os::NetworkBase::connect(m_local + "/rpc:o", m_remote + "/rpc:i")) { yCError(JOYPADCONTROLCLIENT) << "Handshake failed. unable to connect to remote port" << m_remote + "/rpc:i"; diff --git a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.h b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.h index a7a5d1b29a6..8797e2dad0e 100644 --- a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.h +++ b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient.h @@ -8,6 +8,7 @@ #include #include #include +#include "JoypadControlClient_ParamsParser.h" #define DEFAULT_THREAD_PERIOD 10 @@ -31,15 +32,12 @@ class JoypadControlWatchdog : * * \section JoypadControlClient Description of input parameters * -* Parameters accepted in the config argument of the open method: -* | Parameter name | Type | Units | Default Value | Required | Description | Notes | -* |:-----------------:|:------:|:-----:|:-------------:|:---------:|:--------------------------------------------:|:-----:| -* | local | string | | | yes | name for the local port to open | | -* | remote | string | | | yes | name of the remote server port to connect to | | -**/ +* Parameters required by this device are shown in class: JoypadControlClient_ParamsParser +*/ class JoypadControlClient : public yarp::dev::IJoypadEventDriven, - public yarp::dev::DeviceDriver + public yarp::dev::DeviceDriver, + public JoypadControlClient_ParamsParser { private: //---------------utils @@ -58,8 +56,6 @@ class JoypadControlClient : JOYPORT m_stickPort; std::vector m_stickDof; bool m_rpc_only; - std::string m_local; - std::string m_remote; JoypadControlWatchdog watchdog; std::vector m_ports; diff --git a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.cpp b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.cpp new file mode 100644 index 00000000000..b8f234e1082 --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "JoypadControlClient_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(JoypadControlClientParamsCOMPONENT, "yarp.device.JoypadControlClient") +} + + +JoypadControlClient_ParamsParser::JoypadControlClient_ParamsParser() +{ +} + + +std::vector JoypadControlClient_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool JoypadControlClient_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(JoypadControlClientParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(JoypadControlClientParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(JoypadControlClientParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(JoypadControlClientParamsCOMPONENT) << "Description of the parameter: Full port name opened by the client device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(JoypadControlClientParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(JoypadControlClientParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(JoypadControlClientParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the client device connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(JoypadControlClientParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(JoypadControlClientParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string JoypadControlClient_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: JoypadControlClient\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the client device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the client device connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device JoypadControlClient --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device JoypadControlClient --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.h b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.h new file mode 100644 index 00000000000..9f7782d08ad --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef JOYPADCONTROLCLIENT_PARAMSPARSER_H +#define JOYPADCONTROLCLIENT_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class JoypadControlClient. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:---------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the client device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the client device connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device JoypadControlClient --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device JoypadControlClient --local --remote +* \endcode +* +*/ + +class JoypadControlClient_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + JoypadControlClient_ParamsParser(); + ~JoypadControlClient_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"JoypadControlClient"}; + const std::string m_device_name = {"JoypadControlClient"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_params.md b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_params.md new file mode 100644 index 00000000000..1233640cc28 --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlClient/JoypadControlClient_params.md @@ -0,0 +1,2 @@ + * | | local | string | - | - | Yes | Full port name opened by the client device. | | + * | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the client device connects to. | | diff --git a/src/devices/networkWrappers/JoypadControlServer/CMakeLists.txt b/src/devices/networkWrappers/JoypadControlServer/CMakeLists.txt index 02f35ba05fc..5b11503438e 100644 --- a/src/devices/networkWrappers/JoypadControlServer/CMakeLists.txt +++ b/src/devices/networkWrappers/JoypadControlServer/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(JoypadControlServer EXTRA_CONFIG WRAPPER=JoypadControlServer DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_JoypadControlServer) @@ -17,6 +18,8 @@ if(NOT SKIP_JoypadControlServer) PRIVATE JoypadControlServer.cpp JoypadControlServer.h + JoypadControlServer_ParamsParser.cpp + JoypadControlServer_ParamsParser.h ) target_sources(yarp_JoypadControlServer PRIVATE $) diff --git a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.cpp b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.cpp index dca6f94071c..8ecd82cb30b 100644 --- a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.cpp +++ b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.cpp @@ -221,78 +221,31 @@ bool JoypadCtrlParser::respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& re } -JoypadControlServer::JoypadControlServer() : PeriodicThread(DEFAULT_THREAD_PERIOD), - m_period(DEFAULT_THREAD_PERIOD), - m_IJoypad(nullptr), - m_separatePorts(false), - m_profile(false), - m_coordsMode(yarp::dev::IJoypadController::JoypadCtrl_coordinateMode::JypCtrlcoord_POLAR) +JoypadControlServer::JoypadControlServer() : PeriodicThread(DEFAULT_THREAD_PERIOD) { - } JoypadControlServer::~JoypadControlServer() { - m_IJoypad = nullptr; } -bool JoypadControlServer::open(yarp::os::Searchable& params) +bool JoypadControlServer::open(yarp::os::Searchable& config) { - if(params.check("help")) - { - yCInfo(JOYPADCONTROLSERVER) - << "parameters:\n\n" - << "period - refresh period of the broadcasted values in ms.. default" << DEFAULT_THREAD_PERIOD * 1000 << "\n" - << "use_separate_ports - set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port\n" - << "name - Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad\n" - << "subdevice - name of the subdevice to open\n" - << "profile - print the joypad data for debugging purpose"; - return false; - } - std::string rootName; - if (!params.check("period", "refresh period of the broadcasted values in ms")) - { - yCInfo(JOYPADCONTROLSERVER) << "Using default 'period' parameter of" << DEFAULT_THREAD_PERIOD << "s"; - } - else - { - m_period = params.find("period").asInt32() / 1000.0; - } - - m_profile = params.check("profile"); - - if(params.check("use_separate_ports")) - { - m_separatePorts = params.find("use_separate_ports").asBool(); - if(!m_separatePorts) - { - yCError(JOYPADCONTROLSERVER) << "Single port mode not supported at the moment"; - return false; - } - } - else - { - yCError(JOYPADCONTROLSERVER) << "Missing use_separate_ports in configuration"; - return false; - } - m_coordsMode = yarp::dev::IJoypadController::JypCtrlcoord_CARTESIAN; - rootName = params.check("name",Value("/"), "starting '/' if needed.").asString(); + if (!parseParams(config)) { return false; } - if (!params.check("name", "Prefix name of the ports opened by the JoypadControlServer.")) + if(m_use_separate_ports == false) { - yCError(JOYPADCONTROLSERVER) << "Missing 'name' parameter. Check you configuration file; it must be like:"; - yCError(JOYPADCONTROLSERVER) << " name: Prefix name of the ports opened by the JoypadControlServer, e.g. /robotName/joypad"; + yCError(JOYPADCONTROLSERVER) << "Single port mode not supported at the moment"; return false; } - rootName = params.find("name").asString(); - m_rpcPortName = rootName + "/rpc:i"; - m_portButtons.name = rootName + "/buttons:o"; - m_portAxis.name = rootName + "/axis:o"; - m_portStick.name = rootName + "/stick:o"; - m_portTouch.name = rootName + "/touch:o"; - m_portTrackball.name = rootName + "/trackball:o"; - m_portHats.name = rootName + "/hat:o"; + m_rpcPortName = m_name + "/rpc:i"; + m_portButtons.name = m_name + "/buttons:o"; + m_portAxis.name = m_name + "/axis:o"; + m_portStick.name = m_name + "/stick:o"; + m_portTouch.name = m_name + "/touch:o"; + m_portTrackball.name = m_name + "/trackball:o"; + m_portHats.name = m_name + "/hat:o"; yCInfo(JOYPADCONTROLSERVER) << "Running, waiting for attach..."; return true; @@ -462,7 +415,7 @@ bool JoypadControlServer::openPorts() // return false; // } // return true; - if(m_separatePorts) + if(m_use_separate_ports) { using countGet = bool (IJoypadController::*)(unsigned int&); @@ -596,7 +549,7 @@ void JoypadControlServer::profile() void JoypadControlServer::run() { - if(m_separatePorts) + if(m_use_separate_ports) { if (m_portButtons.valid) { diff --git a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.h b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.h index 2259132d673..b78fe1b7297 100644 --- a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.h +++ b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer.h @@ -16,7 +16,7 @@ #include #include #include - +#include "JoypadControlServer_ParamsParser.h" class JoypadCtrlParser : public yarp::dev::DeviceResponder @@ -37,12 +37,17 @@ class JoypadCtrlParser : /** * @ingroup dev_impl_wrapper * - * `JoypadControlServer`: Documentation to be added + * `JoypadControlServer`: joypad input network wrapper on server side + * + * \section JoypadControlServer Description of input parameters + * + * Parameters required by this device are shown in class: JoypadControlServer_ParamsParser */ class JoypadControlServer : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PeriodicThread + public yarp::os::PeriodicThread, + public JoypadControlServer_ParamsParser { typedef yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordsMode; typedef yarp::sig::Vector Vector; @@ -51,14 +56,10 @@ class JoypadControlServer : template using JoyPort = JoypadControl::JoyPort; - double m_period; JoypadCtrlParser m_parser; - yarp::dev::IJoypadController* m_IJoypad; + yarp::dev::IJoypadController* m_IJoypad = nullptr; yarp::os::Port m_rpcPort; - bool m_separatePorts; - bool m_profile; std::string m_rpcPortName; - std::string m_name; JoyPort m_portAxis; JoyPort m_portStick; JoyPort m_portTouch; @@ -66,7 +67,7 @@ class JoypadControlServer : JoyPort m_portHats; JoyPort m_portTrackball; yarp::os::BufferedPort m_godPort; //TODO: single port purpose - coordsMode m_coordsMode; + coordsMode m_coordsMode = yarp::dev::IJoypadController::JypCtrlcoord_CARTESIAN; bool openAndAttachSubDevice(yarp::os::Searchable& prop); @@ -82,7 +83,6 @@ class JoypadControlServer : ~JoypadControlServer() override; bool open(yarp::os::Searchable& params) override; - bool fromConfig(yarp::os::Searchable& params); bool close() override; bool attach(yarp::dev::PolyDriver* poly) override; bool detach() override; diff --git a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.cpp b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.cpp new file mode 100644 index 00000000000..9290c14b84f --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.cpp @@ -0,0 +1,153 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:50 2024 + + +#include "JoypadControlServer_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(JoypadControlServerParamsCOMPONENT, "yarp.device.JoypadControlServer") +} + + +JoypadControlServer_ParamsParser::JoypadControlServer_ParamsParser() +{ +} + + +std::vector JoypadControlServer_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + params.push_back("use_separate_ports"); + params.push_back("profile"); + return params; +} + + +bool JoypadControlServer_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(JoypadControlServerParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(JoypadControlServerParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(JoypadControlServerParamsCOMPONENT) << "Description of the parameter: Prefix name of the ports opened by the JoypadControlServer"; + return false; + } + prop_check.unput("name"); + } + + //Parser of parameter use_separate_ports + { + if (config.check("use_separate_ports")) + { + m_use_separate_ports = config.find("use_separate_ports").asBool(); + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'use_separate_ports' using value:" << m_use_separate_ports; + } + else + { + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'use_separate_ports' using DEFAULT value:" << m_use_separate_ports; + } + prop_check.unput("use_separate_ports"); + } + + //Parser of parameter profile + { + if (config.check("profile")) + { + m_profile = config.find("profile").asBool(); + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'profile' using value:" << m_profile; + } + else + { + yCInfo(JoypadControlServerParamsCOMPONENT) << "Parameter 'profile' using DEFAULT value:" << m_profile; + } + prop_check.unput("profile"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(JoypadControlServerParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(JoypadControlServerParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string JoypadControlServer_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: JoypadControlServer\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': Refresh period (in s) of the broadcasted values through yarp ports\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the JoypadControlServer\n"); + doc = doc + std::string("'use_separate_ports': set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port\n"); + doc = doc + std::string("'profile': print the joypad data for debugging purpose\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device JoypadControlServer --period 0.01 --name /robotName/joypad --use_separate_ports true --profile false\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device JoypadControlServer --name /robotName/joypad\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.h b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.h new file mode 100644 index 00000000000..e0e6b7ff67d --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_ParamsParser.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:50 2024 + + +#ifndef JOYPADCONTROLSERVER_PARAMSPARSER_H +#define JOYPADCONTROLSERVER_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class JoypadControlServer. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:------------------:|:------:|:-----:|:-----------------:|:--------:|:----------------------------------------------------------------------------------------------------------:|:-----:| +* | - | period | double | s | 0.01 | 0 | Refresh period (in s) of the broadcasted values through yarp ports | - | +* | - | name | string | - | /robotName/joypad | 1 | Prefix name of the ports opened by the JoypadControlServer | - | +* | - | use_separate_ports | bool | - | true | 0 | set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port | - | +* | - | profile | bool | - | false | 0 | print the joypad data for debugging purpose | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device JoypadControlServer --period 0.01 --name /robotName/joypad --use_separate_ports true --profile false +* \endcode +* +* \code{.unparsed} +* yarpdev --device JoypadControlServer --name /robotName/joypad +* \endcode +* +*/ + +class JoypadControlServer_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + JoypadControlServer_ParamsParser(); + ~JoypadControlServer_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"JoypadControlServer"}; + const std::string m_device_name = {"JoypadControlServer"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.01"}; + const std::string m_name_defaultValue = {"/robotName/joypad"}; + const std::string m_use_separate_ports_defaultValue = {"true"}; + const std::string m_profile_defaultValue = {"false"}; + + double m_period = {0.01}; + std::string m_name = {"/robotName/joypad"}; + bool m_use_separate_ports = {true}; + bool m_profile = {false}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_params.md b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_params.md new file mode 100644 index 00000000000..705cc42ca6c --- /dev/null +++ b/src/devices/networkWrappers/JoypadControlServer/JoypadControlServer_params.md @@ -0,0 +1,4 @@ + * | | period | double | s | 0.01 | No | Refresh period (in s) of the broadcasted values through yarp ports | - | + * | | name | string | - | /robotName/joypad | Yes | Prefix name of the ports opened by the JoypadControlServer | - | + * | | use_separate_ports | bool | - | true | No | set it to 1 to use separate ports (buttons, axes, trackballs, hats) and 0 to stream all in one single port | - | + * | | profile | bool | - | false | No | print the joypad data for debugging purpose | - | diff --git a/src/devices/networkWrappers/JoypadControlServer/tests/joypadControlServer_test.cpp b/src/devices/networkWrappers/JoypadControlServer/tests/joypadControlServer_test.cpp index 0c7935e662a..dcc17ad0132 100644 --- a/src/devices/networkWrappers/JoypadControlServer/tests/joypadControlServer_test.cpp +++ b/src/devices/networkWrappers/JoypadControlServer/tests/joypadControlServer_test.cpp @@ -33,7 +33,6 @@ TEST_CASE("dev::joypadControlServerTest", "[yarp::dev]") Property p_nws; p_nws.put("device", "JoypadControlServer"); - p_nws.put("use_separate_ports", true); p_nws.put("name", "/joyServer"); REQUIRE(dd_nws.open(p_nws)); diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/LLM_nwc_yarp/CMakeLists.txt index 2ae496b578d..c7135a7e570 100644 --- a/src/devices/networkWrappers/LLM_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/LLM_nwc_yarp/CMakeLists.txt @@ -6,6 +6,7 @@ yarp_prepare_plugin(LLM_nwc_yarp TYPE LLM_nwc_yarp INCLUDE LLM_nwc_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_LLM_nwc_yarp) @@ -15,6 +16,8 @@ if(NOT SKIP_LLM_nwc_yarp) PRIVATE LLM_nwc_yarp.cpp LLM_nwc_yarp.h + LLM_nwc_yarp_ParamsParser.cpp + LLM_nwc_yarp_ParamsParser.h ) target_sources(LLM_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.cpp b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.cpp index 07b3e0aae6a..2971637ecec 100644 --- a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.cpp +++ b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.cpp @@ -15,33 +15,20 @@ namespace bool LLM_nwc_yarp::open(yarp::os::Searchable &config) { - std::string local_rpc = config.find("local").asString(); - std::string remote_rpc = config.find("remote").asString(); + if (!parseParams(config)) { return false; } - if (local_rpc == "") - { - yCError(LLM_NWC_YARP, "open() error you have to provide a valid 'local' param"); - return false; - } - - if (remote_rpc == "") - { - yCError(LLM_NWC_YARP, "open() error you have to provide valid 'remote' param"); - return false; - } - - if (!m_rpc_port_to_LLM_server.open(local_rpc)) + if (!m_rpc_port_to_LLM_server.open(m_local)) { yCError(LLM_NWC_YARP, "Cannot open rpc port, check network"); } bool ok = false; - ok = yarp::os::Network::connect(local_rpc, remote_rpc); + ok = yarp::os::Network::connect(m_local, m_remote); if (!ok) { - yCError(LLM_NWC_YARP, "open() error could not connect to %s", remote_rpc.c_str()); + yCError(LLM_NWC_YARP, "open() error could not connect to %s", m_remote.c_str()); return false; } diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.h b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.h index c7216957ff7..35398cbdc87 100644 --- a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.h +++ b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.h @@ -8,20 +8,18 @@ #include #include #include +#include "LLM_nwc_yarp_ParamsParser.h" /** - * @ingroup dev_impl_network_clients + * @ingroup dev_impl_nwc_yarp * * \brief `LLM_nwc_yarp`: The client side of any ILLM capable device. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the nwc device. | | - * | remote | - | string | - | - | Yes | Full port name of the port opened on the server side, to which the nwc connects to. | | + * Parameters required by this device are shown in class: LLM_nwc_yarp_ParamsParser */ class LLM_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::ILLM + public yarp::dev::ILLM, + public LLM_nwc_yarp_ParamsParser { protected: // thrift interface diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..1a19aefc457 --- /dev/null +++ b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "LLM_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(LLM_nwc_yarpParamsCOMPONENT, "yarp.device.LLM_nwc_yarp") +} + + +LLM_nwc_yarp_ParamsParser::LLM_nwc_yarp_ParamsParser() +{ +} + + +std::vector LLM_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool LLM_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(LLM_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(LLM_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(LLM_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(LLM_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the nwc device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(LLM_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(LLM_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(LLM_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the nwc connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(LLM_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(LLM_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string LLM_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: LLM_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the nwc device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the nwc connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device LLM_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device LLM_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..7e19ef67316 --- /dev/null +++ b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef LLM_NWC_YARP_PARAMSPARSER_H +#define LLM_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class LLM_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the nwc device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the nwc connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device LLM_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device LLM_nwc_yarp --local --remote +* \endcode +* +*/ + +class LLM_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + LLM_nwc_yarp_ParamsParser(); + ~LLM_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"LLM_nwc_yarp"}; + const std::string m_device_name = {"LLM_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_params.md b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_params.md new file mode 100644 index 00000000000..0517fb4ce7f --- /dev/null +++ b/src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp_params.md @@ -0,0 +1,2 @@ + * | - | local | string | - | - | Yes | Full port name opened by the nwc device. | | + * | - | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the nwc connects to. | | diff --git a/src/devices/networkWrappers/LLM_nwc_yarp/tests/LLM_nwc_yarp_test.cpp b/src/devices/networkWrappers/LLM_nwc_yarp/tests/LLM_nwc_yarp_test.cpp index d88f47fe2ff..ddbbd33c599 100644 --- a/src/devices/networkWrappers/LLM_nwc_yarp/tests/LLM_nwc_yarp_test.cpp +++ b/src/devices/networkWrappers/LLM_nwc_yarp/tests/LLM_nwc_yarp_test.cpp @@ -15,7 +15,7 @@ using namespace yarp::dev; using namespace yarp::os; -TEST_CASE("dev::LLM_nwc", "[yarp::dev]") +TEST_CASE("dev::LLM_nwc_yarp", "[yarp::dev]") { YARP_REQUIRE_PLUGIN("fakeLLMDevice", "device"); YARP_REQUIRE_PLUGIN("LLM_nws_yarp", "device"); @@ -34,7 +34,7 @@ TEST_CASE("dev::LLM_nwc", "[yarp::dev]") { Property pnws_cfg; pnws_cfg.put("device", "LLM_nws_yarp"); - pnws_cfg.put("name", "/LLM_nws/rpc"); + pnws_cfg.put("name", "/LLM_nws"); REQUIRE(ddnws.open(pnws_cfg)); Property pdev_cfg; @@ -49,7 +49,7 @@ TEST_CASE("dev::LLM_nwc", "[yarp::dev]") Property pnwc_cfg; pnwc_cfg.put("device", "LLM_nwc_yarp"); pnwc_cfg.put("local", "/LLM_nwc/rpc"); - pnwc_cfg.put("remote", "/LLM_nws/rpc"); + pnwc_cfg.put("remote", "/LLM_nws/rpc:i"); REQUIRE(ddnwc.open(pnwc_cfg)); REQUIRE(ddnwc.view(illm)); } diff --git a/src/devices/networkWrappers/LLM_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/LLM_nws_yarp/CMakeLists.txt index 180a94d8456..f0733e8bb89 100644 --- a/src/devices/networkWrappers/LLM_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/LLM_nws_yarp/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(LLM_nws_yarp EXTRA_CONFIG WRAPPER=LLM_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_LLM_nws_yarp) @@ -19,6 +20,8 @@ if(NOT SKIP_LLM_nws_yarp) LLM_nws_yarp.cpp ILLMServerImpl.cpp ILLMServerImpl.h + LLM_nws_yarp_ParamsParser.h + LLM_nws_yarp_ParamsParser.cpp ) target_sources(yarp_LLM_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.cpp b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.cpp index ab88c5ebea4..d5eb761ec67 100644 --- a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.cpp +++ b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.cpp @@ -26,50 +26,25 @@ bool LLM_nws_yarp::attach(yarp::dev::PolyDriver* driver) return false; } - m_RPC.setInterface(m_iLlm, m_streaming_port_name); + std::string streaming_name = m_name + "/conv:o"; + m_RPC.setInterface(m_iLlm, streaming_name); yCDebug(LLM_NWS_YARP) << "Attachment successful"; return true; } -bool LLM_nws_yarp::open(yarp::os::Searchable& prop) +bool LLM_nws_yarp::open(yarp::os::Searchable& config) { - std::string rpc_portname; + if (!parseParams(config)) { return false; } - if (!prop.check("name")) + std::string rpc_name = m_name + "/rpc:i"; + if (!m_RpcPort.open(rpc_name)) { - yCError(LLM_NWS_YARP) << "Missing 'name' parameter. Using something like: /LLM_nws/rpc"; + yCError(LLM_NWS_YARP) << "Unable to open port:" << m_name; return false; } - else - { - rpc_portname = prop.find("name").asString(); - if (rpc_portname.c_str()[0] != '/') - { - yCError(LLM_NWS_YARP) << "Missing '/' in name parameter"; - return false; - } - yCInfo(LLM_NWS_YARP) << "Using local name:" << rpc_portname; - } - - if (!m_RpcPort.open(rpc_portname)) - { - yCError(LLM_NWS_YARP) << "Unable to open port:" << rpc_portname; - return false; - } - - if (prop.check("streaming_name")) - { - m_streaming_port_name = prop.find("streaming_name").asString(); - if (m_streaming_port_name.c_str()[0] != '/') - { - yCError(LLM_NWS_YARP) << "Missing '/' in name parameter"; - return false; - } - } - yCInfo(LLM_NWS_YARP) << "Using streaming port name " << m_streaming_port_name; m_RpcPort.setReader(*this); yCDebug(LLM_NWS_YARP) << "Waiting to be attached"; diff --git a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.h b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.h index 1e74c6f3edd..1d726232d9c 100644 --- a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.h +++ b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp.h @@ -11,6 +11,7 @@ #include #include "ILLMServerImpl.h" +#include "LLM_nws_yarp_ParamsParser.h" /** * @ingroup dev_impl_nws_yarp @@ -19,19 +20,14 @@ * * \brief `LLM_nws_yarp`: A server which can be wrap multiple algorithms and devices to provide LLM services. * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:------:|:------------------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| -* | name | - | string | - | - | Yes | Full name of the rpc port opened by device, e.g. /LLM_nws/rpc | | +* Parameters required by this device are shown in class: LLM_nws_yarp_ParamsParser +* */ class LLM_nws_yarp : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public LLM_nws_yarp_ParamsParser { - -private: - std::string m_streaming_port_name = "/llm/conv:o"; - protected: ILLMRPCd m_RPC; yarp::os::RpcServer m_RpcPort; diff --git a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..6ca0fd82e06 --- /dev/null +++ b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.cpp @@ -0,0 +1,105 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "LLM_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(LLM_nws_yarpParamsCOMPONENT, "yarp.device.LLM_nws_yarp") +} + + +LLM_nws_yarp_ParamsParser::LLM_nws_yarp_ParamsParser() +{ +} + + +std::vector LLM_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + return params; +} + + +bool LLM_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(LLM_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(LLM_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(LLM_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(LLM_nws_yarpParamsCOMPONENT) << "Description of the parameter: Prefix of the ports (rpc and streaming) opened by device"; + return false; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(LLM_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(LLM_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string LLM_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: LLM_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': Prefix of the ports (rpc and streaming) opened by device\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device LLM_nws_yarp --name /LLM_nws\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device LLM_nws_yarp --name /LLM_nws\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..0ab4a37ea0e --- /dev/null +++ b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef LLM_NWS_YARP_PARAMSPARSER_H +#define LLM_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class LLM_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:--------------------------------------------------------:|:--------------------------------------------------:| +* | - | name | string | - | /LLM_nws | 1 | Prefix of the ports (rpc and streaming) opened by device | Two ports will be opened: xxx/rpc:i and xxx/conv:o | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device LLM_nws_yarp --name /LLM_nws +* \endcode +* +* \code{.unparsed} +* yarpdev --device LLM_nws_yarp --name /LLM_nws +* \endcode +* +*/ + +class LLM_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + LLM_nws_yarp_ParamsParser(); + ~LLM_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"LLM_nws_yarp"}; + const std::string m_device_name = {"LLM_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/LLM_nws"}; + + std::string m_name = {"/LLM_nws"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_params.md b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_params.md new file mode 100644 index 00000000000..38813f7d115 --- /dev/null +++ b/src/devices/networkWrappers/LLM_nws_yarp/LLM_nws_yarp_params.md @@ -0,0 +1 @@ +| - | name | string | - | /LLM_nws | Yes | Prefix of the ports (rpc and streaming) opened by device | Two ports will be opened: xxx/rpc:i and xxx/conv:o | diff --git a/src/devices/networkWrappers/LLM_nws_yarp/tests/LLM_nws_yarp_test.cpp b/src/devices/networkWrappers/LLM_nws_yarp/tests/LLM_nws_yarp_test.cpp index a35be08c076..cbd750982a4 100644 --- a/src/devices/networkWrappers/LLM_nws_yarp/tests/LLM_nws_yarp_test.cpp +++ b/src/devices/networkWrappers/LLM_nws_yarp/tests/LLM_nws_yarp_test.cpp @@ -29,7 +29,7 @@ TEST_CASE("dev::llm_nws_yarp", "[yarp::dev]") { Property p_cfg; p_cfg.put("device", "LLM_nws_yarp"); - p_cfg.put("name", "/LLM_nws/rpc"); + p_cfg.put("name", "/LLM_nws"); REQUIRE(dd.open(p_cfg)); } @@ -50,7 +50,7 @@ TEST_CASE("dev::llm_nws_yarp", "[yarp::dev]") { Property pnws_cfg; pnws_cfg.put("device", "LLM_nws_yarp"); - pnws_cfg.put("name", "/LLM_nws/rpc"); + pnws_cfg.put("name", "/LLM_nws"); REQUIRE(ddnws.open(pnws_cfg)); Property pdev_cfg; diff --git a/src/devices/networkWrappers/RGBDSensorClient/CMakeLists.txt b/src/devices/networkWrappers/RGBDSensorClient/CMakeLists.txt index a25c71d5013..41dafc6547f 100644 --- a/src/devices/networkWrappers/RGBDSensorClient/CMakeLists.txt +++ b/src/devices/networkWrappers/RGBDSensorClient/CMakeLists.txt @@ -6,6 +6,7 @@ yarp_prepare_plugin(RGBDSensorClient TYPE RGBDSensorClient INCLUDE RGBDSensorClient.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_RGBDSensorClient) @@ -17,6 +18,8 @@ if(NOT SKIP_RGBDSensorClient) RGBDSensorClient.h RGBDSensorClient_StreamingMsgParser.cpp RGBDSensorClient_StreamingMsgParser.h + RGBDSensorClient_ParamsParser.cpp + RGBDSensorClient_ParamsParser.h ) target_sources(yarp_RGBDSensorClient PRIVATE $) diff --git a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.cpp b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.cpp index 04970328a8b..0b852e1f53a 100644 --- a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.cpp +++ b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.cpp @@ -38,156 +38,48 @@ RGBDSensorClient::~RGBDSensorClient() bool RGBDSensorClient::open(yarp::os::Searchable& config) { - if(verbose >= 5) { - yCTrace(RGBDSENSORCLIENT) << "\n Paramerters are: \n" << config.toString(); - } - - if(!fromConfig(config)) - { - yCError(RGBDSENSORCLIENT) << "Failed to open, check previous log for error messages."; - return false; - } - - sensorId= "RGBDSensorClient for " + local_depthFrame_StreamingPort_name; - - if(!initialize_YARP(config) ) - { - yCError(RGBDSENSORCLIENT) << sensorId << "\n\t* Error initializing YARP ports *"; - return false; - } - - return true; -} - - -bool RGBDSensorClient::fromConfig(yarp::os::Searchable &config) -{ - // Parse LOCAL port names - // TBD: check if user types '...' as port name, how to create RPC port names - if (!config.check("localImagePort", "full name of the port for streaming color image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'localImagePort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " localImagePort: Full name of the local port to open, e.g. /myApp/image_camera"; - return false; - } - - local_colorFrame_StreamingPort_name = config.find("localImagePort").asString(); - - if (!config.check("localDepthPort", "full name of the port for streaming depth image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'localDepthPort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " localDepthPort: Full name of the local port to open, e.g. /myApp/depth_camera"; - return false; - } - - local_depthFrame_StreamingPort_name = config.find("localDepthPort").asString(); - - // Parse REMOTE port names - if (!config.check("remoteImagePort", "full name of the port for streaming color image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'remoteImagePort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " remoteImagePort: Full name of the port to read color images from, e.g. /robotName/image_camera"; - return false; - } - - remote_colorFrame_StreamingPort_name = config.find("remoteImagePort").asString(); - - if (!config.check("remoteDepthPort", "full name of the port for streaming depth image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'remoteDepthPort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " remoteDepthPort: Full name of the port to read depth images from, e.g. /robotName/depth_camera "; - return false; - } - - remote_depthFrame_StreamingPort_name = config.find("remoteDepthPort").asString(); + if (!parseParams(config)) { return false; } - // Single RPC port - if (!config.check("localRpcPort", "full name of the port for streaming depth image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'localRpcPort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " localRpcPort: Full name of the local RPC port to open, e.g. /myApp/RGBD/rpc"; - return false; - } - - local_rpcPort_name = config.find("localRpcPort").asString(); - - if (!config.check("remoteRpcPort", "full name of the port for streaming depth image")) - { - yCError(RGBDSENSORCLIENT) << "Missing 'remoteRpcPort' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORCLIENT) << " remoteRpcPort: Full name of the remote RPC port, e.g. /robotName/RGBD/rpc"; - return false; - } - - remote_rpcPort_name = config.find("remoteRpcPort").asString(); - - image_carrier_type = "udp"; - depth_carrier_type = "udp"; - - if (config.check("ImageCarrier", "carrier for the image stream")) - { - image_carrier_type = config.find("ImageCarrier").asString(); - } - - if (config.check("DepthCarrier", "carrier for the depth stream")) - { - depth_carrier_type = config.find("DepthCarrier").asString(); - } - - /* - * When using multiple RPC ports - * - local_colorFrame_rpcPort_Name = local_colorFrame_StreamingPort_Name + "/rpc:i"; - remote_colorFrame_rpcPort_Name = remote_colorFrame_StreamingPort_Name + "/rpc:i"; - local_depthFrame_rpcPort_Name = local_depthFrame_StreamingPort_Name + "/rpc:i"; - remote_depthFrame_rpcPort_Name = remote_depthFrame_StreamingPort_Name + "/rpc:i"; - - */ - - return true; -} - -bool RGBDSensorClient::initialize_YARP(yarp::os::Searchable& /*config*/) -{ - bool ret; + bool ret = false; // Opening Streaming ports - ret = colorFrame_StreamingPort.open(local_colorFrame_StreamingPort_name); - ret &= depthFrame_StreamingPort.open(local_depthFrame_StreamingPort_name); + ret = colorFrame_StreamingPort.open(m_localImagePort); + ret &= depthFrame_StreamingPort.open(m_localDepthPort); - if(!ret) + if (!ret) { - yCError(RGBDSENSORCLIENT) << sensorId << " cannot open local streaming ports."; + yCError(RGBDSENSORCLIENT) << " cannot open local streaming ports: " << m_localImagePort << " or " << m_localDepthPort; colorFrame_StreamingPort.close(); depthFrame_StreamingPort.close(); } - if(! yarp::os::Network::connect(remote_colorFrame_StreamingPort_name, colorFrame_StreamingPort.getName(), image_carrier_type) ) + if (!yarp::os::Network::connect(m_remoteImagePort, colorFrame_StreamingPort.getName(), m_ImageCarrier)) { - yCError(RGBDSENSORCLIENT) << colorFrame_StreamingPort.getName() << " cannot connect to remote port " << remote_colorFrame_StreamingPort_name << "with carrier " << image_carrier_type; + yCError(RGBDSENSORCLIENT) << colorFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteImagePort << "with carrier " << m_ImageCarrier; return false; } - if(! yarp::os::Network::connect(remote_depthFrame_StreamingPort_name, depthFrame_StreamingPort.getName(), depth_carrier_type) ) + if (!yarp::os::Network::connect(m_remoteDepthPort, depthFrame_StreamingPort.getName(), m_DepthCarrier)) { - yCError(RGBDSENSORCLIENT) << depthFrame_StreamingPort.getName() << " cannot connect to remote port " << remote_depthFrame_StreamingPort_name << "with carrier " << depth_carrier_type; + yCError(RGBDSENSORCLIENT) << depthFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteDepthPort << "with carrier " << m_DepthCarrier; return false; } // Single RPC port - ret = rpcPort.open(local_rpcPort_name); + ret = rpcPort.open(m_localRpcPort); - if(!ret) + if (!ret) { - yCError(RGBDSENSORCLIENT) << sensorId << " cannot open local RPC port " << local_rpcPort_name; + yCError(RGBDSENSORCLIENT) << " cannot open local RPC port " << m_localRpcPort; colorFrame_StreamingPort.close(); depthFrame_StreamingPort.close(); rpcPort.close(); } - if(! rpcPort.addOutput(remote_rpcPort_name) ) + if (!rpcPort.addOutput(m_remoteRpcPort)) { - yCError(RGBDSENSORCLIENT) << sensorId << " cannot connect to port " << remote_rpcPort_name; + yCError(RGBDSENSORCLIENT) << " cannot connect to port " << m_remoteRpcPort; colorFrame_StreamingPort.close(); depthFrame_StreamingPort.close(); rpcPort.close(); @@ -204,7 +96,7 @@ bool RGBDSensorClient::initialize_YARP(yarp::os::Searchable& /*config*/) int major = response.get(3).asInt32(); int minor = response.get(4).asInt32(); - if(major != RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR) + if (major != RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR) { yCError(RGBDSENSORCLIENT) << "Major protocol number does not match, please verify client and server are updated. \ Expected: " << RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR << " received: " << major; @@ -212,36 +104,12 @@ bool RGBDSensorClient::initialize_YARP(yarp::os::Searchable& /*config*/) } - if(minor != RGBD_INTERFACE_PROTOCOL_VERSION_MINOR) + if (minor != RGBD_INTERFACE_PROTOCOL_VERSION_MINOR) { yCWarning(RGBDSENSORCLIENT) << "Minor protocol number does not match, please verify client and server are updated.\ Expected: " << RGBD_INTERFACE_PROTOCOL_VERSION_MINOR << " received: " << minor; } - /* - * Multiple RPC ports - * - ret &= colorFrame_rpcPort.open(local_colorFrame_rpcPort_Name.c_str() ); - ret &= depthFrame_rpcPort.open(local_depthFrame_rpcPort_Name.c_str() ); - - if(!ret) - yCError(RGBDSENSORCLIENT) << "sensorId cannot open ports"; - - // doing connections: How to correctly handle YARP_PORT_PREFIX for remote port names?? - if(! colorFrame_rpcPort.addOutput(remote_colorFrame_rpcPort_Name.c_str()) ) // This will handle local port names only - { - yCError(RGBDSENSORCLIENT) << sensorId << " cannot add output " << remote_colorFrame_rpcPort_Name; - return false; - } - - if(! depthFrame_rpcPort.addOutput(remote_depthFrame_rpcPort_Name.c_str()) ) // This will handle local port names only - { - yCError(RGBDSENSORCLIENT) << sensorId << " cannot add output " << remote_depthFrame_rpcPort_Name; - return false; - } - */ - - streamingReader->attach(&colorFrame_StreamingPort, &depthFrame_StreamingPort); return true; diff --git a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.h b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.h index 5a312f5cf2b..7a38936a0a6 100644 --- a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.h +++ b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient.h @@ -14,6 +14,7 @@ #include #include +#include "RGBDSensorClient_ParamsParser.h" #include #include @@ -36,52 +37,17 @@ class RGBDSensor_StreamingMsgParser; * for depth image following Framegrabber and IDepthSensor interfaces specification respectively. * See they documentation for more details about each interface. * - * This device is paired with its server called RGBDSensorWrapper to receive the data streams and perform remote operations. + * This device is paired with its server called RGBDSensor_nws_yarp to receive the data streams and perform remote operations. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:---------------:|:--------------:|:-------:|:--------------:|:-------------:|:------------: |:-------------------------------------------------------------------------------------:|:-----:| - * | localImagePort | - | string | - | - | | Full name of the local port to open, e.g. /myApp/RGBD/rgb_camera:i | | - * | localDepthPort | - | string | - | - | | Full name of the local port to open, e.g. /myApp/RGBD/depth_camera:i | | - * | localRpcPort | - | string | - | - | | Full name of the local RPC port to open, e.g. /myApp/RGBD/rpc | | - * | remoteImagePort | - | string | - | - | | Full name of the port to read color images from, e.g. /robotName/RGBD/image_camera:o | | - * | remoteDepthPort | - | string | - | - | | Full name of the port to read depth images from, e.g. /robotName/RGBD/depth_camera:o | | - * | remoteRpcPort | - | string | - | - | | Full name of the remote RPC port, e.g. /robotName/RGBD/rpc | | - * | ImageCarrier | - | string | - | udp | No | Carrier name for the Image stream used in the client-server connection | | - * | DepthCarrier | - | string | - | udp | No | Carrier name for the Depth strean used in the client-server connection | | - * - * Configuration file using .ini format, using subdevice keyword. - * - * \code{.unparsed} - * device RGBDSensorClient - * localImagePort /clientRgbPort:i - * localDepthPort /clientDepthPort:i - * localRpcPort /clientRpcPort - * remoteImagePort /RGBD/rgbCamera:o - * remoteDepthPort /RGBD/depthCamera:o - * remoteRpcPort /RGBD/rpc - * \endcode - * - * XML format, using 'networks' keyword. This file is meant to be used in junction with yarprobotinterface executable, - * therefore has an addictional section at the end. - * - * \code{.xml} - * - * - * /clientRgbPort:i - * /clientDepthPort:i - * /clientRpcPort - * /RGBD/rgbCamera:o - * /RGBD/depthCamera:o - * /RGBD/rpc - * \endcode + * Parameters required by this device are shown in class: RGBDSensorClient_ParamsParser * */ class RGBDSensorClient : public yarp::dev::DeviceDriver, public yarp::proto::framegrabber::FrameGrabberControls_Forwarder, - public yarp::dev::IRGBDSensor + public yarp::dev::IRGBDSensor, + public RGBDSensorClient_ParamsParser { protected: yarp::os::Port rpcPort; @@ -89,53 +55,20 @@ class RGBDSensorClient : yarp::proto::framegrabber::RgbVisualParams_Forwarder* RgbMsgSender{nullptr}; yarp::proto::framegrabber::DepthVisualParams_Forwarder* DepthMsgSender{nullptr}; protected: - std::string local_colorFrame_StreamingPort_name; - std::string local_depthFrame_StreamingPort_name; - std::string remote_colorFrame_StreamingPort_name; - std::string remote_depthFrame_StreamingPort_name; - std::string image_carrier_type; - std::string depth_carrier_type; RgbImageBufferedPort colorFrame_StreamingPort; FloatImageBufferedPort depthFrame_StreamingPort; - // Use a single RPC port for now - std::string local_rpcPort_name; - std::string remote_rpcPort_name; - - /* - * In case the client has to connect to 2 different wrappers/server because the rgb - * and depth comes from two different sources. - * - * It should be possible to attach this guy to more than one port, try to see what - * will happen when receiving 2 calls at the same time (receive one calls while serving - * another one, it will result in concurrent thread most probably) and buffering issues. - * - - std::string local_colorFrame_rpcPort_Name; - std::string local_depthFrame_rpcPort_Name; - std::string remote_colorFrame_rpcPort_Name; - std::string remote_depthFrame_rpcPort_Name; - - yarp::os::Port colorFrame_rpcPort; - yarp::os::Port depthFrame_rpcPort; - */ - // Image data specs - std::string sensorId; yarp::dev::IRGBDSensor *sensor_p{nullptr}; IRGBDSensor::RGBDSensor_status sensorStatus{IRGBDSensor::RGBD_SENSOR_NOT_READY}; int verbose{2}; - bool initialize_YARP(yarp::os::Searchable &config); - yarp::os::Stamp colorStamp; yarp::os::Stamp depthStamp; - // This is gonna be superseded by the synchronized when it'll be ready RGBDSensor_StreamingMsgParser *streamingReader{nullptr}; - bool fromConfig(yarp::os::Searchable &config); public: RGBDSensorClient(); diff --git a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.cpp b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.cpp new file mode 100644 index 00000000000..31c5b8718b5 --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.cpp @@ -0,0 +1,243 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "RGBDSensorClient_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(RGBDSensorClientParamsCOMPONENT, "yarp.device.RGBDSensorClient") +} + + +RGBDSensorClient_ParamsParser::RGBDSensorClient_ParamsParser() +{ +} + + +std::vector RGBDSensorClient_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("localImagePort"); + params.push_back("localDepthPort"); + params.push_back("remoteImagePort"); + params.push_back("remoteDepthPort"); + params.push_back("localRpcPort"); + params.push_back("remoteRpcPort"); + params.push_back("ImageCarrier"); + params.push_back("DepthCarrier"); + return params; +} + + +bool RGBDSensorClient_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(RGBDSensorClientParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter localImagePort + { + if (config.check("localImagePort")) + { + m_localImagePort = config.find("localImagePort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'localImagePort' using value:" << m_localImagePort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'localImagePort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the local image streaming port to open"; + return false; + } + prop_check.unput("localImagePort"); + } + + //Parser of parameter localDepthPort + { + if (config.check("localDepthPort")) + { + m_localDepthPort = config.find("localDepthPort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'localDepthPort' using value:" << m_localDepthPort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'localDepthPort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the local depth streaming port to open"; + return false; + } + prop_check.unput("localDepthPort"); + } + + //Parser of parameter remoteImagePort + { + if (config.check("remoteImagePort")) + { + m_remoteImagePort = config.find("remoteImagePort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'remoteImagePort' using value:" << m_remoteImagePort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'remoteImagePort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the remote image port to connect to"; + return false; + } + prop_check.unput("remoteImagePort"); + } + + //Parser of parameter remoteDepthPort + { + if (config.check("remoteDepthPort")) + { + m_remoteDepthPort = config.find("remoteDepthPort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'remoteDepthPort' using value:" << m_remoteDepthPort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'remoteDepthPort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the remote depth port to connect to"; + return false; + } + prop_check.unput("remoteDepthPort"); + } + + //Parser of parameter localRpcPort + { + if (config.check("localRpcPort")) + { + m_localRpcPort = config.find("localRpcPort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'localRpcPort' using value:" << m_localRpcPort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'localRpcPort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the local rpc port to open"; + return false; + } + prop_check.unput("localRpcPort"); + } + + //Parser of parameter remoteRpcPort + { + if (config.check("remoteRpcPort")) + { + m_remoteRpcPort = config.find("remoteRpcPort").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'remoteRpcPort' using value:" << m_remoteRpcPort; + } + else + { + yCError(RGBDSensorClientParamsCOMPONENT) << "Mandatory parameter 'remoteRpcPort' not found!"; + yCError(RGBDSensorClientParamsCOMPONENT) << "Description of the parameter: Full name of the remote rpc port to connect to"; + return false; + } + prop_check.unput("remoteRpcPort"); + } + + //Parser of parameter ImageCarrier + { + if (config.check("ImageCarrier")) + { + m_ImageCarrier = config.find("ImageCarrier").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'ImageCarrier' using value:" << m_ImageCarrier; + } + else + { + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'ImageCarrier' using DEFAULT value:" << m_ImageCarrier; + } + prop_check.unput("ImageCarrier"); + } + + //Parser of parameter DepthCarrier + { + if (config.check("DepthCarrier")) + { + m_DepthCarrier = config.find("DepthCarrier").asString(); + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'DepthCarrier' using value:" << m_DepthCarrier; + } + else + { + yCInfo(RGBDSensorClientParamsCOMPONENT) << "Parameter 'DepthCarrier' using DEFAULT value:" << m_DepthCarrier; + } + prop_check.unput("DepthCarrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(RGBDSensorClientParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(RGBDSensorClientParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string RGBDSensorClient_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: RGBDSensorClient\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period (in s) of the broadcasted values through yarp ports\n"); + doc = doc + std::string("'localImagePort': Full name of the local image streaming port to open\n"); + doc = doc + std::string("'localDepthPort': Full name of the local depth streaming port to open\n"); + doc = doc + std::string("'remoteImagePort': Full name of the remote image port to connect to\n"); + doc = doc + std::string("'remoteDepthPort': Full name of the remote depth port to connect to\n"); + doc = doc + std::string("'localRpcPort': Full name of the local rpc port to open\n"); + doc = doc + std::string("'remoteRpcPort': Full name of the remote rpc port to connect to\n"); + doc = doc + std::string("'ImageCarrier': Carrier for the image stream\n"); + doc = doc + std::string("'DepthCarrier': Carrier for the depth stream\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device RGBDSensorClient --period 0.03 --localImagePort /RGBD_nwc/Image:o --localDepthPort /RGBD_nwc/Depth:o --remoteImagePort /RGBD_nws/Image:o --remoteDepthPort /RGBD_nws/Depth:i --localRpcPort /RGBD_nwc/rpc:o --remoteRpcPort /RGBD_nws/rpc:i --ImageCarrier udp --DepthCarrier udp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device RGBDSensorClient --localImagePort /RGBD_nwc/Image:o --localDepthPort /RGBD_nwc/Depth:o --remoteImagePort /RGBD_nws/Image:o --remoteDepthPort /RGBD_nws/Depth:i --localRpcPort /RGBD_nwc/rpc:o --remoteRpcPort /RGBD_nws/rpc:i\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.h b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.h new file mode 100644 index 00000000000..ead3905240b --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_ParamsParser.h @@ -0,0 +1,93 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef RGBDSENSORCLIENT_PARAMSPARSER_H +#define RGBDSENSORCLIENT_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class RGBDSensorClient. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:---------------:|:------:|:-----:|:-----------------:|:--------:|:------------------------------------------------------------------:|:-------------:| +* | - | period | double | s | 0.03 | 0 | refresh period (in s) of the broadcasted values through yarp ports | default 0.03s | +* | - | localImagePort | string | - | /RGBD_nwc/Image:o | 1 | Full name of the local image streaming port to open | - | +* | - | localDepthPort | string | - | /RGBD_nwc/Depth:o | 1 | Full name of the local depth streaming port to open | - | +* | - | remoteImagePort | string | - | /RGBD_nws/Image:o | 1 | Full name of the remote image port to connect to | - | +* | - | remoteDepthPort | string | - | /RGBD_nws/Depth:i | 1 | Full name of the remote depth port to connect to | - | +* | - | localRpcPort | string | - | /RGBD_nwc/rpc:o | 1 | Full name of the local rpc port to open | - | +* | - | remoteRpcPort | string | - | /RGBD_nws/rpc:i | 1 | Full name of the remote rpc port to connect to | - | +* | - | ImageCarrier | string | - | udp | 0 | Carrier for the image stream | - | +* | - | DepthCarrier | string | - | udp | 0 | Carrier for the depth stream | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device RGBDSensorClient --period 0.03 --localImagePort /RGBD_nwc/Image:o --localDepthPort /RGBD_nwc/Depth:o --remoteImagePort /RGBD_nws/Image:o --remoteDepthPort /RGBD_nws/Depth:i --localRpcPort /RGBD_nwc/rpc:o --remoteRpcPort /RGBD_nws/rpc:i --ImageCarrier udp --DepthCarrier udp +* \endcode +* +* \code{.unparsed} +* yarpdev --device RGBDSensorClient --localImagePort /RGBD_nwc/Image:o --localDepthPort /RGBD_nwc/Depth:o --remoteImagePort /RGBD_nws/Image:o --remoteDepthPort /RGBD_nws/Depth:i --localRpcPort /RGBD_nwc/rpc:o --remoteRpcPort /RGBD_nws/rpc:i +* \endcode +* +*/ + +class RGBDSensorClient_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + RGBDSensorClient_ParamsParser(); + ~RGBDSensorClient_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"RGBDSensorClient"}; + const std::string m_device_name = {"RGBDSensorClient"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.03"}; + const std::string m_localImagePort_defaultValue = {"/RGBD_nwc/Image:o"}; + const std::string m_localDepthPort_defaultValue = {"/RGBD_nwc/Depth:o"}; + const std::string m_remoteImagePort_defaultValue = {"/RGBD_nws/Image:o"}; + const std::string m_remoteDepthPort_defaultValue = {"/RGBD_nws/Depth:i"}; + const std::string m_localRpcPort_defaultValue = {"/RGBD_nwc/rpc:o"}; + const std::string m_remoteRpcPort_defaultValue = {"/RGBD_nws/rpc:i"}; + const std::string m_ImageCarrier_defaultValue = {"udp"}; + const std::string m_DepthCarrier_defaultValue = {"udp"}; + + double m_period = {0.03}; + std::string m_localImagePort = {"/RGBD_nwc/Image:o"}; + std::string m_localDepthPort = {"/RGBD_nwc/Depth:o"}; + std::string m_remoteImagePort = {"/RGBD_nws/Image:o"}; + std::string m_remoteDepthPort = {"/RGBD_nws/Depth:i"}; + std::string m_localRpcPort = {"/RGBD_nwc/rpc:o"}; + std::string m_remoteRpcPort = {"/RGBD_nws/rpc:i"}; + std::string m_ImageCarrier = {"udp"}; + std::string m_DepthCarrier = {"udp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_params.md b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_params.md new file mode 100644 index 00000000000..9e35383117e --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensorClient/RGBDSensorClient_params.md @@ -0,0 +1,9 @@ + * | | period | double | s | 0.03 | No | refresh period (in s) of the broadcasted values through yarp ports | default 0.03s | + * | | localImagePort | string | - | /RGBD_nwc/Image:o | Yes | Full name of the local image streaming port to open | - | + * | | localDepthPort | string | - | /RGBD_nwc/Depth:o | Yes | Full name of the local depth streaming port to open | - | + * | | remoteImagePort | string | - | /RGBD_nws/Image:o | Yes | Full name of the remote image port to connect to | - | + * | | remoteDepthPort | string | - | /RGBD_nws/Depth:i | Yes | Full name of the remote depth port to connect to | - | + * | | localRpcPort | string | - | /RGBD_nwc/rpc:o | Yes | Full name of the local rpc port to open | - | + * | | remoteRpcPort | string | - | /RGBD_nws/rpc:i | Yes | Full name of the remote rpc port to connect to | - | + * | | ImageCarrier | string | - | udp | No | Carrier for the image stream | - | + * | | DepthCarrier | string | - | udp | No | Carrier for the depth stream | - | diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/RGBDSensor_nws_yarp/CMakeLists.txt index b824359b33f..44c98ea5964 100644 --- a/src/devices/networkWrappers/RGBDSensor_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/CMakeLists.txt @@ -9,6 +9,7 @@ yarp_prepare_plugin(rgbdSensor_nws_yarp EXTRA_CONFIG WRAPPER=rgbdSensor_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_rgbdSensor_nws_yarp) @@ -18,6 +19,8 @@ if(NOT SKIP_rgbdSensor_nws_yarp) PRIVATE RgbdSensor_nws_yarp.cpp RgbdSensor_nws_yarp.h + RgbdSensor_nws_yarp_ParamsParser.cpp + RgbdSensor_nws_yarp_ParamsParser.h ) target_sources(yarp_rgbdSensor_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.cpp b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.cpp index 1d5f4e92ea9..f8d6fe62f1a 100644 --- a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.cpp +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.cpp @@ -168,7 +168,6 @@ bool RGBDSensorParser::respond(const Bottle& cmd, Bottle& response) RgbdSensor_nws_yarp::RgbdSensor_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD), - period(DEFAULT_THREAD_PERIOD), sensor_p(nullptr), fgCtrl(nullptr), sensorStatus(IRGBDSensor::RGBD_SENSOR_NOT_READY), @@ -186,56 +185,35 @@ RgbdSensor_nws_yarp::~RgbdSensor_nws_yarp() bool RgbdSensor_nws_yarp::open(yarp::os::Searchable &config) { -// DeviceResponder::makeUsage(); -// addUsage("[set] [bri] $fBrightness", "set brightness"); -// addUsage("[set] [expo] $fExposure", "set exposure"); -// - m_conf.fromString(config.toString()); - if (verbose >= 5) { - yCTrace(RGBDSENSORNWSYARP) << "\nParameters are: \n" - << config.toString(); - } + if (!parseParams(config)) { return false; } - if(!fromConfig(config)) - { - yCError(RGBDSENSORNWSYARP) << "Failed to open, check previous log for error messages."; - return false; - } + //port names + std::string rootName = m_name; + std::string rpcPort_Name = rootName + "/rpc:i"; + colorFrame_StreamingPort_Name = rootName + "/rgbImage:o"; + depthFrame_StreamingPort_Name = rootName + "/depthImage:o"; - if(!initialize_YARP(config)) + // Open ports + bool bRet; + bRet = true; + if (!rpcPort.open(rpcPort_Name)) { - yCError(RGBDSENSORNWSYARP) << sensorId << "Error initializing YARP ports"; - return false; + yCError(RGBDSENSORNWSYARP) << "Unable to open rpc Port" << rpcPort_Name.c_str(); + bRet = false; } + rpcPort.setReader(rgbdParser); - return true; -} - -bool RgbdSensor_nws_yarp::fromConfig(yarp::os::Searchable &config) -{ - if (!config.check("period", "refresh period of the broadcasted values in s")) + if (!colorFrame_StreamingPort.open(colorFrame_StreamingPort_Name)) { - if (verbose >= 3) { - yCInfo(RGBDSENSORNWSYARP) << "Using default 'period' parameter of " << DEFAULT_THREAD_PERIOD << "s"; - } - } else { - period = config.find("period").asFloat64(); + yCError(RGBDSENSORNWSYARP) << "Unable to open color streaming Port" << colorFrame_StreamingPort_Name.c_str(); + bRet = false; } - - std::string rootName; - rootName = config.check("name",Value("/"), "starting '/' if needed.").asString(); - - if (!config.check("name", "Prefix name of the ports opened by the RGBD wrapper.")) { - yCError(RGBDSENSORNWSYARP) << "Missing 'name' parameter. Check you configuration file; it must be like:"; - yCError(RGBDSENSORNWSYARP) << " name: Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD"; - return false; + if (!depthFrame_StreamingPort.open(depthFrame_StreamingPort_Name)) + { + yCError(RGBDSENSORNWSYARP) << "Unable to open depth streaming Port" << depthFrame_StreamingPort_Name.c_str(); + bRet = false; } - rootName = config.find("name").asString(); - rpcPort_Name = rootName + "/rpc:i"; - colorFrame_StreamingPort_Name = rootName + "/rgbImage:o"; - depthFrame_StreamingPort_Name = rootName + "/depthImage:o"; - return true; } @@ -256,34 +234,6 @@ bool RgbdSensor_nws_yarp::close() return true; } -/* Helper functions */ - -bool RgbdSensor_nws_yarp::initialize_YARP(yarp::os::Searchable ¶ms) -{ - // Open ports - bool bRet; - bRet = true; - if(!rpcPort.open(rpcPort_Name)) - { - yCError(RGBDSENSORNWSYARP) << "Unable to open rpc Port" << rpcPort_Name.c_str(); - bRet = false; - } - rpcPort.setReader(rgbdParser); - - if(!colorFrame_StreamingPort.open(colorFrame_StreamingPort_Name)) - { - yCError(RGBDSENSORNWSYARP) << "Unable to open color streaming Port" << colorFrame_StreamingPort_Name.c_str(); - bRet = false; - } - if(!depthFrame_StreamingPort.open(depthFrame_StreamingPort_Name)) - { - yCError(RGBDSENSORNWSYARP) << "Unable to open depth streaming Port" << depthFrame_StreamingPort_Name.c_str(); - bRet = false; - } - - return bRet; -} - /** * WrapperSingle interface */ @@ -331,7 +281,7 @@ bool RgbdSensor_nws_yarp::attach(PolyDriver* poly) yCWarning(RGBDSENSORNWSYARP) << "Attached device has no valid IFrameGrabberControls interface."; } - PeriodicThread::setPeriod(period); + PeriodicThread::setPeriod(m_period); return PeriodicThread::start(); } @@ -504,7 +454,7 @@ void RgbdSensor_nws_yarp::run() default: { if (verbose >= 1) { // better not to print it every cycle anyway, too noisy - yCError(RGBDSENSORNWSYARP, "%s: Sensor returned error", sensorId.c_str()); + yCError(RGBDSENSORNWSYARP, "%s: Sensor returned error", m_name.c_str()); } } } @@ -512,7 +462,7 @@ void RgbdSensor_nws_yarp::run() else { if(verbose >= 6) { - yCError(RGBDSENSORNWSYARP, "%s: Sensor interface is not valid", sensorId.c_str()); + yCError(RGBDSENSORNWSYARP, "%s: Sensor interface is not valid", m_name.c_str()); } } } diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.h b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.h index ad43081736b..ff79593b142 100644 --- a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.h +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp.h @@ -31,6 +31,8 @@ #include #include +#include "RgbdSensor_nws_yarp_ParamsParser.h" + namespace RGBDImpl { #define DEFAULT_THREAD_PERIOD 0.03 // s @@ -74,28 +76,14 @@ class RGBDSensorParser : * * This device is paired with its client called RgbdSensor_nws_yarp to receive the data streams and perform remote operations. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:-----------------------:|:-------:|:--------------:|:-------------:|:-----------------------------: |:---------------------------------------------------------------------------------------------------:|:-----:| - * | period | - | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | - * | name | - | string | - | - | Yes | Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD | Required suffix like '/rpc' will be added by the device | - * - * Some example of configuration files: - * - * Example of configuration file using .ini format. - * - * \code{.unparsed} - * device RGBDSensorWrapper - * subdevice - * period 0.03 - * name //RGBDSensor - * \endcode + * Parameters required by this device are shown in class: RgbdSensor_nws_yarp_ParamsParser */ class RgbdSensor_nws_yarp : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PeriodicThread + public yarp::os::PeriodicThread, + public RgbdSensor_nws_yarp_ParamsParser { private: typedef yarp::sig::ImageOf DepthImage; @@ -139,18 +127,14 @@ class RgbdSensor_nws_yarp : // Image data specs // int hDim, vDim; - double period; - std::string sensorId; yarp::dev::IRGBDSensor* sensor_p; yarp::dev::IFrameGrabberControls* fgCtrl; yarp::dev::IRGBDSensor::RGBDSensor_status sensorStatus; int verbose; - bool initialize_YARP(yarp::os::Searchable& config); // Synch yarp::os::Stamp colorStamp; yarp::os::Stamp depthStamp; - yarp::os::Property m_conf; bool writeData(); bool setCamInfo(const std::string& frame_id, @@ -166,7 +150,6 @@ class RgbdSensor_nws_yarp : ~RgbdSensor_nws_yarp() override; bool open(yarp::os::Searchable ¶ms) override; - bool fromConfig(yarp::os::Searchable ¶ms); bool close() override; /** diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..50945dc0ded --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.cpp @@ -0,0 +1,121 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "RgbdSensor_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(RgbdSensor_nws_yarpParamsCOMPONENT, "yarp.device.RgbdSensor_nws_yarp") +} + + +RgbdSensor_nws_yarp_ParamsParser::RgbdSensor_nws_yarp_ParamsParser() +{ +} + + +std::vector RgbdSensor_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + return params; +} + + +bool RgbdSensor_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(RgbdSensor_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(RgbdSensor_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(RgbdSensor_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(RgbdSensor_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(RgbdSensor_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(RgbdSensor_nws_yarpParamsCOMPONENT) << "Description of the parameter: Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD"; + return false; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(RgbdSensor_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(RgbdSensor_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string RgbdSensor_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: RgbdSensor_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period of the broadcasted values in s\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device rgbdSensor_nws_yarp --period 0.02 --name \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device rgbdSensor_nws_yarp --name \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..b84cbaf94b7 --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef RGBDSENSOR_NWS_YARP_PARAMSPARSER_H +#define RGBDSENSOR_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class RgbdSensor_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-------------------------------------------------------------------------:|:-------------------------------------------------------:| +* | - | period | double | s | 0.02 | 0 | refresh period of the broadcasted values in s | default 0.02s | +* | - | name | string | - | - | 1 | Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD | Required suffix like '/rpc' will be added by the device | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device rgbdSensor_nws_yarp --period 0.02 --name +* \endcode +* +* \code{.unparsed} +* yarpdev --device rgbdSensor_nws_yarp --name +* \endcode +* +*/ + +class RgbdSensor_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + RgbdSensor_nws_yarp_ParamsParser(); + ~RgbdSensor_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"RgbdSensor_nws_yarp"}; + const std::string m_device_name = {"rgbdSensor_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_name_defaultValue = {""}; + + double m_period = {0.02}; + std::string m_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_params.md b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_params.md new file mode 100644 index 00000000000..68774b34f50 --- /dev/null +++ b/src/devices/networkWrappers/RGBDSensor_nws_yarp/RgbdSensor_nws_yarp_params.md @@ -0,0 +1,2 @@ + * | | period | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | + * | | name | string | - | - | Yes | Prefix name of the ports opened by the RGBD wrapper, e.g. /robotName/RGBD | Required suffix like '/rpc' will be added by the device | diff --git a/src/devices/networkWrappers/Rangefinder2DClient/Rangefinder2DClient.cpp b/src/devices/networkWrappers/Rangefinder2DClient/Rangefinder2DClient.cpp index bc1baf4adb5..785e4cc907b 100644 --- a/src/devices/networkWrappers/Rangefinder2DClient/Rangefinder2DClient.cpp +++ b/src/devices/networkWrappers/Rangefinder2DClient/Rangefinder2DClient.cpp @@ -153,6 +153,8 @@ void Rangefinder2DInputPortProcessor::getEstFrequency(int &ite, double &av, doub bool Rangefinder2DClient::open(yarp::os::Searchable &config) { + yCError(RANGEFINDER2DCLIENT) << "This device is deprecated. Please use Rangefinder2D_nwc_yarp instead."; + local.clear(); remote.clear(); diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/CMakeLists.txt index 30ff2bb020c..61f8935d311 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(rangefinder2D_nwc_yarp INCLUDE Rangefinder2D_nwc_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_rangefinder2D_nwc_yarp) @@ -16,6 +17,8 @@ if(NOT SKIP_rangefinder2D_nwc_yarp) PRIVATE Rangefinder2D_nwc_yarp.cpp Rangefinder2D_nwc_yarp.h + Rangefinder2D_nwc_yarp_ParamsParser.cpp + Rangefinder2D_nwc_yarp_ParamsParser.h ) target_link_libraries(yarp_rangefinder2D_nwc_yarp diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.cpp b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.cpp index 360553bffee..f5e1536009f 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.cpp +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.cpp @@ -154,33 +154,14 @@ void Rangefinder2DInputPortProcessor::getEstFrequency(int &ite, double &av, doub bool Rangefinder2D_nwc_yarp::open(yarp::os::Searchable &config) { - m_local_portname.clear(); - m_remote_portname.clear(); + if (!parseParams(config)) { return false; } - m_local_portname = config.find("local").asString(); - m_remote_portname = config.find("remote").asString(); + std::string local_rpc_portname = m_local+ "/rpc:o"; + std::string remote_rpc_portname = m_remote + "/rpc:i"; - m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString(); - - if (m_local_portname =="") - { - yCError(RANGEFINDER2DCLIENT, "open() error you have to provide valid local name"); - return false; - } - if (m_remote_portname =="") - { - yCError(RANGEFINDER2DCLIENT, "open() error you have to provide valid remote name"); - return false; - } - - std::string local_rpc_portname = m_local_portname; - local_rpc_portname += "/rpc:o"; - std::string remote_rpc_portname = m_remote_portname; - remote_rpc_portname += "/rpc:i"; - - if (!m_inputPort.open(m_local_portname)) + if (!m_inputPort.open(m_local)) { - yCError(RANGEFINDER2DCLIENT, "open() error could not open port %s, check network\n", m_local_portname.c_str()); + yCError(RANGEFINDER2DCLIENT, "open() error could not open port %s, check network\n", m_local.c_str()); return false; } m_inputPort.useCallback(); @@ -191,10 +172,10 @@ bool Rangefinder2D_nwc_yarp::open(yarp::os::Searchable &config) return false; } - bool ok=Network::connect(m_remote_portname.c_str(), m_local_portname.c_str(), m_carrier); + bool ok=Network::connect(m_remote.c_str(), m_local.c_str(), m_carrier); if (!ok) { - yCError(RANGEFINDER2DCLIENT, "open() error could not connect to %s\n", m_remote_portname.c_str()); + yCError(RANGEFINDER2DCLIENT, "open() error could not connect to %s\n", m_remote.c_str()); return false; } diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.h b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.h index 34c42a4a1b1..c2c7fb2f9c7 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.h +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp.h @@ -20,6 +20,8 @@ #include +#include "Rangefinder2D_nwc_yarp_ParamsParser.h" + class Rangefinder2DInputPortProcessor : public yarp::os::BufferedPort { @@ -60,25 +62,17 @@ class Rangefinder2DInputPortProcessor : * * \brief `Rangefinder2D_nwc_yarp`: The client side of any ILaserRangefinder2D capable device. * -* Still single thread! concurrent access is unsafe. +* Parameters required by this device are shown in class: Rangefinder2D_nwc_yarp_ParamsParser * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| -* | local | - | string | - | - | Yes | Full port name opened by the Rangefinder2D_nwc_yarp device. | | -* | remote | - | string | - | - | Yes | Full port name of the port opened on the server side, to which the Rangefinder2D_nwc_yarp connects to. | | -* | carrier | - | string | - | tcp | No | The carrier used for the connection with the server. | | */ class Rangefinder2D_nwc_yarp: public yarp::dev::DeviceDriver, - public yarp::dev::IRangefinder2D + public yarp::dev::IRangefinder2D, + public Rangefinder2D_nwc_yarp_ParamsParser { protected: Rangefinder2DInputPortProcessor m_inputPort; yarp::os::Port m_rpcPort; - std::string m_local_portname; - std::string m_remote_portname; - std::string m_carrier; yarp::os::Stamp m_lastTs; std::string m_deviceId; diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..0b8610cc9db --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,139 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#include "Rangefinder2D_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Rangefinder2D_nwc_yarpParamsCOMPONENT, "yarp.device.Rangefinder2D_nwc_yarp") +} + + +Rangefinder2D_nwc_yarp_ParamsParser::Rangefinder2D_nwc_yarp_ParamsParser() +{ +} + + +std::vector Rangefinder2D_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + params.push_back("carrier"); + return params; +} + + +bool Rangefinder2D_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Rangefinder2D_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the Rangefinder2D_nwc_yarp device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the Rangefinder2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Rangefinder2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Rangefinder2D_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Rangefinder2D_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the Rangefinder2D_nwc_yarp device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the Rangefinder2D_nwc_yarp connects to.\n"); + doc = doc + std::string("'carrier': The carrier used for the connection with the server.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device rangefinder2D_nwc_yarp --local --remote --carrier tcp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device rangefinder2D_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..78acf88a52a --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef RANGEFINDER2D_NWC_YARP_PARAMSPARSER_H +#define RANGEFINDER2D_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Rangefinder2D_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the Rangefinder2D_nwc_yarp device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the Rangefinder2D_nwc_yarp connects to. | - | +* | - | carrier | string | - | tcp | 0 | The carrier used for the connection with the server. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device rangefinder2D_nwc_yarp --local --remote --carrier tcp +* \endcode +* +* \code{.unparsed} +* yarpdev --device rangefinder2D_nwc_yarp --local --remote +* \endcode +* +*/ + +class Rangefinder2D_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Rangefinder2D_nwc_yarp_ParamsParser(); + ~Rangefinder2D_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Rangefinder2D_nwc_yarp"}; + const std::string m_device_name = {"rangefinder2D_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"tcp"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"tcp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_params.md b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_params.md new file mode 100644 index 00000000000..0b32db36170 --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nwc_yarp/Rangefinder2D_nwc_yarp_params.md @@ -0,0 +1,3 @@ +* | | local | string | - | - | Yes | Full port name opened by the Rangefinder2D_nwc_yarp device. | | +* | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the Rangefinder2D_nwc_yarp connects to. | | +* | | carrier | string | - | tcp | No | The carrier used for the connection with the server. | | diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/CMakeLists.txt index f2a1b46ccd6..e93dc23d05e 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(rangefinder2D_nws_yarp EXTRA_CONFIG WRAPPER=rangefinder2D_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_rangefinder2D_nws_yarp) @@ -17,6 +18,8 @@ if(NOT SKIP_rangefinder2D_nws_yarp) PRIVATE Rangefinder2D_nws_yarp.cpp Rangefinder2D_nws_yarp.h + Rangefinder2D_nws_yarp_ParamsParser.cpp + Rangefinder2D_nws_yarp_ParamsParser.h ) target_link_libraries(yarp_rangefinder2D_nws_yarp diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.cpp b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.cpp index a3a30987445..ac8b253b581 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.cpp +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.cpp @@ -28,7 +28,6 @@ YARP_LOG_COMPONENT(RANGEFINDER2D_NWS_YARP, "yarp.devices.Rangefinder2D_nws_yarp" Rangefinder2D_nws_yarp::Rangefinder2D_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD), sens_p(nullptr), - _period(DEFAULT_THREAD_PERIOD), minAngle(0), maxAngle(0), minDistance(0), @@ -77,7 +76,7 @@ bool Rangefinder2D_nws_yarp::attach(yarp::dev::PolyDriver* driver) return false; } - PeriodicThread::setPeriod(_period); + PeriodicThread::setPeriod(m_period); return PeriodicThread::start(); } @@ -290,55 +289,19 @@ bool Rangefinder2D_nws_yarp::threadInit() bool Rangefinder2D_nws_yarp::open(yarp::os::Searchable &config) { - Property params; - params.fromString(config.toString()); + if (!parseParams(config)) { return false; } - if (!config.check("period")) + if (!streamingPort.open(m_name)) { - yCError(RANGEFINDER2D_NWS_YARP) << "missing 'period' parameter. Check you configuration file\n"; + yCError(RANGEFINDER2D_NWS_YARP, "failed to open port %s", m_name.c_str()); return false; - } else { - _period = config.find("period").asFloat64(); } - - if (!config.check("name")) - { - yCError(RANGEFINDER2D_NWS_YARP) << "Rangefinder2D_nws_yarp: missing 'name' parameter. Check you configuration file; it must be like:"; - yCError(RANGEFINDER2D_NWS_YARP) << " name: full name of the port, like /robotName/deviceId/sensorType:o"; - return false; - } - else - { - streamingPortName = config.find("name").asString(); - rpcPortName = streamingPortName + "/rpc:i"; - } - - if (config.check("frame_id")) - { - frame_id = config.find("frame_id").asString(); - } - - if(!initialize_YARP(config) ) + std::string rpc_portname = m_name + "/rpc:i"; + if (!rpcPort.open(rpc_portname)) { - yCError(RANGEFINDER2D_NWS_YARP) << streamingPortName << "Error initializing YARP ports"; + yCError(RANGEFINDER2D_NWS_YARP, "failed to open port %s", rpc_portname.c_str()); return false; } - - return true; -} - -bool Rangefinder2D_nws_yarp::initialize_YARP(yarp::os::Searchable ¶ms) -{ - if (!streamingPort.open(streamingPortName)) - { - yCError(RANGEFINDER2D_NWS_YARP, "failed to open port %s", streamingPortName.c_str()); - return false; - } - if (!rpcPort.open(rpcPortName)) - { - yCError(RANGEFINDER2D_NWS_YARP, "failed to open port %s", rpcPortName.c_str()); - return false; - } rpcPort.setReader(*this); return true; } @@ -390,7 +353,7 @@ void Rangefinder2D_nws_yarp::run() } else { - yCError(RANGEFINDER2D_NWS_YARP, "%s: Sensor returned error", streamingPortName.c_str()); + yCError(RANGEFINDER2D_NWS_YARP, "%s: Sensor returned error", m_name.c_str()); } } } diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.h b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.h index a67e975d126..05e8844c657 100644 --- a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.h +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp.h @@ -31,39 +31,26 @@ #include #include #include +#include "Rangefinder2D_nws_yarp_ParamsParser.h" #define DEFAULT_THREAD_PERIOD 0.02 //s /** * @ingroup dev_impl_nws_yarp dev_impl_lidar * - * \section rangefinder2D_nws_yarp_device_parameters Description of input parameters * \brief `rangefinder2D_nws_yarp`: A Network grabber for 2D Rangefinder devices. * This device will stream data on the specified YARP ports. * - * This device is paired with its YARP client called Rangefinder2DClient to receive the data streams and perform RPC operations. + * This device is paired with its YARP client called rangefinder2D_nwc_yarp to receive the data streams and perform RPC operations. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:-----------------------:|:-------:|:--------------:|:-------------:|:-----------------------------: |:---------------------------------------------------------------------------------------------------:|:-----:| - * | period | - | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | - * | name | - | string | - | - | Yes | Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor | Required suffix like '/rpc' will be added by the device | - * | frame_id | - | string | - | - | No | name of the attached frame | Currently not used, reserved for future use | - * - * Example of configuration file using .ini format. - * - * \code{.unparsed} - * device rangefinder2D_nws_yarp - * subdevice - * period 20 - * name //Rangefinder2DSensor - * \endcode + * Parameters required by this device are shown in class: Rangefinder2D_nws_yarp_ParamsParser */ class Rangefinder2D_nws_yarp : public yarp::os::PeriodicThread, public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public Rangefinder2D_nws_yarp_ParamsParser { public: Rangefinder2D_nws_yarp(); @@ -82,10 +69,6 @@ class Rangefinder2D_nws_yarp : bool read(yarp::os::ConnectionReader& connection) override; private: - //yarp streaming data - std::string streamingPortName; - std::string rpcPortName; - std::string frame_id; yarp::os::Port rpcPort; yarp::os::BufferedPort streamingPort; @@ -94,13 +77,9 @@ class Rangefinder2D_nws_yarp : //device data yarp::os::Stamp lastStateStamp; - double _period; double minAngle, maxAngle; double minDistance, maxDistance; double resolution; - - //private methods - bool initialize_YARP(yarp::os::Searchable &config); }; #endif //YARP_DEV_RANGEFINDER2D_NWS_YARP_H diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..579fd364aa4 --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.cpp @@ -0,0 +1,137 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#include "Rangefinder2D_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Rangefinder2D_nws_yarpParamsCOMPONENT, "yarp.device.Rangefinder2D_nws_yarp") +} + + +Rangefinder2D_nws_yarp_ParamsParser::Rangefinder2D_nws_yarp_ParamsParser() +{ +} + + +std::vector Rangefinder2D_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + params.push_back("frame_id"); + return params; +} + + +bool Rangefinder2D_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Description of the parameter: Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor"; + return false; + } + prop_check.unput("name"); + } + + //Parser of parameter frame_id + { + if (config.check("frame_id")) + { + m_frame_id = config.find("frame_id").asString(); + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Parameter 'frame_id' using value:" << m_frame_id; + } + else + { + yCInfo(Rangefinder2D_nws_yarpParamsCOMPONENT) << "Parameter 'frame_id' using DEFAULT value:" << m_frame_id; + } + prop_check.unput("frame_id"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Rangefinder2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Rangefinder2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Rangefinder2D_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Rangefinder2D_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period of the broadcasted values in s\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor\n"); + doc = doc + std::string("'frame_id': name of the attached frame\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device rangefinder2D_nws_yarp --period 0.02 --name --frame_id \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device rangefinder2D_nws_yarp --name \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..376745010eb --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef RANGEFINDER2D_NWS_YARP_PARAMSPARSER_H +#define RANGEFINDER2D_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Rangefinder2D_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------------------------------------------------:|:-------------------------------------------------------:| +* | - | period | double | s | 0.02 | 0 | refresh period of the broadcasted values in s | default 0.02s | +* | - | name | string | - | - | 1 | Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor | Required suffix like '/rpc' will be added by the device | +* | - | frame_id | string | - | - | 0 | name of the attached frame | Currently not used, reserved for future use | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device rangefinder2D_nws_yarp --period 0.02 --name --frame_id +* \endcode +* +* \code{.unparsed} +* yarpdev --device rangefinder2D_nws_yarp --name +* \endcode +* +*/ + +class Rangefinder2D_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Rangefinder2D_nws_yarp_ParamsParser(); + ~Rangefinder2D_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Rangefinder2D_nws_yarp"}; + const std::string m_device_name = {"rangefinder2D_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_name_defaultValue = {""}; + const std::string m_frame_id_defaultValue = {""}; + + double m_period = {0.02}; + std::string m_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_frame_id = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_params.md b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_params.md new file mode 100644 index 00000000000..5ffd751ea4e --- /dev/null +++ b/src/devices/networkWrappers/Rangefinder2D_nws_yarp/Rangefinder2D_nws_yarp_params.md @@ -0,0 +1,3 @@ + * | | period | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | + * | | name | string | - | - | Yes | Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor | Required suffix like '/rpc' will be added by the device | + * | | frame_id | string | - | - | No | name of the attached frame | Currently not used, reserved for future use | diff --git a/src/devices/networkWrappers/RemoteControlBoard/CMakeLists.txt b/src/devices/networkWrappers/RemoteControlBoard/CMakeLists.txt index 796779346dc..9f5e71b8f64 100644 --- a/src/devices/networkWrappers/RemoteControlBoard/CMakeLists.txt +++ b/src/devices/networkWrappers/RemoteControlBoard/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(remote_controlboard EXTRA_CONFIG WRAPPER=controlboard_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_remote_controlboard) @@ -17,6 +18,8 @@ if(NOT SKIP_remote_controlboard) PRIVATE RemoteControlBoard.cpp RemoteControlBoard.h + RemoteControlBoard_ParamsParser.cpp + RemoteControlBoard_ParamsParser.h RemoteControlBoardLogComponent.cpp RemoteControlBoardLogComponent.h stateExtendedReader.cpp diff --git a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.cpp b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.cpp index 1d748421255..f79c7993c1f 100644 --- a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.cpp +++ b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.cpp @@ -180,86 +180,61 @@ bool RemoteControlBoard::checkProtocolVersion(bool ignore) bool RemoteControlBoard::open(Searchable& config) { - remote = config.find("remote").asString(); - local = config.find("local").asString(); + if (!parseParams(config)) { return false; } - if (config.check("timeout")) - { - extendedIntputStatePort.setTimeout(config.find("timeout").asFloat64()); - } - // check the Qos perefernces if available (local and remote) + extendedIntputStatePort.setTimeout(m_timeout); + + //handle local Qos yarp::os::QosStyle localQos; - if (config.check("local_qos")) { - Bottle& qos = config.findGroup("local_qos"); - if (qos.check("thread_priority")) { - localQos.setThreadPriority(qos.find("thread_priority").asInt32()); - } - if (qos.check("thread_policy")) { - localQos.setThreadPolicy(qos.find("thread_policy").asInt32()); - } - if (qos.check("packet_priority")) { - localQos.setPacketPriority(qos.find("packet_priority").asString()); - } + if (m_local_qos_enable) + { + localQos.setThreadPriority(m_local_qos_thread_priority); + localQos.setThreadPolicy(m_local_qos_thread_policy); + localQos.setPacketPriority(m_local_qos_packet_priority); } + //handle remote Qos yarp::os::QosStyle remoteQos; - if (config.check("remote_qos")) { - Bottle& qos = config.findGroup("remote_qos"); - if (qos.check("thread_priority")) { - remoteQos.setThreadPriority(qos.find("thread_priority").asInt32()); - } - if (qos.check("thread_policy")) { - remoteQos.setThreadPolicy(qos.find("thread_policy").asInt32()); - } - if (qos.check("packet_priority")) { - remoteQos.setPacketPriority(qos.find("packet_priority").asString()); - } + if (m_remote_qos_enable) + { + remoteQos.setThreadPriority(m_remote_qos_thread_priority); + remoteQos.setThreadPolicy(m_remote_qos_thread_policy); + remoteQos.setPacketPriority(m_remote_qos_packet_priority); } - bool writeStrict_isFound = config.check("writeStrict"); - if(writeStrict_isFound) + //handle param writeStrict + if (m_writeStrict == "on") { - Value &gotStrictVal = config.find("writeStrict"); - if(gotStrictVal.asString() == "on") - { - writeStrict_singleJoint = true; - writeStrict_moreJoints = true; - yCInfo(REMOTECONTROLBOARD, "RemoteControlBoard is ENABLING the writeStrict option for all commands"); - } - else if(gotStrictVal.asString() == "off") - { - writeStrict_singleJoint = false; - writeStrict_moreJoints = false; - yCInfo(REMOTECONTROLBOARD, "RemoteControlBoard is DISABLING the writeStrict opition for all commands"); - } else { - yCError(REMOTECONTROLBOARD, "Found writeStrict opition with wrong value. Accepted options are 'on' or 'off'"); - } + writeStrict_singleJoint = true; + writeStrict_moreJoints = true; + yCInfo(REMOTECONTROLBOARD, "RemoteControlBoard is ENABLING the writeStrict option for all commands"); } - - if (local=="") { - yCError(REMOTECONTROLBOARD, "Problem connecting to remote controlboard, 'local' port prefix not given"); - return false; + else if(m_writeStrict == "off") + { + writeStrict_singleJoint = false; + writeStrict_moreJoints = false; + yCInfo(REMOTECONTROLBOARD, "RemoteControlBoard is DISABLING the writeStrict option for all commands"); } - - if (remote=="") { - yCError(REMOTECONTROLBOARD, "Problem connecting to remote controlboard, 'remote' port name not given"); + else if (m_writeStrict.empty()) + { + //leave the default values + } + else + { + yCError(REMOTECONTROLBOARD, "Found writeStrict option with wrong value. Accepted options are 'on' or 'off'"); return false; } - std::string carrier = - config.check("carrier", - Value("udp"), - "default carrier for streaming robot state").asString(); - + //open ports bool portProblem = false; - if (local != "") { - std::string s1 = local; + if (m_local != "") { + std::string s1 = m_local; s1 += "/rpc:o"; if (!rpc_p.open(s1)) { portProblem = true; } - s1 = local; + s1 = m_local; s1 += "/command:o"; if (!command_p.open(s1)) { portProblem = true; } - s1 = local; + s1 = m_local; s1 += "/stateExt:i"; if (!extendedIntputStatePort.open(s1)) { portProblem = true; } if (!portProblem) @@ -269,11 +244,11 @@ bool RemoteControlBoard::open(Searchable& config) } bool connectionProblem = false; - if (remote != "" && !portProblem) + if (m_remote != "" && !portProblem) { - std::string s1 = remote; + std::string s1 = m_remote; s1 += "/rpc:i"; - std::string s2 = local; + std::string s2 = m_local; s2 += "/rpc:o"; bool ok = false; // RPC port needs to be tcp, therefore no carrier option is added here @@ -285,32 +260,32 @@ bool RemoteControlBoard::open(Searchable& config) connectionProblem = true; } - s1 = remote; + s1 = m_remote; s1 += "/command:i"; - s2 = local; + s2 = m_local; s2 += "/command:o"; //ok = Network::connect(s2.c_str(), s1.c_str(), carrier); // ok=Network::connect(command_p.getName(), s1.c_str(), carrier); //doesn't take into consideration possible YARP_PORT_PREFIX on local ports - ok = command_p.addOutput(s1, carrier); + ok = command_p.addOutput(s1, m_carrier); if (!ok) { yCError(REMOTECONTROLBOARD, "Problem connecting to %s, is the remote device available?", s1.c_str()); connectionProblem = true; } // set the QoS preferences for the 'command' port - if (config.check("local_qos") || config.check("remote_qos")) { + if (m_local_qos_enable || m_remote_qos_enable) { NetworkBase::setConnectionQos(command_p.getName(), s1, localQos, remoteQos, false); } - s1 = remote; + s1 = m_remote; s1 += "/stateExt:o"; - s2 = local; + s2 = m_local; s2 += "/stateExt:i"; // not checking return value for now since it is wip (different machines can have different compilation flags - ok = Network::connect(s1, extendedIntputStatePort.getName(), carrier); + ok = Network::connect(s1, extendedIntputStatePort.getName(), m_carrier); if (ok) { // set the QoS preferences for the 'state' port - if (config.check("local_qos") || config.check("remote_qos")) { + if (m_local_qos_enable || m_remote_qos_enable) { NetworkBase::setConnectionQos(s1, extendedIntputStatePort.getName(), remoteQos, localQos, false); } } @@ -332,7 +307,7 @@ bool RemoteControlBoard::open(Searchable& config) state_buffer.setStrict(false); command_buffer.attach(command_p); - if (!checkProtocolVersion(config.check("ignoreProtocolCheck"))) + if (!checkProtocolVersion(m_ignoreProtocolCheck)) { yCError(REMOTECONTROLBOARD) << "checkProtocolVersion failed"; command_buffer.detach(); @@ -343,7 +318,7 @@ bool RemoteControlBoard::open(Searchable& config) } if (!isLive()) { - if (remote!="") { + if (m_remote!="") { yCError(REMOTECONTROLBOARD, "Problems with obtaining the number of controlled axes"); command_buffer.detach(); rpc_p.close(); @@ -353,13 +328,11 @@ bool RemoteControlBoard::open(Searchable& config) } } - if (config.check("diagnostic")) + if (m_diagnostic) { diagnosticThread = new DiagnosticThread(DIAGNOSTIC_THREAD_PERIOD); diagnosticThread->setOwner(&extendedIntputStatePort); diagnosticThread->start(); - } else { - diagnosticThread = nullptr; } // allocate memory for helper struct diff --git a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.h b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.h index 549d73f352b..ca8116037c1 100644 --- a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.h +++ b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard.h @@ -34,6 +34,7 @@ #include #include "stateExtendedReader.h" +#include "RemoteControlBoard_ParamsParser.h" struct ProtocolVersion { @@ -54,14 +55,7 @@ class DiagnosticThread; * to use a device exposing controlboard method even from a different process (or even computer) * from the one that opened the controlboard device. * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:-----:|:-------------:|:-----------: |:----------------------------------------------:|:-----:| -* | remote | - | string | - | - | Yes | Prefix of the port to which to connect. | | -* | local | - | string | - | - | Yes | Port prefix of the port opened by this device. | | -* | writeStrict | - | string | - | See note | No | | | -* | carrier | - | string | - | udp | No | Specify the carrier used for reading state and sending references. This option does not change the carrier used by rpc, that is hardcoded to tcp. | | -* +* Parameters required by this device are shown in class: RemoteControlBoard_ParamsParser */ class RemoteControlBoard : public yarp::dev::IPidControl, @@ -85,7 +79,8 @@ class RemoteControlBoard : public yarp::dev::IRemoteVariables, public yarp::dev::IPWMControl, public yarp::dev::ICurrentControl, - public yarp::dev::IJointFault + public yarp::dev::IJointFault, + public RemoteControlBoard_ParamsParser { protected: yarp::os::Port rpc_p; @@ -106,8 +101,6 @@ class RemoteControlBoard : // yarp::os::Port extendedIntputStatePort; // Port /stateExt:i reading the state of the joints yarp::dev::impl::jointData last_wholePart; // tmp to store last received data for whole part - std::string remote; - std::string local; mutable Stamp lastStamp; //this is shared among all calls that read encoders size_t nj{0}; bool njIsKnown{false}; diff --git a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.cpp b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.cpp new file mode 100644 index 00000000000..480d0399d5d --- /dev/null +++ b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.cpp @@ -0,0 +1,347 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#include "RemoteControlBoard_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(RemoteControlBoardParamsCOMPONENT, "yarp.device.RemoteControlBoard") +} + + +RemoteControlBoard_ParamsParser::RemoteControlBoard_ParamsParser() +{ +} + + +std::vector RemoteControlBoard_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("remote"); + params.push_back("local"); + params.push_back("writeStrict"); + params.push_back("carrier"); + params.push_back("timeout"); + params.push_back("local_qos::enable"); + params.push_back("local_qos::thread_priority"); + params.push_back("local_qos::thread_policy"); + params.push_back("local_qos::packet_priority"); + params.push_back("remote_qos::enable"); + params.push_back("remote_qos::thread_priority"); + params.push_back("remote_qos::thread_policy"); + params.push_back("remote_qos::packet_priority"); + params.push_back("ignoreProtocolCheck"); + params.push_back("diagnostic"); + return params; +} + + +bool RemoteControlBoard_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(RemoteControlBoardParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(RemoteControlBoardParamsCOMPONENT) << "Description of the parameter: Prefix of the port to which to connect."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(RemoteControlBoardParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(RemoteControlBoardParamsCOMPONENT) << "Description of the parameter: Port prefix of the port opened by this device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter writeStrict + { + if (config.check("writeStrict")) + { + m_writeStrict = config.find("writeStrict").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'writeStrict' using value:" << m_writeStrict; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'writeStrict' using DEFAULT value:" << m_writeStrict; + } + prop_check.unput("writeStrict"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + //Parser of parameter timeout + { + if (config.check("timeout")) + { + m_timeout = config.find("timeout").asFloat32(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'timeout' using value:" << m_timeout; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'timeout' using DEFAULT value:" << m_timeout; + } + prop_check.unput("timeout"); + } + + //Parser of parameter local_qos::enable + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("local_qos"); + if (sectionp.check("enable")) + { + m_local_qos_enable = sectionp.find("enable").asBool(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::enable' using value:" << m_local_qos_enable; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::enable' using DEFAULT value:" << m_local_qos_enable; + } + prop_check.unput("local_qos::enable"); + } + + //Parser of parameter local_qos::thread_priority + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("local_qos"); + if (sectionp.check("thread_priority")) + { + m_local_qos_thread_priority = sectionp.find("thread_priority").asInt64(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::thread_priority' using value:" << m_local_qos_thread_priority; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::thread_priority' using DEFAULT value:" << m_local_qos_thread_priority; + } + prop_check.unput("local_qos::thread_priority"); + } + + //Parser of parameter local_qos::thread_policy + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("local_qos"); + if (sectionp.check("thread_policy")) + { + m_local_qos_thread_policy = sectionp.find("thread_policy").asInt64(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::thread_policy' using value:" << m_local_qos_thread_policy; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::thread_policy' using DEFAULT value:" << m_local_qos_thread_policy; + } + prop_check.unput("local_qos::thread_policy"); + } + + //Parser of parameter local_qos::packet_priority + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("local_qos"); + if (sectionp.check("packet_priority")) + { + m_local_qos_packet_priority = sectionp.find("packet_priority").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::packet_priority' using value:" << m_local_qos_packet_priority; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'local_qos::packet_priority' using DEFAULT value:" << m_local_qos_packet_priority; + } + prop_check.unput("local_qos::packet_priority"); + } + + //Parser of parameter remote_qos::enable + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("remote_qos"); + if (sectionp.check("enable")) + { + m_remote_qos_enable = sectionp.find("enable").asBool(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::enable' using value:" << m_remote_qos_enable; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::enable' using DEFAULT value:" << m_remote_qos_enable; + } + prop_check.unput("remote_qos::enable"); + } + + //Parser of parameter remote_qos::thread_priority + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("remote_qos"); + if (sectionp.check("thread_priority")) + { + m_remote_qos_thread_priority = sectionp.find("thread_priority").asInt64(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::thread_priority' using value:" << m_remote_qos_thread_priority; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::thread_priority' using DEFAULT value:" << m_remote_qos_thread_priority; + } + prop_check.unput("remote_qos::thread_priority"); + } + + //Parser of parameter remote_qos::thread_policy + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("remote_qos"); + if (sectionp.check("thread_policy")) + { + m_remote_qos_thread_policy = sectionp.find("thread_policy").asInt64(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::thread_policy' using value:" << m_remote_qos_thread_policy; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::thread_policy' using DEFAULT value:" << m_remote_qos_thread_policy; + } + prop_check.unput("remote_qos::thread_policy"); + } + + //Parser of parameter remote_qos::packet_priority + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("remote_qos"); + if (sectionp.check("packet_priority")) + { + m_remote_qos_packet_priority = sectionp.find("packet_priority").asString(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::packet_priority' using value:" << m_remote_qos_packet_priority; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'remote_qos::packet_priority' using DEFAULT value:" << m_remote_qos_packet_priority; + } + prop_check.unput("remote_qos::packet_priority"); + } + + //Parser of parameter ignoreProtocolCheck + { + if (config.check("ignoreProtocolCheck")) + { + m_ignoreProtocolCheck = config.find("ignoreProtocolCheck").asBool(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'ignoreProtocolCheck' using value:" << m_ignoreProtocolCheck; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'ignoreProtocolCheck' using DEFAULT value:" << m_ignoreProtocolCheck; + } + prop_check.unput("ignoreProtocolCheck"); + } + + //Parser of parameter diagnostic + { + if (config.check("diagnostic")) + { + m_diagnostic = config.find("diagnostic").asBool(); + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'diagnostic' using value:" << m_diagnostic; + } + else + { + yCInfo(RemoteControlBoardParamsCOMPONENT) << "Parameter 'diagnostic' using DEFAULT value:" << m_diagnostic; + } + prop_check.unput("diagnostic"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(RemoteControlBoardParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(RemoteControlBoardParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string RemoteControlBoard_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: RemoteControlBoard\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'remote': Prefix of the port to which to connect.\n"); + doc = doc + std::string("'local': Port prefix of the port opened by this device.\n"); + doc = doc + std::string("'writeStrict': It can be 'on' or 'off'\n"); + doc = doc + std::string("'carrier': carrier used for streaming robot state\n"); + doc = doc + std::string("'timeout': timeout for the input port which receives the streamed robot state\n"); + doc = doc + std::string("'local_qos::enable': Enable the usage of local Qos\n"); + doc = doc + std::string("'local_qos::thread_priority': Local Qos. See https://yarp.it/latest/channelprioritization.html\n"); + doc = doc + std::string("'local_qos::thread_policy': Local Qos. See https://yarp.it/latest/channelprioritization.html\n"); + doc = doc + std::string("'local_qos::packet_priority': Local Qos. See https://yarp.it/latest/channelprioritization.html\n"); + doc = doc + std::string("'remote_qos::enable': Enable the usage of remote Qos\n"); + doc = doc + std::string("'remote_qos::thread_priority': Remote Qos. See https://yarp.it/latest/channelprioritization.html\n"); + doc = doc + std::string("'remote_qos::thread_policy': Remote Qos. See https://yarp.it/latest/channelprioritization.html.\n"); + doc = doc + std::string("'remote_qos::packet_priority': Remote Qos. See https://yarp.it/latest/channelprioritization.html.\n"); + doc = doc + std::string("'ignoreProtocolCheck': For development purpose only\n"); + doc = doc + std::string("'diagnostic': For development purpose only\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device remote_controlboard --remote --local --writeStrict --carrier udp --timeout 0.5 --local_qos::enable false --local_qos::thread_priority 0 --local_qos::thread_policy 0 --local_qos::packet_priority --remote_qos::enable false --remote_qos::thread_priority 0 --remote_qos::thread_policy 0 --remote_qos::packet_priority --ignoreProtocolCheck false --diagnostic false\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device remote_controlboard --remote --local \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.h b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.h new file mode 100644 index 00000000000..07f13141d5c --- /dev/null +++ b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_ParamsParser.h @@ -0,0 +1,111 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#ifndef REMOTECONTROLBOARD_PARAMSPARSER_H +#define REMOTECONTROLBOARD_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class RemoteControlBoard. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:-------------------:|:------:|:-----:|:-------------:|:--------:|:------------------------------------------------------------------:|:------------------:| +* | - | remote | string | - | - | 1 | Prefix of the port to which to connect. | - | +* | - | local | string | - | - | 1 | Port prefix of the port opened by this device. | - | +* | - | writeStrict | string | - | - | 0 | It can be 'on' or 'off' | See implementation | +* | - | carrier | string | - | udp | 0 | carrier used for streaming robot state | - | +* | - | timeout | float | - | 0.5 | 0 | timeout for the input port which receives the streamed robot state | - | +* | local_qos | enable | bool | - | false | 0 | Enable the usage of local Qos | - | +* | local_qos | thread_priority | int | - | 0 | 0 | Local Qos. See https://yarp.it/latest/channelprioritization.html | - | +* | local_qos | thread_policy | int | - | 0 | 0 | Local Qos. See https://yarp.it/latest/channelprioritization.html | - | +* | local_qos | packet_priority | string | - | - | 0 | Local Qos. See https://yarp.it/latest/channelprioritization.html | - | +* | remote_qos | enable | bool | - | false | 0 | Enable the usage of remote Qos | - | +* | remote_qos | thread_priority | int | - | 0 | 0 | Remote Qos. See https://yarp.it/latest/channelprioritization.html | - | +* | remote_qos | thread_policy | int | - | 0 | 0 | Remote Qos. See https://yarp.it/latest/channelprioritization.html. | - | +* | remote_qos | packet_priority | string | - | - | 0 | Remote Qos. See https://yarp.it/latest/channelprioritization.html. | - | +* | - | ignoreProtocolCheck | bool | - | false | 0 | For development purpose only | - | +* | - | diagnostic | bool | - | false | 0 | For development purpose only | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device remote_controlboard --remote --local --writeStrict --carrier udp --timeout 0.5 --local_qos::enable false --local_qos::thread_priority 0 --local_qos::thread_policy 0 --local_qos::packet_priority --remote_qos::enable false --remote_qos::thread_priority 0 --remote_qos::thread_policy 0 --remote_qos::packet_priority --ignoreProtocolCheck false --diagnostic false +* \endcode +* +* \code{.unparsed} +* yarpdev --device remote_controlboard --remote --local +* \endcode +* +*/ + +class RemoteControlBoard_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + RemoteControlBoard_ParamsParser(); + ~RemoteControlBoard_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"RemoteControlBoard"}; + const std::string m_device_name = {"remote_controlboard"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_remote_defaultValue = {""}; + const std::string m_local_defaultValue = {""}; + const std::string m_writeStrict_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"udp"}; + const std::string m_timeout_defaultValue = {"0.5"}; + const std::string m_local_qos_enable_defaultValue = {"false"}; + const std::string m_local_qos_thread_priority_defaultValue = {"0"}; + const std::string m_local_qos_thread_policy_defaultValue = {"0"}; + const std::string m_local_qos_packet_priority_defaultValue = {""}; + const std::string m_remote_qos_enable_defaultValue = {"false"}; + const std::string m_remote_qos_thread_priority_defaultValue = {"0"}; + const std::string m_remote_qos_thread_policy_defaultValue = {"0"}; + const std::string m_remote_qos_packet_priority_defaultValue = {""}; + const std::string m_ignoreProtocolCheck_defaultValue = {"false"}; + const std::string m_diagnostic_defaultValue = {"false"}; + + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_writeStrict = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + std::string m_carrier = {"udp"}; + float m_timeout = {0.5}; + bool m_local_qos_enable = {false}; + int m_local_qos_thread_priority = {0}; + int m_local_qos_thread_policy = {0}; + std::string m_local_qos_packet_priority = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + bool m_remote_qos_enable = {false}; + int m_remote_qos_thread_priority = {0}; + int m_remote_qos_thread_policy = {0}; + std::string m_remote_qos_packet_priority = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + bool m_ignoreProtocolCheck = {false}; + bool m_diagnostic = {false}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_params.md b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_params.md new file mode 100644 index 00000000000..2ca95e99d98 --- /dev/null +++ b/src/devices/networkWrappers/RemoteControlBoard/RemoteControlBoard_params.md @@ -0,0 +1,15 @@ +* | | remote | string | - | - | Yes | Prefix of the port to which to connect. | | +* | | local | string | - | - | Yes | Port prefix of the port opened by this device. | | +* | | writeStrict | string | - | - | No | It can be 'on' or 'off' | See implementation | +* | | carrier | string | - | udp | No | carrier used for streaming robot state | | +* | | timeout | float | - | 0.5 | No | timeout for the input port which receives the streamed robot state | | +* | local_qos | enable | bool | - | false | No | Enable the usage of local Qos | | +* | local_qos | thread_priority | int | - | 0 | No | Local Qos. See https://yarp.it/latest/channelprioritization.html | | +* | local_qos | thread_policy | int | - | 0 | No | Local Qos. See https://yarp.it/latest/channelprioritization.html | | +* | local_qos | packet_priority | string | - | | No | Local Qos. See https://yarp.it/latest/channelprioritization.html | | +* | remote_qos | enable | bool | - | false | No | Enable the usage of remote Qos | | +* | remote_qos | thread_priority | int | - | 0 | No | Remote Qos. See https://yarp.it/latest/channelprioritization.html | | +* | remote_qos | thread_policy | int | - | 0 | No | Remote Qos. See https://yarp.it/latest/channelprioritization.html. | | +* | remote_qos | packet_priority | string | - | | No | Remote Qos. See https://yarp.it/latest/channelprioritization.html. | | +* | | ignoreProtocolCheck | bool | - | false | No | For development purpose only | | +* | | diagnostic | bool | - | false | No | For development purpose only | | diff --git a/src/devices/networkWrappers/RobotDescriptionClient/CMakeLists.txt b/src/devices/networkWrappers/RobotDescriptionClient/CMakeLists.txt index 719970892b9..7ebf0fddb95 100644 --- a/src/devices/networkWrappers/RobotDescriptionClient/CMakeLists.txt +++ b/src/devices/networkWrappers/RobotDescriptionClient/CMakeLists.txt @@ -5,6 +5,7 @@ yarp_prepare_plugin(robotDescriptionClient CATEGORY device TYPE RobotDescriptionClient INCLUDE RobotDescriptionClient.h + GENERATE_PARSER DEFAULT ON ) @@ -15,6 +16,8 @@ if(NOT SKIP_robotDescriptionClient) PRIVATE RobotDescriptionClient.cpp RobotDescriptionClient.h + RobotDescriptionClient_ParamsParser.cpp + RobotDescriptionClient_ParamsParser.h ) target_link_libraries(yarp_robotDescriptionClient diff --git a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.cpp b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.cpp index 08326371185..4d82f83cc42 100644 --- a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.cpp +++ b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.cpp @@ -25,42 +25,21 @@ YARP_LOG_COMPONENT(ROBOTDESCRIPTIONCLIENT, "yarp.device.robotDescriptionClient") bool RobotDescriptionClient::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_remote_name.clear(); + if (!this->parseParams(config)) { return false; } - m_local_name = config.find("local").asString(); - m_remote_name = config.find("remote").asString(); - - if (m_local_name == "") - { - yCError(ROBOTDESCRIPTIONCLIENT, "open(): Invalid local name"); - return false; - } - - if (m_remote_name == "") - { - yCError(ROBOTDESCRIPTIONCLIENT, "open(): Invalid remote name"); - return false; - } - - std::string local_rpc, remote_rpc; - - local_rpc = m_local_name + "/rpc"; - remote_rpc = m_remote_name + "/rpc"; - - if (!m_rpc_port.open(local_rpc)) + if (!m_rpc_port.open(m_local)) { - yCError(ROBOTDESCRIPTIONCLIENT, "open(): Could not open rpc port %s, check network", local_rpc.c_str()); + yCError(ROBOTDESCRIPTIONCLIENT, "open(): Could not open rpc port %s, check network", m_local.c_str()); return false; } bool ok = true; - ok = Network::connect(local_rpc, remote_rpc); + ok = Network::connect(m_local, m_remote); if (!ok) { - yCError(ROBOTDESCRIPTIONCLIENT, "open(): Could not connect to %s", remote_rpc.c_str()); + yCError(ROBOTDESCRIPTIONCLIENT, "open(): Could not connect to %s", m_remote.c_str()); return false; } diff --git a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.h b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.h index 8145d29876d..fba06dcdc7e 100644 --- a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.h +++ b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient.h @@ -18,27 +18,24 @@ #include #include +#include "RobotDescriptionClient_ParamsParser.h" + /** * @ingroup dev_impl_network_clients * * \brief `robotDescriptionClient`: This client device is used to connect to a robotDescriptionServer and ask info about the currently opened devices. * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:---------------------------------------------------------------------------:|:-----:| -* | local | - | string | - | - | Yes | prefix of the port opened by the device, like /my_module/descriptionClient | MUST start with a '/' character. /rpc is automatically appended. | -* | remote | - | string | - | - | Yes | prefix of the port opened by the robotDescriptionServer, like /descriptionServer. | MUST start with a '/' character. /rpc is automatically appended. | +* Parameters required by this device are shown in class: RobotDescriptionClient_ParamsParser */ class RobotDescriptionClient : public yarp::dev::DeviceDriver, - public yarp::dev::IRobotDescription + public yarp::dev::IRobotDescription, + public RobotDescriptionClient_ParamsParser { protected: std::mutex m_mutex; yarp::os::Port m_rpc_port; - std::string m_local_name; - std::string m_remote_name; public: /* DeviceDriver methods */ diff --git a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.cpp b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.cpp new file mode 100644 index 00000000000..d496fd279d2 --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "RobotDescriptionClient_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(RobotDescriptionClientParamsCOMPONENT, "yarp.device.RobotDescriptionClient") +} + + +RobotDescriptionClient_ParamsParser::RobotDescriptionClient_ParamsParser() +{ +} + + +std::vector RobotDescriptionClient_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool RobotDescriptionClient_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(RobotDescriptionClientParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(RobotDescriptionClientParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(RobotDescriptionClientParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(RobotDescriptionClientParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(RobotDescriptionClientParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(RobotDescriptionClientParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(RobotDescriptionClientParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the device connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(RobotDescriptionClientParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(RobotDescriptionClientParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string RobotDescriptionClient_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: RobotDescriptionClient\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the device connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device robotDescriptionClient --local /robotDescriptionClient/rpc --remote /robotDescriptionServer/rpc\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device robotDescriptionClient --local /robotDescriptionClient/rpc --remote /robotDescriptionServer/rpc\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.h b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.h new file mode 100644 index 00000000000..5fc756a4a0e --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef ROBOTDESCRIPTIONCLIENT_PARAMSPARSER_H +#define ROBOTDESCRIPTIONCLIENT_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class RobotDescriptionClient. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:---------------------------:|:--------:|:--------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | /robotDescriptionClient/rpc | 1 | Full port name opened by the device. | - | +* | - | remote | string | - | /robotDescriptionServer/rpc | 1 | Full port name of the port opened on the server side, to which the device connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device robotDescriptionClient --local /robotDescriptionClient/rpc --remote /robotDescriptionServer/rpc +* \endcode +* +* \code{.unparsed} +* yarpdev --device robotDescriptionClient --local /robotDescriptionClient/rpc --remote /robotDescriptionServer/rpc +* \endcode +* +*/ + +class RobotDescriptionClient_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + RobotDescriptionClient_ParamsParser(); + ~RobotDescriptionClient_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"RobotDescriptionClient"}; + const std::string m_device_name = {"robotDescriptionClient"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {"/robotDescriptionClient/rpc"}; + const std::string m_remote_defaultValue = {"/robotDescriptionServer/rpc"}; + + std::string m_local = {"/robotDescriptionClient/rpc"}; + std::string m_remote = {"/robotDescriptionServer/rpc"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_params.md b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_params.md new file mode 100644 index 00000000000..cf29f7e7948 --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionClient/RobotDescriptionClient_params.md @@ -0,0 +1,2 @@ +* | | local | string | - | /robotDescriptionClient/rpc | Yes | Full port name opened by the device. | | +* | | remote | string | - | /robotDescriptionServer/rpc | Yes | Full port name of the port opened on the server side, to which the device connects to. | | diff --git a/src/devices/networkWrappers/RobotDescriptionServer/CMakeLists.txt b/src/devices/networkWrappers/RobotDescriptionServer/CMakeLists.txt index 7165bfa7055..f3ba17a66ab 100644 --- a/src/devices/networkWrappers/RobotDescriptionServer/CMakeLists.txt +++ b/src/devices/networkWrappers/RobotDescriptionServer/CMakeLists.txt @@ -5,6 +5,7 @@ yarp_prepare_plugin(robotDescriptionServer CATEGORY device TYPE RobotDescriptionServer INCLUDE RobotDescriptionServer.h + GENERATE_PARSER DEFAULT ON ) @@ -15,6 +16,8 @@ if(NOT SKIP_robotDescriptionServer) PRIVATE RobotDescriptionServer.cpp RobotDescriptionServer.h + RobotDescriptionServer_ParamsParser.cpp + RobotDescriptionServer_ParamsParser.h ) target_link_libraries(yarp_robotDescriptionServer diff --git a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.cpp b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.cpp index 40bbe3cb860..8af8ab31d4f 100644 --- a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.cpp +++ b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.cpp @@ -24,21 +24,11 @@ YARP_LOG_COMPONENT(ROBOTDESCRIPTIONSERVER, "yarp.device.robotDescriptionServer") bool RobotDescriptionServer::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_local_name = config.find("local").asString(); + if (!this->parseParams(config)) { return false; } - if (m_local_name == "") + if (!m_rpc_port.open(m_local)) { - yCError(ROBOTDESCRIPTIONSERVER, "open(): Invalid local name"); - return false; - } - - std::string local_rpc = m_local_name; - local_rpc += "/rpc"; - - if (!m_rpc_port.open(local_rpc)) - { - yCError(ROBOTDESCRIPTIONSERVER, "open(): Could not open rpc port %s, check network", local_rpc.c_str()); + yCError(ROBOTDESCRIPTIONSERVER, "open(): Could not open rpc port %s, check network", m_local.c_str()); return false; } diff --git a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.h b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.h index e1365617e6b..9cdfdadd802 100644 --- a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.h +++ b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer.h @@ -18,30 +18,29 @@ #include #include +#include "RobotDescriptionServer_ParamsParser.h" + /** * @ingroup dev_impl_wrapper * * \brief `robotDescriptionServer`: This device is a storage which contains a list of the currently opened device drivers. * * yarprobotinterfaces adds/removes devices to the storage using attachAll()/detachAll() methods. -* A robotDescriptionClient devices can bused by the user to retrieve information about the currently opened devices. +* A robotDescriptionClient devices can used by the user to retrieve information about the currently opened devices. * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:-----------------------------------------------------------------:|:-----:| -* | local | - | string | - | - | Yes | prefix of the port opened by the device, like /descriptionServer | MUST start with a '/' character. /rpc is automatically appended. | +* Parameters required by this device are shown in class: RobotDescriptionServer_ParamsParser */ class RobotDescriptionServer : public yarp::dev::DeviceDriver, public yarp::os::PortReader, - public yarp::dev::IMultipleWrapper + public yarp::dev::IMultipleWrapper, + public RobotDescriptionServer_ParamsParser { protected: std::mutex m_external_mutex; std::mutex m_internal_mutex; yarp::os::Port m_rpc_port; - std::string m_local_name; std::vector m_robot_devices; public: diff --git a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.cpp b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.cpp new file mode 100644 index 00000000000..072b3f84212 --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.cpp @@ -0,0 +1,105 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "RobotDescriptionServer_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(RobotDescriptionServerParamsCOMPONENT, "yarp.device.RobotDescriptionServer") +} + + +RobotDescriptionServer_ParamsParser::RobotDescriptionServer_ParamsParser() +{ +} + + +std::vector RobotDescriptionServer_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + return params; +} + + +bool RobotDescriptionServer_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(RobotDescriptionServerParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(RobotDescriptionServerParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(RobotDescriptionServerParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(RobotDescriptionServerParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(RobotDescriptionServerParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(RobotDescriptionServerParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string RobotDescriptionServer_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: RobotDescriptionServer\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device robotDescriptionServer --local /robotDescriptionServer/rpc\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device robotDescriptionServer --local /robotDescriptionServer/rpc\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.h b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.h new file mode 100644 index 00000000000..fbddcf61b9d --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef ROBOTDESCRIPTIONSERVER_PARAMSPARSER_H +#define ROBOTDESCRIPTIONSERVER_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class RobotDescriptionServer. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:---------------------------:|:--------:|:------------------------------------:|:-----:| +* | - | local | string | - | /robotDescriptionServer/rpc | 1 | Full port name opened by the device. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device robotDescriptionServer --local /robotDescriptionServer/rpc +* \endcode +* +* \code{.unparsed} +* yarpdev --device robotDescriptionServer --local /robotDescriptionServer/rpc +* \endcode +* +*/ + +class RobotDescriptionServer_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + RobotDescriptionServer_ParamsParser(); + ~RobotDescriptionServer_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"RobotDescriptionServer"}; + const std::string m_device_name = {"robotDescriptionServer"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {"/robotDescriptionServer/rpc"}; + + std::string m_local = {"/robotDescriptionServer/rpc"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_params.md b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_params.md new file mode 100644 index 00000000000..453c6e977d9 --- /dev/null +++ b/src/devices/networkWrappers/RobotDescriptionServer/RobotDescriptionServer_params.md @@ -0,0 +1 @@ +* | | local | string | - | /robotDescriptionServer/rpc | Yes | Full port name opened by the device. | | diff --git a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.cpp b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.cpp index 73ebef932ce..573716a7c96 100644 --- a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.cpp +++ b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.cpp @@ -23,13 +23,10 @@ using namespace yarp::os; namespace { YARP_LOG_COMPONENT(AUDIOPLAYERWRAPPER, "yarp.device.AudioPlayerWrapper") constexpr double DEFAULT_THREAD_PERIOD = 0.02; // seconds -constexpr double DEFAULT_BUFFER_DELAY = 5.0; // seconds } AudioPlayerWrapper::AudioPlayerWrapper() : - PeriodicThread(DEFAULT_THREAD_PERIOD), - m_period(DEFAULT_THREAD_PERIOD), - m_buffer_delay(DEFAULT_BUFFER_DELAY) + PeriodicThread(DEFAULT_THREAD_PERIOD) { } @@ -160,61 +157,32 @@ bool AudioPlayerWrapper::threadInit() bool AudioPlayerWrapper::open(yarp::os::Searchable &config) { - m_config.fromString(config.toString()); + if (!parseParams(config)) { return false; } - if (config.check("debug")) - { - m_debug_enabled = true; - } - - if (config.check("period")) - { - m_period = config.find("period").asFloat64(); - } - - std::string name = "/audioPlayerWrapper"; - if (config.check("name")) - { - name = config.find("name").asString(); - } - m_audioInPortName = name + "/audio:i"; - m_rpcPortName = name + "/rpc:i"; - m_statusPortName = name + "/status:o"; + std::string audioInPortName = m_name + "/audio:i"; + std::string rpcPortName = m_name + "/rpc:i"; + std::string statusPortName = m_name + "/status:o"; - if(!initialize_YARP(config) ) + if (!m_audioInPort.open(audioInPortName)) { - yCError(AUDIOPLAYERWRAPPER) << "Error initializing YARP ports"; + yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", audioInPortName.c_str()); return false; } - - if (config.check("playback_network_buffer_size")) + if (!m_statusPort.open(statusPortName)) { - m_buffer_delay = config.find("playback_network_buffer_size").asFloat64(); - } - yCInfo(AUDIOPLAYERWRAPPER) << "Using a 'playback_network_buffer_size' of" << m_buffer_delay << "s"; - yCInfo(AUDIOPLAYERWRAPPER) << "Increase this value to robustify the real-time audio stream (it will increase latency too)"; - - return true; -} - -bool AudioPlayerWrapper::initialize_YARP(yarp::os::Searchable ¶ms) -{ - if (!m_audioInPort.open(m_audioInPortName)) - { - yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", m_audioInPortName.c_str()); + yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", statusPortName.c_str()); return false; } - if (!m_statusPort.open(m_statusPortName)) + if (!m_rpcPort.open(rpcPortName)) { - yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", m_statusPortName.c_str()); - return false; - } - if (!m_rpcPort.open(m_rpcPortName)) - { - yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", m_rpcPortName.c_str()); + yCError(AUDIOPLAYERWRAPPER, "Failed to open port %s", rpcPortName.c_str()); return false; } m_rpcPort.setReader(*this); + + yCInfo(AUDIOPLAYERWRAPPER) << "Using a 'playback_network_buffer_size' of" << m_playback_network_buffer_size << "s"; + yCInfo(AUDIOPLAYERWRAPPER) << "Increase this value to robustify the real-time audio stream (it will increase latency too)"; + return true; } @@ -232,7 +200,7 @@ void AudioPlayerWrapper::afterStart(bool success) { if(success) { - if (m_config.check("start")) + if (m_start) { m_irender->startPlayback(); m_irender->isPlaying(m_isPlaying); @@ -247,7 +215,7 @@ void AudioPlayerWrapper::run() Sound* s = m_audioInPort.read(false); if (s != nullptr) { - if (m_debug_enabled) + if (m_debug) { yCDebug(AUDIOPLAYERWRAPPER) << "Received sound of:" << s->getSamples() << " samples"; } @@ -255,7 +223,7 @@ void AudioPlayerWrapper::run() scheduled_sound_type ss; #if 1 //This is simple, but we don't know how big the sound is... - ss.scheduled_time = current_time + m_buffer_delay; + ss.scheduled_time = current_time + m_playback_network_buffer_size; #elif 0 //This is ok, but it doesn't work if the sounds have different durations... ss.scheduled_time = current_time + 5.0 * s.getDuration(); @@ -273,7 +241,7 @@ void AudioPlayerWrapper::run() } m_irender->getPlaybackAudioBufferCurrentSize(m_current_buffer_size); - if (m_debug_enabled) + if (m_debug) { static double printer_wdt = yarp::os::Time::now(); if (yarp::os::Time::now() - printer_wdt > 1.0) diff --git a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.h b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.h index 53a9fc05e49..874b3fd20d1 100644 --- a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.h +++ b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper.h @@ -32,19 +32,15 @@ #include #include +#include "AudioPlayerWrapper_ParamsParser.h" + /** * @ingroup dev_impl_wrapper * * \brief `AudioPlayerWrapper`: A Wrapper which receives audio streams from a network port and sends it to device for playback * \section AudioPlayerWrapper_device_parameters Description of input parameters - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-----------------------:|:--------------------------: |:--------------------------------------------------------------------------:|:-----:| - * | name | - | string | - | /audioPlayerWrapper | No | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:i, xxx/rpc:i, xxx/status:o, ports are opened | - * | period | - | int | ms | 20 | No | period of the internal thread, in ms | default 20ms | - * | debug | - | bool | - | - | No | developers use only | | - * | playback_network_buffer_size | - | float | s | 5.0 | No | size of the audio buffer in seconds, increasing this value to robustify the real-time audio stream (it will increase latency too) | Audio playback will start when the buffer is full | - * | start | - | bool | - | false | No | automatically activates the playback when the device is started | if false, the playback is enabled via rpc port | + * + * Parameters required by this device are shown in class: AudioPlayerWrapper_ParamsParser * * See \ref AudioDoc for additional documentation on YARP audio. */ @@ -53,7 +49,8 @@ class AudioPlayerWrapper : public yarp::os::PeriodicThread, public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public AudioPlayerWrapper_ParamsParser { struct scheduled_sound_type @@ -86,25 +83,18 @@ class AudioPlayerWrapper : void run() override; private: - std::string m_rpcPortName; yarp::os::Port m_rpcPort; - std::string m_audioInPortName; yarp::os::BufferedPort m_audioInPort; - std::string m_statusPortName; yarp::os::Port m_statusPort; - yarp::os::Property m_config; yarp::dev::IAudioRender *m_irender = nullptr; yarp::os::Stamp m_lastStateStamp; yarp::dev::AudioBufferSize m_current_buffer_size; yarp::dev::AudioBufferSize m_max_buffer_size; std::queue m_sound_buffer; - double m_period; - double m_buffer_delay; - bool m_debug_enabled = false; + bool m_isPlaying = false; - bool initialize_YARP(yarp::os::Searchable &config); bool read(yarp::os::ConnectionReader& connection) override; }; diff --git a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.cpp b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.cpp new file mode 100644 index 00000000000..e2a8155b0f7 --- /dev/null +++ b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.cpp @@ -0,0 +1,167 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:43 2024 + + +#include "AudioPlayerWrapper_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(AudioPlayerWrapperParamsCOMPONENT, "yarp.device.AudioPlayerWrapper") +} + + +AudioPlayerWrapper_ParamsParser::AudioPlayerWrapper_ParamsParser() +{ +} + + +std::vector AudioPlayerWrapper_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + params.push_back("period"); + params.push_back("debug"); + params.push_back("playback_network_buffer_size"); + params.push_back("start"); + return params; +} + + +bool AudioPlayerWrapper_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat32(); + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter debug + { + if (config.check("debug")) + { + m_debug = config.find("debug").asBool(); + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'debug' using value:" << m_debug; + } + else + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'debug' using DEFAULT value:" << m_debug; + } + prop_check.unput("debug"); + } + + //Parser of parameter playback_network_buffer_size + { + if (config.check("playback_network_buffer_size")) + { + m_playback_network_buffer_size = config.find("playback_network_buffer_size").asFloat64(); + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'playback_network_buffer_size' using value:" << m_playback_network_buffer_size; + } + else + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'playback_network_buffer_size' using DEFAULT value:" << m_playback_network_buffer_size; + } + prop_check.unput("playback_network_buffer_size"); + } + + //Parser of parameter start + { + if (config.check("start")) + { + m_start = config.find("start").asBool(); + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'start' using value:" << m_start; + } + else + { + yCInfo(AudioPlayerWrapperParamsCOMPONENT) << "Parameter 'start' using DEFAULT value:" << m_start; + } + prop_check.unput("start"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(AudioPlayerWrapperParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(AudioPlayerWrapperParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string AudioPlayerWrapper_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: AudioPlayerWrapper\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': prefix of the ports opened by the device\n"); + doc = doc + std::string("'period': period of the internal thread, in s\n"); + doc = doc + std::string("'debug': developers use only\n"); + doc = doc + std::string("'playback_network_buffer_size': size of the audio buffer in seconds, increasing this value to robustify the real-time audio stream (it will increase latency too)\n"); + doc = doc + std::string("'start': automatically activates the playback when the device is started\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device AudioPlayerWrapper --name /audioPlayerWrapper --period 0.02 --debug false --playback_network_buffer_size 5.0 --start false\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device AudioPlayerWrapper\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.h b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.h new file mode 100644 index 00000000000..9def7a7bc15 --- /dev/null +++ b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_ParamsParser.h @@ -0,0 +1,81 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:43 2024 + + +#ifndef AUDIOPLAYERWRAPPER_PARAMSPARSER_H +#define AUDIOPLAYERWRAPPER_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class AudioPlayerWrapper. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:----------------------------:|:------:|:-----:|:-------------------:|:--------:|:---------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------:| +* | - | name | string | - | /audioPlayerWrapper | 0 | prefix of the ports opened by the device | xxx/audio:i, xxx/rpc:i, xxx/status:o, ports are opened | +* | - | period | float | s | 0.02 | 0 | period of the internal thread, in s | - | +* | - | debug | bool | - | false | 0 | developers use only | - | +* | - | playback_network_buffer_size | double | s | 5.0 | 0 | size of the audio buffer in seconds, increasing this value to robustify the real-time audio stream (it will increase latency too) | Audio playback will start when the buffer is full | +* | - | start | bool | - | false | 0 | automatically activates the playback when the device is started | if false, the playback is enabled via rpc port | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device AudioPlayerWrapper --name /audioPlayerWrapper --period 0.02 --debug false --playback_network_buffer_size 5.0 --start false +* \endcode +* +* \code{.unparsed} +* yarpdev --device AudioPlayerWrapper +* \endcode +* +*/ + +class AudioPlayerWrapper_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + AudioPlayerWrapper_ParamsParser(); + ~AudioPlayerWrapper_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"AudioPlayerWrapper"}; + const std::string m_device_name = {"AudioPlayerWrapper"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/audioPlayerWrapper"}; + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_debug_defaultValue = {"false"}; + const std::string m_playback_network_buffer_size_defaultValue = {"5.0"}; + const std::string m_start_defaultValue = {"false"}; + + std::string m_name = {"/audioPlayerWrapper"}; + float m_period = {0.02}; + bool m_debug = {false}; + double m_playback_network_buffer_size = {5.0}; + bool m_start = {false}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_params.md b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_params.md new file mode 100644 index 00000000000..28b59fda1b5 --- /dev/null +++ b/src/devices/networkWrappers/audioPlayerWrapper/AudioPlayerWrapper_params.md @@ -0,0 +1,5 @@ + * | | name | string | - | /audioPlayerWrapper | No | prefix of the ports opened by the device | xxx/audio:i, xxx/rpc:i, xxx/status:o, ports are opened | + * | | period | float | s | 0.02 | No | period of the internal thread, in s | | + * | | debug | bool | - | false | No | developers use only | | + * | | playback_network_buffer_size | double | s | 5.0 | No | size of the audio buffer in seconds, increasing this value to robustify the real-time audio stream (it will increase latency too) | Audio playback will start when the buffer is full | + * | | start | bool | - | false | No | automatically activates the playback when the device is started | if false, the playback is enabled via rpc port | diff --git a/src/devices/networkWrappers/audioPlayerWrapper/CMakeLists.txt b/src/devices/networkWrappers/audioPlayerWrapper/CMakeLists.txt index 9d9a6cf0800..a112cb53e2b 100644 --- a/src/devices/networkWrappers/audioPlayerWrapper/CMakeLists.txt +++ b/src/devices/networkWrappers/audioPlayerWrapper/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(AudioPlayerWrapper EXTRA_CONFIG WRAPPER=AudioPlayerWrapper DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_AudioPlayerWrapper) @@ -17,6 +18,8 @@ if(NOT SKIP_AudioPlayerWrapper) PRIVATE AudioPlayerWrapper.cpp AudioPlayerWrapper.h + AudioPlayerWrapper_ParamsParser.cpp + AudioPlayerWrapper_ParamsParser.h ) target_link_libraries(yarp_AudioPlayerWrapper diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.cpp b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.cpp similarity index 82% rename from src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.cpp rename to src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.cpp index eee135a4387..b22f9478a04 100644 --- a/src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.cpp +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "audioRecorder_nwc_yarp.h" +#include "AudioRecorder_nwc_yarp.h" #include #include @@ -51,33 +51,18 @@ inline bool InputPortProcessor::getLast(yarp::sig::Sound& data, Stamp &stmp) bool AudioRecorder_nwc_yarp::open(yarp::os::Searchable &config) { - yCDebug(AUDIORECORDER_NWC) << config.toString(); - std::string local_name = config.find("local").asString(); - std::string remote_name = config.find("remote").asString(); - std::string carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the stream connection with the server").asString(); - m_useStreaming = config.check("useStream"); + if (!this->parseParams(config)) { return false; } - if (local_name =="") - { - yCError(AUDIORECORDER_NWC, "open(): Invalid local name. --local parameter missing."); - return false; - } - if (remote_name =="") - { - yCError(AUDIORECORDER_NWC, "open(): Invalid remote name. --remote parameter missing."); - return false; - } - - std::string local_stream = local_name; + std::string local_stream = m_local; local_stream += "/data:i"; - std::string local_rpc = local_name; + std::string local_rpc = m_local; local_rpc += "/rpc"; - std::string remote_stream = remote_name; + std::string remote_stream = m_remote; remote_stream += "/data:o"; - std::string remote_rpc = remote_name; + std::string remote_rpc = m_remote; remote_rpc += "/rpc"; - if (m_useStreaming) + if (m_useStream) { if (!m_inputPort.open(local_stream)) { @@ -94,9 +79,9 @@ bool AudioRecorder_nwc_yarp::open(yarp::os::Searchable &config) } bool ok; - if (m_useStreaming) + if (m_useStream) { - ok=Network::connect(remote_stream.c_str(), local_stream.c_str(), carrier); + ok=Network::connect(remote_stream.c_str(), local_stream.c_str(), m_carrier); if (!ok) { yCError(AUDIORECORDER_NWC, "open(): Could not connect %s -> %s", remote_stream.c_str(), local_stream.c_str()); @@ -123,7 +108,7 @@ bool AudioRecorder_nwc_yarp::open(yarp::os::Searchable &config) bool AudioRecorder_nwc_yarp::close() { m_rpcPort.close(); - if (m_useStreaming) + if (m_useStream) { m_inputPort.close(); } @@ -201,7 +186,7 @@ bool AudioRecorder_nwc_yarp::getRecordingAudioBufferCurrentSize(yarp::dev::Aud bool AudioRecorder_nwc_yarp::getSound(yarp::sig::Sound& sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) { - if (m_useStreaming) + if (m_useStream) { yCError(AUDIORECORDER_NWC, "Unable to: getSound() streaming version not yet implemented"); return false; diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.h b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.h similarity index 68% rename from src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.h rename to src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.h index 1011bc8170c..bd23cb771ee 100644 --- a/src/devices/networkWrappers/audioRecorder_nwc_yarp/audioRecorder_nwc_yarp.h +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp.h @@ -17,6 +17,7 @@ #include "IAudioGrabberMsgs.h" #include +#include "AudioRecorder_nwc_yarp_ParamsParser.h" class InputPortProcessor : public yarp::os::BufferedPort { @@ -34,31 +35,26 @@ class InputPortProcessor : public yarp::os::BufferedPort }; /** -* @ingroup dev_impl_network_clients +* @ingroup dev_impl_nwc_yarp * * \brief `audioRecoder_nwc_yarp`: The client side of any IAudioGrabberSound capable device. * \section AudioRecorder_nwc_yarp_device_parameters Description of input parameters * Please note that the getSound() method is currently implemented as a RPC call and streaming functions are not yet implemented. * -* Parameters required by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| -* | local | - | string | - | - | Yes | Full port name opened by the audioRecoder_nwc_yarp device. | | -* | remote | - | string | - | - | Yes | Full port name of the port opened on the server side, to which the audioRecoder_nwc_yarp connects to. | | -* | carrier | - | string | - | tcp | No | The carrier used for the streaming connection with the server. | | +* Parameters required by this device are shown in class: AudioRecorder_nwc_yarp_ParamsParser * * See \ref AudioDoc for additional documentation on YARP audio. */ class AudioRecorder_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::IAudioGrabberSound + public yarp::dev::IAudioGrabberSound, + public AudioRecorder_nwc_yarp_ParamsParser { protected: InputPortProcessor m_inputPort; yarp::os::Port m_rpcPort; IAudioGrabberMsgs m_audiograb_RPC; std::mutex m_mutex; - bool m_useStreaming = false; public: diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..50e7baaf8b4 --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,155 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#include "AudioRecorder_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(AudioRecorder_nwc_yarpParamsCOMPONENT, "yarp.device.AudioRecorder_nwc_yarp") +} + + +AudioRecorder_nwc_yarp_ParamsParser::AudioRecorder_nwc_yarp_ParamsParser() +{ +} + + +std::vector AudioRecorder_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + params.push_back("carrier"); + params.push_back("useStream"); + return params; +} + + +bool AudioRecorder_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the audioRecoder_nwc_yarp device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the audioRecoder_nwc_yarp connects to."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + //Parser of parameter useStream + { + if (config.check("useStream")) + { + m_useStream = config.find("useStream").asBool(); + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'useStream' using value:" << m_useStream; + } + else + { + yCInfo(AudioRecorder_nwc_yarpParamsCOMPONENT) << "Parameter 'useStream' using DEFAULT value:" << m_useStream; + } + prop_check.unput("useStream"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(AudioRecorder_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(AudioRecorder_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string AudioRecorder_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: AudioRecorder_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the audioRecoder_nwc_yarp device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the audioRecoder_nwc_yarp connects to.\n"); + doc = doc + std::string("'carrier': The carrier used for the streaming connection with the server.\n"); + doc = doc + std::string("'useStream': If true, enables a streaming connection with the server. Otherwise only rpc is used\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device audioRecorder_nwc_yarp --local --remote --carrier fast_tcp --useStream false\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device audioRecorder_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..3788f882482 --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_ParamsParser.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef AUDIORECORDER_NWC_YARP_PARAMSPARSER_H +#define AUDIORECORDER_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class AudioRecorder_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the audioRecoder_nwc_yarp device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the audioRecoder_nwc_yarp connects to. | - | +* | - | carrier | string | - | fast_tcp | 0 | The carrier used for the streaming connection with the server. | - | +* | - | useStream | bool | - | false | 0 | If true, enables a streaming connection with the server. Otherwise only rpc is used | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device audioRecorder_nwc_yarp --local --remote --carrier fast_tcp --useStream false +* \endcode +* +* \code{.unparsed} +* yarpdev --device audioRecorder_nwc_yarp --local --remote +* \endcode +* +*/ + +class AudioRecorder_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + AudioRecorder_nwc_yarp_ParamsParser(); + ~AudioRecorder_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"AudioRecorder_nwc_yarp"}; + const std::string m_device_name = {"audioRecorder_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"fast_tcp"}; + const std::string m_useStream_defaultValue = {"false"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"fast_tcp"}; + bool m_useStream = {false}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_params.md b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_params.md new file mode 100644 index 00000000000..c20092ba8f5 --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/AudioRecorder_nwc_yarp_params.md @@ -0,0 +1,4 @@ +* | | local | string | - | - | Yes | Full port name opened by the audioRecoder_nwc_yarp device. | | +* | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the audioRecoder_nwc_yarp connects to. | | +* | | carrier | string | - | fast_tcp | No | The carrier used for the streaming connection with the server. | | +* | | useStream | bool | - | false | No | If true, enables a streaming connection with the server. Otherwise only rpc is used | | diff --git a/src/devices/networkWrappers/audioRecorder_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/audioRecorder_nwc_yarp/CMakeLists.txt index 7ce086a120d..6a5a6cfd343 100644 --- a/src/devices/networkWrappers/audioRecorder_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/audioRecorder_nwc_yarp/CMakeLists.txt @@ -4,7 +4,8 @@ yarp_prepare_plugin(audioRecorder_nwc_yarp CATEGORY device TYPE AudioRecorder_nwc_yarp - INCLUDE audioRecorder_nwc_yarp.h + INCLUDE AudioRecorder_nwc_yarp.h + GENERATE_PARSER DEFAULT ON ) @@ -13,8 +14,10 @@ if(NOT SKIP_audioRecorder_nwc_yarp) target_sources(yarp_audioRecorder_nwc_yarp PRIVATE - audioRecorder_nwc_yarp.cpp - audioRecorder_nwc_yarp.h + AudioRecorder_nwc_yarp.cpp + AudioRecorder_nwc_yarp.h + AudioRecorder_nwc_yarp_ParamsParser.cpp + AudioRecorder_nwc_yarp_ParamsParser.h ) target_link_libraries(yarp_audioRecorder_nwc_yarp diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.cpp b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.cpp index 5e80b90edca..1d517efa0e7 100644 --- a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.cpp +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.cpp @@ -12,19 +12,10 @@ using namespace yarp::os; namespace { YARP_LOG_COMPONENT(AUDIORECORDER_NWS_YARP, "yarp.device.audioRecorder_nws_yarp") -constexpr double DEFAULT_THREAD_PERIOD = 0.02; // seconds -constexpr size_t DEFAULT_MIN_NUMBER_OF_SAMPLES_OVER_NETWORK = 11250; -constexpr size_t DEFAULT_MAX_NUMBER_OF_SAMPLES_OVER_NETWORK = 11250; -constexpr double DEFAULT_GETSOUND_TIMEOUT = 1.0; - } -AudioRecorder_nws_yarp::AudioRecorder_nws_yarp() : - m_period(DEFAULT_THREAD_PERIOD), - m_min_number_of_samples_over_network(DEFAULT_MIN_NUMBER_OF_SAMPLES_OVER_NETWORK), - m_max_number_of_samples_over_network(DEFAULT_MAX_NUMBER_OF_SAMPLES_OVER_NETWORK), - m_getSound_timeout(DEFAULT_GETSOUND_TIMEOUT) +AudioRecorder_nws_yarp::AudioRecorder_nws_yarp() { m_stamp.update(); } @@ -36,44 +27,15 @@ AudioRecorder_nws_yarp::~AudioRecorder_nws_yarp() bool AudioRecorder_nws_yarp::open(yarp::os::Searchable& config) { - m_config.fromString(config.toString()); - - if (config.check("period")) - { - m_period = config.find("period").asFloat64(); - } - - // Get parameter samples_over_network - if (config.check("min_samples_over_network")) - { - m_min_number_of_samples_over_network = config.find("min_samples_over_network").asInt64(); - } - if (config.check("max_samples_over_network")) - { - m_max_number_of_samples_over_network = config.find("max_samples_over_network").asInt64(); - } - yCInfo(AUDIORECORDER_NWS_YARP) << "Wrapper configured to produce packets with the following size (in samples): " << - m_min_number_of_samples_over_network << " < samples < " << m_max_number_of_samples_over_network; - - // Get parameter samples_over_network - if (config.check("max_samples_timeout")) - { - m_getSound_timeout = config.find("max_samples_timeout").asFloat64(); - } - yCInfo(AUDIORECORDER_NWS_YARP) << "Wrapper configured with max_samples_timeout: " << m_getSound_timeout << "s"; + if (!this->parseParams(config)) { return false; } - // Set parameter send_sound_on_stop - if (config.check("send_sound_on_stop")) - { - m_send_sound_on_stop = config.find("send_sound_on_stop").asBool(); - } + //just info + yCDebug(AUDIORECORDER_NWS_YARP) << "Wrapper configured to produce packets with the following size (in samples): " << + m_min_samples_over_network << " < samples < " << m_max_samples_over_network; + yCDebug(AUDIORECORDER_NWS_YARP) << "Wrapper configured with max_samples_timeout: " << m_getSound_timeout << "s"; // Set the streaming port - std::string portname = "/audioRecorder_nws"; - if (config.check("name")) - { - portname= config.find("name").asString(); - } + std::string portname = m_name; if (m_streamingPort.open(portname + "/audio:o") == false) { yCError(AUDIORECORDER_NWS_YARP) << "Unable to open port" << portname + "/audio:o"; @@ -152,7 +114,7 @@ bool AudioRecorder_nws_yarp::attach(PolyDriver* driver) m_statusThread->start(); // Wait a little and then start if requested - if (m_config.check("start")) { + if (m_start) { yCDebug(AUDIORECORDER_NWS_YARP) << "Auto start requested"; yarp::os::SystemClock::delaySystem(1); m_mic->startRecording(); @@ -242,14 +204,14 @@ void AudioRecorderDataThread::run() { //acquire sound data from attached device yarp::sig::Sound current_sound; - m_ARW->m_mic->getSound(current_sound, m_ARW->m_min_number_of_samples_over_network, m_ARW->m_max_number_of_samples_over_network, m_ARW->m_getSound_timeout); - if (current_sound.getSamples() < m_ARW->m_min_number_of_samples_over_network || - current_sound.getSamples() > m_ARW->m_max_number_of_samples_over_network) + m_ARW->m_mic->getSound(current_sound, m_ARW->m_min_samples_over_network, m_ARW->m_max_samples_over_network, m_ARW->m_getSound_timeout); + if (current_sound.getSamples() < m_ARW->m_min_samples_over_network || + current_sound.getSamples() > m_ARW->m_max_samples_over_network) { yCWarning(AUDIORECORDER_NWS_YARP) << "subdevice->getSound() is not producing sounds of the requested size (" - << m_ARW->m_min_number_of_samples_over_network << "<" + << m_ARW->m_min_samples_over_network << "<" << current_sound.getSamples() << "<" - << m_ARW->m_max_number_of_samples_over_network << ") failed"; + << m_ARW->m_max_samples_over_network << ") failed"; } #ifdef PRINT_DEBUG_MESSAGES { diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.h b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.h index e510757beb8..49d56af4d14 100644 --- a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.h +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp.h @@ -24,51 +24,39 @@ #include #include "AudioRecorderServerImpl.h" +#include "AudioRecorder_nws_yarp_ParamsParser.h" class AudioRecorderStatusThread; class AudioRecorderDataThread; /** - * @ingroup dev_impl_wrapper + * @ingroup dev_impl_nws_yarp * * \brief `AudioRecorder_nws_yarp`: A Wrapper which streams audio over the network, after grabbing it from a device. * \section AudioRecorder_nws_yarp_device_parameters Description of input parameters - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:------------------------:|:--------------------------: |:--------------------------------------------------------------------------:|:-----:| - * | name | - | string | - | /audioRecorderWrapper | No | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:o and xxx/rpc suffixes are appended | - * | period | - | int | ms | 20 | No | period of the internal thread, in ms | default 20ms | - * | debug | - | bool | - | - | No | developers use only | | - * | min_samples_over_network | - | int | samples | 11250 | No | sends the network packet ifs n samples are collected AND the timeout is expired | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | - * | max_samples_over_network | - | int | samples | 11250 | No | sends the network packet as soon as n samples have been collected | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | - * | max_samples_timeout | - | float | s | 1.0 | No | timeout for sample collection | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | - * | start | - | bool | - | false | No | automatically activates the recording when the device is started | if false, the recording is enabled via rpc port | - * | send_sound_on_stop | - | bool | - | true | No | send the sound when the stop rpc is called, even if it does not met network size parameters | it will not send empty sounds | + * + * Parameters required by this device are shown in class: AudioRecorder_nws_yarp_ParamsParser * * See \ref AudioDoc for additional documentation on YARP audio. */ class AudioRecorder_nws_yarp : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public AudioRecorder_nws_yarp_ParamsParser { private: yarp::dev::PolyDriver m_driver; yarp::dev::IAudioGrabberSound* m_mic = nullptr; //The microphone device yarp::os::Property m_config; - double m_period; yarp::os::Port m_rpcPort; yarp::os::Port m_streamingPort; yarp::os::Port m_statusPort; yarp::os::Stamp m_stamp; - size_t m_min_number_of_samples_over_network; - size_t m_max_number_of_samples_over_network; - double m_getSound_timeout; AudioRecorderStatusThread* m_statusThread = nullptr; AudioRecorderDataThread* m_dataThread =nullptr; - bool m_debug_enabled = false; + const bool m_debug_enabled = false; std::list m_listofsnds; - bool m_send_sound_on_stop = true; private: double m_debug_last_time=0; diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..69c850c58b5 --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.cpp @@ -0,0 +1,215 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#include "AudioRecorder_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(AudioRecorder_nws_yarpParamsCOMPONENT, "yarp.device.AudioRecorder_nws_yarp") +} + + +AudioRecorder_nws_yarp_ParamsParser::AudioRecorder_nws_yarp_ParamsParser() +{ +} + + +std::vector AudioRecorder_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + params.push_back("period"); + params.push_back("debug"); + params.push_back("min_samples_over_network"); + params.push_back("max_samples_over_network"); + params.push_back("max_samples_timeout"); + params.push_back("start"); + params.push_back("send_sound_on_stop"); + return params; +} + + +bool AudioRecorder_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat32(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter debug + { + if (config.check("debug")) + { + m_debug = config.find("debug").asBool(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'debug' using value:" << m_debug; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'debug' using DEFAULT value:" << m_debug; + } + prop_check.unput("debug"); + } + + //Parser of parameter min_samples_over_network + { + if (config.check("min_samples_over_network")) + { + m_min_samples_over_network = config.find("min_samples_over_network").asInt64(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'min_samples_over_network' using value:" << m_min_samples_over_network; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'min_samples_over_network' using DEFAULT value:" << m_min_samples_over_network; + } + prop_check.unput("min_samples_over_network"); + } + + //Parser of parameter max_samples_over_network + { + if (config.check("max_samples_over_network")) + { + m_max_samples_over_network = config.find("max_samples_over_network").asInt64(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_over_network' using value:" << m_max_samples_over_network; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_over_network' using DEFAULT value:" << m_max_samples_over_network; + } + prop_check.unput("max_samples_over_network"); + } + + //Parser of parameter max_samples_timeout + { + if (config.check("max_samples_timeout")) + { + m_getSound_timeout = config.find("max_samples_timeout").asFloat32(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_timeout' using value:" << m_getSound_timeout; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'max_samples_timeout' using DEFAULT value:" << m_getSound_timeout; + } + prop_check.unput("max_samples_timeout"); + } + + //Parser of parameter start + { + if (config.check("start")) + { + m_start = config.find("start").asBool(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'start' using value:" << m_start; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'start' using DEFAULT value:" << m_start; + } + prop_check.unput("start"); + } + + //Parser of parameter send_sound_on_stop + { + if (config.check("send_sound_on_stop")) + { + m_send_sound_on_stop = config.find("send_sound_on_stop").asBool(); + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'send_sound_on_stop' using value:" << m_send_sound_on_stop; + } + else + { + yCInfo(AudioRecorder_nws_yarpParamsCOMPONENT) << "Parameter 'send_sound_on_stop' using DEFAULT value:" << m_send_sound_on_stop; + } + prop_check.unput("send_sound_on_stop"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(AudioRecorder_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(AudioRecorder_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string AudioRecorder_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: AudioRecorder_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': full name of the port opened by the device\n"); + doc = doc + std::string("'period': period of the internal thread, in ms\n"); + doc = doc + std::string("'debug': developers use only\n"); + doc = doc + std::string("'min_samples_over_network': sends the network packet ifs n samples are collected AND the timeout is expired\n"); + doc = doc + std::string("'max_samples_over_network': sends the network packet as soon as n samples have been collected\n"); + doc = doc + std::string("'max_samples_timeout': timeout for sample collection\n"); + doc = doc + std::string("'start': automatically activates the recording when the device is started\n"); + doc = doc + std::string("'send_sound_on_stop': send the sound when the stop rpc is called, even if it does not met network size parameters\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device audioRecorder_nws_yarp --name /audioRecorder_nws --period 0.02 --debug false --min_samples_over_network 11250 --max_samples_over_network 11250 --max_samples_timeout 1.0 --start false --send_sound_on_stop true\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device audioRecorder_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..e3ce561769c --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_ParamsParser.h @@ -0,0 +1,90 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef AUDIORECORDER_NWS_YARP_PARAMSPARSER_H +#define AUDIORECORDER_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class AudioRecorder_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:------------------------:|:------:|:-------:|:------------------:|:--------:|:-------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:| +* | - | name | string | - | /audioRecorder_nws | 0 | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:o and xxx/rpc suffixes are appended | +* | - | period | float | s | 0.02 | 0 | period of the internal thread, in ms | default 20ms | +* | - | debug | bool | - | false | 0 | developers use only | - | +* | - | min_samples_over_network | size_t | samples | 11250 | 0 | sends the network packet ifs n samples are collected AND the timeout is expired | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | +* | - | max_samples_over_network | size_t | samples | 11250 | 0 | sends the network packet as soon as n samples have been collected | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | +* | - | max_samples_timeout | float | s | 1.0 | 0 | timeout for sample collection | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | +* | - | start | bool | - | false | 0 | automatically activates the recording when the device is started | if false, the recording is enabled via rpc port | +* | - | send_sound_on_stop | bool | - | true | 0 | send the sound when the stop rpc is called, even if it does not met network size parameters | it will not send empty sounds | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device audioRecorder_nws_yarp --name /audioRecorder_nws --period 0.02 --debug false --min_samples_over_network 11250 --max_samples_over_network 11250 --max_samples_timeout 1.0 --start false --send_sound_on_stop true +* \endcode +* +* \code{.unparsed} +* yarpdev --device audioRecorder_nws_yarp +* \endcode +* +*/ + +class AudioRecorder_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + AudioRecorder_nws_yarp_ParamsParser(); + ~AudioRecorder_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"AudioRecorder_nws_yarp"}; + const std::string m_device_name = {"audioRecorder_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/audioRecorder_nws"}; + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_debug_defaultValue = {"false"}; + const std::string m_min_samples_over_network_defaultValue = {"11250"}; + const std::string m_max_samples_over_network_defaultValue = {"11250"}; + const std::string m_getSound_timeout_defaultValue = {"1.0"}; + const std::string m_start_defaultValue = {"false"}; + const std::string m_send_sound_on_stop_defaultValue = {"true"}; + + std::string m_name = {"/audioRecorder_nws"}; + float m_period = {0.02}; + bool m_debug = {false}; + size_t m_min_samples_over_network = {11250}; + size_t m_max_samples_over_network = {11250}; + float m_getSound_timeout = {1.0}; + bool m_start = {false}; + bool m_send_sound_on_stop = {true}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_params.md b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_params.md new file mode 100644 index 00000000000..39f1aa50c85 --- /dev/null +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/AudioRecorder_nws_yarp_params.md @@ -0,0 +1,8 @@ + * | | name | string | - | /audioRecorder_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:o and xxx/rpc suffixes are appended | + * | | period | float | s | 0.02 | No | period of the internal thread, in ms | default 20ms | + * | | debug | bool | - | false | No | developers use only | | + * | | min_samples_over_network | size_t | samples | 11250 | No | sends the network packet ifs n samples are collected AND the timeout is expired | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | + * | | max_samples_over_network | size_t | samples | 11250 | No | sends the network packet as soon as n samples have been collected | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | + * | | max_samples_timeout | float | s | 1.0 | No | timeout for sample collection | the algorithm is implemented in AudioRecorderDeviceBase::getSound() method | getSound_timeout | + * | | start | bool | - | false | No | automatically activates the recording when the device is started | if false, the recording is enabled via rpc port | + * | | send_sound_on_stop | bool | - | true | No | send the sound when the stop rpc is called, even if it does not met network size parameters | it will not send empty sounds | diff --git a/src/devices/networkWrappers/audioRecorder_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/audioRecorder_nws_yarp/CMakeLists.txt index 32a5e6d1ea3..8c30fbca446 100644 --- a/src/devices/networkWrappers/audioRecorder_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/audioRecorder_nws_yarp/CMakeLists.txt @@ -5,6 +5,7 @@ yarp_prepare_plugin(audioRecorder_nws_yarp CATEGORY device TYPE AudioRecorder_nws_yarp INCLUDE AudioRecorder_nws_yarp.h + GENERATE_PARSER DEFAULT ON ) @@ -17,6 +18,8 @@ if(NOT SKIP_AudioRecorderWrapper) AudioRecorder_nws_yarp.h AudioRecorderServerImpl.cpp AudioRecorderServerImpl.h + AudioRecorder_nws_yarp_ParamsParser.cpp + AudioRecorder_nws_yarp_ParamsParser.h ) target_sources(yarp_audioRecorder_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.cpp b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.cpp similarity index 87% rename from src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.cpp rename to src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.cpp index 3babb002f36..95b942052a1 100644 --- a/src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.cpp +++ b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "battery_nwc_yarp.h" +#include "Battery_nwc_yarp.h" #include #include @@ -174,31 +174,15 @@ void BatteryInputPortProcessor::getEstFrequency(int &ite, double &av, double &mi bool Battery_nwc_yarp::open(yarp::os::Searchable &config) { - local.clear(); - remote.clear(); - yCDebug(BATTERYCLIENT) << config.toString(); - local = config.find("local").asString(); - remote = config.find("remote").asString(); - m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString(); - - if (local=="") - { - yCError(BATTERYCLIENT, "open(): Invalid local name. --local parameter missing."); - return false; - } - if (remote=="") - { - yCError(BATTERYCLIENT, "open(): Invalid remote name. --remote parameter missing."); - return false; - } + if (!parseParams(config)) { return false; } - std::string local_stream = local; + std::string local_stream = m_local; local_stream += "/data:i"; - std::string local_rpc = local; + std::string local_rpc = m_local; local_rpc += "/rpc:o"; - std::string remote_stream = remote; + std::string remote_stream = m_remote; remote_stream += "/data:o"; - std::string remote_rpc = remote; + std::string remote_rpc = m_remote; remote_rpc += "/rpc:i"; if (!inputPort.open(local_stream)) diff --git a/src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.h b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.h similarity index 75% rename from src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.h rename to src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.h index 939c9413f82..e5e0a5b9fd9 100644 --- a/src/devices/networkWrappers/battery_nwc_yarp/battery_nwc_yarp.h +++ b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp.h @@ -18,7 +18,7 @@ #include #include - +#include "Battery_nwc_yarp_ParamsParser.h" #define DEFAULT_THREAD_PERIOD 20 //ms const int BATTERY_TIMEOUT=100; //ms @@ -67,26 +67,18 @@ class BatteryInputPortProcessor : public yarp::os::BufferedPort +#include + +namespace { + YARP_LOG_COMPONENT(Battery_nwc_yarpParamsCOMPONENT, "yarp.device.Battery_nwc_yarp") +} + + +Battery_nwc_yarp_ParamsParser::Battery_nwc_yarp_ParamsParser() +{ +} + + +std::vector Battery_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + params.push_back("carrier"); + return params; +} + + +bool Battery_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Battery_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(Battery_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(Battery_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(Battery_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the batteryClient device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(Battery_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(Battery_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(Battery_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the batteryClient connects to."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(Battery_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(Battery_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Battery_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Battery_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Battery_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Battery_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the batteryClient device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the batteryClient connects to.\n"); + doc = doc + std::string("'carrier': The carrier used for the connection with the server.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device battery_nwc_yarp --local --remote --carrier tcp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device battery_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..003f0c3672f --- /dev/null +++ b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef BATTERY_NWC_YARP_PARAMSPARSER_H +#define BATTERY_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Battery_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:---------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the batteryClient device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the batteryClient connects to. | - | +* | - | carrier | string | - | tcp | 0 | The carrier used for the connection with the server. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device battery_nwc_yarp --local --remote --carrier tcp +* \endcode +* +* \code{.unparsed} +* yarpdev --device battery_nwc_yarp --local --remote +* \endcode +* +*/ + +class Battery_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Battery_nwc_yarp_ParamsParser(); + ~Battery_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Battery_nwc_yarp"}; + const std::string m_device_name = {"battery_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"tcp"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"tcp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_params.md b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_params.md new file mode 100644 index 00000000000..e9a05d6f0ef --- /dev/null +++ b/src/devices/networkWrappers/battery_nwc_yarp/Battery_nwc_yarp_params.md @@ -0,0 +1,3 @@ +* | | local | string | - | - | Yes | Full port name opened by the batteryClient device. | | +* | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the batteryClient connects to. | | +* | | carrier | string | - | tcp | No | The carrier used for the connection with the server. | | diff --git a/src/devices/networkWrappers/battery_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/battery_nwc_yarp/CMakeLists.txt index dbf16f46c81..2492735b207 100644 --- a/src/devices/networkWrappers/battery_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/battery_nwc_yarp/CMakeLists.txt @@ -4,7 +4,8 @@ yarp_prepare_plugin(battery_nwc_yarp CATEGORY device TYPE Battery_nwc_yarp - INCLUDE battery_nwc_yarp.h + INCLUDE Battery_nwc_yarp.h + GENERATE_PARSER DEFAULT ON ) @@ -13,8 +14,10 @@ if(NOT SKIP_battery_nwc_yarp) target_sources(yarp_battery_nwc_yarp PRIVATE - battery_nwc_yarp.cpp - battery_nwc_yarp.h + Battery_nwc_yarp.cpp + Battery_nwc_yarp.h + Battery_nwc_yarp_ParamsParser.cpp + Battery_nwc_yarp_ParamsParser.h ) target_link_libraries(yarp_battery_nwc_yarp diff --git a/src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.cpp b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.cpp similarity index 88% rename from src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.cpp rename to src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.cpp index 0f18397b3b0..15fdac2633e 100644 --- a/src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.cpp +++ b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "battery_nws_yarp.h" +#include "Battery_nws_yarp.h" #include #include #include @@ -121,40 +121,10 @@ bool Battery_nws_yarp::threadInit() bool Battery_nws_yarp::open(yarp::os::Searchable &config) { - Property params; - params.fromString(config.toString()); + if (!parseParams(config)) { return false; } - if (!config.check("period")) - { - m_period = 1.0; - yCWarning(BATTERYWRAPPER) << "Missing 'period' parameter. Assuming default value 1.0 s"; - } - else - { - m_period = config.find("period").asFloat32(); - } - yCInfo(BATTERYWRAPPER) << "Using period:" << m_period << "s"; - - if (!config.check("quitPortName")) - { - m_quitPortName = config.find("quitPortName").asString(); - } - - if (!config.check("name")) - { - yCError(BATTERYWRAPPER) << "Missing 'name' parameter. Check you configuration file; it must be like:"; - yCError(BATTERYWRAPPER) << "--name: prefix of the ports opened by the device, e.g. /robotName/battery1"; - yCError(BATTERYWRAPPER) << "/data:o and /rpc:i are automatically appended by the wrapper at the end"; - return false; - } - else - { - m_streamingPortName = config.find("name").asString() + "/data:o"; - m_rpcPortName = config.find("name").asString() + "/rpc:i"; - } - - m_enable_shutdown = config.check("enable_shutdown", Value(0), "enable/disable the automatic shutdown").asBool(); - m_enable_log = config.check("enable_log", Value(0), "enable/disable log to file").asBool(); + m_streamingPortName = m_name + "/data:o"; + m_rpcPortName = m_name + "/rpc:i"; if(!initialize_YARP(config)) { diff --git a/src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.h b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.h similarity index 54% rename from src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.h rename to src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.h index 68ce4ea5c83..c62c4819368 100644 --- a/src/devices/networkWrappers/battery_nws_yarp/battery_nws_yarp.h +++ b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp.h @@ -31,6 +31,8 @@ #include #include +#include "Battery_nws_yarp_ParamsParser.h" + #define DEFAULT_THREAD_PERIOD 0.02 //s /** @@ -38,45 +40,17 @@ * * \brief `Battery_nws_yarp`: Device that expose a battery sensor (using the IBattery interface) on the YARP network. * - * \section Battery_nws_yarp_device_parameters Description of input parameters - * * It reads the data from a battery sensor and sends them on a port, acting as a streaming server for a batteryClient device. * It creates one rpc port and its related handler for every output port. * - * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:-----------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:--------------------------------------------------------------------------------:|:-----:| - * | name | - | string | - | - | Yes | prefix of the ports opened by the device, e.g. /robotName/battery1 | MUST start with a '/' character. /data:o and /rpc:i is automatically appended by the wrapper at the end | - * | period | - | double | s | 1.0 | No | refresh period of the broadcasted values in seconds | optional, default 1.0s | - * | enable_shutdown | - | bool | - | false | No | if enabled, batteryWrapper will start a system shutdown when charge is below 5% | - | - * | enable_log | - | bool | - | false | No | if enabled, stores a log of battery usage on disk | data stored on file batteryLog.txt | - * | quitPortName | - | string | - | - | No | name of port used to terminate the execution of yarpRobotInterface | used only if enable_shutdown=true | - * - * Some example of configuration files: - * - * Configuration file using .xml format. - * - * \code{.xml} - * - * 20 - * /myBatterySensor - * - * - * - * my_battery - * - * - * - * - * - * \endcode - * */ + * Parameters required by this device are shown in class: Battery_nws_yarp_ParamsParser + */ class Battery_nws_yarp : public yarp::os::PeriodicThread, public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + Battery_nws_yarp_ParamsParser { public: Battery_nws_yarp(); @@ -96,7 +70,6 @@ class Battery_nws_yarp : //ports stuff std::string m_streamingPortName; std::string m_rpcPortName; - std::string m_quitPortName; yarp::os::Port m_rpcPort; yarp::os::BufferedPort m_streamingPort; @@ -111,10 +84,6 @@ class Battery_nws_yarp : double m_period; std::string m_sensorId; - //behavior controls - bool m_enable_shutdown; - bool m_enable_log; - //log stuff char m_log_buffer[1024]; FILE *m_logFile; diff --git a/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..456b215fbe3 --- /dev/null +++ b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.cpp @@ -0,0 +1,169 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#include "Battery_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Battery_nws_yarpParamsCOMPONENT, "yarp.device.Battery_nws_yarp") +} + + +Battery_nws_yarp_ParamsParser::Battery_nws_yarp_ParamsParser() +{ +} + + +std::vector Battery_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + params.push_back("period"); + params.push_back("enable_shutdown"); + params.push_back("enable_log"); + params.push_back("quitPortName"); + return params; +} + + +bool Battery_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Battery_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(Battery_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(Battery_nws_yarpParamsCOMPONENT) << "Description of the parameter: prefix of the ports opened by the device"; + return false; + } + prop_check.unput("name"); + } + + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter enable_shutdown + { + if (config.check("enable_shutdown")) + { + m_enable_shutdown = config.find("enable_shutdown").asBool(); + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'enable_shutdown' using value:" << m_enable_shutdown; + } + else + { + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'enable_shutdown' using DEFAULT value:" << m_enable_shutdown; + } + prop_check.unput("enable_shutdown"); + } + + //Parser of parameter enable_log + { + if (config.check("enable_log")) + { + m_enable_log = config.find("enable_log").asBool(); + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'enable_log' using value:" << m_enable_log; + } + else + { + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'enable_log' using DEFAULT value:" << m_enable_log; + } + prop_check.unput("enable_log"); + } + + //Parser of parameter quitPortName + { + if (config.check("quitPortName")) + { + m_quitPortName = config.find("quitPortName").asString(); + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'quitPortName' using value:" << m_quitPortName; + } + else + { + yCInfo(Battery_nws_yarpParamsCOMPONENT) << "Parameter 'quitPortName' using DEFAULT value:" << m_quitPortName; + } + prop_check.unput("quitPortName"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Battery_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Battery_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Battery_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Battery_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': prefix of the ports opened by the device\n"); + doc = doc + std::string("'period': refresh period of the broadcasted values in seconds\n"); + doc = doc + std::string("'enable_shutdown': if enabled, batteryWrapper will start a system shutdown when charge is below 5%\n"); + doc = doc + std::string("'enable_log': if enabled, stores a log of battery usage on disk\n"); + doc = doc + std::string("'quitPortName': if present, this yarp port will be opened and used to send a sthutdown command to other processes\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device battery_nws_yarp --name /robotName/battery1 --period 1.0 --enable_shutdown false --enable_log false --quitPortName \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device battery_nws_yarp --name /robotName/battery1\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..82021f4dd50 --- /dev/null +++ b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_ParamsParser.h @@ -0,0 +1,81 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef BATTERY_NWS_YARP_PARAMSPARSER_H +#define BATTERY_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Battery_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:---------------:|:------:|:-----:|:-------------------:|:--------:|:-------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------:| +* | - | name | string | - | /robotName/battery1 | 1 | prefix of the ports opened by the device | MUST start with a '/' character. /data:o and /rpc:i is automatically appended by the wrapper at the end | +* | - | period | double | s | 1.0 | 0 | refresh period of the broadcasted values in seconds | optional, default 1.0s | +* | - | enable_shutdown | bool | - | false | 0 | if enabled, batteryWrapper will start a system shutdown when charge is below 5% | - | +* | - | enable_log | bool | - | false | 0 | if enabled, stores a log of battery usage on disk | data stored on file batteryLog.txt | +* | - | quitPortName | string | - | - | 0 | if present, this yarp port will be opened and used to send a sthutdown command to other processes | enable_shutdown must be enabled | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device battery_nws_yarp --name /robotName/battery1 --period 1.0 --enable_shutdown false --enable_log false --quitPortName +* \endcode +* +* \code{.unparsed} +* yarpdev --device battery_nws_yarp --name /robotName/battery1 +* \endcode +* +*/ + +class Battery_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Battery_nws_yarp_ParamsParser(); + ~Battery_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Battery_nws_yarp"}; + const std::string m_device_name = {"battery_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/robotName/battery1"}; + const std::string m_period_defaultValue = {"1.0"}; + const std::string m_enable_shutdown_defaultValue = {"false"}; + const std::string m_enable_log_defaultValue = {"false"}; + const std::string m_quitPortName_defaultValue = {""}; + + std::string m_name = {"/robotName/battery1"}; + double m_period = {1.0}; + bool m_enable_shutdown = {false}; + bool m_enable_log = {false}; + std::string m_quitPortName = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_params.md b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_params.md new file mode 100644 index 00000000000..49cd0a83488 --- /dev/null +++ b/src/devices/networkWrappers/battery_nws_yarp/Battery_nws_yarp_params.md @@ -0,0 +1,5 @@ + * | | name | string | - | /robotName/battery1 | Yes | prefix of the ports opened by the device | MUST start with a '/' character. /data:o and /rpc:i is automatically appended by the wrapper at the end | + * | | period | double | s | 1.0 | No | refresh period of the broadcasted values in seconds | optional, default 1.0s | + * | | enable_shutdown | bool | - | false | No | if enabled, batteryWrapper will start a system shutdown when charge is below 5% | - | + * | | enable_log | bool | - | false | No | if enabled, stores a log of battery usage on disk | data stored on file batteryLog.txt | + * | | quitPortName | string | - | - | No | if present, this yarp port will be opened and used to send a sthutdown command to other processes | enable_shutdown must be enabled | diff --git a/src/devices/networkWrappers/battery_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/battery_nws_yarp/CMakeLists.txt index a6105fac0aa..9b8869f5794 100644 --- a/src/devices/networkWrappers/battery_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/battery_nws_yarp/CMakeLists.txt @@ -4,7 +4,8 @@ yarp_prepare_plugin(battery_nws_yarp CATEGORY device TYPE Battery_nws_yarp - INCLUDE battery_nws_yarp.h + INCLUDE Battery_nws_yarp.h + GENERATE_PARSER EXTRA_CONFIG WRAPPER=battery_nws_yarp DEFAULT ON @@ -15,8 +16,10 @@ if(NOT SKIP_battery_nws_yarp) target_sources(yarp_battery_nws_yarp PRIVATE - battery_nws_yarp.cpp - battery_nws_yarp.h + Battery_nws_yarp.cpp + Battery_nws_yarp.h + Battery_nws_yarp_ParamsParser.cpp + Battery_nws_yarp_ParamsParser.h ) target_link_libraries(yarp_battery_nws_yarp diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/chatBot_nwc_yarp/CMakeLists.txt index 98c84d75ee9..393fbfb4e03 100644 --- a/src/devices/networkWrappers/chatBot_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/CMakeLists.txt @@ -5,6 +5,7 @@ yarp_prepare_plugin(chatBot_nwc_yarp CATEGORY device TYPE ChatBot_nwc_yarp INCLUDE ChatBot_nwc_yarp.h + GENERATE_PARSER DEFAULT ON ) @@ -15,6 +16,8 @@ if(NOT SKIP_chatBot_nwc_yarp) PRIVATE ChatBot_nwc_yarp.cpp ChatBot_nwc_yarp.h + ChatBot_nwc_yarp_ParamsParser.h + ChatBot_nwc_yarp_ParamsParser.cpp ) target_sources(chatBot_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.cpp b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.cpp index 546f75dfa79..0094561c280 100644 --- a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.cpp +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.cpp @@ -15,22 +15,9 @@ namespace bool ChatBot_nwc_yarp::open(yarp::os::Searchable &config) { - std::string local_rpc = config.find("local").asString(); - std::string remote_rpc = config.find("remote").asString(); + if (!parseParams(config)) { return false; } - if (local_rpc == "") - { - yCError(CHATBOT_NWC_YARP) << "open() error you have to provide a valid 'local' param"; - return false; - } - - if (remote_rpc == "") - { - yCError(CHATBOT_NWC_YARP) << "open() error you have to provide valid 'remote' param"; - return false; - } - - if (!m_thriftClientPort.open(local_rpc)) + if (!m_thriftClientPort.open(m_local)) { yCError(CHATBOT_NWC_YARP) << "Cannot open rpc port, check network"; @@ -39,11 +26,11 @@ bool ChatBot_nwc_yarp::open(yarp::os::Searchable &config) bool ok = false; - ok = yarp::os::Network::connect(local_rpc, remote_rpc); + ok = yarp::os::Network::connect(m_local, m_remote); if (!ok) { - yCError(CHATBOT_NWC_YARP) << "open() error could not connect to" << remote_rpc; + yCError(CHATBOT_NWC_YARP) << "open() error could not connect to" << m_remote; return false; } diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.h b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.h index 545dc606872..88ba1a7fcfc 100644 --- a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.h +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp.h @@ -10,20 +10,19 @@ #include #include #include "IChatBotMsgs.h" +#include "ChatBot_nwc_yarp_ParamsParser.h" /** * @ingroup dev_impl_network_clients * * \brief `chatBot_nwc_yarp`: The client side of any IChatBot capable device. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the nwc device. | | - * | remote | - | string | - | - | Yes | Full port name of the port opened on the server side, to which the nwc connects to. | | + * Parameters required by this device are shown in class: ChatBot_nwc_yarp_ParamsParser + * */ class ChatBot_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::IChatBot + public yarp::dev::IChatBot, + public ChatBot_nwc_yarp_ParamsParser { protected: // thrift interface diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..c459efc849d --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#include "ChatBot_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(ChatBot_nwc_yarpParamsCOMPONENT, "yarp.device.ChatBot_nwc_yarp") +} + + +ChatBot_nwc_yarp_ParamsParser::ChatBot_nwc_yarp_ParamsParser() +{ +} + + +std::vector ChatBot_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool ChatBot_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(ChatBot_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(ChatBot_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(ChatBot_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(ChatBot_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the nwc device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(ChatBot_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(ChatBot_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(ChatBot_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the nwc connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(ChatBot_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(ChatBot_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string ChatBot_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: ChatBot_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the nwc device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the nwc connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device chatBot_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device chatBot_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..788c0365616 --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef CHATBOT_NWC_YARP_PARAMSPARSER_H +#define CHATBOT_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class ChatBot_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the nwc device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the nwc connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device chatBot_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device chatBot_nwc_yarp --local --remote +* \endcode +* +*/ + +class ChatBot_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + ChatBot_nwc_yarp_ParamsParser(); + ~ChatBot_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"ChatBot_nwc_yarp"}; + const std::string m_device_name = {"chatBot_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_params.md b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_params.md new file mode 100644 index 00000000000..a2e619642ef --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nwc_yarp/ChatBot_nwc_yarp_params.md @@ -0,0 +1,2 @@ + * | - | local | string | - | - | Yes | Full port name opened by the nwc device. | | + * | - | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the nwc connects to. | | diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/chatBot_nws_yarp/CMakeLists.txt index 1c31c17a0fb..ef2a217f197 100644 --- a/src/devices/networkWrappers/chatBot_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/chatBot_nws_yarp/CMakeLists.txt @@ -5,6 +5,7 @@ yarp_prepare_plugin(chatBot_nws_yarp CATEGORY device TYPE ChatBot_nws_yarp INCLUDE ChatBot_nws_yarp.h + GENERATE_PARSER DEFAULT ON ) @@ -17,6 +18,8 @@ if(NOT SKIP_chatBot_nws_yarp) IChatBotMsgsImpl.cpp ChatBot_nws_yarp.cpp ChatBot_nws_yarp.h + ChatBot_nws_yarp_ParamsParser.cpp + ChatBot_nws_yarp_ParamsParser.h ) target_link_libraries(yarp_chatBot_nws_yarp diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.cpp b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.cpp index c141bbac200..7ffcf3ba8a7 100644 --- a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.cpp +++ b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.cpp @@ -23,24 +23,22 @@ bool ChatBot_nws_yarp::close() return closeMain(); } -bool ChatBot_nws_yarp::open(Searchable& prop) +bool ChatBot_nws_yarp::open(Searchable& config) { - std::string rootName = - prop.check("name",Value("/chatBot_nws"), - "prefix for port names").asString(); + if (!parseParams(config)) { return false; } m_inputBuffer.attach(m_inputPort); - if(!m_inputPort.open(rootName+"/text:i")) + if(!m_inputPort.open(m_name+"/text:i")) { - yCError(CHATBOT_NWS_YARP) << "Could not open port" << rootName+"/text:i"; + yCError(CHATBOT_NWS_YARP) << "Could not open port" << m_name +"/text:i"; return false; } - if(!m_outputPort.open(rootName + "/text:o")) + if(!m_outputPort.open(m_name + "/text:o")) { - yCError(CHATBOT_NWS_YARP) << "Could not open port" << rootName+"/text:o"; + yCError(CHATBOT_NWS_YARP) << "Could not open port" << m_name +"/text:o"; return false; } - if (!m_thriftServerPort.open(rootName+"/rpc")) + if (!m_thriftServerPort.open(m_name +"/rpc")) { yCError(CHATBOT_NWS_YARP, "Failed to open rpc port"); return false; diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.h b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.h index 5d0ac73755d..6a785cec586 100644 --- a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.h +++ b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp.h @@ -20,6 +20,7 @@ #include #include #include "IChatBotMsgs.h" +#include "ChatBot_nws_yarp_ParamsParser.h" using namespace yarp::os; using namespace yarp::dev; @@ -68,19 +69,18 @@ class IChatBotMsgsImpl : public IChatBotMsgs * * The network interface is composed by two ports. * When a text bottle is received on the input port, the attached subdevice sends it to the chatbot - * and sends the bot resonse on the output port + * and sends the bot response on the output port * The same functionality is available also via rpc port, which also provides additional functionalities, * such as setting the language, resetting the bot and performing backup and restore operations. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:----------------------------:|:----------: |:---------------------------------------------------------------------:|:-----------------------------------------------------------------------------------:| - * | name | - | string | - | /chatBot_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/text:i, xxx/rpc, xxx/audio:o ports are opened | + * Parameters required by this device are shown in class: ChatBot_nws_yarp_ParamsParser + * */ class ChatBot_nws_yarp : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public ChatBot_nws_yarp_ParamsParser { private: yarp::dev::IChatBot* m_iChatBot{ nullptr }; diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..5dfa6837f6d --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.cpp @@ -0,0 +1,119 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#include "ChatBot_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(ChatBot_nws_yarpParamsCOMPONENT, "yarp.device.ChatBot_nws_yarp") +} + + +ChatBot_nws_yarp_ParamsParser::ChatBot_nws_yarp_ParamsParser() +{ +} + + +std::vector ChatBot_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + params.push_back("streaming_name"); + return params; +} + + +bool ChatBot_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(ChatBot_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(ChatBot_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(ChatBot_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + //Parser of parameter streaming_name + { + if (config.check("streaming_name")) + { + m_streaming_name = config.find("streaming_name").asString(); + yCInfo(ChatBot_nws_yarpParamsCOMPONENT) << "Parameter 'streaming_name' using value:" << m_streaming_name; + } + else + { + yCInfo(ChatBot_nws_yarpParamsCOMPONENT) << "Parameter 'streaming_name' using DEFAULT value:" << m_streaming_name; + } + prop_check.unput("streaming_name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(ChatBot_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(ChatBot_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string ChatBot_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: ChatBot_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': prefix for all ports opened by the device\n"); + doc = doc + std::string("'streaming_name': \n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device chatBot_nws_yarp --name /chatBot_nws --streaming_name \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device chatBot_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..1e712c06f0a --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef CHATBOT_NWS_YARP_PARAMSPARSER_H +#define CHATBOT_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class ChatBot_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------:|:---------------------------------------------------------------------------------:| +* | - | name | string | - | /chatBot_nws | 0 | prefix for all ports opened by the device | MUST start with a '/' character, xxx/text:i, xxx/text:o, xxx/rpc ports are opened | +* | - | streaming_name | string | - | - | 0 | - | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device chatBot_nws_yarp --name /chatBot_nws --streaming_name +* \endcode +* +* \code{.unparsed} +* yarpdev --device chatBot_nws_yarp +* \endcode +* +*/ + +class ChatBot_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + ChatBot_nws_yarp_ParamsParser(); + ~ChatBot_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"ChatBot_nws_yarp"}; + const std::string m_device_name = {"chatBot_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/chatBot_nws"}; + const std::string m_streaming_name_defaultValue = {""}; + + std::string m_name = {"/chatBot_nws"}; + std::string m_streaming_name = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_params.md b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_params.md new file mode 100644 index 00000000000..d3f1bef8ad9 --- /dev/null +++ b/src/devices/networkWrappers/chatBot_nws_yarp/ChatBot_nws_yarp_params.md @@ -0,0 +1,2 @@ + * | - | name | string | - | /chatBot_nws | No | prefix for all ports opened by the device | MUST start with a '/' character, xxx/text:i, xxx/text:o, xxx/rpc ports are opened | + * | - | streaming_name | string | - | | No | | | diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/controlBoard_nws_yarp/CMakeLists.txt index 891f965b2f5..8e32532bf29 100644 --- a/src/devices/networkWrappers/controlBoard_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/CMakeLists.txt @@ -9,6 +9,7 @@ yarp_prepare_plugin( EXTRA_CONFIG WRAPPER=controlBoard_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_controlBoard_nws_yarp) @@ -23,6 +24,8 @@ if(NOT SKIP_controlBoard_nws_yarp) PRIVATE ControlBoard_nws_yarp.cpp ControlBoard_nws_yarp.h + ControlBoard_nws_yarp_ParamsParser.cpp + ControlBoard_nws_yarp_ParamsParser.h RPCMessagesParser.cpp RPCMessagesParser.h StreamingMessagesParser.cpp diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.cpp b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.cpp index f4fe2330d82..bcea6d9c7ed 100644 --- a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.cpp +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.cpp @@ -21,8 +21,10 @@ using namespace yarp::dev; using namespace yarp::sig; using yarp::dev::impl::jointData; +const double DEFAULT_PERIOD = 0.02; + ControlBoard_nws_yarp::ControlBoard_nws_yarp() : - yarp::os::PeriodicThread(default_period) + yarp::os::PeriodicThread(DEFAULT_PERIOD) { } @@ -55,68 +57,11 @@ bool ControlBoard_nws_yarp::close() return true; } -bool ControlBoard_nws_yarp::checkPortName(Searchable& params) -{ - // find name as port name (similar both in new and old policy) - if (!params.check("name")) { - yCError(CONTROLBOARD) << - "*************************************************************************************\n" - "* controlBoard_nws_yarp missing mandatory parameter 'name' for port name, usage is: *\n" - "* name: full port prefix name with leading '/', e.g. /robotName/part/ *\n" - "*************************************************************************************"; - return false; - } - - partName = params.find("name").asString(); - if (partName[0] != '/') { - yCWarning(CONTROLBOARD) << - "*************************************************************************************\n" - "* controlBoard_nws_yarp 'name' parameter for port name does not follow convention, *\n" - "* it MUST start with a leading '/' since it is used as the full prefix port name *\n" - "* name: full port prefix name with leading '/', e.g. /robotName/part/ *\n" - "* A temporary automatic fix will be done for you, but please fix your config file *\n" - "*************************************************************************************"; - rootName = "/" + partName; - } else { - rootName = partName; - } - - return true; -} - - bool ControlBoard_nws_yarp::open(Searchable& config) { - Property prop; - prop.fromString(config.toString()); + if (!parseParams(config)) { return false; } - if (!checkPortName(config)) { - yCError(CONTROLBOARD) << "'portName' was not correctly set, check you r configuration file"; - return false; - } - - // Check parameter, so if both are present we use the correct one - if (prop.check("period")) { - if (!prop.find("period").isFloat64()) { - yCError(CONTROLBOARD) << "'period' parameter is not a double value"; - return false; - } - period = prop.find("period").asFloat64(); - if (period <= 0) { - yCError(CONTROLBOARD) << "'period' parameter is not valid, read value is" << period; - return false; - } - } else { - yCDebug(CONTROLBOARD) << "'period' parameter missing, using default thread period = 0.02s"; - period = default_period; - } - - rootName = prop.check("rootName", Value("/"), "starting '/' if needed.").asString(); - partName = prop.check("name", Value("controlboard"), "prefix for port names").asString(); - rootName += (partName); - if (rootName.find("//") != std::string::npos) { - rootName.replace(rootName.find("//"), 2, "/"); - } + std::string rootName = m_name; // Open ports, then attach the readers or callbacks if (!inputRPCPort.open((rootName + "/rpc:i"))) { @@ -153,7 +98,7 @@ bool ControlBoard_nws_yarp::open(Searchable& config) // In case attach is not deferred and the controlboard already owns a valid device // we can start the thread. Otherwise this will happen when attachAll is called if (subdevice_ready) { - setPeriod(period); + setPeriod(m_period); if (!start()) { yCError(CONTROLBOARD) << "Error starting thread"; return false; @@ -381,7 +326,7 @@ bool ControlBoard_nws_yarp::attach(yarp::dev::PolyDriver* poly) return false; } - setPeriod(period); + setPeriod(m_period); if (!start()) { yCError(CONTROLBOARD) << "Error starting thread"; return false; diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.h b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.h index 20f5ded90da..ef7498803c4 100644 --- a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.h +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp.h @@ -42,7 +42,7 @@ #include "StreamingMessagesParser.h" #include "RPCMessagesParser.h" - +#include "ControlBoard_nws_yarp_ParamsParser.h" /** * @ingroup dev_impl_nws_yarp @@ -51,6 +51,8 @@ * * \section controlBoard_nws_yarp_device_parameters Description of input parameters * + * Parameters required by this device are shown in class: ControlBoard_nws_yarp_ParamsParser + * * Parameters required by this device are: * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:-----------------------------------------------------------------:|:-----:| @@ -61,13 +63,10 @@ class ControlBoard_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::PeriodicThread, - public yarp::dev::WrapperSingle + public yarp::dev::WrapperSingle, + public ControlBoard_nws_yarp_ParamsParser { private: - std::string rootName; - - bool checkPortName(yarp::os::Searchable ¶ms); - yarp::os::BufferedPort outputPositionStatePort; // Port /state:o streaming out the encoder positions yarp::os::BufferedPort inputStreamingPort; // Input streaming port for high frequency commands yarp::os::Port inputRPCPort; // Input RPC port for set/get remote calls @@ -79,9 +78,6 @@ class ControlBoard_nws_yarp : RPCMessagesParser RPC_parser; // Message parser associated to the inputRPCPort port StreamingMessagesParser streaming_parser; // Message parser associated to the inputStreamingPort port - static constexpr double default_period = 0.02; // s - double period {default_period}; - std::string partName; // to open ports and print more detailed debug messages yarp::sig::Vector times; // time for each joint yarp::os::Stamp time; // envelope to attach to the state port diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..43e91917fac --- /dev/null +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.cpp @@ -0,0 +1,121 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#include "ControlBoard_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(ControlBoard_nws_yarpParamsCOMPONENT, "yarp.device.ControlBoard_nws_yarp") +} + + +ControlBoard_nws_yarp_ParamsParser::ControlBoard_nws_yarp_ParamsParser() +{ +} + + +std::vector ControlBoard_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + return params; +} + + +bool ControlBoard_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(ControlBoard_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(ControlBoard_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(ControlBoard_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(ControlBoard_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(ControlBoard_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(ControlBoard_nws_yarpParamsCOMPONENT) << "Description of the parameter: Prefix name of the ports opened by the device"; + return false; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(ControlBoard_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(ControlBoard_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string ControlBoard_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: ControlBoard_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': period of the main thread\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the device\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device controlBoard_nws_yarp --period 0.02 --name /robot/part\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device controlBoard_nws_yarp --name /robot/part\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..5f0a472bd0f --- /dev/null +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:49 2024 + + +#ifndef CONTROLBOARD_NWS_YARP_PARAMSPARSER_H +#define CONTROLBOARD_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class ControlBoard_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:---------------------------------------------:|:------------------------------------------------------------------------:| +* | - | period | double | s | 0.02 | 0 | period of the main thread | - | +* | - | name | string | - | /robot/part | 1 | Prefix name of the ports opened by the device | opened ports will be: xxx/rpc:i xxx/command:i xxx/state:o xxx/stateExt:o | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device controlBoard_nws_yarp --period 0.02 --name /robot/part +* \endcode +* +* \code{.unparsed} +* yarpdev --device controlBoard_nws_yarp --name /robot/part +* \endcode +* +*/ + +class ControlBoard_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + ControlBoard_nws_yarp_ParamsParser(); + ~ControlBoard_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"ControlBoard_nws_yarp"}; + const std::string m_device_name = {"controlBoard_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_name_defaultValue = {"/robot/part"}; + + double m_period = {0.02}; + std::string m_name = {"/robot/part"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_params.md b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_params.md new file mode 100644 index 00000000000..0086e72b72f --- /dev/null +++ b/src/devices/networkWrappers/controlBoard_nws_yarp/ControlBoard_nws_yarp_params.md @@ -0,0 +1,2 @@ + * | | period | double | s | 0.02 | No | period of the main thread | | + * | | name | string | - | /robot/part | Yes | Prefix name of the ports opened by the device | opened ports will be: xxx/rpc:i xxx/command:i xxx/state:o xxx/stateExt:o | diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/frameGrabber_nwc_yarp/CMakeLists.txt index ddee458891b..8994e7e3fc7 100644 --- a/src/devices/networkWrappers/frameGrabber_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/CMakeLists.txt @@ -8,16 +8,19 @@ yarp_prepare_plugin(frameGrabber_nwc_yarp EXTRA_CONFIG WRAPPER=frameGrabber_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_frameGrabber_nwc_yarp) yarp_add_plugin(yarp_frameGrabber_nwc_yarp) target_sources(yarp_frameGrabber_nwc_yarp - PRIVATE - FrameGrabber_nwc_yarp.cpp - FrameGrabber_nwc_yarp.h - ) + PRIVATE + FrameGrabber_nwc_yarp.cpp + FrameGrabber_nwc_yarp.h + FrameGrabber_nwc_yarp_ParamsParser.h + FrameGrabber_nwc_yarp_ParamsParser.cpp + ) target_sources(yarp_frameGrabber_nwc_yarp PRIVATE $) target_include_directories(yarp_frameGrabber_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.cpp b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.cpp index 2e483f8872a..fda1e73d705 100644 --- a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.cpp +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.cpp @@ -218,18 +218,10 @@ FrameGrabber_nwc_yarp::FrameGrabber_nwc_yarp() : bool FrameGrabber_nwc_yarp::open(yarp::os::Searchable& config) { - std::string remote = config.check("remote", yarp::os::Value(""), "port name of real grabber").asString(); - std::string local = config.check("local", yarp::os::Value("..."), "port name to use locally").asString(); - if (config.check("stream")) - { - yCError(FRAMEGRABBER_NWC_YARP) << "'stream' parameter was deprecated. Please rename it to 'carrier'"; - return false; - } - std::string carrier = config.check("carrier", yarp::os::Value("fast_tcp"), "carrier to use for streaming").asString(); - bool no_stream = config.check("no_stream"); + if (!this->parseParams(config)) { return false; } - if (!no_stream) { - if (!streamReceiver.open(local, remote, carrier)) { + if (!m_no_stream) { + if (!streamReceiver.open(m_local, m_remote, m_carrier)) { return false; } FrameGrabberOf_ForwarderWithStream>::setStreamReceiver(&streamReceiver); @@ -238,13 +230,13 @@ bool FrameGrabber_nwc_yarp::open(yarp::os::Searchable& config) FrameGrabberOf_ForwarderWithStream::setStreamReceiver(&streamReceiver); } - std::string rpc_local = local + "/rpc_client"; - std::string rpc_remote = remote + "/rpc"; + std::string rpc_local = m_local + "/rpc_client"; + std::string rpc_remote = m_remote + "/rpc"; if (!rpcPort.open(rpc_local)) { yCError(FRAMEGRABBER_NWC_YARP) << "Failed to open " << rpc_local << "port."; } - if (!remote.empty()) { + if (!m_remote.empty()) { yCInfo(FRAMEGRABBER_NWC_YARP) << "Connecting" << rpcPort.getName() << "to" << rpc_remote; if (!yarp::os::NetworkBase::connect(rpcPort.getName(), rpc_remote)) { yCError(FRAMEGRABBER_NWC_YARP) << "Failed to connect" << rpcPort.getName() << "to" << rpc_remote; diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.h b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.h index b1bd95a9392..7b2d6f33fe7 100644 --- a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.h +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp.h @@ -18,7 +18,7 @@ #include #include - +#include "FrameGrabber_nwc_yarp_ParamsParser.h" class StreamReceiver { @@ -80,13 +80,8 @@ class FrameGrabberOf_ForwarderWithStream: * \section frameGrabber_nwc_yarp * * \brief `frameGrabber_nwc_yarp`: The client of a frameGrabber_nws_yarp. - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Prefix of the ports opened locally by the nwc for streaming and rpc operations | | - * | remote | - | string | - | - | Yes | Name of the remote rpc port opened by the nws | | - * | carrier | - | string | - | fast_tcp | No | Protocol used for connection with the nws streaming port | | - * | no_stream | - | bool | - | false | No | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | | + * + * Parameters required by this device are shown in class: FrameGrabber_nwc_yarp_ParamsParser */ class FrameGrabber_nwc_yarp : public yarp::dev::DeviceDriver, @@ -97,7 +92,8 @@ class FrameGrabber_nwc_yarp : public yarp::proto::framegrabber::FrameGrabberControls_Forwarder, public yarp::proto::framegrabber::FrameGrabberControlsDC1394_Forwarder, public yarp::proto::framegrabber::RgbVisualParams_Forwarder, - public yarp::dev::IPreciselyTimed + public yarp::dev::IPreciselyTimed, + public FrameGrabber_nwc_yarp_ParamsParser { public: FrameGrabber_nwc_yarp(); diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..aa1d668705f --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,155 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#include "FrameGrabber_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(FrameGrabber_nwc_yarpParamsCOMPONENT, "yarp.device.FrameGrabber_nwc_yarp") +} + + +FrameGrabber_nwc_yarp_ParamsParser::FrameGrabber_nwc_yarp_ParamsParser() +{ +} + + +std::vector FrameGrabber_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + params.push_back("carrier"); + params.push_back("no_stream"); + return params; +} + + +bool FrameGrabber_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Prefix of the ports opened locally by the nwc for streaming and rpc operations"; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Name of the remote rpc port opened by the nws"; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + //Parser of parameter no_stream + { + if (config.check("no_stream")) + { + m_no_stream = config.find("no_stream").asBool(); + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'no_stream' using value:" << m_no_stream; + } + else + { + yCInfo(FrameGrabber_nwc_yarpParamsCOMPONENT) << "Parameter 'no_stream' using DEFAULT value:" << m_no_stream; + } + prop_check.unput("no_stream"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(FrameGrabber_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(FrameGrabber_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string FrameGrabber_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: FrameGrabber_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Prefix of the ports opened locally by the nwc for streaming and rpc operations\n"); + doc = doc + std::string("'remote': Name of the remote rpc port opened by the nws\n"); + doc = doc + std::string("'carrier': Protocol used for connection with the nws streaming port\n"); + doc = doc + std::string("'no_stream': Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device frameGrabber_nwc_yarp --local --remote --carrier fast_tcp --no_stream false\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device frameGrabber_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..d925e4caea3 --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_ParamsParser.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef FRAMEGRABBER_NWC_YARP_PARAMSPARSER_H +#define FRAMEGRABBER_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class FrameGrabber_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Prefix of the ports opened locally by the nwc for streaming and rpc operations | - | +* | - | remote | string | - | - | 1 | Name of the remote rpc port opened by the nws | - | +* | - | carrier | string | - | fast_tcp | 0 | Protocol used for connection with the nws streaming port | - | +* | - | no_stream | bool | - | false | 0 | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device frameGrabber_nwc_yarp --local --remote --carrier fast_tcp --no_stream false +* \endcode +* +* \code{.unparsed} +* yarpdev --device frameGrabber_nwc_yarp --local --remote +* \endcode +* +*/ + +class FrameGrabber_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + FrameGrabber_nwc_yarp_ParamsParser(); + ~FrameGrabber_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"FrameGrabber_nwc_yarp"}; + const std::string m_device_name = {"frameGrabber_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"fast_tcp"}; + const std::string m_no_stream_defaultValue = {"false"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"fast_tcp"}; + bool m_no_stream = {false}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_params.md b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_params.md new file mode 100644 index 00000000000..a1415596592 --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nwc_yarp/FrameGrabber_nwc_yarp_params.md @@ -0,0 +1,4 @@ + * | | local | string | - | - | Yes | Prefix of the ports opened locally by the nwc for streaming and rpc operations | | + * | | remote | string | - | - | Yes | Name of the remote rpc port opened by the nws | | + * | | carrier | string | - | fast_tcp | No | Protocol used for connection with the nws streaming port | | + * | | no_stream | bool | - | false | No | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | | diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/frameGrabber_nws_yarp/CMakeLists.txt index 10411af280e..f93eebf07e5 100644 --- a/src/devices/networkWrappers/frameGrabber_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(frameGrabber_nws_yarp EXTRA_CONFIG WRAPPER=frameGrabber_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_frameGrabber_nws_yarp) @@ -15,8 +16,10 @@ if(NOT SKIP_frameGrabber_nws_yarp) target_sources(yarp_frameGrabber_nws_yarp PRIVATE - FrameGrabber_nws_yarp.cpp - FrameGrabber_nws_yarp.h + FrameGrabber_nws_yarp.cpp + FrameGrabber_nws_yarp.h + FrameGrabber_nws_yarp_ParamsParser.cpp + FrameGrabber_nws_yarp_ParamsParser.h ) target_sources(yarp_frameGrabber_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.cpp b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.cpp index 7b83246b0b0..3cd4673159b 100644 --- a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.cpp +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.cpp @@ -18,6 +18,8 @@ YARP_LOG_COMPONENT(FRAMEGRABBER_NWS_YARP, "yarp.device.frameGrabber_nws_yarp") } // namespace +static constexpr double DEFAULT_THREAD_PERIOD = 0.033; // seconds + FrameGrabber_nws_yarp::FrameGrabber_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD) { @@ -32,11 +34,6 @@ FrameGrabber_nws_yarp::~FrameGrabber_nws_yarp() bool FrameGrabber_nws_yarp::close() { - if (!active) { - return false; - } - active = false; - detach(); pImg.interrupt(); @@ -57,42 +54,17 @@ bool FrameGrabber_nws_yarp::close() bool FrameGrabber_nws_yarp::open(yarp::os::Searchable& config) { - if (active) { - yCError(FRAMEGRABBER_NWS_YARP, "Device is already opened"); - return false; - } - - - // Check "period" option - if (config.check("period", "refresh period(in s) of the broadcasted values through yarp ports") && config.find("period").isFloat64()) { - period = config.find("period").asFloat64(); - } else { - yCInfo(FRAMEGRABBER_NWS_YARP) - << "Period parameter not found, using default of" - << DEFAULT_THREAD_PERIOD - << "seconds"; - } - PeriodicThread::setPeriod(period); + if (!this->parseParams(config)) { return false; } + PeriodicThread::setPeriod(m_period); // Check "capabilities" option - if (config.check("capabilities", "two capabilities supported, COLOR and RAW respectively for rgb and raw streaming")) { - if (config.find("capabilities").asString() == "COLOR") { - cap = COLOR; - } else if (config.find("capabilities").asString() == "RAW") { - cap = RAW; - } - } else { - yCWarning(FRAMEGRABBER_NWS_YARP) << "'capabilities' parameter not found or misspelled, the option available are COLOR(default) and RAW, using default"; - } - - - // Check "no_drop" option - noDrop = config.check("no_drop", "if present, use strict policy for sending data"); // FIXME DRDANZ - + if (m_capabilities == "COLOR") { m_cap = COLOR; } + else if (m_capabilities == "RAW") { m_cap = RAW; } + else { yCError(FRAMEGRABBER_NWS_YARP) << "'capabilities' parameter unsupported value"; return false;} // Check "name" option and open ports - std::string pImg_Name = config.check("name", yarp::os::Value("/grabber"), "name of port to send data on").asString(); + std::string pImg_Name = m_name; std::string rpcPort_Name = pImg_Name + "/rpc"; if (!rpcPort.open(rpcPort_Name)) { @@ -103,7 +75,7 @@ bool FrameGrabber_nws_yarp::open(yarp::os::Searchable& config) pImg.promiseType(yarp::os::Type::byName("yarp/image")); pImg.setWriteOnly(); - pImg.setStrict(noDrop); + pImg.setStrict(m_no_drop); if (!pImg.open(pImg_Name)) { yCError(FRAMEGRABBER_NWS_YARP) << "Unable to open image streaming Port" << pImg_Name.c_str(); return false; @@ -111,7 +83,6 @@ bool FrameGrabber_nws_yarp::open(yarp::os::Searchable& config) pImg.setReader(*this); yCInfo(FRAMEGRABBER_NWS_YARP) << "Running, waiting for attach..."; - active = true; return true; } @@ -130,7 +101,7 @@ bool FrameGrabber_nws_yarp::attach(yarp::dev::PolyDriver* poly) poly->view(iFrameGrabberControlsDC1394); poly->view(iPreciselyTimed); - switch (cap) { + switch (m_cap) { case COLOR: { if (iFrameGrabberImage == nullptr) { yCError(FRAMEGRABBER_NWS_YARP) << "Capability \"COLOR\" required not supported"; @@ -206,7 +177,7 @@ bool FrameGrabber_nws_yarp::detach() bool FrameGrabber_nws_yarp::threadInit() { - if (cap == COLOR) { + if (m_cap == COLOR) { img = new yarp::sig::ImageOf; } else { img_Raw = new yarp::sig::ImageOf; @@ -225,7 +196,7 @@ void FrameGrabber_nws_yarp::run() yarp::sig::FlexImage& flex_i = pImg.prepare(); - if (cap == COLOR) { + if (m_cap == COLOR) { if (iFrameGrabberImage != nullptr) { if (iFrameGrabberImage->getImage(*img)) {flex_i.swap(*img);} @@ -236,7 +207,7 @@ void FrameGrabber_nws_yarp::run() } } - if (cap == RAW) { + if (m_cap == RAW) { if (iFrameGrabberImageRaw != nullptr) { if (iFrameGrabberImageRaw->getImage(*img_Raw)) {flex_i.swap(*img_Raw);} @@ -248,11 +219,11 @@ void FrameGrabber_nws_yarp::run() } if (iPreciselyTimed) { - stamp = iPreciselyTimed->getLastInputStamp(); + m_stamp = iPreciselyTimed->getLastInputStamp(); } else { - stamp.update(yarp::os::Time::now()); + m_stamp.update(yarp::os::Time::now()); } - pImg.setEnvelope(stamp); + pImg.setEnvelope(m_stamp); pImg.write(); } diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.h b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.h index 98b9c606ced..fd9b5e151de 100644 --- a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.h +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp.h @@ -25,6 +25,7 @@ #include #include +#include "FrameGrabber_nws_yarp_ParamsParser.h" /** * @ingroup dev_impl_nws_yarp @@ -39,52 +40,15 @@ * * \section frameGrabber_nws_yarp_device_parameters Description of input parameters * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:-----------------------:|:-------:|:--------------:|:-------------:|:--------:|:--------------------------------------------------------------------------------:|:-----:| - * | period | - | double | s | 0.03 | No | refresh period (in s) of the broadcasted values through yarp ports | default 0.03s | - * | name | - | string | - | /grabber | No | Prefix name of the ports opened by the FrameGrabber_nws_yarp | Required suffix like '/rpc' will be added by the device | - * | capabilities | - | string | - | COLOR | No | two capabilities supported, COLOR and RAW respectively for rgb and raw streaming | - | -// FIXME DRDANZ no_drop? - * - * Some example of configuration files: - * - * Example of configuration file using .ini format. - * - * \code{.unparsed} - * device frameGrabber_nws_yarp - * capabilities COLOR # not necessary to specify 'COLOR', this is the default value if capabilities is omitted - * period 30 - * subdevice fakeFrameGrabber - * \endcode - * - * Example of configuration file using .xml format. - * - * \code{.xml} - * - * - * grid - * 1 - * 30 - * - * - * - * 30 - * /grabber - * COLOR - * - * - * grabber - * - * - * - * \endcode + * Parameters required by this device are shown in class: FrameGrabber_nws_yarp_ParamsParser */ + class FrameGrabber_nws_yarp : public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, public yarp::os::PeriodicThread, - public yarp::dev::DeviceResponder + public yarp::dev::DeviceResponder, + public FrameGrabber_nws_yarp_ParamsParser { private: // Ports @@ -111,20 +75,14 @@ class FrameGrabber_nws_yarp : yarp::sig::ImageOf* img_Raw {nullptr}; // Internal state - bool active {false}; - yarp::os::Stamp stamp; - - // Options - static constexpr double DEFAULT_THREAD_PERIOD = 0.03; // seconds - double period {DEFAULT_THREAD_PERIOD}; - bool noDrop {true}; // FIXME DRDANZ + yarp::os::Stamp m_stamp; enum Capabilities { COLOR, RAW, }; - Capabilities cap {COLOR}; + Capabilities m_cap {COLOR}; public: FrameGrabber_nws_yarp(); diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..69d2aa31349 --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.cpp @@ -0,0 +1,151 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#include "FrameGrabber_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(FrameGrabber_nws_yarpParamsCOMPONENT, "yarp.device.FrameGrabber_nws_yarp") +} + + +FrameGrabber_nws_yarp_ParamsParser::FrameGrabber_nws_yarp_ParamsParser() +{ +} + + +std::vector FrameGrabber_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + params.push_back("capabilities"); + params.push_back("no_drop"); + return params; +} + + +bool FrameGrabber_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + //Parser of parameter capabilities + { + if (config.check("capabilities")) + { + m_capabilities = config.find("capabilities").asString(); + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'capabilities' using value:" << m_capabilities; + } + else + { + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'capabilities' using DEFAULT value:" << m_capabilities; + } + prop_check.unput("capabilities"); + } + + //Parser of parameter no_drop + { + if (config.check("no_drop")) + { + m_no_drop = config.find("no_drop").asBool(); + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'no_drop' using value:" << m_no_drop; + } + else + { + yCInfo(FrameGrabber_nws_yarpParamsCOMPONENT) << "Parameter 'no_drop' using DEFAULT value:" << m_no_drop; + } + prop_check.unput("no_drop"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(FrameGrabber_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(FrameGrabber_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string FrameGrabber_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: FrameGrabber_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period (in s) of the broadcasted values through yarp ports\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the FrameGrabber_nws_yarp\n"); + doc = doc + std::string("'capabilities': two capabilities supported, COLOR and RAW respectively for rgb and raw streaming\n"); + doc = doc + std::string("'no_drop': if present, use strict policy for sending data\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device frameGrabber_nws_yarp --period 0.033 --name /grabber --capabilities COLOR --no_drop true\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device frameGrabber_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..94e83b7daa7 --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_ParamsParser.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:44 2024 + + +#ifndef FRAMEGRABBER_NWS_YARP_PARAMSPARSER_H +#define FRAMEGRABBER_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class FrameGrabber_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:--------------------------------------------------------------------------------:|:-------------------------------------------------------:| +* | - | period | double | s | 0.033 | 0 | refresh period (in s) of the broadcasted values through yarp ports | default 0.03s | +* | - | name | string | - | /grabber | 0 | Prefix name of the ports opened by the FrameGrabber_nws_yarp | Required suffix like '/rpc' will be added by the device | +* | - | capabilities | string | - | COLOR | 0 | two capabilities supported, COLOR and RAW respectively for rgb and raw streaming | - | +* | - | no_drop | bool | - | true | 0 | if present, use strict policy for sending data | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device frameGrabber_nws_yarp --period 0.033 --name /grabber --capabilities COLOR --no_drop true +* \endcode +* +* \code{.unparsed} +* yarpdev --device frameGrabber_nws_yarp +* \endcode +* +*/ + +class FrameGrabber_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + FrameGrabber_nws_yarp_ParamsParser(); + ~FrameGrabber_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"FrameGrabber_nws_yarp"}; + const std::string m_device_name = {"frameGrabber_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.033"}; + const std::string m_name_defaultValue = {"/grabber"}; + const std::string m_capabilities_defaultValue = {"COLOR"}; + const std::string m_no_drop_defaultValue = {"true"}; + + double m_period = {0.033}; + std::string m_name = {"/grabber"}; + std::string m_capabilities = {"COLOR"}; + bool m_no_drop = {true}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_params.md b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_params.md new file mode 100644 index 00000000000..0a793d972f2 --- /dev/null +++ b/src/devices/networkWrappers/frameGrabber_nws_yarp/FrameGrabber_nws_yarp_params.md @@ -0,0 +1,4 @@ + * | | period | double | s | 0.033 | No | refresh period (in s) of the broadcasted values through yarp ports | default 0.03s | + * | | name | string | - | /grabber | No | Prefix name of the ports opened by the FrameGrabber_nws_yarp | Required suffix like '/rpc' will be added by the device | + * | | capabilities | string | - | COLOR | No | two capabilities supported, COLOR and RAW respectively for rgb and raw streaming | - | + * | | no_drop | bool | - | true | No | if present, use strict policy for sending data | - | diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/localization2D_nwc_yarp/CMakeLists.txt index 50911f25bfe..d1caec89d54 100644 --- a/src/devices/networkWrappers/localization2D_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(localization2D_nwc_yarp INCLUDE Localization2D_nwc_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_localization2D_nwc_yarp) @@ -16,6 +17,8 @@ if(NOT SKIP_localization2D_nwc_yarp) PRIVATE Localization2D_nwc_yarp.cpp Localization2D_nwc_yarp.h + Localization2D_nwc_yarp_ParamsParser.cpp + Localization2D_nwc_yarp_ParamsParser.h ) target_sources(yarp_localization2D_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.cpp b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.cpp index 711a4364147..e065debd649 100644 --- a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.cpp +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.cpp @@ -25,23 +25,7 @@ YARP_LOG_COMPONENT(LOCALIZATION2D_NWC_YARP, "yarp.device.Localization2D_nwc_yarp bool Localization2D_nwc_yarp::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_remote_name.clear(); - - m_local_name = config.find("local").asString(); - m_remote_name = config.find("remote").asString(); - - if (m_local_name == "") - { - yCError(LOCALIZATION2D_NWC_YARP, "open() error you have to provide a valid 'local' param"); - return false; - } - - if (m_remote_name == "") - { - yCError(LOCALIZATION2D_NWC_YARP, "open() error you have to provide valid 'remote' param"); - return false; - } + if (!parseParams(config)) { return false; } std::string local_rpc, @@ -49,10 +33,10 @@ bool Localization2D_nwc_yarp::open(yarp::os::Searchable &config) remote_streaming_name, local_streaming_name; - local_rpc = m_local_name + "/localization/rpc"; - remote_rpc = m_remote_name + "/rpc"; - remote_streaming_name = m_remote_name + "/stream:o"; - local_streaming_name = m_local_name + "/stream:i"; + local_rpc = m_local + "/localization/rpc"; + remote_rpc = m_remote + "/rpc"; + remote_streaming_name = m_remote + "/stream:o"; + local_streaming_name = m_local + "/stream:i"; if (!m_rpc_port_localization_server.open(local_rpc)) { diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.h b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.h index f24237d9ef2..dc88f253259 100644 --- a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.h +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp.h @@ -22,6 +22,8 @@ #include #include "ILocalization2DMsgs.h" +#include "Localization2D_nwc_yarp_ParamsParser.h" + /** * @ingroup dev_impl_nwc_yarp dev_impl_navigation * @@ -29,21 +31,16 @@ * * \brief `Localization2D_nwc_yarp` A device which allows a user application retrieve the current position of the robot in the world. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the Localization2D_nwc_yarp device. | | - * | remote | - | string | - | - | Yes | Full port name of the port opened on the server side, to which the Localization2D_nwc_yarp connects to. | | + * Parameters required by this device are shown in class: Localization2D_nwc_yarp_ParamsParser */ class Localization2D_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::Nav2D::ILocalization2D + public yarp::dev::Nav2D::ILocalization2D, + public Localization2D_nwc_yarp_ParamsParser { protected: std::mutex m_mutex; yarp::os::Port m_rpc_port_localization_server; - std::string m_local_name; - std::string m_remote_name; ILocalization2DMsgs m_RPC; public: diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..0701ac1b9c8 --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "Localization2D_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Localization2D_nwc_yarpParamsCOMPONENT, "yarp.device.Localization2D_nwc_yarp") +} + + +Localization2D_nwc_yarp_ParamsParser::Localization2D_nwc_yarp_ParamsParser() +{ +} + + +std::vector Localization2D_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool Localization2D_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Localization2D_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(Localization2D_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(Localization2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(Localization2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the Localization2D_nwc_yarp device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(Localization2D_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(Localization2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(Localization2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the Localization2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Localization2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Localization2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Localization2D_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Localization2D_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the Localization2D_nwc_yarp device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the Localization2D_nwc_yarp connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device localization2D_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device localization2D_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..19d21d35be6 --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef LOCALIZATION2D_NWC_YARP_PARAMSPARSER_H +#define LOCALIZATION2D_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Localization2D_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the Localization2D_nwc_yarp device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the Localization2D_nwc_yarp connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device localization2D_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device localization2D_nwc_yarp --local --remote +* \endcode +* +*/ + +class Localization2D_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Localization2D_nwc_yarp_ParamsParser(); + ~Localization2D_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Localization2D_nwc_yarp"}; + const std::string m_device_name = {"localization2D_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_params.md b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_params.md new file mode 100644 index 00000000000..36f80cb5e1e --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nwc_yarp/Localization2D_nwc_yarp_params.md @@ -0,0 +1,2 @@ + * | | local | string | - | - | Yes | Full port name opened by the Localization2D_nwc_yarp device. | | + * | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the Localization2D_nwc_yarp connects to. | | diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/localization2D_nws_yarp/CMakeLists.txt index f5115007c29..f9c1bf8e5dd 100644 --- a/src/devices/networkWrappers/localization2D_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/localization2D_nws_yarp/CMakeLists.txt @@ -9,6 +9,7 @@ yarp_prepare_plugin(localization2D_nws_yarp EXTRA_CONFIG WRAPPER=localization2D_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_localization2D_nws_yarp) @@ -20,6 +21,8 @@ if(NOT SKIP_localization2D_nws_yarp) Localization2D_nws_yarp.cpp ILocalization2DServerImpl.cpp ILocalization2DServerImpl.h + Localization2D_nws_yarp_ParamsParser.h + Localization2D_nws_yarp_ParamsParser.cpp ) target_sources(yarp_localization2D_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.cpp b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.cpp index b1888ae644a..c3952c7fc65 100644 --- a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.cpp +++ b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.cpp @@ -41,8 +41,7 @@ namespace //------------------------------------------------------------------------------------------------------------------------------ -Localization2D_nws_yarp::Localization2D_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD), - m_period(DEFAULT_THREAD_PERIOD) +Localization2D_nws_yarp::Localization2D_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD) { m_stats_time_last = yarp::os::Time::now(); } @@ -83,7 +82,7 @@ bool Localization2D_nws_yarp::attach(PolyDriver* driver) return false; } - PeriodicThread::setPeriod(m_period); + PeriodicThread::setPeriod(m_GENERAL_period); return PeriodicThread::start(); } @@ -101,67 +100,35 @@ bool Localization2D_nws_yarp::detach() bool Localization2D_nws_yarp::open(Searchable& config) { - Property params; - params.fromString(config.toString().c_str()); - yCDebug(LOCALIZATION2D_NWS_YARP) << "Configuration: \n" << config.toString().c_str(); + if (!parseParams(config)) { return false; } - if (config.check("GENERAL") == false) + //check some parameters consistency + if (!m_GENERAL_retrieve_position_periodically) { - yCWarning(LOCALIZATION2D_NWS_YARP) << "Missing GENERAL group, assuming default options"; - } + m_RPC.m_getdata_using_periodic_thread = false; - Bottle& general_group = config.findGroup("GENERAL"); - if (!general_group.check("period")) - { - yCInfo(LOCALIZATION2D_NWS_YARP) << "Missing 'period' parameter. Using default value: " << DEFAULT_THREAD_PERIOD; - m_period = DEFAULT_THREAD_PERIOD; + if (!m_GENERAL_publish_odometry) + {yCWarning(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically is true, but data is not published because publish_odometry is false. This configuration is strange";} + if (!m_GENERAL_publish_location) + {yCWarning(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically is true, but data is not published because publish_location is false. This configuration is strange";} } else { - m_period = general_group.find("period").asFloat64(); - yCInfo(LOCALIZATION2D_NWS_YARP) << "Period requested: " << m_period; - } - - if (!general_group.check("publish_odometry")) - { - m_enable_publish_odometry = general_group.find("publish_odometry").asBool(); - } - if (!general_group.check("publish_location")) - { - m_enable_publish_location = general_group.find("publish_location").asBool(); - } - yCInfo(LOCALIZATION2D_NWS_YARP) << "publish_odometry=" << m_enable_publish_odometry; - yCInfo(LOCALIZATION2D_NWS_YARP) << "publish_location=" << m_enable_publish_location; - - if (!general_group.check("retrieve_position_periodically")) - { - yCInfo(LOCALIZATION2D_NWS_YARP) << "Missing 'retrieve_position_periodically' parameter. Using default value: true. Period:" << m_period ; m_RPC.m_getdata_using_periodic_thread = true; - if (!m_enable_publish_odometry) {yCWarning(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically is true, but data is not published because \ - publish_odometry is false. This configuration is strange";} - if (!m_enable_publish_location) {yCWarning(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically is true, but data is not published because \ - publish_location is false. This configuration is strange";} - } - else - { - m_RPC.m_getdata_using_periodic_thread = general_group.find("retrieve_position_periodically").asBool(); - if (m_RPC.m_getdata_using_periodic_thread) - { yCInfo(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically requested, Period:" << m_period; } - else - { yCInfo(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically NOT requested. Localization data obtained asynchronously."; } } - if (!general_group.check("name")) + //Some debug prints + if (m_RPC.m_getdata_using_periodic_thread) { - yCInfo(LOCALIZATION2D_NWS_YARP) << "Missing 'name' parameter. Using default value:" << m_local_name; + yCInfo(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically requested, Period:" << m_GENERAL_period; } else { - m_local_name = general_group.find("name").asString(); - if (m_local_name.c_str()[0] != '/') { yCError(LOCALIZATION2D_NWS_YARP) << "Missing '/' in name parameter" ; return false; } - yCInfo(LOCALIZATION2D_NWS_YARP) << "Using local name:" << m_local_name; + yCInfo(LOCALIZATION2D_NWS_YARP) << "retrieve_position_periodically NOT requested. Localization data obtained asynchronously."; } + + m_local_name = m_GENERAL_name; m_rpcPortName = m_local_name + "/rpc"; m_2DLocationPortName = m_local_name + "/streaming:o"; m_odometryPortName = m_local_name + "/odometry:o"; @@ -275,10 +242,10 @@ void Localization2D_nws_yarp::run() } m_RPC.getMutex()->unlock(); - if (m_enable_publish_odometry) { + if (m_GENERAL_publish_odometry) { publish_odometry_on_yarp_port(); } - if (m_enable_publish_location) { + if (m_GENERAL_publish_location) { publish_2DLocation_on_yarp_port(); } } diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.h b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.h index 4eeedcf9f9c..35aec5d4740 100644 --- a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.h +++ b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp.h @@ -22,6 +22,7 @@ #include #include "ILocalization2DServerImpl.h" +#include "Localization2D_nws_yarp_ParamsParser.h" /** * @ingroup dev_impl_nws_yarp dev_impl_navigation @@ -30,21 +31,14 @@ * * \brief `localization2D_nws_yarp`: A localization server which can be wrap multiple algorithms and devices to provide robot localization in a 2D World. * - * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:------------------:|:------------------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | GENERAL | period | double | s | 0.01 | No | The period of the working thread | | - * | GENERAL | retrieve_position_periodically | bool | - | true | No | If true, the subdevice is asked periodically to retrieve the current location. Otherwise the current location is obtained asynchronously when a getCurrentPosition() command is issued. | - | - * | GENERAL | name | string | - | /localization2D_nws_yarp | No | The name of the server, used as a prefix for the opened ports | By default ports opened are /xxx/rpc and /xxx/streaming:o | - * | GENERAL | publish_odometry | bool | - | true | No | Periodically publish odometry data over the network | - | - * | GENERAL | publish_location | bool | - | true | No | PEriodically publish location data over the network | - | + * Parameters required by this device are shown in class: Localization2D_nws_yarp_ParamsParser */ class Localization2D_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::PeriodicThread, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public Localization2D_nws_yarp_ParamsParser { protected: @@ -59,15 +53,12 @@ class Localization2D_nws_yarp : std::string m_2DLocationPortName; yarp::os::BufferedPort m_odometryPort; std::string m_odometryPortName; - bool m_enable_publish_odometry=true; - bool m_enable_publish_location=true; //drivers and interfaces yarp::dev::PolyDriver pLoc; yarp::dev::Nav2D::ILocalization2D* iLoc = nullptr; double m_stats_time_last; - double m_period; private: void publish_2DLocation_on_yarp_port(); diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..ba45ce9eae3 --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.cpp @@ -0,0 +1,177 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "Localization2D_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Localization2D_nws_yarpParamsCOMPONENT, "yarp.device.Localization2D_nws_yarp") +} + + +Localization2D_nws_yarp_ParamsParser::Localization2D_nws_yarp_ParamsParser() +{ +} + + +std::vector Localization2D_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("GENERAL::period"); + params.push_back("GENERAL::retrieve_position_periodically"); + params.push_back("GENERAL::name"); + params.push_back("GENERAL::publish_odometry"); + params.push_back("GENERAL::publish_location"); + return params; +} + + +bool Localization2D_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter GENERAL::period + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("period")) + { + m_GENERAL_period = sectionp.find("period").asFloat64(); + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::period' using value:" << m_GENERAL_period; + } + else + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::period' using DEFAULT value:" << m_GENERAL_period; + } + prop_check.unput("GENERAL::period"); + } + + //Parser of parameter GENERAL::retrieve_position_periodically + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("retrieve_position_periodically")) + { + m_GENERAL_retrieve_position_periodically = sectionp.find("retrieve_position_periodically").asBool(); + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::retrieve_position_periodically' using value:" << m_GENERAL_retrieve_position_periodically; + } + else + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::retrieve_position_periodically' using DEFAULT value:" << m_GENERAL_retrieve_position_periodically; + } + prop_check.unput("GENERAL::retrieve_position_periodically"); + } + + //Parser of parameter GENERAL::name + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("name")) + { + m_GENERAL_name = sectionp.find("name").asString(); + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::name' using value:" << m_GENERAL_name; + } + else + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::name' using DEFAULT value:" << m_GENERAL_name; + } + prop_check.unput("GENERAL::name"); + } + + //Parser of parameter GENERAL::publish_odometry + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("publish_odometry")) + { + m_GENERAL_publish_odometry = sectionp.find("publish_odometry").asBool(); + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::publish_odometry' using value:" << m_GENERAL_publish_odometry; + } + else + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::publish_odometry' using DEFAULT value:" << m_GENERAL_publish_odometry; + } + prop_check.unput("GENERAL::publish_odometry"); + } + + //Parser of parameter GENERAL::publish_location + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("publish_location")) + { + m_GENERAL_publish_location = sectionp.find("publish_location").asBool(); + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::publish_location' using value:" << m_GENERAL_publish_location; + } + else + { + yCInfo(Localization2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::publish_location' using DEFAULT value:" << m_GENERAL_publish_location; + } + prop_check.unput("GENERAL::publish_location"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Localization2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Localization2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Localization2D_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Localization2D_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'GENERAL::period': The period of the working thread\n"); + doc = doc + std::string("'GENERAL::retrieve_position_periodically': If true, the subdevice is asked periodically to retrieve the current location. Otherwise the current location is obtained asynchronously when a getCurrentPosition() command is issued.\n"); + doc = doc + std::string("'GENERAL::name': The name of the server, used as a prefix for the opened ports\n"); + doc = doc + std::string("'GENERAL::publish_odometry': Periodically publish odometry data over the network\n"); + doc = doc + std::string("'GENERAL::publish_location': PEriodically publish location data over the network\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device localization2D_nws_yarp --GENERAL::period 0.01 --GENERAL::retrieve_position_periodically true --GENERAL::name /localization2D_nws_yarp --GENERAL::publish_odometry true --GENERAL::publish_location true\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device localization2D_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..1a770786eaa --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_ParamsParser.h @@ -0,0 +1,81 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef LOCALIZATION2D_NWS_YARP_PARAMSPARSER_H +#define LOCALIZATION2D_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Localization2D_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:------------------------------:|:------:|:-----:|:------------------------:|:--------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------:| +* | GENERAL | period | double | s | 0.01 | 0 | The period of the working thread | - | +* | GENERAL | retrieve_position_periodically | bool | - | true | 0 | If true, the subdevice is asked periodically to retrieve the current location. Otherwise the current location is obtained asynchronously when a getCurrentPosition() command is issued. | - | +* | GENERAL | name | string | - | /localization2D_nws_yarp | 0 | The name of the server, used as a prefix for the opened ports | By default ports opened are /xxx/rpc and /xxx/streaming:o | +* | GENERAL | publish_odometry | bool | - | true | 0 | Periodically publish odometry data over the network | - | +* | GENERAL | publish_location | bool | - | true | 0 | PEriodically publish location data over the network | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device localization2D_nws_yarp --GENERAL::period 0.01 --GENERAL::retrieve_position_periodically true --GENERAL::name /localization2D_nws_yarp --GENERAL::publish_odometry true --GENERAL::publish_location true +* \endcode +* +* \code{.unparsed} +* yarpdev --device localization2D_nws_yarp +* \endcode +* +*/ + +class Localization2D_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Localization2D_nws_yarp_ParamsParser(); + ~Localization2D_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Localization2D_nws_yarp"}; + const std::string m_device_name = {"localization2D_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_GENERAL_period_defaultValue = {"0.01"}; + const std::string m_GENERAL_retrieve_position_periodically_defaultValue = {"true"}; + const std::string m_GENERAL_name_defaultValue = {"/localization2D_nws_yarp"}; + const std::string m_GENERAL_publish_odometry_defaultValue = {"true"}; + const std::string m_GENERAL_publish_location_defaultValue = {"true"}; + + double m_GENERAL_period = {0.01}; + bool m_GENERAL_retrieve_position_periodically = {true}; + std::string m_GENERAL_name = {"/localization2D_nws_yarp"}; + bool m_GENERAL_publish_odometry = {true}; + bool m_GENERAL_publish_location = {true}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_params.md b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_params.md new file mode 100644 index 00000000000..66e31b128a8 --- /dev/null +++ b/src/devices/networkWrappers/localization2D_nws_yarp/Localization2D_nws_yarp_params.md @@ -0,0 +1,5 @@ + * | GENERAL | period | double | s | 0.01 | No | The period of the working thread | | + * | GENERAL | retrieve_position_periodically | bool | - | true | No | If true, the subdevice is asked periodically to retrieve the current location. Otherwise the current location is obtained asynchronously when a getCurrentPosition() command is issued. | - | + * | GENERAL | name | string | - | /localization2D_nws_yarp | No | The name of the server, used as a prefix for the opened ports | By default ports opened are /xxx/rpc and /xxx/streaming:o | + * | GENERAL | publish_odometry | bool | - | true | No | Periodically publish odometry data over the network | - | + * | GENERAL | publish_location | bool | - | true | No | PEriodically publish location data over the network | - | diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/map2D_nwc_yarp/CMakeLists.txt index c0c6f8e7185..3c804846e55 100644 --- a/src/devices/networkWrappers/map2D_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/map2D_nwc_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(map2D_nwc_yarp INCLUDE Map2D_nwc_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_map2D_nwc_yarp) @@ -16,6 +17,8 @@ if(NOT SKIP_map2D_nwc_yarp) PRIVATE Map2D_nwc_yarp.cpp Map2D_nwc_yarp.h + Map2D_nwc_yarp_ParamsParser.cpp + Map2D_nwc_yarp_ParamsParser.h ) target_sources(yarp_map2D_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.cpp b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.cpp index 203937a2e8c..05a90c096d9 100644 --- a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.cpp +++ b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.cpp @@ -26,28 +26,12 @@ YARP_LOG_COMPONENT(MAP2D_NWC_YARP, "yarp.device.map2D_nwc_yarp") bool Map2D_nwc_yarp::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_map_server.clear(); + if (!parseParams(config)) { return false; } - m_local_name = config.find("local").asString(); - m_map_server = config.find("remote").asString(); - m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString(); - - if (m_local_name.empty()) - { - yCError(MAP2D_NWC_YARP, "open() error you have to provide valid local name"); - return false; - } - if (m_map_server.empty()) - { - yCError(MAP2D_NWC_YARP, "open() error you have to provide valid remote name"); - return false; - } - - std::string local_rpc1 = m_local_name; + std::string local_rpc1 = m_local; local_rpc1 += "/mapClient_rpc"; - std::string remote_rpc1 = m_map_server; + std::string remote_rpc1 = m_remote; remote_rpc1 += "/rpc"; if (!m_rpcPort_to_Map2D_nws.open(local_rpc1)) diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.h b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.h index fc9b1af3831..2376a8c20b0 100644 --- a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.h +++ b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp.h @@ -19,6 +19,8 @@ #include #include "IMap2DMsgs.h" +#include "Map2D_nwc_yarp_ParamsParser.h" + /** * @ingroup dev_impl_nwc_yarp dev_impl_navigation * @@ -26,23 +28,17 @@ * * \brief `Map2D_nwc_yarp`: A device which allows a client application to store/retrieve user maps device in a map server. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the Map2D_nwc_yarp device. | | - * | remote | - | string | - | - | Yes | Full port name of the port remotely opened by the Map2D_nws_yarp, to which the Map2D_nwc_yarp connects to. | | - * | carrier | - | string | - | tcp | No | The carier used for the connection with the server. | | + * Parameters required by this device are shown in class: Map2D_nwc_yarp_ParamsParser + * */ class Map2D_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::Nav2D::IMap2D + public yarp::dev::Nav2D::IMap2D, + public Map2D_nwc_yarp_ParamsParser { protected: yarp::os::Port m_rpcPort_to_Map2D_nws; - std::string m_local_name; - std::string m_map_server; - std::string m_carrier; IMap2DMsgs m_map_RPC; std::mutex m_mutex; diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..47a0cb691b8 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,139 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "Map2D_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Map2D_nwc_yarpParamsCOMPONENT, "yarp.device.Map2D_nwc_yarp") +} + + +Map2D_nwc_yarp_ParamsParser::Map2D_nwc_yarp_ParamsParser() +{ +} + + +std::vector Map2D_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + params.push_back("carrier"); + return params; +} + + +bool Map2D_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Map2D_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(Map2D_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(Map2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(Map2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the Map2D_nwc_yarp device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(Map2D_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(Map2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(Map2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the Map2D_nws_yarp, to which the Map2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(Map2D_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(Map2D_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Map2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Map2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Map2D_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Map2D_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the Map2D_nwc_yarp device.\n"); + doc = doc + std::string("'remote': Full port name of the port remotely opened by the Map2D_nws_yarp, to which the Map2D_nwc_yarp connects to.\n"); + doc = doc + std::string("'carrier': The carrier used for the connection with the server.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device map2D_nwc_yarp --local --remote --carrier fast_tcp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device map2D_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..5b82fbb9fa6 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef MAP2D_NWC_YARP_PARAMSPARSER_H +#define MAP2D_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Map2D_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:----------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the Map2D_nwc_yarp device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port remotely opened by the Map2D_nws_yarp, to which the Map2D_nwc_yarp connects to. | - | +* | - | carrier | string | - | fast_tcp | 0 | The carrier used for the connection with the server. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device map2D_nwc_yarp --local --remote --carrier fast_tcp +* \endcode +* +* \code{.unparsed} +* yarpdev --device map2D_nwc_yarp --local --remote +* \endcode +* +*/ + +class Map2D_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Map2D_nwc_yarp_ParamsParser(); + ~Map2D_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Map2D_nwc_yarp"}; + const std::string m_device_name = {"map2D_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"fast_tcp"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"fast_tcp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_params.md b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_params.md new file mode 100644 index 00000000000..db3ac0671d6 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nwc_yarp/Map2D_nwc_yarp_params.md @@ -0,0 +1,3 @@ + * | - | local | string | - | - | Yes | Full port name opened by the Map2D_nwc_yarp device. | | + * | - | remote | string | - | - | Yes | Full port name of the port remotely opened by the Map2D_nws_yarp, to which the Map2D_nwc_yarp connects to. | | + * | - | carrier | string | - | fast_tcp | No | The carrier used for the connection with the server. | | diff --git a/src/devices/networkWrappers/map2D_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/map2D_nws_yarp/CMakeLists.txt index 06035000975..3cadfaefe86 100644 --- a/src/devices/networkWrappers/map2D_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/map2D_nws_yarp/CMakeLists.txt @@ -10,6 +10,7 @@ yarp_prepare_plugin(map2D_nws_yarp EXTRA_CONFIG WRAPPER=map2D_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_map2D_nws_yarp) @@ -21,6 +22,8 @@ if(NOT SKIP_map2D_nws_yarp) Map2D_nws_yarp.h Map2DServerImpl.cpp Map2DServerImpl.h + Map2D_nws_yarp_ParamsParser.cpp + Map2D_nws_yarp_ParamsParser.h ) target_sources(yarp_map2D_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.cpp b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.cpp index d39721ee787..4924eac1d73 100644 --- a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.cpp +++ b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.cpp @@ -53,22 +53,12 @@ bool Map2D_nws_yarp::read(yarp::os::ConnectionReader& connection) bool Map2D_nws_yarp::open(yarp::os::Searchable &config) { - Property params; - params.fromString(config.toString()); - - if (!config.check("name")) - { - m_rpcPortName = "/map2D_nws_yarp/rpc"; - } - else - { - m_rpcPortName = config.find("name").asString(); - } + if (!parseParams(config)) { return false; } //open rpc port - if (!m_rpcPort.open(m_rpcPortName)) + if (!m_rpcPort.open(m_name)) { - yCError(MAP2D_NWS_YARP, "Failed to open port %s", m_rpcPortName.c_str()); + yCError(MAP2D_NWS_YARP, "Failed to open port %s", m_name.c_str()); return false; } m_rpcPort.setReader(*this); diff --git a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.h b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.h index 9aee96030cf..dace9294c5b 100644 --- a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.h +++ b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp.h @@ -35,6 +35,7 @@ #include #include "Map2DServerImpl.h" +#include "Map2D_nws_yarp_ParamsParser.h" /** * @ingroup dev_impl_nws_yarp dev_impl_navigation @@ -43,17 +44,15 @@ * * \brief `map2D_nws_yarp`: A device capable of read/save collections of maps from disk, and make them accessible to any Map2DClient device. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:----------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | name | - | string | - | /map2D_nws_yarp/rpc | No | Full name of the rpc port opened by the map2D_nws_yarp device. | | - + * Parameters required by this device are shown in class: Map2D_nws_yarp_ParamsParser + * */ class Map2D_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::PortReader, - public yarp::dev::WrapperSingle + public yarp::dev::WrapperSingle, + public Map2D_nws_yarp_ParamsParser { public: Map2D_nws_yarp(); @@ -73,7 +72,6 @@ class Map2D_nws_yarp : private: std::mutex m_mutex; - std::string m_rpcPortName; yarp::os::RpcServer m_rpcPort; bool read(yarp::os::ConnectionReader& connection) override; diff --git a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..7dcb5e0e2a1 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.cpp @@ -0,0 +1,103 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "Map2D_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Map2D_nws_yarpParamsCOMPONENT, "yarp.device.Map2D_nws_yarp") +} + + +Map2D_nws_yarp_ParamsParser::Map2D_nws_yarp_ParamsParser() +{ +} + + +std::vector Map2D_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + return params; +} + + +bool Map2D_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Map2D_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(Map2D_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(Map2D_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Map2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Map2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Map2D_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Map2D_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': Full name of the rpc port opened by the map2D_nws_yarp device.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device map2D_nws_yarp --name /map2D_nws_yarp/rpc\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device map2D_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..a27c2601330 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef MAP2D_NWS_YARP_PARAMSPARSER_H +#define MAP2D_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Map2D_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------------:|:--------:|:--------------------------------------------------------------:|:-----:| +* | - | name | string | - | /map2D_nws_yarp/rpc | 0 | Full name of the rpc port opened by the map2D_nws_yarp device. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device map2D_nws_yarp --name /map2D_nws_yarp/rpc +* \endcode +* +* \code{.unparsed} +* yarpdev --device map2D_nws_yarp +* \endcode +* +*/ + +class Map2D_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Map2D_nws_yarp_ParamsParser(); + ~Map2D_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Map2D_nws_yarp"}; + const std::string m_device_name = {"map2D_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/map2D_nws_yarp/rpc"}; + + std::string m_name = {"/map2D_nws_yarp/rpc"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_params.md b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_params.md new file mode 100644 index 00000000000..7ee359fba08 --- /dev/null +++ b/src/devices/networkWrappers/map2D_nws_yarp/Map2D_nws_yarp_params.md @@ -0,0 +1 @@ + * | | name | string | - | /map2D_nws_yarp/rpc | No | Full name of the rpc port opened by the map2D_nws_yarp device. | | diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/CMakeLists.txt index d8cd0e4c36e..c717220add8 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(mobileBaseVelocityControl_nwc_yarp INCLUDE MobileBaseVelocityControl_nwc_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_mobileBaseVelocityControl_nwc_yarp) @@ -16,6 +17,8 @@ if(NOT SKIP_mobileBaseVelocityControl_nwc_yarp) PRIVATE MobileBaseVelocityControl_nwc_yarp.cpp MobileBaseVelocityControl_nwc_yarp.h + MobileBaseVelocityControl_nwc_yarp_ParamsParser.cpp + MobileBaseVelocityControl_nwc_yarp_ParamsParser.h ) target_sources(yarp_mobileBaseVelocityControl_nwc_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.cpp b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.cpp index 28dfb2bc5af..249868f3d59 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.cpp +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.cpp @@ -26,30 +26,10 @@ YARP_LOG_COMPONENT(MOBVEL_NWC_YARP, "yarp.device.MobileBaseVelocityControl_nwc_y bool MobileBaseVelocityControl_nwc_yarp::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_server_name.clear(); + if (!parseParams(config)) { return false; } - m_local_name = config.find("local").asString(); - m_server_name = config.find("server").asString(); - m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString(); - - if (m_local_name.empty()) - { - yCError(MOBVEL_NWC_YARP, "open() error you have to provide a valid 'local' param"); - return false; - } - - if (m_server_name.empty()) - { - yCError(MOBVEL_NWC_YARP, "open() error you have to provide a valid 'server' param"); - return false; - } - - std::string local_rpc_1; - std::string remote_rpc_1; - - local_rpc_1 = m_local_name + "/navigation/rpc:o"; - remote_rpc_1 = m_server_name + "/rpc:i"; + std::string local_rpc_1 = m_local + "/navigation/rpc:o"; + std::string remote_rpc_1 = m_server + "/rpc:i"; if (!m_rpc_port.open(local_rpc_1)) { diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.h b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.h index dd2033748e5..c008d754c21 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.h +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp.h @@ -17,6 +17,7 @@ #include #include +#include "MobileBaseVelocityControl_nwc_yarp_ParamsParser.h" /** * @ingroup dev_impl_nwc_yarp dev_impl_navigation @@ -25,24 +26,18 @@ * * \brief `MobileBaseVelocityControl_nwc_yarp`: A device which connects to MobileBaseVelocityControl_nws_yarp to control the velocity of a mobile base. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the device. | | - * | server | - | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | - * | carrier | - | string | - | tcp | No | The carier used for the connection with the server. | | + * Parameters required by this device are shown in class: MobileBaseVelocityControl_nwc_yarp_ParamsParser + * */ class MobileBaseVelocityControl_nwc_yarp: public yarp::dev::DeviceDriver, - public yarp::dev::Nav2D::INavigation2DVelocityActions + public yarp::dev::Nav2D::INavigation2DVelocityActions, + public MobileBaseVelocityControl_nwc_yarp_ParamsParser { protected: std::mutex m_mutex; yarp::os::Port m_rpc_port; - std::string m_local_name; - std::string m_server_name; - std::string m_carrier; MobileBaseVelocityControlRPC m_RPC; public: diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..bc7a11166c4 --- /dev/null +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,139 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#include "MobileBaseVelocityControl_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT, "yarp.device.MobileBaseVelocityControl_nwc_yarp") +} + + +MobileBaseVelocityControl_nwc_yarp_ParamsParser::MobileBaseVelocityControl_nwc_yarp_ParamsParser() +{ +} + + +std::vector MobileBaseVelocityControl_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("server"); + params.push_back("carrier"); + return params; +} + + +bool MobileBaseVelocityControl_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter server + { + if (config.check("server")) + { + m_server = config.find("server").asString(); + yCInfo(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Parameter 'server' using value:" << m_server; + } + else + { + yCError(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'server' not found!"; + yCError(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the server, to which this client connects to."; + return false; + } + prop_check.unput("server"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(MobileBaseVelocityControl_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string MobileBaseVelocityControl_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: MobileBaseVelocityControl_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("'server': Full port name of the port remotely opened by the server, to which this client connects to.\n"); + doc = doc + std::string("'carrier': The carier used for the connection with the server.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device mobileBaseVelocityControl_nwc_yarp --local --server --carrier tcp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device mobileBaseVelocityControl_nwc_yarp --local --server \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..59bc3fded69 --- /dev/null +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef MOBILEBASEVELOCITYCONTROL_NWC_YARP_PARAMSPARSER_H +#define MOBILEBASEVELOCITYCONTROL_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class MobileBaseVelocityControl_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the device. | - | +* | - | server | string | - | - | 1 | Full port name of the port remotely opened by the server, to which this client connects to. | - | +* | - | carrier | string | - | tcp | 0 | The carier used for the connection with the server. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device mobileBaseVelocityControl_nwc_yarp --local --server --carrier tcp +* \endcode +* +* \code{.unparsed} +* yarpdev --device mobileBaseVelocityControl_nwc_yarp --local --server +* \endcode +* +*/ + +class MobileBaseVelocityControl_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + MobileBaseVelocityControl_nwc_yarp_ParamsParser(); + ~MobileBaseVelocityControl_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"MobileBaseVelocityControl_nwc_yarp"}; + const std::string m_device_name = {"mobileBaseVelocityControl_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_server_defaultValue = {""}; + const std::string m_carrier_defaultValue = {"tcp"}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_server = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_carrier = {"tcp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_params.md b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_params.md new file mode 100644 index 00000000000..3713a7b00e6 --- /dev/null +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nwc_yarp/MobileBaseVelocityControl_nwc_yarp_params.md @@ -0,0 +1,3 @@ + * | | local | string | - | - | Yes | Full port name opened by the device. | | + * | | server | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | + * | | carrier | string | - | tcp | No | The carier used for the connection with the server. | | diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/CMakeLists.txt index 96d98aca120..ad73f755712 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(mobileBaseVelocityControl_nws_yarp INCLUDE MobileBaseVelocityControl_nws_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_mobileBaseVelocityControl_nws_yarp) @@ -16,6 +17,8 @@ if(NOT SKIP_mobileBaseVelocityControl_nws_yarp) PRIVATE MobileBaseVelocityControl_nws_yarp.cpp MobileBaseVelocityControl_nws_yarp.h + MobileBaseVelocityControl_nws_yarp_ParamsParser.cpp + MobileBaseVelocityControl_nws_yarp_ParamsParser.h ) target_sources(yarp_mobileBaseVelocityControl_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.cpp b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.cpp index cd5a7b6f3a1..a2a9dae683e 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.cpp +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.cpp @@ -41,19 +41,12 @@ void VelocityInputPortProcessor::onRead(yarp::dev::MobileBaseVelocity& v) bool MobileBaseVelocityControl_nws_yarp::open(yarp::os::Searchable &config) { - //param configuration - m_local_name = config.find("local").asString(); - - if (m_local_name.empty()) - { - yCError(MOBVEL_NWS_YARP, "open() error you have to provide a valid 'local' param"); - return false; - } + if (!parseParams(config)) { return false; } //rpc block { std::string local_rpc_1; - local_rpc_1 = m_local_name + "/rpc:i"; + local_rpc_1 = m_local + "/rpc:i"; if (!m_rpc_port_navigation_server.open(local_rpc_1)) { @@ -71,7 +64,7 @@ bool MobileBaseVelocityControl_nws_yarp::open(yarp::os::Searchable &config) //streaming input block { std::string local_stream_1; - local_stream_1 = m_local_name + "/data:i"; + local_stream_1 = m_local + "/data:i"; if (!m_StreamingInput.open(local_stream_1)) { diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.h b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.h index ade4f6c3c76..5b7df1c5cbe 100644 --- a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.h +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp.h @@ -20,23 +20,7 @@ #include #include -/** - * @ingroup dev_impl_network_clients dev_impl_navigation - * - * \section MobileBaseVelocityControl_nws_yarp - * - * \brief `MobileBaseVelocityControl_nws_yarp`: A device which allows a client to control the velocity of a mobile base from YARP. - * The device opens two ports: a streaming port `/exampleName/data:i` for receiving streaming commands, and a rpc port `/exampleName/rpc:i` for rpc connection with - * a `MobileBaseVelocityControl_nwc_yarp` client device. - * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:-----:|:-------------:|:-------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full name of the port opened by the device. For both ports (i.e. /rpc:i, /data:i) the corresponding suffix is automatically added | | - * - * Example usage: - * yarpdev --device mobileBaseVelocityControl_nws_yarp --subdevice velocityInputHandler --local /input1 -*/ +#include "MobileBaseVelocityControl_nws_yarp_ParamsParser.h" class VelocityInputPortProcessor : public yarp::os::BufferedPort { @@ -49,16 +33,30 @@ class VelocityInputPortProcessor : public yarp::os::BufferedPort +#include + +namespace { + YARP_LOG_COMPONENT(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT, "yarp.device.MobileBaseVelocityControl_nws_yarp") +} + + +MobileBaseVelocityControl_nws_yarp_ParamsParser::MobileBaseVelocityControl_nws_yarp_ParamsParser() +{ +} + + +std::vector MobileBaseVelocityControl_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + return params; +} + + +bool MobileBaseVelocityControl_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << "Description of the parameter: Name of the port opened by the device. For both ports (i.e. /rpc:i, /data:i) the corresponding suffix is automatically added"; + return false; + } + prop_check.unput("local"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(MobileBaseVelocityControl_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string MobileBaseVelocityControl_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: MobileBaseVelocityControl_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Name of the port opened by the device. For both ports (i.e. /rpc:i, /data:i) the corresponding suffix is automatically added\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device mobileBaseVelocityControl_nws_yarp --local /MobileBaseVelocityControl_nws\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device mobileBaseVelocityControl_nws_yarp --local /MobileBaseVelocityControl_nws\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..3143d94586b --- /dev/null +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:45 2024 + + +#ifndef MOBILEBASEVELOCITYCONTROL_NWS_YARP_PARAMSPARSER_H +#define MOBILEBASEVELOCITYCONTROL_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class MobileBaseVelocityControl_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:------------------------------:|:--------:|:----------------------------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | /MobileBaseVelocityControl_nws | 1 | Name of the port opened by the device. For both ports (i.e. /rpc:i, /data:i) the corresponding suffix is automatically added | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device mobileBaseVelocityControl_nws_yarp --local /MobileBaseVelocityControl_nws +* \endcode +* +* \code{.unparsed} +* yarpdev --device mobileBaseVelocityControl_nws_yarp --local /MobileBaseVelocityControl_nws +* \endcode +* +*/ + +class MobileBaseVelocityControl_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + MobileBaseVelocityControl_nws_yarp_ParamsParser(); + ~MobileBaseVelocityControl_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"MobileBaseVelocityControl_nws_yarp"}; + const std::string m_device_name = {"mobileBaseVelocityControl_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {"/MobileBaseVelocityControl_nws"}; + + std::string m_local = {"/MobileBaseVelocityControl_nws"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_params.md b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_params.md new file mode 100644 index 00000000000..0eaea613b72 --- /dev/null +++ b/src/devices/networkWrappers/mobileBaseVelocityControl_nws_yarp/MobileBaseVelocityControl_nws_yarp_params.md @@ -0,0 +1 @@ + * | | local | string | - | /MobileBaseVelocityControl_nws | Yes | Name of the port opened by the device. For both ports (i.e. /rpc:i, /data:i) the corresponding suffix is automatically added | | diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/CMakeLists.txt b/src/devices/networkWrappers/multipleanalogsensorsclient/CMakeLists.txt index c5bc077202c..3139f72caaf 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsclient/CMakeLists.txt +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/CMakeLists.txt @@ -6,6 +6,7 @@ yarp_prepare_plugin(multipleanalogsensorsclient TYPE MultipleAnalogSensorsClient INCLUDE MultipleAnalogSensorsClient.h DEFAULT ON + GENERATE_PARSER ) if(ENABLE_multipleanalogsensorsclient) @@ -15,6 +16,8 @@ if(ENABLE_multipleanalogsensorsclient) PRIVATE MultipleAnalogSensorsClient.cpp MultipleAnalogSensorsClient.h + MultipleAnalogSensorsClient_ParamsParser.cpp + MultipleAnalogSensorsClient_ParamsParser.h ) target_sources(yarp_multipleanalogsensorsclient PRIVATE $) diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.cpp b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.cpp index 9e2c348c805..1143e6538ae 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.cpp +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.cpp @@ -39,88 +39,63 @@ void SensorStreamingDataInputPort::updateTimeoutStatus() const bool MultipleAnalogSensorsClient::open(yarp::os::Searchable& config) { - m_carrier = config.check("carrier", yarp::os::Value("tcp"), "the carrier used for the connection with the server").asString(); + if (!parseParams(config)) { return false; } - m_externalConnection = config.check("externalConnection",yarp::os::Value(false)).asBool(); - if (!config.check("remote")) - { - yCError(MULTIPLEANALOGSENSORSCLIENT, "Missing name parameter, exiting."); - return false; - } - - if (!config.check("local")) - { - yCError(MULTIPLEANALOGSENSORSCLIENT, "Missing local parameter, exiting."); - return false; - } - - if (config.check("timeout") && !(config.find("timeout").isFloat64())) - { - yCError(MULTIPLEANALOGSENSORSCLIENT, "'timeout' parameter is present but is not double, exiting."); - return false; - } - - std::string remote = config.find("remote").asString(); - std::string local = config.find("local").asString(); + m_streamingPort.timeoutInSeconds = m_timeout; - // Optional timeout parameter - m_streamingPort.timeoutInSeconds = config.check("timeout", yarp::os::Value(0.02), "Timeout parameter").asFloat64(); - - m_localRPCPortName = local + "/rpc:i"; - m_localStreamingPortName = local + "/measures:i"; - m_remoteRPCPortName = remote + "/rpc:o"; - m_remoteStreamingPortName = remote + "/measures:o"; + std::string localRPCPortName = m_local + "/rpc:i"; + std::string localStreamingPortName = m_local + "/measures:i"; + std::string remoteRPCPortName = m_remote + "/rpc:o"; + std::string remoteStreamingPortName = m_remote + "/measures:o"; // TODO(traversaro) : as soon as the method for checking port names validity // are available in YARP ( https://github.com/robotology/yarp/pull/1508 ) add some checks // Open ports - bool ok = m_rpcPort.open(m_localRPCPortName); + bool ok = m_rpcPort.open(localRPCPortName); if (!ok) { yCError(MULTIPLEANALOGSENSORSCLIENT, "Failure to open the port %s.", - m_localRPCPortName.c_str()); + localRPCPortName.c_str()); close(); return false; } - ok = m_streamingPort.open(m_localStreamingPortName); + ok = m_streamingPort.open(localStreamingPortName); m_streamingPort.useCallback(); if (!ok) { yCError(MULTIPLEANALOGSENSORSCLIENT, "Failure to open the port %s.", - m_localStreamingPortName.c_str()); + localStreamingPortName.c_str()); close(); return false; } // Connect ports if (!m_externalConnection) { - ok = yarp::os::Network::connect(m_localRPCPortName, m_remoteRPCPortName, m_carrier); + ok = yarp::os::Network::connect(localRPCPortName, remoteRPCPortName, m_carrier); if (!ok) { yCError(MULTIPLEANALOGSENSORSCLIENT, "Failure connecting port %s to %s.", - m_localRPCPortName.c_str(), - m_remoteRPCPortName.c_str()); + localRPCPortName.c_str(), + remoteRPCPortName.c_str()); yCError(MULTIPLEANALOGSENSORSCLIENT, "Check that the specified MultipleAnalogSensorsServer is up."); close(); return false; } - m_RPCConnectionActive = true; - ok = yarp::os::Network::connect(m_remoteStreamingPortName, m_localStreamingPortName, m_carrier); + ok = yarp::os::Network::connect(remoteStreamingPortName, localStreamingPortName, m_carrier); if (!ok) { yCError(MULTIPLEANALOGSENSORSCLIENT, "Failure connecting port %s to %s.", - m_remoteStreamingPortName.c_str(), - m_localStreamingPortName.c_str()); + remoteStreamingPortName.c_str(), + localStreamingPortName.c_str()); yCError(MULTIPLEANALOGSENSORSCLIENT, "Check that the specified MultipleAnalogSensorsServer is up."); close(); return false; } - m_StreamingConnectionActive = true; // Once the connection is active, we just the metadata only once ok = m_RPCInterface.yarp().attachAsClient(m_rpcPort); @@ -143,15 +118,6 @@ bool MultipleAnalogSensorsClient::open(yarp::os::Searchable& config) bool MultipleAnalogSensorsClient::close() { - if (m_StreamingConnectionActive) - { - yarp::os::Network::disconnect(m_remoteStreamingPortName, m_localStreamingPortName); - } - if (m_RPCConnectionActive) - { - yarp::os::Network::disconnect(m_localRPCPortName, m_remoteRPCPortName); - } - m_streamingPort.close(); m_rpcPort.close(); diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.h b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.h index aab3f74e166..a9fe9714340 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.h +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient.h @@ -15,6 +15,8 @@ #include #include +#include "MultipleAnalogSensorsClient_ParamsParser.h" + #include @@ -38,18 +40,7 @@ class SensorStreamingDataInputPort : * * \brief `multipleanalogsensorsclient`: The client side of a device exposing MultipleAnalogSensors interfaces. * -* | YARP device name | -* |:-----------------:| -* | `multipleanalogsensorsclient` | -* -* The parameters accepted by this device are: -* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | -* |:------------------:|:--------------:|:-------:|:--------------:|:-------------:|:------------:|:--------------------------------------------------------------------------------------:|:-----:| -* | remote | - | string | - | - | Yes | Prefix of the ports to which to connect, opened by MultipleAnalogSensorsServer device. | | -* | local | - | string | - | - | Yes | Port prefix of the ports opened by this device. | | -* | timeout | - | double | seconds | 0.02 | No | Timeout after which the device reports an error if no measurement was received. | | -* | externalConnection | - | bool | - | false | No | If set to true, the connection to the rpc port of the MAS server is skipped and it is possible to connect to the data source externally after being opened | Use case: e.g yarpdataplayer source. Note that with this configuration some information like sensor name, frame name and sensor number will be not available.| -* | carrier | - | string | - | tcp | No | The carier used for the connection with the server. | | +* Parameters required by this device are shown in class: MultipleAnalogSensorsClient_ParamsParser * */ class MultipleAnalogSensorsClient : @@ -63,18 +54,11 @@ class MultipleAnalogSensorsClient : public yarp::dev::ISixAxisForceTorqueSensors, public yarp::dev::IContactLoadCellArrays, public yarp::dev::IEncoderArrays, - public yarp::dev::ISkinPatches + public yarp::dev::ISkinPatches, + public MultipleAnalogSensorsClient_ParamsParser { SensorStreamingDataInputPort m_streamingPort; yarp::os::Port m_rpcPort; - std::string m_localRPCPortName; - std::string m_localStreamingPortName; - std::string m_remoteRPCPortName; - std::string m_remoteStreamingPortName; - std::string m_carrier; - bool m_RPCConnectionActive{false}; - bool m_StreamingConnectionActive{false}; - bool m_externalConnection{false}; MultipleAnalogSensorsMetadata m_RPCInterface; SensorRPCData m_sensorsMetadata; diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.cpp b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.cpp new file mode 100644 index 00000000000..c67a392bf13 --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.cpp @@ -0,0 +1,171 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "MultipleAnalogSensorsClient_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(MultipleAnalogSensorsClientParamsCOMPONENT, "yarp.device.MultipleAnalogSensorsClient") +} + + +MultipleAnalogSensorsClient_ParamsParser::MultipleAnalogSensorsClient_ParamsParser() +{ +} + + +std::vector MultipleAnalogSensorsClient_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("remote"); + params.push_back("local"); + params.push_back("timeout"); + params.push_back("externalConnection"); + params.push_back("carrier"); + return params; +} + + +bool MultipleAnalogSensorsClient_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(MultipleAnalogSensorsClientParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(MultipleAnalogSensorsClientParamsCOMPONENT) << "Description of the parameter: Prefix of the ports to which to connect, opened by MultipleAnalogSensorsServer device."; + return false; + } + prop_check.unput("remote"); + } + + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(MultipleAnalogSensorsClientParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(MultipleAnalogSensorsClientParamsCOMPONENT) << "Description of the parameter: Port prefix of the ports opened by this device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter timeout + { + if (config.check("timeout")) + { + m_timeout = config.find("timeout").asFloat64(); + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'timeout' using value:" << m_timeout; + } + else + { + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'timeout' using DEFAULT value:" << m_timeout; + } + prop_check.unput("timeout"); + } + + //Parser of parameter externalConnection + { + if (config.check("externalConnection")) + { + m_externalConnection = config.find("externalConnection").asBool(); + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'externalConnection' using value:" << m_externalConnection; + } + else + { + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'externalConnection' using DEFAULT value:" << m_externalConnection; + } + prop_check.unput("externalConnection"); + } + + //Parser of parameter carrier + { + if (config.check("carrier")) + { + m_carrier = config.find("carrier").asString(); + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'carrier' using value:" << m_carrier; + } + else + { + yCInfo(MultipleAnalogSensorsClientParamsCOMPONENT) << "Parameter 'carrier' using DEFAULT value:" << m_carrier; + } + prop_check.unput("carrier"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(MultipleAnalogSensorsClientParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(MultipleAnalogSensorsClientParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string MultipleAnalogSensorsClient_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: MultipleAnalogSensorsClient\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'remote': Prefix of the ports to which to connect, opened by MultipleAnalogSensorsServer device.\n"); + doc = doc + std::string("'local': Port prefix of the ports opened by this device.\n"); + doc = doc + std::string("'timeout': Timeout after which the device reports an error if no measurement was received.\n"); + doc = doc + std::string("'externalConnection': If set to true, the connection to the rpc port of the MAS server is skipped and it is possible to connect to the data source externally after being opened\n"); + doc = doc + std::string("'carrier': The carier used for the connection with the server.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device multipleanalogsensorsclient --remote --local --timeout 0.02 --externalConnection false --carrier tcp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device multipleanalogsensorsclient --remote --local \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.h b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.h new file mode 100644 index 00000000000..5f0ce9f33dd --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_ParamsParser.h @@ -0,0 +1,81 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef MULTIPLEANALOGSENSORSCLIENT_PARAMSPARSER_H +#define MULTIPLEANALOGSENSORSCLIENT_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class MultipleAnalogSensorsClient. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:------------------:|:------:|:-----:|:-------------:|:--------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------:| +* | - | remote | string | - | - | 1 | Prefix of the ports to which to connect, opened by MultipleAnalogSensorsServer device. | - | +* | - | local | string | - | - | 1 | Port prefix of the ports opened by this device. | - | +* | - | timeout | double | s | 0.02 | 0 | Timeout after which the device reports an error if no measurement was received. | - | +* | - | externalConnection | bool | - | false | 0 | If set to true, the connection to the rpc port of the MAS server is skipped and it is possible to connect to the data source externally after being opened | Use case: e.g yarpdataplayer source. Note that with this configuration some information like sensor name, frame name and sensor number will be not available. | +* | - | carrier | string | - | tcp | 0 | The carier used for the connection with the server. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device multipleanalogsensorsclient --remote --local --timeout 0.02 --externalConnection false --carrier tcp +* \endcode +* +* \code{.unparsed} +* yarpdev --device multipleanalogsensorsclient --remote --local +* \endcode +* +*/ + +class MultipleAnalogSensorsClient_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + MultipleAnalogSensorsClient_ParamsParser(); + ~MultipleAnalogSensorsClient_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"MultipleAnalogSensorsClient"}; + const std::string m_device_name = {"multipleanalogsensorsclient"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_remote_defaultValue = {""}; + const std::string m_local_defaultValue = {""}; + const std::string m_timeout_defaultValue = {"0.02"}; + const std::string m_externalConnection_defaultValue = {"false"}; + const std::string m_carrier_defaultValue = {"tcp"}; + + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + double m_timeout = {0.02}; + bool m_externalConnection = {false}; + std::string m_carrier = {"tcp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_params.md b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_params.md new file mode 100644 index 00000000000..b65163e4fa2 --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsclient/MultipleAnalogSensorsClient_params.md @@ -0,0 +1,5 @@ +* | | remote | string | - | - | Yes | Prefix of the ports to which to connect, opened by MultipleAnalogSensorsServer device. | | +* | | local | string | - | - | Yes | Port prefix of the ports opened by this device. | | +* | | timeout | double | s | 0.02 | No | Timeout after which the device reports an error if no measurement was received. | | +* | | externalConnection | bool | - | false | No | If set to true, the connection to the rpc port of the MAS server is skipped and it is possible to connect to the data source externally after being opened | Use case: e.g yarpdataplayer source. Note that with this configuration some information like sensor name, frame name and sensor number will be not available.| +* | | carrier | string | - | tcp | No | The carier used for the connection with the server. | | diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/CMakeLists.txt b/src/devices/networkWrappers/multipleanalogsensorsserver/CMakeLists.txt index 603eaecc86d..83833a7e667 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsserver/CMakeLists.txt +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/CMakeLists.txt @@ -8,6 +8,7 @@ yarp_prepare_plugin(multipleanalogsensorsserver EXTRA_CONFIG WRAPPER=multipleanalogsensorsserver DEFAULT ON + GENERATE_PARSER ) if(ENABLE_multipleanalogsensorsserver) @@ -17,6 +18,8 @@ if(ENABLE_multipleanalogsensorsserver) PRIVATE MultipleAnalogSensorsServer.cpp MultipleAnalogSensorsServer.h + MultipleAnalogSensorsServer_ParamsParser.h + MultipleAnalogSensorsServer_ParamsParser.cpp ) target_sources(yarp_multipleanalogsensorsserver PRIVATE $) diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.cpp b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.cpp index bb5e29e2ad8..5dda2b54a68 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.cpp +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.cpp @@ -112,25 +112,9 @@ MultipleAnalogSensorsServer::~MultipleAnalogSensorsServer() = default; bool MultipleAnalogSensorsServer::open(yarp::os::Searchable& config) { - if (!config.check("name")) - { - yCError(MULTIPLEANALOGSENSORSSERVER, "Missing name parameter, exiting."); - return false; - } - - if (!config.check("period")) - { - yCError(MULTIPLEANALOGSENSORSSERVER, "Missing period parameter, exiting."); - return false; - } + if (!parseParams(config)) { return false; } - if (!config.find("period").isInt32()) - { - yCError(MULTIPLEANALOGSENSORSSERVER, "Period parameter is present but it is not an integer, exiting."); - return false; - } - - m_periodInS = config.find("period").asInt32() / 1000.0; + m_periodInS = m_period / 1000.0; if (m_periodInS <= 0) { @@ -140,8 +124,6 @@ bool MultipleAnalogSensorsServer::open(yarp::os::Searchable& config) return false; } - std::string name = config.find("name").asString(); - // Reserve a fair amount of elements // It would be great if yarp::sig::Vector had a reserve method m_buffer.resize(100); @@ -149,10 +131,8 @@ bool MultipleAnalogSensorsServer::open(yarp::os::Searchable& config) // TODO(traversaro) Add port name validation when ready, // see https://github.com/robotology/yarp/pull/1508 - m_RPCPortName = name + "/rpc:o"; - m_streamingPortName = name + "/measures:o"; - - + m_RPCPortName = m_name + "/rpc:o"; + m_streamingPortName = m_name + "/measures:o"; return true; } diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.h b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.h index 36e6f5dbc22..15e315987b4 100644 --- a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.h +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer.h @@ -18,6 +18,7 @@ #include "SensorStreamingData.h" #include "MultipleAnalogSensorsMetadata.h" +#include "MultipleAnalogSensorsServer_ParamsParser.h" /** * @ingroup dev_impl_wrapper @@ -27,21 +28,14 @@ * The data on the /${name}/measures:o is streamed every ${period} milliseconds, and an envelope to each data is added with a timestamp obtained by calling the * yarp::os::Time::now() method when the message is written on the port. * - * | YARP device name | - * |:-----------------:| - * | `multipleanalogsensorsserver` | - * - * The parameters accepted by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:--------------------------: |:-----------------------------------------------------------------:|:-----:| - * | name | - | string | - | - | Yes | Prefix of the port opened by this device | MUST start with a '/' character | - * | period | - | int | ms | - | Yes | Refresh period of the broadcasted values in ms | | + * Parameters required by this device are shown in class: MultipleAnalogSensorsServer_ParamsParser */ class MultipleAnalogSensorsServer : public yarp::os::PeriodicThread, public yarp::dev::DeviceDriver, public yarp::dev::IMultipleWrapper, - public MultipleAnalogSensorsMetadata + public MultipleAnalogSensorsMetadata, + public MultipleAnalogSensorsServer_ParamsParser { double m_periodInS{0.01}; yarp::os::Stamp m_stamp; diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.cpp b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.cpp new file mode 100644 index 00000000000..8773af25574 --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.cpp @@ -0,0 +1,124 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#include "MultipleAnalogSensorsServer_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(MultipleAnalogSensorsServerParamsCOMPONENT, "yarp.device.MultipleAnalogSensorsServer") +} + + +MultipleAnalogSensorsServer_ParamsParser::MultipleAnalogSensorsServer_ParamsParser() +{ +} + + +std::vector MultipleAnalogSensorsServer_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + params.push_back("period"); + return params; +} + + +bool MultipleAnalogSensorsServer_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(MultipleAnalogSensorsServerParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(MultipleAnalogSensorsServerParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "Description of the parameter: Prefix of the port opened by this device"; + return false; + } + prop_check.unput("name"); + } + + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asInt64(); + yCInfo(MultipleAnalogSensorsServerParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "Mandatory parameter 'period' not found!"; + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "Description of the parameter: Refresh period of the broadcasted values in ms"; + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "Remember: Units for this parameter are: 'ms'"; + return false; + } + prop_check.unput("period"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(MultipleAnalogSensorsServerParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(MultipleAnalogSensorsServerParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string MultipleAnalogSensorsServer_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: MultipleAnalogSensorsServer\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': Prefix of the port opened by this device\n"); + doc = doc + std::string("'period': Refresh period of the broadcasted values in ms\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device multipleanalogsensorsserver --name --period \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device multipleanalogsensorsserver --name --period \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.h b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.h new file mode 100644 index 00000000000..9fd49db6b39 --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:46 2024 + + +#ifndef MULTIPLEANALOGSENSORSSERVER_PARAMSPARSER_H +#define MULTIPLEANALOGSENSORSSERVER_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class MultipleAnalogSensorsServer. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:----------------------------------------------:|:-------------------------------:| +* | - | name | string | - | - | 1 | Prefix of the port opened by this device | MUST start with a '/' character | +* | - | period | int | ms | - | 1 | Refresh period of the broadcasted values in ms | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device multipleanalogsensorsserver --name --period +* \endcode +* +* \code{.unparsed} +* yarpdev --device multipleanalogsensorsserver --name --period +* \endcode +* +*/ + +class MultipleAnalogSensorsServer_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + MultipleAnalogSensorsServer_ParamsParser(); + ~MultipleAnalogSensorsServer_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"MultipleAnalogSensorsServer"}; + const std::string m_device_name = {"multipleanalogsensorsserver"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {""}; + const std::string m_period_defaultValue = {""}; + + std::string m_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + int m_period = {0}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_params.md b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_params.md new file mode 100644 index 00000000000..379990d4597 --- /dev/null +++ b/src/devices/networkWrappers/multipleanalogsensorsserver/MultipleAnalogSensorsServer_params.md @@ -0,0 +1,2 @@ + * | | name | string | - | - | Yes | Prefix of the port opened by this device | MUST start with a '/' character | + * | | period | int | ms | - | Yes | Refresh period of the broadcasted values in ms | | diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/navigation2D_nwc_yarp/CMakeLists.txt index 622bf8e6af8..fd614e5df94 100644 --- a/src/devices/networkWrappers/navigation2D_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/CMakeLists.txt @@ -7,6 +7,7 @@ yarp_prepare_plugin(navigation2D_nwc_yarp INCLUDE Navigation2D_nwc_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_navigation2D_nwc_yarp) @@ -21,6 +22,8 @@ if(NOT SKIP_navigation2D_nwc_yarp) Navigation2D_nwc_yarp_iNav2DTarget.cpp Navigation2D_nwc_yarp.cpp Navigation2D_nwc_yarp.h + Navigation2D_nwc_yarp_ParamsParser.cpp + Navigation2D_nwc_yarp_ParamsParser.h ) target_link_libraries(yarp_navigation2D_nwc_yarp diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.cpp b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.cpp index 5230d4d5a0d..622b3b59a88 100644 --- a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.cpp +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.cpp @@ -26,49 +26,12 @@ YARP_LOG_COMPONENT(NAVIGATION2D_NWC_YARP, "yarp.device.navigation2D_nwc_yarp") bool Navigation2D_nwc_yarp::open(yarp::os::Searchable &config) { - m_local_name.clear(); - m_navigation_server_name.clear(); - m_map_locations_server_name.clear(); - m_localization_server_name.clear(); + if (!parseParams(config)) { return false; } - m_local_name = config.find("local").asString(); - m_navigation_server_name = config.find("navigation_server").asString(); - m_map_locations_server_name = config.find("map_locations_server").asString(); - m_localization_server_name = config.find("localization_server").asString(); - - if (m_local_name == "") - { - yCError(NAVIGATION2D_NWC_YARP, "open() error you have to provide a valid 'local' param"); - return false; - } - - if (m_navigation_server_name == "") - { - yCError(NAVIGATION2D_NWC_YARP, "open() error you have to provide a valid 'navigation_server' param"); - return false; - } - - if (m_map_locations_server_name == "") - { - yCError(NAVIGATION2D_NWC_YARP, "open() error you have to provide valid 'map_locations_server' param"); - return false; - } - - if (m_localization_server_name == "") - { - yCError(NAVIGATION2D_NWC_YARP, "open() error you have to provide valid 'localization_server' param"); - return false; - } - - if (config.check("period")) - { - m_period = config.find("period").asInt32(); - } - else - { - m_period = 10; - yCWarning(NAVIGATION2D_NWC_YARP, "Using default period of %d ms" , m_period); - } + std::string local_name = m_local; + std::string navigation_server_name = m_navigation_server; + std::string map_locations_server_name = m_map_locations_server; + std::string localization_server_name = m_localization_server; std::string local_rpc_1, @@ -81,15 +44,15 @@ bool Navigation2D_nwc_yarp::open(yarp::os::Searchable &config) local_streaming_name, rpc_port_user_commandsName; - local_rpc_1 = m_local_name + "/navigation/rpc"; - local_rpc_2 = m_local_name + "/locations/rpc"; - local_rpc_3 = m_local_name + "/localization/rpc"; - remote_rpc_1 = m_navigation_server_name + "/rpc"; - remote_rpc_2 = m_map_locations_server_name + "/rpc"; - remote_rpc_3 = m_localization_server_name + "/rpc"; - remote_streaming_name = m_localization_server_name + "/stream:o"; - local_streaming_name = m_local_name + "/stream:i"; - rpc_port_user_commandsName = m_local_name + "/user_commands/rpc"; + local_rpc_1 = local_name + "/navigation/rpc"; + local_rpc_2 = local_name + "/locations/rpc"; + local_rpc_3 = local_name + "/localization/rpc"; + remote_rpc_1 = navigation_server_name + "/rpc"; + remote_rpc_2 = map_locations_server_name + "/rpc"; + remote_rpc_3 = localization_server_name + "/rpc"; + remote_streaming_name = localization_server_name + "/stream:o"; + local_streaming_name = local_name + "/stream:i"; + rpc_port_user_commandsName = local_name + "/user_commands/rpc"; if (!m_rpc_port_to_navigation_server.open(local_rpc_1)) { diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.h b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.h index aae66e45874..07696e9f69f 100644 --- a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.h +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp.h @@ -19,6 +19,7 @@ #include #include +#include "Navigation2D_nwc_yarp_ParamsParser.h" #define DEFAULT_THREAD_PERIOD 20 //ms @@ -30,19 +31,14 @@ * * \brief `navigation2D_nwc_yarp`: A device which allows a client application to perform navigation tasks, such as commanding the robot to reach a specific location in a map. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the Navigation2D_nwc_yarp device. | | - * | navigation_server | - | string | - | - | Yes | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | | - * | map_locations_server | - | string | - | - | Yes | Full port name of the port remotely opened by the Map2DServer, to which the Navigation2D_nwc_yarp connects to. | | - * | localization_server | - | string | - | - | Yes | Full port name of the port remotely opened by the Localization server, to which the Navigation2D_nwc_yarp connects to. | | + * Parameters required by this device are shown in class: Navigation2D_nwc_yarp_ParamsParser */ class Navigation2D_nwc_yarp: public yarp::dev::DeviceDriver, public yarp::dev::Nav2D::INavigation2D, - public yarp::os::PortReader + public yarp::os::PortReader, + public Navigation2D_nwc_yarp_ParamsParser { protected: //thrift stuff @@ -56,11 +52,6 @@ class Navigation2D_nwc_yarp: yarp::os::Port m_rpc_port_to_Map2DServer; yarp::os::Port m_rpc_port_to_localization_server; yarp::os::Port m_rpc_port_user_commands; - std::string m_local_name; - std::string m_navigation_server_name; - std::string m_map_locations_server_name; - std::string m_localization_server_name; - int m_period; public: diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..0fe11f777de --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,159 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "Navigation2D_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Navigation2D_nwc_yarpParamsCOMPONENT, "yarp.device.Navigation2D_nwc_yarp") +} + + +Navigation2D_nwc_yarp_ParamsParser::Navigation2D_nwc_yarp_ParamsParser() +{ +} + + +std::vector Navigation2D_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("navigation_server"); + params.push_back("map_locations_server"); + params.push_back("localization_server"); + return params; +} + + +bool Navigation2D_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Navigation2D_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(Navigation2D_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the Navigation2D_nwc_yarp device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter navigation_server + { + if (config.check("navigation_server")) + { + m_navigation_server = config.find("navigation_server").asString(); + yCInfo(Navigation2D_nwc_yarpParamsCOMPONENT) << "Parameter 'navigation_server' using value:" << m_navigation_server; + } + else + { + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'navigation_server' not found!"; + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("navigation_server"); + } + + //Parser of parameter map_locations_server + { + if (config.check("map_locations_server")) + { + m_map_locations_server = config.find("map_locations_server").asString(); + yCInfo(Navigation2D_nwc_yarpParamsCOMPONENT) << "Parameter 'map_locations_server' using value:" << m_map_locations_server; + } + else + { + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'map_locations_server' not found!"; + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the Map2DServer, to which the Navigation2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("map_locations_server"); + } + + //Parser of parameter localization_server + { + if (config.check("localization_server")) + { + m_localization_server = config.find("localization_server").asString(); + yCInfo(Navigation2D_nwc_yarpParamsCOMPONENT) << "Parameter 'localization_server' using value:" << m_localization_server; + } + else + { + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'localization_server' not found!"; + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the Localization server, to which the Navigation2D_nwc_yarp connects to."; + return false; + } + prop_check.unput("localization_server"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Navigation2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Navigation2D_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Navigation2D_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Navigation2D_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the Navigation2D_nwc_yarp device.\n"); + doc = doc + std::string("'navigation_server': Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to.\n"); + doc = doc + std::string("'map_locations_server': Full port name of the port remotely opened by the Map2DServer, to which the Navigation2D_nwc_yarp connects to.\n"); + doc = doc + std::string("'localization_server': Full port name of the port remotely opened by the Localization server, to which the Navigation2D_nwc_yarp connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device navigation2D_nwc_yarp --local --navigation_server --map_locations_server --localization_server \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device navigation2D_nwc_yarp --local --navigation_server --map_locations_server --localization_server \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..0273eff8b10 --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_ParamsParser.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef NAVIGATION2D_NWC_YARP_PARAMSPARSER_H +#define NAVIGATION2D_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Navigation2D_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------------:|:------:|:-----:|:-------------:|:--------:|:----------------------------------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the Navigation2D_nwc_yarp device. | - | +* | - | navigation_server | string | - | - | 1 | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | - | +* | - | map_locations_server | string | - | - | 1 | Full port name of the port remotely opened by the Map2DServer, to which the Navigation2D_nwc_yarp connects to. | - | +* | - | localization_server | string | - | - | 1 | Full port name of the port remotely opened by the Localization server, to which the Navigation2D_nwc_yarp connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device navigation2D_nwc_yarp --local --navigation_server --map_locations_server --localization_server +* \endcode +* +* \code{.unparsed} +* yarpdev --device navigation2D_nwc_yarp --local --navigation_server --map_locations_server --localization_server +* \endcode +* +*/ + +class Navigation2D_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Navigation2D_nwc_yarp_ParamsParser(); + ~Navigation2D_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Navigation2D_nwc_yarp"}; + const std::string m_device_name = {"navigation2D_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_navigation_server_defaultValue = {""}; + const std::string m_map_locations_server_defaultValue = {""}; + const std::string m_localization_server_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_navigation_server = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_map_locations_server = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_localization_server = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_params.md b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_params.md new file mode 100644 index 00000000000..d77c94be857 --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nwc_yarp/Navigation2D_nwc_yarp_params.md @@ -0,0 +1,4 @@ + * | | local | string | - | - | Yes | Full port name opened by the Navigation2D_nwc_yarp device. | | + * | | navigation_server | string | - | - | Yes | Full port name of the port remotely opened by the Navigation server, to which the Navigation2D_nwc_yarp connects to. | | + * | | map_locations_server | string | - | - | Yes | Full port name of the port remotely opened by the Map2DServer, to which the Navigation2D_nwc_yarp connects to. | | + * | | localization_server | string | - | - | Yes | Full port name of the port remotely opened by the Localization server, to which the Navigation2D_nwc_yarp connects to. | | diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/navigation2D_nws_yarp/CMakeLists.txt index 520b999e41a..5d3c4a3705f 100644 --- a/src/devices/networkWrappers/navigation2D_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/CMakeLists.txt @@ -3,10 +3,11 @@ yarp_prepare_plugin(navigation2D_nws_yarp CATEGORY device - TYPE navigation2D_nws_yarp - INCLUDE navigation2D_nws_yarp.h + TYPE Navigation2D_nws_yarp + INCLUDE Navigation2D_nws_yarp.h DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_navigation2D_nws_yarp) @@ -14,10 +15,12 @@ if(NOT SKIP_navigation2D_nws_yarp) target_sources(yarp_navigation2D_nws_yarp PRIVATE - navigation2D_nws_yarp.h - navigation2D_nws_yarp.cpp + Navigation2D_nws_yarp.h + Navigation2D_nws_yarp.cpp INavigation2DServerImpl.h INavigation2DServerImpl.cpp + Navigation2D_nws_yarp_ParamsParser.cpp + Navigation2D_nws_yarp_ParamsParser.h ) target_sources(yarp_navigation2D_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.cpp b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.cpp similarity index 72% rename from src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.cpp rename to src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.cpp index fee281d0578..605d667e674 100644 --- a/src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.cpp +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.cpp @@ -14,7 +14,7 @@ #include #include #include -#include "navigation2D_nws_yarp.h" +#include "Navigation2D_nws_yarp.h" using namespace yarp::os; using namespace yarp::dev; @@ -24,14 +24,14 @@ namespace { YARP_LOG_COMPONENT(NAVIGATION2D_NWS_YARP, "yarp.device.navigation2D_nws_yarp") } -navigation2D_nws_yarp::navigation2D_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD) +Navigation2D_nws_yarp::Navigation2D_nws_yarp() : PeriodicThread(DEFAULT_THREAD_PERIOD) { m_navigation_status=yarp::dev::Nav2D::navigation_status_idle; m_stats_time_last = yarp::os::Time::now(); m_prev_navigation_status = getStatusAsString(m_navigation_status); } -bool navigation2D_nws_yarp::attach(PolyDriver* driver) +bool Navigation2D_nws_yarp::attach(PolyDriver* driver) { if (driver->isValid()) { @@ -54,11 +54,11 @@ bool navigation2D_nws_yarp::attach(PolyDriver* driver) m_RPC.setInterfaces(iNav_target, iNav_ctrl, iNav_vel); - PeriodicThread::setPeriod(m_period); + PeriodicThread::setPeriod(m_GENERAL_period); return PeriodicThread::start(); } -bool navigation2D_nws_yarp::detach() +bool Navigation2D_nws_yarp::detach() { if (PeriodicThread::isRunning()) { @@ -71,40 +71,12 @@ bool navigation2D_nws_yarp::detach() return true; } -bool navigation2D_nws_yarp::open(Searchable& config) +bool Navigation2D_nws_yarp::open(Searchable& config) { - Property params; - params.fromString(config.toString().c_str()); - yCDebug(NAVIGATION2D_NWS_YARP) << "Configuration: \n" << config.toString().c_str(); + if (!parseParams(config)) { return false; } - if (config.check("GENERAL") == false) - { - yCWarning(NAVIGATION2D_NWS_YARP) << "Missing GENERAL group, assuming default options"; - } - - Bottle& general_group = config.findGroup("GENERAL"); - if (!general_group.check("period")) - { - yCInfo(NAVIGATION2D_NWS_YARP) << "Missing 'period' parameter. Using default value: 0.010"; - m_period = 0.010; - } - else - { - m_period = config.find("period").asFloat64(); - } - - if (!general_group.check("name")) - { - yCInfo(NAVIGATION2D_NWS_YARP) << "Missing 'name' parameter. Using default value: " << m_local_name; - } - else - { - m_local_name = config.find("name").asString(); - if (m_local_name.c_str()[0] != '/') { yCError(NAVIGATION2D_NWS_YARP) << "Missing '/' in name parameter"; return false; } - yCInfo(NAVIGATION2D_NWS_YARP) << "Using local name:" << m_local_name; - } - m_rpcPortName = m_local_name + "/rpc"; - m_statusPortName = m_local_name + "/status:o"; + m_rpcPortName = m_GENERAL_name + "/rpc"; + m_statusPortName = m_GENERAL_name + "/status:o"; if (!initialize_YARP(config)) { @@ -117,7 +89,7 @@ bool navigation2D_nws_yarp::open(Searchable& config) return true; } -bool navigation2D_nws_yarp::initialize_YARP(yarp::os::Searchable ¶ms) +bool Navigation2D_nws_yarp::initialize_YARP(yarp::os::Searchable ¶ms) { if (!m_rpcPort.open(m_rpcPortName.c_str())) { @@ -135,7 +107,7 @@ bool navigation2D_nws_yarp::initialize_YARP(yarp::os::Searchable ¶ms) return true; } -bool navigation2D_nws_yarp::close() +bool Navigation2D_nws_yarp::close() { yCTrace(NAVIGATION2D_NWS_YARP, "Close"); if (PeriodicThread::isRunning()) @@ -147,7 +119,7 @@ bool navigation2D_nws_yarp::close() return true; } -bool navigation2D_nws_yarp::read(yarp::os::ConnectionReader& connection) +bool Navigation2D_nws_yarp::read(yarp::os::ConnectionReader& connection) { bool b = m_RPC.read(connection); if (b) @@ -161,7 +133,7 @@ bool navigation2D_nws_yarp::read(yarp::os::ConnectionReader& connection) } } -void navigation2D_nws_yarp::run() +void Navigation2D_nws_yarp::run() { bool ok = iNav_ctrl->getNavigationStatus(m_navigation_status); @@ -186,7 +158,7 @@ void navigation2D_nws_yarp::run() } } -std::string navigation2D_nws_yarp::getStatusAsString(NavigationStatusEnum status) +std::string Navigation2D_nws_yarp::getStatusAsString(NavigationStatusEnum status) { if (status == navigation_status_idle) { return std::string("navigation_status_idle"); @@ -212,7 +184,7 @@ std::string navigation2D_nws_yarp::getStatusAsString(NavigationStatusEnum status return std::string("navigation_status_error"); } -void navigation2D_nws_yarp::updateStatusPort(std::string& status) +void Navigation2D_nws_yarp::updateStatusPort(std::string& status) { Bottle output_state; output_state.addString(status); diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.h b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.h similarity index 69% rename from src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.h rename to src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.h index 6c511077b4c..c401e4eb8a2 100644 --- a/src/devices/networkWrappers/navigation2D_nws_yarp/navigation2D_nws_yarp.h +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp.h @@ -16,6 +16,8 @@ #include "INavigation2DServerImpl.h" #include +#include "Navigation2D_nws_yarp_ParamsParser.h" + #ifndef NAV_SERVER_H #define NAV_SERVER_H @@ -28,26 +30,22 @@ * * \brief `navigation2D_nws_yarp`: A navigation server which can be wrap multiple algorithms and devices to perform a navigation task in a 2D World. * + * Parameters required by this device are shown in class: Navigation2D_nws_yarp_ParamsParser * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:------------------:|:------------------------:|:-----------: |:-----------------------------------------------------------------:|:-----:| - * | GENERAL | period | double | s | 0.01 | No | The period of the working thread | | - * | GENERAL | name | string | - | /navigation_nws_yarp | No | The name of the server, used as a prefix for the opened ports | - | */ #define DEF_m_RPC 1 -class navigation2D_nws_yarp : public yarp::dev::DeviceDriver, +class Navigation2D_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::PeriodicThread, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public Navigation2D_nws_yarp_ParamsParser { protected: //thrift INavigation2DRPCd m_RPC; - std::string m_local_name = "/navigation2D_nws_yarp"; yarp::os::Port m_rpcPort; yarp::os::Port m_statusPort; std::string m_rpcPortName; @@ -61,14 +59,13 @@ class navigation2D_nws_yarp : public yarp::dev::DeviceDriver, yarp::dev::Nav2D::INavigation2DTargetActions* iNav_target = nullptr; yarp::dev::Nav2D::INavigation2DVelocityActions* iNav_vel = nullptr; - double m_period; double m_stats_time_last; public: /** * Default module constructor */ - navigation2D_nws_yarp(); + Navigation2D_nws_yarp(); public: virtual bool open(yarp::os::Searchable& prop) override; diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..412185bf46b --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "Navigation2D_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Navigation2D_nws_yarpParamsCOMPONENT, "yarp.device.Navigation2D_nws_yarp") +} + + +Navigation2D_nws_yarp_ParamsParser::Navigation2D_nws_yarp_ParamsParser() +{ +} + + +std::vector Navigation2D_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("GENERAL::period"); + params.push_back("GENERAL::name"); + return params; +} + + +bool Navigation2D_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Navigation2D_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter GENERAL::period + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("period")) + { + m_GENERAL_period = sectionp.find("period").asFloat64(); + yCInfo(Navigation2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::period' using value:" << m_GENERAL_period; + } + else + { + yCInfo(Navigation2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::period' using DEFAULT value:" << m_GENERAL_period; + } + prop_check.unput("GENERAL::period"); + } + + //Parser of parameter GENERAL::name + { + yarp::os::Bottle sectionp; + sectionp = config.findGroup("GENERAL"); + if (sectionp.check("name")) + { + m_GENERAL_name = sectionp.find("name").asString(); + yCInfo(Navigation2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::name' using value:" << m_GENERAL_name; + } + else + { + yCInfo(Navigation2D_nws_yarpParamsCOMPONENT) << "Parameter 'GENERAL::name' using DEFAULT value:" << m_GENERAL_name; + } + prop_check.unput("GENERAL::name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Navigation2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Navigation2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Navigation2D_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Navigation2D_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'GENERAL::period': The period of the working thread\n"); + doc = doc + std::string("'GENERAL::name': The name of the server, used as a prefix for the opened ports\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device navigation2D_nws_yarp --GENERAL::period 0.01 --GENERAL::name /navigation2D_nws_yarp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device navigation2D_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..0f033600bcf --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef NAVIGATION2D_NWS_YARP_PARAMSPARSER_H +#define NAVIGATION2D_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Navigation2D_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:----------------------:|:--------:|:-------------------------------------------------------------:|:-----:| +* | GENERAL | period | double | s | 0.01 | 0 | The period of the working thread | - | +* | GENERAL | name | string | - | /navigation2D_nws_yarp | 0 | The name of the server, used as a prefix for the opened ports | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device navigation2D_nws_yarp --GENERAL::period 0.01 --GENERAL::name /navigation2D_nws_yarp +* \endcode +* +* \code{.unparsed} +* yarpdev --device navigation2D_nws_yarp +* \endcode +* +*/ + +class Navigation2D_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Navigation2D_nws_yarp_ParamsParser(); + ~Navigation2D_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Navigation2D_nws_yarp"}; + const std::string m_device_name = {"navigation2D_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_GENERAL_period_defaultValue = {"0.01"}; + const std::string m_GENERAL_name_defaultValue = {"/navigation2D_nws_yarp"}; + + double m_GENERAL_period = {0.01}; + std::string m_GENERAL_name = {"/navigation2D_nws_yarp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_params.md b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_params.md new file mode 100644 index 00000000000..4c144ac7b5d --- /dev/null +++ b/src/devices/networkWrappers/navigation2D_nws_yarp/Navigation2D_nws_yarp_params.md @@ -0,0 +1,2 @@ + * | GENERAL | period | double | s | 0.01 | No | The period of the working thread | | + * | GENERAL | name | string | - | /navigation2D_nws_yarp | No | The name of the server, used as a prefix for the opened ports | - | diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/odometry2D_nws_yarp/CMakeLists.txt index a3050f50d39..d6e03e45771 100644 --- a/src/devices/networkWrappers/odometry2D_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/CMakeLists.txt @@ -10,6 +10,7 @@ yarp_prepare_plugin(odometry2D_nws_yarp WRAPPER=odometry2D_nws_yarp DEPENDS "TARGET YARP::YARP_math" DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_odometry2D_nws_yarp) @@ -21,6 +22,8 @@ if(NOT SKIP_odometry2D_nws_yarp) Odometry2D_nws_yarp.h Odometry2DServerImpl.cpp Odometry2DServerImpl.h + Odometry2D_nws_yarp_ParamsParser.cpp + Odometry2D_nws_yarp_ParamsParser.h ) target_sources(yarp_odometry2D_nws_yarp PRIVATE $) diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.cpp b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.cpp index ddc85b18cf4..19a4cefa967 100644 --- a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.cpp +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.cpp @@ -63,30 +63,12 @@ bool Odometry2D_nws_yarp::threadInit() bool Odometry2D_nws_yarp::open(yarp::os::Searchable &config) { - yarp::os::Property params; - params.fromString(config.toString()); + if (!this->parseParams(config)) { return false; } - if (!config.check("period")) - { - yCWarning(ODOMETRY2D_NWS_YARP) << "missing 'period' parameter, using default value of" << DEFAULT_THREAD_PERIOD; - } else { - m_period = config.find("period").asFloat64(); - } - - if (!config.check("name")) - { - yCInfo(ODOMETRY2D_NWS_YARP) << "Missing 'name' parameter. Using default value: " << m_local_name; - } - else - { - m_local_name = config.find("name").asString(); - if (m_local_name.c_str()[0] != '/') { yCError(ODOMETRY2D_NWS_YARP) << "Missing '/' in name parameter"; return false; } - yCInfo(ODOMETRY2D_NWS_YARP) << "Using local name:" << m_local_name; - } - m_rpcPortName = m_local_name + "/rpc"; - m_odometerStreamingPortName = m_local_name + "/odometer:o"; - m_odometryStreamingPortName = m_local_name + "/odometry:o"; - m_velocityStreamingPortName = m_local_name + "/velocity:o"; + m_rpcPortName = m_name + "/rpc"; + m_odometerStreamingPortName = m_name + "/odometer:o"; + m_odometryStreamingPortName = m_name + "/odometry:o"; + m_velocityStreamingPortName = m_name + "/velocity:o"; //open rpc port if (!m_rpcPort.open(m_rpcPortName)) diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.h b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.h index e5d584cdc9c..2e801a0f418 100644 --- a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.h +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp.h @@ -15,6 +15,8 @@ #include #include +#include "Odometry2D_nws_yarp_ParamsParser.h" + #define DEFAULT_THREAD_PERIOD 0.02 //s /** @@ -27,56 +29,15 @@ * - a port for velocity. * The attached device must implement a `yarp::dev::Nav2D::IOdometry2D` interface. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:-------------------:|:-----------------------:|:-------:|:--------------:|:---------------------:|:-----------------------------: |:-----------------------------------------------------:|:-----:| - * | period | - | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | - * | name | - | string | - | /odometry2D_nws_yarp | No | The name of the server, used as a prefix for the opened ports | | - * - * Example of configuration file using .ini format. - * - * \code{.unparsed} - * device odometry2D_nws_yarp - * period 0.02 - * name /odometry2D_nws_yarp - * - * subdevice fakeOdometry - * \endcode - * - * example of xml file with a fake odometer - * - * \code{.unparsed} - * - * - * - * - * - * - * - * /odometry2D_nws_yarp - * - * - * fakeOdometry_device - * - * - * - * - * - * - * \endcode - * - * example of command via terminal. - * - * \code{.unparsed} - * yarpdev --device odometry2D_nws_yarp --period 0.01 --subdevice fakeOdometry - * \endcode + * Parameters required by this device are shown in class: Odometry2D_nws_yarp_ParamsParser */ class Odometry2D_nws_yarp : public yarp::os::PeriodicThread, public yarp::dev::DeviceDriver, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public Odometry2D_nws_yarp_ParamsParser { public: Odometry2D_nws_yarp(); @@ -109,7 +70,6 @@ class Odometry2D_nws_yarp : yarp::os::RpcServer m_rpcPort; //yarp streaming data - std::string m_local_name = "/odometry2D_nws_yarp"; std::string m_odometerStreamingPortName; std::string m_odometryStreamingPortName; std::string m_velocityStreamingPortName; @@ -118,9 +78,6 @@ class Odometry2D_nws_yarp : size_t m_stampCount{0}; yarp::dev::OdometryData m_oldOdometryData{0,0,0,0,0,0,0,0,0}; - // thread - double m_period{DEFAULT_THREAD_PERIOD}; - // timestamp yarp::os::Stamp m_lastStateStamp; diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..6f4b87ff22a --- /dev/null +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.cpp @@ -0,0 +1,119 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "Odometry2D_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(Odometry2D_nws_yarpParamsCOMPONENT, "yarp.device.Odometry2D_nws_yarp") +} + + +Odometry2D_nws_yarp_ParamsParser::Odometry2D_nws_yarp_ParamsParser() +{ +} + + +std::vector Odometry2D_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + return params; +} + + +bool Odometry2D_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(Odometry2D_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(Odometry2D_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(Odometry2D_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(Odometry2D_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(Odometry2D_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(Odometry2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(Odometry2D_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string Odometry2D_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: Odometry2D_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period of the broadcasted values in s\n"); + doc = doc + std::string("'name': The name of the server, used as a prefix for the opened ports\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device odometry2D_nws_yarp --period 0.02 --name /odometry2D_nws_yarp\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device odometry2D_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..e643df6b87a --- /dev/null +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef ODOMETRY2D_NWS_YARP_PARAMSPARSER_H +#define ODOMETRY2D_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class Odometry2D_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:--------------------:|:--------:|:-------------------------------------------------------------:|:-------------:| +* | - | period | double | s | 0.02 | 0 | refresh period of the broadcasted values in s | default 0.02s | +* | - | name | string | - | /odometry2D_nws_yarp | 0 | The name of the server, used as a prefix for the opened ports | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device odometry2D_nws_yarp --period 0.02 --name /odometry2D_nws_yarp +* \endcode +* +* \code{.unparsed} +* yarpdev --device odometry2D_nws_yarp +* \endcode +* +*/ + +class Odometry2D_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + Odometry2D_nws_yarp_ParamsParser(); + ~Odometry2D_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"Odometry2D_nws_yarp"}; + const std::string m_device_name = {"odometry2D_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_name_defaultValue = {"/odometry2D_nws_yarp"}; + + double m_period = {0.02}; + std::string m_name = {"/odometry2D_nws_yarp"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_params.md b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_params.md new file mode 100644 index 00000000000..3a2a02a5702 --- /dev/null +++ b/src/devices/networkWrappers/odometry2D_nws_yarp/Odometry2D_nws_yarp_params.md @@ -0,0 +1,2 @@ + * | | period | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | + * | | name | string | - | /odometry2D_nws_yarp | No | The name of the server, used as a prefix for the opened ports | | diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/serialPort_nwc_yarp/CMakeLists.txt index a17eecd2799..d7036361941 100644 --- a/src/devices/networkWrappers/serialPort_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/CMakeLists.txt @@ -4,8 +4,9 @@ yarp_prepare_plugin(serialPort_nwc_yarp CATEGORY device TYPE SerialPort_nwc_yarp - INCLUDE serialPort_nwc_yarp.h + INCLUDE SerialPort_nwc_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_serialPort_nwc_yarp) @@ -13,8 +14,10 @@ if(NOT SKIP_serialPort_nwc_yarp) target_sources(yarp_serialPort_nwc_yarp PRIVATE - serialPort_nwc_yarp.cpp - serialPort_nwc_yarp.h + SerialPort_nwc_yarp.cpp + SerialPort_nwc_yarp.h + SerialPort_nwc_yarp_ParamsParser.cpp + SerialPort_nwc_yarp_ParamsParser.h ) target_link_libraries(yarp_serialPort_nwc_yarp diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.cpp b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.cpp similarity index 85% rename from src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.cpp rename to src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.cpp index 5e1573a3e70..508d4f0874d 100644 --- a/src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.cpp +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "serialPort_nwc_yarp.h" +#include "SerialPort_nwc_yarp.h" #include #include @@ -67,15 +67,13 @@ bool SerialPort_nwc_yarp::close() return closeMain(); } -bool SerialPort_nwc_yarp::open(Searchable& prop) +bool SerialPort_nwc_yarp::open(Searchable& config) { + if (!parseParams(config)) { return false; } + { - std::string local_rpc = - prop.check("local",Value("/serialPort_nwc_yarp"), - "local rpc port name").asString(); - std::string remote_rpc = - prop.check("remote", Value("/serialPort_nws_yarp/rpc"), - "remote rpc port name").asString(); + std::string local_rpc = m_local; + std::string remote_rpc = m_remote; if (!m_rpcPort.open(local_rpc)) { diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.h b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.h similarity index 89% rename from src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.h rename to src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.h index 6ce74cc72e6..3626186b4e4 100644 --- a/src/devices/networkWrappers/serialPort_nwc_yarp/serialPort_nwc_yarp.h +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp.h @@ -19,6 +19,8 @@ #include #include "ISerialMsgs.h" +#include "SerialPort_nwc_yarp_ParamsParser.h" + using namespace yarp::os; using namespace yarp::sig; using namespace yarp::dev; @@ -28,10 +30,12 @@ using namespace yarp::dev; * * \brief `serialPort_nwc_yarp`: a client for a serialPort_nws_yarp device * + * Parameters required by this device are shown in class: SerialPort_nwc_yarp_ParamsParser */ class SerialPort_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::ISerialDevice + public yarp::dev::ISerialDevice, + public SerialPort_nwc_yarp_ParamsParser { private: ISerialMsgs m_rpc; diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..24be6ed0a66 --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "SerialPort_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SerialPort_nwc_yarpParamsCOMPONENT, "yarp.device.SerialPort_nwc_yarp") +} + + +SerialPort_nwc_yarp_ParamsParser::SerialPort_nwc_yarp_ParamsParser() +{ +} + + +std::vector SerialPort_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool SerialPort_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SerialPort_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(SerialPort_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(SerialPort_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(SerialPort_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(SerialPort_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(SerialPort_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(SerialPort_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port opened on the server side, to which the device connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SerialPort_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SerialPort_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SerialPort_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SerialPort_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("'remote': Full port name of the port opened on the server side, to which the device connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device serialPort_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device serialPort_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..b18c862fd4a --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef SERIALPORT_NWC_YARP_PARAMSPARSER_H +#define SERIALPORT_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SerialPort_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:--------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port opened on the server side, to which the device connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device serialPort_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device serialPort_nwc_yarp --local --remote +* \endcode +* +*/ + +class SerialPort_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SerialPort_nwc_yarp_ParamsParser(); + ~SerialPort_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SerialPort_nwc_yarp"}; + const std::string m_device_name = {"serialPort_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_params.md b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_params.md new file mode 100644 index 00000000000..372ef4a8616 --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nwc_yarp/SerialPort_nwc_yarp_params.md @@ -0,0 +1,2 @@ +* | | local | string | - | - | Yes | Full port name opened by the device. | | +* | | remote | string | - | - | Yes | Full port name of the port opened on the server side, to which the device connects to. | | diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/serialPort_nws_yarp/CMakeLists.txt index 45837a135ee..8f1d5835591 100644 --- a/src/devices/networkWrappers/serialPort_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/serialPort_nws_yarp/CMakeLists.txt @@ -4,10 +4,11 @@ yarp_prepare_plugin(serialPort_nws_yarp CATEGORY device TYPE SerialPort_nws_yarp - INCLUDE serialPort_nws_yarp.h + INCLUDE SerialPort_nws_yarp.h EXTRA_CONFIG WRAPPER=serialPort_nws_yarp DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_serialPort_nws_yarp) @@ -15,8 +16,10 @@ if(NOT SKIP_serialPort_nws_yarp) target_sources(yarp_serialPort_nws_yarp PRIVATE - serialPort_nws_yarp.cpp - serialPort_nws_yarp.h + SerialPort_nws_yarp.cpp + SerialPort_nws_yarp.h + SerialPort_nws_yarp_ParamsParser.cpp + SerialPort_nws_yarp_ParamsParser.h ) target_link_libraries(yarp_serialPort_nws_yarp diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.cpp b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.cpp similarity index 95% rename from src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.cpp rename to src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.cpp index f0d5299c304..731df0cea20 100644 --- a/src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.cpp +++ b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "serialPort_nws_yarp.h" +#include "SerialPort_nws_yarp.h" #include #include @@ -22,11 +22,11 @@ bool SerialPort_nws_yarp::close() return closeMain(); } -bool SerialPort_nws_yarp::open(Searchable& prop) +bool SerialPort_nws_yarp::open(Searchable& config) { - std::string rootName = - prop.check("name",Value("/serial"), - "prefix for port names").asString(); + if (!parseParams(config)) { return false; } + + std::string rootName = m_name; command_buffer.attach(toDevice); reply_buffer.attach(fromDevice); diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.h b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.h similarity index 93% rename from src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.h rename to src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.h index 67af55bc8be..51e27e1ee15 100644 --- a/src/devices/networkWrappers/serialPort_nws_yarp/serialPort_nws_yarp.h +++ b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp.h @@ -21,6 +21,8 @@ #include #include "ISerialMsgs.h" +#include "SerialPort_nws_yarp_ParamsParser.h" + using namespace yarp::os; using namespace yarp::sig; using namespace yarp::dev; @@ -70,12 +72,15 @@ class ISerialMsgsd : public ISerialMsgs * text to the serial port. * The output port streams out whatever information it gets in the * serial port as text bottles. + * + * Parameters required by this device are shown in class: SerialPort_nws_yarp_ParamsParser */ class SerialPort_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::Thread, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public SerialPort_nws_yarp_ParamsParser { private: yarp::dev::ISerialDevice* m_iserial{ nullptr }; diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..bb41477ccbd --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.cpp @@ -0,0 +1,137 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#include "SerialPort_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SerialPort_nws_yarpParamsCOMPONENT, "yarp.device.SerialPort_nws_yarp") +} + + +SerialPort_nws_yarp_ParamsParser::SerialPort_nws_yarp_ParamsParser() +{ +} + + +std::vector SerialPort_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("period"); + params.push_back("name"); + params.push_back("frame_id"); + return params; +} + + +bool SerialPort_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter period + { + if (config.check("period")) + { + m_period = config.find("period").asFloat64(); + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << "Parameter 'period' using value:" << m_period; + } + else + { + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << "Parameter 'period' using DEFAULT value:" << m_period; + } + prop_check.unput("period"); + } + + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCError(SerialPort_nws_yarpParamsCOMPONENT) << "Mandatory parameter 'name' not found!"; + yCError(SerialPort_nws_yarpParamsCOMPONENT) << "Description of the parameter: Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor"; + return false; + } + prop_check.unput("name"); + } + + //Parser of parameter frame_id + { + if (config.check("frame_id")) + { + m_frame_id = config.find("frame_id").asString(); + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << "Parameter 'frame_id' using value:" << m_frame_id; + } + else + { + yCInfo(SerialPort_nws_yarpParamsCOMPONENT) << "Parameter 'frame_id' using DEFAULT value:" << m_frame_id; + } + prop_check.unput("frame_id"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SerialPort_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SerialPort_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SerialPort_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SerialPort_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'period': refresh period of the broadcasted values in s\n"); + doc = doc + std::string("'name': Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor\n"); + doc = doc + std::string("'frame_id': name of the attached frame\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device serialPort_nws_yarp --period 0.02 --name --frame_id \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device serialPort_nws_yarp --name \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..0d241c9072a --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_ParamsParser.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:47 2024 + + +#ifndef SERIALPORT_NWS_YARP_PARAMSPARSER_H +#define SERIALPORT_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SerialPort_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-----------------------------------------------------------------------------------:|:-------------------------------------------------------:| +* | - | period | double | s | 0.02 | 0 | refresh period of the broadcasted values in s | default 0.02s | +* | - | name | string | - | - | 1 | Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor | Required suffix like '/rpc' will be added by the device | +* | - | frame_id | string | - | - | 0 | name of the attached frame | Currently not used, reserved for future use | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device serialPort_nws_yarp --period 0.02 --name --frame_id +* \endcode +* +* \code{.unparsed} +* yarpdev --device serialPort_nws_yarp --name +* \endcode +* +*/ + +class SerialPort_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SerialPort_nws_yarp_ParamsParser(); + ~SerialPort_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SerialPort_nws_yarp"}; + const std::string m_device_name = {"serialPort_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_period_defaultValue = {"0.02"}; + const std::string m_name_defaultValue = {""}; + const std::string m_frame_id_defaultValue = {""}; + + double m_period = {0.02}; + std::string m_name = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_frame_id = {}; //This default value of this string is an empty string. It is highly recommended to provide a suggested value also for optional string parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_params.md b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_params.md new file mode 100644 index 00000000000..5ffd751ea4e --- /dev/null +++ b/src/devices/networkWrappers/serialPort_nws_yarp/SerialPort_nws_yarp_params.md @@ -0,0 +1,3 @@ + * | | period | double | s | 0.02 | No | refresh period of the broadcasted values in s | default 0.02s | + * | | name | string | - | - | Yes | Prefix name of the ports opened by the wrapper, e.g. /robotName/Rangefinder2DSensor | Required suffix like '/rpc' will be added by the device | + * | | frame_id | string | - | - | No | name of the attached frame | Currently not used, reserved for future use | diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/CMakeLists.txt index fbefdf309a8..b738edf66f2 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/CMakeLists.txt @@ -6,6 +6,7 @@ yarp_prepare_plugin(speechSynthesizer_nwc_yarp TYPE SpeechSynthesizer_nwc_yarp INCLUDE SpeechSynthesizer_nwc_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_speechSynthesizer_nwc_yarp) @@ -15,6 +16,8 @@ if(NOT SKIP_speechSynthesizer_nwc_yarp) PRIVATE SpeechSynthesizer_nwc_yarp.cpp SpeechSynthesizer_nwc_yarp.h + SpeechSynthesizer_nwc_yarp_ParamsParser.h + SpeechSynthesizer_nwc_yarp_ParamsParser.cpp ) target_link_libraries(yarp_speechSynthesizer_nwc_yarp diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp index 5413de0d970..e7b214a05cc 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.cpp @@ -25,27 +25,10 @@ bool SpeechSynthesizer_nwc_yarp::close() bool SpeechSynthesizer_nwc_yarp::open(yarp::os::Searchable& config) { - m_local_name.clear(); - m_thrift_server_name.clear(); + if (!parseParams(config)) { return false; } - if(!config.check("local")) - { - yCError(SPEECHSYNTH_NWC) << "No local name specified"; - - return false; - } - m_local_name = config.find("local").asString(); - - if(!config.check("remote")) - { - yCError(SPEECHSYNTH_NWC) << "No remote name specified"; - - return false; - } - m_thrift_server_name = config.find("remote").asString(); - - std::string thriftClientPortName = m_local_name + "/thrift:c"; - std::string thriftServerPortName = m_thrift_server_name + "/rpc"; + std::string thriftClientPortName = m_local + "/thrift:c"; + std::string thriftServerPortName = m_remote + "/rpc"; if(!m_thriftClientPort.open(thriftClientPortName)) { diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h index c1ba532591b..eb1ec988548 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp.h @@ -21,7 +21,7 @@ #include #include #include "ISpeechSynthesizerMsgs.h" - +#include "SpeechSynthesizer_nwc_yarp_ParamsParser.h" /** * @ingroup dev_impl_nwc_yarp @@ -30,16 +30,14 @@ * * \brief `speechSynthesizer_nwc_yarp`: A network wrapper client that connects to a speechSynthesizer_nws_yarp to perform speech synthesis. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the device. | | - * | remote | - | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | + * Parameters required by this device are shown in class: SpeechSynthesizer_nwc_yarp_ParamsParser + * */ class SpeechSynthesizer_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::ISpeechSynthesizer + public yarp::dev::ISpeechSynthesizer, + public SpeechSynthesizer_nwc_yarp_ParamsParser { // Methods private: @@ -74,8 +72,6 @@ class SpeechSynthesizer_nwc_yarp : protected: yarp::os::Port m_thriftClientPort; - std::string m_local_name; - std::string m_thrift_server_name; }; diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..9fc6efbffc4 --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#include "SpeechSynthesizer_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SpeechSynthesizer_nwc_yarpParamsCOMPONENT, "yarp.device.SpeechSynthesizer_nwc_yarp") +} + + +SpeechSynthesizer_nwc_yarp_ParamsParser::SpeechSynthesizer_nwc_yarp_ParamsParser() +{ +} + + +std::vector SpeechSynthesizer_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool SpeechSynthesizer_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the server, to which this client connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SpeechSynthesizer_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SpeechSynthesizer_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SpeechSynthesizer_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("'remote': Full port name of the port remotely opened by the server, to which this client connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device speechSynthesizer_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device speechSynthesizer_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..7be63b953fc --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#ifndef SPEECHSYNTHESIZER_NWC_YARP_PARAMSPARSER_H +#define SPEECHSYNTHESIZER_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SpeechSynthesizer_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port remotely opened by the server, to which this client connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device speechSynthesizer_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device speechSynthesizer_nwc_yarp --local --remote +* \endcode +* +*/ + +class SpeechSynthesizer_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SpeechSynthesizer_nwc_yarp_ParamsParser(); + ~SpeechSynthesizer_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SpeechSynthesizer_nwc_yarp"}; + const std::string m_device_name = {"speechSynthesizer_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_params.md b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_params.md new file mode 100644 index 00000000000..211cab3abf4 --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nwc_yarp/SpeechSynthesizer_nwc_yarp_params.md @@ -0,0 +1,2 @@ + * | | local | string | - | - | Yes | Full port name opened by the device. | | + * | | remote | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/CMakeLists.txt index 50415aa78e1..a070eb20aff 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/CMakeLists.txt @@ -4,8 +4,9 @@ yarp_prepare_plugin(speechSynthesizer_nws_yarp CATEGORY device TYPE SpeechSynthesizer_nws_yarp - INCLUDE speechSynthesizer_nws_yarp.h + INCLUDE SpeechSynthesizer_nws_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_speechSynthesizer_nws_yarp) @@ -13,8 +14,10 @@ if(NOT SKIP_speechSynthesizer_nws_yarp) target_sources(yarp_speechSynthesizer_nws_yarp PRIVATE - speechSynthesizer_nws_yarp.cpp - speechSynthesizer_nws_yarp.h + SpeechSynthesizer_nws_yarp.cpp + SpeechSynthesizer_nws_yarp.h + SpeechSynthesizer_nws_yarp_ParamsParser.cpp + SpeechSynthesizer_nws_yarp_ParamsParser.h ) target_link_libraries(yarp_speechSynthesizer_nws_yarp diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.cpp b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp similarity index 94% rename from src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.cpp rename to src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp index f631f43bde4..f8be491cf63 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.cpp +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "speechSynthesizer_nws_yarp.h" +#include "SpeechSynthesizer_nws_yarp.h" #include #include @@ -22,16 +22,14 @@ bool SpeechSynthesizer_nws_yarp::close() return closeMain(); } -bool SpeechSynthesizer_nws_yarp::open(Searchable& prop) +bool SpeechSynthesizer_nws_yarp::open(Searchable& config) { - std::string rootName = - prop.check("name",Value("/speechSynthesizer_nws"), - "prefix for port names").asString(); + if (!parseParams(config)) { return false; } input_buffer.attach(m_inputPort); - m_inputPort.open(rootName+"/text:i"); - m_outputPort.open(rootName + "/sound:o"); - if (!m_rpcPort.open(rootName+"/rpc")) + m_inputPort.open(m_name +"/text:i"); + m_outputPort.open(m_name + "/sound:o"); + if (!m_rpcPort.open(m_name +"/rpc")) { yCError(SPEECHSYNTH_NWS, "Failed to open rpc port"); return false; diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.h b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h similarity index 84% rename from src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.h rename to src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h index 3bf4edf0a7c..d78ddc1ac19 100644 --- a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/speechSynthesizer_nws_yarp.h +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp.h @@ -21,6 +21,7 @@ #include #include #include "ISpeechSynthesizerMsgs.h" +#include "SpeechSynthesizer_nws_yarp_ParamsParser.h" using namespace yarp::os; using namespace yarp::sig; @@ -82,16 +83,14 @@ class ISpeechSynthesizerMsgsd : public ISpeechSynthesizerMsgs * The same functionality is available also via rpc port, which also provides additional functionalities, * such as setting of the voice or the language. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:----------------------------:|:----------: |:---------------------------------------------------------------------:|:-----:| - * | name | - | string | - | /speechSynthesizer_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/text:i, xxx/rpc, xxx/audio:o ports are opened | + * Parameters required by this device are shown in class: SpeechSynthesizer_nws_yarp_ParamsParser */ class SpeechSynthesizer_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::Thread, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public SpeechSynthesizer_nws_yarp_ParamsParser { private: yarp::dev::ISpeechSynthesizer* m_isptr{ nullptr }; diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..2a8a8482ca2 --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.cpp @@ -0,0 +1,103 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#include "SpeechSynthesizer_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SpeechSynthesizer_nws_yarpParamsCOMPONENT, "yarp.device.SpeechSynthesizer_nws_yarp") +} + + +SpeechSynthesizer_nws_yarp_ParamsParser::SpeechSynthesizer_nws_yarp_ParamsParser() +{ +} + + +std::vector SpeechSynthesizer_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + return params; +} + + +bool SpeechSynthesizer_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SpeechSynthesizer_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(SpeechSynthesizer_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(SpeechSynthesizer_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SpeechSynthesizer_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SpeechSynthesizer_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SpeechSynthesizer_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SpeechSynthesizer_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': full name of the port opened by the device\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device speechSynthesizer_nws_yarp --name /speechSynthesizer_nws\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device speechSynthesizer_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..435fedd12c0 --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#ifndef SPEECHSYNTHESIZER_NWS_YARP_PARAMSPARSER_H +#define SPEECHSYNTHESIZER_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SpeechSynthesizer_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:----------------------:|:--------:|:------------------------------------------:|:----------------------------------------------------------------------------------:| +* | - | name | string | - | /speechSynthesizer_nws | 0 | full name of the port opened by the device | MUST start with a '/' character, xxx/text:i, xxx/rpc, xxx/audio:o ports are opened | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device speechSynthesizer_nws_yarp --name /speechSynthesizer_nws +* \endcode +* +* \code{.unparsed} +* yarpdev --device speechSynthesizer_nws_yarp +* \endcode +* +*/ + +class SpeechSynthesizer_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SpeechSynthesizer_nws_yarp_ParamsParser(); + ~SpeechSynthesizer_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SpeechSynthesizer_nws_yarp"}; + const std::string m_device_name = {"speechSynthesizer_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/speechSynthesizer_nws"}; + + std::string m_name = {"/speechSynthesizer_nws"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_params.md b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_params.md new file mode 100644 index 00000000000..fc21bfe12a6 --- /dev/null +++ b/src/devices/networkWrappers/speechSynthesizer_nws_yarp/SpeechSynthesizer_nws_yarp_params.md @@ -0,0 +1 @@ + * | | name | string | - | /speechSynthesizer_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/text:i, xxx/rpc, xxx/audio:o ports are opened | diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/CMakeLists.txt b/src/devices/networkWrappers/speechTranscription_nwc_yarp/CMakeLists.txt index 5bd32955272..c4dbbc2c67c 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/CMakeLists.txt @@ -6,6 +6,7 @@ yarp_prepare_plugin(speechTranscription_nwc_yarp TYPE SpeechTranscription_nwc_yarp INCLUDE SpeechTranscription_nwc_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_speechTranscription_nwc_yarp) @@ -15,6 +16,8 @@ if(NOT SKIP_speechTranscription_nwc_yarp) PRIVATE SpeechTranscription_nwc_yarp.cpp SpeechTranscription_nwc_yarp.h + SpeechTranscription_nwc_yarp_ParamsParser.h + SpeechTranscription_nwc_yarp_ParamsParser.cpp ) target_link_libraries(yarp_speechTranscription_nwc_yarp diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp index 3bd108214ac..218c23a54a5 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.cpp @@ -25,27 +25,10 @@ bool SpeechTranscription_nwc_yarp::close() bool SpeechTranscription_nwc_yarp::open(yarp::os::Searchable& config) { - m_local_name.clear(); - m_thrift_server_name.clear(); + if (!parseParams(config)) { return false; } - if(!config.check("local")) - { - yCError(SPEECHTR_NWC) << "No local name specified"; - - return false; - } - m_local_name = config.find("local").asString(); - - if(!config.check("remote")) - { - yCError(SPEECHTR_NWC) << "No remote name specified"; - - return false; - } - m_thrift_server_name = config.find("remote").asString(); - - std::string thriftClientPortName = m_local_name + "/thrift:c"; - std::string thriftServerPortName = m_thrift_server_name + "/rpc"; + std::string thriftClientPortName = m_local + "/thrift:c"; + std::string thriftServerPortName = m_remote + "/rpc"; if(!m_thriftClientPort.open(thriftClientPortName)) { diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h index 0de30100be9..b4150dd10a4 100644 --- a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp.h @@ -21,7 +21,7 @@ #include #include #include "ISpeechTranscriptionMsgs.h" - +#include "SpeechTranscription_nwc_yarp_ParamsParser.h" /** * @ingroup dev_impl_nwc_yarp @@ -30,16 +30,13 @@ * * \brief `speechTranscription_nwc_yarp`: A network wrapper client that connects to a speechTranscription_nws_yarp to perform speech transcription. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:------------:|:-------:|:--------------:|:-------------:|:-----------: |:-----------------------------------------------------------------------------------------------------:|:-----:| - * | local | - | string | - | - | Yes | Full port name opened by the device. | | - * | remote | - | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | + * Parameters required by this device are shown in class: SpeechTranscription_nwc_yarp_ParamsParser */ class SpeechTranscription_nwc_yarp : public yarp::dev::DeviceDriver, - public yarp::dev::ISpeechTranscription + public yarp::dev::ISpeechTranscription, + public SpeechTranscription_nwc_yarp_ParamsParser { // Methods private: @@ -68,8 +65,6 @@ class SpeechTranscription_nwc_yarp : protected: yarp::os::Port m_thriftClientPort; - std::string m_local_name; - std::string m_thrift_server_name; }; diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.cpp b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..69779aa45c9 --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.cpp @@ -0,0 +1,123 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#include "SpeechTranscription_nwc_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SpeechTranscription_nwc_yarpParamsCOMPONENT, "yarp.device.SpeechTranscription_nwc_yarp") +} + + +SpeechTranscription_nwc_yarp_ParamsParser::SpeechTranscription_nwc_yarp_ParamsParser() +{ +} + + +std::vector SpeechTranscription_nwc_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("local"); + params.push_back("remote"); + return params; +} + + +bool SpeechTranscription_nwc_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SpeechTranscription_nwc_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter local + { + if (config.check("local")) + { + m_local = config.find("local").asString(); + yCInfo(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Parameter 'local' using value:" << m_local; + } + else + { + yCError(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'local' not found!"; + yCError(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name opened by the device."; + return false; + } + prop_check.unput("local"); + } + + //Parser of parameter remote + { + if (config.check("remote")) + { + m_remote = config.find("remote").asString(); + yCInfo(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Parameter 'remote' using value:" << m_remote; + } + else + { + yCError(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Mandatory parameter 'remote' not found!"; + yCError(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "Description of the parameter: Full port name of the port remotely opened by the server, to which this client connects to."; + return false; + } + prop_check.unput("remote"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SpeechTranscription_nwc_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SpeechTranscription_nwc_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SpeechTranscription_nwc_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'local': Full port name opened by the device.\n"); + doc = doc + std::string("'remote': Full port name of the port remotely opened by the server, to which this client connects to.\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device speechTranscription_nwc_yarp --local --remote \n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device speechTranscription_nwc_yarp --local --remote \n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.h b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.h new file mode 100644 index 00000000000..085b1d9a82a --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_ParamsParser.h @@ -0,0 +1,72 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#ifndef SPEECHTRANSCRIPTION_NWC_YARP_PARAMSPARSER_H +#define SPEECHTRANSCRIPTION_NWC_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SpeechTranscription_nwc_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:-------------:|:--------:|:-------------------------------------------------------------------------------------------:|:-----:| +* | - | local | string | - | - | 1 | Full port name opened by the device. | - | +* | - | remote | string | - | - | 1 | Full port name of the port remotely opened by the server, to which this client connects to. | - | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device speechTranscription_nwc_yarp --local --remote +* \endcode +* +* \code{.unparsed} +* yarpdev --device speechTranscription_nwc_yarp --local --remote +* \endcode +* +*/ + +class SpeechTranscription_nwc_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SpeechTranscription_nwc_yarp_ParamsParser(); + ~SpeechTranscription_nwc_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SpeechTranscription_nwc_yarp"}; + const std::string m_device_name = {"speechTranscription_nwc_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_local_defaultValue = {""}; + const std::string m_remote_defaultValue = {""}; + + std::string m_local = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + std::string m_remote = {}; //This default value is autogenerated. It is highly recommended to provide a suggested value also for mandatory parameters. + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_params.md b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_params.md new file mode 100644 index 00000000000..f9b9087f634 --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nwc_yarp/SpeechTranscription_nwc_yarp_params.md @@ -0,0 +1,2 @@ + * | | local | string | - | - | Yes | Full port name opened by the device. | | + * | | remote | string | - | - | Yes | Full port name of the port remotely opened by the server, to which this client connects to. | | diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/CMakeLists.txt b/src/devices/networkWrappers/speechTranscription_nws_yarp/CMakeLists.txt index a2a218fa54d..51a3b671b45 100644 --- a/src/devices/networkWrappers/speechTranscription_nws_yarp/CMakeLists.txt +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/CMakeLists.txt @@ -4,8 +4,9 @@ yarp_prepare_plugin(speechTranscription_nws_yarp CATEGORY device TYPE SpeechTranscription_nws_yarp - INCLUDE speechTranscription_nws_yarp.h + INCLUDE SpeechTranscription_nws_yarp.h DEFAULT ON + GENERATE_PARSER ) if(NOT SKIP_speechTranscription_nws_yarp) @@ -13,8 +14,10 @@ if(NOT SKIP_speechTranscription_nws_yarp) target_sources(yarp_speechTranscription_nws_yarp PRIVATE - speechTranscription_nws_yarp.cpp - speechTranscription_nws_yarp.h + SpeechTranscription_nws_yarp.cpp + SpeechTranscription_nws_yarp.h + SpeechTranscription_nws_yarp_ParamsParser.h + SpeechTranscription_nws_yarp_ParamsParser.cpp ) target_link_libraries(yarp_speechTranscription_nws_yarp diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.cpp b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp similarity index 92% rename from src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.cpp rename to src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp index 344fb7583ce..313c79f7696 100644 --- a/src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.cpp +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "speechTranscription_nws_yarp.h" +#include "SpeechTranscription_nws_yarp.h" #include #include @@ -22,16 +22,14 @@ bool SpeechTranscription_nws_yarp::close() return closeMain(); } -bool SpeechTranscription_nws_yarp::open(Searchable& prop) +bool SpeechTranscription_nws_yarp::open(Searchable& config) { - std::string rootName = - prop.check("name",Value("/speechTranscription_nws"), - "prefix for port names").asString(); + if (!parseParams(config)) { return false; } input_buffer.attach(m_inputPort); - m_inputPort.open(rootName+"/sound:i"); - m_outputPort.open(rootName + "/text:o"); - if (!m_rpcPort.open(rootName+"/rpc")) + m_inputPort.open(m_name +"/sound:i"); + m_outputPort.open(m_name + "/text:o"); + if (!m_rpcPort.open(m_name +"/rpc")) { yCError(SPEECHTR_NWS, "Failed to open rpc port"); return false; diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.h b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h similarity index 83% rename from src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.h rename to src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h index 8384c415108..654c9b53f67 100644 --- a/src/devices/networkWrappers/speechTranscription_nws_yarp/speechTranscription_nws_yarp.h +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp.h @@ -21,6 +21,7 @@ #include #include #include "ISpeechTranscriptionMsgs.h" +#include "SpeechTranscription_nws_yarp_ParamsParser.h" using namespace yarp::os; using namespace yarp::sig; @@ -75,16 +76,15 @@ class ISpeechTranscriptionMsgsd : public ISpeechTranscriptionMsgs * The same functionality is available also via rpc port, which also provides additional functionalities, * such as setting of the transcription language. * - * Parameters required by this device are: - * | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | - * |:--------------:|:--------------:|:-------:|:--------------:|:----------------------------:|:----------: |:---------------------------------------------------------------------:|:-----:| - * | name | - | string | - | /speechTranscription_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:i, xxx/rpc, xxx/texts:o ports are opened | + * Parameters required by this device are shown in class: SpeechTranscription_nws_yarp_ParamsParser + * */ class SpeechTranscription_nws_yarp : public yarp::dev::DeviceDriver, public yarp::os::Thread, public yarp::dev::WrapperSingle, - public yarp::os::PortReader + public yarp::os::PortReader, + public SpeechTranscription_nws_yarp_ParamsParser { private: yarp::dev::ISpeechTranscription* m_isptr{ nullptr }; diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.cpp b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.cpp new file mode 100644 index 00000000000..ea26ede189a --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.cpp @@ -0,0 +1,103 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#include "SpeechTranscription_nws_yarp_ParamsParser.h" +#include +#include + +namespace { + YARP_LOG_COMPONENT(SpeechTranscription_nws_yarpParamsCOMPONENT, "yarp.device.SpeechTranscription_nws_yarp") +} + + +SpeechTranscription_nws_yarp_ParamsParser::SpeechTranscription_nws_yarp_ParamsParser() +{ +} + + +std::vector SpeechTranscription_nws_yarp_ParamsParser::getListOfParams() const +{ + std::vector params; + params.push_back("name"); + return params; +} + + +bool SpeechTranscription_nws_yarp_ParamsParser::parseParams(const yarp::os::Searchable & config) +{ + //Check for --help option + if (config.check("help")) + { + yCInfo(SpeechTranscription_nws_yarpParamsCOMPONENT) << getDocumentationOfDeviceParams(); + } + + std::string config_string = config.toString(); + yarp::os::Property prop_check(config_string.c_str()); + //Parser of parameter name + { + if (config.check("name")) + { + m_name = config.find("name").asString(); + yCInfo(SpeechTranscription_nws_yarpParamsCOMPONENT) << "Parameter 'name' using value:" << m_name; + } + else + { + yCInfo(SpeechTranscription_nws_yarpParamsCOMPONENT) << "Parameter 'name' using DEFAULT value:" << m_name; + } + prop_check.unput("name"); + } + + /* + //This code check if the user set some parameter which are not check by the parser + //If the parser is set in strict mode, this will generate an error + if (prop_check.size() > 0) + { + bool extra_params_found = false; + for (auto it=prop_check.begin(); it!=prop_check.end(); it++) + { + if (m_parser_is_strict) + { + yCError(SpeechTranscription_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<name <<" which is unknown to this parser!"; + extra_params_found = true; + } + else + { + yCWarning(SpeechTranscription_nws_yarpParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!"; + } + } + + if (m_parser_is_strict && extra_params_found) + { + return false; + } + } + */ + return true; +} + + +std::string SpeechTranscription_nws_yarp_ParamsParser::getDocumentationOfDeviceParams() const +{ + std::string doc; + doc = doc + std::string("\n=============================================\n"); + doc = doc + std::string("This is the help for device: SpeechTranscription_nws_yarp\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("This is the list of the parameters accepted by the device:\n"); + doc = doc + std::string("'name': full name of the port opened by the device\n"); + doc = doc + std::string("\n"); + doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n"); + doc = doc + " yarpdev --device speechTranscription_nws_yarp --name /speechTranscription_nws\n"; + doc = doc + std::string("Using only mandatory params:\n"); + doc = doc + " yarpdev --device speechTranscription_nws_yarp\n"; + doc = doc + std::string("=============================================\n\n"); return doc; +} diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.h b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.h new file mode 100644 index 00000000000..4955ac08346 --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_ParamsParser.h @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + + +// Generated by yarpDeviceParamParserGenerator (1.0) +// This is an automatically generated file. Please do not edit it. +// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON. + +// Generated on: Thu Mar 7 17:59:48 2024 + + +#ifndef SPEECHTRANSCRIPTION_NWS_YARP_PARAMSPARSER_H +#define SPEECHTRANSCRIPTION_NWS_YARP_PARAMSPARSER_H + +#include +#include +#include +#include + +/** +* This class is the parameters parser for class SpeechTranscription_nws_yarp. +* +* These are the used parameters: +* | Group name | Parameter name | Type | Units | Default Value | Required | Description | Notes | +* |:----------:|:--------------:|:------:|:-----:|:------------------------:|:--------:|:------------------------------------------:|:-----------------------------------------------------------------------------------:| +* | - | name | string | - | /speechTranscription_nws | 0 | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:i, xxx/rpc, xxx/texts:o ports are opened | +* +* The device can be launched by yarpdev using one of the following examples (with and without all optional parameters): +* \code{.unparsed} +* yarpdev --device speechTranscription_nws_yarp --name /speechTranscription_nws +* \endcode +* +* \code{.unparsed} +* yarpdev --device speechTranscription_nws_yarp +* \endcode +* +*/ + +class SpeechTranscription_nws_yarp_ParamsParser : public yarp::dev::IDeviceDriverParams +{ +public: + SpeechTranscription_nws_yarp_ParamsParser(); + ~SpeechTranscription_nws_yarp_ParamsParser() override = default; + +public: + const std::string m_device_classname = {"SpeechTranscription_nws_yarp"}; + const std::string m_device_name = {"speechTranscription_nws_yarp"}; + bool m_parser_is_strict = false; + struct parser_version_type + { + int major = 1; + int minor = 0; + }; + const parser_version_type m_parser_version = {}; + + const std::string m_name_defaultValue = {"/speechTranscription_nws"}; + + std::string m_name = {"/speechTranscription_nws"}; + + bool parseParams(const yarp::os::Searchable & config) override; + std::string getDeviceClassName() const override { return m_device_classname; } + std::string getDeviceName() const override { return m_device_name; } + std::string getDocumentationOfDeviceParams() const override; + std::vector getListOfParams() const override; +}; + +#endif diff --git a/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_params.md b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_params.md new file mode 100644 index 00000000000..4dc48e6fc8c --- /dev/null +++ b/src/devices/networkWrappers/speechTranscription_nws_yarp/SpeechTranscription_nws_yarp_params.md @@ -0,0 +1 @@ + * | | name | string | - | /speechTranscription_nws | No | full name of the port opened by the device | MUST start with a '/' character, xxx/audio:i, xxx/rpc, xxx/texts:o ports are opened | From f05f360e84b13c1c2ad87227afaaba5fe42b06a3 Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Fri, 8 Mar 2024 01:00:24 +0100 Subject: [PATCH 2/2] Valgrind fix --- src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp b/src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp index eb696187eae..44e61d09670 100644 --- a/src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp +++ b/src/devices/fake/fakeFrameGrabber/FakeFrameGrabber.cpp @@ -222,9 +222,8 @@ bool FakeFrameGrabber::open(yarp::os::Searchable& config) m_intrinsic.put("principalPointX",m_principalPointX); m_intrinsic.put("principalPointY",m_principalPointY); - Value val; - val.makeList(); - auto* bb = val.asList(); + Value* val = Value::makeList(); + auto* bb = val->asList(); for (double num : m_rectificationMatrix) { bb->addFloat64(num); } m_intrinsic.put("rectificationMatrix",val);