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

#include <test_server_thread.h>

Classes

class  ServerColaRequest
 

Public Member Functions

void messageCbResultPortTelegrams (const sick_scan_xd::SickLocResultPortTelegramMsg &msg)
 
virtual void messageCbResultPortTelegramsROS2 (const std::shared_ptr< sick_scan_xd::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, const std::string &scanner_type="", bool start_scandata_immediately=false)
 
virtual ~TestServerThread ()
 

Protected Types

enum  ERROR_SIMULATION_ENUM {
  SIMU_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_xd::TestServerThread::ERROR_SIMULATION_ENUM ERROR_SIMULATION_FLAG
 < enumerates testcases for simulation of communication errors More...
 
typedef sick_scan_xd::ServerSocketsocket_ptr
 shortcut for pointer to socket More...
 
typedef std::thread * thread_ptr
 shortcut for pointer to std::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_xd::SickLocResultPortTelegramMsg &telegram_msg)
 
virtual void runConnectionThreadColaCb (void)
 
template<typename Callable >
void runConnectionThreadGenericCb (int ip_port_results, Callable thread_function_cb)
 
virtual void runConnectionThreadResultCb (void)
 
virtual void runErrorSimulationThreadCb (void)
 
virtual void runWorkerThreadColaCb (socket_ptr p_socket)
 
virtual void runWorkerThreadResultCb (socket_ptr p_socket)
 
