27 #include "nmea_msgs/Sentence.h" 33 #include <sys/socket.h> 34 #include <netinet/in.h> 37 void msg_callback(
const nmea_msgs::SentenceConstPtr sentence_msg_ptr)
43 int main(
int argc,
char **argv)
45 ros::init(argc, argv,
"nmea_socket_node");
49 int listener_fd = socket(AF_INET, SOCK_STREAM, 0);
57 n_local.
param(
"port", port, 29500);
60 n_local.
param<std::string>(
"frame_id", frame_id,
"navsat");
63 struct sockaddr_in serv_addr, cli_addr;
64 bzero((
char *) &serv_addr,
sizeof(serv_addr));
65 serv_addr.sin_family = AF_INET;
66 serv_addr.sin_addr.s_addr = INADDR_ANY;
67 serv_addr.sin_port = htons(port);
70 int previous_success = 1;
73 if (bind(listener_fd, (
struct sockaddr *) &serv_addr,
74 sizeof(serv_addr)) < 0)
78 ROS_ERROR(
"Unable to bind socket. Is port %d in use? Retrying every 1s.", port);
104 listen(listener_fd, 5);
106 unsigned int clilen =
sizeof(cli_addr);
108 ROS_INFO(
"Now listening for connections on port %d.", port);
109 struct pollfd pollfds[] = { { listener_fd, POLLIN, 0 } };
112 int retval = poll(pollfds, 1, 500);
115 int new_client_fd = accept(listener_fd, (
struct sockaddr *) &cli_addr, &clilen);
116 if (new_client_fd < 0)
void msg_callback(const nmea_msgs::SentenceConstPtr sentence_msg_ptr)
int main(int argc, char **argv)
void rx_thread_start(ros::NodeHandle &n, int fd, std::string frame_id, uint32_t byte_time_ns=0)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void shutdown()