... | ... | @@ -17,15 +17,18 @@ This example shows the usage of the EventSniffer, in the simple case in which it |
|
|
|
|
|
First of all define the possible events and topics:
|
|
|
```cpp
|
|
|
#include <Common.h>
|
|
|
#include <miosix.h>
|
|
|
#include "events/EventBroker.h"
|
|
|
#include "events/utils/EventSniffer.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
|
|
|
};
|
|
|
|
... | ... | @@ -55,27 +58,28 @@ In the main we can create a vector of topics (only `TOPIC_1` in this case) and p |
|
|
int main()
|
|
|
{
|
|
|
vector<uint8_t> topics{TOPIC_1};
|
|
|
EventSniffer sniffer(*sEventBroker, topics, &callback);
|
|
|
EventSniffer sniffer(sEventBroker, topics, &callback);
|
|
|
|
|
|
// the first two events will trigger the callback
|
|
|
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);
|
|
|
|
|
|
// this will not tigger the callback since
|
|
|
// the sniffer is subscribed only to TOPIC_1
|
|
|
sEventBroker->post(Event{EV_2}, TOPIC_2);
|
|
|
sEventBroker.post(Event{EV_2}, TOPIC_2);
|
|
|
Thread::sleep(100);
|
|
|
|
|
|
sEventBroker->stop();
|
|
|
sEventBroker.stop();
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
#### Output
|
|
|
```
|
|
|
0.12> Callback : EV_1 on topic 0
|
|
|
0.24> Callback : EV_2 on topic 0
|
|
|
0.04> Callback : EV_1 on topic 0
|
|
|
0.14> Callback : EV_2 on topic 0
|
|
|
``` |
|
|
\ No newline at end of file |