BluetoothSPPConnection Class Reference

Bluetooth SPP Connection class. More...

#include <BluetoothSPPConnection.h>

Inheritance diagram for BluetoothSPPConnection:
SerialPortInterface

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

BluetoothSPPConnection::~BluetoothSPPConnection (  ) 

Class destructor.

Unregisters and uninitializes the BluetoothSPPConnection object

BluetoothSPPConnection::BluetoothSPPConnection ( BluetoothModule pBtModule,
bool  incoming 
) [protected]

Class constructor.

Virtual constructor for BluetoothSPPConnection class

Parameters:
pBtModule Pointer to the bluetooth module object
incoming Set to true, if the connection will be initiated by the other party

Member Function Documentation

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.

Returns:
Returns true if connected successfully, false on error.
void BluetoothSPPConnection::disconnect (  ) 

Disconnect from remote device.

Disconnect a Bluetooth SPP connection.

void BluetoothSPPConnection::drainOutput ( void   )  [virtual]

Drain the serial port.

Note:
This function is not implemented yet

Implements SerialPortInterface.

void BluetoothSPPConnection::flushInput ( void   )  [virtual]

Flush Rx FIFO.

Empties Rx FIFO buffer.

Implements SerialPortInterface.

void BluetoothSPPConnection::flushOutput ( void   )  [virtual]

Flush serial port output.

Note:
This function is not implemented yet

Implements SerialPortInterface.

bool BluetoothSPPConnection::getDestAddr ( unsigned char *  pAddr  ) 

Get the destination address of the bluetooth device.

Parameters:
pAddr Buffer where to store the destination address, unsigned char[6]
Returns:
Returns true if the address was successfully stored into buffer, false otherwise Returns false if the module waits for incoming connections.
int BluetoothSPPConnection::getDestPort (  ) 

Get destination port of the remote bluetooth device.

Returns:
Returns destination port or 0 if not set.
int BluetoothSPPConnection::getFifoCnt (  ) 

Get Rx FIFO count.

Returns the number of unread bytes in Rx FIFO.

Returns:
Returns number of bytes in Rx FIFO.
int BluetoothSPPConnection::getLocalPort (  ) 

Get local bluetooth device port.

Returns:
Returns local port or 0 if not set.
void BluetoothSPPConnection::getPin ( char *  pin,
size_t  pinlen 
)

Get bluetooth PIN.

Returns Bluetooth PIN set for this connection.

Note:
Bluetooth PIN is a unicode string!
Parameters:
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

Parameters:
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.

Parameters:
timeout Timeout in milliseconds
Returns:
Returns true if data is in buffer, false otherwise

Implements SerialPortInterface.

bool BluetoothSPPConnection::isPortOpen (  )  [virtual]

isPortOpen

Not implemented for BluetoothSPPConnection, port is always open

Returns:
Returns always true

Implements SerialPortInterface.

bool BluetoothSPPConnection::listen (  ) 

Start listening of incoming connections.

Returns:
Returns true if initiated successfully, false on error.
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.

Parameters:
timeout Timeout in milliseconds
Returns:
Returns the number of bytes in FIFO.

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

Parameters:
vbuf Pointer to the buffer where to store the data
buflen Size of the buffer
Returns:
Returns number of bytes received

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.

Returns:
Returns true if SPP connection was successfully registered, false otherwise.
bool BluetoothSPPConnection::reOpen (  )  [virtual]

ReOpen.

Not implemented for BluetoothSPPConnection, port can not be reOpened

Returns:
Returns always false

Implements SerialPortInterface.

void BluetoothSPPConnection::setConnectionState ( SPP_CONN_STATUS  connStatus  )  [protected]

Set connection state.

Called by friend class BluetoothModule to notify of connection state change.

Parameters:
connStatus New status of the bluetooth connection
bool BluetoothSPPConnection::setDestAddr ( const unsigned char *  pAddr  ) 

Set destination address of the bluetooth device.

Parameters:
pAddr Destination address, unsigned char[6]
Returns:
Returns true if set, false on error. Returns false if the module waits for incoming connections.
bool BluetoothSPPConnection::setDestPort ( int  destPort  ) 

Set destination port for remote bluetooth device.

Parameters:
destPort Destination port of the remote bluetooth device
Returns:
Returns true if set, false on error
bool BluetoothSPPConnection::setLocalPort ( int  localPort  ) 

Set local bluetooth device port.

Parameters:
localPort Port of the local bluetooth device
Returns:
Returns true if set, false on error
bool BluetoothSPPConnection::setPin ( const char *  newpin  ) 

Set bluetooth PIN.

Sets Bluetooth PIN set for this connection.

Note:
Bluetooth PIN is a unicode string!
Parameters:
newpin Bluetooth pin as zero-terminated unicode string.
Returns:
Returns true if set, false on error
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.

Parameters:
buf Pointer to the buffer that contains the data that will be sent
len Buffer length
Note:
This does not guarantee that the receiver has received it, just that it was transmitted!
Returns:
Returns number of bytes transmitted.

Implements SerialPortInterface.


The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:43 2010 for libspatha by  doxygen 1.6.3