added debugging
Fork of BLE_nRF8001 by
BLE_nRF8001/BLEDescriptor.cpp@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 | #include "Arduino.h" |
RedBearLab | 0:075ea2812998 | 2 | #include "BLEDescriptor.h" |
RedBearLab | 0:075ea2812998 | 3 | |
RedBearLab | 0:075ea2812998 | 4 | BLEDescriptor::BLEDescriptor(const char* uuid, unsigned char valueSize) : |
RedBearLab | 0:075ea2812998 | 5 | BLEAttribute(uuid, BLETypeDescriptor), |
RedBearLab | 0:075ea2812998 | 6 | _valueSize(min(valueSize, BLE_ATTRIBUTE_MAX_VALUE_LENGTH)), |
RedBearLab | 0:075ea2812998 | 7 | _valueLength(0) |
RedBearLab | 0:075ea2812998 | 8 | { |
RedBearLab | 0:075ea2812998 | 9 | _value = (unsigned char*)malloc(this->_valueSize); |
RedBearLab | 0:075ea2812998 | 10 | } |
RedBearLab | 0:075ea2812998 | 11 | |
RedBearLab | 0:075ea2812998 | 12 | BLEDescriptor::BLEDescriptor(const char* uuid, const char* value) : |
RedBearLab | 0:075ea2812998 | 13 | BLEAttribute(uuid, BLETypeDescriptor), |
RedBearLab | 0:075ea2812998 | 14 | _valueSize(min(strlen(value), BLE_ATTRIBUTE_MAX_VALUE_LENGTH)), |
RedBearLab | 0:075ea2812998 | 15 | _valueLength(0) |
RedBearLab | 0:075ea2812998 | 16 | { |
RedBearLab | 0:075ea2812998 | 17 | _value = (unsigned char*)malloc(this->_valueSize); |
RedBearLab | 0:075ea2812998 | 18 | this->setValue(value); |
RedBearLab | 0:075ea2812998 | 19 | } |
RedBearLab | 0:075ea2812998 | 20 | |
RedBearLab | 0:075ea2812998 | 21 | BLEDescriptor::~BLEDescriptor() { |
RedBearLab | 0:075ea2812998 | 22 | if (this->_value) { |
RedBearLab | 0:075ea2812998 | 23 | free(this->_value); |
RedBearLab | 0:075ea2812998 | 24 | } |
RedBearLab | 0:075ea2812998 | 25 | } |
RedBearLab | 0:075ea2812998 | 26 | |
RedBearLab | 0:075ea2812998 | 27 | unsigned char BLEDescriptor::valueSize() const { |
RedBearLab | 0:075ea2812998 | 28 | return this->_valueSize; |
RedBearLab | 0:075ea2812998 | 29 | } |
RedBearLab | 0:075ea2812998 | 30 | |
RedBearLab | 0:075ea2812998 | 31 | const unsigned char* BLEDescriptor::value() const { |
RedBearLab | 0:075ea2812998 | 32 | return this->_value; |
RedBearLab | 0:075ea2812998 | 33 | } |
RedBearLab | 0:075ea2812998 | 34 | |
RedBearLab | 0:075ea2812998 | 35 | unsigned char BLEDescriptor::valueLength() const { |
RedBearLab | 0:075ea2812998 | 36 | return this->_valueLength; |
RedBearLab | 0:075ea2812998 | 37 | } |
RedBearLab | 0:075ea2812998 | 38 | |
RedBearLab | 0:075ea2812998 | 39 | void BLEDescriptor::setValue(const unsigned char value[], unsigned char length) { |
RedBearLab | 0:075ea2812998 | 40 | this->_valueLength = min(length, this->_valueSize); |
RedBearLab | 0:075ea2812998 | 41 | |
RedBearLab | 0:075ea2812998 | 42 | memcpy(this->_value, value, this->_valueLength); |
RedBearLab | 0:075ea2812998 | 43 | } |
RedBearLab | 0:075ea2812998 | 44 | |
RedBearLab | 0:075ea2812998 | 45 | void BLEDescriptor::setValue(const char* value) { |
RedBearLab | 0:075ea2812998 | 46 | this->setValue((const unsigned char *)value, strlen(value)); |
RedBearLab | 0:075ea2812998 | 47 | } |