Host modification based on DSPS

This article is mainly aimed at the actual project that needs to be developed for a specific slave to achieve data communication, so it is recorded that the host project is based on DSPS demo: DA14585_DSPS\projects\target_apps\dsps\dsps_host\Keil_5
1. In slave engineering, there is only one service for communication, but this service includes two features (handles), one for receiving data, and one for sending data as follows:
Insert picture description here
Insert picture description here

SVC1_ADC_VAL_1_UUID_128 is used to send data from the slave to the master (FFF2), and
SVC1_ADC_VAL_2_UUID_128 has been sent in the notify mode for the master to send data to the slave (FFF1), and sent in the GATTC_WRITE mode.
2. Add the characteristic UUID and handle in the first step above Later, we need to define the feature-specific descriptors in spsc_sps_char_desc. Here, there are two descriptors for viewing the slave service through the mobile phone app on No. 1, and one on No. 2, corresponding to 2901 and 2902 as follows:
Insert picture description here
Insert picture description here
Insert picture description here

3. After adding the feature attributes, it is how to use these two features in order to search and compare with the slaves of the specific service when the host is scanning.
1. In sps_client_enable_req_handler, add the primary service to sps_data_service_uuid
Insert picture description here
2. Add the database spsc_sps_char_16 just added:
Insert picture description here
3. In the following function gattc_disc_char_desc_ind_handler, add the total length of the handle and the database.
Insert picture description here
4. Sps_client_enable_status
Insert picture description here
= return status return service to confirm ATT_ERR_send. Indicates that the service was added successfully.
4. Data transmission and reception with the slave
Insert picture description here
This function is used to receive messages from the slave.
Insert picture description here
At this point, the service is added. At this time, we can communicate with the slave by calling these two interface functions.

Note:
1. The more important function is gattc_cmp_evt_handler. In this function, adding services and receiving data are all done in this function. The architecture is:
if(state == SPS_CLIENT_DISCOVERING){}
else if (state == SPS_CLIENT_CONNECTED){}
2. Add process:
->sps_client_enable_req_handler (add the first task)
->gattc_disc_svc_ind_handler()
->gattc_cmp_evt_handler (main function) , The process of discovering the service is carried out here, refer to Note1)
->prf_disc_char_all_send
->gattc_disc_char_ind_handler (by calling prf_search_chars to compare the characteristic value database of the master and the slave)
->prf_check_svc_char_validity_128 (verify the validity of the service characteristic
value_c_end_chardesc_disc ) ->
->gattc_disc_char_desc_ind_handler (by calling prf_search_descs to compare the descriptor database of the master and the slave)
->prf_search_descs
->sps_client_enable_cfm_send (return whether the result of adding the service is successful)
3. When writing data to the slave: the handle needs to be passed through the following function Write, the last parameter is the writing method
Insert picture description here
Insert picture description here
4. When receiving data from the slave: It is necessary to determine which handle is sent.
Insert picture description here
5. It is worth noting that the master-slave communication is mainly based on UUID as the transmission channel. Therefore, in the master-slave code, it is normal that the serial numbers are not matched. The key is to see whether the UUID corresponding to the serial number of the operation can be matched. This is the most Basic operation.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_24179601/article/details/83788699