2012-08-04 12:20:47 +02:00
|
|
|
/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2012-08-04 12:20:47 +02:00
|
|
|
This software may be distributed and modified under the terms of the GNU
|
|
|
|
General Public License version 2 (GPL2) as published by the Free Software
|
|
|
|
Foundation and appearing in the file GPL2.TXT included in the packaging of
|
|
|
|
this file. Please note that GPL2 Section 2[b] requires that all works based
|
|
|
|
on this software must also be made publicly available under the terms of
|
|
|
|
the GPL2 ("Copyleft").
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2012-08-04 12:20:47 +02:00
|
|
|
Contact information
|
|
|
|
-------------------
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2012-08-04 12:20:47 +02:00
|
|
|
Kristian Lauszus, TKJ Electronics
|
|
|
|
Web : http://www.tkjelectronics.com
|
|
|
|
e-mail : kristianl@tkjelectronics.com
|
|
|
|
*/
|
|
|
|
|
2014-04-21 18:41:39 +02:00
|
|
|
#ifndef _sppserver_h_
|
|
|
|
#define _sppserver_h_
|
2012-08-04 12:20:47 +02:00
|
|
|
|
2014-04-21 18:27:04 +02:00
|
|
|
#include "SPPBase.h"
|
2012-08-04 12:20:47 +02:00
|
|
|
|
2013-11-25 18:20:22 +01:00
|
|
|
/**
|
2014-04-21 18:27:04 +02:00
|
|
|
* 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.
|
2013-11-25 18:20:22 +01:00
|
|
|
*/
|
2014-04-21 18:41:39 +02:00
|
|
|
class SPPServer : public SPPBase {
|
2012-08-04 12:20:47 +02:00
|
|
|
public:
|
2013-03-28 09:46:43 +01:00
|
|
|
/**
|
2014-04-21 18:41:39 +02:00
|
|
|
* Constructor for the SPPServer class.
|
2014-04-21 18:27:04 +02:00
|
|
|
* @param p Pointer to BTD class instance.
|
|
|
|
* @param name Set the name to BTD#btdName. If argument is omitted, then "Arduino" will be used.
|
2013-11-25 02:20:57 +01:00
|
|
|
* @param pin Write the pin to BTD#btdPin. If argument is omitted, then "0000" will be used.
|
2013-03-28 09:46:43 +01:00
|
|
|
*/
|
2014-04-22 01:22:57 +02:00
|
|
|
SPPServer(BTD *p, const char *name = "Arduino", const char *pin = "0000");
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2014-04-21 18:27:04 +02:00
|
|
|
/** @name SPPBase implementation */
|
2013-03-28 09:46:43 +01:00
|
|
|
/**
|
|
|
|
* Used to pass acldata to the services.
|
|
|
|
* @param ACLData Incoming acldata.
|
|
|
|
*/
|
2014-04-21 18:27:04 +02:00
|
|
|
virtual void ACLData(uint8_t *ACLData);
|
2013-03-28 09:46:43 +01:00
|
|
|
/** Used to establish the connection automatically. */
|
|
|
|
virtual void Run();
|
|
|
|
/** Use this to reset the service. */
|
|
|
|
virtual void Reset();
|
|
|
|
/**@}*/
|
|
|
|
|
2012-08-04 12:20:47 +02:00
|
|
|
private:
|
2013-12-11 09:29:38 +01:00
|
|
|
uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events
|
2013-03-28 09:46:43 +01:00
|
|
|
|
|
|
|
unsigned long timer;
|
|
|
|
bool waitForLastCommand;
|
|
|
|
|
|
|
|
bool firstMessage; // Used to see if it's the first SDP request received
|
|
|
|
|
|
|
|
/* State machines */
|
|
|
|
void SDP_task(); // SDP state machine
|
|
|
|
void RFCOMM_task(); // RFCOMM state machine
|
|
|
|
|
|
|
|
/* SDP Commands */
|
2014-04-21 18:27:04 +02:00
|
|
|
virtual void SDP_Command(uint8_t *data, uint8_t nbytes);
|
2013-03-28 09:46:43 +01:00
|
|
|
void serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow);
|
|
|
|
void serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
|
|
|
|
void serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
|
|
|
|
void l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
|
|
|
|
void l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
|
|
|
|
|
2014-04-21 18:27:04 +02:00
|
|
|
virtual void RFCOMM_Command(uint8_t *data, uint8_t nbytes); // Used for RFCOMM commands
|
2012-08-04 12:20:47 +02:00
|
|
|
};
|
2013-12-25 11:09:57 +01:00
|
|
|
#endif
|