YARP
Yet Another Robot Platform
DiagnosticStatus.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6// This is an automatically generated file.
7
8// Generated from the following "diagnostic_msgs/DiagnosticStatus" msg definition:
9// # This message holds the status of an individual component of the robot.
10// #
11//
12// # Possible levels of operations
13// byte OK=0
14// byte WARN=1
15// byte ERROR=2
16// byte STALE=3
17//
18// byte level # level of operation enumerated above
19// string name # a description of the test/component reporting
20// string message # a description of the status
21// string hardware_id # a hardware unique string
22// KeyValue[] values # an array of values associated with the status
23//
24// Instances of this class can be read and written with YARP ports,
25// using a ROS-compatible format.
26
27#ifndef YARP_ROSMSG_diagnostic_msgs_DiagnosticStatus_h
28#define YARP_ROSMSG_diagnostic_msgs_DiagnosticStatus_h
29
30#include <yarp/os/Wire.h>
31#include <yarp/os/Type.h>
33#include <string>
34#include <vector>
36
37namespace yarp {
38namespace rosmsg {
39namespace diagnostic_msgs {
40
42{
43public:
44 static const std::uint8_t OK = 0;
45 static const std::uint8_t WARN = 1;
46 static const std::uint8_t ERROR = 2;
47 static const std::uint8_t STALE = 3;
48 std::uint8_t level;
49 std::string name;
50 std::string message;
51 std::string hardware_id;
52 std::vector<yarp::rosmsg::diagnostic_msgs::KeyValue> values;
53
55 level(0),
56 name(""),
57 message(""),
58 hardware_id(""),
59 values()
60 {
61 }
62
63 void clear()
64 {
65 // *** OK ***
66
67 // *** WARN ***
68
69 // *** ERROR ***
70
71 // *** STALE ***
72
73 // *** level ***
74 level = 0;
75
76 // *** name ***
77 name = "";
78
79 // *** message ***
80 message = "";
81
82 // *** hardware_id ***
83 hardware_id = "";
84
85 // *** values ***
86 values.clear();
87 }
88
89 bool readBare(yarp::os::ConnectionReader& connection) override
90 {
91 // *** level ***
92 level = connection.expectInt8();
93
94 // *** name ***
95 int len = connection.expectInt32();
96 name.resize(len);
97 if (!connection.expectBlock((char*)name.c_str(), len)) {
98 return false;
99 }
100
101 // *** message ***
102 len = connection.expectInt32();
103 message.resize(len);
104 if (!connection.expectBlock((char*)message.c_str(), len)) {
105 return false;
106 }
107
108 // *** hardware_id ***
109 len = connection.expectInt32();
110 hardware_id.resize(len);
111 if (!connection.expectBlock((char*)hardware_id.c_str(), len)) {
112 return false;
113 }
114
115 // *** values ***
116 len = connection.expectInt32();
117 values.resize(len);
118 for (int i=0; i<len; i++) {
119 if (!values[i].read(connection)) {
120 return false;
121 }
122 }
123
124 return !connection.isError();
125 }
126
127 bool readBottle(yarp::os::ConnectionReader& connection) override
128 {
129 connection.convertTextMode();
130 yarp::os::idl::WireReader reader(connection);
131 if (!reader.readListHeader(9)) {
132 return false;
133 }
134
135 // *** level ***
136 level = reader.expectInt8();
137
138 // *** name ***
139 if (!reader.readString(name)) {
140 return false;
141 }
142
143 // *** message ***
144 if (!reader.readString(message)) {
145 return false;
146 }
147
148 // *** hardware_id ***
149 if (!reader.readString(hardware_id)) {
150 return false;
151 }
152
153 // *** values ***
154 if (connection.expectInt32() != BOTTLE_TAG_LIST) {
155 return false;
156 }
157 int len = connection.expectInt32();
158 values.resize(len);
159 for (int i=0; i<len; i++) {
160 if (!values[i].read(connection)) {
161 return false;
162 }
163 }
164
165 return !connection.isError();
166 }
167
169 bool read(yarp::os::ConnectionReader& connection) override
170 {
171 return (connection.isBareMode() ? readBare(connection)
172 : readBottle(connection));
173 }
174
175 bool writeBare(yarp::os::ConnectionWriter& connection) const override
176 {
177 // *** level ***
178 connection.appendInt8(level);
179
180 // *** name ***
181 connection.appendInt32(name.length());
182 connection.appendExternalBlock((char*)name.c_str(), name.length());
183
184 // *** message ***
185 connection.appendInt32(message.length());
186 connection.appendExternalBlock((char*)message.c_str(), message.length());
187
188 // *** hardware_id ***
189 connection.appendInt32(hardware_id.length());
190 connection.appendExternalBlock((char*)hardware_id.c_str(), hardware_id.length());
191
192 // *** values ***
193 connection.appendInt32(values.size());
194 for (size_t i=0; i<values.size(); i++) {
195 if (!values[i].write(connection)) {
196 return false;
197 }
198 }
199
200 return !connection.isError();
201 }
202
203 bool writeBottle(yarp::os::ConnectionWriter& connection) const override
204 {
205 connection.appendInt32(BOTTLE_TAG_LIST);
206 connection.appendInt32(9);
207
208 // *** level ***
209 connection.appendInt32(BOTTLE_TAG_INT8);
210 connection.appendInt8(level);
211
212 // *** name ***
213 connection.appendInt32(BOTTLE_TAG_STRING);
214 connection.appendInt32(name.length());
215 connection.appendExternalBlock((char*)name.c_str(), name.length());
216
217 // *** message ***
218 connection.appendInt32(BOTTLE_TAG_STRING);
219 connection.appendInt32(message.length());
220 connection.appendExternalBlock((char*)message.c_str(), message.length());
221
222 // *** hardware_id ***
223 connection.appendInt32(BOTTLE_TAG_STRING);
224 connection.appendInt32(hardware_id.length());
225 connection.appendExternalBlock((char*)hardware_id.c_str(), hardware_id.length());
226
227 // *** values ***
228 connection.appendInt32(BOTTLE_TAG_LIST);
229 connection.appendInt32(values.size());
230 for (size_t i=0; i<values.size(); i++) {
231 if (!values[i].write(connection)) {
232 return false;
233 }
234 }
235
236 connection.convertTextMode();
237 return !connection.isError();
238 }
239
241 bool write(yarp::os::ConnectionWriter& connection) const override
242 {
243 return (connection.isBareMode() ? writeBare(connection)
244 : writeBottle(connection));
245 }
246
247 // This class will serialize ROS style or YARP style depending on protocol.
248 // If you need to force a serialization style, use one of these classes:
251
252 // The name for this message, ROS will need this
253 static constexpr const char* typeName = "diagnostic_msgs/DiagnosticStatus";
254
255 // The checksum for this message, ROS will need this
256 static constexpr const char* typeChecksum = "d0ce08bc6e5ba34c7754f563a9cabaf1";
257
258 // The source text for this message, ROS will need this
259 static constexpr const char* typeText = "\
260# This message holds the status of an individual component of the robot.\n\
261# \n\
262\n\
263# Possible levels of operations\n\
264byte OK=0\n\
265byte WARN=1\n\
266byte ERROR=2\n\
267byte STALE=3\n\
268\n\
269byte level # level of operation enumerated above \n\
270string name # a description of the test/component reporting\n\
271string message # a description of the status\n\
272string hardware_id # a hardware unique string\n\
273KeyValue[] values # an array of values associated with the status\n\
274\n\
275\n\
276================================================================================\n\
277MSG: diagnostic_msgs/KeyValue\n\
278string key # what to label this value when viewing\n\
279string value # a value to track over time\n\
280";
281
282 yarp::os::Type getType() const override
283 {
286 typ.addProperty("message_definition", yarp::os::Value(typeText));
287 return typ;
288 }
289};
290
291} // namespace diagnostic_msgs
292} // namespace rosmsg
293} // namespace yarp
294
295#endif // YARP_ROSMSG_diagnostic_msgs_DiagnosticStatus_h
#define BOTTLE_TAG_INT8
Definition: Bottle.h:19
#define BOTTLE_TAG_STRING
Definition: Bottle.h:26
#define BOTTLE_TAG_LIST
Definition: Bottle.h:28
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
static Type byName(const char *name)
Definition: Type.cpp:171
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:134
A single value (typically within a Bottle).
Definition: Value.h:43
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:21
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool write(const yarp::os::idl::WireWriter &writer) const
IDL-friendly connection reader.
Definition: WireReader.h:27
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:376
std::int8_t expectInt8()
Definition: WireReader.h:77
yarp::os::idl::BareStyle< yarp::rosmsg::diagnostic_msgs::DiagnosticStatus > rosStyle
bool readBottle(yarp::os::ConnectionReader &connection) override
yarp::os::idl::BottleStyle< yarp::rosmsg::diagnostic_msgs::DiagnosticStatus > bottleStyle
bool readBare(yarp::os::ConnectionReader &connection) override
bool writeBare(yarp::os::ConnectionWriter &connection) const override
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
std::vector< yarp::rosmsg::diagnostic_msgs::KeyValue > values
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
The main, catch-all namespace for YARP.
Definition: dirs.h:16