YARP
Yet Another Robot Platform
LaserEcho.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 // This is an automatically generated file.
10 
11 // Generated from the following "sensor_msgs/LaserEcho" msg definition:
12 // # This message is a submessage of MultiEchoLaserScan and is not intended
13 // # to be used separately.
14 //
15 // float32[] echoes # Multiple values of ranges or intensities.
16 // # Each array represents data from the same angle increment.// Instances of this class can be read and written with YARP ports,
17 // using a ROS-compatible format.
18 
19 #ifndef YARP_ROSMSG_sensor_msgs_LaserEcho_h
20 #define YARP_ROSMSG_sensor_msgs_LaserEcho_h
21 
22 #include <yarp/os/Wire.h>
23 #include <yarp/os/Type.h>
25 #include <string>
26 #include <vector>
27 
28 namespace yarp {
29 namespace rosmsg {
30 namespace sensor_msgs {
31 
33 {
34 public:
35  std::vector<yarp::conf::float32_t> echoes;
36 
38  echoes()
39  {
40  }
41 
42  void clear()
43  {
44  // *** echoes ***
45  echoes.clear();
46  }
47 
48  bool readBare(yarp::os::ConnectionReader& connection) override
49  {
50  // *** echoes ***
51  int len = connection.expectInt32();
52  echoes.resize(len);
53  if (len > 0 && !connection.expectBlock((char*)&echoes[0], sizeof(yarp::conf::float32_t)*len)) {
54  return false;
55  }
56 
57  return !connection.isError();
58  }
59 
60  bool readBottle(yarp::os::ConnectionReader& connection) override
61  {
62  connection.convertTextMode();
63  yarp::os::idl::WireReader reader(connection);
64  if (!reader.readListHeader(1)) {
65  return false;
66  }
67 
68  // *** echoes ***
69  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT32)) {
70  return false;
71  }
72  int len = connection.expectInt32();
73  echoes.resize(len);
74  for (int i=0; i<len; i++) {
75  echoes[i] = (yarp::conf::float32_t)connection.expectFloat32();
76  }
77 
78  return !connection.isError();
79  }
80 
82  bool read(yarp::os::ConnectionReader& connection) override
83  {
84  return (connection.isBareMode() ? readBare(connection)
85  : readBottle(connection));
86  }
87 
88  bool writeBare(yarp::os::ConnectionWriter& connection) const override
89  {
90  // *** echoes ***
91  connection.appendInt32(echoes.size());
92  if (echoes.size()>0) {
93  connection.appendExternalBlock((char*)&echoes[0], sizeof(yarp::conf::float32_t)*echoes.size());
94  }
95 
96  return !connection.isError();
97  }
98 
99  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
100  {
101  connection.appendInt32(BOTTLE_TAG_LIST);
102  connection.appendInt32(1);
103 
104  // *** echoes ***
106  connection.appendInt32(echoes.size());
107  for (size_t i=0; i<echoes.size(); i++) {
108  connection.appendFloat32(echoes[i]);
109  }
110 
111  connection.convertTextMode();
112  return !connection.isError();
113  }
114 
116  bool write(yarp::os::ConnectionWriter& connection) const override
117  {
118  return (connection.isBareMode() ? writeBare(connection)
119  : writeBottle(connection));
120  }
121 
122  // This class will serialize ROS style or YARP style depending on protocol.
123  // If you need to force a serialization style, use one of these classes:
126 
127  // The name for this message, ROS will need this
128  static constexpr const char* typeName = "sensor_msgs/LaserEcho";
129 
130  // The checksum for this message, ROS will need this
131  static constexpr const char* typeChecksum = "8bc5ae449b200fba4d552b4225586696";
132 
133  // The source text for this message, ROS will need this
134  static constexpr const char* typeText = "\
135 # This message is a submessage of MultiEchoLaserScan and is not intended\n\
136 # to be used separately.\n\
137 \n\
138 float32[] echoes # Multiple values of ranges or intensities.\n\
139  # Each array represents data from the same angle increment.\n\
140 ";
141 
142  yarp::os::Type getType() const override
143  {
144  yarp::os::Type typ = yarp::os::Type::byName(typeName, typeName);
145  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
146  typ.addProperty("message_definition", yarp::os::Value(typeText));
147  return typ;
148  }
149 };
150 
151 } // namespace sensor_msgs
152 } // namespace rosmsg
153 } // namespace yarp
154 
155 #endif // YARP_ROSMSG_sensor_msgs_LaserEcho_h
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 expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: LaserEcho.h:88
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: LaserEcho.h:48
static Type byName(const char *name)
Definition: Type.cpp:179
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:141
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::LaserEcho > rosStyle
Definition: LaserEcho.h:124
#define BOTTLE_TAG_FLOAT32
Definition: Bottle.h:26
virtual bool isError() const =0
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
virtual bool isBareMode() const =0
Check if the connection is bare mode.
std::vector< yarp::conf::float32_t > echoes
Definition: LaserEcho.h:35
An interface for writing to a network connection.
virtual bool write(const yarp::os::idl::WireWriter &writer) const
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual bool read(yarp::os::idl::WireReader &reader)
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::LaserEcho > bottleStyle
Definition: LaserEcho.h:125
virtual bool isError() const =0
yarp::os::Type getType() const override
Definition: LaserEcho.h:142
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:30
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: LaserEcho.h:60
An interface for reading from a network connection.
static constexpr const char * typeText
Definition: LaserEcho.h:134
float float32_t
Definition: numeric.h:50
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: LaserEcho.h:82
A single value (typically within a Bottle).
Definition: Value.h:40
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: LaserEcho.h:116
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
static constexpr const char * typeChecksum
Definition: LaserEcho.h:131
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: LaserEcho.h:99
IDL-friendly connection reader.
Definition: WireReader.h:37
static constexpr const char * typeName
Definition: LaserEcho.h:128