Skip to content
Snippets Groups Projects
Commit 7c76571d authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Merge branch 'master' into 'can_devel'

# Conflicts:
#   include/can/can.h
parents f0f851a5 b8ffd8ba
No related branches found
No related tags found
1 merge request!2Changed the name of the get_num_bytes() function to get_num_data().
...@@ -10,7 +10,7 @@ build-package: ...@@ -10,7 +10,7 @@ build-package:
script: script:
- apt update || apt -y install ca-certificates && apt update - apt update || apt -y install ca-certificates && apt update
# Uncomment to install dependencies # Uncomment to install dependencies
# - apt -y install iri-<package_name>-dev # - apt -y iri-<package_name>-dev
- apt -y install iri-iriutils-dev - apt -y install iri-iriutils-dev
- mkdir -pv build - mkdir -pv build
- cd build - cd build
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/can/bcm.h> #include <linux/can/bcm.h>
#include <linux/can/raw.h> #include <linux/can/raw.h>
#include <map> #include <map>
#include <linux/sockios.h>
#include "threadserver.h" #include "threadserver.h"
#include "eventserver.h" #include "eventserver.h"
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <asm/termbits.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "comm.h" #include "comm.h"
#include "commexceptions.h" #include "commexceptions.h"
#include "ctime.h" #include "ctime.h"
#include "pthread.h"
CComm::CComm(const std::string& comm_id) CComm::CComm(const std::string& comm_id)
{ {
...@@ -127,7 +128,8 @@ int CComm::read(unsigned char *data,int len) ...@@ -127,7 +128,8 @@ int CComm::read(unsigned char *data,int len)
} }
else else
{ {
throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id); return 0;
// throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
} }
} }
return len; return len;
...@@ -164,7 +166,8 @@ int CComm::write(unsigned char *data,int len) ...@@ -164,7 +166,8 @@ int CComm::write(unsigned char *data,int len)
else else
{ {
this->access_comm.exit(); this->access_comm.exit();
throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id); return 0;
// throw CCommException(_HERE_,"The communication device is not configured yet.\n",this->comm_id);
} }
this->access_comm.exit(); this->access_comm.exit();
return len; return len;
...@@ -212,7 +215,9 @@ void CComm::close(void) ...@@ -212,7 +215,9 @@ void CComm::close(void)
{ {
/* finish the thread */ /* finish the thread */
if(this->state==configured) if(this->state==configured)
{
this->thread_server->kill_thread(this->comm_thread_id); this->thread_server->kill_thread(this->comm_thread_id);
}
/* close the communication device */ /* close the communication device */
this->access_comm.try_enter(); this->access_comm.try_enter();
try{ try{
...@@ -238,7 +243,9 @@ void *CComm::comm_thread(void *param) ...@@ -238,7 +243,9 @@ void *CComm::comm_thread(void *param)
while(!end) while(!end)
{ {
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
wait_result=comm_dev->hard_wait_comm_event(); wait_result=comm_dev->hard_wait_comm_event();
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
try{ try{
comm_dev->access_comm.enter(); comm_dev->access_comm.enter();
if(wait_result==-1) if(wait_result==-1)
...@@ -256,6 +263,17 @@ void *CComm::comm_thread(void *param) ...@@ -256,6 +263,17 @@ void *CComm::comm_thread(void *param)
} }
comm_dev->access_comm.exit(); comm_dev->access_comm.exit();
}catch(CException &e){ }catch(CException &e){
try{
comm_dev->hard_close();
}catch(CException &close){
std::cout << close.what() << std::endl;
}
/* flush the data queues */
comm_dev->receive_queue.flush();
/* change the current state */
comm_dev->state=created;
comm_dev->access_comm.exit();
std::cout << e.what() << std::endl;
end=true; end=true;
} }
} }
...@@ -309,16 +327,12 @@ void CComm::on_error(void) ...@@ -309,16 +327,12 @@ void CComm::on_error(void)
CComm::~CComm() CComm::~CComm()
{ {
this->close();
/* delete the events */ /* delete the events */
if(this->rx_event_id.size()!=0) this->event_server->delete_event(this->rx_event_id);
this->event_server->delete_event(this->rx_event_id); this->rx_event_id="";
if(this->error_event_id.size()!=0) this->event_server->delete_event(this->error_event_id);
{ this->error_event_id="";
this->event_server->delete_event(this->error_event_id);
}
/* delete the thread */ /* delete the thread */
if(this->comm_thread_id.size()!=0) this->thread_server->delete_thread(this->comm_thread_id);
{
this->thread_server->delete_thread(this->comm_thread_id);
}
} }
#include "rs232.h" #include "rs232.h"
#include "rs232exceptions.h" #include "rs232exceptions.h"
#include "ctime.h" #include "ctime.h"
#include <asm/termbits.h>
CRS232::CRS232(const std::string& comm_id) : CComm(comm_id) CRS232::CRS232(const std::string& comm_id) : CComm(comm_id)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment