udp_com.h
Go to the documentation of this file.
1 /*
9  * Software License Agreement (BSD License)
10  *
11  * Copyright 2015 Hunter Laux
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above
21  * copyright notice, this list of conditions and the following
22  * disclaimer in the documentation and/or other materials provided
23  * with the distribution.
24  * * Neither the name of owner nor the names of its
25  * contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  *
41  *
42  */
43 
44 #ifndef UDP_COM_H
45 #define UDP_COM_H
46 
47 #include <boost/asio.hpp>
48 #include <boost/thread.hpp>
49 #include <cstdlib>
50 #include <iostream>
51 #include <string>
52 #include <vector>
53 // WANT TO REMOVE:
54 #include <ros/ros.h>
55 #include <udp_com/UdpPacket.h>
56 #include <udp_com/UdpSend.h>
57 #include <udp_com/UdpSocket.h>
58 
59 using boost::asio::ip::udp;
60 
61 namespace udp_com
62 {
63 
68 class UdpCom
69 {
70 public:
80  UdpCom(std::string computer_address, std::string sensor_address,
81  uint16_t port, bool is_multicast, ros::Publisher publisher);
82 
86  ~UdpCom();
87 
96  void doReceive();
97 
109  size_t send(const std::vector<u_char> &data, const std::string &ip_address,
110  const uint16_t udp_port);
111 
113  std::string getIp()
114  {
115  return computer_address_;
116  }
117 
118 private:
120  udp::endpoint receiver_endpoint_;
121 
123  udp::endpoint sender_endpoint_;
124 
127 
129  UdpPacket udp_packet_;
130 
132  boost::asio::io_service io_service_;
133 
135  udp::socket socket_;
136 
138  boost::thread thread_;
139 
141  std::string computer_address_;
142 };
143 
144 } // namespace udp_com
145 
146 #endif // UDP_COM_H
std::string computer_address_
Source (computer) IP Address.
Definition: udp_com.h:141
boost::asio::io_service io_service_
UDP IO service.
Definition: udp_com.h:132
std::string getIp()
Returns the src IP for the created socket.
Definition: udp_com.h:113
UdpPacket udp_packet_
UDP packet to be sent.
Definition: udp_com.h:129
UdpCom(std::string computer_address, std::string sensor_address, uint16_t port, bool is_multicast, ros::Publisher publisher)
Definition: udp_com.cpp:18
udp::endpoint receiver_endpoint_
UDP endpoint receiver.
Definition: udp_com.h:120
Implements the UDP methods for recieving and sending within the ROS ecosystem.
Definition: udp_com.h:68
size_t send(const std::vector< u_char > &data, const std::string &ip_address, const uint16_t udp_port)
Definition: udp_com.cpp:112
void doReceive()
Definition: udp_com.cpp:89
ros::Publisher udp_packet_publisher_
ROS publisher.
Definition: udp_com.h:126
udp::socket socket_
UDP socket.
Definition: udp_com.h:135
udp::endpoint sender_endpoint_
UDP endpoint sender.
Definition: udp_com.h:123
boost::thread thread_
Thread for service.
Definition: udp_com.h:138


udp_com
Author(s): Hunter Laux , Max Ginier , Evan Flynn , Gerardo Bravo , Moises Diaz
autogenerated on Sat Dec 5 2020 04:01:00