Files
microchip-application-bmd38…/le_dis_c.c
T
chain40 bc92926b0f 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
2023-06-03 23:10:53 +08:00

72 lines
2.3 KiB
C

#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);
}