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

The Manager class. More...

#include <Manager.h>

Inheritance diagram for IO::Manager:
Inheritance graph
Collaboration diagram for IO::Manager:
Collaboration graph

Public Types

enum class  DataSource { Serial , Network }
 
enum class  ValidationStatus { FrameOk , ChecksumError , ChecksumIncomplete }
 

Public Slots

void connectDevice ()
 
void toggleConnection ()
 
void disconnectDevice ()
 
void setWriteEnabled (const bool enabled)
 
void processPayload (const QByteArray &payload)
 
void setMaxBufferSize (const int maxBufferSize)
 
void setStartSequence (const QString &sequence)
 
void setFinishSequence (const QString &sequence)
 
void setSeparatorSequence (const QString &sequence)
 
void setDataSource (const IO::Manager::DataSource &source)
 

Signals

void deviceChanged ()
 
void connectedChanged ()
 
void dataSourceChanged ()
 
void writeEnabledChanged ()
 
void configurationChanged ()
 
void receivedBytesChanged ()
 
void maxBufferSizeChanged ()
 
void startSequenceChanged ()
 
void finishSequenceChanged ()
 
void separatorSequenceChanged ()
 
void frameValidationRegexChanged ()
 
void dataSent (const QByteArray &data)
 
void dataReceived (const QByteArray &data)
 
void frameReceived (const QByteArray &frame)
 

Public Member Functions

bool readOnly ()
 
bool readWrite ()
 
bool connected ()
 
bool deviceAvailable ()
 
bool configurationOk () const
 
int maxBufferSize () const
 
QIODevice * device ()
 
DataSource dataSource () const
 
QString startSequence () const
 
QString finishSequence () const
 
QString separatorSequence () const
 
Q_INVOKABLE StringList dataSourcesList () const
 
Q_INVOKABLE qint64 writeData (const QByteArray &data)
 

Static Public Member Functions

static Managerinstance ()
 

Properties

bool readOnly
 
bool readWrite
 
bool connected
 
bool deviceAvailable
 
IO::Manager::DataSource dataSource
 
QString startSequence
 
QString finishSequence
 
QString separatorSequence
 
bool configurationOk
 

Private Slots

void readFrames ()
 
void onDataReceived ()
 
void clearTempBuffer ()
 
void setDevice (QIODevice *device)
 

Private Member Functions

 Manager ()
 
 Manager (Manager &&)=delete
 
 Manager (const Manager &)=delete
 
Manageroperator= (Manager &&)=delete
 
Manageroperator= (const Manager &)=delete
 
ValidationStatus integrityChecks (const QByteArray &frame, const QByteArray &masterBuffer, int *bytesToChop)
 

Private Attributes

bool m_enableCrc
 
bool m_writeEnabled
 
int m_maxBufferSize
 
QIODevice * m_device
 
DataSource m_dataSource
 
QByteArray m_dataBuffer
 
quint64 m_receivedBytes
 
QString m_startSequence
 
QString m_finishSequence
 
QString m_separatorSequence
 

Detailed Description

The Manager class.

The I/O Manager class provides an abstraction layer between the physical device (e.g. a serial or network port) and the rest of the application.

Additionaly, all frame parsing, checksum verification and data processing is done directly by this class. In this way, programmers can focus on implementing the code to read and write data to a device, while the manager class deals with the processing of the received data and generates frames.

A "frame" is equivalent to a packet of data. To identify frames, the manager class needs to know three things:

  • The start sequence or header of the frame
  • The end sequence or footer of the frame
  • The data separator sequence, which allows Serial Studio to differentiate between a dataset value and another dataset value.

Example of a frame:

$A,B,C,D,E,F,G;

In this case, the start sequence of the frame is "$", while the end sequence is ";". The data separator sequence is ",". Knowing this, Serial Studio can process the frame and deduce that A,B,C,D,E,F and G are individual dataset values.

Member Enumeration Documentation

◆ DataSource

enum class IO::Manager::DataSource
strong
Enumerator
Serial 
Network 

◆ ValidationStatus

enum class IO::Manager::ValidationStatus
strong
Enumerator
FrameOk 
ChecksumError 
ChecksumIncomplete 

Constructor & Destructor Documentation

