YARP
Yet Another Robot Platform
LaserEcho.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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  {
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
yarp::os::ConnectionWriter::appendFloat32
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
yarp::rosmsg::sensor_msgs::LaserEcho::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: LaserEcho.h:48
yarp::rosmsg::sensor_msgs::LaserEcho::LaserEcho
LaserEcho()
Definition: LaserEcho.h:37
yarp::rosmsg::sensor_msgs::LaserEcho::clear
void clear()
Definition: LaserEcho.h:42
WireTypes.h
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
yarp::os::idl::BottleStyle
Definition: BottleStyle.h:22
yarp::os::Type
Definition: Type.h:24
yarp::os::idl::WirePortable::read
virtual bool read(yarp::os::idl::WireReader &reader)
Definition: WirePortable.cpp:14
yarp::rosmsg::sensor_msgs::LaserEcho::typeName
static constexpr const char * typeName
Definition: LaserEcho.h:128
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
Wire.h
yarp::rosmsg::sensor_msgs::LaserEcho::typeChecksum
static constexpr const char * typeChecksum
Definition: LaserEcho.h:131
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
BOTTLE_TAG_FLOAT32
#define BOTTLE_TAG_FLOAT32
Definition: Bottle.h:26
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
Type.h
yarp::rosmsg::sensor_msgs::LaserEcho
Definition: LaserEcho.h:33
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::rosmsg::sensor_msgs::LaserEcho::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: LaserEcho.h:88
yarp::rosmsg::sensor_msgs::LaserEcho::typeText
static constexpr const char * typeText
Definition: LaserEcho.h:134
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
yarp::rosmsg::sensor_msgs::LaserEcho::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: LaserEcho.h:99
yarp::rosmsg::sensor_msgs::LaserEcho::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: LaserEcho.h:116
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
yarp::os::ConnectionWriter::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::os::idl::WireReader
IDL-friendly connection reader.
Definition: WireReader.h:33
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::idl::BareStyle
Definition: BareStyle.h:22
yarp::rosmsg::sensor_msgs::LaserEcho::getType
yarp::os::Type getType() const override
Definition: LaserEcho.h:142
yarp::rosmsg::sensor_msgs::LaserEcho::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: LaserEcho.h:82
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::ConnectionReader::expectFloat32
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
yarp::rosmsg::sensor_msgs::LaserEcho::echoes
std::vector< yarp::conf::float32_t > echoes
Definition: LaserEcho.h:35
yarp::rosmsg::sensor_msgs::LaserEcho::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::LaserEcho > bottleStyle
Definition: LaserEcho.h:125
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::rosmsg::sensor_msgs::LaserEcho::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::LaserEcho > rosStyle
Definition: LaserEcho.h:124
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
sensor_msgs
Definition: BatteryState.h:22
yarp::rosmsg::sensor_msgs::LaserEcho::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: LaserEcho.h:60
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WirePortable::write
virtual bool write(const yarp::os::idl::WireWriter &writer) const
Definition: WirePortable.cpp:20