YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SerialPort_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
9#include <yarp/os/Os.h>
10
11namespace {
12YARP_LOG_COMPONENT(SERIAL_NWC, "yarp.devices.serialPort_nwc_yarp")
13}
14
19
21{
22 m_sendPort.write(msg);
23 return true;
24}
25
26bool SerialPort_nwc_yarp::send(const char *msg, size_t size)
27{
28 Bottle b;
29 b.addString(std::string(msg));
30 m_sendPort.write(b);
31 return true;
32}
33
35{
36 return false;
37}
38
40{
41 return 0;
42}
43
45{
46 int ret = m_rpc.flush();
47 return ret;
48}
49
51{
52 return 0;
53}
54
55int SerialPort_nwc_yarp::receiveBytes(unsigned char* bytes, const int size)
56{
57 return 0;
58}
59
61{
62 return m_rpc.setDTR(enable);
63}
64
66{
67 return closeMain();
68}
69
71{
72 if (!parseParams(config)) { return false; }
73
74 {
75 std::string local_rpc = m_local;
76 std::string remote_rpc = m_remote;
77
78 if (!m_rpcPort.open(local_rpc))
79 {
80 yCError(SERIAL_NWC, "open() error could not open rpc port %s, check network", local_rpc.c_str());
81 return false;
82 }
83
84 if (!Network::connect(local_rpc, remote_rpc))
85 {
86 yCError(SERIAL_NWC, "open() error could not connect to %s", remote_rpc.c_str());
87 return false;
88 }
89
90 if (!m_rpc.yarp().attachAsClient(m_rpcPort))
91 {
92 yCError(SERIAL_NWC, "Error! Cannot attach the m_rpc_port port as a client");
93 return false;
94 }
95 }
96
97 {
98 std::string local_send = "/serialPort_nwc_yarp/out";
99 std::string remote_send = "/serialPort_nws_yarp/in";
100 if (!m_sendPort.open(local_send))
101 {
102 yCError(SERIAL_NWC, "open() error could not open rpc port %s, check network", local_send.c_str());
103 return false;
104 }
105
106 if (!Network::connect(local_send, remote_send))
107 {
108 yCError(SERIAL_NWC, "open() error could not connect to %s", remote_send.c_str());
109 return false;
110 }
111 }
112
113 return true;
114}
bool ret
virtual bool setDTR(const bool enable)
virtual std::int32_t flush()
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
int receiveLine(char *line, const int MaxLineLength) override
Gets one line (a sequence of chars with a ending '\n' or '\r') from the receive queue.
bool send(const Bottle &msg) override
Sends a string of chars to the serial communications channel.
bool close() override
Close the DeviceDriver.
int receiveChar(char &c) override
Gets one single char from the receive queue.
int flush() override
Flushes the internal buffer.
int receiveBytes(unsigned char *bytes, const int size) override
Gets an array of bytes (unsigned char) with size <= 'size' parameter.
bool receive(Bottle &msg) override
Gets the existing chars in the receive queue.
bool open(Searchable &prop) override
Open the DeviceDriver.
bool setDTR(bool enable) override
Enable/Disable DTR protocol.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:170
A mini-server for performing network communication in the background.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:436
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)