◆ Manager() [1/3]

IO::Manager::Manager ( )
explicitprivate

Constructor function

◆ Manager() [2/3]

IO::Manager::Manager ( Manager &&  )
privatedelete

◆ Manager() [3/3]

IO::Manager::Manager ( const Manager )
privatedelete

Member Function Documentation

◆ clearTempBuffer

void IO::Manager::clearTempBuffer ( )
privateslot

Deletes the contents of the temporary buffer. This function is called automatically by the class when the temporary buffer size exceeds the limit imposed by the maxBufferSize() function.

◆ configurationChanged

void IO::Manager::configurationChanged ( )
signal

◆ configurationOk()

bool IO::Manager::configurationOk ( ) const

Returns true if we are able to connect to a device/port with the current config.

◆ connectDevice

void IO::Manager::connectDevice ( )
slot

Closes the currently selected device and tries to open & configure a new connection. A data source must be selected before calling this function.

◆ connected()

bool IO::Manager::connected ( )

◆ connectedChanged

void IO::Manager::connectedChanged ( )
signal

◆ dataReceived

void IO::Manager::dataReceived ( const QByteArray &  data)
signal

◆ dataSent

void IO::Manager::dataSent ( const QByteArray &  data)
signal

◆ dataSource()

IO::Manager::DataSource IO::Manager::dataSource ( ) const

Returns the currently selected data source, possible return values:

◆ dataSourceChanged

void IO::Manager::dataSourceChanged ( )
signal

◆ dataSourcesList()

StringList IO::Manager::dataSourcesList ( ) const

Returns a list with the possible data source options.

◆ device()

QIODevice * IO::Manager::device ( )

Returns a pointer to the currently selected device.

Warning
you need to check this pointer before using it, it can have a Q_NULLPTR value during normal operations.

◆ deviceAvailable()

bool IO::Manager::deviceAvailable ( )

◆ deviceChanged

void IO::Manager::deviceChanged ( )
signal

◆ disconnectDevice

void IO::Manager::disconnectDevice ( )
slot

Disconnects from the current device and clears temp. data

◆ finishSequence()

QString IO::Manager::finishSequence ( ) const

Returns the finish sequence string used by the application to know where to consider that a frame ends. If the start sequence is empty, then the application shall ignore incoming data. The only thing that wont ignore the incoming data will be the console.

◆ finishSequenceChanged

void IO::Manager::finishSequenceChanged ( )
signal

◆ frameReceived

void IO::Manager::frameReceived ( const QByteArray &  frame)
signal

◆ frameValidationRegexChanged

void IO::Manager::frameValidationRegexChanged ( )
signal

◆ instance()

IO::Manager & IO::Manager::instance ( )
static

Returns the only instance of the class

◆ integrityChecks()

IO::Manager::ValidationStatus IO::Manager::integrityChecks ( const QByteArray &  frame,
const QByteArray &  cursor,
int *  bytes 
)
private

Checks if the cursor has a checksum corresponding to the given frame. If so, the function shall calculate the appropiate checksum to for the frame and compare it with the received checksum to verify the integrity of received data.

Parameters
framedata in which we shall perform integrity checks
cursormaster buffer, should start with checksum type header
bytespointer to the number of bytes that we need to chop from the master buffer

◆ maxBufferSize()

int IO::Manager::maxBufferSize ( ) const

Returns the maximum size of the buffer. This is useful to avoid consuming to much memory when a large block of invalid data is received (for example, when the user selects an invalid baud rate configuration).

◆ maxBufferSizeChanged

void IO::Manager::maxBufferSizeChanged ( )
signal

◆ onDataReceived

void IO::Manager::onDataReceived ( )
privateslot

Reads incoming data from the serial device, updates the serial console object, registers incoming data to temporary buffer & extracts valid data frames from the buffer using the readFrame() function.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ processPayload

void IO::Manager::processPayload ( const QByteArray &  payload)
slot

Reads the given payload and emits it as if it were received from a device. This function is for convenience to interact with other application modules & plugins.

◆ readFrames

void IO::Manager::readFrames ( )
privateslot

Read frames from temporary buffer, every frame that contains the appropiate start/end sequence is removed from the buffer as soon as its read.

