YARP
Yet Another Robot Platform
ServerSerial.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006 Alexandre Bernardino
4  * Copyright (C) 2006 Carlos Beltran-Gonzalez
5  * All rights reserved.
6  *
7  * This software may be modified and distributed under the terms of the
8  * BSD-3-Clause license. See the accompanying LICENSE file for details.
9  */
10 
11 #ifndef YARP_DEV_SERVERSERIAL_H
12 #define YARP_DEV_SERVERSERIAL_H
13 
14 #include <cstdio>
15 #include <cstdlib>
16 
17 #include <yarp/os/BufferedPort.h>
18 #include <yarp/dev/PolyDriver.h>
19 #include <yarp/dev/ISerialDevice.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Network.h>
22 #include <yarp/os/Thread.h>
23 #include <yarp/os/Vocab.h>
24 #include <yarp/os/Bottle.h>
25 
26 
27 using namespace yarp::os;
28 using namespace yarp::sig;
29 using namespace yarp::dev;
30 
31 
32 class ServerSerial;
33 
38  public yarp::os::TypedReaderCallback<yarp::os::Bottle>
39 {
40 protected:
41  yarp::dev::ISerialDevice* ser{nullptr};
42 
43 public:
50 
56  void onRead(Bottle& b) override;
57 };
58 
59 
71 class ServerSerial :
74  private yarp::os::Thread
75 {
76 private:
77  bool verb{false};
79  yarp::os::Port toDevice;
80  yarp::os::Port fromDevice;
81 
84 
85  yarp::dev::ISerialDevice *serial{nullptr};
86  ImplementCallbackHelper2 callback_impl{this};
87 
88 
89  bool closeMain()
90  {
91  if (Thread::isRunning()) {
92  Thread::stop();
93  }
94  //close the port connection here
95  toDevice.close();
96  fromDevice.close();
97  poly.close();
98  return true;
99  }
100 
101 public:
102  ServerSerial() = default;
103  ServerSerial(const ServerSerial&) = delete;
107  ~ServerSerial() override;
108 
109  bool send(const Bottle& msg) override;
110  bool send(char *msg, size_t size) override;
111  bool receive(Bottle& msg) override;
112  int receiveChar(char& c) override;
113  int flush () override;
114  int receiveLine(char* line, const int MaxLineLength) override;
115  int receiveBytes(unsigned char* bytes, const int size) override;
116  bool setDTR(bool enable) override;
117 
122  virtual bool open();
123 
128  bool close() override;
129 
140  bool open(Searchable& prop) override;
141 
145  void run() override;
146 };
147 
148 #endif // YARP_DEV_SERVERSERIAL_H
yarp::os::Port::close
void close() override
Stop port activity.
Definition: Port.cpp:357
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Network.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::sig
Signal processing.
Definition: Image.h:25
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
ImplementCallbackHelper2::ImplementCallbackHelper2
ImplementCallbackHelper2()
Constructor.
yarp::os::PortReaderBuffer< yarp::os::Bottle >
yarp::os::PortWriterBuffer< yarp::os::Bottle >
yarp::os::TypedReaderCallback
A callback for typed data from a port.
Definition: TypedReaderCallback.h:31
yarp::os::Thread
An abstraction for a thread of execution.
Definition: Thread.h:25
yarp::dev::ISerialDevice
A generic interface to serial port devices.
Definition: ISerialDevice.h:28
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::Thread::isRunning
bool isRunning()
Returns true if the thread is running (Thread::start has been called successfully and the thread has ...
Definition: Thread.cpp:108
ServerSerial::ServerSerial
ServerSerial(const ServerSerial &)=delete
PolyDriver.h
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
yarp::dev::PolyDriver::close
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:176
Thread.h
ServerSerial
serial: Export a serial sensor.
Definition: ServerSerial.h:75
ISerialDevice.h
BufferedPort.h
ServerSerial::ServerSerial
ServerSerial()=default
ServerSerial::ServerSerial
ServerSerial(ServerSerial &&)=delete
ImplementCallbackHelper2
Callback implementation after buffered input.
Definition: ServerSerial.h:39
ServerSerial::operator=
ServerSerial & operator=(ServerSerial &&)=delete
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
Vocab.h
ServerSerial::operator=
ServerSerial & operator=(const ServerSerial &)=delete
Time.h
yarp::os::Thread::stop
bool stop()
Stop the thread.
Definition: Thread.cpp:84
Bottle.h