Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Jan 16, 2024
1 parent 04a77c3 commit 5237a7e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libraries/YarpPlugins/CanBusBroker/CanBusBroker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <yarp/dev/IMultipleWrapper.h>
#include <yarp/dev/ControlBoardInterfaces.h>
#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
#include <yarp/dev/PolyDriverList.h>

#include "DeviceMapper.hpp"
#include "SingleBusBroker.hpp"
Expand Down Expand Up @@ -417,6 +418,8 @@ class CanBusBroker : public yarp::dev::DeviceDriver,
private:
DeviceMapper deviceMapper;
std::vector<SingleBusBroker *> brokers;
yarp::dev::PolyDriverList fakeBuses;
yarp::dev::PolyDriverList fakeNodes;
SyncPeriodicThread * syncThread {nullptr};
};

Expand Down
34 changes: 33 additions & 1 deletion libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool CanBusBroker::open(yarp::os::Searchable & config)

if (!buses)
{
yCError(CBB) << "Missing key \"buses\" or not a list";
yCError(CBB) << R"(Missing key "buses" or not a list)";
return false;
}

Expand Down Expand Up @@ -59,6 +59,38 @@ bool CanBusBroker::open(yarp::os::Searchable & config)
}
}

if (yarp::os::Value * v; config.check("fakeBuses", v, "fake CAN buses"))
{
if (!v->isList())
{
yCError(CBB) << R"(Key "fakeBuses" must be a list)";
return false;
}

const auto * buses = v->asList();

for (int i = 0; i < buses->size(); i++)
{
fakeBuses.push(nullptr, buses->get(i).asString().c_str());
}
}

if (yarp::os::Value * v; config.check("fakeNodes", v, "fake CAN nodes"))
{
if (!v->isList())
{
yCError(CBB) << R"(Key "fakeNodes" must be a list)";
return false;
}

const auto * nodes = v->asList();

for (int i = 0; i < nodes->size(); i++)
{
fakeNodes.push(nullptr, nodes->get(i).asString().c_str());
}
}

if (config.check("syncPeriod", "SYNC message period (s)"))
{
auto syncPeriod = config.find("syncPeriod").asFloat64();
Expand Down
14 changes: 14 additions & 0 deletions libraries/YarpPlugins/CanBusBroker/IMultipleWrapperImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ bool CanBusBroker::detachAll()
ok &= broker->clearFilters();
}

for (int i = 0; i < fakeBuses.size(); i++)
{
ok &= fakeBuses[i]->poly->close();
delete fakeBuses[i]->poly;
fakeBuses[i]->poly = nullptr;
}

for (int i = 0; i < fakeNodes.size(); i++)
{
ok &= fakeNodes[i]->poly->close();
delete fakeNodes[i]->poly;
fakeNodes[i]->poly = nullptr;
}

return ok;
}

Expand Down

0 comments on commit 5237a7e

Please sign in to comment.