Skip to content

Instantly share code, notes, and snippets.

@drdanz
Created May 15, 2019 06:15
Show Gist options
  • Save drdanz/19b2eb8709b4a5fcd8eb09763ee866df to your computer and use it in GitHub Desktop.
Save drdanz/19b2eb8709b4a5fcd8eb09763ee866df to your computer and use it in GitHub Desktop.
#include <yarp/os/Network.h>
#include <yarp/os/Port.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/LogStream.h>
#include <yarp/os/ConnectionReader.h>
#include <yarp/sig/Vector.h>
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
class DataProcessor :
public yarp::os::PortReader
{
bool read(yarp::os::ConnectionReader& connection) override
{
// Read whatever is sent
yarp::os::Bottle b;
bool ok = b.read(connection);
if (!ok) {
return false;
}
yDebug() << b.toString();
// Reply with a vector
yarp::os::ConnectionWriter* writer = connection.getWriter();
yarp::sig::Vector v{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
if (!v.write(*writer)) {
return false;
}
return true;
}
};
int main(int argc, char *argv[])
{
yarp::os::Network yarp;
yarp::os::Port port;
DataProcessor processor;
port.setReader(processor);
port.open("/test");
while (true) {
std::this_thread::sleep_for(1s);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment