Skip to content
Snippets Groups Projects
Commit 281f7493 authored by Johannes Mey's avatar Johannes Mey
Browse files

rename sender and receiver to publisher and subscriber

parent 62c53252
No related branches found
No related tags found
No related merge requests found
......@@ -138,27 +138,27 @@ include_directories(
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(${PROJECT_NAME}_sender src/nng_sender.cpp ${PROTO_SRCS} ${PROTO_HDRS})
add_executable(${PROJECT_NAME}_receiver src/nng_receiver.cpp ${PROTO_SRCS} ${PROTO_HDRS})
add_executable(${PROJECT_NAME}_publisher src/nng_publisher.cpp ${PROTO_SRCS} ${PROTO_HDRS})
add_executable(${PROJECT_NAME}_subscriber src/nng_subscriber.cpp ${PROTO_SRCS} ${PROTO_HDRS})
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
set_target_properties(${PROJECT_NAME}_sender PROPERTIES OUTPUT_NAME sender PREFIX "")
set_target_properties(${PROJECT_NAME}_receiver PROPERTIES OUTPUT_NAME receiver PREFIX "")
set_target_properties(${PROJECT_NAME}_publisher PROPERTIES OUTPUT_NAME publisher PREFIX "")
set_target_properties(${PROJECT_NAME}_subscriber PROPERTIES OUTPUT_NAME subscriber PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_sender
target_link_libraries(${PROJECT_NAME}_publisher
${catkin_LIBRARIES}
nng
${Protobuf_LIBRARIES}
)
target_link_libraries(${PROJECT_NAME}_receiver
target_link_libraries(${PROJECT_NAME}_subscriber
${catkin_LIBRARIES}
nng
${Protobuf_LIBRARIES}
......
......@@ -2,7 +2,7 @@
<package format="2">
<name>nng_test</name>
<version>0.1.0</version>
<description>a sender and receiver node using nng</description>
<description>a publisher and subscriber node using nng</description>
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<maintainer email="johannes.mey@tu-dresden.de">Johannes Mey</maintainer>
......
......@@ -16,7 +16,7 @@ nng_socket sock;
int rv;
void nngCallback(const std_msgs::String::ConstPtr &msg) {
ROS_INFO("sending via NNG: [%s]", msg->data.c_str());
ROS_INFO("publishing via NNG: [%s]", msg->data.c_str());
// wrap into protobuf message
Ping ping;
......@@ -34,7 +34,7 @@ int main(int argc, char **argv) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
ros::init(argc, argv, "nng_sender");
ros::init(argc, argv, "nng_publisher");
ros::NodeHandle n("nnc_test");
......@@ -45,7 +45,7 @@ int main(int argc, char **argv) {
ROS_ERROR_STREAM("nng_listen returned: " << nng_strerror(rv));
}
ros::Subscriber sub = n.subscribe("send_nng", 1000, nngCallback);
ros::Subscriber sub = n.subscribe("publish_to_nng", 1000, nngCallback);
ros::spin();
......
......@@ -15,11 +15,11 @@
const std::string URL = "tcp://localhost:6576";
int main(int argc, char **argv) {
ros::init(argc, argv, "nng_receiver");
ros::init(argc, argv, "nng_subscriber");
ros::NodeHandle n("nnc_test");
ros::Publisher nng_receiver_pub = n.advertise<std_msgs::String>("received_nng", 1000);
ros::Publisher nng_subscriber_pub = n.advertise<std_msgs::String>("received_nng_subscription", 1000);
ros::Rate loop_rate(200);
......@@ -49,13 +49,11 @@ int main(int argc, char **argv) {
ping.ParseFromArray(buf, sz);
nng_free(buf, sz);
ROS_INFO_STREAM("CLIENT: RECEIVED '" << ping.name() << "'");
// build and publish a ROS message
std_msgs::String msg;
msg.data = ping.name();
ROS_INFO_STREAM("Publishing ROS message '" << msg.data << "'");
nng_receiver_pub.publish(msg);
ROS_INFO_STREAM("Received Ping. Publishing ROS message '" << msg.data << "'");
nng_subscriber_pub.publish(msg);
} else if (rv == NNG_EAGAIN) {
// no message received in current spin
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment