API clean up
This commit is contained in:
1 parent
701a407d5e
commit
e86556fd8f
4 files changed
+25
-30
No files matched your search
@@ -347,15 +347,12 @@ uint16_t BLECharacteristic::write(const char * str)
|
||||
return write((const uint8_t*) str, strlen(str));
|
||||
}
|
||||
|
||||
uint16_t BLECharacteristic::write(const void* data, int len, uint16_t offset)
|
||||
uint16_t BLECharacteristic::write(const void* data, uint16_t len)
|
||||
{
|
||||
// could not exceed max len
|
||||
uint16_t actual_len = min16(len, _max_len);
|
||||
|
||||
ble_gatts_value_t value =
|
||||
{
|
||||
.len = (uint16_t) actual_len,
|
||||
.offset = offset,
|
||||
.len = min16(len, _max_len), // could not exceed max len
|
||||
.offset = 0 , // TODO gatts long write
|
||||
.p_value = (uint8_t*) data
|
||||
};
|
||||
|
||||
@@ -395,12 +392,12 @@ uint16_t BLECharacteristic::write(uint8_t num)
|
||||
* @param offset offset of value (dfeault is 0)
|
||||
* @return number of read bytes
|
||||
*/
|
||||
uint16_t BLECharacteristic::read(void* buffer, int bufsize, uint16_t offset)
|
||||
uint16_t BLECharacteristic::read(void* buffer, uint16_t bufsize)
|
||||
{
|
||||
ble_gatts_value_t value =
|
||||
{
|
||||
.len = (uint16_t) bufsize,
|
||||
.offset = offset,
|
||||
.len = bufsize,
|
||||
.offset = 0, // TODO gatts long read
|
||||
.p_value = (uint8_t*) buffer
|
||||
};
|
||||
|
||||
@@ -454,12 +451,12 @@ bool BLECharacteristic::notifyEnabled(void)
|
||||
return (cccd & BLE_GATT_HVX_NOTIFICATION);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify(const void* data, int len)
|
||||
bool BLECharacteristic::notify(const void* data, uint16_t len)
|
||||
{
|
||||
VERIFY( _properties.notify );
|
||||
|
||||
// could not exceed max len
|
||||
uint16_t actual_len = min16(len, _max_len);
|
||||
uint16_t remaining = min16(len, _max_len);
|
||||
|
||||
if ( notifyEnabled() )
|
||||
{
|
||||
@@ -470,30 +467,30 @@ bool BLECharacteristic::notify(const void* data, int len)
|
||||
|
||||
const uint8_t* u8data = (const uint8_t*) data;
|
||||
|
||||
while ( actual_len )
|
||||
while ( remaining )
|
||||
{
|
||||
if ( !Bluefruit.Gap.getTxPacket() ) return BLE_ERROR_NO_TX_PACKETS;
|
||||
|
||||
uint16_t packet_len = min16(MTU_MPS, actual_len);
|
||||
uint16_t packet_len = min16(MTU_MPS, remaining);
|
||||
|
||||
ble_gatts_hvx_params_t hvx_params =
|
||||
{
|
||||
.handle = _handles.value_handle,
|
||||
.type = BLE_GATT_HVX_NOTIFICATION,
|
||||
.offset = 0, // TODO more work with offset
|
||||
.offset = 0,
|
||||
.p_len = &packet_len,
|
||||
.p_data = (uint8_t*) u8data,
|
||||
};
|
||||
|
||||
VERIFY_STATUS( sd_ble_gatts_hvx(Bluefruit.connHandle(), &hvx_params), false );
|
||||
|
||||
actual_len -= packet_len;
|
||||
remaining -= packet_len;
|
||||
u8data += packet_len;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
write(data, actual_len);
|
||||
write(data, remaining);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class BLECharacteristic
|
||||
ble_gatts_char_handles_t handles(void);
|
||||
|
||||
/*------------- Write -------------*/
|
||||
uint16_t write(const void* data, int len, uint16_t offset = 0);
|
||||
uint16_t write(const void* data, uint16_t len);
|
||||
uint16_t write(const char * str);
|
||||
|
||||
uint16_t write(int num);
|
||||
@@ -149,14 +149,14 @@ class BLECharacteristic
|
||||
uint16_t write(uint8_t num);
|
||||
|
||||
/*------------- Read -------------*/
|
||||
uint16_t read(void* buffer, int bufsize, uint16_t offset = 0);
|
||||
uint16_t read(void* buffer, uint16_t bufsize);
|
||||
uint16_t read(uint32_t* num);
|
||||
uint16_t read(uint16_t* num);
|
||||
uint16_t read(uint8_t* num);
|
||||
|
||||
/*------------- Notify -------------*/
|
||||
bool notifyEnabled(void);
|
||||
bool notify(const void* data, int len);
|
||||
bool notify(const void* data, uint16_t len);
|
||||
bool notify(const char * str);
|
||||
bool notify(int num);
|
||||
bool notify(uint32_t num);
|
||||
|
||||
@@ -118,12 +118,11 @@ void BLEClientCharacteristic::begin(void)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* READ
|
||||
*------------------------------------------------------------------*/
|
||||
uint16_t BLEClientCharacteristic::read(void* buffer, int bufsize)
|
||||
uint16_t BLEClientCharacteristic::read(void* buffer, uint16_t bufsize)
|
||||
{
|
||||
// TODO implement READ
|
||||
// VERIFY_STATUS( sd_ble_gattc_read(Bluefruit.Central.connHandle(), _chr.handle_value, offset), 0 );
|
||||
|
||||
// return ERROR_NONE;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@@ -137,7 +136,7 @@ err_t BLEClientCharacteristic::_write_and_wait_rsp(ble_gattc_write_params_t* par
|
||||
return xSemaphoreTake(_sem, ms2tick(BLE_GENERIC_TIMEOUT) ) ? ERROR_NONE : NRF_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
uint16_t BLEClientCharacteristic::write_resp(const void* data, int len32)
|
||||
uint16_t BLEClientCharacteristic::write_resp(const void* data, uint16_t len)
|
||||
{
|
||||
// Break into multiple MTU-3 packet
|
||||
// TODO Currently SD132 v2.0 MTU is fixed with max payload = 20
|
||||
@@ -145,7 +144,6 @@ uint16_t BLEClientCharacteristic::write_resp(const void* data, int len32)
|
||||
// For BLE_GATT_OP_PREP_WRITE_REQ, max data is 18 ( 2 byte is used for offset)
|
||||
enum { MTU_MPS = 20 } ;
|
||||
|
||||
uint16_t len = (uint16_t) len32;
|
||||
const bool long_write = (len > MTU_MPS);
|
||||
const uint8_t* u8data = (const uint8_t*) data;
|
||||
|
||||
@@ -184,7 +182,7 @@ uint16_t BLEClientCharacteristic::write_resp(const void* data, int len32)
|
||||
.write_op = BLE_GATT_OP_PREP_WRITE_REQ,
|
||||
.flags = 0,
|
||||
.handle = _chr.handle_value,
|
||||
.offset = len-remaining,
|
||||
.offset = (uint16_t) (len-remaining),
|
||||
.len = packet_len,
|
||||
.p_value = (uint8_t*) u8data
|
||||
};
|
||||
@@ -220,7 +218,7 @@ uint16_t BLEClientCharacteristic::write_resp(const void* data, int len32)
|
||||
return len;
|
||||
}
|
||||
|
||||
uint16_t BLEClientCharacteristic::write(const void* data, int len)
|
||||
uint16_t BLEClientCharacteristic::write(const void* data, uint16_t len)
|
||||
{
|
||||
// Break into multiple MTU-3 packet
|
||||
// TODO Currently SD132 v2.0 MTU is fixed with max payload = 20
|
||||
@@ -228,7 +226,7 @@ uint16_t BLEClientCharacteristic::write(const void* data, int len)
|
||||
enum { MTU_MPS = 20 } ;
|
||||
const uint8_t* u8data = (const uint8_t*) data;
|
||||
|
||||
int remaining = len;
|
||||
uint16_t remaining = len;
|
||||
while( remaining )
|
||||
{
|
||||
// Write CMD consume a TX buffer
|
||||
|
||||
@@ -62,11 +62,11 @@ class BLEClientCharacteristic
|
||||
BLEClientService& parentService(void);
|
||||
|
||||
/*------------- Read -------------*/
|
||||
uint16_t read(void* buffer, int bufsize);
|
||||
uint16_t read(void* buffer, uint16_t bufsize);
|
||||
|
||||
/*------------- Write -------------*/
|
||||
uint16_t write (const void* data, int len);
|
||||
uint16_t write_resp(const void* data, int len);
|
||||
uint16_t write (const void* data, uint16_t len);
|
||||
uint16_t write_resp(const void* data, uint16_t len);
|
||||
|
||||
/*------------- Notify -------------*/
|
||||
bool writeCCCD (uint16_t value);
|
||||
|
||||
Reference in new issue
Block a user