Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
sick_scan::TestServerThread Class Reference

#include <test_server_thread.h>

Classes

class  ServerColaRequest
 

Public Member Functions

void messageCbResultPortTelegrams (const sick_scan::SickLocResultPortTelegramMsg &msg)
 
virtual void messageCbResultPortTelegramsROS2 (const std::shared_ptr< sick_scan::SickLocResultPortTelegramMsg > msg)
 
virtual bool start (void)
 
virtual bool stop (void)
 
 TestServerThread (ROS::NodePtr nh=0, int ip_port_results=2201, int ip_port_cola=2111)
 
virtual ~TestServerThread ()
 

Protected Types

enum  ERROR_SIMULATION_ENUM {
  NO_ERROR = 0, DONT_LISTEN, DONT_ACCECPT, DONT_SEND,
  SEND_RANDOM_TCP, SEND_INVALID_TELEGRAMS
}
 < enumerates testcases for simulation of communication errors More...
 
typedef enum sick_scan::TestServerThread::ERROR_SIMULATION_ENUM ERROR_SIMULATION_FLAG
 < enumerates testcases for simulation of communication errors More...
 
typedef boost::asio::ip::tcp::socket * socket_ptr
 shortcut for pointer to boost::asio::ip::tcp::socket More...
 
typedef boost::thread * thread_ptr
 shortcut for pointer to boost::thread More...
 

Protected Member Functions

void closeScandataThread (void)
 
void closeSocket (socket_ptr &p_socket)
 
virtual void closeTcpConnections (bool force_shutdown=false)
 
void closeWorkerThreads (void)
 
void errorSimulationWait (double seconds)
 
bool errorSimulationWaitForTelegramReceived (double timeout_seconds, sick_scan::SickLocResultPortTelegramMsg &telegram_msg)
 
virtual void runConnectionThreadColaCb (void)
 
template<typename Callable >
void runConnectionThreadGenericCb (boost::asio::ip::tcp::acceptor &tcp_acceptor_results, int ip_port_results, Callable thread_function_cb)
 
virtual void runConnectionThreadResultCb (void)
 
virtual void runErrorSimulationThreadCb (void)
 
virtual void runWorkerThreadColaCb (boost::asio::ip::tcp::socket *p_socket)
 
virtual void runWorkerThreadResultCb (boost::asio::ip::tcp::socket *p_socket)
 
virtual void runWorkerThreadScandataCb (boost::asio::ip::tcp::socket *p_socket)
 

Protected Attributes

bool m_demo_move_in_circles
 true: simulate a sensor moving in circles, false (default): create random based result port telegrams More...
 
bool m_error_simulation_enabled
 default: false (no error simulation), if true, test server simulates errors and communication failures of type ERROR_SIMULATION_FLAG More...
 
sick_scan::SetGet< ERROR_SIMULATION_FLAGm_error_simulation_flag
 current error simulation flag, default: NO_ERROR More...
 
thread_ptr m_error_simulation_thread
 thread to run error simulation, switches m_error_simulation_flag through the error test cases More...
 
bool m_error_simulation_thread_running
 true: m_error_simulation_thread is running, otherwise false More...
 
boost::asio::io_service m_ioservice
 boost io service for tcp connections More...
 
int m_ip_port_cola
 ip port for for command requests and responses, default: The localization controller uses IP port number 2111 and 2112 to send telegrams and to request data More...
 
int m_ip_port_results
 ip port for result telegrams, default: The localization controller uses IP port number 2201 to send localization results More...
 
sick_scan::SetGet< sick_scan::SickLocResultPortTelegramMsg > m_last_telegram_received
 last telegram message received from sick_scan driver More...
 
double m_result_telegram_rate
 frequency to generate and send result port telegrams, default: 10 Hz More...
 
std::string m_result_testcases_frame_id
 ros frame id of testcase messages (type SickLocResultPortTestcaseMsg), default: "result_testcases" More...
 
sick_scan::SickLocResultPortTestcaseMsgPublisher m_result_testcases_publisher
 ros publisher for testcases with result port telegrams (type SickLocResultPortTestcaseMsg) More...
 
std::string m_scandatafiles
 comma separated list of jsonfiles to emulate scandata messages, f.e. "tim781s_scandata.pcapng.json,tim781s_sopas.pcapng.json" More...
 
std::string m_scandatatypes
 comma separated list of scandata message types, f.e. "sSN LMDscandata,sSN LMDscandatamon" More...
 
std::string m_scanner_type
 currently supported: "sick_lms_5xx", "sick_tim_7xx" More...
 
double m_start_scandata_delay
 delay between scandata activation ("LMCstartmeas" request) and first scandata message, default: 1 second More...
 
