YARP
Yet Another Robot Platform
ServerSerial.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006 Alexandre Bernardino
4 * SPDX-FileCopyrightText: 2006 Carlos Beltran-Gonzalez
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef YARP_DEV_SERVERSERIAL_H
9#define YARP_DEV_SERVERSERIAL_H
10
11#include <cstdio>
12#include <cstdlib>
13
15#include <yarp/dev/PolyDriver.h>
17#include <yarp/os/Time.h>
18#include <yarp/os/Network.h>
19#include <yarp/os/Thread.h>
20#include <yarp/os/Vocab.h>
21#include <yarp/os/Bottle.h>
22
23
24using namespace yarp::os;
25using namespace yarp::sig;
26using namespace yarp::dev;
27
28
29class ServerSerial;
30
35 public yarp::os::TypedReaderCallback<yarp::os::Bottle>
36{
37protected:
39
40public:
47
53 void onRead(Bottle& b) override;
54};
55
56
71 private yarp::os::Thread
72{
73private:
74 bool verb{false};
76 yarp::os::Port toDevice;
77 yarp::os::Port fromDevice;
78
81
82 yarp::dev::ISerialDevice *serial{nullptr};
83 ImplementCallbackHelper2 callback_impl{this};
84
85
86 bool closeMain()
87 {
88 if (Thread::isRunning()) {
89 Thread::stop();
90 }
91 //close the port connection here
92 toDevice.close();
93 fromDevice.close();
94 poly.close();
95 return true;
96 }
97
98public:
99 ServerSerial() = default;
100 ServerSerial(const ServerSerial&) = delete;
104 ~ServerSerial() override;
105
106 bool send(const Bottle& msg) override;
107 bool send(char *msg, size_t size) override;
108 bool receive(Bottle& msg) override;
109 int receiveChar(char& c) override;
110 int flush () override;
111 int receiveLine(char* line, const int MaxLineLength) override;
112 int receiveBytes(unsigned char* bytes, const int size) override;
113 bool setDTR(bool enable) override;
114
119 virtual bool open();
120
125 bool close() override;
126
137 bool open(Searchable& prop) override;
138
142 void run() override;
143};
144
145#endif // YARP_DEV_SERVERSERIAL_H
Callback implementation after buffered input.
Definition: ServerSerial.h:36
ImplementCallbackHelper2()
Constructor.
yarp::dev::ISerialDevice * ser
Definition: ServerSerial.h:38
void onRead(Bottle &b) override
Callback function.
serial: Export a serial sensor.
Definition: ServerSerial.h:72
void run() override
The thread main loop deals with writing on ports here.
~ServerSerial() override
bool close() override
Close the device driver by deallocating all resources and closing ports.
ServerSerial()=default
bool setDTR(bool enable) override
Enable/Disable DTR protocol.
virtual bool open()
Default open() method.
int receiveBytes(unsigned char *bytes, const int size) override
Gets an array of bytes (unsigned char) with size <= 'size' parameter.
ServerSerial & operator=(const ServerSerial &)=delete
bool receive(Bottle &msg) override
Gets the existing chars in the receive queue.
int receiveChar(char &c) override
Gets one single char from the receive queue.
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.
ServerSerial(ServerSerial &&)=delete
ServerSerial & operator=(ServerSerial &&)=delete
bool send(const Bottle &msg) override
Sends a string of chars to the serial communications channel.
int flush() override
Flushes the internal buffer.
ServerSerial(const ServerSerial &)=delete
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
A generic interface to serial port devices.
Definition: ISerialDevice.h:24
A container for a device driver.
Definition: PolyDriver.h:23
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:173
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
A mini-server for network communication.
Definition: Port.h:46
void close() override
Stop port activity.
Definition: Port.cpp:363
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.