Renamed SPP and SPPi library to SPPServer and SPPClient respectively

This commit is contained in:
Kristian Lauszus 2014-04-21 18:41:39 +02:00
parent ee90afde31
commit b516af57df
7 changed files with 41 additions and 40 deletions

View file

@ -19,7 +19,7 @@
*/
#include "SPPi.h"
#include "SPPClient.h"
// To enable serial debugging see "settings.h"
//#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report sent to the Arduino
@ -29,7 +29,7 @@
*/
const uint8_t rfcomm_uuid_sign[6] PROGMEM = { 0x35, 0x05, 0x19, 0x00, 0x03, 0x08 };
SPPi::SPPi(BTD *p, const char* name, const char* pin, bool pair, uint8_t *addr) :
SPPClient::SPPClient(BTD *p, const char* name, const char* pin, bool pair, uint8_t *addr) :
SPPBase(p)
{
if (pBtd)
@ -54,7 +54,7 @@ SPPBase(p)
Reset();
}
void SPPi::Reset() {
void SPPClient::Reset() {
connected = false;
RFCOMMConnected = false;
SDPConnected = false;
@ -66,7 +66,7 @@ void SPPi::Reset() {
rfcomm_found = false;
}
void SPPi::ACLData(uint8_t *l2capinbuf) {
void SPPClient::ACLData(uint8_t *l2capinbuf) {
#ifdef EXTRADEBUG
Notify(PSTR("\r\nIncoming Packet: "), 0x80);
@ -546,7 +546,7 @@ void SPPi::ACLData(uint8_t *l2capinbuf) {
}
}
void SPPi::Run() {
void SPPClient::Run() {
if (pBtd->pairWithOtherDevice){
if (l2cap_sdp_state == L2CAP_SDP_WAIT) {
if (pBtd->connectToOtherDevice && !pBtd->l2capConnectionClaimed && !connected) {
@ -567,11 +567,11 @@ void SPPi::Run() {
/************************************************************/
/* SDP Commands */
/************************************************************/
void SPPi::SDP_Command(uint8_t *data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
void SPPClient::SDP_Command(uint8_t *data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
pBtd->L2CAP_Command(hci_handle, data, nbytes, sdp_dcid[0], sdp_dcid[1]);
}
void SPPi::SDP_Service_Search_Attr(uint8_t transactionIDHigh, uint8_t transactionIDLow, uint8_t remainingLen) {
void SPPClient::SDP_Service_Search_Attr(uint8_t transactionIDHigh, uint8_t transactionIDLow, uint8_t remainingLen) {
l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU;
l2capoutbuf[1] = transactionIDHigh;
l2capoutbuf[2] = transactionIDLow;
@ -617,11 +617,11 @@ void SPPi::SDP_Service_Search_Attr(uint8_t transactionIDHigh, uint8_t transactio
/************************************************************/
/* RFCOMM Commands */
/************************************************************/
void SPPi::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
void SPPClient::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
pBtd->L2CAP_Command(hci_handle, data, nbytes, rfcomm_dcid[0], rfcomm_dcid[1]);
}
void SPPi::parseAttrReply(uint8_t *l2capinbuf) {
void SPPClient::parseAttrReply(uint8_t *l2capinbuf) {
if ((l2capinbuf[2] + 4) < 15) return; // Sanity check
if (rfcomm_found) {

View file

@ -18,8 +18,8 @@
04.04.2014, Magictale Electronics
*/
#ifndef _sppi_h_
#define _sppi_h_
#ifndef _sppclient_h_
#define _sppclient_h_
#include "SPPBase.h"
@ -45,20 +45,20 @@
* This BluetoothService class a Serial Port Protocol (SPP) client.
* It inherits the Arduino Stream class. This allows it to use all the standard Arduino print functions.
*/
class SPPi : public SPPBase {
class SPPClient : public SPPBase {
public:
/**
* Constructor for the SPPi class.
* Constructor for the SPPClient class.
* @param p Pointer to BTD class instance.
* @param name Set the name to BTD#btdName. If argument is omitted, then "Arduino" will be used.
* @param pin Write the pin to BTD#btdPin. If argument is omitted, then "0000" will be used.
* @param pair Set this to true if you want to pair with a device.
* @param addr Set this to the address you want to connect to.
*/
SPPi(BTD *p, const char *name = "Arduino", const char *pin = "0000", bool pair = false, uint8_t *addr = NULL);
SPPClient(BTD *p, const char *name = "Arduino", const char *pin = "0000", bool pair = false, uint8_t *addr = NULL);
#if GCC_VERSION > 40700 // Test for GCC > 4.7.0
SPPi(BTD *p, bool pair = false, uint8_t *addr = NULL) : SPPi(p, "Arduino", "0000", pair, addr) {}; // Use a delegating constructor
SPPClient(BTD *p, bool pair = false, uint8_t *addr = NULL) : SPPClient(p, "Arduino", "0000", pair, addr) {}; // Use a delegating constructor
#endif
/** @name SPPBase implementation */

View file

@ -15,12 +15,12 @@
e-mail : kristianl@tkjelectronics.com
*/
#include "SPP.h"
#include "SPPServer.h"
// To enable serial debugging see "settings.h"
//#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report sent to the Arduino
SPP::SPP(BTD *p, const char *name, const char *pin, bool pair, uint8_t *addr) :
SPPServer::SPPServer(BTD *p, const char *name, const char *pin, bool pair, uint8_t *addr) :
SPPBase(p)
{
if(pBtd)
@ -45,7 +45,7 @@ SPPBase(p)
Reset();
}
void SPP::Reset() {
void SPPServer::Reset() {
connected = false;
RFCOMMConnected = false;
SDPConnected = false;
@ -56,7 +56,7 @@ void SPP::Reset() {
sppIndex = 0;
}
void SPP::ACLData(uint8_t *l2capinbuf) {
void SPPServer::ACLData(uint8_t *l2capinbuf) {
if(!connected) {
if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == SDP_PSM && !pBtd->sdpConnectionClaimed) {
@ -398,7 +398,7 @@ void SPP::ACLData(uint8_t *l2capinbuf) {
}
}
void SPP::Run() {
void SPPServer::Run() {
if(waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80);
@ -411,7 +411,7 @@ void SPP::Run() {
send(); // Send all bytes currently in the buffer
}
void SPP::SDP_task() {
void SPPServer::SDP_task() {
switch(l2cap_sdp_state) {
case L2CAP_SDP_WAIT:
if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_SDP_REQUEST)) {
@ -460,7 +460,7 @@ void SPP::SDP_task() {
}
}
void SPP::RFCOMM_task() {
void SPPServer::RFCOMM_task() {
switch(l2cap_rfcomm_state) {
case L2CAP_RFCOMM_WAIT:
if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)) {
@ -502,11 +502,11 @@ void SPP::RFCOMM_task() {
/************************************************************/
/* SDP Commands */
/************************************************************/
void SPP::SDP_Command(uint8_t *data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
void SPPServer::SDP_Command(uint8_t *data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
pBtd->L2CAP_Command(hci_handle, data, nbytes, sdp_scid[0], sdp_scid[1]);
}
void SPP::serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow) { // See page 235 in the Bluetooth specs
void SPPServer::serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow) { // See page 235 in the Bluetooth specs
l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
l2capoutbuf[1] = transactionIDHigh;
l2capoutbuf[2] = transactionIDLow;
@ -523,7 +523,7 @@ void SPP::serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLo
SDP_Command(l2capoutbuf, 10);
}
void SPP::serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
void SPPServer::serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
l2capoutbuf[1] = transactionIDHigh;
l2capoutbuf[2] = transactionIDLow;
@ -581,7 +581,7 @@ void SPP::serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLo
SDP_Command(l2capoutbuf, 48);
}
void SPP::serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
void SPPServer::serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
l2capoutbuf[1] = transactionIDHigh;
l2capoutbuf[2] = transactionIDLow;
@ -623,16 +623,16 @@ void SPP::serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLo
SDP_Command(l2capoutbuf, 33);
}
void SPP::l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
void SPPServer::l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
serialPortResponse1(transactionIDHigh, transactionIDLow); // These has to send all the supported functions, since it only supports virtual serialport it just sends the message again
}
void SPP::l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
void SPPServer::l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
serialPortResponse2(transactionIDHigh, transactionIDLow); // Same data as serialPortResponse2
}
/************************************************************/
/* RFCOMM Commands */
/************************************************************/
void SPP::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
void SPPServer::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
pBtd->L2CAP_Command(hci_handle, data, nbytes, rfcomm_scid[0], rfcomm_scid[1]);
}

View file

@ -15,8 +15,8 @@
e-mail : kristianl@tkjelectronics.com
*/
#ifndef _spp_h_
#define _spp_h_
#ifndef _sppserver_h_
#define _sppserver_h_
#include "SPPBase.h"
@ -24,17 +24,17 @@
* This BluetoothService class a Serial Port Protocol (SPP) server.
* It inherits the Arduino Stream class. This allows it to use all the standard Arduino print functions.
*/
class SPP : public SPPBase {
class SPPServer : public SPPBase {
public:
/**
* Constructor for the SPP class.
* Constructor for the SPPServer class.
* @param p Pointer to BTD class instance.
* @param name Set the name to BTD#btdName. If argument is omitted, then "Arduino" will be used.
* @param pin Write the pin to BTD#btdPin. If argument is omitted, then "0000" will be used.
* @param pair Set this to true if you want to pair with a device.
* @param addr Set this to the address you want to connect to.
*/
SPP(BTD *p, const char *name = "Arduino", const char *pin = "0000", bool pair = false, uint8_t *addr = NULL);
SPPServer(BTD *p, const char *name = "Arduino", const char *pin = "0000", bool pair = false, uint8_t *addr = NULL);
/** @name SPPBase implementation */
/**

View file

@ -4,7 +4,7 @@
send me an e-mail: kristianl@tkjelectronics.com
*/
#include <SPPi.h>
#include <SPPClient.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
@ -17,7 +17,7 @@ USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
uint8_t addr[6] = { 0x71, 0xB4, 0xB0, 0xC8, 0xBC, 0xC8 }; // Set this to the Bluetooth address you want to connect to
SPPi SerialBT(&Btd, true, addr);
SPPClient SerialBT(&Btd, "Arduino", "0000", true, addr);
boolean firstMessage = true;

View file

@ -4,7 +4,7 @@
send me an e-mail: kristianl@tkjelectronics.com
*/
#include <SPP.h>
#include <SPPServer.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
@ -17,8 +17,8 @@ USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
//SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
SPPServer SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
//SPPServer SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
boolean firstMessage = true;

View file

@ -236,7 +236,8 @@ Y LITERAL1
# Datatypes (KEYWORD1)
####################################################
SPP KEYWORD1
SPPServer KEYWORD1
SPPClient KEYWORD1
####################################################
# Methods and Functions (KEYWORD2)