Public Member Functions | Private Member Functions | Private Attributes | List of all members
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>

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< ScanDatascan_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...
 

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.

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.

Member Function Documentation

bool pepperl_fuchs::ScanDataReceiver::checkConnection ( )
private

Checks if the connection is alive

Returns
True if connection is alive, false otherwise

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.

int pepperl_fuchs::ScanDataReceiver::findPacketStart ( )
private

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.

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

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.

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

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.

std::size_t pepperl_fuchs::ScanDataReceiver::getScansAvailable ( ) const
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.

int pepperl_fuchs::ScanDataReceiver::getUDPPort ( ) const
inline

Get open and receiving UDP port.

Definition at line 45 of file scan_data_receiver.h.

bool pepperl_fuchs::ScanDataReceiver::handleNextPacket ( )
private

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.

bool pepperl_fuchs::ScanDataReceiver::isConnected ( ) const
inline

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

std::mutex pepperl_fuchs::ScanDataReceiver::data_mutex_
private

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.

std::istream pepperl_fuchs::ScanDataReceiver::instream_
private

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.

boost::thread pepperl_fuchs::ScanDataReceiver::io_service_thread_
private

Event handler thread.

Definition at line 110 of file scan_data_receiver.h.

bool pepperl_fuchs::ScanDataReceiver::is_connected_
private

Internal connection state.

Definition at line 107 of file scan_data_receiver.h.

double pepperl_fuchs::ScanDataReceiver::last_data_time_
private

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.

std::deque<ScanData> pepperl_fuchs::ScanDataReceiver::scan_data_
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.

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.

int pepperl_fuchs::ScanDataReceiver::udp_port_
private

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 Mon Jun 10 2019 14:12:48