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

Implemented the clear_id_filters() function and added a public close() function.

parent cea127e5
No related branches found
No related tags found
No related merge requests found
...@@ -323,7 +323,8 @@ void CCAN::add_id_filter(unsigned short int can_id,bool invert) ...@@ -323,7 +323,8 @@ void CCAN::add_id_filter(unsigned short int can_id,bool invert)
new_filters=new struct can_filter[this->num_filters+1]; new_filters=new struct can_filter[this->num_filters+1];
memcpy(new_filters,this->rx_filters,sizeof(struct can_filter)*this->num_filters); memcpy(new_filters,this->rx_filters,sizeof(struct can_filter)*this->num_filters);
delete[] this->rx_filters; if(this->rx_filters!=NULL)
delete[] this->rx_filters;
this->rx_filters=new_filters; this->rx_filters=new_filters;
// update the new filter // update the new filter
if((can_id&(~CAN_SFF_MASK))!=0)// it's an extended identifier if((can_id&(~CAN_SFF_MASK))!=0)// it's an extended identifier
...@@ -353,7 +354,8 @@ void CCAN::add_id_filter(unsigned short int can_id,unsigned short int mask,bool ...@@ -353,7 +354,8 @@ void CCAN::add_id_filter(unsigned short int can_id,unsigned short int mask,bool
new_filters=new struct can_filter[this->num_filters+1]; new_filters=new struct can_filter[this->num_filters+1];
memcpy(new_filters,this->rx_filters,sizeof(struct can_filter)*this->num_filters); memcpy(new_filters,this->rx_filters,sizeof(struct can_filter)*this->num_filters);
delete[] this->rx_filters; if(this->rx_filters!=NULL)
delete[] this->rx_filters;
this->rx_filters=new_filters; this->rx_filters=new_filters;
// update the new filter // update the new filter
if((can_id&(~CAN_SFF_MASK))!=0)// it's an extended identifier if((can_id&(~CAN_SFF_MASK))!=0)// it's an extended identifier
...@@ -379,7 +381,23 @@ void CCAN::add_id_filter(unsigned short int can_id,unsigned short int mask,bool ...@@ -379,7 +381,23 @@ void CCAN::add_id_filter(unsigned short int can_id,unsigned short int mask,bool
void CCAN::clear_id_filters(void) void CCAN::clear_id_filters(void)
{ {
if(this->rx_filters!=NULL)
{
delete this->rx_filters;
this->rx_filters=NULL;
this->num_filters=0;
}
if(setsockopt(this->can_socket_fd,SOL_CAN_RAW,CAN_RAW_FILTER,this->rx_filters,sizeof(struct can_filter)*this->num_filters)==-1)
{
/* handle exceptions */
throw CCommException(_HERE_,"Error while clearing the existing filters",this->comm_id);
}
}
void CCAN::close(void)
{
if(this->can_socket_fd!=-1)
this->close();
} }
CCAN::~CCAN() CCAN::~CCAN()
......
...@@ -243,6 +243,10 @@ class CCAN : protected CComm ...@@ -243,6 +243,10 @@ class CCAN : protected CComm
* \brief * \brief
*/ */
void clear_id_filters(void); void clear_id_filters(void);
/**
* \brief
*/
void close(void);
/** /**
* \brief Destructor * \brief Destructor
* *
......
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