forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nRF51822.h
106 lines (83 loc) · 3.74 KB
/
nRF51822.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
#ifndef _NRF_51822_H_
#define _NRF_51822_H_
#ifdef __RFduino__
#include <utility/nrf51822/s110/ble_gatts.h>
#include <utility/nrf51822/s110/ble_gattc.h>
#include <utility/nrf51822/s110/nrf_soc.h>
#else
#include <s110/ble_gatts.h>
#include <s110/ble_gattc.h>
#include <s110/nrf_soc.h>
#endif
#include "BLEDevice.h"
class nRF51822 : public BLEDevice
{
friend class BLEPeripheral;
protected:
struct localCharacteristicInfo {
BLECharacteristic* characteristic;
BLEService* service;
ble_gatts_char_handles_t handles;
bool notifySubscribed;
bool indicateSubscribed;
};
struct remoteServiceInfo {
BLERemoteService* service;
ble_uuid_t uuid;
ble_gattc_handle_range_t handlesRange;
};
struct remoteCharacteristicInfo {
BLERemoteCharacteristic* characteristic;
BLERemoteService* service;
ble_uuid_t uuid;
ble_gatt_char_props_t properties;
uint16_t valueHandle;
};
nRF51822();
virtual ~nRF51822();
virtual void begin(unsigned char advertisementDataType,
unsigned char advertisementDataLength,
const unsigned char* advertisementData,
unsigned char scanDataType,
unsigned char scanDataLength,
const unsigned char* scanData,
BLELocalAttribute** localAttributes,
unsigned char numLocalAttributes,
BLERemoteAttribute** remoteAttributes,
unsigned char numRemoteAttributes);
virtual void poll();
virtual void startAdvertising();
virtual void disconnect();
virtual bool updateCharacteristicValue(BLECharacteristic& characteristic);
virtual bool broadcastCharacteristic(BLECharacteristic& characteristic);
virtual bool canNotifyCharacteristic(BLECharacteristic& characteristic);
virtual bool canIndicateCharacteristic(BLECharacteristic& characteristic);
virtual bool canReadRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool readRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool canWriteRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool writeRemoteCharacteristic(BLERemoteCharacteristic& characteristic, const unsigned char value[], unsigned char length);
virtual bool canSubscribeRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool subscribeRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool canUnsubscribeRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual bool unsubcribeRemoteCharacteristic(BLERemoteCharacteristic& characteristic);
virtual void requestAddress();
virtual void requestTemperature();
virtual void requestBatteryLevel();
private:
unsigned char _advData[31];
unsigned char _advDataLen;
BLECharacteristic* _broadcastCharacteristic;
uint16_t _connectionHandle;
bool _storeAuthStatus;
uint8_t _authStatusBuffer[((sizeof(ble_gap_evt_auth_status_t) + 3) / 4) * 4] __attribute__ ((__aligned__(4)));
ble_gap_evt_auth_status_t* _authStatus;
unsigned char _numLocalCharacteristics;
struct localCharacteristicInfo* _localCharacteristicInfo;
unsigned char _numRemoteServices;
struct remoteServiceInfo* _remoteServiceInfo;
unsigned char _remoteServiceDiscoveryIndex;
unsigned char _numRemoteCharacteristics;
struct remoteCharacteristicInfo* _remoteCharacteristicInfo;
bool _remoteRequestInProgress;
};
#endif