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 
15 
16 // C++ Includes
17 #include <cstdio>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 #include <boost/asio.hpp>
22 #include <boost/bind.hpp>
23 
24 // OS Includes
25 #include <unistd.h>
26 
27 namespace AS
28 {
29 namespace Network
30 {
31 
33 {
34 public:
35  UDPInterface();
36 
37  // Called to pass in parameters and open ethernet link
38  ReturnStatuses open(const std::string& ip_address, uint32_t port, uint32_t receive_buffer_size);
39  ReturnStatuses open(const std::string& ip_address, uint32_t port);
40 
41  // Close the ethernet link
43 
44  // Check on the status of the link
45  bool is_open();
46 
47  // Read a message - UDP is datagram-based so you cannot read exactly x bytes.
48  ReturnStatuses read(std::vector<uint8_t> *msg);
49 
50  // Send a message
51  ReturnStatuses write(const std::vector<uint8_t>& msg);
52 
53 private:
54  uint32_t receive_buffer_size_ = 1024;
55  boost::asio::io_service io_service_;
56  boost::asio::ip::udp::socket socket_;
57  boost::asio::ip::udp::endpoint sender_endpoint_;
58 };
59 
61 {
62 public:
63  TCPInterface();
64 
65  // Called to pass in parameters and open ethernet link
66  ReturnStatuses open(std::string ip_address, const int &port);
67 
68  // Close the ethernet link
70 
71  // Check on the status of the link
72  bool is_open();
73 
74  // Read a message
75  ReturnStatuses read(std::vector<uint8_t> *msg);
76  ReturnStatuses read_exactly(std::vector<uint8_t> *msg, const size_t &bytes_to_read);
77 
78  // Send a message
79  ReturnStatuses write(const std::vector<uint8_t> &msg);
80 private:
81  boost::asio::io_service io_service_;
82  boost::asio::ip::tcp::socket socket_;
83  boost::system::error_code error_;
84 };
85 
86 std::string return_status_desc(const ReturnStatuses &ret);
87 
88 } // namespace Network
89 } // namespace AS
90 #endif // NETWORK_INTERFACE_NETWORK_INTERFACE_H
AS::Network::TCPInterface::open
ReturnStatuses open(std::string ip_address, const int &port)
Definition: tcp_interface.cpp:22
AS::Network::UDPInterface::io_service_
boost::asio::io_service io_service_
Definition: network_interface.h:55
AS::Network::TCPInterface::socket_
boost::asio::ip::tcp::socket socket_
Definition: network_interface.h:82
AS::Network::TCPInterface::read
ReturnStatuses read(std::vector< uint8_t > *msg)
Definition: tcp_interface.cpp:70
AS::Network::UDPInterface::write
ReturnStatuses write(const std::vector< uint8_t > &msg)
Definition: udp_interface.cpp:92
AS::Network::UDPInterface::receive_buffer_size_
uint32_t receive_buffer_size_
Definition: network_interface.h:54
AS::Network::TCPInterface::read_exactly
ReturnStatuses read_exactly(std::vector< uint8_t > *msg, const size_t &bytes_to_read)
Definition: tcp_interface.cpp:89
AS::Network::TCPInterface::close
ReturnStatuses close()
Definition: tcp_interface.cpp:51
AS::Network::TCPInterface
Definition: network_interface.h:60
AS::Network::UDPInterface::read
ReturnStatuses read(std::vector< uint8_t > *msg)
Definition: udp_interface.cpp:76
AS::Network::TCPInterface::error_
boost::system::error_code error_
Definition: network_interface.h:83
AS::Network::TCPInterface::write
ReturnStatuses write(const std::vector< uint8_t > &msg)
Definition: tcp_interface.cpp:108
AS::Network::UDPInterface
Definition: network_interface.h:32
AS::Network::UDPInterface::sender_endpoint_
boost::asio::ip::udp::endpoint sender_endpoint_
Definition: network_interface.h:57
AS
Definition: common.h:11
common.h
AS::Network::return_status_desc
std::string return_status_desc(const ReturnStatuses &ret)
Definition: utils.cpp:11
AS::Network::TCPInterface::TCPInterface
TCPInterface()
Definition: tcp_interface.cpp:17
AS::Network::UDPInterface::socket_
boost::asio::ip::udp::socket socket_
Definition: network_interface.h:56
AS::Network::UDPInterface::UDPInterface
UDPInterface()
Definition: udp_interface.cpp:17
AS::Network::UDPInterface::is_open
bool is_open()
Definition: udp_interface.cpp:71
AS::Network::UDPInterface::open
ReturnStatuses open(const std::string &ip_address, uint32_t port, uint32_t receive_buffer_size)
Definition: udp_interface.cpp:22
AS::Network::TCPInterface::io_service_
boost::asio::io_service io_service_
Definition: network_interface.h:81
AS::Network::TCPInterface::is_open
bool is_open()
Definition: tcp_interface.cpp:65
AS::Network::UDPInterface::close
ReturnStatuses close()
Definition: udp_interface.cpp:57
AS::Network::ReturnStatuses
ReturnStatuses
Definition: common.h:16


network_interface
Author(s): Joshua Whitley , Daniel Stanek , Joe Kale
autogenerated on Wed Mar 2 2022 00:35:33