11 #ifndef SCAN_DATA_RECEIVER_H 12 #define SCAN_DATA_RECEIVER_H 14 #define BOOST_CB_DISABLE_DEBUG 18 #include <condition_variable> 21 #include <boost/bind.hpp> 22 #include <boost/asio.hpp> 23 #include <boost/thread.hpp> 24 #include <boost/circular_buffer.hpp> 75 void handleSocketRead(
const boost::system::error_code& error, std::size_t bytes_transferred);
148 #endif // SCAN_DATA_RECEIVER_H boost::thread io_service_thread_
Event handler thread.
boost::asio::ip::tcp::socket * tcp_socket_
Receiving socket.
int getUDPPort() const
Get open and receiving UDP port.
std::size_t getScansAvailable() const
Get the total number of laserscans available (even scans which are not fully reveived yet) ...
void disconnect()
Disconnect and cleanup.
~ScanDataReceiver()
Disconnect cleanly.
std::size_t getFullScansAvailable() const
Get the total number of fully received laserscans available.
double last_data_time_
time in seconds since epoch, when last data was received
void handleSocketRead(const boost::system::error_code &error)
Asynchronous callback function, called if data has been reveived by the TCP socket.
boost::asio::streambuf inbuf_
Boost::Asio streambuffer.
boost::asio::ip::udp::socket * udp_socket_
Receiving socket.
Normally contains one complete laserscan (a full rotation of the scanner head)
std::mutex data_mutex_
Protection against data races between ROS and IO threads.
boost::asio::ip::udp::endpoint udp_endpoint_
Endpoint in case of UDP receiver.
std::condition_variable data_notifier_
Data notification condition variable.
bool retrievePacket(std::size_t start, PacketTypeC *p)
boost::circular_buffer< char > ring_buffer_
Internal ringbuffer for temporarily storing reveived data.
ScanDataReceiver()
Open an UDP port and listen on it.
boost::asio::io_service io_service_
Structure of a UDP or TCP data packet from the laserscanner.
bool isConnected() const
Return connection status.
Receives data of the laser range finder via IP socket Receives the scanner data with asynchronous fun...
std::array< char, 65536 > udp_buffer_
Buffer in case of UDP receiver.
void readBufferFront(char *dst, std::size_t numbytes)
void writeBufferBack(char *src, std::size_t numbytes)
int udp_port_
Data (UDP) port at local side.
std::deque< ScanData > scan_data_
Double ended queue with sucessfully received and parsed data, organized as single complete scans...
bool is_connected_
Internal connection state.
std::istream instream_
Input stream.