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/PeriodicThread.h>
10#include <yarp/os/PortWriterBuffer.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 public yarp::os::PortWriterBuffer<yarp::os::Bottle>
40{
41public:
43 BusLoadMonitor(double period) : yarp::os::PeriodicThread(period), bitrate(1.0)
44 { }
45
46 void setBitrate(unsigned int bitrate)
47 { this->bitrate = bitrate; }
48
49 ICanMessageNotifier * getReadMonitor()
50 { return &readMonitor; }
51
52 ICanMessageNotifier * getWriteMonitor()
53 { return &writeMonitor; }
54
55protected:
57 void run() override;
58
59private:
60 unsigned int bitrate;
61
62 OneWayMonitor readMonitor;
63 OneWayMonitor writeMonitor;
64};
65
66} // namespace roboticslab
67
68#endif // __BUS_LOAD_MONITOR_HPP__
Periodically sends CAN bus load stats through a YARP port.
Definition BusLoadMonitor.hpp:40
void run() override
The thread will invoke this periodically.
Definition BusLoadMonitor.cpp:37
BusLoadMonitor(double period)
Constructor.
Definition BusLoadMonitor.hpp:43
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