boost::asio::ip::tcp::acceptor m_tcp_acceptor_cola
 boost acceptor for tcp clients for command requests and responses More...
 
boost::asio::ip::tcp::acceptor m_tcp_acceptor_results
 boost acceptor for tcp clients for result telegrams More...
 
thread_ptr m_tcp_connection_thread_cola
 thread to accept tcp clients for command requests and responses More...
 
thread_ptr m_tcp_connection_thread_results
 thread to accept tcp clients for result port telegrams More...
 
bool m_tcp_connection_thread_running
 true: m_tcp_connection_thread is running, otherwise false More...
 
thread_ptr m_tcp_send_scandata_thread
 thread to send scandata and scandatamon tcp messages More...
 
bool m_tcp_send_scandata_thread_running
 true: m_tcp_send_scandata_thread is running, otherwise false More...
 
std::list< boost::asio::ip::tcp::socket * > m_tcp_sockets
 list of tcp sockets (one socket for each tcp client) More...
 
std::list< thread_ptrm_tcp_worker_threads
 list of tcp worker thread (one thread for each tcp client, generating telegrams) More...
 
boost::mutex m_tcp_worker_threads_mutex
 mutex to protect m_tcp_worker_threads More...
 
bool m_worker_thread_running
 true: worker threads started, otherwise false More...
 

Detailed Description

class TestServerThread runs a thread to listen and accept tcp connections from clients and generates telegrams to test the ros driver for sim localization.

Definition at line 80 of file test_server_thread.h.

Member Typedef Documentation

< enumerates testcases for simulation of communication errors

typedef boost::asio::ip::tcp::socket* sick_scan::TestServerThread::socket_ptr
protected

shortcut for pointer to boost::asio::ip::tcp::socket

Definition at line 132 of file test_server_thread.h.

typedef boost::thread* sick_scan::TestServerThread::thread_ptr
protected

shortcut for pointer to boost::thread

Definition at line 131 of file test_server_thread.h.

Member Enumeration Documentation

< enumerates testcases for simulation of communication errors

Enumerator
NO_ERROR 

Default: run test server without simulated errors, send valid telegrams.

DONT_LISTEN 

Testserver does not open listening port.

DONT_ACCECPT 

Testserver does not accecpt tcp clients.

DONT_SEND 

Testserver does not send any data.

SEND_RANDOM_TCP 

Testserver sends invalid random tcp packets.

SEND_INVALID_TELEGRAMS 

Testserver sends invalid telegrams (invalid data, false checksums, etc.)

Definition at line 247 of file test_server_thread.h.

Constructor & Destructor Documentation

sick_scan::TestServerThread::TestServerThread ( ROS::NodePtr  nh = 0,
int  ip_port_results = 2201,
int  ip_port_cola = 2111 
)

Constructor. The server thread does not start automatically, call start() and stop() to start and stop the server.

Parameters
[in]nhros node handle
[in]ip_port_resultsip port for result telegrams, default: 2201
[in]ip_port_colaip port for command requests and responses, default: 2111

Definition at line 74 of file test_server_thread.cpp.

sick_scan::TestServerThread::~TestServerThread ( )
virtual

Destructor. Stops the server thread and closes all tcp connections.

Definition at line 113 of file test_server_thread.cpp.

Member Function Documentation

void sick_scan::TestServerThread::closeScandataThread ( void  )
protected

Closes the send scandata thread

Definition at line 197 of file test_server_thread.cpp.

void sick_scan::TestServerThread::closeSocket ( socket_ptr p_socket)
protected

Closes a socket.

Parameters
[in,out]p_socketsocket to be closed

Definition at line 238 of file test_server_thread.cpp.

void sick_scan::TestServerThread::closeTcpConnections ( bool  force_shutdown = false)
protectedvirtual

Closes all tcp connections

Parameters
[in]force_shutdownif true, sockets are immediately forced to shutdown

Definition at line 212 of file test_server_thread.cpp.

void sick_scan::TestServerThread::closeWorkerThreads ( void  )
protected

Stops all worker threads

Definition at line 269 of file test_server_thread.cpp.

void sick_scan::TestServerThread::errorSimulationWait ( double  seconds)
protected

Waits for a given time in seconds, as long as ROS::ok() and m_error_simulation_thread_running == true.

Parameters
[in]secondsdelay in seconds

Definition at line 618 of file test_server_thread.cpp.

bool sick_scan::TestServerThread::errorSimulationWaitForTelegramReceived ( double  timeout_seconds,
sick_scan::SickLocResultPortTelegramMsg &  telegram_msg 
)
protected

Waits for and returns the next telegram message from sick_scan driver.

Parameters
[in]timeout_secondswait timeout in seconds
[out]telegram_msglast telegram message received
Returns
true, if a new telegram message received, false otherwise (timeout or shutdown)

