|
SBB Host
Host communication with the self balancing bike.
|
A class for host communication via UDP protocol using the broadcast IP. More...
#include <HostPortUDP.h>
Public Member Functions | |
| HostPortUDP () | |
| Constructor. More... | |
| ~HostPortUDP () | |
| Desctructor. More... | |
| bool | begin (const std::string &ipaddr, unsigned short port) |
| Begin the host port. More... | |
| bool | begin (const std::string &ipaddr, unsigned short port, unsigned int header, unsigned int terminator) |
| Begin the host port. More... | |
| bool | begin (const std::string &ipaddr, unsigned short port, 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 | flush (void) |
| Flush the port. More... | |
| bool | setPort (unsigned short port) |
| Set the serial port. More... | |
| bool | setIP (const std::string &ipaddr) |
| Set the IP address. More... | |
| bool | setHeader (unsigned int header) |
| Set the header. More... | |
| bool | setTerminator (unsigned int terminator) |
| Set the terminator. More... | |
| bool | setTimeout (unsigned int timeout) |
| Set the timeout. More... | |
| unsigned short | getPort (void) |
| Get the serial port. More... | |
| std::string | getIP (void) |
| Get the IP address. More... | |
| unsigned int | getHeader (void) |
| Get the header. More... | |
| unsigned int | getTerminator (void) |
| Get the terminator. More... | |
| unsigned int | getTimeout (void) |
| Get the timeout. 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 = 1000 |
| Default timeout. More... | |
| static constexpr unsigned int | MAX_PACKET_SIZE = 256 |
| Maximum packet size in bytes. More... | |
Private Member Functions | |
| bool | init (const std::string &ipaddr, unsigned short port, unsigned int timeout) |
| Private initialization function. More... | |
Private Attributes | |
| sockpp::socket_initializer | sockInit |
| sockpp::udp_socket | client |
| Socket object. More... | |
| unsigned int | _port |
| Socket port. More... | |
| std::string | _ip |
| IP address. More... | |
| unsigned int | _terminator |
| Terminator bytes. More... | |
| unsigned int | _header |
| Header bytes. More... | |
| unsigned int | _timeout |
| Timeout. More... | |
| int | _enable = 1 |
| 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 UDP protocol using the broadcast IP.
Class for host communication via UDP protocol using the broadcast IP with a specified communication protocol. Data packet consists of
| HostPortUDP::HostPortUDP | ( | ) |
Constructor.
Default constructor.
| HostPortUDP::~HostPortUDP | ( | ) |
Desctructor.
Default destructor. It automatically destroy the serial object.
| bool HostPortUDP::begin | ( | const std::string & | ipaddr, |
| unsigned short | port | ||
| ) |
Begin the host port.
Function to begin the host port communication with default header, terminator, and timeout.
| ipaddr | The IP address to use. Must be the broadcast IP. |
| port | The socket port to use. |
| bool HostPortUDP::begin | ( | const std::string & | ipaddr, |
| unsigned short | port, | ||
| 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.
| ipaddr | The IP address to use. Must be the broadcast IP. |
| port | The socket port to use. |
| 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 HostPortUDP::begin | ( | const std::string & | ipaddr, |
| unsigned short | port, | ||
| 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.
| ipaddr | The IP address to use. Must be the broadcast IP. |
| port | The socket port to use. |
| 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 HostPortUDP::close | ( | void | ) |
Close the host port.
Function to close the host port. Host port must be opened before.
| bool HostPortUDP::flush | ( | void | ) |
Flush the port.
Function to flush the port. Host port must be opened before.
| unsigned int HostPortUDP::getHeader | ( | void | ) |
Get the header.
Function to get the header used for the host communication.
| std::string HostPortUDP::getIP | ( | void | ) |
Get the IP address.
Function to get the IP address used for the socket communication.
| unsigned short HostPortUDP::getPort | ( | void | ) |
Get the serial port.
Function to get the serial port used for the host communication.
| unsigned int HostPortUDP::getTerminator | ( | void | ) |
Get the terminator.
Function to get the terminator used for the host communication.
| unsigned int HostPortUDP::getTimeout | ( | void | ) |
Get the timeout.
Function to get the timeout used for the host communication.
|
private |
Private initialization function.
| bool HostPortUDP::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 HostPortUDP::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 HostPortUDP::restart | ( | void | ) |
Restart the host port.
Function to restart the host port. Host port must be opened before.
| bool HostPortUDP::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 HostPortUDP::setIP | ( | const std::string & | ipaddr | ) |
Set the IP address.
Function to set the IP address of the socket communiation. The restart function must be called to make the change effective.
| bool HostPortUDP::setPort | ( | unsigned short | port | ) |
Set the serial port.
Function to set the socket port. The restart function must be called to make the change effective.
| bool HostPortUDP::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 HostPortUDP::setTimeout | ( | unsigned int | timeout | ) |
Set the timeout.
Function to set the timeout of the host communication. The restart function must be called to make the change effective.
| bool HostPortUDP::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 |
|
private |
Header bytes.
|
private |
IP address.
|
private |
True if firt packer read.
|
private |
Socket port.
|
private |
Terminator bytes.
|
private |
Timeout.
|
private |
Socket object.
|
staticconstexpr |
Default header.
|
staticconstexprprivate |
Mask for parsing.
|
staticconstexpr |
Maximum packet size in bytes.
|
private |
|
staticconstexpr |
Default terminator.
|
staticconstexpr |
Default timeout.