YARP
Yet Another Robot Platform
JoypadControlNetUtils.cpp
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 
10 
13 
15 {
16  Buttons.resize(connection.expectInt32());
17  Sticks.resize(connection.expectInt32());
18  Axes.resize(connection.expectInt32());
19  Balls.resize(connection.expectInt32());
20  Touch.resize(connection.expectInt32());
21  Hats.resize(connection.expectInt32());
22  connection.expectBlock((char*)Buttons.data(), Buttons.length() * sizeof(double));
23  connection.expectBlock((char*)Sticks.data(), Sticks.length() * sizeof(double));
24  connection.expectBlock((char*)Axes.data(), Axes.length() * sizeof(double));
25  connection.expectBlock((char*)Balls.data(), Balls.length() * sizeof(double));
26  connection.expectBlock((char*)Touch.data(), Touch.length() * sizeof(double));
27  connection.expectBlock((char*)&Hats[0], Hats.size() * sizeof(char));
28  return !connection.isError();
29 }
30 
32 {
33  connection.appendInt32(Buttons.length());
34  connection.appendInt32(Sticks.length());
35  connection.appendInt32(Axes.length() );
36  connection.appendInt32(Balls.length() );
37  connection.appendInt32(Touch.length() );
38  connection.appendInt32(Hats.size() );
39  connection.appendBlock((char*)Buttons.data(), Buttons.length() * sizeof(double));
40  connection.appendBlock((char*)Sticks.data(), Sticks.length() * sizeof(double));
41  connection.appendBlock((char*)Axes.data(), Axes.length() * sizeof(double));
42  connection.appendBlock((char*)Balls.data(), Balls.length() * sizeof(double));
43  connection.appendBlock((char*)Touch.data(), Touch.length() * sizeof(double));
44  connection.appendBlock((char*)&Hats[0], Hats.size() * sizeof(char));
45  connection.convertTextMode();
46  return !connection.isError();
47 }
yarp::os::ConnectionWriter::appendBlock
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
yarp::sig::VectorOf::resize
void resize(size_t size) override
Resize the vector.
Definition: Vector.h:254
ConnectionWriter.h
JoyData::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: JoypadControlNetUtils.cpp:14
JoypadControlNetUtils.h
JoyData::Buttons
yarp::sig::Vector Buttons
Definition: JoypadControlNetUtils.h:18
JoyData::Axes
yarp::sig::Vector Axes
Definition: JoypadControlNetUtils.h:20
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
JoyData::Touch
yarp::sig::Vector Touch
Definition: JoypadControlNetUtils.h:22
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
JoyData::Balls
yarp::sig::Vector Balls
Definition: JoypadControlNetUtils.h:21
yarp::sig::VectorOf::length
size_t length() const
Get the length of the vector.
Definition: Vector.h:363
JoyData::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: JoypadControlNetUtils.cpp:31
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::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::sig::VectorOf::data
T * data()
Return a pointer to the first element of the vector.
Definition: Vector.h:239
JoyData::Sticks
yarp::sig::Vector Sticks
Definition: JoypadControlNetUtils.h:19
yarp::sig::VectorOf::size
size_t size() const
Definition: Vector.h:355
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
JoyData::Hats
yarp::sig::VectorOf< unsigned char > Hats
Definition: JoypadControlNetUtils.h:23
ConnectionReader.h