yarp-devices
Loading...
Searching...
No Matches
SingleBusBroker.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __SINGLE_BUS_BROKER_HPP__
4#define __SINGLE_BUS_BROKER_HPP__
5
6#include <mutex>
7#include <string>
8
9#include <yarp/os/Bottle.h>
10#include <yarp/os/BufferedPort.h>
11#include <yarp/os/RpcServer.h>
12#include <yarp/os/Searchable.h>
13#include <yarp/os/TypedReaderCallback.h>
14
15#include <yarp/dev/CanBusInterface.h>
16#include <yarp/dev/PolyDriver.h>
17
18#include "CanRxTxThreads.hpp"
19#include "SdoReplier.hpp"
20#include "BusLoadMonitor.hpp"
21
22namespace roboticslab
23{
24
37class SingleBusBroker final : public yarp::os::TypedReaderCallback<yarp::os::Bottle>
38{
39public:
41 SingleBusBroker(const std::string & name);
42
44 ~SingleBusBroker() override;
45
47 bool configure(const yarp::os::Searchable & config);
48
50 bool registerDevice(yarp::dev::PolyDriver * driver);
51
53 bool clearFilters();
54
56 bool startThreads();
57
59 bool stopThreads();
60
63 { return readerThread; }
64
67 { return writerThread; }
68
70 std::string getName() const
71 { return name; }
72
74 void onRead(yarp::os::Bottle & b) override;
75
76private:
78 bool createPorts(const std::string & prefix);
79
80 std::string name;
81
82 CanReaderThread * readerThread {nullptr};
83 CanWriterThread * writerThread {nullptr};
84
85 yarp::dev::ICanBus * iCanBus {nullptr};
86 yarp::dev::ICanBufferFactory * iCanBufferFactory {nullptr};
87
88 yarp::os::BufferedPort<yarp::os::Bottle> dumpPort;
89 std::mutex dumpMutex;
90
91 yarp::os::BufferedPort<yarp::os::Bottle> commandPort;
92
93 yarp::os::RpcServer sdoPort;
94 SdoReplier sdoReplier;
95
96 yarp::os::BufferedPort<yarp::os::Bottle> busLoadPort;
97 BusLoadMonitor * busLoadMonitor {nullptr};
98};
99
100} // namespace roboticslab
101
102#endif // __SINGLE_BUS_BROKER_HPP__
A thread that deals with CAN reads.
Definition CanRxTxThreads.hpp:108
A thread that attends CAN writes.
Definition CanRxTxThreads.hpp:140
void onRead(yarp::os::Bottle &b) override
Callback on incoming remote CAN commands.
Definition SingleBusBroker.cpp:270
bool configure(const yarp::os::Searchable &config)
Configure this CAN bus.
Definition SingleBusBroker.cpp:42
bool clearFilters()
Clear CAN acceptance filters.
Definition SingleBusBroker.cpp:191
bool stopThreads()
Stop CAN read/write threads.
Definition SingleBusBroker.cpp:235
std::string getName() const
Retrieve string identifier for this CAN bus.
Definition SingleBusBroker.hpp:70
bool startThreads()
Start CAN read/write threads.
Definition SingleBusBroker.cpp:210
bool registerDevice(yarp::dev::PolyDriver *driver)
Register CAN handles associated to the input device driver.
Definition SingleBusBroker.cpp:82
bool createPorts(const std::string &prefix)
Open remote CAN interface ports.
Definition SingleBusBroker.cpp:124
~SingleBusBroker() override
Destructor.
Definition SingleBusBroker.cpp:22
SingleBusBroker(const std::string &name)
Constructor, passes string identifier of the CAN bus.
Definition SingleBusBroker.cpp:16
CanWriterThread * getWriter() const
Get handle.
Definition SingleBusBroker.hpp:66
CanReaderThread * getReader() const
Get handle of the CAN RX thread.
Definition SingleBusBroker.hpp:62
The main, catch-all namespace for Robotics Lab UC3M.
Definition groups.dox:6