From a7f28a183f90b019592e3acac2d94aeed8de5309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20Hern=C3=A0ndez=20Juan?= <shernand@iri.upc.edu> Date: Tue, 31 May 2016 13:13:10 +0000 Subject: [PATCH] Moved the evetn and thread destruction to the class destructor instead of the close() function. --- src/can/can.cpp | 52 ++++++++++++++++++------------------- src/examples/CMakeLists.txt | 6 +++++ src/examples/test_rs232.cpp | 4 +-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/can/can.cpp b/src/can/can.cpp index 31fec83..ca8d68a 100755 --- a/src/can/can.cpp +++ b/src/can/can.cpp @@ -156,32 +156,6 @@ void CCAN::hard_close(void) // close the can device if(this->can_socket_fd!=-1) ::close(this->can_socket_fd); - // free all the resources - if(this->finish_can_thread_event_id!="") - { - this->event_server->set_event(this->finish_can_thread_event_id); - this->thread_server->end_thread(this->can_thread_id); - this->thread_server->detach_thread(this->can_thread_id); - this->thread_server->delete_thread(this->can_thread_id); - this->can_thread_id=""; - this->event_server->delete_event(this->finish_can_thread_event_id); - this->finish_can_thread_event_id=""; - } - if(this->new_frame_event_id!="") - { - this->event_server->delete_event(this->new_frame_event_id); - this->new_frame_event_id=""; - } - if(this->frame_error_event_id!="") - { - this->event_server->delete_event(this->frame_error_event_id); - this->frame_error_event_id=""; - } - if(this->data_requested_event_id!="") - { - this->event_server->delete_event(this->data_requested_event_id); - this->data_requested_event_id=""; - } } void *CCAN::can_thread(void *param) @@ -405,5 +379,31 @@ CCAN::~CCAN() // close the can device if(this->can_socket_fd!=-1) CComm::close(); + // free all the resources + if(this->finish_can_thread_event_id!="") + { + this->event_server->set_event(this->finish_can_thread_event_id); + this->thread_server->end_thread(this->can_thread_id); + this->thread_server->detach_thread(this->can_thread_id); + this->thread_server->delete_thread(this->can_thread_id); + this->can_thread_id=""; + this->event_server->delete_event(this->finish_can_thread_event_id); + this->finish_can_thread_event_id=""; + } + if(this->new_frame_event_id!="") + { + this->event_server->delete_event(this->new_frame_event_id); + this->new_frame_event_id=""; + } + if(this->frame_error_event_id!="") + { + this->event_server->delete_event(this->frame_error_event_id); + this->frame_error_event_id=""; + } + if(this->data_requested_event_id!="") + { + this->event_server->delete_event(this->data_requested_event_id); + this->data_requested_event_id=""; + } } diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 171b454..0f50c9a 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -16,6 +16,12 @@ ADD_EXECUTABLE(test_can_rx test_can_rx.cpp) # edit the following line to add the necessary libraries TARGET_LINK_LIBRARIES(test_can_rx ${IRIUTILS_LIBRARY} comm pthread) +# edit the following line to add the source code for the example and the name of the executable +ADD_EXECUTABLE(test_candump test_candump.cpp) + +# edit the following line to add the necessary libraries +TARGET_LINK_LIBRARIES(test_candump ${IRIUTILS_LIBRARY} comm pthread) + IF(BUILD_FTDI) ADD_EXECUTABLE(test_ftdi test_ftdi.cpp) diff --git a/src/examples/test_rs232.cpp b/src/examples/test_rs232.cpp index 4598df3..c377b62 100644 --- a/src/examples/test_rs232.cpp +++ b/src/examples/test_rs232.cpp @@ -7,7 +7,7 @@ #include <string> #include <iostream> -const std::string serial_dev="/dev/ttyS0"; +const std::string serial_dev="/dev/ttyUSB0"; const std::string empty_string=""; /** @@ -65,7 +65,7 @@ int main(int argc,char *argv[]) int num=0,total_length=0,i=0; TRS232_config serial_config; - serial_config.baud=9600; + serial_config.baud=1000000; serial_config.num_bits=8; serial_config.parity=none; serial_config.stop_bits=1; -- GitLab