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