YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2D_nws_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "Map2D_nws_yarp.h"
7
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
11
13#include <yarp/dev/IMap2D.h>
15
16#include <yarp/math/Math.h>
17
18#include <cstdlib>
19#include <fstream>
20#include <limits>
21#include <mutex>
22#include <sstream>
23
24using namespace yarp::sig;
25using namespace yarp::dev;
26using namespace yarp::dev::Nav2D;
27using namespace yarp::os;
28
29namespace {
30YARP_LOG_COMPONENT(MAP2D_NWS_YARP, "yarp.device.map2D_nws_yarp")
31}
32
40
42
43bool Map2D_nws_yarp::read(yarp::os::ConnectionReader& connection)
44{
45 bool b = m_RPC.read(connection);
46 if (b)
47 {
48 return true;
49 }
50 yCDebug(MAP2D_NWS_YARP) << "read() Command failed";
51 return false;
52}
53
55{
56 Property params;
57 params.fromString(config.toString());
58
59 if (!config.check("name"))
60 {
61 m_rpcPortName = "/map2D_nws_yarp/rpc";
62 }
63 else
64 {
65 m_rpcPortName = config.find("name").asString();
66 }
67
68 //open rpc port
69 if (!m_rpcPort.open(m_rpcPortName))
70 {
71 yCError(MAP2D_NWS_YARP, "Failed to open port %s", m_rpcPortName.c_str());
72 return false;
73 }
74 m_rpcPort.setReader(*this);
75
76 yCInfo(MAP2D_NWS_YARP) << "Waiting for device to attach";
77
78 return true;
79}
80
82{
83 yCTrace(MAP2D_NWS_YARP, "Close");
84
85 m_rpcPort.interrupt();
86 m_rpcPort.close();
87
88 return true;
89}
90
92{
93 m_iMap2D = nullptr;
94 return true;
95}
96
98{
99 if (driver->isValid())
100 {
101 driver->view(m_iMap2D);
102 m_RPC.setInterface(m_iMap2D);
103 }
104
105 if (nullptr == m_iMap2D)
106 {
107 yCError(MAP2D_NWS_YARP, "Subdevice passed to attach method is invalid");
108 return false;
109 }
110
111 yCInfo(MAP2D_NWS_YARP, "Attach done");
112 return true;
113}
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void setInterface(yarp::dev::Nav2D::IMap2D *_imap)
Map2D_nws_yarp()
Map2D_nws_yarp.
bool detach() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void setReader(PortReader &reader) override
Set an external reader for port data.
void close() override
Stop port activity.
void interrupt() override
Interrupt any current reads or writes attached to the port.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
A class for storing options and configuration information.
Definition Property.h:33
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
A base class for nested structures that can be searched.
Definition Searchable.h:56
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.