added debugging
Fork of BLE_nRF8001 by
BLE_nRF8001/BLECharacteristic.h@2:7805a5595aab, 2014-11-10 (annotated)
- Committer:
- jn80842
- Date:
- Mon Nov 10 01:24:23 2014 +0000
- Revision:
- 2:7805a5595aab
- Parent:
- 0:075ea2812998
just added debugging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RedBearLab | 0:075ea2812998 | 1 | #ifndef _BLE_CHARACTERISTIC_H_ |
RedBearLab | 0:075ea2812998 | 2 | #define _BLE_CHARACTERISTIC_H_ |
RedBearLab | 0:075ea2812998 | 3 | |
RedBearLab | 0:075ea2812998 | 4 | #include "BLEAttribute.h" |
RedBearLab | 0:075ea2812998 | 5 | |
RedBearLab | 0:075ea2812998 | 6 | enum BLEProperty { |
RedBearLab | 0:075ea2812998 | 7 | BLERead = 0x02, |
RedBearLab | 0:075ea2812998 | 8 | BLEWriteWithoutResponse = 0x04, |
RedBearLab | 0:075ea2812998 | 9 | BLEWrite = 0x08, |
RedBearLab | 0:075ea2812998 | 10 | BLENotify = 0x10, |
RedBearLab | 0:075ea2812998 | 11 | BLEIndicate = 0x20 |
RedBearLab | 0:075ea2812998 | 12 | }; |
RedBearLab | 0:075ea2812998 | 13 | |
RedBearLab | 0:075ea2812998 | 14 | enum BLECharacteristicEvent { |
RedBearLab | 0:075ea2812998 | 15 | BLEWritten = 0, |
RedBearLab | 0:075ea2812998 | 16 | BLESubscribed = 1, |
RedBearLab | 0:075ea2812998 | 17 | BLEUnsubscribed = 2 |
RedBearLab | 0:075ea2812998 | 18 | }; |
RedBearLab | 0:075ea2812998 | 19 | |
RedBearLab | 0:075ea2812998 | 20 | class BLECentral; |
RedBearLab | 0:075ea2812998 | 21 | class BLECharacteristic; |
RedBearLab | 0:075ea2812998 | 22 | |
RedBearLab | 0:075ea2812998 | 23 | typedef void (*BLECharacteristicEventHandler)(BLECentral& central, BLECharacteristic& characteristic); |
RedBearLab | 0:075ea2812998 | 24 | |
RedBearLab | 0:075ea2812998 | 25 | class BLECharacteristicValueChangeListener |
RedBearLab | 0:075ea2812998 | 26 | { |
RedBearLab | 0:075ea2812998 | 27 | public: |
RedBearLab | 0:075ea2812998 | 28 | virtual bool characteristicValueChanged(BLECharacteristic& characteristic) = 0; |
RedBearLab | 0:075ea2812998 | 29 | virtual bool canNotifyCharacteristic(BLECharacteristic& characteristic) = 0; |
RedBearLab | 0:075ea2812998 | 30 | virtual bool canIndicateCharacteristic(BLECharacteristic& characteristic) = 0; |
RedBearLab | 0:075ea2812998 | 31 | }; |
RedBearLab | 0:075ea2812998 | 32 | |
RedBearLab | 0:075ea2812998 | 33 | class BLECharacteristic : public BLEAttribute |
RedBearLab | 0:075ea2812998 | 34 | { |
RedBearLab | 0:075ea2812998 | 35 | friend class BLEPeripheral; |
RedBearLab | 0:075ea2812998 | 36 | |
RedBearLab | 0:075ea2812998 | 37 | public: |
RedBearLab | 0:075ea2812998 | 38 | BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize, bool fixedLength = false); |
RedBearLab | 0:075ea2812998 | 39 | BLECharacteristic(const char* uuid, unsigned char properties, const char* value, bool fixedLength = false); |
RedBearLab | 0:075ea2812998 | 40 | |
RedBearLab | 0:075ea2812998 | 41 | virtual ~BLECharacteristic(); |
RedBearLab | 0:075ea2812998 | 42 | |
RedBearLab | 0:075ea2812998 | 43 | unsigned char properties() const; |
RedBearLab | 0:075ea2812998 | 44 | |
RedBearLab | 0:075ea2812998 | 45 | unsigned char valueSize() const; |
RedBearLab | 0:075ea2812998 | 46 | const unsigned char* value() const; |
RedBearLab | 0:075ea2812998 | 47 | unsigned char valueLength() const; |
RedBearLab | 0:075ea2812998 | 48 | bool fixedLength() const; |
RedBearLab | 0:075ea2812998 | 49 | |
RedBearLab | 0:075ea2812998 | 50 | bool setValue(const unsigned char value[], unsigned char length); |
RedBearLab | 0:075ea2812998 | 51 | bool setValue(const char* value); |
RedBearLab | 0:075ea2812998 | 52 | |
RedBearLab | 0:075ea2812998 | 53 | bool written(); |
RedBearLab | 0:075ea2812998 | 54 | bool subscribed(); |
RedBearLab | 0:075ea2812998 | 55 | bool canNotify(); |
RedBearLab | 0:075ea2812998 | 56 | bool canIndicate(); |
RedBearLab | 0:075ea2812998 | 57 | |
RedBearLab | 0:075ea2812998 | 58 | void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler eventHandler); |
RedBearLab | 0:075ea2812998 | 59 | |
RedBearLab | 0:075ea2812998 | 60 | protected: |
RedBearLab | 0:075ea2812998 | 61 | void setValue(BLECentral& central, const unsigned char value[], unsigned char length); |
RedBearLab | 0:075ea2812998 | 62 | void setSubscribed(BLECentral& central, bool written); |
RedBearLab | 0:075ea2812998 | 63 | |
RedBearLab | 0:075ea2812998 | 64 | void setValueChangeListener(BLECharacteristicValueChangeListener& listener); |
RedBearLab | 0:075ea2812998 | 65 | |
RedBearLab | 0:075ea2812998 | 66 | private: |
RedBearLab | 0:075ea2812998 | 67 | unsigned char _properties; |
RedBearLab | 0:075ea2812998 | 68 | unsigned char _valueSize; |
RedBearLab | 0:075ea2812998 | 69 | unsigned char* _value; |
RedBearLab | 0:075ea2812998 | 70 | unsigned char _valueLength; |
RedBearLab | 0:075ea2812998 | 71 | bool _fixedLength; |
RedBearLab | 0:075ea2812998 | 72 | |
RedBearLab | 0:075ea2812998 | 73 | bool _written; |
RedBearLab | 0:075ea2812998 | 74 | bool _subscribed; |
RedBearLab | 0:075ea2812998 | 75 | |
RedBearLab | 0:075ea2812998 | 76 | BLECharacteristicValueChangeListener* _listener; |
RedBearLab | 0:075ea2812998 | 77 | BLECharacteristicEventHandler _eventHandlers[3]; |
RedBearLab | 0:075ea2812998 | 78 | }; |
RedBearLab | 0:075ea2812998 | 79 | |
RedBearLab | 0:075ea2812998 | 80 | #endif |