Definition at line 633 of file test_server_thread.cpp.

void sick_scan::TestServerThread::messageCbResultPortTelegrams ( const sick_scan::SickLocResultPortTelegramMsg &  msg)

Callback for result telegram messages (SickLocResultPortTelegramMsg) from sim_loc_driver. Buffers the last telegram to monitor sim_loc_driver messages in error simulation mode.

Parameters
[in]msgresult telegram message (SickLocResultPortTelegramMsg)

Definition at line 287 of file test_server_thread.cpp.

virtual void sick_scan::TestServerThread::messageCbResultPortTelegramsROS2 ( const std::shared_ptr< sick_scan::SickLocResultPortTelegramMsg >  msg)
inlinevirtual

ROS2 version of function messageCbResultPortTelegrams

Definition at line 116 of file test_server_thread.h.

void sick_scan::TestServerThread::runConnectionThreadColaCb ( void  )
protectedvirtual

Thread callback, listens and accept tcp connections from clients for cola telegrams. Starts a new worker thread to receive command requests for each tcp client.

Definition at line 305 of file test_server_thread.cpp.

template<typename Callable >
void sick_scan::TestServerThread::runConnectionThreadGenericCb ( boost::asio::ip::tcp::acceptor &  tcp_acceptor_results,
int  ip_port_results,
Callable  thread_function_cb 
)
protected

Generic thread callback, listens and accept tcp connections from clients. Starts a worker thread running thread_function_cb for each tcp client.

Thread callback, listens and accept tcp connections from clients. Starts a worker thread for each tcp client.

Definition at line 314 of file test_server_thread.cpp.

void sick_scan::TestServerThread::runConnectionThreadResultCb ( void  )
protectedvirtual

Thread callback, listens and accept tcp connections from clients for result telegrams. Starts a new worker thread to generate result port telegrams for each tcp client.

Definition at line 296 of file test_server_thread.cpp.

void sick_scan::TestServerThread::runErrorSimulationThreadCb ( void  )
protectedvirtual

Thread callback, runs an error simulation and switches m_error_simulation_flag through the error test cases.

Definition at line 651 of file test_server_thread.cpp.

void sick_scan::TestServerThread::runWorkerThreadColaCb ( boost::asio::ip::tcp::socket *  p_socket)
protectedvirtual

Worker thread callback, receives command requests from a tcp client and sends a synthetical command response. There's one request worker thread for each tcp client.

Parameters
[in]p_socketsocket to receive command requests from the tcp client

Definition at line 441 of file test_server_thread.cpp.

void sick_scan::TestServerThread::runWorkerThreadResultCb ( boost::asio::ip::tcp::socket *  p_socket)
protectedvirtual

Worker thread callback, generates and sends result telegrams to a tcp client. There's one result worker thread for each tcp client.

Parameters
[in]p_socketsocket to send result telegrams to the tcp client

Definition at line 366 of file test_server_thread.cpp.

void sick_scan::TestServerThread::runWorkerThreadScandataCb ( boost::asio::ip::tcp::socket *  p_socket)
protectedvirtual

Worker thread callback, sends scandata and scandatamon messages to the tcp client. Reads scandata and scandatamon messages from jsonfile and sends the messages in a loop while m_tcp_send_scandata_thread_running is true.

Parameters
[in]p_socketsocket to sends scandata and scandatamon messages the tcp client

Definition at line 535 of file test_server_thread.cpp.

bool sick_scan::TestServerThread::start ( void  )
virtual

Starts the server thread, starts to listen and accept tcp connections from clients.

Returns
true on success, false on failure.

Definition at line 122 of file test_server_thread.cpp.

bool sick_scan::TestServerThread::stop ( void  )
virtual

Stops the server thread and closes all tcp connections.

Returns
true on success, false on failure.

Definition at line 151 of file test_server_thread.cpp.

Member Data Documentation

bool sick_scan::TestServerThread::m_demo_move_in_circles
protected

true: simulate a sensor moving in circles, false (default): create random based result port telegrams

Definition at line 238 of file test_server_thread.h.

bool sick_scan::TestServerThread::m_error_simulation_enabled
protected

default: false (no error simulation), if true, test server simulates errors and communication failures of type ERROR_SIMULATION_FLAG

Definition at line 258 of file test_server_thread.h.

sick_scan::SetGet<ERROR_SIMULATION_FLAG> sick_scan::TestServerThread::m_error_simulation_flag
protected

current error simulation flag, default: NO_ERROR

Definition at line 257 of file test_server_thread.h.

thread_ptr sick_scan::TestServerThread::m_error_simulation_thread
protected

thread to run error simulation, switches m_error_simulation_flag through the error test cases

Definition at line 259 of file test_server_thread.h.

