Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
comm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
drivers
comm
Commits
5c17356a
Commit
5c17356a
authored
8 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/can/virtual_can.cpp
+15
-1
15 additions, 1 deletion
src/can/virtual_can.cpp
src/can/virtual_can.h
+10
-0
10 additions, 0 deletions
src/can/virtual_can.h
src/examples/test_virtual_can_rx.cpp
+1
-0
1 addition, 0 deletions
src/examples/test_virtual_can_rx.cpp
with
26 additions
and
1 deletion
src/can/virtual_can.cpp
+
15
−
1
View file @
5c17356a
...
...
@@ -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
(
1000
000
/
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
;
...
...
This diff is collapsed.
Click to expand it.
src/can/virtual_can.h
+
10
−
0
View file @
5c17356a
...
...
@@ -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
*/
...
...
This diff is collapsed.
Click to expand it.
src/examples/test_virtual_can_rx.cpp
+
1
−
0
View file @
5c17356a
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment