YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
os/summer/summer.cpp

Add up numbers received on a port, and send the result back out.

Add up numbers received on a port, and send the result back out.

/*
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <yarp/os/Bottle.h>
#include <iostream>
int main(int argc, char* argv[])
{
YARP_UNUSED(argc);
YARP_UNUSED(argv);
Network yarp;
BufferedPort<Bottle> port;
port.open("/summer");
while (true) {
yInfo() << "waiting for input";
Bottle* input = port.read();
if (input != nullptr) {
yInfo() << "got " << input->toString().c_str();
double total = 0;
for (size_t i = 0; i < input->size(); i++) {
total += input->get(i).asFloat64();
}
Bottle& output = port.prepare();
output.clear();
output.addString("total");
output.addFloat64(total);
yInfo() << "writing " << output.toString().c_str();
port.write();
}
}
return 0;
}
#define yInfo(...)
Definition Log.h:319
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:706
The main, catch-all namespace for YARP.
Definition dirs.h:16
#define YARP_UNUSED(var)
Definition api.h:162