This function also checks that the buffer size does not exceed specified size limitations.

Implemementation credits: @jpnorair and @alex-spataru

◆ readOnly()

bool IO::Manager::readOnly ( )

◆ readWrite()

bool IO::Manager::readWrite ( )

◆ receivedBytesChanged

void IO::Manager::receivedBytesChanged ( )
signal

◆ separatorSequence()

QString IO::Manager::separatorSequence ( ) const

Returns the separator sequence string used by the application to know where to consider that a data item ends.

◆ separatorSequenceChanged

void IO::Manager::separatorSequenceChanged ( )
signal

◆ setDataSource

void IO::Manager::setDataSource ( const IO::Manager::DataSource source)
slot

Changes the data source type. Check the dataSource() funciton for more information.

◆ setDevice

void IO::Manager::setDevice ( QIODevice *  device)
privateslot

Changes the target device pointer. Deletion should be handled by the interface implementation, not by this class.

◆ setFinishSequence

void IO::Manager::setFinishSequence ( const QString &  sequence)
slot

Changes the frame end sequence. Check the finishSequence() function for more information.

◆ setMaxBufferSize

void IO::Manager::setMaxBufferSize ( const int  maxBufferSize)
slot

Changes the maximum permited buffer size. Check the maxBufferSize() function for more information.

◆ setSeparatorSequence

void IO::Manager::setSeparatorSequence ( const QString &  sequence)
slot

Changes the frame separator sequence. Check the separatorSequence() function for more information.

◆ setStartSequence

void IO::Manager::setStartSequence ( const QString &  sequence)
slot

Changes the frame start sequence. Check the startSequence() function for more information.

◆ setWriteEnabled

void IO::Manager::setWriteEnabled ( const bool  enabled)
slot

Enables/disables RW mode

◆ startSequence()

QString IO::Manager::startSequence ( ) const

Returns the start sequence string used by the application to know where to consider that a frame begins. If the start sequence is empty, then the application shall ignore incoming data. The only thing that wont ignore the incoming data will be the console.

◆ startSequenceChanged

void IO::Manager::startSequenceChanged ( )
signal

◆ toggleConnection

void IO::Manager::toggleConnection ( )
slot

Connects/disconnects the application from the currently selected device. This function is used as a convenience for the connect/disconnect button.

◆ writeData()

qint64 IO::Manager::writeData ( const QByteArray &  data)

Tries to write the given data to the current device.

Returns
the number of bytes written to the target device

◆ writeEnabledChanged

void IO::Manager::writeEnabledChanged ( )
signal

Member Data Documentation

◆ m_dataBuffer

QByteArray IO::Manager::m_dataBuffer
private

◆ m_dataSource

DataSource IO::Manager::m_dataSource
private

◆ m_device

QIODevice* IO::Manager::m_device
private

◆ m_enableCrc

bool IO::Manager::m_enableCrc
private

◆ m_finishSequence

QString IO::Manager::m_finishSequence
private

◆ m_maxBufferSize

int IO::Manager::m_maxBufferSize
private

◆ m_receivedBytes

quint64 IO::Manager::m_receivedBytes
private

◆ m_separatorSequence

QString IO::Manager::m_separatorSequence
private

◆ m_startSequence

QString IO::Manager::m_startSequence
private

◆ m_writeEnabled

bool IO::Manager::m_writeEnabled
private

Property Documentation

◆ configurationOk

bool IO::Manager::configurationOk
read

◆ connected

bool IO::Manager::connected
read

Returns true if a device is currently selected and opened or if the MQTT client is currently connected as a subscriber.

◆ dataSource

IO::Manager::DataSource IO::Manager::dataSource
readwrite

◆ deviceAvailable

bool IO::Manager::deviceAvailable
read

Returns true if a device is currently selected

◆ finishSequence

QString IO::Manager::finishSequence
readwrite

◆ readOnly

bool IO::Manager::readOnly
read

Returns true if a device is connected and its open in read-only mode

◆ readWrite

bool IO::Manager::readWrite
read

Returns true if a device is connected and its open in read/write mode

◆ separatorSequence

QString IO::Manager::separatorSequence
readwrite

◆ startSequence

QString IO::Manager::startSequence
readwrite

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