Loading...
Searching...
No Matches
SerialStreamBuf.cpp
/******************************************************************************
* @file SerialStreamBuf.cpp *
* @copyright (C) 2004-2018 LibSerial Development Team. All rights reserved. *
* crayzeewulf@gmail.com *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in *
* the documentation and/or other materials provided with the *
* distribution. *
* 3. Neither the name PX4 nor the names of its contributors may be *
* used to endorse or promote products derived from this software *
* without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
*****************************************************************************/
#include "libserial/SerialStreamBuf.h"
#include "libserial/SerialPort.h"
#include <cassert>
#include <cstring>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
namespace LibSerial
{
class SerialStreamBuf::Implementation
{
public:
Implementation() = default ;
~Implementation() ;
Implementation(const std::string& fileName,
const BaudRate& baudRate,
const CharacterSize& characterSize,
const FlowControl& flowControlType,
const Parity& parityType,
const StopBits& stopBits) ;
Implementation(const Implementation& otherImplementation) = delete ;
Implementation(const Implementation&& otherImplementation) = delete ;
Implementation& operator=(const Implementation& otherImplementation) = delete ;
Implementation& operator=(const Implementation&& otherImplementation) = delete ;
void Open(const std::string& fileName,
const std::ios_base::openmode& openMode) ;
void Close() ;
void DrainWriteBuffer() ;
void FlushInputBuffer() ;
void FlushOutputBuffer() ;
void FlushIOBuffers() ;
bool IsDataAvailable() ;
bool IsOpen() const ;
void SetDefaultSerialPortParameters() ;
void SetBaudRate(const BaudRate& baudRate) ;
BaudRate GetBaudRate() const ;
void SetCharacterSize(const CharacterSize& characterSize) ;
CharacterSize GetCharacterSize() const ;
void SetFlowControl(const FlowControl& flowControlType) ;
FlowControl GetFlowControl() const ;
void SetParity(const Parity& parityType) ;
Parity GetParity() const ;
void SetStopBits(const StopBits& stopBits) ;
StopBits GetStopBits() const ;
void SetVMin(const short vmin) ;
short GetVMin() const ;
void SetVTime(const short vtime) ;
short GetVTime() const ;
void SetDTR(const bool dtrState) ;
bool GetDTR() const ;
void SetRTS(const bool rtsState) ;
bool GetRTS() const ;
bool GetCTS() ;
bool GetDSR() ;
int GetFileDescriptor() const ;
int GetNumberOfBytesAvailable() ;
#ifdef __linux__
std::vector<std::string> GetAvailableSerialPorts() const ;
#endif
std::streamsize xsputn(const char_type* character,
std::streamsize numberOfBytes) ;
std::streamsize xsgetn(char_type* character,
std::streamsize numberOfBytes) ;
std::streambuf::int_type overflow(int_type character) ;
std::streambuf::int_type underflow() ;
std::streambuf::int_type uflow() ;
std::streambuf::int_type pbackfail(int_type character) ;
std::streamsize showmanyc() ;
bool mPutbackAvailable {false} ;
char mPutbackChar {0} ;
private:
SerialPort mSerialPort {} ;
} ;
SerialStreamBuf::SerialStreamBuf()
: mImpl(new Implementation)
{
setbuf(nullptr, 0) ;
}
SerialStreamBuf::SerialStreamBuf(const std::string& fileName,
const BaudRate& baudRate,
const CharacterSize& characterSize,
const FlowControl& flowControlType,
const Parity& parityType,
const StopBits& stopBits)
: mImpl(new Implementation(fileName,
baudRate,
characterSize,
flowControlType,
parityType,
stopBits))
{
setbuf(nullptr, 0) ;
}
SerialStreamBuf::~SerialStreamBuf() = default ;
void
SerialStreamBuf::Open(const std::string& fileName,
const std::ios_base::openmode& openMode)
{
mImpl->Open(fileName,
openMode) ;
}
void
SerialStreamBuf::Close()
{
mImpl->Close() ;
}
void
SerialStreamBuf::DrainWriteBuffer()
{
mImpl->DrainWriteBuffer() ;
}
void
SerialStreamBuf::FlushInputBuffer()
{
mImpl->FlushInputBuffer() ;
}
void
SerialStreamBuf::FlushOutputBuffer()
{
mImpl->FlushOutputBuffer() ;
}
void
SerialStreamBuf::FlushIOBuffers()
{
mImpl->FlushIOBuffers() ;
}
bool
SerialStreamBuf::IsDataAvailable()
{
return mImpl->IsDataAvailable() ;
}
bool
SerialStreamBuf::IsOpen() const
{
return mImpl->IsOpen() ;
}
void
SerialStreamBuf::SetDefaultSerialPortParameters()
{
mImpl->SetDefaultSerialPortParameters() ;
}
void
SerialStreamBuf::SetBaudRate(const BaudRate& baudRate)
{
mImpl->SetBaudRate(baudRate) ;
}
BaudRate
SerialStreamBuf::GetBaudRate() const
{
return mImpl->GetBaudRate() ;
}
void
SerialStreamBuf::SetCharacterSize(const CharacterSize& characterSize)
{
mImpl->SetCharacterSize(characterSize) ;
}
CharacterSize
SerialStreamBuf::GetCharacterSize() const
{
return mImpl->GetCharacterSize() ;
}
void
SerialStreamBuf::SetFlowControl(const FlowControl& flowControlType)
{
mImpl->SetFlowControl(flowControlType) ;
}
FlowControl
SerialStreamBuf::GetFlowControl() const
{
return mImpl->GetFlowControl() ;
}
void
SerialStreamBuf::SetParity(const Parity& parityType)
{
mImpl->SetParity(parityType) ;
}
Parity
SerialStreamBuf::GetParity() const
{
return mImpl->GetParity() ;
}
void
SerialStreamBuf::SetStopBits(const StopBits& stopBits)
{
mImpl->SetStopBits(stopBits) ;
}
StopBits
SerialStreamBuf::GetStopBits() const
{
return mImpl->GetStopBits() ;
}
void
SerialStreamBuf::SetVMin(const short vmin)
{
mImpl->SetVMin(vmin) ;
}
short
SerialStreamBuf::GetVMin() const
{
return mImpl->GetVMin() ;
}
void
SerialStreamBuf::SetVTime(const short vtime)
{
mImpl->SetVTime(vtime) ;
}
short
SerialStreamBuf::GetVTime() const
{
return mImpl->GetVTime() ;
}
void
SerialStreamBuf::SetDTR(const bool dtrState)
{
mImpl->SetDTR(dtrState) ;
}
bool
SerialStreamBuf::GetDTR() const
{
return mImpl->GetDTR() ;
}
void
SerialStreamBuf::SetRTS(const bool rtsState)
{
mImpl->SetRTS(rtsState) ;
}
bool
SerialStreamBuf::GetRTS() const
{
return mImpl->GetRTS() ;
}
bool
SerialStreamBuf::GetCTS()
{
return mImpl->GetCTS() ;
}
bool
SerialStreamBuf::GetDSR()
{
return mImpl->GetDSR() ;
}
int
SerialStreamBuf::GetFileDescriptor() const
{
return mImpl->GetFileDescriptor() ;
}
int
SerialStreamBuf::GetNumberOfBytesAvailable()
{
return mImpl->GetNumberOfBytesAvailable() ;
}
#ifdef __linux__
std::vector<std::string>
SerialStreamBuf::GetAvailableSerialPorts() const
{
return mImpl->GetAvailableSerialPorts() ;
}
#endif
std::streambuf*
SerialStreamBuf::setbuf(char_type* character, std::streamsize numberOfBytes)
{
return std::streambuf::setbuf(character, numberOfBytes) ;
}
std::streamsize
SerialStreamBuf::xsputn(const char_type* character, std::streamsize numberOfBytes)
{
return mImpl->xsputn(character, numberOfBytes) ;
}
std::streamsize
SerialStreamBuf::xsgetn(char_type* character, std::streamsize numberOfBytes)
{
return mImpl->xsgetn(character, numberOfBytes) ;
}
std::streambuf::int_type
SerialStreamBuf::overflow(const int_type character)
{
return mImpl->overflow(character) ;
}
std::streambuf::int_type
SerialStreamBuf::underflow()
{
return mImpl->underflow() ;
}
std::streambuf::int_type
SerialStreamBuf::uflow()
{
return mImpl->uflow() ;
}
std::streambuf::int_type
SerialStreamBuf::pbackfail(const int_type character)
{
return mImpl->pbackfail(character) ;
}
std::streamsize
SerialStreamBuf::showmanyc()
{
return mImpl->showmanyc() ;
}
inline
SerialStreamBuf::Implementation::Implementation(const std::string& fileName,
const BaudRate& baudRate,
const CharacterSize& characterSize,
const FlowControl& flowControlType,
const Parity& parityType,
const StopBits& stopBits)
try : mSerialPort(fileName,
baudRate,
characterSize,
flowControlType,
parityType,
stopBits)
{
// empty
}
catch (const std::exception& err)
{
throw OpenFailed(err.what()) ;
}
inline
SerialStreamBuf::Implementation::~Implementation()
try
{
// Close the serial port if it is open.
if (IsOpen())
{
Close() ;
}
}
catch(...)
{
//
// :IMPORTANT: We do not let any exceptions escape the destructor.
// (see https://isocpp.org/wiki/faq/exceptions#dtors-shouldnt-throw)
//
// :TODO: Once we add logging to LibSerial, we should issue a warning
// if we reach here.
//
}
inline
void
SerialStreamBuf::Implementation::Open(const std::string& fileName,
const std::ios_base::openmode& openMode)
try
{
mSerialPort.Open(fileName,
openMode) ;
// @note - Stream communications need to happen in blocking mode.
mSerialPort.SetSerialPortBlockingStatus(true) ;
}
catch (const AlreadyOpen&)
{
throw ;
}
catch (const OpenFailed&)
{
throw ;
}
catch (const std::exception& err)
{
throw OpenFailed(err.what()) ;
}
inline
void
SerialStreamBuf::Implementation::Close()
{
mSerialPort.Close() ;
}
inline
void
SerialStreamBuf::Implementation::DrainWriteBuffer()
{
mSerialPort.DrainWriteBuffer() ;
}
inline
void
SerialStreamBuf::Implementation::FlushInputBuffer()
{
mSerialPort.FlushInputBuffer() ;
}
inline
void
SerialStreamBuf::Implementation::FlushOutputBuffer()
{
mSerialPort.FlushOutputBuffer() ;
}
inline
void
SerialStreamBuf::Implementation::FlushIOBuffers()
{
mSerialPort.FlushIOBuffers() ;
}
inline
bool
SerialStreamBuf::Implementation::IsOpen() const
{
return mSerialPort.IsOpen() ;
}
inline
bool
SerialStreamBuf::Implementation::IsDataAvailable()
{
return mSerialPort.IsDataAvailable() ;
}
inline
void
SerialStreamBuf::Implementation::SetDefaultSerialPortParameters()
{
mSerialPort.SetDefaultSerialPortParameters() ;
}
inline
void
SerialStreamBuf::Implementation::SetBaudRate(const BaudRate& baudRate)
{
mSerialPort.SetBaudRate(baudRate) ;
}
inline
BaudRate
SerialStreamBuf::Implementation::GetBaudRate() const
{
return mSerialPort.GetBaudRate() ;
}
inline
void
SerialStreamBuf::Implementation::SetCharacterSize(const CharacterSize& characterSize)
{
mSerialPort.SetCharacterSize(characterSize) ;
}
inline
CharacterSize
SerialStreamBuf::Implementation::GetCharacterSize() const
{
return mSerialPort.GetCharacterSize() ;
}
inline
void
SerialStreamBuf::Implementation::SetFlowControl(const FlowControl& flowControlType)
{
mSerialPort.SetFlowControl(flowControlType) ;
}
inline
FlowControl
SerialStreamBuf::Implementation::GetFlowControl() const
{
return mSerialPort.GetFlowControl() ;
}
inline
void
SerialStreamBuf::Implementation::SetParity(const Parity& parityType)
{
mSerialPort.SetParity(parityType) ;
}
inline
Parity
SerialStreamBuf::Implementation::GetParity() const
{
return mSerialPort.GetParity() ;
}
inline
void
SerialStreamBuf::Implementation::SetStopBits(const StopBits& stopBits)
{
mSerialPort.SetStopBits(stopBits) ;
}
inline
StopBits
SerialStreamBuf::Implementation::GetStopBits() const
{
return mSerialPort.GetStopBits() ;
}
inline
void
SerialStreamBuf::Implementation::SetVMin(const short vmin)
{
mSerialPort.SetVMin(vmin) ;
}
inline
short
SerialStreamBuf::Implementation::GetVMin() const
{
return mSerialPort.GetVMin() ;
}
inline
void
SerialStreamBuf::Implementation::SetVTime(const short vtime)
{
mSerialPort.SetVTime(vtime) ;
}
inline
short
SerialStreamBuf::Implementation::GetVTime() const
{
return mSerialPort.GetVTime() ;
}
inline
void
SerialStreamBuf::Implementation::SetDTR(const bool dtrState)
{
mSerialPort.SetDTR(dtrState) ;
}
inline
bool
SerialStreamBuf::Implementation::GetDTR() const
{
return mSerialPort.GetDTR() ;
}
inline
void
SerialStreamBuf::Implementation::SetRTS(const bool rtsState)
{
mSerialPort.SetRTS(rtsState) ;
}
inline
bool
SerialStreamBuf::Implementation::GetRTS() const
{
return mSerialPort.GetRTS() ;
}
inline
bool
SerialStreamBuf::Implementation::GetCTS()
{
return mSerialPort.GetCTS() ;
}
inline
bool
SerialStreamBuf::Implementation::GetDSR()
{
return mSerialPort.GetDSR() ;
}
inline
int
SerialStreamBuf::Implementation::GetFileDescriptor() const
{
return mSerialPort.GetFileDescriptor() ;
}
inline
int
SerialStreamBuf::Implementation::GetNumberOfBytesAvailable()
{
return mSerialPort.GetNumberOfBytesAvailable() ;
}
#ifdef __linux__
inline
std::vector<std::string>
SerialStreamBuf::Implementation::GetAvailableSerialPorts() const
{
return mSerialPort.GetAvailableSerialPorts() ;
}
#endif
inline
std::streamsize
SerialStreamBuf::Implementation::xsputn(const char_type* character,
std::streamsize numberOfBytes)
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
// If n is less than 1 there is nothing to accomplish.
if (numberOfBytes <= 0)
{
return 0 ;
}
// Write the n characters to the serial port.
//
// :TODO: Consider using mSerialPort.Write() here instead of writing
// to the file descriptor directly.
const auto fd = mSerialPort.GetFileDescriptor() ;
ssize_t result = call_with_retry(write, fd, character, numberOfBytes) ;
// If the write failed then return 0.
if (result <= 0)
{
return 0 ;
}
// Otherwise, return the number of bytes actually written.
return result;
}
inline
std::streamsize
SerialStreamBuf::Implementation::xsgetn(char_type* character,
std::streamsize numberOfBytes)
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
// If n is less than 1 there is nothing to accomplish.
if (numberOfBytes <= 0)
{
return 0 ;
}
if (character == nullptr) {
return 0 ;
}
// Try to read up to n characters in the array s.
ssize_t result = -1;
// If a putback character is available, then we need to read only
// n-1 character.
if (mPutbackAvailable)
{
// Put the mPutbackChar at the beginning of the array 's'.
// Increment result to indicate that a character has been placed in s.
character[0] = mPutbackChar;
result++;
// The putback character is no longer available.
mPutbackAvailable = false;
// If we need to read more than one character, then call read()
// and try to read numberOfBytes-1 more characters and put them
// at location starting from &character[1].
if (numberOfBytes > 1)
{
//
// :TODO: Consider using mSerialPort.Read() here instead of
// using the file descriptor.
//
const auto fd = mSerialPort.GetFileDescriptor() ;
result = call_with_retry(read, fd, &character[1], numberOfBytes-1) ;
// If read was successful, then we need to increment result by
// one to indicate that the putback character was prepended to
// the array, s. If read failed then leave result at -1.
if (result != -1)
{
result++;
}
}
}
else
{
// If no putback character is available then we try to
// read numberOfBytes characters.
//
// :TODO: Consider using mSerialPort.Read() here instead of
// using the file descriptor.
const auto fd = mSerialPort.GetFileDescriptor() ;
result = call_with_retry(read, fd, character, numberOfBytes) ;
}
// If result == -1 then the read call had an error, otherwise, if
// result == 0 then we could not read the characters. In either
// case, we return 0 to indicate that no characters could be read
// from the serial port.
if (result <= 0)
{
return 0 ;
}
// Return the number of characters actually read from the serial port.
return result;
}
inline
std::streambuf::int_type
SerialStreamBuf::Implementation::overflow(const int_type character)
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
// Try to write the specified character to the serial port.
if (traits_type::eq_int_type(character, traits_type::eof()))
{
// If character is the eof character then we do nothing.
return traits_type::eof() ;
}
// Otherwise we write the character to the serial port.
//
// :TODO: Consider using a method of SerialPort class here instead
// of using the file descriptor.
const auto fd = mSerialPort.GetFileDescriptor() ;
char out_char = traits_type::to_char_type(character) ;
ssize_t result = call_with_retry(write, fd, &out_char, 1) ;
// If the write failed then return eof.
if (result <= 0)
{
return traits_type::eof() ;
}
// Otherwise, return something other than eof().
return traits_type::not_eof(character) ;
}
inline
std::streambuf::int_type
SerialStreamBuf::Implementation::underflow()
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
// Read the next character from the serial port.
char next_char = 0 ;
ssize_t result = -1;
// If a putback character is available then we return that
// character. However, we are not supposed to change the value of
// gptr() in this routine so we leave mPutbackAvailable set to true.
if (mPutbackAvailable)
{
next_char = mPutbackChar;
}
else
{
// If no putback character is available then we need to read one
// character from the serial port.
//
// :TODO: Consider using a method of SerialPort class here instead
// of using the file descriptor.
//
const auto fd = mSerialPort.GetFileDescriptor() ;
result = call_with_retry(read, fd, &next_char, 1) ;
// Make the next character the putback character. This has the
// effect of returning the next character without changing gptr()
// as required by the C++ standard.
if (result == 1)
{
mPutbackChar = next_char;
mPutbackAvailable = true ;
}
else if (result <= 0)
{
// If we had a problem reading the character, we return
// traits::eof().
return traits_type::eof() ;
}
}
// :NOTE: Wed Aug 9 21:26:51 2000 Pagey
// The value of mPutbackAvailable is always true when the code
// reaches here.
// Return the character as an int value as required by the C++
// standard.
return traits_type::to_int_type(next_char) ;
}
inline
std::streambuf::int_type
SerialStreamBuf::Implementation::uflow()
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
int_type next_char = underflow() ;
mPutbackAvailable = false;
return next_char;
}
inline
std::streambuf::int_type
SerialStreamBuf::Implementation::pbackfail(const int_type character)
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
// If a putback character is already available, then we cannot
// do any more putback and hence need to return eof.
if (mPutbackAvailable)
{
return traits_type::eof() ;
}
if (traits_type::eq_int_type(character, traits_type::eof()))
{
// If an eof character is passed in, then we are required to
// backup one character. However, we cannot do this for a serial
// port. Hence we return eof to signal an error.
return traits_type::eof() ;
}
//
// If no putback character is available at present, then make
// "character" the putback character and return it.
mPutbackChar = traits_type::to_char_type(character) ;
mPutbackAvailable = true ;
return traits_type::not_eof(character) ;
}
inline
std::streamsize
SerialStreamBuf::Implementation::showmanyc()
{
// Throw an exception if the serial port is not open.
if (!this->IsOpen())
{
throw NotOpen(ERR_MSG_PORT_NOT_OPEN) ;
}
ssize_t number_of_bytes_available = 0 ;
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg)
//
// :TODO: Consider using a method of SerialPort class here instead
// of using the file descriptor.
const auto fd = mSerialPort.GetFileDescriptor() ;
const auto result = call_with_retry(ioctl,
fd,
FIONREAD,
&number_of_bytes_available) ;
if ((result >= 0) and (number_of_bytes_available > 0))
{
mPutbackAvailable = true ;
}
return number_of_bytes_available;
}
} // namespace LibSerial
LibSerial::AlreadyOpen
Exception error thrown when the serial port is already open.
Definition SerialPortConstants.h:141
LibSerial::NotOpen
Exception error thrown when the serial port is not open.
Definition SerialPortConstants.h:126
LibSerial::OpenFailed
Exception error thrown when the serial port could not be opened.
Definition SerialPortConstants.h:156
LibSerial::SerialPort
SerialPort allows an object oriented approach to serial port communication. A serial port object can ...
Definition SerialPort.h:56
LibSerial::SerialStreamBuf::Implementation
SerialStreamBuf::Implementation is the SerialStreamBuf implementation class.
Definition SerialStreamBuf.cpp:49
LibSerial::SerialStreamBuf::Implementation::SetRTS
void SetRTS(const bool rtsState)
Sets the serial port RTS line status.
Definition SerialStreamBuf.cpp:890
LibSerial::SerialStreamBuf::Implementation::SetBaudRate
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
Definition SerialStreamBuf.cpp:778
LibSerial::SerialStreamBuf::Implementation::SetVMin
void SetVMin(const short vmin)
Sets the minimum number of characters for non-canonical reads.
Definition SerialStreamBuf.cpp:848
LibSerial::SerialStreamBuf::Implementation::GetRTS
bool GetRTS() const
Gets the serial port RTS line status.
Definition SerialStreamBuf.cpp:897
LibSerial::SerialStreamBuf::Implementation::GetStopBits
StopBits GetStopBits() const
Gets the number of stop bits currently being used by the serial.
Definition SerialStreamBuf.cpp:841
LibSerial::SerialStreamBuf::Implementation::~Implementation
~Implementation()
Default Destructor.
Definition SerialStreamBuf.cpp:675
LibSerial::SerialStreamBuf::Implementation::operator=
Implementation & operator=(const Implementation &otherImplementation)=delete
Copy assignment is disallowed.
LibSerial::SerialStreamBuf::Implementation::xsgetn
std::streamsize xsgetn(char_type *character, std::streamsize numberOfBytes)
Reads up to n characters from the serial port and returns them through the character array located at...
Definition SerialStreamBuf.cpp:975
LibSerial::SerialStreamBuf::Implementation::SetFlowControl
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
Definition SerialStreamBuf.cpp:806
LibSerial::SerialStreamBuf::Implementation::IsDataAvailable
bool IsDataAvailable()
Determines if data is available at the serial port.
Definition SerialStreamBuf.cpp:764
LibSerial::SerialStreamBuf::Implementation::xsputn
std::streamsize xsputn(const char_type *character, std::streamsize numberOfBytes)
Writes up to n characters from the character sequence at char s to the serial port associated with th...
Definition SerialStreamBuf.cpp:941
LibSerial::SerialStreamBuf::Implementation::FlushIOBuffers
void FlushIOBuffers()
Flushes the serial port input and output buffers.
Definition SerialStreamBuf.cpp:750
LibSerial::SerialStreamBuf::Implementation::uflow
std::streambuf::int_type uflow()
Reads and returns the next character from the associated serial port if one otherwise returns traits:...
Definition SerialStreamBuf.cpp:1148
LibSerial::SerialStreamBuf::Implementation::GetCharacterSize
CharacterSize GetCharacterSize() const
Gets the character size being used for serial communication.
Definition SerialStreamBuf.cpp:799
LibSerial::SerialStreamBuf::Implementation::GetBaudRate
BaudRate GetBaudRate() const
Gets the current baud rate for the serial port.
Definition SerialStreamBuf.cpp:785
LibSerial::SerialStreamBuf::Implementation::DrainWriteBuffer
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
Definition SerialStreamBuf.cpp:729
LibSerial::SerialStreamBuf::Implementation::Implementation
Implementation()=default
Default Constructor.
LibSerial::SerialStreamBuf::Implementation::SetVTime
void SetVTime(const short vtime)
Sets character buffer timeout for non-canonical reads in deciseconds.
Definition SerialStreamBuf.cpp:862
LibSerial::SerialStreamBuf::Implementation::Close
void Close()
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed...
Definition SerialStreamBuf.cpp:722
LibSerial::SerialStreamBuf::Implementation::SetDTR
void SetDTR(const bool dtrState)
Sets the serial port DTR line status.
Definition SerialStreamBuf.cpp:876
LibSerial::SerialStreamBuf::Implementation::GetNumberOfBytesAvailable
int GetNumberOfBytesAvailable()
Gets the number of bytes available in the read buffer.
Definition SerialStreamBuf.cpp:925
LibSerial::SerialStreamBuf::Implementation::GetCTS
bool GetCTS()
Gets the serial port CTS line status.
Definition SerialStreamBuf.cpp:904
LibSerial::SerialStreamBuf::Implementation::GetFlowControl
FlowControl GetFlowControl() const
Get the current flow control setting.
Definition SerialStreamBuf.cpp:813
LibSerial::SerialStreamBuf::Implementation::overflow
std::streambuf::int_type overflow(int_type character)
Writes the specified character to the associated serial port.
Definition SerialStreamBuf.cpp:1056
LibSerial::SerialStreamBuf::Implementation::GetFileDescriptor
int GetFileDescriptor() const
Gets the serial port file descriptor.
Definition SerialStreamBuf.cpp:918
LibSerial::SerialStreamBuf::Implementation::pbackfail
std::streambuf::int_type pbackfail(int_type character)
This function is called when a putback of a character fails. This must be implemented for unbuffered ...
Definition SerialStreamBuf.cpp:1165
LibSerial::SerialStreamBuf::Implementation::mPutbackAvailable
bool mPutbackAvailable
True if a putback value is available in mPutbackChar.
Definition SerialStreamBuf.cpp:363
LibSerial::SerialStreamBuf::Implementation::GetVMin
short GetVMin() const
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonic...
Definition SerialStreamBuf.cpp:855
LibSerial::SerialStreamBuf::Implementation::underflow
std::streambuf::int_type underflow()
Reads and returns the next character from the associated serial port if one otherwise returns traits:...
Definition SerialStreamBuf.cpp:1091
LibSerial::SerialStreamBuf::Implementation::GetDTR
bool GetDTR() const
Gets the serial port DTR line status.
Definition SerialStreamBuf.cpp:883
LibSerial::SerialStreamBuf::Implementation::SetParity
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.
Definition SerialStreamBuf.cpp:820
LibSerial::SerialStreamBuf::Implementation::GetDSR
bool GetDSR()
Gets the serial port DSR line status.
Definition SerialStreamBuf.cpp:911
LibSerial::SerialStreamBuf::Implementation::Implementation
Implementation(const Implementation &otherImplementation)=delete
Copy construction is disallowed.
LibSerial::SerialStreamBuf::Implementation::operator=
Implementation & operator=(const Implementation &&otherImplementation)=delete
Move assignment is disallowed.
LibSerial::SerialStreamBuf::Implementation::mPutbackChar
char mPutbackChar
We use unbuffered I/O for the serial port. However, we need to provide the putback of at least one ch...
Definition SerialStreamBuf.cpp:372
LibSerial::SerialStreamBuf::Implementation::FlushOutputBuffer
void FlushOutputBuffer()
Flushes the serial port output buffer.
Definition SerialStreamBuf.cpp:743
LibSerial::SerialStreamBuf::Implementation::SetCharacterSize
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
Definition SerialStreamBuf.cpp:792
LibSerial::SerialStreamBuf::Implementation::Open
void Open(const std::string &fileName, const std::ios_base::openmode &openMode)
Opens the serial port associated with the specified file name and the specified mode.
Definition SerialStreamBuf.cpp:697
LibSerial::SerialStreamBuf::Implementation::SetStopBits
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.
Definition SerialStreamBuf.cpp:834
LibSerial::SerialStreamBuf::Implementation::Implementation
Implementation(const Implementation &&otherImplementation)=delete
Move construction is disallowed.
LibSerial::SerialStreamBuf::Implementation::IsOpen
bool IsOpen() const
Determines if the serial port is open for I/O.
Definition SerialStreamBuf.cpp:757
LibSerial::SerialStreamBuf::Implementation::GetVTime
short GetVTime() const
Gets the current timeout value for non-canonical reads in deciseconds.
Definition SerialStreamBuf.cpp:869
LibSerial::SerialStreamBuf::Implementation::showmanyc
std::streamsize showmanyc()
Checks whether input is available on the port.
Definition SerialStreamBuf.cpp:1196
LibSerial::SerialStreamBuf::Implementation::FlushInputBuffer
void FlushInputBuffer()
Flushes the serial port input buffer.
Definition SerialStreamBuf.cpp:736
LibSerial::SerialStreamBuf::Implementation::SetDefaultSerialPortParameters
void SetDefaultSerialPortParameters()
Sets all serial port paramters to their default values.
Definition SerialStreamBuf.cpp:771
LibSerial::SerialStreamBuf::Implementation::GetParity
Parity GetParity() const
Gets the parity type for the serial port.
Definition SerialStreamBuf.cpp:827
LibSerial::SerialStreamBuf::GetCharacterSize
CharacterSize GetCharacterSize() const
Gets the character size being used for serial communication.
Definition SerialStreamBuf.cpp:481
LibSerial::SerialStreamBuf::GetCTS
bool GetCTS()
Get the status of the CTS line.
Definition SerialStreamBuf.cpp:571
LibSerial::SerialStreamBuf::IsOpen
bool IsOpen() const
Determines if the serial port is open for I/O.
Definition SerialStreamBuf.cpp:451
LibSerial::SerialStreamBuf::~SerialStreamBuf
virtual ~SerialStreamBuf()
Default Destructor for a SerialStreamBuf object. Closes the serial port associated with mFileDescript...
LibSerial::SerialStreamBuf::setbuf
virtual std::streambuf * setbuf(char_type *character, std::streamsize numberOfBytes) override
Performs an operation that is defined separately for each class derived from streambuf....
Definition SerialStreamBuf.cpp:603
LibSerial::SerialStreamBuf::GetNumberOfBytesAvailable
int GetNumberOfBytesAvailable()
Gets the number of bytes available in the read buffer.
Definition SerialStreamBuf.cpp:589
LibSerial::SerialStreamBuf::showmanyc
virtual std::streamsize showmanyc() override
Checks whether input is available on the port. If you call SerialStream::in_avail,...
Definition SerialStreamBuf.cpp:645
LibSerial::SerialStreamBuf::overflow
virtual int_type overflow(const int_type character) override
Writes the specified character to the associated serial port.
Definition SerialStreamBuf.cpp:621
LibSerial::SerialStreamBuf::IsDataAvailable
bool IsDataAvailable()
Checks if data is available at the input of the serial port.
Definition SerialStreamBuf.cpp:445
LibSerial::SerialStreamBuf::pbackfail
virtual int_type pbackfail(const int_type character) override
This function is called when a putback of a character fails. This must be implemented for unbuffered ...
Definition SerialStreamBuf.cpp:639
LibSerial::SerialStreamBuf::SerialStreamBuf
SerialStreamBuf()
Default Constructor.
Definition SerialStreamBuf.cpp:382
LibSerial::SerialStreamBuf::FlushOutputBuffer
void FlushOutputBuffer()
Flushes the serial port output buffer.
Definition SerialStreamBuf.cpp:433
LibSerial::SerialStreamBuf::xsgetn
virtual std::streamsize xsgetn(char_type *character, std::streamsize numberOfBytes) override
Reads up to n characters from the serial port and returns them through the character array located at...
Definition SerialStreamBuf.cpp:615
LibSerial::SerialStreamBuf::SetDefaultSerialPortParameters
void SetDefaultSerialPortParameters()
Sets all serial port paramters to their default values.
Definition SerialStreamBuf.cpp:457
LibSerial::SerialStreamBuf::Open
void Open(const std::string &fileName, const std::ios_base::openmode &openMode=std::ios_base::in|std::ios_base::out)
Opens the serial port associated with the specified file name and the specified mode.
Definition SerialStreamBuf.cpp:407
LibSerial::SerialStreamBuf::GetStopBits
StopBits GetStopBits() const
Gets the number of stop bits currently being used by the serial.
Definition SerialStreamBuf.cpp:517
LibSerial::SerialStreamBuf::SetDTR
void SetDTR(const bool dtrState=true)
Sets the DTR line to the specified value.
Definition SerialStreamBuf.cpp:547
LibSerial::SerialStreamBuf::GetVMin
short GetVMin() const
Gets the VMIN value for the device, which represents the minimum number of characters for non-canonic...
Definition SerialStreamBuf.cpp:529
LibSerial::SerialStreamBuf::GetDSR
bool GetDSR()
Get the status of the DSR line.
Definition SerialStreamBuf.cpp:577
LibSerial::SerialStreamBuf::xsputn
virtual std::streamsize xsputn(const char_type *character, std::streamsize numberOfBytes) override
Writes up to n characters from the character sequence at char s to the serial port associated with th...
Definition SerialStreamBuf.cpp:609
LibSerial::SerialStreamBuf::SetVTime
void SetVTime(const short vtime)
Sets character buffer timeout for non-canonical reads in deciseconds.
Definition SerialStreamBuf.cpp:535
LibSerial::SerialStreamBuf::GetRTS
bool GetRTS() const
Get the status of the RTS line.
Definition SerialStreamBuf.cpp:565
LibSerial::SerialStreamBuf::underflow
virtual int_type underflow() override
Reads and returns the next character from the associated serial port if one otherwise returns traits:...
Definition SerialStreamBuf.cpp:627
LibSerial::SerialStreamBuf::GetVTime
short GetVTime() const
Gets the current timeout value for non-canonical reads in deciseconds.
Definition SerialStreamBuf.cpp:541
LibSerial::SerialStreamBuf::GetDTR
bool GetDTR() const
Gets the status of the DTR line.
Definition SerialStreamBuf.cpp:553
LibSerial::SerialStreamBuf::SetCharacterSize
void SetCharacterSize(const CharacterSize &characterSize)
Sets the character size for the serial port.
Definition SerialStreamBuf.cpp:475
LibSerial::SerialStreamBuf::SetVMin
void SetVMin(const short vmin)
Sets the minimum number of characters for non-canonical reads.
Definition SerialStreamBuf.cpp:523
LibSerial::SerialStreamBuf::GetFlowControl
FlowControl GetFlowControl() const
Gets the current flow control setting.
Definition SerialStreamBuf.cpp:493
LibSerial::SerialStreamBuf::DrainWriteBuffer
void DrainWriteBuffer()
Waits until the write buffer is drained and then returns.
Definition SerialStreamBuf.cpp:421
LibSerial::SerialStreamBuf::Close
void Close()
Closes the serial port. All settings of the serial port will be lost and no more I/O can be performed...
Definition SerialStreamBuf.cpp:415
LibSerial::SerialStreamBuf::GetBaudRate
BaudRate GetBaudRate() const
Gets the current baud rate for the serial port.
Definition SerialStreamBuf.cpp:469
LibSerial::SerialStreamBuf::SetParity
void SetParity(const Parity &parityType)
Sets the parity type for the serial port.
Definition SerialStreamBuf.cpp:499
LibSerial::SerialStreamBuf::SetBaudRate
void SetBaudRate(const BaudRate &baudRate)
Sets the baud rate for the serial port to the specified value.
Definition SerialStreamBuf.cpp:463
LibSerial::SerialStreamBuf::GetParity
Parity GetParity() const
Gets the parity type for the serial port.
Definition SerialStreamBuf.cpp:505
LibSerial::SerialStreamBuf::FlushIOBuffers
void FlushIOBuffers()
Flushes the serial port input and output buffers.
Definition SerialStreamBuf.cpp:439
LibSerial::SerialStreamBuf::SetFlowControl
void SetFlowControl(const FlowControl &flowControlType)
Sets flow control for the serial port.
Definition SerialStreamBuf.cpp:487
LibSerial::SerialStreamBuf::FlushInputBuffer
void FlushInputBuffer()
Flushes the serial port input buffer.
Definition SerialStreamBuf.cpp:427
LibSerial::SerialStreamBuf::GetFileDescriptor
int GetFileDescriptor() const
Gets the serial port file descriptor.
Definition SerialStreamBuf.cpp:583
LibSerial::SerialStreamBuf::SetStopBits
void SetStopBits(const StopBits &stopBits)
Sets the number of stop bits to be used with the serial port.
Definition SerialStreamBuf.cpp:511
LibSerial::SerialStreamBuf::SetRTS
void SetRTS(const bool rtsState=true)
Set the RTS line to the specified value.
Definition SerialStreamBuf.cpp:559
LibSerial::SerialStreamBuf::uflow
virtual int_type uflow() override
Reads and returns the next character from the associated serial port if one otherwise returns traits:...
Definition SerialStreamBuf.cpp:633