22 YARP_LOG_COMPONENT(REMOTECONTROLBOARDREMAPPER,
"yarp.device.remotecontrolboardremapper")
26 void RemoteControlBoardRemapper::closeAllRemoteControlBoards()
28 for(
auto& m_remoteControlBoardDevice : m_remoteControlBoardDevices)
30 if( m_remoteControlBoardDevice )
32 m_remoteControlBoardDevice->close();
33 delete m_remoteControlBoardDevice;
34 m_remoteControlBoardDevice =
nullptr;
38 m_remoteControlBoardDevices.resize(0);
54 closeAllRemoteControlBoards();
64 std::string localPortPrefix;
65 std::vector<std::string> remoteControlBoardsPorts;
70 localPortPrefix = prop.
find(
"localPortPrefix").
asString();
74 yCError(REMOTECONTROLBOARDREMAPPER) <<
"Parsing parameters: \"localPortPrefix\" should be a string.";
79 if(remoteControlBoards==
nullptr)
81 yCError(REMOTECONTROLBOARDREMAPPER) <<
"Parsing parameters: \"remoteControlBoards\" should be followed by a list.";
85 remoteControlBoardsPorts.resize(remoteControlBoards->
size());
86 for(
size_t ax=0; ax < remoteControlBoards->
size(); ax++)
88 remoteControlBoardsPorts[ax] = remoteControlBoards->
get(ax).
asString();
94 Bottle & optionsGroupBot = prop.
findGroup(
"REMOTE_CONTROLBOARD_OPTIONS");
95 if( !(optionsGroupBot.
isNull()) )
102 m_remoteControlBoardDevices.resize(remoteControlBoardsPorts.size(),
nullptr);
106 for(
size_t ctrlBrd=0; ctrlBrd < remoteControlBoardsPorts.size(); ctrlBrd++ )
108 std::string remote = remoteControlBoardsPorts[ctrlBrd];
110 std::string local = localPortPrefix+remote;
112 Property options = remoteControlBoardsOptions;
113 options.
put(
"device",
"remote_controlboard");
114 options.
put(
"local", local);
115 options.
put(
"remote", remote);
117 m_remoteControlBoardDevices[ctrlBrd] =
new PolyDriver();
119 bool ok = m_remoteControlBoardDevices[ctrlBrd]->open(options);
121 if( !ok || !(m_remoteControlBoardDevices[ctrlBrd]->
isValid()) )
123 yCError(REMOTECONTROLBOARDREMAPPER) <<
"Opening remote_controlboard with remote \"" << remote <<
"\", opening the device failed.";
124 closeAllRemoteControlBoards();
129 remoteControlBoardsList.
push((m_remoteControlBoardDevices[ctrlBrd]),remote.c_str());
137 yCError(REMOTECONTROLBOARDREMAPPER) <<
"Opening the controlboardremapper device, opening the device failed.";
139 closeAllRemoteControlBoards();
148 yCError(REMOTECONTROLBOARDREMAPPER) <<
"Calling attachAll in the controlboardremapper device, opening the device failed.";
150 closeAllRemoteControlBoards();
bool close() override
Close the device driver by deallocating all resources and closing ports.
bool open(yarp::os::Searchable &prop) override
Open the device driver.
bool detachAll() override
Detach the object (you must have first called attach).
bool attachAll(const yarp::dev::PolyDriverList &l) override
Attach to a list of objects.
bool open(yarp::os::Searchable &prop) override
Open the device driver.
bool close() override
Close the device driver by deallocating all resources and closing ports.
void push(PolyDriver *p, const char *k)
A container for a device driver.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool isNull() const override
Checks if the object is invalid.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
A base class for nested structures that can be searched.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual bool isString() const
Checks if value is a string.
virtual Bottle * asList() const
Get list value.
virtual std::string asString() const
Get string value.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
bool isValid()
Check if time is valid (non-zero).
An interface to the operating system, including Port based communication.