Public Member Functions | Private Member Functions | Private Attributes
pepperl_fuchs::ScanDataReceiver Class Reference

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>

List of all members.

Public Member Functions

void disconnect ()
 Disconnect and cleanup.
ScanData getFullScan ()
std::size_t getFullScansAvailable () const
 Get the total number of fully received laserscans available.
ScanData getScan ()
std::size_t getScansAvailable () const
 Get the total number of laserscans available (even scans which are not fully reveived yet)
int getUDPPort () const
 Get open and receiving UDP port.
bool isConnected () const
 Return connection status.
 ScanDataReceiver (const std::string hostname, const int tcp_port)
 Connect synchronously to the given IP and TCP port and start reading asynchronously.
 ScanDataReceiver ()
 Open an UDP port and listen on it.
 ~ScanDataReceiver ()
 Disconnect cleanly.

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.
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.
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.
std::condition_variable data_notifier_
 Data notification condition variable.
boost::asio::streambuf inbuf_
 Boost::Asio streambuffer.
std::istream instream_
 Input stream.
boost::asio::io_service io_service_
boost::thread io_service_thread_
 Event handler thread.
bool is_connected_
 Internal connection state.
double last_data_time_
 time in seconds since epoch, when last data was received
boost::circular_buffer< char > ring_buffer_
 Internal ringbuffer for temporarily storing reveived data.
std::deque< ScanDatascan_data_
 Double ended queue with sucessfully received and parsed data, organized as single complete scans.
boost::asio::ip::tcp::socket * tcp_socket_
 Receiving socket.
std::array< char, 65536 > udp_buffer_
 Buffer in case of UDP receiver.
boost::asio::ip::udp::endpoint udp_endpoint_
 Endpoint in case of UDP receiver.
int udp_port_
 Data (UDP) port at local side.
boost::asio::ip::udp::socket * udp_socket_
 Receiving socket.

Detailed Description

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.


Constructor & Destructor Documentation

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.

Open an UDP port and listen on it.

Definition at line 58 of file scan_data_receiver.cpp.

Disconnect cleanly.

Definition at line 87 of file scan_data_receiver.cpp.


Member Function Documentation

Checks if the connection is alive

Returns:
True if connection is alive, false otherwise

Definition at line 262 of file scan_data_receiver.cpp.

Disconnect and cleanup.

Definition at line 242 of file scan_data_receiver.cpp.

Search for magic header bytes in the internal ring buffer

Returns:
Position of possible packet start, which normally should be zero

Definition at line 200 of file scan_data_receiver.cpp.

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

Returns:
A ScanData struct with distance and amplitude data as well as the packet headers belonging to the data

Definition at line 284 of file scan_data_receiver.cpp.

Get the total number of fully received laserscans available.

Definition at line 301 of file scan_data_receiver.cpp.

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

Returns:
A ScanData struct with distance and amplitude data as well as the packet headers belonging to the data

Definition at line 275 of file scan_data_receiver.cpp.

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.

Get open and receiving UDP port.

Definition at line 45 of file scan_data_receiver.h.

Try to read and parse next packet from the internal ring buffer

Returns:
True if a packet has been parsed, false otherwise

Definition at line 150 of file scan_data_receiver.cpp.

void pepperl_fuchs::ScanDataReceiver::handleSocketRead ( const boost::system::error_code &  error) [private]

Asynchronous callback function, called if data has been reveived by the TCP socket.

Definition at line 95 of file scan_data_receiver.cpp.

void pepperl_fuchs::ScanDataReceiver::handleSocketRead ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
) [private]

Asynchronous callback function, called if data has been reveived by the UDP socket.

Definition at line 125 of file scan_data_receiver.cpp.

Return connection status.

Definition at line 48 of file scan_data_receiver.h.

void pepperl_fuchs::ScanDataReceiver::readBufferFront ( char *  dst,
std::size_t  numbytes 
) [private]

Read fast from the front of the internal ring buffer

Parameters:
dstDestination buffer Number of bytes to read

Definition at line 335 of file scan_data_receiver.cpp.

bool pepperl_fuchs::ScanDataReceiver::retrievePacket ( std::size_t  start,
PacketTypeC p 
) [private]

Try to read a packet from the internal ring buffer

Returns:
True on success, False otherwise

Definition at line 218 of file scan_data_receiver.cpp.

void pepperl_fuchs::ScanDataReceiver::writeBufferBack ( char *  src,
std::size_t  numbytes 
) [private]

Write fast at the back of the internal ring buffer

Parameters:
srcSource buffer Number of bytes to write

Definition at line 309 of file scan_data_receiver.cpp.


Member Data Documentation

Protection against data races between ROS and IO threads.

Definition at line 135 of file scan_data_receiver.h.

std::condition_variable pepperl_fuchs::ScanDataReceiver::data_notifier_ [private]

Data notification condition variable.

Definition at line 138 of file scan_data_receiver.h.

boost::asio::streambuf pepperl_fuchs::ScanDataReceiver::inbuf_ [private]

Boost::Asio streambuffer.

Definition at line 114 of file scan_data_receiver.h.

Input stream.

Definition at line 117 of file scan_data_receiver.h.

boost::asio::io_service pepperl_fuchs::ScanDataReceiver::io_service_ [private]

Definition at line 111 of file scan_data_receiver.h.

Event handler thread.

Definition at line 110 of file scan_data_receiver.h.

Internal connection state.

Definition at line 107 of file scan_data_receiver.h.

time in seconds since epoch, when last data was received

Definition at line 144 of file scan_data_receiver.h.

boost::circular_buffer<char> pepperl_fuchs::ScanDataReceiver::ring_buffer_ [private]

Internal ringbuffer for temporarily storing reveived data.

Definition at line 132 of file scan_data_receiver.h.

Double ended queue with sucessfully received and parsed data, organized as single complete scans.

Definition at line 141 of file scan_data_receiver.h.

boost::asio::ip::tcp::socket* pepperl_fuchs::ScanDataReceiver::tcp_socket_ [private]

Receiving socket.

Definition at line 120 of file scan_data_receiver.h.

std::array< char, 65536 > pepperl_fuchs::ScanDataReceiver::udp_buffer_ [private]

Buffer in case of UDP receiver.

Definition at line 129 of file scan_data_receiver.h.

boost::asio::ip::udp::endpoint pepperl_fuchs::ScanDataReceiver::udp_endpoint_ [private]

Endpoint in case of UDP receiver.

Definition at line 126 of file scan_data_receiver.h.

Data (UDP) port at local side.

Definition at line 104 of file scan_data_receiver.h.

boost::asio::ip::udp::socket* pepperl_fuchs::ScanDataReceiver::udp_socket_ [private]

Receiving socket.

Definition at line 123 of file scan_data_receiver.h.


The documentation for this class was generated from the following files:


pepperl_fuchs_r2000
Author(s): Denis Dillenberger
autogenerated on Thu Jun 6 2019 19:34:12