Compare commits
1 Commits
615637e24c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 30cccee5f6 |
@@ -5,22 +5,22 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
/* Private function declarations */
|
/* Private function declarations */
|
||||||
static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
static int temp_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||||
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
||||||
static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
static int led_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||||
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
struct ble_gatt_access_ctxt *ctxt, void *arg);
|
||||||
|
|
||||||
/* Private variables */
|
/* Private variables */
|
||||||
/* Heart rate service */
|
/* temp rate service */
|
||||||
static const ble_uuid16_t heart_rate_svc_uuid = BLE_UUID16_INIT(0x180D);
|
static const ble_uuid16_t temp_svc_uuid = BLE_UUID16_INIT(0x180D);
|
||||||
|
|
||||||
static uint8_t heart_rate_chr_val[2] = {0};
|
static uint8_t temp_chr_val[2] = {0};
|
||||||
static uint16_t heart_rate_chr_val_handle;
|
static uint16_t temp_chr_val_handle;
|
||||||
static const ble_uuid16_t heart_rate_chr_uuid = BLE_UUID16_INIT(0x2A37);
|
static const ble_uuid16_t temp_chr_uuid = BLE_UUID16_INIT(0x2A37);
|
||||||
|
|
||||||
static uint16_t heart_rate_chr_conn_handle = 0;
|
static uint16_t temp_chr_conn_handle = 0;
|
||||||
static bool heart_rate_chr_conn_handle_inited = false;
|
static bool temp_chr_conn_handle_inited = false;
|
||||||
static bool heart_rate_ind_status = false;
|
static bool temp_ind_status = false;
|
||||||
|
|
||||||
/* Automation IO service */
|
/* Automation IO service */
|
||||||
static const ble_uuid16_t auto_io_svc_uuid = BLE_UUID16_INIT(0x1815);
|
static const ble_uuid16_t auto_io_svc_uuid = BLE_UUID16_INIT(0x1815);
|
||||||
@@ -31,16 +31,16 @@ static const ble_uuid128_t led_chr_uuid =
|
|||||||
|
|
||||||
/* GATT services table */
|
/* GATT services table */
|
||||||
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||||
/* Heart rate service */
|
/* Temp rate service */
|
||||||
{.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
{.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||||
.uuid = &heart_rate_svc_uuid.u,
|
.uuid = &temp_svc_uuid.u,
|
||||||
.characteristics =
|
.characteristics =
|
||||||
(struct ble_gatt_chr_def[]){
|
(struct ble_gatt_chr_def[]){
|
||||||
{/* Heart rate characteristic */
|
{/* Temp rate characteristic */
|
||||||
.uuid = &heart_rate_chr_uuid.u,
|
.uuid = &temp_chr_uuid.u,
|
||||||
.access_cb = heart_rate_chr_access,
|
.access_cb = temp_chr_access,
|
||||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_INDICATE,
|
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_INDICATE,
|
||||||
.val_handle = &heart_rate_chr_val_handle},
|
.val_handle = &temp_chr_val_handle},
|
||||||
{
|
{
|
||||||
0, /* No more characteristics in this service. */
|
0, /* No more characteristics in this service. */
|
||||||
}}},
|
}}},
|
||||||
@@ -64,13 +64,13 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Private functions */
|
/* Private functions */
|
||||||
static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
static int temp_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||||
struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
||||||
/* Local variables */
|
/* Local variables */
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Handle access events */
|
/* Handle access events */
|
||||||
/* Note: Heart rate characteristic is read only */
|
/* Note: Temp rate characteristic is read only */
|
||||||
switch (ctxt->op) {
|
switch (ctxt->op) {
|
||||||
|
|
||||||
/* Read characteristic event */
|
/* Read characteristic event */
|
||||||
@@ -85,11 +85,11 @@ static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Verify attribute handle */
|
/* Verify attribute handle */
|
||||||
if (attr_handle == heart_rate_chr_val_handle) {
|
if (attr_handle == temp_chr_val_handle) {
|
||||||
/* Update access buffer value */
|
/* Update access buffer value */
|
||||||
heart_rate_chr_val[1] = get_temp();
|
temp_chr_val[1] = get_temp();
|
||||||
rc = os_mbuf_append(ctxt->om, &heart_rate_chr_val,
|
rc = os_mbuf_append(ctxt->om, &temp_chr_val,
|
||||||
sizeof(heart_rate_chr_val));
|
sizeof(temp_chr_val));
|
||||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||||
}
|
}
|
||||||
goto error;
|
goto error;
|
||||||
@@ -102,7 +102,7 @@ static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
|||||||
error:
|
error:
|
||||||
ESP_LOGE(
|
ESP_LOGE(
|
||||||
TAG,
|
TAG,
|
||||||
"unexpected access operation to heart rate characteristic, opcode: %d",
|
"unexpected access operation to temp rate characteristic, opcode: %d",
|
||||||
ctxt->op);
|
ctxt->op);
|
||||||
return BLE_ATT_ERR_UNLIKELY;
|
return BLE_ATT_ERR_UNLIKELY;
|
||||||
}
|
}
|
||||||
@@ -161,9 +161,9 @@ error:
|
|||||||
|
|
||||||
/* Public functions */
|
/* Public functions */
|
||||||
void send_heart_rate_indication(void) {
|
void send_heart_rate_indication(void) {
|
||||||
if (heart_rate_ind_status && heart_rate_chr_conn_handle_inited) {
|
if (temp_ind_status && temp_chr_conn_handle_inited) {
|
||||||
ble_gatts_indicate(heart_rate_chr_conn_handle,
|
ble_gatts_indicate(temp_chr_conn_handle,
|
||||||
heart_rate_chr_val_handle);
|
temp_chr_val_handle);
|
||||||
ESP_LOGI(TAG, "heart rate indication sent!");
|
ESP_LOGI(TAG, "heart rate indication sent!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* GATT server subscribe event callback
|
* GATT server subscribe event callback
|
||||||
* 1. Update heart rate subscription status
|
* 1. Update temp rate subscription status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gatt_svr_subscribe_cb(struct ble_gap_event *event) {
|
void gatt_svr_subscribe_cb(struct ble_gap_event *event) {
|
||||||
@@ -227,11 +227,11 @@ void gatt_svr_subscribe_cb(struct ble_gap_event *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check attribute handle */
|
/* Check attribute handle */
|
||||||
if (event->subscribe.attr_handle == heart_rate_chr_val_handle) {
|
if (event->subscribe.attr_handle == temp_chr_val_handle) {
|
||||||
/* Update heart rate subscription status */
|
/* Update temp rate subscription status */
|
||||||
heart_rate_chr_conn_handle = event->subscribe.conn_handle;
|
temp_chr_conn_handle = event->subscribe.conn_handle;
|
||||||
heart_rate_chr_conn_handle_inited = true;
|
temp_chr_conn_handle_inited = true;
|
||||||
heart_rate_ind_status = event->subscribe.cur_indicate;
|
temp_ind_status = event->subscribe.cur_indicate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user