add check for characteristic max_len
This commit is contained in:
1 parent
36cfbe0106
commit
4bffc65b9e
2 files changed
+10
-6
No files matched your search
@@ -130,11 +130,11 @@ void setupHRM(void)
|
||||
// B6:7 = UINT16 - RR Internal (1/1024 second resolution)
|
||||
hrmc.setProperties(CHR_PROPS_NOTIFY);
|
||||
hrmc.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
hrmc.setMaxLen(8);
|
||||
hrmc.setMaxLen(2);
|
||||
hrmc.start();
|
||||
|
||||
// Set the characteristic to use 8-bit values, with the sensor connected and detected
|
||||
uint8_t hrmdata[2] = { 0b00000110, 0x40 };
|
||||
uint8_t hrmdata[2] = { 0b00000000, 0x40 };
|
||||
hrmc.write(hrmdata, 2);
|
||||
|
||||
// Configure the Body Sensor Location characteristic
|
||||
|
||||
@@ -355,9 +355,12 @@ err_t BLECharacteristic::write(const char * str)
|
||||
|
||||
err_t BLECharacteristic::write(const uint8_t* data, int len, uint16_t offset)
|
||||
{
|
||||
// could not exceed max len
|
||||
uint16_t actual_len = min16(len, _max_len);
|
||||
|
||||
ble_gatts_value_t value =
|
||||
{
|
||||
.len = (uint16_t) len,
|
||||
.len = (uint16_t) actual_len,
|
||||
.offset = offset,
|
||||
.p_value = (uint8_t*) data
|
||||
};
|
||||
@@ -388,7 +391,7 @@ err_t BLECharacteristic::write(uint8_t num)
|
||||
|
||||
bool BLECharacteristic::notifyEnabled(void)
|
||||
{
|
||||
VERIFY( _properties.notify );
|
||||
VERIFY( _properties.notify && Bluefruit.connected() );
|
||||
uint16_t cccd;
|
||||
ble_gatts_value_t value =
|
||||
{
|
||||
@@ -409,14 +412,15 @@ err_t BLECharacteristic::notify(const uint8_t* data, int len, uint16_t offset)
|
||||
// Whether Txbuf available or not we still update the chars'value
|
||||
(void) Bluefruit.txbuf_get(100);
|
||||
|
||||
uint16_t len16 = (uint16_t) len;
|
||||
// could not exceed max len
|
||||
uint16_t actual_len = min16(len, _max_len);
|
||||
|
||||
ble_gatts_hvx_params_t hvx_params =
|
||||
{
|
||||
.handle = _handles.value_handle,
|
||||
.type = BLE_GATT_HVX_NOTIFICATION,
|
||||
.offset = offset,
|
||||
.p_len = &len16,
|
||||
.p_len = &actual_len,
|
||||
.p_data = (uint8_t*) data,
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user