| 1 |
/* |
| 2 |
* ISerialInterface.hpp |
| 3 |
* |
| 4 |
* Copyright 2020 Kevin Krüger <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 |
* MA 02110-1301, USA. |
| 20 |
* |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef _ISERIALINTERFACE_H_INCLUDED_ |
| 25 |
#define _ISERIALINTERFACE_H_INCLUDED_ |
| 26 |
|
| 27 |
#include <cstdint> |
| 28 |
#include "config.h" |
| 29 |
|
| 30 |
namespace SerialDeviceControl |
| 31 |
{ |
| 32 |
//Abstraction of the serial interface to allow reuse of code for several implementations. |
| 33 |
class ISerialInterface |
| 34 |
{ |
| 35 |
public: |
| 36 |
//Opens the serial device, the acutal implementation has to deal with the handles! |
| 37 |
virtual bool Open() = 0; |
| 38 |
|
| 39 |
//Closes the serial device, the actual implementation has to deal with the handles! |
| 40 |
virtual bool Close() = 0; |
| 41 |
|
| 42 |
//Returns true if the serial port is open and ready to receive or transmit data. |
| 43 |
virtual bool IsOpen() = 0; |
| 44 |
|
| 45 |
//Returns the number of bytes to read available in the serial receiver queue. |
| 46 |
virtual size_t BytesToRead() = 0; |
| 47 |
|
| 48 |
//Reads a byte from the serial device. Can safely cast to uint8_t unless -1 is returned, corresponding to "stream end reached". |
| 49 |
virtual int16_t ReadByte() = 0; |
| 50 |
|
| 51 |
//writes the buffer to the serial interface. |
| 52 |
//this function should handle all the quirks of various serial interfaces. |
| 53 |
virtual bool Write(uint8_t* buffer, size_t offset, size_t length) = 0; |
| 54 |
|
| 55 |
//flush the buffer. |
| 56 |
virtual bool Flush() = 0; |
| 57 |
}; |
| 58 |
} |
| 59 |
#endif |