|
SBB Host
Host communication with the self balancing bike.
|
A class for host communication via serial port. More...
#include <HostPort.h>
Public Member Functions | |
| HostPort () | |
| Constructor. More... | |
| ~HostPort () | |
| Desctructor. More... | |
| bool | begin (unsigned int port, unsigned int baud) |
| Begin the host port. More... | |
| bool | begin (unsigned int port, unsigned int baud, unsigned int header, unsigned int terminator) |
| Begin the host port. More... | |
| bool | begin (unsigned int port, unsigned int baud, unsigned int header, unsigned int terminator, unsigned int timeout) |
| Begin the host port. More... | |
| bool | read (unsigned char *packetPtr, unsigned int size) |
| Read data buffer. More... | |
| bool | write (unsigned char *packetPtr, unsigned int size) |
| Write data buffer. More... | |
| bool | close (void) |
| Close the host port. More... | |
| bool | restart (void) |
| Restart the host port. More... | |
| bool | setPort (unsigned int port) |
| Set the serial port. More... | |
| bool | setBaud (unsigned int baud) |
| Set the baudrate. More... | |
| bool | setHeader (unsigned int header) |
| Set the header. More... | |
| bool | setTerminator (unsigned int terminator) |
| Set the terminator. More... | |
| unsigned int | getPort (void) |
| Get the serial port. More... | |
| unsigned int | getBaud (void) |
| Get the baudate. More... | |
| unsigned int | getHeader (void) |
| Get the header. More... | |
| unsigned int | getTerminator (void) |
| Get the terminator. More... | |
| bool | isInit (void) |
| Check if host port is open. More... | |
| operator bool () | |
| Check if host port is open. More... | |
Static Public Attributes | |
| static constexpr unsigned int | HEADER = 0xFF812345 |
| Default header. More... | |
| static constexpr unsigned int | TERMINATOR = 0xFF8CABDE |
| Default terminator. More... | |
| static constexpr unsigned int | TIMEOUT = 100 |
| Default timeout. More... | |
Private Member Functions | |
| bool | init (unsigned int port, unsigned int baud, unsigned int timeout) |
| Private initialization function. More... | |
Private Attributes | |
| Serial | serial |
| Serial object. More... | |
| unsigned int | _port |
| Serial port. More... | |
| unsigned int | _baud |
| Baudrate. More... | |
| unsigned int | _terminator |
| Terminator bytes. More... | |
| unsigned int | _header |
| Header bytes. More... | |
| unsigned int | _timeout |
| Timeout. More... | |
| unsigned char | _tx_buf [1024] |
| Tx buffer. More... | |
| bool | _isFirstRead = false |
| True if firt packer read. More... | |
Static Private Attributes | |
| static constexpr unsigned int | MASK = 0xFF |
| Mask for parsing. More... | |
A class for host communication via serial port.
Class for host communication via serial port with a specified communication protocol. Data packet consists of
| HostPort::HostPort | ( | ) |
Constructor.
Default constructor.
| HostPort::~HostPort | ( | ) |
Desctructor.
Default destructor. It automatically destroy the serial object.
| bool HostPort::begin | ( | unsigned int | port, |
| unsigned int | baud | ||
| ) |
Begin the host port.
Function to begin the host port communication with default header, terminator, and timeout.
| port | The serial port to use. |
| baud | The baudrate of the serial communication. |
| bool HostPort::begin | ( | unsigned int | port, |
| unsigned int | baud, | ||
| unsigned int | header, | ||
| unsigned int | terminator | ||
| ) |
Begin the host port.
Function to begin the host port communication with given header and terminator and default timeout.
| port | The serial port to use. |
| baud | The baudrate of the serial communication. |
| header | The header to use (as a HEX number of 4-bytes). |
| terminator | The terminator to use (as a HEX number of 4-bytes). |
| bool HostPort::begin | ( | unsigned int | port, |
| unsigned int | baud, | ||
| unsigned int | header, | ||
| unsigned int | terminator, | ||
| unsigned int | timeout | ||
| ) |
Begin the host port.
Function to begin the host port communication with given header, terminator and timeout.
| port | The serial port to use. |
| baud | The baudrate of the serial communication. |
| header | The header to use (as a HEX number of 4-bytes). |
| terminator | The terminator to use (as a HEX number of 4-bytes). |
| timeout | The timeout of the serial communcication. |
| bool HostPort::close | ( | void | ) |
Close the host port.
Function to close the host port. Host port must be opened before.
| unsigned int HostPort::getBaud | ( | void | ) |
Get the baudate.
Function to get the baudrate used for the serial communication.
| unsigned int HostPort::getHeader | ( | void | ) |
Get the header.
Function to get the header used for the host communication.
| unsigned int HostPort::getPort | ( | void | ) |
Get the serial port.
Function to get the serial port used for the host communication.
| unsigned int HostPort::getTerminator | ( | void | ) |
Get the terminator.
Function to get the terminator used for the host communication.
|
private |
Private initialization function.
| bool HostPort::isInit | ( | void | ) |
Check if host port is open.
Function to check if the host port has been open successfully.
|
inline |
Check if host port is open.
Boolean operator to check if the host port has been open successfully.
| bool HostPort::read | ( | unsigned char * | packetPtr, |
| unsigned int | size | ||
| ) |
Read data buffer.
Function to read a data buffer with given length from the host port. Host port must be opened before.
| packetPtr | The pointer to the data buffer. |
| size | The size of the data buffer. |
| bool HostPort::restart | ( | void | ) |
Restart the host port.
Function to restart the host port. Host port must be opened before.
| bool HostPort::setBaud | ( | unsigned int | baud | ) |
Set the baudrate.
Function to set the baudrate of the serial communiation. The restart function must be called to make the change effective.
| bool HostPort::setHeader | ( | unsigned int | header | ) |
Set the header.
Function to set the header of the host communication. The restart function must be called to make the change effective.
| bool HostPort::setPort | ( | unsigned int | port | ) |
Set the serial port.
Function to set the serial port. The restart function must be called to make the change effective.
| bool HostPort::setTerminator | ( | unsigned int | terminator | ) |
Set the terminator.
Function to set the terminator of the host communication. The restart function must be called to make the change effective.
| bool HostPort::write | ( | unsigned char * | packetPtr, |
| unsigned int | size | ||
| ) |
Write data buffer.
Function to write a data buffer with given length to the host port. Host port must be opened before.
| packetPtr | The pointer to the data buffer. |
| size | The size of the data buffer. |
|
private |
Baudrate.
|
private |
Header bytes.
|
private |
True if firt packer read.
|
private |
Serial port.
|
private |
Terminator bytes.
|
private |
Timeout.
|
private |
Tx buffer.
|
staticconstexpr |
Default header.
|
staticconstexprprivate |
Mask for parsing.
|
staticconstexpr |
Default terminator.
|
staticconstexpr |
Default timeout.