mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-06 07:00:59 +00:00
examples: fix chunk len calculation in att_read_callback for le_couner and spp_and_le_couner
This commit is contained in:
parent
ebaeb1be2d
commit
7b6395ea58
@ -117,6 +117,9 @@ static void le_counter_setup(void){
|
||||
heartbeat.process = &heartbeat_handler;
|
||||
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
||||
btstack_run_loop_add_timer(&heartbeat);
|
||||
|
||||
// beat once
|
||||
beat();
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
@ -189,13 +192,18 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
// - if buffer != NULL, copy data and return number bytes copied
|
||||
// @param offset defines start of attribute value
|
||||
static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
|
||||
uint16_t size = 0;
|
||||
if (att_handle == ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE){
|
||||
if (buffer){
|
||||
memcpy(buffer, &counter_string[offset], counter_string_len - offset);
|
||||
// size is bound by actual value chunk and provided buffer
|
||||
size = btstack_min(counter_string_len - offset, buffer_size);
|
||||
memcpy(buffer, &counter_string[offset], size);
|
||||
} else {
|
||||
// size is only bound by actual value chunk
|
||||
size = counter_string_len - offset;
|
||||
}
|
||||
return counter_string_len - offset;
|
||||
}
|
||||
return 0;
|
||||
return size;
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
|
@ -176,14 +176,18 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
// - if buffer != NULL, copy data and return number bytes copied
|
||||
// @param offset defines start of attribute value
|
||||
static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
|
||||
uint16_t size = 0;
|
||||
if (att_handle == ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE){
|
||||
if (buffer){
|
||||
log_info("att_read_callback for Characteristic *FF11*, value %s", counter_string);
|
||||
memcpy(buffer, &counter_string[offset], counter_string_len - offset);
|
||||
// size is bound by actual value chunk and provided buffer
|
||||
size = btstack_min(counter_string_len - offset, buffer_size);
|
||||
memcpy(buffer, &counter_string[offset], size);
|
||||
} else {
|
||||
// size is only bound by actual value chunk
|
||||
size = counter_string_len - offset;
|
||||
}
|
||||
return counter_string_len - offset;
|
||||
}
|
||||
return 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
// write requests
|
||||
@ -207,6 +211,12 @@ static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle,
|
||||
}
|
||||
}
|
||||
|
||||
static void beat(void){
|
||||
counter++;
|
||||
counter_string_len = sprintf(counter_string, "BTstack counter %04u", counter);
|
||||
puts(counter_string);
|
||||
}
|
||||
|
||||
/*
|
||||
* @section Heartbeat Handler
|
||||
*
|
||||
@ -217,9 +227,9 @@ static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle,
|
||||
/* LISTING_START(heartbeat): Combined Heartbeat handler */
|
||||
static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||
|
||||
counter++;
|
||||
counter_string_len = sprintf(counter_string, "BTstack counter %04u\n", counter);
|
||||
// log_info("%s", counter_string);
|
||||
if (rfcomm_channel_id || le_notification_enabled) {
|
||||
beat();
|
||||
}
|
||||
|
||||
if (rfcomm_channel_id){
|
||||
rfcomm_request_can_send_now_event(rfcomm_channel_id);
|
||||
@ -228,6 +238,7 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||
if (le_notification_enabled) {
|
||||
att_server_request_can_send_now_event(att_con_handle);
|
||||
}
|
||||
|
||||
btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
btstack_run_loop_add_timer(ts);
|
||||
}
|
||||
@ -288,6 +299,9 @@ int btstack_main(void)
|
||||
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
|
||||
gap_advertisements_enable(1);
|
||||
|
||||
// beat once
|
||||
beat();
|
||||
|
||||
// turn on!
|
||||
hci_power_control(HCI_POWER_ON);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user