Public Types | |
enum | Status { unknown, error, cmd_ok, ans_ok } |
Signals | |
void | status (bool bOpen, McuSerial::Status eStatus) |
Public Member Functions | |
bool | open (const QString &qsPort) |
void | close () |
bool | send (IMcuCmd *pCmd) |
bool | recv (IMcuAns *pAns, int nTimeout=200) |
void | flush () |
Static Public Member Functions | |
static void | msleep (int nMsecs) |
Static Private Member Functions | |
static QString | hex (const QByteArray &aData) |
Private Attributes | |
QextSerialPort * | m_pSerPort |
bool | m_bOpen |
Status | m_eStatus |
QString | m_qsLastCmd |
This class encapsulates the serial port that is used to talk to the MCU.
It provides methods for passing commands described by IMcuCmd derived classes to the MCU and filling in the received answers.
bool McuSerial::send | ( | IMcuCmd * | pCmd | ) |
Send command pCmd over serial line to MCU
Typically send() is followed by an immediate recv(). Except a few special cases, a flush() should be issued before send().
bool McuSerial::recv | ( | IMcuAns * | pAns, | |
int | nTimeout = 200 | |||
) |
Recieve answer pAns from MCU serial line
Typically recv() is called immediately after send().
Since the communication with QExtSerialPort seems to be very fragile when attempting to read more answer characters than available, an iterative approach is chosen:
void McuSerial::flush | ( | ) |
Flush serial receive queue.
For most commands, it is recommended to flush the receive queue befor sending a new command, to avoid stale answer bytes spoiling the real answer to this command.
There are exceptions where flushing is not wanted, i.e. while receiving a PEC table, where commands for reading each PEC value are issued and then all answers are read (for performance improvement).
void McuSerial::msleep | ( | int | nMsecs | ) | [static] |
Sleep nMsecs milliseconds
QString McuSerial::hex | ( | const QByteArray & | aData | ) | [static, private] |
Return binary data oData as hexdump and string of characters, with non-printable characters replaced by "."