Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

SPP Class Reference

This BluetoothService class implements the Serial Port Protocol (SPP). More...

#include <SPP.h>

Inherits BluetoothService.

Public Member Functions

 SPP (BTD *p, const char *name="Arduino", const char *pin="0000")
 Constructor for the SPP class.
 operator bool ()
 Used to provide Boolean tests for the class.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the device is successfully initialized.
Serial port profile (SPP) Print functions
int available (void)
 Get number of bytes waiting to be read.
void flush (void)
 Send out all bytes in the buffer.
int peek (void)
 Used to read the next value in the buffer without advancing to the next one.
int read (void)
 Used to read the buffer.
size_t write (uint8_t data)
 Writes the byte to send to a buffer.
size_t write (const uint8_t *data, size_t size)
 Writes the bytes to send to a buffer.
void write (uint8_t data)
 Writes the byte to send to a buffer.
void write (const uint8_t *data, size_t size)
 Writes the bytes to send to a buffer.
void discard (void)
 Discard all the bytes in the buffer.
void send (void)
 This will send all the bytes in the buffer.

Data Fields

bool connected
 Variable used to indicate if the connection is established.

Protected Member Functions

bool checkHciHandle (uint8_t *buf, uint16_t handle)
 Used to check if the incoming L2CAP data matches the HCI Handle.

Protected Attributes

void(* pFuncOnInit )(void)
 Pointer to function called in onInit().
BTDpBtd
 Pointer to BTD instance.
uint16_t hci_handle
 The HCI Handle for the connection.
uint32_t l2cap_event_flag
 L2CAP flags of received Bluetooth events.
uint8_t identifier
 Identifier for L2CAP commands.

BluetoothService implementation

void disconnect ()
 Used this to disconnect the virtual serial port.
void ACLData (uint8_t *ACLData)
 Used to pass acldata to the services.
void Run ()
 Used to establish the connection automatically.
void Reset ()
 Use this to reset the service.
void onInit ()
 Called when a device is successfully initialized.

Detailed Description

This BluetoothService class implements the Serial Port Protocol (SPP).

It inherits the Arduino Stream class. This allows it to use all the standard Arduino print and stream functions.

Definition at line 62 of file SPP.h.


Constructor & Destructor Documentation

SPP ( BTD p,
const char *  name = "Arduino",
const char *  pin = "0000" 
)

Constructor for the SPP class.

Parameters:
pPointer to BTD class instance.
nameSet the name to BTD::btdName. If argument is omitted, then "Arduino" will be used.
pinWrite the pin to BTD::btdPin. If argument is omitted, then "0000" will be used.

Definition at line 45 of file SPP.cpp.


Member Function Documentation

void ACLData ( uint8_t *  ACLData ) [protected, virtual]

Used to pass acldata to the services.

Parameters:
ACLDataIncoming acldata.

Implements BluetoothService.

Definition at line 84 of file SPP.cpp.

void attachOnInit ( void(*)(void)  funcOnInit ) [inherited]

Used to call your own function when the device is successfully initialized.

Parameters:
funcOnInitFunction to call.

Definition at line 592 of file BTD.h.

int available ( void   )

Get number of bytes waiting to be read.

Returns:
Return the number of bytes ready to be read.
bool checkHciHandle ( uint8_t *  buf,
uint16_t  handle 
) [protected, inherited]

Used to check if the incoming L2CAP data matches the HCI Handle.

Definition at line 605 of file BTD.h.

void discard ( void   )

Discard all the bytes in the buffer.

void disconnect (  ) [virtual]

Used this to disconnect the virtual serial port.

Implements BluetoothService.

Definition at line 72 of file SPP.cpp.

void flush ( void   )

Send out all bytes in the buffer.

Definition at line 95 of file SPP.h.

void onInit (  ) [protected, virtual]

Called when a device is successfully initialized.

Use attachOnInit(void (*funcOnInit)(void)) to call your own function. This is useful for instance if you want to set the LEDs in a specific way.

Implements BluetoothService.

Definition at line 433 of file SPP.cpp.

operator bool (  )

Used to provide Boolean tests for the class.

Returns:
Return true if SPP communication is connected.

Definition at line 81 of file SPP.h.

int peek ( void   )

Used to read the next value in the buffer without advancing to the next one.

Returns:
Return the byte. Will return -1 if no bytes are available.
int read ( void   )

Used to read the buffer.

Returns:
Return the byte. Will return -1 if no bytes are available.
void Reset (  ) [protected, virtual]

Use this to reset the service.

Implements BluetoothService.

Definition at line 60 of file SPP.cpp.

void Run (  ) [protected, virtual]

Used to establish the connection automatically.

Implements BluetoothService.

Definition at line 423 of file SPP.cpp.

void send ( void   )

This will send all the bytes in the buffer.

This is called whenever Usb.Task() is called, but can also be called via this function.

void write ( const uint8_t *  data,
size_t  size 
)

Writes the bytes to send to a buffer.

The message is send when either send() or after Usb.Task() is called.

Parameters:
dataThe data array to send.
sizeSize of the data.
void write ( uint8_t  data )

Writes the byte to send to a buffer.

The message is send when either send() or after Usb.Task() is called.

Parameters:
dataThe byte to write.
Returns:
Return the number of bytes written.

Definition at line 742 of file SPP.cpp.

size_t write ( const uint8_t *  data,
size_t  size 
)

Writes the bytes to send to a buffer.

The message is send when either send() or after Usb.Task() is called.

Parameters:
dataThe data array to send.
sizeSize of the data.
Returns:
Return the number of bytes written.

Definition at line 754 of file SPP.cpp.

void write ( uint8_t  data )

Writes the byte to send to a buffer.

The message is send when either send() or after Usb.Task() is called.

Parameters:
dataThe byte to write.

Field Documentation

bool connected

Variable used to indicate if the connection is established.

Definition at line 85 of file SPP.h.

uint16_t hci_handle [protected, inherited]

The HCI Handle for the connection.

Definition at line 616 of file BTD.h.

uint8_t identifier [protected, inherited]

Identifier for L2CAP commands.

Definition at line 622 of file BTD.h.

uint32_t l2cap_event_flag [protected, inherited]

L2CAP flags of received Bluetooth events.

Definition at line 619 of file BTD.h.

BTD* pBtd [protected, inherited]

Pointer to BTD instance.

Definition at line 613 of file BTD.h.

void(* pFuncOnInit)(void) [protected, inherited]

Pointer to function called in onInit().

Definition at line 610 of file BTD.h.