Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
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
Model registry
Analyze
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
Avionics
Software Development
Skyward Boardcore
Wiki
EventCounter
Changes
Page history
New page
Templates
Clone repository
Update EventCounter
authored
2 years ago
by
Angelo Zangari
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
EventCounter.md
+13
-10
13 additions, 10 deletions
EventCounter.md
with
13 additions
and
10 deletions
EventCounter.md
View page @
ae21046b
...
...
@@ -16,15 +16,18 @@ This example shows the usage of the EventCounter using a single topic.
First of all define the possible events and topics:
```
cpp
#include
<
Common
.h>
#include
<
miosix
.h>
#include
"events/EventBroker.h"
#include
"events/utils/EventCounter.h"
#define sEventBroker Singleton<EventBroker>::getInstance()
using
namespace
miosix
;
using
namespace
Boardcore
;
enum
ExampleEvents
:
uint8_t
{
EV_1
=
EV_FIRST_
SIGNAL
,
EV_1
=
EV_FIRST_
CUSTOM
,
EV_2
};
...
...
@@ -38,14 +41,14 @@ If we post some events, we can check how many events have been posted, both in t
```
cpp
int
main
()
{
EventCounter
counter
{
*
sEventBroker
};
EventCounter
counter
{
sEventBroker
};
counter
.
subscribe
(
TOPIC_1
);
Thread
::
sleep
(
100
);
// post two events
sEventBroker
->
post
(
Event
{
EV_1
},
TOPIC_1
);
sEventBroker
.
post
(
Event
{
EV_1
},
TOPIC_1
);
Thread
::
sleep
(
100
);
sEventBroker
->
post
(
Event
{
EV_2
},
TOPIC_1
);
sEventBroker
.
post
(
Event
{
EV_2
},
TOPIC_1
);
Thread
::
sleep
(
100
);
// As a result we have 2 events in total
...
...
@@ -59,7 +62,7 @@ int main()
TRACE
(
"Last event : %d
\n
"
,
counter
.
getLastEvent
());
counter
.
stop
();
sEventBroker
->
stop
();
sEventBroker
.
stop
();
return
0
;
}
...
...
@@ -67,8 +70,8 @@ int main()
#### Output
```
sh
0.4
2
> Total : 2
0.
4
3> EV_1 count : 1
0.
4
4> EV_2 count : 1
0.4
5
> Last event : 5
0.
3
4> Total : 2
0.3
4
> EV_1 count : 1
0.
3
4> EV_2 count : 1
0.
3
4> Last event : 5
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.