bool sick_scan::TestServerThread::m_error_simulation_thread_running
protected

true: m_error_simulation_thread is running, otherwise false

Definition at line 260 of file test_server_thread.h.

boost::asio::io_service sick_scan::TestServerThread::m_ioservice
protected

boost io service for tcp connections

Definition at line 229 of file test_server_thread.h.

int sick_scan::TestServerThread::m_ip_port_cola
protected

ip port for for command requests and responses, default: The localization controller uses IP port number 2111 and 2112 to send telegrams and to request data

Definition at line 221 of file test_server_thread.h.

int sick_scan::TestServerThread::m_ip_port_results
protected

ip port for result telegrams, default: The localization controller uses IP port number 2201 to send localization results

Definition at line 220 of file test_server_thread.h.

sick_scan::SetGet<sick_scan::SickLocResultPortTelegramMsg> sick_scan::TestServerThread::m_last_telegram_received
protected

last telegram message received from sick_scan driver

Definition at line 261 of file test_server_thread.h.

double sick_scan::TestServerThread::m_result_telegram_rate
protected

frequency to generate and send result port telegrams, default: 10 Hz

Definition at line 222 of file test_server_thread.h.

std::string sick_scan::TestServerThread::m_result_testcases_frame_id
protected

ros frame id of testcase messages (type SickLocResultPortTestcaseMsg), default: "result_testcases"

Definition at line 237 of file test_server_thread.h.

sick_scan::SickLocResultPortTestcaseMsgPublisher sick_scan::TestServerThread::m_result_testcases_publisher
protected

ros publisher for testcases with result port telegrams (type SickLocResultPortTestcaseMsg)

Definition at line 236 of file test_server_thread.h.

std::string sick_scan::TestServerThread::m_scandatafiles
protected

comma separated list of jsonfiles to emulate scandata messages, f.e. "tim781s_scandata.pcapng.json,tim781s_sopas.pcapng.json"

Definition at line 239 of file test_server_thread.h.

std::string sick_scan::TestServerThread::m_scandatatypes
protected

comma separated list of scandata message types, f.e. "sSN LMDscandata,sSN LMDscandatamon"

Definition at line 240 of file test_server_thread.h.

std::string sick_scan::TestServerThread::m_scanner_type
protected

currently supported: "sick_lms_5xx", "sick_tim_7xx"

Definition at line 241 of file test_server_thread.h.

double sick_scan::TestServerThread::m_start_scandata_delay
protected

delay between scandata activation ("LMCstartmeas" request) and first scandata message, default: 1 second

Definition at line 227 of file test_server_thread.h.

boost::asio::ip::tcp::acceptor sick_scan::TestServerThread::m_tcp_acceptor_cola
protected

boost acceptor for tcp clients for command requests and responses

Definition at line 231 of file test_server_thread.h.

boost::asio::ip::tcp::acceptor sick_scan::TestServerThread::m_tcp_acceptor_results
protected

boost acceptor for tcp clients for result telegrams

Definition at line 230 of file test_server_thread.h.

thread_ptr sick_scan::TestServerThread::m_tcp_connection_thread_cola
protected

thread to accept tcp clients for command requests and responses

Definition at line 224 of file test_server_thread.h.

thread_ptr sick_scan::TestServerThread::m_tcp_connection_thread_results
protected

thread to accept tcp clients for result port telegrams

Definition at line 223 of file test_server_thread.h.

bool sick_scan::TestServerThread::m_tcp_connection_thread_running
protected

true: m_tcp_connection_thread is running, otherwise false

Definition at line 228 of file test_server_thread.h.

thread_ptr sick_scan::TestServerThread::m_tcp_send_scandata_thread
protected

thread to send scandata and scandatamon tcp messages

Definition at line 225 of file test_server_thread.h.

bool sick_scan::TestServerThread::m_tcp_send_scandata_thread_running
protected

true: m_tcp_send_scandata_thread is running, otherwise false

Definition at line 226 of file test_server_thread.h.

std::list<boost::asio::ip::tcp::socket*> sick_scan::TestServerThread::m_tcp_sockets
protected

list of tcp sockets (one socket for each tcp client)

Definition at line 232 of file test_server_thread.h.

std::list<thread_ptr> sick_scan::TestServerThread::m_tcp_worker_threads
protected

list of tcp worker thread (one thread for each tcp client, generating telegrams)

Definition at line 233 of file test_server_thread.h.

boost::mutex sick_scan::TestServerThread::m_tcp_worker_threads_mutex
protected

mutex to protect m_tcp_worker_threads

Definition at line 234 of file test_server_thread.h.

bool sick_scan::TestServerThread::m_worker_thread_running
protected

true: worker threads started, otherwise false

Definition at line 235 of file test_server_thread.h.


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


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:49