-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathBLEDevice.h
122 lines (90 loc) · 3.38 KB
/
BLEDevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _BLE_DEVICE_H_
#define _BLE_DEVICE_H_
#include <Arduino.h>
#include "BLEService.h"
enum BLEDeviceEvent {
BLEConnected = 0,
BLEDisconnected = 1,
BLEDiscovered = 2,
BLEDeviceLastEvent
};
class BLEDevice;
typedef void (*BLEDeviceEventHandler)(BLEDevice device);
class BLEDevice {
public:
BLEDevice();
virtual ~BLEDevice();
virtual void poll();
virtual void poll(unsigned long timeout);
virtual bool connected() const;
virtual bool disconnect();
virtual String address() const;
virtual void address(uint8_t* address) const;
bool hasLocalName() const;
bool hasAdvertisedServiceUuid() const;
bool hasAdvertisedServiceUuid(int index) const;
int advertisedServiceUuidCount() const;
String localName() const;
String advertisedServiceUuid() const;
String advertisedServiceUuid(int index) const;
bool hasAdvertisementData() const;
int advertisementDataLength() const;
int advertisementData(uint8_t value[], int length) const;
bool hasManufacturerData() const;
int manufacturerDataLength() const;
int manufacturerData(uint8_t value[], int length) const;
virtual int rssi();
bool connect();
bool discoverAttributes();
bool discoverService(const char* serviceUuid);
virtual operator bool() const;
virtual bool operator==(const BLEDevice& rhs) const;
virtual bool operator!=(const BLEDevice& rhs) const;
String deviceName();
int appearance();
int serviceCount() const;
bool hasService(const char* uuid) const;
bool hasService(const char* uuid, int index) const;
BLEService service(int index) const;
BLEService service(const char * uuid) const;
BLEService service(const char * uuid, int index) const;
int characteristicCount() const;
bool hasCharacteristic(const char* uuid) const;
bool hasCharacteristic(const char* uuid, int index) const;
BLECharacteristic characteristic(int index) const;
BLECharacteristic characteristic(const char * uuid) const;
BLECharacteristic characteristic(const char * uuid, int index) const;
protected:
friend class ATTClass;
friend class GAPClass;
BLEDevice(uint8_t addressType, uint8_t address[6]);
protected:
friend class GAPClass;
bool hasAddress(uint8_t addressType, uint8_t address[6]);
void setAdvertisementData(uint8_t type, uint8_t eirDataLength, uint8_t eirData[], int8_t rssi);
void setScanResponseData(uint8_t eirDataLength, uint8_t eirData[], int8_t rssi);
bool discovered();
private:
uint8_t _addressType;
uint8_t _address[6];
uint8_t _advertisementTypeMask;
uint8_t _eirDataLength;
uint8_t _eirData[31 * 2];
int8_t _rssi;
};
#endif