From bc92926b0f85ea5cdcc0da56e773b4ffafc82bdc Mon Sep 17 00:00:00 2001 From: chain40 Date: Sat, 3 Jun 2023 23:09:10 +0800 Subject: [PATCH] add le_dis_c 1. discovery device info service 2. dis client handling events from the database discovery module 3. reading different characteristics from DIS, and show with segger rtt --- app_config.h | 5 +++ bmd380_central.vcxproj | 1 + bmd380_central.vcxproj.filters | 3 ++ le_db_discovery.c | 2 + le_dis_c.c | 72 ++++++++++++++++++++++++++++++++++ main.c | 3 ++ 6 files changed, 86 insertions(+) create mode 100644 le_dis_c.c diff --git a/app_config.h b/app_config.h index 14c164c..b1e63be 100644 --- a/app_config.h +++ b/app_config.h @@ -200,6 +200,11 @@ extern "C" #define BLE_DB_DISCOVERY_ENABLED 1 // Priority with which BLE events are dispatched to the Database Discovery module. #define BLE_DB_DISC_BLE_OBSERVER_PRIO 1 +// Enable Device Information Client module +#define BLE_DIS_C_ENABLED 1 +// Priority with which BLE events are dispatched to the Device Information Client. +#define BLE_DIS_C_BLE_OBSERVER_PRIO 1 + #define COUNTOF(x) (sizeof(x) / sizeof(x[0])) diff --git a/bmd380_central.vcxproj b/bmd380_central.vcxproj index d5106bc..80a5fbf 100644 --- a/bmd380_central.vcxproj +++ b/bmd380_central.vcxproj @@ -376,6 +376,7 @@ + diff --git a/bmd380_central.vcxproj.filters b/bmd380_central.vcxproj.filters index 736077a..d538840 100644 --- a/bmd380_central.vcxproj.filters +++ b/bmd380_central.vcxproj.filters @@ -1664,6 +1664,9 @@ Source files + + Source files + diff --git a/le_db_discovery.c b/le_db_discovery.c index f8b6cf0..48d3d2e 100644 --- a/le_db_discovery.c +++ b/le_db_discovery.c @@ -24,6 +24,8 @@ static void db_disc_handler(ble_db_discovery_evt_t *p_evt) { case BLE_DB_DISCOVERY_COMPLETE: NRF_LOG_INFO("BLE_DB_DISCOVERY_COMPLETE"); + extern void le_dis_c_on_db_disc_evt(ble_db_discovery_evt_t *p_evt); + le_dis_c_on_db_disc_evt(p_evt); break; case BLE_DB_DISCOVERY_ERROR: NRF_LOG_INFO("BLE_DB_DISCOVERY_ERROR"); diff --git a/le_dis_c.c b/le_dis_c.c new file mode 100644 index 0000000..a40b48d --- /dev/null +++ b/le_dis_c.c @@ -0,0 +1,72 @@ +#include "ble_dis_c.h" + +#include "ble_gattc.h" +#include "nrf_ble_gq.h" + +#include "nrf_log.h" +#include "nrf_log_ctrl.h" +#include "nrf_log_default_backends.h" + +ble_dis_c_char_type_t dis_c_char_types[10]; +BLE_DIS_C_DEF(m_ble_dis_c); + +void dis_c_evt_handler(ble_dis_c_t *p_ble_dis_c, ble_dis_c_evt_t const *p_evt) +{ + switch (p_evt->evt_type) + { + case BLE_DIS_C_EVT_DISCOVERY_COMPLETE: + ble_dis_c_handles_assign(p_ble_dis_c, p_evt->conn_handle, p_evt->params.disc_complete.handles); + ble_dis_c_read(&m_ble_dis_c, BLE_DIS_C_MANUF_NAME); + ble_dis_c_read(&m_ble_dis_c, BLE_DIS_C_MODEL_NUM); + ble_dis_c_read(&m_ble_dis_c, BLE_DIS_C_SERIAL_NUM); + ble_dis_c_read(&m_ble_dis_c, BLE_DIS_C_FW_REV); + ble_dis_c_read(&m_ble_dis_c, BLE_DIS_C_HW_REV); + break; + case BLE_DIS_C_EVT_DIS_C_READ_RSP: { + char str[32]; + memset(str, 0x00, sizeof(str)); + memcpy(str, p_evt->params.read_rsp.content.string.p_data, p_evt->params.read_rsp.content.string.len); + switch (p_evt->params.read_rsp.char_type) + { + case BLE_DIS_C_MANUF_NAME: + NRF_LOG_INFO("Manufacture: %s", str); + break; + case BLE_DIS_C_MODEL_NUM: + NRF_LOG_INFO("Model: %s", str); + break; + case BLE_DIS_C_SERIAL_NUM: + NRF_LOG_INFO("Serial Num: %s", str); + break; + case BLE_DIS_C_FW_REV: + NRF_LOG_INFO("FW Ver: %s", str); + break; + case BLE_DIS_C_HW_REV: + NRF_LOG_INFO("HW Ver: %s", str); + break; + default: + break; + } + break; + } + default: + break; + } +} + +void le_dis_c_init(void) +{ + ble_dis_c_init_t dis_init; + memset(&dis_init, 0x00, sizeof(dis_init)); + + extern nrf_ble_gq_t *le_gap_queue(void); + dis_init.evt_handler = dis_c_evt_handler; + dis_init.p_gatt_queue = le_gap_queue(); + dis_init.error_handler = NULL; + + ble_dis_c_init(&m_ble_dis_c, &dis_init); +} + +void le_dis_c_on_db_disc_evt(ble_db_discovery_evt_t *p_evt) +{ + ble_dis_c_on_db_disc_evt(&m_ble_dis_c, p_evt); +} \ No newline at end of file diff --git a/main.c b/main.c index 00e0c79..d68075e 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,9 @@ int main(void) extern void le_db_discovery_init(void); le_db_discovery_init(); + extern void le_dis_c_init(void); + le_dis_c_init(); + extern void le_gap_init(void); le_gap_init();