YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
BatteryData.cpp
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// Autogenerated by Thrift Compiler (0.14.1-yarped)
7//
8// This is an automatically generated file.
9// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
10
12
13namespace yarp::dev {
14
15// Constructor with field values
16BatteryData::BatteryData(const double charge,
17 const double voltage,
18 const double current,
19 const double temperature,
20 const std::int32_t status) :
21 WirePortable(),
22 charge(charge),
23 voltage(voltage),
24 current(current),
25 temperature(temperature),
26 status(status)
27{
28}
29
30// Read structure on a Wire
32{
33 if (!read_charge(reader)) {
34 return false;
35 }
36 if (!read_voltage(reader)) {
37 return false;
38 }
39 if (!read_current(reader)) {
40 return false;
41 }
42 if (!read_temperature(reader)) {
43 return false;
44 }
45 if (!read_status(reader)) {
46 return false;
47 }
48 if (reader.isError()) {
49 return false;
50 }
51 return true;
52}
53
54// Read structure on a Connection
56{
57 yarp::os::idl::WireReader reader(connection);
58 if (!reader.readListHeader(5)) {
59 return false;
60 }
61 if (!read(reader)) {
62 return false;
63 }
64 return true;
65}
66
67// Write structure on a Wire
69{
70 if (!write_charge(writer)) {
71 return false;
72 }
73 if (!write_voltage(writer)) {
74 return false;
75 }
76 if (!write_current(writer)) {
77 return false;
78 }
79 if (!write_temperature(writer)) {
80 return false;
81 }
82 if (!write_status(writer)) {
83 return false;
84 }
85 if (writer.isError()) {
86 return false;
87 }
88 return true;
89}
90
91// Write structure on a Connection
93{
94 yarp::os::idl::WireWriter writer(connection);
95 if (!writer.writeListHeader(5)) {
96 return false;
97 }
98 if (!write(writer)) {
99 return false;
100 }
101 return true;
102}
103
104// Convert to a printable string
105std::string BatteryData::toString() const
106{
108 if (!yarp::os::Portable::copyPortable(*this, b)) {
109 return {};
110 }
111 return b.toString();
112}
113
114// read charge field
115bool BatteryData::read_charge(yarp::os::idl::WireReader& reader)
116{
117 if (reader.noMore()) {
118 reader.fail();
119 return false;
120 }
121 if (!reader.readFloat64(charge)) {
122 reader.fail();
123 return false;
124 }
125 return true;
126}
127
128// write charge field
129bool BatteryData::write_charge(const yarp::os::idl::WireWriter& writer) const
130{
131 if (!writer.writeFloat64(charge)) {
132 return false;
133 }
134 return true;
135}
136
137// read (nested) charge field
138bool BatteryData::nested_read_charge(yarp::os::idl::WireReader& reader)
139{
140 if (reader.noMore()) {
141 reader.fail();
142 return false;
143 }
144 if (!reader.readFloat64(charge)) {
145 reader.fail();
146 return false;
147 }
148 return true;
149}
150
151// write (nested) charge field
152bool BatteryData::nested_write_charge(const yarp::os::idl::WireWriter& writer) const
153{
154 if (!writer.writeFloat64(charge)) {
155 return false;
156 }
157 return true;
158}
159
160// read voltage field
161bool BatteryData::read_voltage(yarp::os::idl::WireReader& reader)
162{
163 if (reader.noMore()) {
164 reader.fail();
165 return false;
166 }
167 if (!reader.readFloat64(voltage)) {
168 reader.fail();
169 return false;
170 }
171 return true;
172}
173
174// write voltage field
175bool BatteryData::write_voltage(const yarp::os::idl::WireWriter& writer) const
176{
177 if (!writer.writeFloat64(voltage)) {
178 return false;
179 }
180 return true;
181}
182
183// read (nested) voltage field
184bool BatteryData::nested_read_voltage(yarp::os::idl::WireReader& reader)
185{
186 if (reader.noMore()) {
187 reader.fail();
188 return false;
189 }
190 if (!reader.readFloat64(voltage)) {
191 reader.fail();
192 return false;
193 }
194 return true;
195}
196
197// write (nested) voltage field
198bool BatteryData::nested_write_voltage(const yarp::os::idl::WireWriter& writer) const
199{
200 if (!writer.writeFloat64(voltage)) {
201 return false;
202 }
203 return true;
204}
205
206// read current field
207bool BatteryData::read_current(yarp::os::idl::WireReader& reader)
208{
209 if (reader.noMore()) {
210 reader.fail();
211 return false;
212 }
213 if (!reader.readFloat64(current)) {
214 reader.fail();
215 return false;
216 }
217 return true;
218}
219
220// write current field
221bool BatteryData::write_current(const yarp::os::idl::WireWriter& writer) const
222{
223 if (!writer.writeFloat64(current)) {
224 return false;
225 }
226 return true;
227}
228
229// read (nested) current field
230bool BatteryData::nested_read_current(yarp::os::idl::WireReader& reader)
231{
232 if (reader.noMore()) {
233 reader.fail();
234 return false;
235 }
236 if (!reader.readFloat64(current)) {
237 reader.fail();
238 return false;
239 }
240 return true;
241}
242
243// write (nested) current field
244bool BatteryData::nested_write_current(const yarp::os::idl::WireWriter& writer) const
245{
246 if (!writer.writeFloat64(current)) {
247 return false;
248 }
249 return true;
250}
251
252// read temperature field
253bool BatteryData::read_temperature(yarp::os::idl::WireReader& reader)
254{
255 if (reader.noMore()) {
256 reader.fail();
257 return false;
258 }
259 if (!reader.readFloat64(temperature)) {
260 reader.fail();
261 return false;
262 }
263 return true;
264}
265
266// write temperature field
267bool BatteryData::write_temperature(const yarp::os::idl::WireWriter& writer) const
268{
269 if (!writer.writeFloat64(temperature)) {
270 return false;
271 }
272 return true;
273}
274
275// read (nested) temperature field
276bool BatteryData::nested_read_temperature(yarp::os::idl::WireReader& reader)
277{
278 if (reader.noMore()) {
279 reader.fail();
280 return false;
281 }
282 if (!reader.readFloat64(temperature)) {
283 reader.fail();
284 return false;
285 }
286 return true;
287}
288
289// write (nested) temperature field
290bool BatteryData::nested_write_temperature(const yarp::os::idl::WireWriter& writer) const
291{
292 if (!writer.writeFloat64(temperature)) {
293 return false;
294 }
295 return true;
296}
297
298// read status field
299bool BatteryData::read_status(yarp::os::idl::WireReader& reader)
300{
301 if (!reader.readI32(status)) {
302 status = 3;
303 }
304 return true;
305}
306
307// write status field
308bool BatteryData::write_status(const yarp::os::idl::WireWriter& writer) const
309{
310 if (!writer.writeI32(status)) {
311 return false;
312 }
313 return true;
314}
315
316// read (nested) status field
317bool BatteryData::nested_read_status(yarp::os::idl::WireReader& reader)
318{
319 if (!reader.readI32(status)) {
320 status = 3;
321 }
322 return true;
323}
324
325// write (nested) status field
326bool BatteryData::nested_write_status(const yarp::os::idl::WireWriter& writer) const
327{
328 if (!writer.writeI32(status)) {
329 return false;
330 }
331 return true;
332}
333
334} // namespace yarp::dev
double charge
Battery charge percentage [%].
Definition BatteryData.h:29
double voltage
Battery Voltage [V].
Definition BatteryData.h:33
double current
Battery Current [A].
Definition BatteryData.h:37
bool write(const yarp::os::idl::WireWriter &writer) const override
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool read(yarp::os::idl::WireReader &reader) override
std::int32_t status
the status of the device.
Definition BatteryData.h:45
double temperature
Battery Temperature [degC].
Definition BatteryData.h:41
std::string toString() const
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:211
An interface for reading from a network connection.
An interface for writing to a network connection.
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
Definition Portable.cpp:16
IDL-friendly connection reader.
Definition WireReader.h:27
bool readI32(std::int32_t &x)
bool readFloat64(yarp::conf::float64_t &x)
IDL-friendly connection writer.
Definition WireWriter.h:28
bool writeI32(std::int32_t x, bool skip_tag=false) const
bool writeListHeader(int len) const
bool writeFloat64(yarp::conf::float64_t x, bool skip_tag=false) const
For streams capable of holding different kinds of content, check what they actually have.