Serial Studio 1.1.6
A dashboard software for your embedded projects
IO::Console Class Reference

The Console class. More...

#include <Console.h>

Inheritance diagram for IO::Console:
Inheritance graph
Collaboration diagram for IO::Console:
Collaboration graph

Public Types

enum class  DisplayMode { DisplayPlainText , DisplayHexadecimal }
 
enum class  DataMode { DataUTF8 , DataHexadecimal }
 
enum class  LineEnding { NoLineEnding , NewLine , CarriageReturn , BothNewLineAndCarriageReturn }
 

Public Slots

void save ()
 
void clear ()
 
void historyUp ()
 
void historyDown ()
 
void send (const QString &data)
 
void setEcho (const bool enabled)
 
void print (const QString &fontFamily)
 
void setAutoscroll (const bool enabled)
 
void setShowTimestamp (const bool enabled)
 
void setDataMode (const IO::Console::DataMode &mode)
 
void setLineEnding (const IO::Console::LineEnding &mode)
 
void setDisplayMode (const IO::Console::DisplayMode &mode)
 
void append (const QString &str, const bool addTimestamp=false)
 

Signals

void echoChanged ()
 
void dataReceived ()
 
void dataModeChanged ()
 
void autoscrollChanged ()
 
void lineEndingChanged ()
 
void displayModeChanged ()
 
void historyItemChanged ()
 
void textDocumentChanged ()
 
void showTimestampChanged ()
 
void stringReceived (const QString &text)
 

Public Member Functions

bool echo () const
 
bool autoscroll () const
 
bool saveAvailable () const
 
bool showTimestamp () const
 
DataMode dataMode () const
 
LineEnding lineEnding () const
 
DisplayMode displayMode () const
 
QString currentHistoryString () const
 
Q_INVOKABLE StringList dataModes () const
 
Q_INVOKABLE StringList lineEndings () const
 
Q_INVOKABLE StringList displayModes () const
 
Q_INVOKABLE QString formatUserHex (const QString &text)
 

Static Public Member Functions

static Consoleinstance ()
 

Properties

bool echo
 
bool autoscroll
 
bool showTimestamp
 
bool saveAvailable
 
IO::Console::DataMode dataMode
 
IO::Console::LineEnding lineEnding
 
IO::Console::DisplayMode displayMode
 
QString currentHistoryString
 

Private Slots

void onDataSent (const QByteArray &data)
 
void addToHistory (const QString &command)
 
void onDataReceived (const QByteArray &data)
 

Private Member Functions

 Console ()
 
 Console (Console &&)=delete
 
 Console (const Console &)=delete
 
Consoleoperator= (Console &&)=delete
 
Consoleoperator= (const Console &)=delete
 
QByteArray hexToBytes (const QString &data)
 
QString dataToString (const QByteArray &data)
 
QString plainTextStr (const QByteArray &data)
 
QString hexadecimalStr (const QByteArray &data)
 

Private Attributes

DataMode m_dataMode
 
LineEnding m_lineEnding
 
DisplayMode m_displayMode
 
int m_historyItem
 
bool m_echo
 
bool m_autoscroll
 
bool m_showTimestamp
 
bool m_isStartingLine
 
StringList m_lines
 
StringList m_historyItems
 
QString m_printFont
 
QString m_textBuffer
 

Detailed Description

The Console class.

The console class receives data from the IO::Manager class and processes it so that it can be easily appended to a text edit widget.

The class also controls various UI-related factors, such as the display format of the data (e.g. ASCII or HEX), history of sent commands and exporting of the RX data.

Member Enumeration Documentation

◆ DataMode

enum class IO::Console::DataMode
strong
Enumerator
DataUTF8 
DataHexadecimal 

◆ DisplayMode

enum class IO::Console::DisplayMode
strong
Enumerator
DisplayPlainText 
DisplayHexadecimal 

◆ LineEnding

enum class IO::Console::LineEnding
strong
Enumerator
NoLineEnding 
NewLine 
CarriageReturn 
BothNewLineAndCarriageReturn 

Constructor & Destructor Documentation

◆ Console() [1/3]

IO::Console::Console ( )
explicitprivate

Constructor function

