YARP
Yet Another Robot Platform
TickDuration.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 "duration" native type definition:
12 // Instances of this class can be read and written with YARP ports,
13 // using a ROS-compatible format.
14 
15 #ifndef YARP_ROSMSG_TickDuration_h
16 #define YARP_ROSMSG_TickDuration_h
17 
18 #include <yarp/os/Wire.h>
19 #include <yarp/os/Type.h>
20 #include <yarp/os/idl/WireTypes.h>
21 #include <string>
22 #include <vector>
23 #include <climits>
24 #include <cstdint>
25 
26 namespace yarp {
27 namespace rosmsg {
28 
30 {
31 public:
32  std::uint32_t sec;
33  std::uint32_t nsec;
34 
36  sec(0),
37  nsec(0)
38  {
39  }
40 
41  TickDuration(double timestamp) :
42  sec(0),
43  nsec(0)
44  {
45  uint64_t time = (uint64_t) (timestamp * 1000000000UL);
46  uint64_t sec_part = (time / 1000000000UL);
47  uint64_t nsec_part = (time % 1000000000UL);
48  if (sec > UINT32_MAX) {
49  yWarning("TickDuration::TickDuration(): Timestamp exceeded the 32 bit representation, resetting it to 0");
50  sec = 0;
51  }
52  sec = static_cast<yarp::os::NetUint32>(sec_part);
53  nsec = static_cast<yarp::os::NetUint32>(nsec_part);
54  }
55 
56  TickDuration& operator=(const double timestamp)
57  {
58  uint64_t time = (uint64_t) (timestamp * 1000000000UL);
59  uint64_t sec_part = (time / 1000000000UL);
60  uint64_t nsec_part = (time % 1000000000UL);
61  if (sec > UINT32_MAX) {
62  yWarning("TickDuration::operator=(): Timestamp exceeded the 32 bit representation, resetting it to 0");
63  sec = 0;
64  }
65  sec = static_cast<yarp::os::NetUint32>(sec_part);
66  nsec = static_cast<yarp::os::NetUint32>(nsec_part);
67  return *this;
68  }
69 
70  operator double()
71  {
72  if (nsec > 1000000000UL) {
73  yWarning("TickDuration::operator double(): Check on nsec > 1000000000UL failed");
74  }
75  return sec + nsec * 1000000000.0;
76  }
77 
78  void clear()
79  {
80  // *** sec ***
81  sec = 0;
82 
83  // *** nsec ***
84  nsec = 0;
85  }
86 
87  bool readBare(yarp::os::ConnectionReader& connection) override
88  {
89  // *** sec ***
90  sec = connection.expectInt32();
91 
92  // *** nsec ***
93  nsec = connection.expectInt32();
94 
95  return !connection.isError();
96  }
97 
98  bool readBottle(yarp::os::ConnectionReader& connection) override
99  {
100  connection.convertTextMode();
101  yarp::os::idl::WireReader reader(connection);
102  if (!reader.readListHeader(2)) {
103  return false;
104  }
105 
106  // *** sec ***
107  sec = reader.expectInt32();
108 
109  // *** nsec ***
110  nsec = reader.expectInt32();
111 
112  return !connection.isError();
113  }
114 
116  bool read(yarp::os::ConnectionReader& connection) override
117  {
118  return (connection.isBareMode() ? readBare(connection)
119  : readBottle(connection));
120  }
121 
122  bool writeBare(yarp::os::ConnectionWriter& connection) const override
123  {
124  // *** sec ***
125  connection.appendInt32(sec);
126 
127  // *** nsec ***
128  connection.appendInt32(nsec);
129 
130  return !connection.isError();
131  }
132 
133  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
134  {
135  connection.appendInt32(BOTTLE_TAG_LIST);
136  connection.appendInt32(2);
137 
138  // *** sec ***
139  connection.appendInt32(BOTTLE_TAG_INT32);
140  connection.appendInt32(sec);
141 
142  // *** nsec ***
143  connection.appendInt32(BOTTLE_TAG_INT32);
144  connection.appendInt32(nsec);
145 
146  connection.convertTextMode();
147  return !connection.isError();
148  }
149 
151  bool write(yarp::os::ConnectionWriter& connection) const override
152  {
153  return (connection.isBareMode() ? writeBare(connection)
154  : writeBottle(connection));
155  }
156 
157  // This class will serialize ROS style or YARP style depending on protocol.
158  // If you need to force a serialization style, use one of these classes:
161 
162  // The name for this message, ROS will need this
163  static constexpr const char* typeName = "TickDuration";
164 
165  // The checksum for this message, ROS will need this
166  static constexpr const char* typeChecksum = "4771ad66fef816d2e4bead2f45a1cde6";
167 
168  // The source text for this message, ROS will need this
169  static constexpr const char* typeText = "\
170 \n\
171 ";
172 
173  yarp::os::Type getType() const override
174  {
176  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
177  typ.addProperty("message_definition", yarp::os::Value(typeText));
178  return typ;
179  }
180 };
181 
182 } // namespace rosmsg
183 } // namespace yarp
184 
185 #endif // YARP_ROSMSG_TickDuration_h
yarp::rosmsg::TickDuration::sec
std::uint32_t sec
Definition: TickDuration.h:32
yarp::rosmsg::TickDuration::TickDuration
TickDuration()
Definition: TickDuration.h:35
yarp::rosmsg::TickDuration::TickDuration
TickDuration(double timestamp)
Definition: TickDuration.h:41
yarp::rosmsg::TickDuration::getType
yarp::os::Type getType() const override
Definition: TickDuration.h:173
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::TickDuration::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::TickDuration > rosStyle
Definition: TickDuration.h:159
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
Wire.h
yarp::rosmsg::TickDuration::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: TickDuration.h:122
yarp::rosmsg::TickDuration::operator=
TickDuration & operator=(const double timestamp)
Definition: TickDuration.h:56
yarp::rosmsg::TickDuration::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: TickDuration.h:133
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::rosmsg::TickDuration::typeName
static constexpr const char * typeName
Definition: TickDuration.h:163
yarp::rosmsg::TickDuration
Definition: TickDuration.h:30
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
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::rosmsg::TickDuration::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::TickDuration > bottleStyle
Definition: TickDuration.h:160
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
Type.h
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::NetUint32
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
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.
yWarning
#define yWarning(...)
Definition: Log.h:271
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
yarp::rosmsg::TickDuration::nsec
std::uint32_t nsec
Definition: TickDuration.h:33
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::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::rosmsg::TickDuration::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: TickDuration.h:98
yarp::os::idl::BareStyle
Definition: BareStyle.h:22
yarp::os::idl::WireReader::expectInt32
std::int32_t expectInt32()
Definition: WireReader.h:99
yarp::rosmsg::TickDuration::clear
void clear()
Definition: TickDuration.h:78
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::rosmsg::TickDuration::typeText
static constexpr const char * typeText
Definition: TickDuration.h:169
yarp::rosmsg::TickDuration::typeChecksum
static constexpr const char * typeChecksum
Definition: TickDuration.h:166
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::rosmsg::TickDuration::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: TickDuration.h:151
yarp::rosmsg::TickDuration::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: TickDuration.h:87
yarp::rosmsg::TickDuration::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: TickDuration.h:116
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