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

Added an attribute to chnage the new packet update rate and functions to handle it.

parent 3913bd1c
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ CVirtualCAN::CVirtualCAN(const std::string &comm_id) : CComm(comm_id)
this->event_server->create_event(this->data_requested_event_id);
this->finish_can_thread_event_id=comm_id + "_finish_can_thread_event_id";
this->event_server->create_event(this->finish_can_thread_event_id);
this->update_rate_hz=1000;
}
void CVirtualCAN::hard_open(void *comm_dev)
......@@ -94,7 +95,7 @@ int CVirtualCAN::hard_get_num_data(void)
int CVirtualCAN::hard_wait_comm_event(void)
{
usleep(1000);// publish can packets at 1KHz
usleep(1000000/this->update_rate_hz);// publish can packets at 1KHz
return 1;
}
......@@ -155,6 +156,19 @@ void CVirtualCAN::open(const std::string &dump_filename)
this->config();
}
void CVirtualCAN::set_update_rate(double rate_hz)
{
if(rate_hz<10.0 || rate_hz>10000.0)
throw CCommException(_HERE_,"Invalid update rate. Supported rate range between 10 Hz and 10 kHz.",this->comm_id);
else
this->update_rate_hz=rate_hz;
}
double CVirtualCAN::get_update_rate(void)
{
return this->update_rate_hz;
}
std::string CVirtualCAN::get_new_frame_event_id(void)
{
return this->new_frame_event_id;
......
......@@ -46,6 +46,8 @@ class CVirtualCAN : protected CComm
struct can_filter *rx_filters;
unsigned int num_filters;
CMutex can_access;
// desired rate
double update_rate_hz;
protected:
/**
* \brief Function to actually open the device
......@@ -198,6 +200,14 @@ class CVirtualCAN : protected CComm
* class.
*/
CVirtualCAN(const std::string &comm_id);
/**
* \brief
*/
void set_update_rate(double rate_hz);
/**
* \brief
*/
double get_update_rate(void);
/**
* \brief
*/
......
......@@ -28,6 +28,7 @@ int main(int argc,char *argv[])
events.push_back(can_port.get_new_frame_event_id());
try{
can_port.open(dump_file);
can_port.set_update_rate(100);
can_port.add_id_filter(0x010,0x0F0,false);
while(1)
{
......
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