Skip to content

Commit

Permalink
Parse global options from config
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Jan 24, 2024
1 parent 9b39efa commit f2a38b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
23 changes: 14 additions & 9 deletions libraries/YarpPlugins/CanBusBroker/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ using namespace roboticslab;

bool CanBusBroker::open(yarp::os::Searchable & config)
{
const auto * buses = config.find("buses").asList();
yarp::os::Property options;
options.fromString(config.findGroup("global").toString());
options.fromString(config.findGroup("common").toString(), false); // override global options
options.fromString(config.toString(), false); // override common options

const auto * buses = options.find("buses").asList();

if (!buses)
{
Expand All @@ -27,19 +32,19 @@ bool CanBusBroker::open(yarp::os::Searchable & config)
{
auto bus = buses->get(i).asString();

if (!config.check(bus))
if (!options.check(bus))
{
yCError(CBB) << "Missing CAN bus key:" << bus;
return false;
}

if (!config.find(bus).isList())
if (!options.find(bus).isList())
{
yCError(CBB) << "Key" << bus << "must be a list";
return false;
}

const auto * nodes = config.find(bus).asList();
const auto * nodes = options.find(bus).asList();

std::vector<std::string> names;

Expand All @@ -52,14 +57,14 @@ bool CanBusBroker::open(yarp::os::Searchable & config)
auto * broker = new SingleBusBroker(bus, names);
brokers.push_back(broker);

if (!broker->configure(config))
if (!broker->configure(options))
{
yCError(CBB) << "Unable to configure broker of CAN bus device" << bus;
return false;
}
}

if (yarp::os::Value * v; config.check("fakeNodes", v, "fake CAN nodes"))
if (yarp::os::Value * v; options.check("fakeNodes", v, "fake CAN nodes"))
{
if (!v->isList())
{
Expand All @@ -75,9 +80,9 @@ bool CanBusBroker::open(yarp::os::Searchable & config)
}
}

if (config.check("syncPeriod", "SYNC message period (s)"))
if (options.check("syncPeriod", "SYNC message period (s)"))
{
auto syncPeriod = config.find("syncPeriod").asFloat64();
auto syncPeriod = options.find("syncPeriod").asFloat64();

if (syncPeriod <= 0.0)
{
Expand Down Expand Up @@ -107,7 +112,7 @@ bool CanBusBroker::open(yarp::os::Searchable & config)
return false;
}

if (yarp::os::Value * v; config.check("syncObserver", v, "synchronization signal observer") && v->isBlob())
if (yarp::os::Value * v; options.check("syncObserver", v, "synchronization signal observer") && v->isBlob())
{
yCDebug(CBB) << "Setting synchronization signal observer";
auto * observer = *reinterpret_cast<TypedStateObserver<double> * const *>(v->asBlob());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool CanBusBroker::attachAll(const yarp::dev::PolyDriverList & drivers)
return false;
}

yCInfo(CBB) << "Attached" << buses.size() << "bus devices and" << nodes.size() << "node devices";
yCInfo(CBB) << "Attached" << buses.size() << "bus device(s) and" << nodes.size() << "node device(s)";

for (int i = 0; i < buses.size(); i++)
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/YarpPlugins/TechnosoftIpos/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ constexpr auto DEFAULT_DRIVE_STATE_TIMEOUT = 2.0;
bool TechnosoftIposBase::open(yarp::os::Searchable & config)
{
yarp::os::Property iposOptions;
iposOptions.fromString(config.findGroup("common").toString());
iposOptions.fromString(config.findGroup("global").toString());
iposOptions.fromString(config.findGroup("common").toString(), false); // override global options
iposOptions.fromString(config.toString(), false); // override common options

const auto & driverOptions = config.findGroup("driver");
Expand Down

0 comments on commit f2a38b6

Please sign in to comment.