forked from robotology/yarp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request robotology#3060 from randaz81/IDeviceDriverParams
IDeviceDriverParams
- Loading branch information
Showing
8 changed files
with
228 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
|
||
#include "audioToFileDeviceParams.h" | ||
#include <yarp/os/LogStream.h> | ||
#include <yarp/os/Value.h> | ||
|
||
namespace { | ||
YARP_LOG_COMPONENT(AUDIOTOFILE, "yarp.device.audioToFileDevice") | ||
} | ||
|
||
bool audioToFileDevice_params::parseParams(const yarp::os::Searchable& config) | ||
{ | ||
if (config.check("help")) | ||
{ | ||
yCInfo(AUDIOTOFILE, "Some examples:"); | ||
yCInfo(AUDIOTOFILE, "yarpdev --device audioToFileDevice --help"); | ||
yCInfo(AUDIOTOFILE, "yarpdev --device AudioPlayerWrapper --subdevice audioToFileDevice --start"); | ||
yCInfo(AUDIOTOFILE, "yarpdev --device AudioPlayerWrapper --subdevice audioToFileDevice --start --file_name audio_out.wav --save_mode overwrite_file"); | ||
yCInfo(AUDIOTOFILE, "save_mode can be overwrite_file, append_file, rename_file, break_file"); | ||
yCInfo(AUDIOTOFILE, "use --add_marker option to add a marker at the beginning and at the ending of each received waveform"); | ||
return false; | ||
} | ||
|
||
if (config.check("file_name")) | ||
{ | ||
m_audio_filename = config.find("file_name").asString(); | ||
yCInfo(AUDIOTOFILE) << "Audio will be saved on exit to file:" << m_audio_filename; | ||
} | ||
else | ||
{ | ||
yCInfo(AUDIOTOFILE) << "No `file_name` option specified. Audio will be saved on exit to default file:" << m_audio_filename; | ||
} | ||
|
||
if (config.check("add_marker")) | ||
{ | ||
m_add_marker = true; | ||
yCInfo(AUDIOTOFILE) << "`add_marker` option enabled"; | ||
} | ||
else | ||
{ | ||
yCInfo(AUDIOTOFILE) << "No `add_marker` option specified. Default is:" << m_add_marker; | ||
} | ||
|
||
if (config.check("save_mode")) | ||
{ | ||
m_save_mode_s = config.find("save_mode").toString(); | ||
yCInfo(AUDIOTOFILE) << "`save_mode` selected:" << m_save_mode_s; | ||
} | ||
else | ||
{ | ||
yCInfo(AUDIOTOFILE) << "No `save_mode` option specified. Default is:" << m_audio_filename; | ||
} | ||
return true; | ||
} | ||
|
||
std::string audioToFileDevice_params::getDocumentationOfDeviceParams() const | ||
{ | ||
return std::string ("\ | ||
Parameters required by this device are :\n\ | ||
| Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes |\n\ | ||
| : ---------- : | : -------- : | : ----- : | : ------: | : ---------- : | : ---- : | : ---------------------------------------------------------------- - : | : ---- - : |\n\ | ||
| file_name | - | string | - | audio_out.wav | No | The name of the file written by the module | Only.wav and .mp3 files are supported |\n\ | ||
| save_mode | - | string | - | overwrite_file | No | Affects the behavior of the module and defines the save mode, as described in the documentation. | |\n\ | ||
| add_marker | - | bool | - | - | No | If set, it will add a marker at the beginning and at the ending of each received waveform. | |\n\ | ||
\n\ | ||
Three different operating modes are available, defined by the optional string parameter `save_mode`:\n\ | ||
if save_mode == append_data, the file is written only when the module terminates.\n\ | ||
Every start / stop operation just pauses the module.On resume, the new data is concatenated at the end of the file.\n\ | ||
\n\ | ||
If save_mode == overwrite_file, the output file is written every time the stop() method is called or when the module terminates.\n\ | ||
If the file already exists, it will be overwritten with the new data.\n\ | ||
\n\ | ||
If save_mode == rename_file, the output file is written to a NEW file every time the stop() method is called or when the module terminates.\n\ | ||
The file name is modified, using an incremental counter appended at the end of the file name.\n\ | ||
\n\ | ||
If save_mode = break_file, the output file is written to a NEW file every time a yarp::sig::sound is received or when the module terminates.\n\ | ||
The file name is modified, using an incremental counter appended at the end of the file name.\n\ | ||
"); | ||
} | ||
|
||
std::vector<std::string> audioToFileDevice_params::getListOfParams() const | ||
{ | ||
std::vector<std::string> params; | ||
params.push_back("file_name"); | ||
params.push_back("save_mode"); | ||
params.push_back("add_marker"); | ||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include <yarp/os/Searchable.h> | ||
#include <yarp/dev/IDeviceDriverParams.h> | ||
#include <string> | ||
|
||
/** | ||
* @ingroup dev_impl_media | ||
* | ||
* Parameters required by this device are: | ||
* | Parameter name | SubParameter | Type | Units | Default Value | Required | Description | Notes | | ||
* |:--------------:|:--------------:|:-------:|:--------------:|:------------------------:|:--------------------------: |:-----------------------------------------------------------------:|:-----:| | ||
* | file_name | - | string | - | audio_out.wav | No | The name of the file written by the module | Only .wav and .mp3 files are supported | | ||
* | save_mode | - | string | - | overwrite_file | No | Affects the behavior of the module and defines the save mode, as described in the documentation. | | | ||
* | add_marker | - | bool | - | - | No | If set, it will add a marker at the beginning and at the ending of each received waveform. | | | ||
* | ||
* Three different operating modes are available, defined by the optional string parameter `save_mode`: | ||
* if save_mode == "append_data", the file is written only when the module terminates. | ||
* Every start/stop operation just pauses the module. On resume, the new data is concatenated at the end of the file. | ||
* | ||
* if save_mode == "overwrite_file", the output file is written every time the stop() method is called or when the module terminates. | ||
* If the file already exists, it will be overwritten with the new data. | ||
* | ||
* if save_mode = "rename_file", the output file is written to a NEW file every time the stop() method is called or when the module terminates. | ||
* The file name is modified, using an incremental counter appended at the end of the file name. | ||
* | ||
* if save_mode = "break_file", the output file is written to a NEW file every time a yarp::sig::sound is received or when the module terminates. | ||
* The file name is modified, using an incremental counter appended at the end of the file name. | ||
* | ||
*/ | ||
class audioToFileDevice_params : public yarp::dev::IDeviceDriverParams | ||
{ | ||
public: | ||
~audioToFileDevice_params() override = default; | ||
|
||
private: | ||
std::string m_device_type = "audioToFileDevice"; | ||
|
||
public: | ||
bool m_add_marker = false; | ||
std::string m_audio_filename = "audio_out.wav"; | ||
std::string m_save_mode_s = "overwrite_file"; | ||
|
||
public: | ||
bool parseParams(const yarp::os::Searchable& config) override; | ||
std::string getDeviceType() const override { return m_device_type; } | ||
std::string getDocumentationOfDeviceParams() const override; | ||
std::vector<std::string> getListOfParams() const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include <yarp/dev/IDeviceDriverParams.h> | ||
|
||
yarp::dev::IDeviceDriverParams::~IDeviceDriverParams() = default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef YARP_DEV_IDEVICEDRIVERPARAMETERS_H | ||
#define YARP_DEV_IDEVICEDRIVERPARAMETERS_H | ||
|
||
#include <yarp/dev/api.h> | ||
#include <yarp/os/Searchable.h> | ||
#include <string> | ||
|
||
#include <vector> | ||
|
||
namespace yarp::dev { | ||
class IDeviceDriverParams; | ||
} | ||
|
||
/** | ||
* \ingroup dev_class | ||
* | ||
* An interface for the management of the parameters of a DeviceDriver. | ||
* Methods should be reimplemented independently by each DeviceDriver. | ||
*/ | ||
class YARP_dev_API yarp::dev::IDeviceDriverParams | ||
{ | ||
public: | ||
virtual ~IDeviceDriverParams(); | ||
|
||
/** | ||
* Parse the DeviceDriver parameters | ||
* @return true if the parsing is successful, false otherwise | ||
*/ | ||
virtual bool parseParams(const yarp::os::Searchable& config) = 0; | ||
|
||
/** | ||
* Get the name of the DeviceDriver class. | ||
* @return A string containing the name of the DeviceDriver. | ||
*/ | ||
virtual std::string getDeviceType() const = 0; | ||
|
||
/** | ||
* Get the documentation of the DeviceDriver's parameters. | ||
* @return A string containing the documentation. | ||
*/ | ||
virtual std::string getDocumentationOfDeviceParams() const = 0; | ||
|
||
/** | ||
* Return a list of all params used by the device. | ||
* @return A vector containing the names of parameters used by the device. | ||
*/ | ||
virtual std::vector<std::string> getListOfParams() const = 0; | ||
}; | ||
|
||
#endif //YARP_DEV_IDEVICEDRIVERPARAMETERS_H |