BLECharacteristic allow user set buffer

This commit is contained in:
hathach committed 2019-11-14 13:14:03 +07:00
1 parent 0ab39ca9df
commit d898f17f44
2 files changed
+24 -12

No files matched your search

@@ -53,6 +53,7 @@ void BLECharacteristic::_init(void)
_attr_meta.read_perm = _attr_meta.write_perm = BLE_SECMODE_OPEN;
_attr_meta.vlen = 1;
_attr_meta.vloc = BLE_GATTS_VLOC_STACK;
_userbuf = NULL;
_handles.value_handle = BLE_GATT_HANDLE_INVALID;
_handles.user_desc_handle = BLE_GATT_HANDLE_INVALID;
@@ -133,6 +134,14 @@ void BLECharacteristic::setFixedLen(uint16_t fixed_len)
}
}
// Use application buffer instead of SD stack buffer
void BLECharacteristic::setBuffer(void* buf, uint16_t bufsize)
{
_max_len = bufsize;
_userbuf = buf;
_attr_meta.vloc = buf ? BLE_GATTS_VLOC_USER : BLE_GATTS_VLOC_STACK;
}
void BLECharacteristic::setPermission(BleSecurityMode read_perm, BleSecurityMode write_perm)
{
memcpy(&_attr_meta.read_perm , &read_perm, 1);
@@ -270,7 +279,7 @@ err_t BLECharacteristic::begin(void)
.init_len = (_attr_meta.vlen == 1) ? (uint16_t) 0 : _max_len,
.init_offs = 0,
.max_len = _max_len,
.p_value = NULL
.p_value = _userbuf
};
VERIFY_STATUS( sd_ble_gatts_characteristic_add(BLE_GATT_HANDLE_INVALID, &char_md, &attr_char_value, &_handles) );