当前位置:网站首页>Nrf52832 custom services and features
Nrf52832 custom services and features
2022-06-12 05:46:00 【m0_ seven thousand seven hundred and eighty-eight】
The experiment purpose : Customize Service Private service and transmission of temperature and humidity sensor data . This experiment is based on SDK17.02 in ble_app_uart Change the sample code .
One 、 background
1.1GAP initialization :
Mainly complete three tasks :
a.GAP Initialize safe mode configuration , Security mode refers to whether authentication is required when connecting .
b. Bluetooth device name settings , That is, set the name of Bluetooth broadcast , Note that the length of the name is limited , It's best not to exceed eighteen bytes
c. Connection parameter settings , Connection parameter settings , It's mainly about setting up : Minimum connection interval 、 Maximum connection interval 、 Latency cycle of slave equipment 、 Connection timeout . These values represent the expected parameters of the peripheral for the connection .
1.2GATT initialization
GATT It is called the general attribute specification (Generic Attribute profile,GATT),GATT The layer is where the real data is transmitted layer . It includes a data transmission and storage framework and its basic operation . Most of its custom functions are in .C Written , In the main function, you only need to initialize and configure the relationship between functions .
GATT Used ATT(Attribute Protocol) agreement ,ATT The agreement put Service,Characteristic The corresponding data is saved in a lookup table , Lookup table usage 16bit ID As an index of each item .GATT The defined multi-layer data structure can be summarized as service (Service) It can contain more than one features (Characteristic), Each feature contains attribute (Properties) and value (Value), It can also contain multiple describe (Descriptor).
Two 、ble_lbs.c function
battery_level Is the of analog electricity value
2.1 Host client event handling
ble_lbs.h Observer mode NRF_SDH_BLE_OBSERVER—>>>ble_lbs_on_ble_evt—>>>lbs_c_evt_handler()
case BLE_GATTS_EVT_WRITE: //LED When a feature is written to data , Produced GATT Write events , Will call on_write function .
lbs_c_evt_handler(p_lbs, p_ble_evt);
ble_lbs_on_ble_evt—>>>lbs_c_evt_handler()
p_lbs->led_write_handler(p_ble_evt->evt.gap_evt.conn_handle, p_lbs, p_evt_write->data[0]);
ble_srv_is_notification_enabled(p_evt_write->data)
2.2 Host client initialization ble_lbs_init()
// Initialize service structure
p_lbs->evt_handler = p_lbs_init->evt_handler;
p_lbs->is_notification_supported = p_lbs_init->support_notification;
p_lbs->battery_level_last = INVALID_BATTERY_LEVEL;
// Add service
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BATTERY_SERVICE);
// Add battery level characteristic
err_code = battery_level_char_add(p_lbs, p_lbs_init);
Feature add function battery_level_char_add()
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
memset(&char_md, 0, sizeof(char_md));
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BATTERY_LEVEL_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
initial_battery_level = p_bas_init->initial_batt_level;
memset(&attr_char_value, 0, sizeof(attr_char_value));
err_code = sd_ble_gatts_characteristic_add(p_bas->service_handle, &char_md,
&attr_char_value,
&p_bas->battery_level_handles);
2.3 Host client temperature data processing function
main.c Timer call battery_level_update():
memset(&gatts_value, 0, sizeof(gatts_value));
err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID,
p_bas->battery_level_handles.value_handle,
&gatts_value);
err_code = battery_notification_send(&hvx_params, conn_handles.conn_handles[i]);
battery_level_update()—>>>battery_notification_send()
err_code = sd_ble_gatts_hvx(conn_handle, p_hvx_params);
3、 ... and .main.c function
3.1. Macro definition
APP_TIMER_DEF(m_battery_timer_id);
BLE_LBS_mpu6050_DEF(m_mpu6050);// Observer mode
static ble_lbs_t m_mpu6050;
ble_bas_battery_level_update(&m_mpu6050, TIME_TEMP, BLE_CONN_HANDLE_ALL);
3.2.services_init
Mainly initialization ble_lbs.c Inside ble_lbs_init
ble_lbs_init_t bas_init_obj;
memset(&bas_init_obj, 0, sizeof(bas_init_obj));
err_code = ble_lbs_init(&m_mpu6050, &bas_init_obj);
3.3. Timer
Callback function measure_timer_handler
TIME_TEMP Is an analog value
ble_bas_battery_level_update(&m_mpu6050, TIME_TEMP, BLE_CONN_HANDLE_ALL);
边栏推荐
- Memory model, reference and function supplement of program
- RTMP streaming +rtmp playback low delay solution in unity environment
- Laravel8 authentication login
- [go] Viper reads the configuration file in the go project
- Introduction to sringmvc
- Go 面向接口编程实战
- 国企为什么要上市
- CCF noi2022 quota allocation scheme
- Tabulation skills and matrix processing skills
- March 4, 2021
猜你喜欢

公司注册认缴资金多久
![[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation](/img/12/27531fc791b3f49306385831309c5e.png)
[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation

Word frequency statistics using Jieba database

Performance test - GTI application service performance monitoring platform

Nature | make an account of the new crown casualties in the world

FPGA语法的细节

TCP and UDP introduction

Wireshark filter rule

Halcon 3D 深度图转换为3D图像

Towards End-to-End Lane Detection: an Instance SegmentationApproach
随机推荐
Review notes of naturallanguageprocessing based on deep learning
Memory model, reference and function supplement of program
Redis cluster cluster capacity expansion and data migration
基于LFFD模型目标检测自动标注生成xml文件
Laravel8 authentication login
March 23, 2021
登录验证过滤器
Multiple ways 99.9% to solve the problem of garbled code after copying text from PDF
Halcon 3D 深度图转换为3D图像
Optipng can optimize the compressed PNG picture file format
Greenplum [question 05] Greenplum streaming server custom client problem handling (increasing)
Oracle EBS interface/api (34) - update vendor API
Golang idea configures the agent to improve the speed of packages downloaded by go get
Flex / fixed Upper, Middle and Lower (Mobile end)
XML parameter schema, the same MTK SW version is compatible with two different sets of audio parameters
Legal liabilities to be borne by the person in charge of the branch
[untitled]
Individual application for ov type SSL certificate
Is the individual industrial and commercial door a legal person enterprise
Heap classical problem