This is a simple example of a ros package with source files written in C++. The idea is that the folder structure, cmakelists and package.xml files format can be used as template for more complex packages.
As recommended somewhere, the pure C code should be separated from the ROS interface.
To serve as an example, the simple node will subscribe to a listen topic and publish an echo topic at a fixed rate with the message repeated n times. Whenever a new message is received in listen, the output message will be updated.
n can be chosen by setting a echoer/n_echos parameter on ROS parameter server before running the node. If not set, it defaults to 5. Value of n can be changed during run time by calling the services increase_echos and decrease_echos.
To run an example, go to a terminal and issue:
roslaunch roscpp_example echoer.launch
Then, on another terminal, issue:
rostopic pub /listen std_msgs/String "data: 'Hello'"
To increase number of echos:
rosservice call echoer/increase_echos