Receives data of the laser range finder via IP socket Receives the scanner data with asynchronous functions of the Boost::Asio library. More...
#include <scan_data_receiver.h>
Public Member Functions | |
| void | disconnect () |
| Disconnect and cleanup. More... | |
| ScanData | getFullScan () |
| std::size_t | getFullScansAvailable () const |
| Get the total number of fully received laserscans available. More... | |
| ScanData | getScan () |
| std::size_t | getScansAvailable () const |
| Get the total number of laserscans available (even scans which are not fully reveived yet) More... | |
| int | getUDPPort () const |
| Get open and receiving UDP port. More... | |
| bool | isConnected () const |
| Return connection status. More... | |
| ScanDataReceiver (const std::string hostname, const int tcp_port) | |
| Connect synchronously to the given IP and TCP port and start reading asynchronously. More... | |
| ScanDataReceiver () | |
| Open an UDP port and listen on it. More... | |
| ~ScanDataReceiver () | |
| Disconnect cleanly. More... | |
Private Member Functions | |
| bool | checkConnection () |
| int | findPacketStart () |
| bool | handleNextPacket () |
| void | handleSocketRead (const boost::system::error_code &error) |
| Asynchronous callback function, called if data has been reveived by the TCP socket. More... | |
| void | handleSocketRead (const boost::system::error_code &error, std::size_t bytes_transferred) |
| Asynchronous callback function, called if data has been reveived by the UDP socket. More... | |
| void | readBufferFront (char *dst, std::size_t numbytes) |
| bool | retrievePacket (std::size_t start, PacketTypeC *p) |
| void | writeBufferBack (char *src, std::size_t numbytes) |
Private Attributes | |
| std::mutex | data_mutex_ |
| Protection against data races between ROS and IO threads. More... | |
| std::condition_variable | data_notifier_ |
| Data notification condition variable. More... | |
| boost::asio::streambuf | inbuf_ |
| Boost::Asio streambuffer. More... | |
| std::istream | instream_ |
| Input stream. More... | |
| boost::asio::io_service | io_service_ |
| boost::thread | io_service_thread_ |
| Event handler thread. More... | |
| bool | is_connected_ |
| Internal connection state. More... | |
| double | last_data_time_ |
| time in seconds since epoch, when last data was received More... | |
| boost::circular_buffer< char > | ring_buffer_ |
| Internal ringbuffer for temporarily storing reveived data. More... | |
| std::deque< ScanData > | scan_data_ |
| Double ended queue with sucessfully received and parsed data, organized as single complete scans. More... | |
| boost::asio::ip::tcp::socket * | tcp_socket_ |
| Receiving socket. More... | |
| std::array< char, 65536 > | udp_buffer_ |
| Buffer in case of UDP receiver. More... | |
| boost::asio::ip::udp::endpoint | udp_endpoint_ |
| Endpoint in case of UDP receiver. More... | |
| int | udp_port_ |
| Data (UDP) port at local side. More... | |
| boost::asio::ip::udp::socket * | udp_socket_ |
| Receiving socket. More... | |
Receives data of the laser range finder via IP socket Receives the scanner data with asynchronous functions of the Boost::Asio library.
Definition at line 32 of file scan_data_receiver.h.
| pepperl_fuchs::ScanDataReceiver::ScanDataReceiver | ( | const std::string | hostname, |
| const int | tcp_port | ||
| ) |
Connect synchronously to the given IP and TCP port and start reading asynchronously.
Definition at line 17 of file scan_data_receiver.cpp.
| pepperl_fuchs::ScanDataReceiver::ScanDataReceiver | ( | ) |
Open an UDP port and listen on it.
Definition at line 58 of file scan_data_receiver.cpp.
| pepperl_fuchs::ScanDataReceiver::~ScanDataReceiver | ( | ) |
Disconnect cleanly.
Definition at line 87 of file scan_data_receiver.cpp.
|
private |
Checks if the connection is alive
Definition at line 262 of file scan_data_receiver.cpp.
| void pepperl_fuchs::ScanDataReceiver::disconnect | ( | ) |
Disconnect and cleanup.
Definition at line 242 of file scan_data_receiver.cpp.
|
private |
Search for magic header bytes in the internal ring buffer
Definition at line 200 of file scan_data_receiver.cpp.
| ScanData pepperl_fuchs::ScanDataReceiver::getFullScan | ( | ) |
Pop a single full scan out of the internal FIFO queue if there is any If no full scan is available yet, blocks until a full scan is available
Definition at line 284 of file scan_data_receiver.cpp.
| std::size_t pepperl_fuchs::ScanDataReceiver::getFullScansAvailable | ( | ) | const |
Get the total number of fully received laserscans available.
Definition at line 301 of file scan_data_receiver.cpp.
| ScanData pepperl_fuchs::ScanDataReceiver::getScan | ( | ) |
Pop a single scan out of the internal FIFO queue CAUTION: Returns also unfinished scans for which a full rotation is not received yet Call getFullScansAvailable() first to see how many full scans are available
Definition at line 275 of file scan_data_receiver.cpp.
|
inline |
Get the total number of laserscans available (even scans which are not fully reveived yet)
Definition at line 65 of file scan_data_receiver.h.
|
inline |
Get open and receiving UDP port.
Definition at line 45 of file scan_data_receiver.h.
|
private |
Try to read and parse next packet from the internal ring buffer
Definition at line 150 of file scan_data_receiver.cpp.
|
private |
Asynchronous callback function, called if data has been reveived by the TCP socket.
Definition at line 95 of file scan_data_receiver.cpp.
|
private |
Asynchronous callback function, called if data has been reveived by the UDP socket.
Definition at line 125 of file scan_data_receiver.cpp.
|
inline |
Return connection status.
Definition at line 48 of file scan_data_receiver.h.
|
private |
Read fast from the front of the internal ring buffer
| dst | Destination buffer Number of bytes to read |
Definition at line 335 of file scan_data_receiver.cpp.
|
private |
Try to read a packet from the internal ring buffer
Definition at line 218 of file scan_data_receiver.cpp.
|
private |
Write fast at the back of the internal ring buffer
| src | Source buffer Number of bytes to write |
Definition at line 309 of file scan_data_receiver.cpp.
|
private |
Protection against data races between ROS and IO threads.
Definition at line 135 of file scan_data_receiver.h.
|
private |
Data notification condition variable.
Definition at line 138 of file scan_data_receiver.h.
|
private |
Boost::Asio streambuffer.
Definition at line 114 of file scan_data_receiver.h.
|
private |
Input stream.
Definition at line 117 of file scan_data_receiver.h.
|
private |
Definition at line 111 of file scan_data_receiver.h.
|
private |
Event handler thread.
Definition at line 110 of file scan_data_receiver.h.
|
private |
Internal connection state.
Definition at line 107 of file scan_data_receiver.h.
|
private |
time in seconds since epoch, when last data was received
Definition at line 144 of file scan_data_receiver.h.
|
private |
Internal ringbuffer for temporarily storing reveived data.
Definition at line 132 of file scan_data_receiver.h.
|
private |
Double ended queue with sucessfully received and parsed data, organized as single complete scans.
Definition at line 141 of file scan_data_receiver.h.
|
private |
Receiving socket.
Definition at line 120 of file scan_data_receiver.h.
|
private |
Buffer in case of UDP receiver.
Definition at line 129 of file scan_data_receiver.h.
|
private |
Endpoint in case of UDP receiver.
Definition at line 126 of file scan_data_receiver.h.
|
private |
Data (UDP) port at local side.
Definition at line 104 of file scan_data_receiver.h.
|
private |
Receiving socket.
Definition at line 123 of file scan_data_receiver.h.