src
util
dump_param.cpp
Go to the documentation of this file.
1
// Small utility that prints a ROS parameter type and value
2
// Author: Max Schwarz <max.schwarz@ais.uni-bonn.de>
3
4
#include <
ros/ros.h
>
5
6
#include <
rosfmt/rosfmt.h
>
7
8
int
main
(
int
argc,
char
** argv)
9
{
10
ros::init
(argc, argv,
"dump_param"
,
ros::init_options::AnonymousName
);
11
12
if
(argc < 2 || std::string(argv[1]) ==
"--help"
)
13
{
14
fmt::print(stderr,
"Usage: dump_param <name>\n"
);
15
return
1;
16
}
17
18
ros::NodeHandle
nh;
19
20
using
Value =
XmlRpc::XmlRpcValue
;
21
Value value;
22
23
if
(!nh.
getParam
(argv[1], value))
24
{
25
fmt::print(stderr,
"Could not retrieve parameter '{}', does it exist?"
, argv[1]);
26
return
1;
27
}
28
29
switch
(value.getType())
30
{
31
case
Value::TypeString:
32
fmt::print(
"Type: String\n"
);
33
fmt::print(
"Value: '{}'\n"
,
static_cast<
std::string
>
(value));
34
break
;
35
36
case
Value::TypeBoolean:
37
fmt::print(
"Type: Bool\n"
);
38
fmt::print(
"Value: {}\n"
,
static_cast<
bool
>
(value));
39
break
;
40
41
case
Value::TypeDouble:
42
{
43
fmt::print(
"Type: Double\n"
);
44
45
double
v = value;
46
fmt::print(
"Value: {}\n"
, v);
47
48
uint64_t vhex = 0;
49
std::memcpy(&vhex, &v,
sizeof
(vhex));
50
51
fmt::print(
"Hex: 0x{:08X}\n"
, vhex);
52
break
;
53
}
54
55
case
Value::TypeInt:
56
fmt::print(
"Type: Int\n"
);
57
fmt::print(
"Value: {}\n"
,
static_cast<
int
>
(value));
58
break
;
59
60
case
Value::TypeArray:
61
fmt::print(
"Type: Array\n"
);
62
break
;
63
64
case
Value::TypeBase64:
65
fmt::print(
"Type: Base64\n"
);
66
break
;
67
68
case
Value::TypeDateTime:
69
fmt::print(
"Type: DateTime\n"
);
70
break
;
71
72
case
Value::TypeInvalid:
73
fmt::print(
"Type: Invalid\n"
);
74
break
;
75
76
case
Value::TypeStruct:
77
fmt::print(
"Type: Struct\n"
);
78
break
;
79
80
default
:
81
fmt::print(
"Type: Unknown\n"
);
82
break
;
83
}
84
}
ros::init_options::AnonymousName
AnonymousName
rosfmt.h
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
main
int main(int argc, char **argv)
Definition:
dump_param.cpp:8
XmlRpc::XmlRpcValue
ros::NodeHandle
rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Feb 21 2024 04:01:14