add BLECharacteristic::setTempMemory() to explicitly exclude chars from managing table
This commit is contained in:
1 parent
a6861aee31
commit
5766aa3d10
5 files changed
+26
-4
No files matched your search
@@ -38,6 +38,7 @@
|
||||
|
||||
void BLECharacteristic::init(void)
|
||||
{
|
||||
_is_temp = false;
|
||||
varclr(&_properties);
|
||||
_descriptor = NULL;
|
||||
_max_len = BLE_GATTS_VAR_ATTR_LEN_MAX;
|
||||
@@ -90,6 +91,18 @@ void BLECharacteristic::setUuid(uint8_t const uuid128[])
|
||||
uuid.set(uuid128);
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be set when Charactertistic is declared locally (e.g insdie function)
|
||||
* and is not last throughout programs. Useful for one-shot set-and-forget
|
||||
* Characteristics such as read-only one. Where there is no need for interactions
|
||||
* later on. This call will prevent the Characteristics to be hooked into
|
||||
* managing chars list of AdafruitBluefruit
|
||||
*/
|
||||
void BLECharacteristic::setTempMemory(void)
|
||||
{
|
||||
_is_temp = true;
|
||||
}
|
||||
|
||||
void BLECharacteristic::setProperties(uint8_t prop)
|
||||
{
|
||||
memcpy(&_properties, &prop, 1);
|
||||
@@ -259,9 +272,10 @@ err_t BLECharacteristic::start(void)
|
||||
(void) ref_hdl; // not used
|
||||
}
|
||||
|
||||
// Only register to Bluefruit when having callback support
|
||||
// The Characteristic must not be temporary memory aka local variable
|
||||
if (_rd_authorize_cb || _wr_authorize_cb || _wr_cb)
|
||||
// Currently Only register to Bluefruit when having callback support
|
||||
// And The Characteristic must not be temporary memory aka local variable
|
||||
if ( !_is_temp &&
|
||||
(_rd_authorize_cb || _wr_authorize_cb || _wr_cb || _properties.notify || _properties.indicate) )
|
||||
{
|
||||
(void) Bluefruit._registerCharacteristic(this);
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ class BLECharacteristic
|
||||
typedef void (*write_cb_t) (BLECharacteristic& chr, ble_gatts_evt_write_t* request);
|
||||
|
||||
protected:
|
||||
bool _is_temp;
|
||||
|
||||
ble_gatt_char_props_t _properties;
|
||||
const char* _descriptor;
|
||||
uint16_t _max_len;
|
||||
@@ -116,11 +118,12 @@ class BLECharacteristic
|
||||
return *_service;
|
||||
}
|
||||
|
||||
|
||||
void setUuid(uint16_t uuid16);
|
||||
void setUuid(uint8_t const uuid128[]);
|
||||
|
||||
// Configure
|
||||
void setTempMemory(void);
|
||||
|
||||
void setProperties(uint8_t prop);
|
||||
void setPermission(BleSecurityMode read_perm, BleSecurityMode write_perm);
|
||||
|
||||
|
||||
@@ -167,6 +167,7 @@ err_t BLEDfu::start(void)
|
||||
|
||||
// No need to keep packet & revision characteristics
|
||||
BLECharacteristic chr_packet(UUID128_CHR_DFU_PACKET);
|
||||
chr_packet.setTempMemory();
|
||||
chr_packet.setProperties(CHR_PROPS_WRITE_WO_RESP);
|
||||
chr_packet.setMaxLen(20);
|
||||
VERIFY_STATUS( chr_packet.start() );
|
||||
@@ -177,6 +178,7 @@ err_t BLEDfu::start(void)
|
||||
VERIFY_STATUS( _chr_control.start() );
|
||||
|
||||
BLECharacteristic chr_revision(UUID128_CHR_DFU_REVISON);
|
||||
chr_packet.setTempMemory();
|
||||
chr_revision.setProperties(CHR_PROPS_READ);
|
||||
chr_revision.setFixedLen(2);
|
||||
VERIFY_STATUS( chr_revision.start());
|
||||
|
||||
@@ -97,6 +97,7 @@ err_t BLEDis::start(void)
|
||||
if ( _strarr[i] != NULL )
|
||||
{
|
||||
BLECharacteristic chars(UUID16_CHR_MODEL_NUMBER_STRING+i);
|
||||
chars.setTempMemory();
|
||||
|
||||
chars.setProperties(CHR_PROPS_READ);
|
||||
chars.setFixedLen(strlen(_strarr[i]));
|
||||
|
||||
@@ -315,6 +315,7 @@ err_t BLEHidGeneric::start(void)
|
||||
|
||||
// Report Map (HID Report Descriptor)
|
||||
BLECharacteristic report_map(UUID16_CHR_REPORT_MAP);
|
||||
report_map.setTempMemory();
|
||||
report_map.setProperties(CHR_PROPS_READ);
|
||||
report_map.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
report_map.setFixedLen(_report_map_len);
|
||||
@@ -350,6 +351,7 @@ err_t BLEHidGeneric::start(void)
|
||||
|
||||
// HID Info
|
||||
BLECharacteristic hid_info(UUID16_CHR_HID_INFORMATION);
|
||||
hid_info.setTempMemory();
|
||||
hid_info.setProperties(CHR_PROPS_READ);
|
||||
hid_info.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
hid_info.setFixedLen(sizeof(_hid_info));
|
||||
|
||||
Reference in new issue
Block a user