Skip to content

Commit 416c598

Browse files
committed
Modified the loadDeviceId() function to accept optional parameter names for the device UUID and device name
1 parent 4fa985c commit 416c598

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

fuse_variables/include/fuse_variables/stamped.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,32 @@ class Stamped
111111
/**
112112
* @brief Load a device id from the parameter server
113113
*
114-
* This function first checks if the 'device_id' parameter is available. If so, it attempts to load the device_id
114+
* This function first checks if the \p uuid_parameter parameter is available. If so, it attempts to load the device_id
115115
* using that parameter. There are a few supported formats:
116116
* - "01234567-89AB-CDEF-0123-456789ABCDEF"
117117
* - "01234567-89ab-cdef-0123-456789abcdef"
118118
* - "0123456789abcdef0123456789abcdef"
119119
* - "{01234567-89ab-cdef-0123-456789abcdef}"
120120
*
121-
* If the 'device_id' parameter doesn't exist, this function checks for the 'device_name' parameter. If found, a
122-
* device_id is generated by computing a hash on the provided string. See fuse_core::uuid::generate(const std::string&)
123-
* for details.
121+
* If the \p uuid_parameter parameter doesn't exist, this function checks for the \p name_parameter'device_name'
122+
* parameter. If found, a device_id is generated by computing a hash on the provided string. See
123+
* fuse_core::uuid::generate(const std::string&) for details.
124124
*
125125
* If neither parameter exits, the device_id is populated by all zeros, the so-called NIL UUID.
126126
*
127127
* Will throw if the device_id parameter is not in an expected format.
128128
*
129129
* @param[in] node_handle A node handle in the desired parameter namespace
130-
* @return A device UUID
130+
* @param[in] uuid_parameter The parameter name that holds the device uuid to be loaded
131+
* @param[in] name_parameter The parameter name that holds the device name. The uuid will be generated from the name.
132+
* @param[in] silent If true, no ROS log warnings are generated
133+
* @return A device UUID
131134
*/
132-
fuse_core::UUID loadDeviceId(const ros::NodeHandle& node_handle);
135+
fuse_core::UUID loadDeviceId(
136+
const ros::NodeHandle& node_handle,
137+
const std::string& uuid_parameter = "device_id",
138+
const std::string& name_parameter = "device_name",
139+
bool silent = true);
133140

134141
} // namespace fuse_variables
135142

fuse_variables/src/stamped.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <fuse_variables/stamped.h>
3535

3636
#include <fuse_core/uuid.h>
37+
#include <ros/console.h>
3738
#include <ros/node_handle.h>
3839

3940
#include <string>
@@ -42,21 +43,28 @@
4243
namespace fuse_variables
4344
{
4445

45-
fuse_core::UUID loadDeviceId(const ros::NodeHandle& node_handle)
46+
fuse_core::UUID loadDeviceId(
47+
const ros::NodeHandle& node_handle,
48+
const std::string& uuid_parameter,
49+
const std::string& name_parameter,
50+
bool silent)
4651
{
4752
fuse_core::UUID device_id;
4853
std::string device_str;
49-
if (node_handle.getParam("device_id", device_str))
54+
if (node_handle.getParam(uuid_parameter, device_str))
5055
{
5156
device_id = fuse_core::uuid::from_string(device_str);
5257
}
53-
else if (node_handle.getParam("device_name", device_str))
58+
else if (node_handle.getParam(name_parameter, device_str))
5459
{
5560
device_id = fuse_core::uuid::generate(device_str);
5661
}
5762
else
5863
{
5964
device_id = fuse_core::uuid::NIL;
65+
ROS_WARN_STREAM_COND(
66+
!silent,
67+
"No " + uuid_parameter + " or " + name_parameter + " parameter was provided on the parameter server.");
6068
}
6169
return device_id;
6270
}

0 commit comments

Comments
 (0)