Serial Studio 1.1.6
A dashboard software for your embedded projects
|
#include <Manager.h>
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 Manager & | instance () |
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 | |
Manager & | operator= (Manager &&)=delete |
Manager & | operator= (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 |
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:
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.
|
strong |
|
strong |
|
explicitprivate |
Constructor function
|
privatedelete |
|
privatedelete |
|
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.
|
signal |
bool IO::Manager::configurationOk | ( | ) | const |
Returns true
if we are able to connect to a device/port with the current config.
|
slot |
Closes the currently selected device and tries to open & configure a new connection. A data source must be selected before calling this function.
bool IO::Manager::connected | ( | ) |
|
signal |
|
signal |
|
signal |
IO::Manager::DataSource IO::Manager::dataSource | ( | ) | const |
Returns the currently selected data source, possible return values:
DataSource::Serial
use a serial port as a data sourceDataSource::Network
use a network port as a data source
|
signal |
StringList IO::Manager::dataSourcesList | ( | ) | const |
Returns a list with the possible data source options.
QIODevice * IO::Manager::device | ( | ) |
Returns a pointer to the currently selected device.
Q_NULLPTR
value during normal operations. bool IO::Manager::deviceAvailable | ( | ) |
|
signal |
|
slot |
Disconnects from the current device and clears temp. data
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.
|
signal |
|
signal |
|
signal |
|
static |
Returns the only instance of the class
|
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.
frame | data in which we shall perform integrity checks |
cursor | master buffer, should start with checksum type header |
bytes | pointer to the number of bytes that we need to chop from the master buffer |
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).
|
signal |
|
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.
|
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.
|
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
bool IO::Manager::readOnly | ( | ) |
bool IO::Manager::readWrite | ( | ) |
|
signal |
QString IO::Manager::separatorSequence | ( | ) | const |
Returns the separator sequence string used by the application to know where to consider that a data item ends.
|
signal |
|
slot |
Changes the data source type. Check the dataSource()
funciton for more information.
|
privateslot |
Changes the target device pointer. Deletion should be handled by the interface implementation, not by this class.
|
slot |
Changes the frame end sequence. Check the finishSequence()
function for more information.
|
slot |
Changes the maximum permited buffer size. Check the maxBufferSize()
function for more information.
|
slot |
Changes the frame separator sequence. Check the separatorSequence()
function for more information.
|
slot |
Changes the frame start sequence. Check the startSequence()
function for more information.
|
slot |
Enables/disables RW mode
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.
|
signal |
|
slot |
Connects/disconnects the application from the currently selected device. This function is used as a convenience for the connect/disconnect button.
qint64 IO::Manager::writeData | ( | const QByteArray & | data | ) |
Tries to write the given data to the current device.
|
signal |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
read |
|
read |
Returns true
if a device is currently selected and opened or if the MQTT client is currently connected as a subscriber.
|
readwrite |
|
read |
Returns true
if a device is currently selected
|
readwrite |
|
read |
Returns true
if a device is connected and its open in read-only mode
|
read |
Returns true
if a device is connected and its open in read/write mode
|
readwrite |
|
readwrite |