◆ Console() [2/3]

IO::Console::Console ( Console &&  )
privatedelete

◆ Console() [3/3]

IO::Console::Console ( const Console )
privatedelete

Member Function Documentation

◆ addToHistory

void IO::Console::addToHistory ( const QString &  command)
privateslot

Registers the given command to the list of sent commands.

◆ append

void IO::Console::append ( const QString &  string,
const bool  addTimestamp = false 
)
slot

Inserts the given string into the list of lines of the console, if addTimestamp is set to true, an timestamp is added for each line.

◆ autoscroll()

bool IO::Console::autoscroll ( ) const

Returns true if the vertical position of the console display shall be automatically moved to show latest data.

◆ autoscrollChanged

void IO::Console::autoscrollChanged ( )
signal

◆ clear

void IO::Console::clear ( )
slot

Deletes all the text displayed by the current QML text document

◆ currentHistoryString()

QString IO::Console::currentHistoryString ( ) const

Returns the current command history string selected by the user.

Note
the user can navigate through sent commands using the Up/Down keys on the keyboard. This behaviour is managed by the historyUp() & historyDown() functions.

◆ dataMode()

IO::Console::DataMode IO::Console::dataMode ( ) const

Returns the type of data that the user inputs to the console. There are two possible values:

  • DataMode::DataUTF8 the user is sending data formated in the UTF-8 codec.
  • DataMode::DataHexadecimal the user is sending binary data represented in hexadecimal format, we must do a conversion to obtain and send the appropiate binary data to the target device.

◆ dataModeChanged

void IO::Console::dataModeChanged ( )
signal

◆ dataModes()

StringList IO::Console::dataModes ( ) const

Returns a list with the available data (sending) modes. This list must be synchronized with the order of the DataMode enums.

◆ dataReceived

void IO::Console::dataReceived ( )
signal

◆ dataToString()

QString IO::Console::dataToString ( const QByteArray &  data)
private

Converts the given data to a string according to the console display mode set by the user.

◆ displayMode()

IO::Console::DisplayMode IO::Console::displayMode ( ) const

Returns the display format of the console. Posible values are:

◆ displayModeChanged

void IO::Console::displayModeChanged ( )
signal

◆ displayModes()

StringList IO::Console::displayModes ( ) const

Returns a list with the available console display modes. This list must be synchronized with the order of the DisplayMode enums.

◆ echo()

bool IO::Console::echo ( ) const

Returns true if the console shall display the commands that the user has sent to the serial/network device.

◆ echoChanged

void IO::Console::echoChanged ( )
signal

◆ formatUserHex()

QString IO::Console::formatUserHex ( const QString &  text)

Validates the given text and adds space to display the text in a byte-oriented view

◆ hexadecimalStr()

QString IO::Console::hexadecimalStr ( const QByteArray &  data)
private

Converts the given data into a HEX representation string.

◆ hexToBytes()

QByteArray IO::Console::hexToBytes ( const QString &  data)
private

Converts the given data in HEX format into real binary data.

◆ historyDown

void IO::Console::historyDown ( )
slot

Comamnds sent by the user are stored in a StringList, in which the first items are the oldest commands.

The user can navigate the list using the up/down keys. This function allows the user to navigate the list from oldst command to most recent command.

◆ historyItemChanged

void IO::Console::historyItemChanged ( )
signal

◆ historyUp

void IO::Console::historyUp ( )
slot

Comamnds sent by the user are stored in a StringList, in which the first items are the oldest commands.

The user can navigate the list using the up/down keys. This function allows the user to navigate the list from most recent command to oldest command.

◆ instance()

IO::Console & IO::Console::instance ( )
static

Returns the only instance of the class

◆ lineEnding()

IO::Console::LineEnding IO::Console::lineEnding ( ) const

Returns the line ending character that is added to each datablock sent by the user. Possible values are:

◆ lineEndingChanged

void IO::Console::lineEndingChanged ( )
signal

◆ lineEndings()

StringList IO::Console::lineEndings ( ) const

Returns a list with the available line endings options. This list must be synchronized with the order of the LineEnding enums.

◆ onDataReceived

void IO::Console::onDataReceived ( const QByteArray &  data)
privateslot

