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/LogStream.h>
10#include <yarp/os/Os.h>
11
12namespace {
13YARP_LOG_COMPONENT(SERIAL_NWC, "yarp.devices.serialPort_nwc_yarp")
14}
15
20
22{
23 m_sendPort.write(msg);
24 return true;
25}
26
27bool SerialPort_nwc_yarp::send(const char *msg, size_t size)
28{
29 Bottle b;
30 b.addString(std::string(msg));
31 m_sendPort.write(b);
32 return true;
33}
34
36{
37 return false;
38}
39
41{
42 return 0;
43}
44
46{
47 int ret = m_rpc.flush();
48 return ret;
49}
50
52{
53 return 0;
54}
55
56int SerialPort_nwc_yarp::receiveBytes(unsigned char* bytes, const int size)
57{
58 return 0;
59}
60
62{
63 return m_rpc.setDTR(enable);
64}
65
67{
68 return closeMain();
69}
70
72{
73 if (!parseParams(config)) { return false; }
74
75 {
76 std::string local_rpc = m_local;
77 std::string remote_rpc = m_remote;
78
79 if (!m_rpcPort.open(local_rpc))
80 {
81 yCError(SERIAL_NWC, "open() error could not open rpc port %s, check network", local_rpc.c_str());
82 return false;
83 }
84
85 if (!Network::connect(local_rpc, remote_rpc))
86 {
87 yCError(SERIAL_NWC, "open() error could not connect to %s", remote_rpc.c_str());
88 return false;
89 }
90
91 if (!m_rpc.yarp().attachAsClient(m_rpcPort))
92 {
93 yCError(SERIAL_NWC, "Error! Cannot attach the m_rpc_port port as a client");
94 return false;
95 }
96 }
97
98 {
99 std::string local_send = "/serialPort_nwc_yarp/out";
100 std::string remote_send = "/serialPort_nws_yarp/in";
101 if (!m_sendPort.open(local_send))
102 {
103 yCError(SERIAL_NWC, "open() error could not open rpc port %s, check network", local_send.c_str());
104 return false;
105 }
106
107 if (!Network::connect(local_send, remote_send))
108 {
109 yCError(SERIAL_NWC, "open() error could not connect to %s", remote_send.c_str());
110 return false;
111 }
112 }
113
114 //Check the protocol version
115 if (!m_rpc.checkProtocolVersion()) { return false; }
116
117 yCInfo(SERIAL_NWC) << "Opening of NWC successful";
118 return true;
119}
bool ret
virtual bool checkProtocolVersion()
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:65
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:176
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:395
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 yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)