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 "ISerialMsgs.h"
23
24using namespace yarp::os;
25using namespace yarp::sig;
26using namespace yarp::dev;
27
29
47
49{
50private:
51 std::mutex m_mutex;
52 yarp::dev::ISerialDevice* m_iser = nullptr;
53
54public:
55 bool setDTR(bool enable) override;
56 int flush() override;
57
58public:
60 std::mutex* getMutex() { return &m_mutex; }
61};
62
76 public yarp::os::Thread,
79{
80private:
81 yarp::dev::ISerialDevice* m_iserial{ nullptr };
82 yarp::os::Port toDevice;
83 yarp::os::Port fromDevice;
84 yarp::os::Port m_rpcPort;
85 ISerialMsgsd m_rpc;
86
89 ImplementCallbackHelper2* callback_impl{ nullptr };
90
91 // yarp::dev::IWrapper
92 bool attach(yarp::dev::PolyDriver* deviceToAttach) override;
93 bool detach() override;
94
95private:
96 bool receive(Bottle& msg);
97 int receiveChar(char& c);
98 bool closeMain();
99
100public:
106 virtual ~SerialPort_nws_yarp() override;
107
108 bool open(yarp::os::Searchable& config) override;
109 bool close() override;
111 void run() override;
112};
113
114#endif // YARP_DEV_SERIALPORT_NWS_YARP_H
void setInterfaces(yarp::dev::ISerialDevice *iser)
int flush() override
std::mutex * getMutex()
bool setDTR(bool enable) override
Callback implementation after buffered input.
yarp::dev::ISerialDevice * m_iser
virtual ~ImplementCallbackHelper2() override
void onRead(Bottle &b) override
Callback method.
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:56
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.