Displays the given data in the console

◆ onDataSent

void IO::Console::onDataSent ( const QByteArray &  data)
privateslot

Displays the given data in the console. QByteArray to ~QString conversion is done by the dataToString() function, which displays incoming data either in UTF-8 or in hexadecimal mode.

◆ operator=() [1/2]

Console & IO::Console::operator= ( Console &&  )
privatedelete

◆ operator=() [2/2]

Console & IO::Console::operator= ( const Console )
privatedelete

◆ plainTextStr()

QString IO::Console::plainTextStr ( const QByteArray &  data)
private

Converts the given data into an UTF-8 string

◆ print

void IO::Console::print ( const QString &  fontFamily)
slot

Creates a text document with current console output & prints it using native system libraries/toolkits.

Parameters
fontFamilythe font family to use to render the text document

◆ save

void IO::Console::save ( )
slot

Allows the user to export the information displayed on the console

◆ saveAvailable()

bool IO::Console::saveAvailable ( ) const

Returns true if data buffer contains information that the user can export.

◆ send

void IO::Console::send ( const QString &  data)
slot

Sends the given data to the currently connected device using the options specified by the user with the rest of the functions of this class.

Note
data is added to the history of sent commands, regardless if the data writing was successfull or not.

◆ setAutoscroll

void IO::Console::setAutoscroll ( const bool  enabled)
slot

Enables/disables autoscrolling of the console text.

◆ setDataMode

void IO::Console::setDataMode ( const IO::Console::DataMode mode)
slot

Changes the data mode for user commands. See dataMode() for more information.

◆ setDisplayMode

void IO::Console::setDisplayMode ( const IO::Console::DisplayMode mode)
slot

Changes the display mode of the console. See displayMode() for more information.

◆ setEcho

void IO::Console::setEcho ( const bool  enabled)
slot

Enables or disables displaying sent data in the console screen. See echo() for more information.

◆ setLineEnding

void IO::Console::setLineEnding ( const IO::Console::LineEnding mode)
slot

Changes line ending mode for sent user commands. See lineEnding() for more information.

◆ setShowTimestamp

void IO::Console::setShowTimestamp ( const bool  enabled)
slot

Enables/disables displaying a timestamp of each received data block.

◆ showTimestamp()

bool IO::Console::showTimestamp ( ) const

Returns true if a timestamp should be shown before each displayed data block.

◆ showTimestampChanged

void IO::Console::showTimestampChanged ( )
signal

◆ stringReceived

void IO::Console::stringReceived ( const QString &  text)
signal

◆ textDocumentChanged

void IO::Console::textDocumentChanged ( )
signal

Member Data Documentation

◆ m_autoscroll

bool IO::Console::m_autoscroll
private

◆ m_dataMode

DataMode IO::Console::m_dataMode
private

◆ m_displayMode

DisplayMode IO::Console::m_displayMode
private

◆ m_echo

bool IO::Console::m_echo
private

◆ m_historyItem

int IO::Console::m_historyItem
private

◆ m_historyItems

StringList IO::Console::m_historyItems
private

◆ m_isStartingLine

bool IO::Console::m_isStartingLine
private

◆ m_lineEnding

LineEnding IO::Console::m_lineEnding
private

◆ m_lines

StringList IO::Console::m_lines
private

◆ m_printFont

QString IO::Console::m_printFont
private

◆ m_showTimestamp

bool IO::Console::m_showTimestamp
private

◆ m_textBuffer

QString IO::Console::m_textBuffer
private

Property Documentation

◆ autoscroll

bool IO::Console::autoscroll
readwrite

◆ currentHistoryString

QString IO::Console::currentHistoryString
read

◆ dataMode

IO::Console::DataMode IO::Console::dataMode
readwrite

◆ displayMode

IO::Console::DisplayMode IO::Console::displayMode
readwrite

◆ echo

bool IO::Console::echo
readwrite

◆ lineEnding

IO::Console::LineEnding IO::Console::lineEnding
readwrite

◆ saveAvailable

bool IO::Console::saveAvailable
read

◆ showTimestamp

bool IO::Console::showTimestamp
readwrite

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