network_interface.h
Go to the documentation of this file.
1 /*
2 * Unpublished Copyright (c) 2009-2017 AutonomouStuff, LLC, All Rights Reserved.
3 *
4 * This file is part of the network_interface ROS 1.0 driver which is released under the MIT license.
5 * See file LICENSE included with this software or go to https://opensource.org/licenses/MIT for full license details.
6 */
7 
8 // Define a class that supports a basic network interface that's independent of the hardware and driver library used
9 // Different libraries can be created to define all these functions for a specific driver library
10 
11 #ifndef NETWORK_INTERFACE_NETWORK_INTERFACE_H
12 #define NETWORK_INTERFACE_NETWORK_INTERFACE_H
13 
14 // C++ Includes
15 #include <cstdio>
16 #include <iostream>
17 #include <string>
18 #include <boost/asio.hpp>
19 #include <boost/bind.hpp>
20 
21 // OS Includes
22 #include <unistd.h>
23 
24 namespace AS
25 {
26 namespace Network
27 {
29 {
30  OK = 0,
32  BAD_PARAM = -2,
40 };
41 
43 {
44 public:
45  UDPInterface();
46 
47  ~UDPInterface();
48 
49  // Called to pass in parameters and open ethernet link
50  return_statuses open(const char *ip_address, const int &port);
51 
52  // Close the ethernet link
54 
55  // Check on the status of the link
56  bool is_open();
57 
58  // Read a message - UDP is datagram-based so you cannot read exactly x bytes.
59  return_statuses read(unsigned char *msg,
60  const size_t &buf_size,
61  size_t &bytes_read);
62 
63  // Send a message
64  return_statuses write(unsigned char *msg, const size_t &msg_size);
65 
66 private:
67  boost::asio::io_service io_service_;
68  boost::asio::ip::udp::socket socket_;
69  boost::asio::ip::udp::endpoint sender_endpoint_;
70 };
71 
73 {
74 public:
75  TCPInterface();
76 
77  ~TCPInterface();
78 
79  // Called to pass in parameters and open ethernet link
80  return_statuses open(const char *ip_address,
81  const int &port);
82 
83  // Close the ethernet link
85 
86  // Check on the status of the link
87  bool is_open();
88 
89  // Read a message
90  return_statuses read(unsigned char *msg,
91  const size_t &buf_size,
92  size_t &bytes_read,
93  int timeout_ms = 0); // Optional timeout argument, in milliseconds
94  return_statuses read_exactly(unsigned char *msg,
95  const size_t &buf_size,
96  const size_t &bytes_to_read,
97  int timeout_ms = 0); // Optional timeout argument, in milliseconds
98 
99  // Send a message
100  return_statuses write(unsigned char *msg, const size_t &msg_size);
101 private:
102  boost::asio::io_service io_service_;
103  boost::asio::ip::tcp::socket socket_;
104  boost::system::error_code error_;
105  size_t bytes_read_;
106 
107  void timeout_handler(const boost::system::error_code& error);
108  void read_handler(const boost::system::error_code& error, size_t bytes_read);
109 };
110 
111 // Utility Functions
112 std::string return_status_desc(const return_statuses &ret);
113 } // namespace Network
114 } // namespace AS
115 #endif // NETWORK_INTERFACE_NETWORK_INTERFACE_H
boost::asio::io_service io_service_
boost::asio::ip::tcp::socket socket_
return_statuses write(unsigned char *msg, const size_t &msg_size)
return_statuses read(unsigned char *msg, const size_t &buf_size, size_t &bytes_read)
return_statuses close()
std::string return_status_desc(const return_statuses &ret)
Definition: utils.cpp:11
boost::system::error_code error_
boost::asio::ip::udp::endpoint sender_endpoint_
boost::asio::ip::udp::socket socket_
boost::asio::io_service io_service_
return_statuses open(const char *ip_address, const int &port)


network_interface
Author(s): Joshua Whitley , Daniel Stanek , Joe Kale
autogenerated on Sat Sep 7 2019 03:30:10