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
This commit is contained in:
chain40
2023-06-03 23:09:10 +08:00
parent 17dda9143a
commit bc92926b0f
6 changed files with 86 additions and 0 deletions
+5
View File
@@ -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]))
+1
View File
@@ -376,6 +376,7 @@
<ClCompile Include="..\bmd380_sdk\components\ble\nrf_ble_scan\nrf_ble_scan.c" />
<ClCompile Include="..\bmd380_sdk\components\libraries\queue\nrf_queue.c" />
<ClCompile Include="le_db_discovery.c" />
<ClCompile Include="le_dis_c.c" />
<ClCompile Include="le_gap.c" />
<ClCompile Include="le_gatt.c" />
<ClCompile Include="le_gap_queue.c" />
+3
View File
@@ -1664,6 +1664,9 @@
<ClCompile Include="le_gap_queue.c">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="le_dis_c.c">
<Filter>Source files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\bmd380_sdk\components\ble\ble_services\ble_dis_c\ble_dis_c.h">
+2
View File
@@ -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");
+72
View File
@@ -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);
}
+3
View File
@@ -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();