virtual void runWorkerThreadScandataCb (socket_ptr 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_xd::SetGet< ERROR_SIMULATION_FLAGm_error_simulation_flag
 current error simulation flag, default: SIMU_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...
 
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_xd::SetGet< sick_scan_xd::SickLocResultPortTelegramMsgm_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_xd::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...
 
bool m_start_scandata_immediately
 default (false): send scandata after switch into measurement mode (true: start send scandata thread immediately) 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< sick_scan_xd::ServerSocket * > 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...
 
std::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 76 of file test/emulator/include/sick_scan/test_server_thread.h.

Member Typedef Documentation

◆ ERROR_SIMULATION_FLAG

< enumerates testcases for simulation of communication errors

◆ socket_ptr

shortcut for pointer to socket

Definition at line 129 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ thread_ptr

typedef std::thread* sick_scan_xd::TestServerThread::thread_ptr
protected

shortcut for pointer to std::thread

Definition at line 128 of file test/emulator/include/sick_scan/test_server_thread.h.

Member Enumeration Documentation

◆ ERROR_SIMULATION_ENUM

< enumerates testcases for simulation of communication errors

Enumerator
SIMU_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 242 of file test/emulator/include/sick_scan/test_server_thread.h.

Constructor & Destructor Documentation

◆ TestServerThread()

sick_scan_xd::TestServerThread::TestServerThread ( ROS::NodePtr  nh = 0,
int  ip_port_results = 2201,
int  ip_port_cola = 2111,
const std::string &  scanner_type = "",
bool  start_scandata_immediately = false 
)

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
[in]start_scandata_immediatelydefault (false): send scandata after switch into measurement mode (true: start send scandata thread immediately)

Definition at line 83 of file test/emulator/src/test_server_thread.cpp.

◆ ~TestServerThread()

sick_scan_xd::TestServerThread::~TestServerThread ( )
virtual

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

Definition at line 123 of file test/emulator/src/test_server_thread.cpp.

Member Function Documentation

◆ closeScandataThread()

void sick_scan_xd::TestServerThread::closeScandataThread ( void  )
protected

Closes the send scandata thread

Definition at line 196 of file test/emulator/src/test_server_thread.cpp.

◆ closeSocket()

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

Closes a socket.

Parameters
[in,out]p_socketsocket to be closed

Definition at line 232 of file test/emulator/src/test_server_thread.cpp.

◆ closeTcpConnections()

void sick_scan_xd::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 211 of file test/emulator/src/test_server_thread.cpp.

◆ closeWorkerThreads()

void sick_scan_xd::TestServerThread::closeWorkerThreads ( void  )
protected

Stops all worker threads

Definition at line 261 of file test/emulator/src/test_server_thread.cpp.

◆ errorSimulationWait()

void sick_scan_xd::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 627 of file test/emulator/src/test_server_thread.cpp.

◆ errorSimulationWaitForTelegramReceived()

bool sick_scan_xd::TestServerThread::errorSimulationWaitForTelegramReceived ( double  timeout_seconds,
sick_scan_xd::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 642 of file test/emulator/src/test_server_thread.cpp.

◆ messageCbResultPortTelegrams()

void sick_scan_xd::TestServerThread::messageCbResultPortTelegrams ( const sick_scan_xd::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 279 of file test/emulator/src/test_server_thread.cpp.

◆ messageCbResultPortTelegramsROS2()

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

ROS2 version of function messageCbResultPortTelegrams

Definition at line 113 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ runConnectionThreadColaCb()

void sick_scan_xd::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 297 of file test/emulator/src/test_server_thread.cpp.

◆ runConnectionThreadGenericCb()

template<typename Callable >
void sick_scan_xd::TestServerThread::runConnectionThreadGenericCb ( 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 306 of file test/emulator/src/test_server_thread.cpp.

◆ runConnectionThreadResultCb()

void sick_scan_xd::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 288 of file test/emulator/src/test_server_thread.cpp.

◆ runErrorSimulationThreadCb()

void sick_scan_xd::TestServerThread::runErrorSimulationThreadCb ( void  )
protectedvirtual

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

Definition at line 660 of file test/emulator/src/test_server_thread.cpp.

◆ runWorkerThreadColaCb()

void sick_scan_xd::TestServerThread::runWorkerThreadColaCb ( socket_ptr  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 446 of file test/emulator/src/test_server_thread.cpp.

◆ runWorkerThreadResultCb()

void sick_scan_xd::TestServerThread::runWorkerThreadResultCb ( socket_ptr  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 371 of file test/emulator/src/test_server_thread.cpp.

◆ runWorkerThreadScandataCb()

void sick_scan_xd::TestServerThread::runWorkerThreadScandataCb ( socket_ptr  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 544 of file test/emulator/src/test_server_thread.cpp.

◆ start()

bool sick_scan_xd::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 132 of file test/emulator/src/test_server_thread.cpp.

◆ stop()

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

Stops the server thread and closes all tcp connections.

Returns
true on success, false on failure.

Definition at line 161 of file test/emulator/src/test_server_thread.cpp.

Member Data Documentation

◆ m_demo_move_in_circles

bool sick_scan_xd::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 232 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_error_simulation_enabled

bool sick_scan_xd::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 253 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_error_simulation_flag

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

current error simulation flag, default: SIMU_NO_ERROR

Definition at line 252 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_error_simulation_thread

thread_ptr sick_scan_xd::TestServerThread::m_error_simulation_thread
protected

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

Definition at line 254 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_error_simulation_thread_running

bool sick_scan_xd::TestServerThread::m_error_simulation_thread_running
protected

true: m_error_simulation_thread is running, otherwise false

Definition at line 255 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_ip_port_cola

int sick_scan_xd::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 218 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_ip_port_results

int sick_scan_xd::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 217 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_last_telegram_received

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

last telegram message received from sick_scan driver

Definition at line 256 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_result_telegram_rate

double sick_scan_xd::TestServerThread::m_result_telegram_rate
protected

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

Definition at line 219 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_result_testcases_frame_id

std::string sick_scan_xd::TestServerThread::m_result_testcases_frame_id
protected

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

Definition at line 231 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_result_testcases_publisher

sick_scan_xd::SickLocResultPortTestcaseMsgPublisher sick_scan_xd::TestServerThread::m_result_testcases_publisher
protected

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

Definition at line 230 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_scandatafiles

std::string sick_scan_xd::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 233 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_scandatatypes

std::string sick_scan_xd::TestServerThread::m_scandatatypes
protected

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

Definition at line 234 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_scanner_type

std::string sick_scan_xd::TestServerThread::m_scanner_type
protected

currently supported: "sick_lms_5xx", "sick_tim_7xx"

Definition at line 235 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_start_scandata_delay

double sick_scan_xd::TestServerThread::m_start_scandata_delay
protected

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

Definition at line 224 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_start_scandata_immediately

bool sick_scan_xd::TestServerThread::m_start_scandata_immediately
protected

default (false): send scandata after switch into measurement mode (true: start send scandata thread immediately)

Definition at line 236 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_connection_thread_cola

thread_ptr sick_scan_xd::TestServerThread::m_tcp_connection_thread_cola
protected

thread to accept tcp clients for command requests and responses

Definition at line 221 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_connection_thread_results

thread_ptr sick_scan_xd::TestServerThread::m_tcp_connection_thread_results
protected

thread to accept tcp clients for result port telegrams

Definition at line 220 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_connection_thread_running

bool sick_scan_xd::TestServerThread::m_tcp_connection_thread_running
protected

true: m_tcp_connection_thread is running, otherwise false

Definition at line 225 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_send_scandata_thread

thread_ptr sick_scan_xd::TestServerThread::m_tcp_send_scandata_thread
protected

thread to send scandata and scandatamon tcp messages

Definition at line 222 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_send_scandata_thread_running

bool sick_scan_xd::TestServerThread::m_tcp_send_scandata_thread_running
protected

true: m_tcp_send_scandata_thread is running, otherwise false

Definition at line 223 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_sockets

std::list<sick_scan_xd::ServerSocket*> sick_scan_xd::TestServerThread::m_tcp_sockets
protected

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

Definition at line 226 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_worker_threads

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

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

Definition at line 227 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_tcp_worker_threads_mutex

std::mutex sick_scan_xd::TestServerThread::m_tcp_worker_threads_mutex
protected

mutex to protect m_tcp_worker_threads

Definition at line 228 of file test/emulator/include/sick_scan/test_server_thread.h.

◆ m_worker_thread_running

bool sick_scan_xd::TestServerThread::m_worker_thread_running
protected

true: worker threads started, otherwise false

Definition at line 229 of file test/emulator/include/sick_scan/test_server_thread.h.


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


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:21