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. | |
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< ScanData > | scan_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. |
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.
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.
bool pepperl_fuchs::ScanDataReceiver::checkConnection | ( | ) | [private] |
Checks if the connection is alive
Definition at line 262 of file scan_data_receiver.cpp.
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
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
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.
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.
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
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
dst | Destination 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
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
src | Source buffer Number of bytes to write |
Definition at line 309 of file scan_data_receiver.cpp.
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.