yarp-devices
Loading...
Searching...
No Matches
BusLoadMonitor.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __BUS_LOAD_MONITOR_HPP__
4#define __BUS_LOAD_MONITOR_HPP__
5
6#include <atomic>
7
8#include <yarp/os/Bottle.h>
9#include <yarp/os/BufferedPort.h>
10#include <yarp/os/PeriodicThread.h>
11
12#include "ICanMessageNotifier.hpp"
13
14namespace roboticslab
15{
16
22{
23public:
25 bool notifyMessage(const can_message & msg) override;
26
28 unsigned int reset();
29
30private:
31 std::atomic<unsigned int> bits;
32};
33
38class BusLoadMonitor final : public yarp::os::PeriodicThread
39{
40public:
42 BusLoadMonitor(double period) : yarp::os::PeriodicThread(period)
43 { }
44
45 void setPort(yarp::os::BufferedPort<yarp::os::Bottle> * port)
46 { this->port = port; }
47
48 void setBitrate(unsigned int bitrate)
49 { this->bitrate = bitrate; }
50
51 ICanMessageNotifier * getReadMonitor()
52 { return &readMonitor; }
53
54 ICanMessageNotifier * getWriteMonitor()
55 { return &writeMonitor; }
56
57protected:
59 void run() override;
60
61private:
62 yarp::os::BufferedPort<yarp::os::Bottle> * port {nullptr};
63 unsigned int bitrate {1};
64
65 OneWayMonitor readMonitor;
66 OneWayMonitor writeMonitor;
67};
68
69} // namespace roboticslab
70
71#endif // __BUS_LOAD_MONITOR_HPP__
void run() override
The thread will invoke this periodically.
Definition BusLoadMonitor.cpp:37
BusLoadMonitor(double period)
Constructor.
Definition BusLoadMonitor.hpp:42
Implementation-agnostic consumer for RX CAN transfers.
Definition ICanMessageNotifier.hpp:22
Registers load statistics per single CAN bus.
Definition BusLoadMonitor.hpp:22
unsigned int reset()
Return stored value and clear counter.
Definition BusLoadMonitor.cpp:30
bool notifyMessage(const can_message &msg) override
Tell observers a new CAN message has arrived.
Definition BusLoadMonitor.cpp:22
The main, catch-all namespace for Robotics Lab UC3M.
Definition groups.dox:6
Proxy CAN message structure.
Definition CanMessage.hpp:20