YARP
Yet Another Robot Platform
TickTime.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 "time" 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_TickTime_h
16 #define YARP_ROSMSG_TickTime_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  TickTime(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("TickTime::TickTime(): 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  TickTime& 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("TickTime::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("TickTime::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 = "TickTime";
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_TickTime_h
yarp::rosmsg::TickTime::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: TickTime.h:133
yarp::rosmsg::TickTime::operator=
TickTime & operator=(const double timestamp)
Definition: TickTime.h:56
yarp::rosmsg::TickTime::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::TickTime > bottleStyle
Definition: TickTime.h:160
WireTypes.h
yarp::rosmsg::TickTime::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: TickTime.h:98
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::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
Wire.h
yarp::rosmsg::TickTime::getType
yarp::os::Type getType() const override
Definition: TickTime.h:173
yarp::rosmsg::TickTime::typeChecksum
static constexpr const char * typeChecksum
Definition: TickTime.h:166
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::rosmsg::TickTime
Definition: TickTime.h:30
yarp::rosmsg::TickTime::typeName
static constexpr const char * typeName
Definition: TickTime.h:163
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::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::rosmsg::TickTime::sec
std::uint32_t sec
Definition: TickTime.h:32
yarp::rosmsg::TickTime::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: TickTime.h:87
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::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::rosmsg::TickTime::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: TickTime.h:116
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::os::idl::WireReader::expectInt32
std::int32_t expectInt32()
Definition: WireReader.h:99
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::rosmsg::TickTime::clear
void clear()
Definition: TickTime.h:78
yarp::rosmsg::TickTime::nsec
std::uint32_t nsec
Definition: TickTime.h:33
yarp::rosmsg::TickTime::TickTime
TickTime(double timestamp)
Definition: TickTime.h:41
yarp::rosmsg::TickTime::typeText
static constexpr const char * typeText
Definition: TickTime.h:169
yarp::rosmsg::TickTime::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::TickTime > rosStyle
Definition: TickTime.h:159
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::rosmsg::TickTime::TickTime
TickTime()
Definition: TickTime.h:35
yarp::rosmsg::TickTime::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: TickTime.h:151
yarp::rosmsg::TickTime::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: TickTime.h:122
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