Instrument Neutral Distributed Interface INDI  2.0.2
Public Types | Public Member Functions | List of all members
TTYBase Class Reference

Base class for serial communications. More...

#include <ttybase.h>

Public Types

enum  TTY_RESPONSE {
  TTY_OK = 0 , TTY_READ_ERROR = -1 , TTY_WRITE_ERROR = -2 , TTY_SELECT_ERROR = -3 ,
  TTY_TIME_OUT = -4 , TTY_PORT_FAILURE = -5 , TTY_PARAM_ERROR = -6 , TTY_ERRNO = -7 ,
  TTY_OVERFLOW = -8
}
 

Public Member Functions

 TTYBase (const char *driverName)
 
virtual ~TTYBase ()
 
TTY_RESPONSE read (uint8_t *buffer, uint32_t nbytes, uint8_t timeout, uint32_t *nbytes_read)
 read buffer from terminal More...
 
TTY_RESPONSE readSection (uint8_t *buffer, uint32_t nsize, uint8_t stop_byte, uint8_t timeout, uint32_t *nbytes_read)
 read buffer from terminal with a delimiter More...
 
TTY_RESPONSE write (const uint8_t *buffer, uint32_t nbytes, uint32_t *nbytes_written)
 Writes a buffer to fd. More...
 
TTY_RESPONSE writeString (const char *string, uint32_t *nbytes_written)
 Writes a null terminated string to fd. More...
 
TTY_RESPONSE connect (const char *device, uint32_t bit_rate, uint8_t word_size, uint8_t parity, uint8_t stop_bits)
 Establishes a tty connection to a terminal device. More...
 
TTY_RESPONSE disconnect ()
 Closes a tty connection and flushes the bus. More...
 
void setDebug (INDI::Logger::VerbosityLevel channel)
 setDebug Enable or Disable debug logging More...
 
const std::string error (TTY_RESPONSE code) const
 Retrieve the tty error message. More...
 
int getPortFD () const
 

Detailed Description

Base class for serial communications.

This class is the C++ implementation of indicom serial functionality. Due to the idiosyncrasies of different serial implementation (including TCP/UDP), the base class methods can be overridden to provide specific implementations for a particular serial behavior.

It provides methods to connect to and disconnect from serial devices, including TCP/UDP connections.

Author
Jasem Mutlaq
Wildi Markus

Definition at line 42 of file ttybase.h.

Member Enumeration Documentation

◆ TTY_RESPONSE

Enumerator
TTY_OK 
TTY_READ_ERROR 
TTY_WRITE_ERROR 
TTY_SELECT_ERROR 
TTY_TIME_OUT 
TTY_PORT_FAILURE 
TTY_PARAM_ERROR 
TTY_ERRNO 
TTY_OVERFLOW 

Definition at line 45 of file ttybase.h.

Constructor & Destructor Documentation

◆ TTYBase()

TTYBase::TTYBase ( const char *  driverName)

Definition at line 73 of file ttybase.cpp.

◆ ~TTYBase()

TTYBase::~TTYBase ( )
virtual

Definition at line 78 of file ttybase.cpp.

Member Function Documentation

◆ connect()

TTYBase::TTY_RESPONSE TTYBase::connect ( const char *  device,
uint32_t  bit_rate,
uint8_t  word_size,
uint8_t  parity,
uint8_t  stop_bits 
)

Establishes a tty connection to a terminal device.

Parameters
devicethe device node. e.g. /dev/ttyS0
bit_ratebit rate
word_sizenumber of data bits, 7 or 8, USE 8 DATA BITS with modbus
parity0=no parity, 1=parity EVEN, 2=parity ODD
stop_bitsnumber of stop bits : 1 or 2
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 500 of file ttybase.cpp.

◆ disconnect()

TTYBase::TTY_RESPONSE TTYBase::disconnect ( )

Closes a tty connection and flushes the bus.

Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 688 of file ttybase.cpp.

◆ error()

const std::string TTYBase::error ( TTY_RESPONSE  code) const

Retrieve the tty error message.

Parameters
err_codethe error code return by any TTY function.
Returns
Error message string

Definition at line 706 of file ttybase.cpp.

◆ getPortFD()

int TTYBase::getPortFD ( ) const
inline

Definition at line 130 of file ttybase.h.

◆ read()

TTYBase::TTY_RESPONSE TTYBase::read ( uint8_t *  buffer,
uint32_t  nbytes,
uint8_t  timeout,
uint32_t *  nbytes_read 
)

read buffer from terminal

Parameters
fdfile descriptor
bufpointer to store data. Must be initialized and big enough to hold data.
nbytesnumber of bytes to read.
timeoutnumber of seconds to wait for terminal before a timeout error is issued.
nbytes_readthe number of bytes read.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 158 of file ttybase.cpp.

◆ readSection()

TTYBase::TTY_RESPONSE TTYBase::readSection ( uint8_t *  buffer,
uint32_t  nsize,
uint8_t  stop_byte,
uint8_t  timeout,
uint32_t *  nbytes_read 
)

read buffer from terminal with a delimiter

Parameters
fdfile descriptor
bufpointer to store data. Must be initilized and big enough to hold data.
stop_charif the function encounters stop_char then it stops reading and returns the buffer.
nsizesize of buf. If stop character is not encountered before nsize, the function aborts.
timeoutnumber of seconds to wait for terminal before a timeout error is issued.
nbytes_readthe number of bytes read.
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 202 of file ttybase.cpp.

◆ setDebug()

void TTYBase::setDebug ( INDI::Logger::VerbosityLevel  channel)

setDebug Enable or Disable debug logging

Parameters
enabledIf true, TTY traffic will be logged.
channelChannel from INDI logger to log to.
Warning
Only enable TTY debugging when diagnosting issues with serial communications. Due to the verbose traffic generated from serial data, this can have significant adverse effects on the function of the driver. Use with caution!

◆ write()

TTYBase::TTY_RESPONSE TTYBase::write ( const uint8_t *  buffer,
uint32_t  nbytes,
uint32_t *  nbytes_written 
)

Writes a buffer to fd.

Parameters
fdfile descriptor
buffera null-terminated buffer to write to fd.
nbytesnumber of bytes to write from buffer
nbytes_writtenthe number of bytes written
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 121 of file ttybase.cpp.

◆ writeString()

TTYBase::TTY_RESPONSE TTYBase::writeString ( const char *  string,
uint32_t *  nbytes_written 
)

Writes a null terminated string to fd.

Parameters
fdfile descriptor
bufferthe buffer to write to fd.
nbytes_writtenthe number of bytes written
Returns
On success, it returns TTY_OK, otherwise, a TTY_ERROR code.

Definition at line 152 of file ttybase.cpp.


The documentation for this class was generated from the following files: