diff --git a/libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp b/libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp index fa7861f9c..b68a6e4c8 100644 --- a/libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp +++ b/libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp @@ -180,6 +180,16 @@ bool CanBusBroker::open(yarp::os::Searchable & config) iCanBusSharer->registerSender(broker->getWriter()->getDelegate()); } } + else + { + auto * broker = new FakeBusBroker(); + brokers.push_back(broker); + + for (auto * iCanBusSharer : busSharers) + { + iCanBusSharer->registerSender(broker->getDelegate()); + } + } } for (auto * broker : brokers) diff --git a/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.cpp b/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.cpp index 84701747e..09b1044cf 100644 --- a/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.cpp +++ b/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.cpp @@ -8,6 +8,7 @@ #include "CanUtils.hpp" #include "LogComponent.hpp" +#include "YarpCanSenderDelegate.hpp" using namespace roboticslab; @@ -323,3 +324,16 @@ void SingleBusBroker::onRead(yarp::os::Bottle & b) } // ----------------------------------------------------------------------------- + +FakeBusBroker::FakeBusBroker() + : sender(new FakeCanSenderDelegate()) +{ } + +// ----------------------------------------------------------------------------- + +FakeBusBroker::~FakeBusBroker() +{ + delete sender; +} + +// ----------------------------------------------------------------------------- diff --git a/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.hpp b/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.hpp index 1786d797d..ecc39a223 100644 --- a/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.hpp +++ b/libraries/YarpPlugins/CanBusBroker/SingleBusBroker.hpp @@ -101,6 +101,28 @@ class SingleBusBroker final : public yarp::os::TypedReaderCallback nodeAvailability; }; +/** + * @ingroup CanBusBroker + * @brief A sender delegate that does nothing. + */ +class FakeCanSenderDelegate : public ICanSenderDelegate +{ +public: + bool prepareMessage(const can_message & msg) override + { return true; } + + void reportAvailability(bool available, unsigned int id) override + { } +}; + } // namespace roboticslab #endif // __YARP_CAN_SENDER_DELEGATE_HPP__