From 72415514310426bd53543e0106e720ca30473a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20=C5=81ukawski?= Date: Sat, 30 Dec 2023 22:26:08 +0100 Subject: [PATCH] [WIP] Introduce a fake CAN sender delegate --- .../CanBusBroker/DeviceDriverImpl.cpp | 10 +++++++++ .../CanBusBroker/SingleBusBroker.cpp | 14 ++++++++++++ .../CanBusBroker/SingleBusBroker.hpp | 22 +++++++++++++++++++ .../CanBusBroker/YarpCanSenderDelegate.hpp | 14 ++++++++++++ 4 files changed, 60 insertions(+) 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__