StuBS
SerialStream Class Reference

Console (VT100 compatible) via Serial interface. More...

#include <serialstream.h>

Inheritance diagram for SerialStream:
Collaboration diagram for SerialStream:

Public Types

enum  Attrib {
  RESET = 0 , BRIGHT = 1 , DIM = 2 , UNDERSCORE = 4 ,
  BLINK = 5 , REVERSE = 7 , HIDDEN = 8
}
 Attributes can be used to influence the display of the output. More...
 
enum  Color
 Color codes. More...
 
- Public Types inherited from Serial
enum  ComPort
 COM-Port. More...
 
enum  BaudRate
 Transmission speed. More...
 
enum  DataBits
 Number of data bits per character.
 
enum  StopBits
 Number of stop bits per character.
 
enum  Parity
 parity bit
 

Public Member Functions

 SerialStream (ComPort port=COM1, BaudRate baud_rate=BAUD_115200, DataBits data_bits=DATA_8BIT, StopBits stop_bits=STOP_1BIT, Parity parity=PARITY_NONE)
 Constructor for the VT100-compatible console. More...
 
void flush () override
 Method to output the buffer contents of the base class Stringbuffer. More...
 
void setForeground (Color c)
 Change foreground color (for subsequent output) More...
 
void setBackground (Color c)
 Change background color (for subsequent output) More...
 
void setAttribute (Attrib a)
 Change text attribute (for subsequent output) More...
 
void reset ()
 Reset terminal. More...
 
void setPos (int x, int y)
 Set the cursor position. More...
 
void print (char *str, int length)
 Display multiple characters in the window starting at the current cursor position. More...
 
- Public Member Functions inherited from OutputStream
 OutputStream ()
 Default constructor. Initial number system is decimal.
 
virtual ~OutputStream ()
 Destructor.
 
OutputStreamoperator<< (char c)
 Print a single character. More...
 
OutputStreamoperator<< (unsigned char c)
 Print a single character. More...
 
OutputStreamoperator<< (const char *string)
 Printing a null-terminated string. More...
 
OutputStreamoperator<< (bool b)
 Print a boolean value. More...
 
OutputStreamoperator<< (short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned short ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned int ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (unsigned long long ival)
 Print an integral number in radix base. More...
 
OutputStreamoperator<< (const void *ptr)
 Print a pointer as hexadecimal number. More...
 
OutputStreamoperator<< (OutputStream &(*f)(OutputStream &))
 Calls one of the manipulator functions. More...
 
- Public Member Functions inherited from Stringbuffer
virtual ~Stringbuffer ()
 Destructor (nothing to do here)
 
- Public Member Functions inherited from Serial
 Serial (ComPort port=COM1, BaudRate baud_rate=BAUD_115200, DataBits data_bits=DATA_8BIT, StopBits stop_bits=STOP_1BIT, Parity parity=PARITY_NONE)
 Constructor. More...
 
int write (char out, bool blocking=true)
 Write one byte to the serial interface. More...
 

Private Member Functions

void write_number (int num)
 Helper to send a multi-digit number as human readable ASCII characters. More...
 

Additional Inherited Members

- Public Attributes inherited from OutputStream
int base
 Number system used for printing integral numbers (one of 2, 8, 10, or 16)
 
- Protected Member Functions inherited from Stringbuffer
 Stringbuffer ()
 Constructor; Marks the buffer as empty.
 
void put (char c)
 Inserts a character into the buffer. More...
 
- Protected Attributes inherited from Stringbuffer
char buffer [80+1]
 
long unsigned pos
 current position in the buffer
 
- Protected Attributes inherited from Serial
const ComPort port
 Selected COM port.
 

Detailed Description

Console (VT100 compatible) via Serial interface.

This class allows to connect a VT100-compatible display terminal via the serial interface.

The utility 'screen' can be used to attach a terminal to an interface at a specified connection speed: screen /dev/ttyS0 115200

Color and position can be adjusted with the help of escape codes.

Member Enumeration Documentation

◆ Attrib

Attributes can be used to influence the display of the output.

Note
The attributes might not be supported or have a different effect depending on the terminal emulator!
Enumerator
RESET 

Turn off character attributes.

BRIGHT 

Bold.

DIM 

Low intensity (dimmed)

UNDERSCORE 

Underline.

BLINK 

Blink (slow)

REVERSE 

Swap fore & background.

HIDDEN 

Concealed.

◆ Color

Color codes.

Default VT100 supports eight colors for both foreground and background (later versions 256 [8 bit] and even true color [32 bit]). The actual color is affected by the attributes and can look significantly different depending on the terminal emulator.

Constructor & Destructor Documentation

◆ SerialStream()

SerialStream::SerialStream ( ComPort  port = COM1,
BaudRate  baud_rate = BAUD_115200,
DataBits  data_bits = DATA_8BIT,
StopBits  stop_bits = STOP_1BIT,
Parity  parity = PARITY_NONE 
)
explicit

Constructor for the VT100-compatible console.

Sets up the serial connection as well

Member Function Documentation

◆ flush()

void SerialStream::flush ( )
overridevirtual

Method to output the buffer contents of the base class Stringbuffer.

The method is automatically called when the buffer is full, but can also be called explicitly to force output of the current buffer.

Implements OutputStream.

◆ print()

void SerialStream::print ( char *  str,
int  length 
)

Display multiple characters in the window starting at the current cursor position.

This method can be used to output a string, starting at the current cursor position. Since the string does not need to contain a '\0' termination (as it is usually the case in C), the parameter length is required to specify the number of characters in the string.

The text is displayed using the previously configured attributes, fore- and background color.

A line break will occur wherever the character \n is inserted in the text to be output (for compatibility reasons a \r is automatically appended).

Parameters
strString to output
lengthlength of string

◆ reset()

void SerialStream::reset ( )

Reset terminal.

Clear screen, place cursor at the beginning and reset colors and attributes to the default value.

◆ setAttribute()

void SerialStream::setAttribute ( Attrib  a)

Change text attribute (for subsequent output)

Parameters
aAttribute

◆ setBackground()

void SerialStream::setBackground ( Color  c)

Change background color (for subsequent output)

Parameters
cColor

◆ setForeground()

void SerialStream::setForeground ( Color  c)

Change foreground color (for subsequent output)

Parameters
cColor

◆ setPos()

void SerialStream::setPos ( int  x,
int  y 
)

Set the cursor position.

Parameters
xColumn in window
yRow in window

◆ write_number()

void SerialStream::write_number ( int  num)
private

Helper to send a multi-digit number as human readable ASCII characters.

Parameters
numNumber to send

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