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 if (!parseParams(config)) { return false; }
57
58 //open rpc port
59 if (!m_rpcPort.open(m_name))
60 {
61 yCError(MAP2D_NWS_YARP, "Failed to open port %s", m_name.c_str());
62 return false;
63 }
64 m_rpcPort.setReader(*this);
65
66 yCInfo(MAP2D_NWS_YARP) << "Waiting for device to attach";
67
68 return true;
69}
70
72{
73 yCTrace(MAP2D_NWS_YARP, "Close");
74
75 m_rpcPort.interrupt();
76 m_rpcPort.close();
77
78 return true;
79}
80
82{
83 m_iMap2D = nullptr;
84 return true;
85}
86
88{
89 if (driver->isValid())
90 {
91 driver->view(m_iMap2D);
92 m_RPC.setInterface(m_iMap2D);
93 }
94
95 if (nullptr == m_iMap2D)
96 {
97 yCError(MAP2D_NWS_YARP, "Subdevice passed to attach method is invalid");
98 return false;
99 }
100
101 yCInfo(MAP2D_NWS_YARP, "Attach done");
102 return true;
103}
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void setInterface(yarp::dev::Nav2D::IMap2D *_imap)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
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 base class for nested structures that can be searched.
Definition Searchable.h:31
#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.