forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nRF8001.h
112 lines (85 loc) · 3.95 KB
/
nRF8001.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
#ifndef _NRF_8001_H_
#define _NRF_8001_H_
#include "Arduino.h"
#include <utility/lib_aci.h>
#include "BLEDevice.h"
class nRF8001 : protected BLEDevice
{
friend class BLEPeripheral;
protected:
struct localPipeInfo {
BLECharacteristic* characteristic;
unsigned short valueHandle;
unsigned short configHandle;
unsigned char advPipe;
unsigned char txPipe;
unsigned char txAckPipe;
unsigned char rxPipe;
unsigned char rxAckPipe;
unsigned char setPipe;
bool txPipeOpen;
bool txAckPipeOpen;
};
struct remotePipeInfo {
BLERemoteCharacteristic* characteristic;
unsigned char txPipe;
unsigned char txAckPipe;
unsigned char rxPipe;
unsigned char rxAckPipe;
unsigned char rxReqPipe;
};
nRF8001(unsigned char req, unsigned char rdy, unsigned char rst);
virtual ~nRF8001();
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 end();
virtual bool setTxPower(int txPower);
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:
void waitForSetupMode();
void sendSetupMessage(hal_aci_data_t* data, bool withCrc = false);
void sendSetupMessage(hal_aci_data_t* setupMsg, unsigned char type, unsigned short& offset, bool withCrc = false);
struct localPipeInfo* localPipeInfoForCharacteristic(BLECharacteristic& characteristic);
struct remotePipeInfo* remotePipeInfoForCharacteristic(BLERemoteCharacteristic& characteristic);
private:
struct aci_state_t _aciState;
hal_aci_evt_t _aciData;
struct localPipeInfo* _localPipeInfo;
unsigned char _numLocalPipeInfo;
unsigned char _broadcastPipe;
bool _timingChanged;
bool _closedPipesCleared;
bool _remoteServicesDiscovered;
struct remotePipeInfo* _remotePipeInfo;
unsigned char _numRemotePipeInfo;
unsigned int _dynamicDataOffset;
unsigned char _dynamicDataSequenceNo;
bool _storeDynamicData;
unsigned short _crcSeed;
};
#endif