YARP
Yet Another Robot Platform
os/summer.cpp

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

/*
* Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <yarp/os/all.h>
#include <iostream>
using namespace std;
using namespace yarp::os;
int main(int argc, char *argv[]) {
port.open("/summer");
while (true) {
cout << "waiting for input" << endl;
Bottle *input = port.read();
if (input!=NULL) {
cout << "got " << input->toString().c_str() << endl;
double total = 0;
for (int i=0; i<input->size(); i++) {
total += input->get(i).asFloat64();
}
Bottle& output = port.prepare();
output.clear();
output.addString("total");
output.addFloat64(total);
cout << "writing " << output.toString().c_str() << endl;
port.write();
}
}
return 0;
}