YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SerialPort_nws_yarp.h
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
6#ifndef YARP_DEV_SERIALPORT_NWS_YARP_H
7#define YARP_DEV_SERIALPORT_NWS_YARP_H
8
9#include <cstdio>
10#include <cstdlib>
11
13#include <yarp/dev/PolyDriver.h>
15#include <yarp/os/Time.h>
16#include <yarp/os/Network.h>
17#include <yarp/os/Thread.h>
18#include <yarp/os/Vocab.h>
19#include <yarp/os/Bottle.h>
20#include <yarp/os/RpcServer.h>
22#include <memory>
23#include "ISerialMsgs.h"
24
26
27using namespace yarp::os;
28using namespace yarp::sig;
29using namespace yarp::dev;
30
32
33// Callback implementation after buffered input.
48
50{
51private:
52 std::mutex m_mutex;
53 yarp::dev::ISerialDevice* m_iser = nullptr;
54
55public:
56 bool setDTR(bool enable) override;
57 int flush() override;
58
59public:
61 std::mutex* getMutex() { return &m_mutex; }
62};
63
79 public yarp::os::Thread,
83{
84private:
85 yarp::dev::ISerialDevice* m_iserial{ nullptr };
86 yarp::os::Port toDevice;
87 yarp::os::Port fromDevice;
88 yarp::os::Port m_rpcPort;
89 ISerialMsgsd m_rpc;
90
93 std::unique_ptr<SerialPort_CallbackHelper> callback_impl;
94
95 // yarp::dev::IWrapper
96 bool attach(yarp::dev::PolyDriver* deviceToAttach) override;
97 bool detach() override;
98
99private:
100 bool receive(Bottle& msg);
101 int receiveChar(char& c);
102 bool closeMain();
103
104public:
110 virtual ~SerialPort_nws_yarp() override;
111
112 bool open(yarp::os::Searchable& config) override;
113 bool close() override;
114 bool read(yarp::os::ConnectionReader& connection) override;
115 void run() override;
116};
117
118#endif // YARP_DEV_SERIALPORT_NWS_YARP_H
void setInterfaces(yarp::dev::ISerialDevice *iser)
int flush() override
std::mutex * getMutex()
bool setDTR(bool enable) override
void onRead(Bottle &b) override
Callback method.
yarp::dev::ISerialDevice * m_iser
virtual ~SerialPort_CallbackHelper() override
This class is the parameters parser for class SerialPort_nws_yarp.
serialPort_nws_yarp: Export a serial sensor.
virtual ~SerialPort_nws_yarp() override
void run() override
Main body of the new thread.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
SerialPort_nws_yarp(SerialPort_nws_yarp &&)=delete
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
SerialPort_nws_yarp(const SerialPort_nws_yarp &)=delete
SerialPort_nws_yarp()=default
SerialPort_nws_yarp & operator=(const SerialPort_nws_yarp &)=delete
SerialPort_nws_yarp & operator=(SerialPort_nws_yarp &&)=delete
Interface implemented by all device drivers.
A generic interface to serial port devices.
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A mini-server for network communication.
Definition Port.h:46
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a thread of execution.
Definition Thread.h:21
A callback for typed data from a port.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.