DESERT 3.5.1
Loading...
Searching...
No Matches
uwserial.h
Go to the documentation of this file.
1//
2// Copyright (c) 2019 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
36#ifndef MSERIAL_H
37#define MSERIAL_H
38
39#include "uwconnector.h"
40
41#include <cstdio>
42#include <cstring>
43#include <fcntl.h> // File controls like O_RDWR
44#include <termios.h> // POSIX terminal control definitions
45#include <unistd.h> // write(), read(), close()
46
52class UwSerial : public UwConnector
53{
54
55public:
59 UwSerial();
60
64 virtual ~UwSerial();
65
72 virtual bool openConnection(const std::string &path);
73
78 virtual bool closeConnection();
79
85 virtual const bool isConnected();
86
91 virtual int writeToDevice(const std::string& msg);
92
99 virtual int readFromDevice(void *wpos, int maxlen);
100
105 virtual int configurePort(const std::string &path);
106
112 virtual bool refreshConnection(const std::string &path);
113
114private:
120
121 struct termios tty;
122};
123
124#endif
Class UwConnector allows to specify an interface between the UwDriver object and the device.
Definition uwconnector.h:52
Class that implements serial port connection.
Definition uwserial.h:53
UwSerial()
Constructor of the UwSerial class.
Definition uwserial.cpp:35
virtual int configurePort(const std::string &path)
Method that loads the termios struct with the serial port parameters.
Definition uwserial.cpp:123
virtual ~UwSerial()
Destructor of the UwSerial class.
Definition uwserial.cpp:42
virtual const bool isConnected()
Returns true if serial port fd differs from -1, that means the connection is up.
Definition uwserial.cpp:47
virtual int writeToDevice(const std::string &msg)
Method that writes a command to the port interface.
Definition uwserial.cpp:97
int serialfd
Integer value that stores the serial port descriptor as generated by the function UwSerial:openConnec...
Definition uwserial.h:119
virtual bool closeConnection()
Method that closes an active connection to a device.
Definition uwserial.cpp:86
virtual bool openConnection(const std::string &path)
Method that opens a serial connection, the input string has to be with a format like <port_name>:pari...
Definition uwserial.cpp:53
struct termios tty
Definition uwserial.h:121
virtual bool refreshConnection(const std::string &path)
Method that refreshes an existing connection creating a new file descriptor.
Definition uwserial.cpp:261
virtual int readFromDevice(void *wpos, int maxlen)
Function that receives data from the device's port to a backup buffer.
Definition uwserial.cpp:109
Generic class that provides a method to interface with the devices. Will be specialized for,...