-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathBLECharacteristic.h
137 lines (105 loc) · 4.09 KB
/
BLECharacteristic.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
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_CHARACTERISTIC_H_
#define _BLE_CHARACTERISTIC_H_
#include <stdint.h>
#include "BLEDescriptor.h"
enum BLECharacteristicEvent {
BLESubscribed = 0,
BLEUnsubscribed = 1,
//BLERead = 2, // defined in BLEProperties.h
BLEWritten = 3,
BLEUpdated = BLEWritten, // alias
BLECharacteristicEventLast
};
class BLECharacteristic;
class BLEDevice;
#ifdef ARDUINO_ARCH_MBED
#include <mbed.h>
typedef mbed::Callback<void (BLEDevice device, BLECharacteristic characteristic)> BLECharacteristicEventHandler;
#else
typedef void (*BLECharacteristicEventHandler)(BLEDevice device, BLECharacteristic characteristic);
#endif
class BLELocalCharacteristic;
class BLERemoteCharacteristic;
class BLECharacteristic {
public:
BLECharacteristic();
BLECharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength = false);
BLECharacteristic(const char* uuid, uint16_t permissions, const char* value);
BLECharacteristic(const BLECharacteristic& other);
virtual ~BLECharacteristic();
const char* uuid() const;
uint8_t properties() const;
int valueSize() const;
const uint8_t* value() const;
int valueLength() const;
uint8_t operator[] (int offset) const;
int readValue(uint8_t value[], int length);
int readValue(void* value, int length);
int readValue(uint8_t& value);
int readValue(int8_t& value);
int readValue(uint16_t& value);
int readValue(int16_t& value);
int readValue(uint32_t& value);
int readValue(int32_t& value);
int writeValue(const uint8_t value[], int length, bool withResponse = true);
int writeValue(const void* value, int length, bool withResponse = true);
int writeValue(const char* value, bool withResponse = true);
int writeValue(uint8_t value, bool withResponse = true);
int writeValue(int8_t value, bool withResponse = true);
int writeValue(uint16_t value, bool withResponse = true);
int writeValue(int16_t value, bool withResponse = true);
int writeValue(uint32_t value, bool withResponse = true);
int writeValue(int32_t value, bool withResponse = true);
// deprecated, use writeValue(...)
int setValue(const uint8_t value[], int length) { return writeValue(value, length); }
int setValue(const char* value) { return writeValue(value); }
int broadcast();
bool written();
bool subscribed();
bool valueUpdated();
void addDescriptor(BLEDescriptor& descriptor);
operator bool() const;
void setEventHandler(int event, BLECharacteristicEventHandler eventHandler);
int descriptorCount() const;
bool hasDescriptor(const char* uuid) const;
bool hasDescriptor(const char* uuid, int index) const;
BLEDescriptor descriptor(int index) const;
BLEDescriptor descriptor(const char * uuid) const;
BLEDescriptor descriptor(const char * uuid, int index) const;
bool canRead();
bool read();
bool canWrite();
bool canSubscribe();
bool subscribe();
bool canUnsubscribe();
bool unsubscribe();
protected:
friend class BLELocalCharacteristic;
friend class BLELocalService;
BLECharacteristic(BLELocalCharacteristic* local);
BLELocalCharacteristic* local();
protected:
friend class BLEDevice;
friend class BLEService;
friend class BLERemoteCharacteristic;
BLECharacteristic(BLERemoteCharacteristic* remote);
private:
BLELocalCharacteristic* _local;
BLERemoteCharacteristic* _remote;
};
#endif