Add up numbers received on a port, and send the result back out.
#include <iostream>
int main(
int argc,
char* argv[])
{
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;
}