24 #define L2CAP_SDP_WAIT 0
25 #define L2CAP_SDP_REQUEST 1
26 #define L2CAP_SDP_SUCCESS 2
27 #define L2CAP_SDP_DONE 3
28 #define L2CAP_DISCONNECT_RESPONSE 4
31 #define L2CAP_RFCOMM_WAIT 0
32 #define L2CAP_RFCOMM_REQUEST 1
33 #define L2CAP_RFCOMM_SUCCESS 2
34 #define L2CAP_RFCOMM_DONE 3
37 #define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x001
38 #define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x002
39 #define L2CAP_FLAG_CONFIG_SDP_REQUEST 0x004
40 #define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST 0x008
41 #define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x010
42 #define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x020
43 #define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x040
44 #define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x080
45 #define L2CAP_FLAG_DISCONNECT_RESPONSE 0x100
48 #define l2cap_connection_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_SDP_REQUEST)
49 #define l2cap_connection_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)
50 #define l2cap_config_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_REQUEST)
51 #define l2cap_config_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_REQUEST)
52 #define l2cap_config_success_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_SUCCESS)
53 #define l2cap_config_success_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS)
54 #define l2cap_disconnect_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_SDP_REQUEST)
55 #define l2cap_disconnect_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)
56 #define l2cap_disconnect_response_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RESPONSE)
59 #define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU 0x06 // See the RFCOMM specs
60 #define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU 0x07 // See the RFCOMM specs
61 #define SERIALPORT_UUID 0x1101 // See http://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
62 #define L2CAP_UUID 0x0100
65 #define RFCOMM_SABM 0x2F
66 #define RFCOMM_UA 0x63
67 #define RFCOMM_UIH 0xEF
69 #define RFCOMM_DISC 0x43
71 #define extendAddress 0x01 // Allways 1
74 #define BT_RFCOMM_PN_CMD 0x83
75 #define BT_RFCOMM_PN_RSP 0x81
76 #define BT_RFCOMM_MSC_CMD 0xE3
77 #define BT_RFCOMM_MSC_RSP 0xE1
78 #define BT_RFCOMM_RPN_CMD 0x93
79 #define BT_RFCOMM_RPN_RSP 0x91
101 SPP(
BTD *p,
const char* name =
"Arduino",
const char* pin =
"1234");
112 virtual void Reset();
126 void print(
const String &str);
131 void println(
const String &str);
136 void print(
const char* str);
146 void print(uint8_t data);
157 void print(uint8_t* array, uint8_t length);
163 void println(uint8_t* array, uint8_t length);
168 void print(
const __FlashStringHelper *ifsh);
173 void println(
const __FlashStringHelper *ifsh);
206 void doubleToString(
double input,
char* output, uint8_t digits = 2);
219 void flush() { rfcommAvailable = 0; };
228 bool RFCOMMConnected;
233 uint8_t l2cap_sdp_state;
234 uint8_t l2cap_rfcomm_state;
235 uint16_t l2cap_event_flag;
238 uint8_t rfcommbuf[10];
243 uint8_t rfcomm_scid[2];
244 uint8_t rfcomm_dcid[2];
248 uint8_t rfcommChannel;
249 uint8_t rfcommChannelConnection;
250 uint8_t rfcommDirection;
251 uint8_t rfcommCommandResponse;
252 uint8_t rfcommChannelType;
256 bool waitForLastCommand;
259 uint8_t rfcommDataBuffer[100];
260 uint8_t rfcommAvailable;
265 unsigned long printTimer;
272 void SDP_Command(uint8_t* data, uint8_t nbytes);
273 void serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow);
274 void serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
275 void serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
276 void l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
277 void l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
280 void RFCOMM_Command(uint8_t* data, uint8_t nbytes);
281 void sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length);
282 void sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t credit);
283 uint8_t calcFcs(uint8_t *data);
284 uint8_t __crc(uint8_t* data);