added debugging
Fork of BLE_nRF8001 by
Embed:
(wiki syntax)
Show/hide line numbers
BLECharacteristic.h
00001 #ifndef _BLE_CHARACTERISTIC_H_ 00002 #define _BLE_CHARACTERISTIC_H_ 00003 00004 #include "BLEAttribute.h" 00005 00006 enum BLEProperty { 00007 BLERead = 0x02, 00008 BLEWriteWithoutResponse = 0x04, 00009 BLEWrite = 0x08, 00010 BLENotify = 0x10, 00011 BLEIndicate = 0x20 00012 }; 00013 00014 enum BLECharacteristicEvent { 00015 BLEWritten = 0, 00016 BLESubscribed = 1, 00017 BLEUnsubscribed = 2 00018 }; 00019 00020 class BLECentral; 00021 class BLECharacteristic; 00022 00023 typedef void (*BLECharacteristicEventHandler)(BLECentral& central, BLECharacteristic& characteristic); 00024 00025 class BLECharacteristicValueChangeListener 00026 { 00027 public: 00028 virtual bool characteristicValueChanged(BLECharacteristic& characteristic) = 0; 00029 virtual bool canNotifyCharacteristic(BLECharacteristic& characteristic) = 0; 00030 virtual bool canIndicateCharacteristic(BLECharacteristic& characteristic) = 0; 00031 }; 00032 00033 class BLECharacteristic : public BLEAttribute 00034 { 00035 friend class BLEPeripheral; 00036 00037 public: 00038 BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize, bool fixedLength = false); 00039 BLECharacteristic(const char* uuid, unsigned char properties, const char* value, bool fixedLength = false); 00040 00041 virtual ~BLECharacteristic(); 00042 00043 unsigned char properties() const; 00044 00045 unsigned char valueSize() const; 00046 const unsigned char* value() const; 00047 unsigned char valueLength() const; 00048 bool fixedLength() const; 00049 00050 bool setValue(const unsigned char value[], unsigned char length); 00051 bool setValue(const char* value); 00052 00053 bool written(); 00054 bool subscribed(); 00055 bool canNotify(); 00056 bool canIndicate(); 00057 00058 void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler eventHandler); 00059 00060 protected: 00061 void setValue(BLECentral& central, const unsigned char value[], unsigned char length); 00062 void setSubscribed(BLECentral& central, bool written); 00063 00064 void setValueChangeListener(BLECharacteristicValueChangeListener& listener); 00065 00066 private: 00067 unsigned char _properties; 00068 unsigned char _valueSize; 00069 unsigned char* _value; 00070 unsigned char _valueLength; 00071 bool _fixedLength; 00072 00073 bool _written; 00074 bool _subscribed; 00075 00076 BLECharacteristicValueChangeListener* _listener; 00077 BLECharacteristicEventHandler _eventHandlers[3]; 00078 }; 00079 00080 #endif
Generated on Tue Jul 12 2022 15:15:46 by 1.7.2