Bluetooth SPP Connection class. More...
#include <BluetoothSPPConnection.h>
Public Member Functions | |
~BluetoothSPPConnection () | |
Class destructor. | |
virtual bool | reOpen () |
ReOpen. | |
virtual bool | isPortOpen () |
isPortOpen | |
virtual ssize_t | writeData (const void *buf, size_t len) |
Send SPP data. | |
virtual ssize_t | readData (void *buf, size_t buflen) |
Read Rx data from FIFO. | |
virtual size_t | numInputPending (int timeout) |
Wait for Rx data. | |
virtual bool | isInputPending (int timeOut) |
Wait for Rx data. | |
virtual void | flushInput () |
Flush Rx FIFO. | |
virtual void | flushOutput () |
Flush serial port output. | |
virtual void | drainOutput () |
Drain the serial port. | |
int | getFifoCnt () |
Get Rx FIFO count. | |
bool | isConnected () |
Get connection status. | |
bool | getDestAddr (unsigned char *pAddr) |
Get the destination address of the bluetooth device. | |
int | getDestPort () |
Get destination port of the remote bluetooth device. | |
int | getLocalPort () |
Get local bluetooth device port. | |
void | getPin (char *pin, size_t pinlen) |
Get bluetooth PIN. | |
bool | setDestAddr (const unsigned char *destaddr) |
Set destination address of the bluetooth device. | |
bool | setDestPort (int destPort) |
Set destination port for remote bluetooth device. | |
bool | setLocalPort (int localPort) |
Set local bluetooth device port. | |
bool | setPin (const char *pin) |
Set bluetooth PIN. | |
bool | connect () |
Connect to remote device. | |
bool | listen () |
Start listening of incoming connections. | |
void | disconnect () |
Disconnect from remote device. | |
Protected Member Functions | |
BluetoothSPPConnection (BluetoothModule *pBtModule, bool incoming) | |
Class constructor. | |
void | incomingData (const void *buf, size_t len) |
Handle incoming data. | |
void | setConnectionState (SPP_CONN_STATUS connStatus) |
Set connection state. | |
bool | registerSPP () |
Register the SPP connection. | |
Friends | |
class | BluetoothModule |
Bluetooth SPP Connection class.
Implements a Bluetooth SPP Connection (Serial Port Protocol, RFComm layer). Every SPPConnection has its Rx FIFO and handles its connection state and data transmission. Use BluetoothModule->createSPPConnection(...) to create it.
BluetoothSPPConnection::~BluetoothSPPConnection | ( | ) |
Class destructor.
Unregisters and uninitializes the BluetoothSPPConnection object
BluetoothSPPConnection::BluetoothSPPConnection | ( | BluetoothModule * | pBtModule, | |
bool | incoming | |||
) | [protected] |
Class constructor.
Virtual constructor for BluetoothSPPConnection class
pBtModule | Pointer to the bluetooth module object | |
incoming | Set to true, if the connection will be initiated by the other party |
bool BluetoothSPPConnection::connect | ( | ) |
Connect to remote device.
Initiate a pairing process and wait until connected. This may take up to CONNECT_TIMEOUT ms. Do not shorten the time, Bluetooth devices may be in low power mode and wake up once in 10 seconds to check for new connections.
void BluetoothSPPConnection::disconnect | ( | ) |
Disconnect from remote device.
Disconnect a Bluetooth SPP connection.
void BluetoothSPPConnection::drainOutput | ( | void | ) | [virtual] |
void BluetoothSPPConnection::flushInput | ( | void | ) | [virtual] |
void BluetoothSPPConnection::flushOutput | ( | void | ) | [virtual] |
bool BluetoothSPPConnection::getDestAddr | ( | unsigned char * | pAddr | ) |
Get the destination address of the bluetooth device.
pAddr | Buffer where to store the destination address, unsigned char[6] |
int BluetoothSPPConnection::getDestPort | ( | ) |
Get destination port of the remote bluetooth device.
int BluetoothSPPConnection::getFifoCnt | ( | ) |
Get Rx FIFO count.
Returns the number of unread bytes in Rx FIFO.
int BluetoothSPPConnection::getLocalPort | ( | ) |
Get local bluetooth device port.
void BluetoothSPPConnection::getPin | ( | char * | pin, | |
size_t | pinlen | |||
) |
Get bluetooth PIN.
Returns Bluetooth PIN set for this connection.
pin | Buffer to store PIN | |
pinlen | Pin buffer length |
void BluetoothSPPConnection::incomingData | ( | const void * | vbuf, | |
size_t | len | |||
) | [protected] |
Handle incoming data.
Friend class BluetoothModule uploads Rx data
vbuf | Pointer to the buffer that contains the data | |
len | Buffer size |
bool BluetoothSPPConnection::isConnected | ( | ) |
Get connection status.
Returns true if still connected, false otherwise. The connection may be dropped by remote host or by bad network coverage!
bool BluetoothSPPConnection::isInputPending | ( | int | timeout | ) | [virtual] |
Wait for Rx data.
Waits until there is at least 1 byte in Rx FIFO before timeout occurs.
timeout | Timeout in milliseconds |
Implements SerialPortInterface.
bool BluetoothSPPConnection::isPortOpen | ( | ) | [virtual] |
isPortOpen
Not implemented for BluetoothSPPConnection, port is always open
Implements SerialPortInterface.
bool BluetoothSPPConnection::listen | ( | ) |
Start listening of incoming connections.
size_t BluetoothSPPConnection::numInputPending | ( | int | timeout | ) | [virtual] |
Wait for Rx data.
Waits until there is at least 1 byte in Rx FIFO before the timeout occurs.
timeout | Timeout in milliseconds |
Implements SerialPortInterface.
ssize_t BluetoothSPPConnection::readData | ( | void * | vbuf, | |
size_t | buflen | |||
) | [virtual] |
Read Rx data from FIFO.
Read received data from FIFO to vbuf. Up to buflen bytes will be read
vbuf | Pointer to the buffer where to store the data | |
buflen | Size of the buffer |
Implements SerialPortInterface.
bool BluetoothSPPConnection::registerSPP | ( | ) | [protected] |
Register the SPP connection.
Registers the SPP connection in the BluetoothModule. This will enable the BluetoothModule to send Rx data and status updates to us.
bool BluetoothSPPConnection::reOpen | ( | ) | [virtual] |
ReOpen.
Not implemented for BluetoothSPPConnection, port can not be reOpened
Implements SerialPortInterface.
void BluetoothSPPConnection::setConnectionState | ( | SPP_CONN_STATUS | connStatus | ) | [protected] |
Set connection state.
Called by friend class BluetoothModule to notify of connection state change.
connStatus | New status of the bluetooth connection |
bool BluetoothSPPConnection::setDestAddr | ( | const unsigned char * | pAddr | ) |
Set destination address of the bluetooth device.
pAddr | Destination address, unsigned char[6] |
bool BluetoothSPPConnection::setDestPort | ( | int | destPort | ) |
Set destination port for remote bluetooth device.
destPort | Destination port of the remote bluetooth device |
bool BluetoothSPPConnection::setLocalPort | ( | int | localPort | ) |
Set local bluetooth device port.
localPort | Port of the local bluetooth device |
bool BluetoothSPPConnection::setPin | ( | const char * | newpin | ) |
Set bluetooth PIN.
Sets Bluetooth PIN set for this connection.
newpin | Bluetooth pin as zero-terminated unicode string. |
ssize_t BluetoothSPPConnection::writeData | ( | const void * | buf, | |
size_t | len | |||
) | [virtual] |
Send SPP data.
Send data over Bluetooth SPP link. Returns nonzero if the data was sent.
buf | Pointer to the buffer that contains the data that will be sent | |
len | Buffer length |
Implements SerialPortInterface.