implement HAP write value and read value response
improve debug visibility
This commit is contained in:
1 parent
3315199da3
commit
4970eb116c
13 files changed
+242
-121
No files matched your search
@@ -115,7 +115,7 @@
|
||||
// DEBUG HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_DEBUG == 2
|
||||
#define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#define malloc_named( name, size ) ({ cprintf("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#else
|
||||
#define malloc_named( name, size ) malloc ( size )
|
||||
#endif
|
||||
@@ -123,17 +123,19 @@
|
||||
int cprintf(const char * format, ...);
|
||||
|
||||
#if CFG_DEBUG
|
||||
#define LOG_LV1(...) ADALOG(__VA_ARGS__)
|
||||
#define LOG_LV1(...) ADALOG(__VA_ARGS__)
|
||||
#define LOG_LV1_BUFFER(...) ADALOG_BUFFER(__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_LV1(...)
|
||||
#define LOG_LV1_BUFFER(...)
|
||||
#endif
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
#define LOG_LV2(...) ADALOG(__VA_ARGS__)
|
||||
#define PRINT2_BUFFER PRINT_BUFFER
|
||||
#define LOG_LV2(...) ADALOG(__VA_ARGS__)
|
||||
#define LOG_LV2_BUFFER(...) ADALOG_BUFFER(__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_LV2(...)
|
||||
#define PRINT2_BUFFER(...)
|
||||
#define LOG_LV2_BUFFER(...)
|
||||
#endif
|
||||
|
||||
#if CFG_DEBUG
|
||||
@@ -162,11 +164,17 @@ int cprintf(const char * format, ...);
|
||||
|
||||
#define ADALOG(tag, ...) \
|
||||
do { \
|
||||
cprintf("[%-5s] ", #tag);\
|
||||
if ( tag ) cprintf("[%-6s] ", tag);\
|
||||
cprintf(__VA_ARGS__);\
|
||||
cprintf("\n");\
|
||||
}while(0)
|
||||
|
||||
#define ADALOG_BUFFER(_tag, _buf, _n) \
|
||||
do {\
|
||||
if ( _tag ) cprintf("[%-6s] ", _tag);\
|
||||
dbgDumpMemory(_buf, 1, _n, true);\
|
||||
}while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define PRINT_LOCATION()
|
||||
|
||||
@@ -170,6 +170,54 @@ void dbgPrintVersion(void)
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Helper function to display memory contents in a friendly format
|
||||
*/
|
||||
/******************************************************************************/
|
||||
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset)
|
||||
{
|
||||
uint8_t const *buf8 = (uint8_t const *) buf;
|
||||
|
||||
char format[] = "%00lX";
|
||||
format[2] += 2*size;
|
||||
|
||||
char offset_fmt[] = "%02lX: ";
|
||||
|
||||
if ( count*size > UINT8_MAX ) format[2] *= 2;
|
||||
if ( count*size > UINT16_MAX ) format[2] *= 2;
|
||||
|
||||
const uint8_t item_per_line = 16 / size;
|
||||
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
uint32_t value=0;
|
||||
|
||||
// Print address
|
||||
if ( i%item_per_line == 0 )
|
||||
{
|
||||
if ( i != 0 ) Serial.println();
|
||||
|
||||
// print offset or absolute address
|
||||
if (printOffset)
|
||||
{
|
||||
Serial.printf(offset_fmt, 16*i/item_per_line);
|
||||
}else
|
||||
{
|
||||
Serial.printf("%08lX:", (uint32_t) buf8);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&value, buf8, size);
|
||||
buf8 += size;
|
||||
|
||||
Serial.print(' ');
|
||||
Serial.printf(format, value);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/*
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ static inline int dbgHeapFree(void)
|
||||
}
|
||||
|
||||
void dbgMemInfo(void);
|
||||
|
||||
void dbgPrintVersion(void);
|
||||
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset);
|
||||
|
||||
#endif
|
||||
@@ -37,6 +37,13 @@
|
||||
#include <bluefruit.h>
|
||||
#include "BLEHomekit.h"
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
static const char* hap_opcode_str[] =
|
||||
{
|
||||
"", "Signature Read", "Write", "Read", "Timed Write", "Execute Write", "Service Signature Read"
|
||||
};
|
||||
#endif
|
||||
|
||||
BLEUuid HAPCharacteristic::_g_uuid_cid(HAP_UUID_DSC_CHARACTERISTIC_ID);
|
||||
|
||||
|
||||
@@ -52,8 +59,13 @@ HAPCharacteristic::HAPCharacteristic(BLEUuid bleuuid, uint8_t format, uint16_t u
|
||||
_cid = 0;
|
||||
_hap_props = 0;
|
||||
|
||||
_value = NULL;
|
||||
_vallen = 0;
|
||||
|
||||
_resp_len = 0;
|
||||
_tid = 0;
|
||||
|
||||
// Need at least decent length for HAP Procedure
|
||||
_max_len = 100;
|
||||
|
||||
setPresentationFormatDescriptor(format, 0, unit, 1, 0);
|
||||
}
|
||||
@@ -115,16 +127,62 @@ err_t HAPCharacteristic::_addChrIdDescriptor(void)
|
||||
return addDescriptor(_g_uuid_cid, &_cid, sizeof(_cid), SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
}
|
||||
|
||||
uint16_t HAPCharacteristic::writeHapValue(const void* data, uint16_t len)
|
||||
{
|
||||
free(_value);
|
||||
|
||||
_vallen = len;
|
||||
_value = rtos_malloc(len);
|
||||
VERIFY(_value, 0);
|
||||
|
||||
memcpy(_value, data, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint16_t HAPCharacteristic::writeHapValue(const char* str)
|
||||
{
|
||||
return writeHapValue((const void*) str, strlen(str));
|
||||
}
|
||||
|
||||
uint16_t HAPCharacteristic::writeHapValue(uint32_t num)
|
||||
{
|
||||
uint8_t len;
|
||||
|
||||
// determine len by format type
|
||||
switch ( _format_desc.format )
|
||||
{
|
||||
case BLE_GATT_CPF_FORMAT_UINT8:
|
||||
case BLE_GATT_CPF_FORMAT_BOOLEAN:
|
||||
len = 1;
|
||||
break;
|
||||
|
||||
case BLE_GATT_CPF_FORMAT_UINT16:
|
||||
len = 2;
|
||||
break;
|
||||
|
||||
case BLE_GATT_CPF_FORMAT_UINT32:
|
||||
len = 4;
|
||||
break;
|
||||
|
||||
default: len = 0; break;
|
||||
}
|
||||
|
||||
VERIFY(len, 0);
|
||||
|
||||
return writeHapValue(&num, len);
|
||||
}
|
||||
|
||||
HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[], uint8_t count)
|
||||
{
|
||||
// Determine body len, including the len's bytes
|
||||
uint8_t body_len = 2;
|
||||
// Determine body len, does not to include 2 byte length itself
|
||||
uint8_t body_len = 0;
|
||||
for(uint8_t i=0; i <count ; i++)
|
||||
{
|
||||
body_len += tlv_para[i].len + 2;
|
||||
}
|
||||
|
||||
HAPResponse_t* hap_resp = (HAPResponse_t*) rtos_malloc(sizeof(HAPResponseHeader_t) + body_len);
|
||||
HAPResponse_t* hap_resp = (HAPResponse_t*) rtos_malloc(sizeof(HAPResponseHeader_t) + 2 + body_len);
|
||||
VERIFY( hap_resp != NULL, NULL );
|
||||
|
||||
/*------------- Header -------------*/
|
||||
@@ -133,8 +191,7 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
|
||||
hap_resp->header.control.type = HAP_PDU_RESPONSE;
|
||||
hap_resp->header.tid = tid;
|
||||
hap_resp->header.status = status;
|
||||
|
||||
hap_resp->body_len = (count ? body_len : 0);
|
||||
hap_resp->body_len = body_len;
|
||||
|
||||
/*------------- Serialize Data -------------*/
|
||||
uint8_t* pdata = hap_resp->body_data;
|
||||
@@ -150,12 +207,51 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
|
||||
return hap_resp;
|
||||
}
|
||||
|
||||
void reverse_uuid128(uint8_t const in[16], uint8_t out[16])
|
||||
HAPResponse_t* HAPCharacteristic::processChrSignatureRead(HAPRequest_t* hap_req)
|
||||
{
|
||||
for(uint8_t i=0; i<16; i++)
|
||||
uint16_t svc_id = ((HAPService*)_service)->getSvcId();
|
||||
|
||||
// ble_gatts_char_pf_t is not packed struct
|
||||
struct ATTR_PACKED
|
||||
{
|
||||
out[i] = in[15-i];
|
||||
}
|
||||
uint8_t format;
|
||||
int8_t exponent;
|
||||
uint16_t unit;
|
||||
uint8_t name_space;
|
||||
uint16_t desc;
|
||||
}fmt_desc =
|
||||
{
|
||||
.format = _format_desc.format,
|
||||
.exponent = _format_desc.exponent,
|
||||
.unit = _format_desc.unit,
|
||||
.name_space = _format_desc.name_space,
|
||||
.desc = _format_desc.desc
|
||||
};
|
||||
|
||||
/* Return <Chr Type, Chr ID, Svc Type, Svc ID, Meta Descriptors>
|
||||
* Where descriptors are:
|
||||
* - Gatt Usr String, Gatt Format Desc, Gatt Valid Range
|
||||
* - Hap Properties, Hap step value, Hap valid values, Hap valid Range
|
||||
*/
|
||||
TLV8_t tlv_para[] =
|
||||
{
|
||||
{ .type = HAP_PARAM_CHR_TYPE, .len = 16, .value = uuid._uuid128 },
|
||||
{ .type = HAP_PARAM_CHR_ID , .len = 2 , .value = &_cid },
|
||||
{ .type = HAP_PARAM_SVC_TYPE, .len = 16, .value = _service->uuid._uuid128 },
|
||||
{ .type = HAP_PARAM_SVC_ID , .len = 2 , .value = &svc_id },
|
||||
// Descriptors
|
||||
{ .type = HAP_PARAM_HAP_CHR_PROPERTIES_DESC, .len = 2 , .value = &_hap_props },
|
||||
{ .type = HAP_PARAM_GATT_FORMAT_DESC , .len = sizeof(fmt_desc) , .value = &fmt_desc },
|
||||
};
|
||||
|
||||
return createHapResponse(hap_req->header.tid, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
|
||||
}
|
||||
|
||||
HAPResponse_t* HAPCharacteristic::processChrRead(HAPRequest_t* hap_req)
|
||||
{
|
||||
TLV8_t tlv_para = { .type = HAP_PARAM_VALUE, .len = _vallen, .value = _value };
|
||||
|
||||
return createHapResponse(hap_req->header.tid, HAP_STATUS_SUCCESS, &tlv_para, 1);
|
||||
}
|
||||
|
||||
void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
@@ -171,8 +267,8 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
{
|
||||
ble_gatts_evt_write_t * gatt_req = &event->evt.gatts_evt.params.authorize_request.request.write;
|
||||
|
||||
LOG_LV2(GATTS, "Write Op = %d, uuid = 0x%04X", gatt_req->op, gatt_req->uuid.uuid);
|
||||
PRINT2_BUFFER(gatt_req->data, gatt_req->len);
|
||||
LOG_LV2("GATTS", "Write Op = %d, uuid = 0x%04X", gatt_req->op, gatt_req->uuid.uuid);
|
||||
LOG_LV2_BUFFER(NULL, gatt_req->data, gatt_req->len);
|
||||
|
||||
HAPRequest_t* hap_req = (HAPRequest_t*) gatt_req->data;
|
||||
HAPResponse_t* hap_resp = NULL;
|
||||
@@ -191,8 +287,6 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
}
|
||||
};
|
||||
|
||||
_tid = hap_req->header.tid;
|
||||
|
||||
if (hap_req->header.control.type != HAP_PDU_REQUEST)
|
||||
{
|
||||
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_UNSUPPORTED_PDU, NULL, 0);
|
||||
@@ -202,48 +296,27 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_INVALID_INSTANCE_ID, NULL, 0);
|
||||
}else
|
||||
{
|
||||
LOG_LV2(HAP, "Opcode = %d", hap_req->header.opcode);
|
||||
LOG_LV2("HAP", "%s request", hap_opcode_str[hap_req->header.opcode]);
|
||||
switch(hap_req->header.opcode)
|
||||
{
|
||||
/* Return <Chr Type, Svc Type, Svc ID, Meta Descriptors>
|
||||
* Where descriptors are:
|
||||
* - Gatt Usr String, Gatt Format Desc, Gatt Valid Range
|
||||
* - Hap Properties, Hap step value, Hap valid values, Hap valid Range
|
||||
*/
|
||||
case HAP_OPCODE_CHR_SIGNATURE_READ:
|
||||
{
|
||||
uint16_t svc_id = ((HAPService*)_service)->getSvcId();
|
||||
hap_resp = processChrSignatureRead(hap_req);
|
||||
break;
|
||||
|
||||
// ble_gatts_char_pf_t is not packed struct
|
||||
struct ATTR_PACKED
|
||||
{
|
||||
uint8_t format;
|
||||
int8_t exponent;
|
||||
uint16_t unit;
|
||||
uint8_t name_space;
|
||||
uint16_t desc;
|
||||
}fmt_desc =
|
||||
{
|
||||
.format = _format_desc.format,
|
||||
.exponent = _format_desc.exponent,
|
||||
.unit = _format_desc.unit,
|
||||
.name_space = _format_desc.name_space,
|
||||
.desc = _format_desc.desc
|
||||
};
|
||||
case HAP_OPCODE_CHR_WRITE:
|
||||
break;
|
||||
|
||||
TLV8_t tlv_para[] =
|
||||
{
|
||||
{ .type = HAP_PARAM_CHR_TYPE, .len = 16, .value = uuid._uuid128 },
|
||||
// { .type = HAP_PARAM_CHR_ID , .len = 2 , .value = &_cid },
|
||||
{ .type = HAP_PARAM_SVC_TYPE, .len = 16, .value = _service->uuid._uuid128 },
|
||||
{ .type = HAP_PARAM_SVC_ID , .len = 2 , .value = &svc_id },
|
||||
// Descriptors
|
||||
{ .type = HAP_PARAM_HAP_CHR_PROPERTIES_DESC, .len = 2 , .value = &_hap_props },
|
||||
{ .type = HAP_PARAM_GATT_FORMAT_DESC , .len = sizeof(fmt_desc) , .value = &fmt_desc },
|
||||
};
|
||||
case HAP_OPCODE_CHR_READ:
|
||||
hap_resp = processChrRead(hap_req);
|
||||
break;
|
||||
|
||||
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
|
||||
}
|
||||
case HAP_OPCODE_CHR_TIMED_WRITE:
|
||||
break;
|
||||
|
||||
case HAP_OPCODE_CHR_EXECUTE_WRITE:
|
||||
break;
|
||||
|
||||
case HAP_OPCODE_SVC_SIGNATURE_READ:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -254,7 +327,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
|
||||
if ( hap_resp )
|
||||
{
|
||||
reply.params.write.len = _resp_len = sizeof(HAPResponseHeader_t) + hap_resp->body_len;
|
||||
reply.params.write.len = _resp_len = sizeof(HAPResponseHeader_t) + 2 + hap_resp->body_len;
|
||||
reply.params.write.p_data = (uint8_t*) hap_resp;
|
||||
}else
|
||||
{
|
||||
@@ -262,7 +335,8 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES;
|
||||
}
|
||||
|
||||
PRINT2_BUFFER(hap_resp, reply.params.write.len);
|
||||
LOG_LV2("HAP", "Response");
|
||||
LOG_LV2_BUFFER(NULL, hap_resp, reply.params.write.len);
|
||||
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
|
||||
rtos_free(hap_resp);
|
||||
@@ -274,7 +348,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
{
|
||||
ble_gatts_evt_read_t * gatt_req = &event->evt.gatts_evt.params.authorize_request.request.read;
|
||||
|
||||
LOG_LV2(GATTS, "Read uuid = 0x%04X, offset = %d", gatt_req->uuid.uuid, gatt_req->offset);
|
||||
LOG_LV2("GATTS", "Read uuid = 0x%04X, offset = %d", gatt_req->uuid.uuid, gatt_req->offset);
|
||||
|
||||
ble_gatts_rw_authorize_reply_params_t reply =
|
||||
{
|
||||
@@ -296,27 +370,9 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply), );
|
||||
}else
|
||||
{
|
||||
#if 1
|
||||
// reject read attempt
|
||||
reply.params.read.gatt_status = BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED;
|
||||
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply), );
|
||||
#elif 0
|
||||
HAPResponse_t* hap_resp = createHapResponse(_tid, HAP_STATUS_INVALID_REQUEST, NULL, 0);
|
||||
|
||||
reply.params.read.update = 1;
|
||||
reply.params.read.len = sizeof(HAPResponseHeader_t) + hap_resp->body_len;
|
||||
reply.params.read.p_data = (uint8_t*) hap_resp;
|
||||
|
||||
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
|
||||
rtos_free(hap_resp);
|
||||
VERIFY_STATUS( err, );
|
||||
#else
|
||||
reply.params.read.update = 1;
|
||||
reply.params.read.len = 0;
|
||||
reply.params.read.p_data = NULL;
|
||||
|
||||
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,8 +385,8 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
// CCCD write
|
||||
if ( request->handle == _handles.cccd_handle )
|
||||
{
|
||||
LOG_LV2(GATTS, "attr's cccd");
|
||||
PRINT2_BUFFER(request->data, request->len);
|
||||
LOG_LV2("GATTS", "attr's cccd");
|
||||
LOG_LV2_BUFFER(NULL, request->data, request->len);
|
||||
|
||||
// Invoke callback if set
|
||||
if (_cccd_wr_cb)
|
||||
|
||||
@@ -62,6 +62,11 @@ class HAPCharacteristic : public BLECharacteristic
|
||||
|
||||
void setHapProperties(uint16_t prop);
|
||||
|
||||
// Write to Hap Value
|
||||
uint16_t writeHapValue(const void* data, uint16_t len);
|
||||
uint16_t writeHapValue(const char* str);
|
||||
uint16_t writeHapValue(uint32_t num);
|
||||
|
||||
/*------------- Internal Functions -------------*/
|
||||
virtual void _eventHandler(ble_evt_t* event);
|
||||
|
||||
@@ -70,10 +75,16 @@ class HAPCharacteristic : public BLECharacteristic
|
||||
uint16_t _hap_props;
|
||||
|
||||
uint16_t _resp_len;
|
||||
uint8_t _tid;
|
||||
|
||||
// Char value is read by HAP procedure, not exposed via GATT
|
||||
void* _value;
|
||||
uint16_t _vallen;
|
||||
|
||||
err_t _addChrIdDescriptor(void);
|
||||
|
||||
HAPResponse_t* processChrSignatureRead(HAPRequest_t* hap_req);
|
||||
HAPResponse_t* processChrRead(HAPRequest_t* hap_req);
|
||||
|
||||
HAPResponse_t* createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[], uint8_t count);
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ HAPPairing::HAPPairing(void)
|
||||
: HAPService(HAP_UUID_SVC_PAIRING),
|
||||
_setup (HAP_UUID_CHR_PAIR_SETUP , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_verify (HAP_UUID_CHR_PAIR_VERIFY , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_features (HAP_UUID_SVC_PAIR_FEATURE , BLE_GATT_CPF_FORMAT_STRUCT),
|
||||
_features (HAP_UUID_SVC_PAIR_FEATURE , BLE_GATT_CPF_FORMAT_UINT8 ),
|
||||
_pairing (HAP_UUID_SVC_PAIR_PAIRING , BLE_GATT_CPF_FORMAT_STRUCT)
|
||||
{
|
||||
|
||||
@@ -62,12 +62,10 @@ err_t HAPPairing::begin(void)
|
||||
VERIFY_STATUS( _verify.begin() );
|
||||
|
||||
_features.setHapProperties(HAP_CHR_PROPS_READ);
|
||||
_features.setMaxLen(100);
|
||||
VERIFY_STATUS( _features.begin() );
|
||||
//_features.write( (uint8_t) 0x01); // support HAP pairing
|
||||
_features.writeHapValue(0x01); // support HAP pairing
|
||||
|
||||
_pairing.setHapProperties(HAP_CHR_PROPS_SECURE_READ | HAP_CHR_PROPS_SECURE_WRITE);
|
||||
_pairing.setMaxLen(100);
|
||||
VERIFY_STATUS( _pairing.begin() );
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
@@ -362,8 +362,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
|
||||
// Value write
|
||||
if (request->handle == _handles.value_handle)
|
||||
{
|
||||
LOG_LV2(GATTS, "attr's value, uuid = 0x%04X", request->uuid.uuid);
|
||||
PRINT2_BUFFER(request->data, request->len);
|
||||
LOG_LV2("GATTS", "attr's value, uuid = 0x%04X", request->uuid.uuid);
|
||||
LOG_LV2_BUFFER(NULL, request->data, request->len);
|
||||
|
||||
// TODO Ada callback
|
||||
if (_wr_cb) _wr_cb(*this, request->data, request->len, request->offset);
|
||||
@@ -372,8 +372,8 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
|
||||
// CCCD write
|
||||
if ( request->handle == _handles.cccd_handle )
|
||||
{
|
||||
LOG_LV2(GATTS, "attr's cccd");
|
||||
PRINT2_BUFFER(request->data, request->len);
|
||||
LOG_LV2("GATTS", "attr's cccd");
|
||||
LOG_LV2_BUFFER(NULL, request->data, request->len);
|
||||
|
||||
// Invoke callback if set
|
||||
if (_cccd_wr_cb)
|
||||
@@ -538,7 +538,7 @@ bool BLECharacteristic::notify(const void* data, uint16_t len)
|
||||
.p_data = (uint8_t*) u8data,
|
||||
};
|
||||
|
||||
LOG_LV2(CHR, "Notify %d bytes", packet_len);
|
||||
LOG_LV2("CHR", "Notify %d bytes", packet_len);
|
||||
VERIFY_STATUS( sd_ble_gatts_hvx(Bluefruit.connHandle(), &hvx_params), false );
|
||||
|
||||
remaining -= packet_len;
|
||||
|
||||
@@ -135,7 +135,7 @@ bool BLEClientCharacteristic::discoverDescriptor(uint16_t conn_handle, ble_gattc
|
||||
if ( disc_rsp.descs[i].uuid.type == BLE_UUID_TYPE_BLE &&
|
||||
disc_rsp.descs[i].uuid.uuid == BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG )
|
||||
{
|
||||
LOG_LV2(Discovery, "Found CCDD: handle = %d", disc_rsp.descs[i].handle);
|
||||
LOG_LV2("DISC", "Found CCDD: handle = %d", disc_rsp.descs[i].handle);
|
||||
_cccd_handle = disc_rsp.descs[i].handle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
|
||||
{
|
||||
ble_gattc_evt_prim_srvc_disc_rsp_t disc_svc;
|
||||
|
||||
LOG_LV2(DISC, "[SVC] Handle start = %d", start_handle);
|
||||
LOG_LV2("DISC", "[SVC] Handle start = %d", start_handle);
|
||||
|
||||
_adamsg.prepare(&disc_svc, sizeof(disc_svc));
|
||||
VERIFY_STATUS( sd_ble_gattc_primary_services_discover(conn_handle, start_handle, &svc.uuid._uuid), false );
|
||||
@@ -90,7 +90,7 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
|
||||
_hdl_range = disc_svc.services[0].handle_range;
|
||||
svc.setHandleRange(_hdl_range);
|
||||
|
||||
LOG_LV2(DISC, "[SVC] Found 0x%04X, Handle start = %d, end = %d\n-----------------", disc_svc.services[0].uuid.uuid, _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
LOG_LV2("DISC", "[SVC] Found 0x%04X, Handle start = %d, end = %d\n-----------------", disc_svc.services[0].uuid.uuid, _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
|
||||
// increase for next discovery
|
||||
_hdl_range.start_handle++;
|
||||
@@ -112,7 +112,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
|
||||
while( found < count )
|
||||
{
|
||||
LOG_LV2(DISC, "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
LOG_LV2("DISC", "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
|
||||
memclr(disc_chr, bufsize);
|
||||
_adamsg.prepare(disc_chr, bufsize);
|
||||
@@ -132,7 +132,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
{
|
||||
if ( chr[i]->uuid == disc_chr->chars[d].uuid )
|
||||
{
|
||||
LOG_LV2(DISC, "[CHR] Found 0x%04X, handle = %d\n-----------------", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value);
|
||||
LOG_LV2("DISC", "[CHR] Found 0x%04X, handle = %d\n-----------------", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value);
|
||||
|
||||
// characteristic assign overload
|
||||
chr[i]->assign(&disc_chr->chars[d]);
|
||||
@@ -171,7 +171,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
|
||||
uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t bufsize, ble_gattc_handle_range_t hdl_range)
|
||||
{
|
||||
LOG_LV2(DISC, "[DESC] Handle start = %d, end = %d", hdl_range.start_handle, hdl_range.end_handle);
|
||||
LOG_LV2("DISC", "[DESC] Handle start = %d, end = %d", hdl_range.start_handle, hdl_range.end_handle);
|
||||
|
||||
_adamsg.prepare(disc_desc, bufsize);
|
||||
|
||||
@@ -185,7 +185,7 @@ uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_d
|
||||
|
||||
for(uint16_t i=0; i<disc_desc->count; i++)
|
||||
{
|
||||
LOG_LV2(DISC, "[DESC] Descriptor %d: uuid = 0x%04X, handle = %d", i, disc_desc->descs[i].uuid.uuid, disc_desc->descs[i].handle);
|
||||
LOG_LV2("DISC", "[DESC] Descriptor %d: uuid = 0x%04X, handle = %d", i, disc_desc->descs[i].uuid.uuid, disc_desc->descs[i].handle);
|
||||
}
|
||||
|
||||
return disc_desc->count;
|
||||
@@ -202,7 +202,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
{
|
||||
ble_gattc_evt_prim_srvc_disc_rsp_t* svc_rsp = &gattc->params.prim_srvc_disc_rsp;
|
||||
|
||||
LOG_LV2(DISC, "[SVC] Service Count: %d", svc_rsp->count);
|
||||
LOG_LV2("DISC", "[SVC] Service Count: %d", svc_rsp->count);
|
||||
|
||||
if (gattc->gatt_status == BLE_GATT_STATUS_SUCCESS)
|
||||
{
|
||||
@@ -213,7 +213,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
}
|
||||
}else
|
||||
{
|
||||
LOG_LV1(DISC, "[SVC] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
LOG_LV1("DISC", "[SVC] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
}
|
||||
|
||||
_adamsg.complete();
|
||||
@@ -224,7 +224,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
{
|
||||
ble_gattc_evt_char_disc_rsp_t* chr_rsp = &gattc->params.char_disc_rsp;
|
||||
|
||||
LOG_LV2(DISC, "[CHR] Characteristic Count: %d", chr_rsp->count);
|
||||
LOG_LV2("DISC", "[CHR] Characteristic Count: %d", chr_rsp->count);
|
||||
|
||||
if (gattc->gatt_status == BLE_GATT_STATUS_SUCCESS)
|
||||
{
|
||||
@@ -235,7 +235,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
}
|
||||
}else
|
||||
{
|
||||
LOG_LV1(DISC, "[CHR] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
LOG_LV1("DISC", "[CHR] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
}
|
||||
|
||||
_adamsg.complete();
|
||||
@@ -246,7 +246,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
{
|
||||
ble_gattc_evt_desc_disc_rsp_t* desc_rsp = &gattc->params.desc_disc_rsp;
|
||||
|
||||
LOG_LV2(DISC, "[DESC] Descriptor Count: %d", desc_rsp->count);
|
||||
LOG_LV2("DISC", "[DESC] Descriptor Count: %d", desc_rsp->count);
|
||||
|
||||
if (gattc->gatt_status == BLE_GATT_STATUS_SUCCESS)
|
||||
{
|
||||
@@ -257,7 +257,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
|
||||
}
|
||||
}else
|
||||
{
|
||||
LOG_LV1(DISC, "[DESC] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
LOG_LV1("DISC", "[DESC] Gatt Status = 0x%04X", gattc->gatt_status);
|
||||
}
|
||||
|
||||
_adamsg.complete();
|
||||
|
||||
@@ -223,7 +223,7 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
|
||||
{
|
||||
ble_gap_data_length_params_t* datalen = &evt->evt.gap_evt.params.data_length_update.effective_params;
|
||||
LOG_LV1(GAP, "Data Length is (tx, rx) octets = (%d, %d), (tx, rx) time = (%d, %d) us",
|
||||
LOG_LV1("GAP", "Data Length is (tx, rx) octets = (%d, %d), (tx, rx) time = (%d, %d) us",
|
||||
datalen->max_tx_octets, datalen->max_rx_octets, datalen->max_tx_time_us, datalen->max_rx_time_us);
|
||||
}
|
||||
break;
|
||||
@@ -233,7 +233,7 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
peer->att_mtu = minof(evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX);
|
||||
VERIFY_STATUS( sd_ble_gatts_exchange_mtu_reply(conn_handle, peer->att_mtu), );
|
||||
|
||||
LOG_LV1(GAP, "ATT MTU is changed to %d", peer->att_mtu);
|
||||
LOG_LV1("GAP", "ATT MTU is changed to %d", peer->att_mtu);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
|
||||
uint32_t err = sd_ble_enable(&ram_start);
|
||||
if ( err )
|
||||
{
|
||||
LOG_LV1(CFG, "SoftDevice config require more SRAM than provided by linker.\n"
|
||||
LOG_LV1("CFG", "SoftDevice config require more SRAM than provided by linker.\n"
|
||||
"App Ram Start must be at least 0x%08X (provided 0x%08X)\n"
|
||||
"Please update linker file or re-config SoftDevice", ram_start, (uint32_t) __data_start__);
|
||||
}
|
||||
@@ -636,7 +636,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
// conn handle has fixed offset regardless of event type
|
||||
const uint16_t evt_conn_hdl = evt->evt.common_evt.conn_handle;
|
||||
|
||||
LOG_LV1(BLE, "%s : Conn Handle = %d", dbg_ble_event_str(evt->header.evt_id), evt_conn_hdl);
|
||||
LOG_LV1("BLE", "%s : Conn Handle = %d", dbg_ble_event_str(evt->header.evt_id), evt_conn_hdl);
|
||||
|
||||
// GAP handler
|
||||
Gap._eventHandler(evt);
|
||||
@@ -670,7 +670,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
_conn_hdl = evt->evt.gap_evt.conn_handle;
|
||||
_conn_interval = para->conn_params.min_conn_interval;
|
||||
|
||||
LOG_LV2(GAP, "Conn Interval= %f", _conn_interval*1.25f);
|
||||
LOG_LV2("GAP", "Conn Interval= %f", _conn_interval*1.25f);
|
||||
|
||||
// Connection interval set by Central is out of preferred range
|
||||
// Try to negotiate with Central using our preferred values
|
||||
@@ -692,7 +692,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
ble_gap_conn_params_t* param = &evt->evt.gap_evt.params.conn_param_update.conn_params;
|
||||
_conn_interval = param->min_conn_interval;
|
||||
|
||||
LOG_LV2(GAP, "Conn Interval= %f", _conn_interval*1.25f);
|
||||
LOG_LV2("GAP", "Conn Interval= %f", _conn_interval*1.25f);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -702,7 +702,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
|
||||
if (_disconnect_cb) ada_callback(NULL, _disconnect_cb, _conn_hdl, evt->evt.gap_evt.params.disconnected.reason);
|
||||
|
||||
LOG_LV2(GAP, "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
|
||||
LOG_LV2("GAP", "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
|
||||
|
||||
_conn_hdl = BLE_CONN_HANDLE_INVALID;
|
||||
_bonded = false;
|
||||
@@ -935,10 +935,10 @@ void AdafruitBluefruit::_saveBondKeys(void)
|
||||
|
||||
if (result)
|
||||
{
|
||||
LOG_LV2(BOND, "Keys for \"%s\" is saved to file %s", devname, filename);
|
||||
LOG_LV2("BOND", "Keys for \"%s\" is saved to file %s", devname, filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1(BOND, "Failed to save keys for \"%s\"", devname);
|
||||
LOG_LV1("BOND", "Failed to save keys for \"%s\"", devname);
|
||||
}
|
||||
printBondDir();
|
||||
}
|
||||
@@ -954,10 +954,10 @@ bool AdafruitBluefruit::_loadBondKeys(uint16_t ediv)
|
||||
|
||||
if ( result )
|
||||
{
|
||||
LOG_LV2(BOND, "Load Keys from file %s", filename);
|
||||
LOG_LV2("BOND", "Load Keys from file %s", filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1(BOND, "Keys not found");
|
||||
LOG_LV1("BOND", "Keys not found");
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -981,10 +981,10 @@ void AdafruitBluefruit::_saveBondCCCD(void)
|
||||
|
||||
if ( Nffs.writeFile(filename, sys_attr, len, BOND_FILE_CCCD_OFFSET) )
|
||||
{
|
||||
LOG_LV2(BOND, "CCCD setting is saved to file %s", filename);
|
||||
LOG_LV2("BOND", "CCCD setting is saved to file %s", filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1(BOND, "Failed to save CCCD setting");
|
||||
LOG_LV1("BOND", "Failed to save CCCD setting");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1021,10 +1021,10 @@ void AdafruitBluefruit::_loadBondCCCD(uint16_t ediv)
|
||||
{
|
||||
loaded = true;
|
||||
|
||||
LOG_LV2(BOND, "Load CCCD from file %s", filename);
|
||||
LOG_LV2("BOND", "Load CCCD from file %s", filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1(BOND, "CCCD setting not found");
|
||||
LOG_LV1("BOND", "CCCD setting not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ void bleuart_rxd_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_
|
||||
svc._rx_fifo.write(data, len);
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
LOG_LV2(BLEUART, "RX: ");
|
||||
LOG_LV2("BLEUART", "RX: ");
|
||||
PRINT_BUFFER(data, len);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ bool EddyStoneUrl::start(void)
|
||||
uint8_t cp_num = (expansion) ? (expansion-url) : strlen(url);
|
||||
if ( cp_num > URL_MAXLEN-(len + (expansion ? 1:0)) )
|
||||
{
|
||||
LOG_LV1(EDDYS, "url is too long");
|
||||
LOG_LV1("EDDYS", "url is too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user