nrf51822 code reading notes three

Device Information Service

Here's a look at the service of nordic nrf51822 that defines device information. This module implements the Device Information Service, which is used to implement the device information service. During initialization it adds the Device Information Service to the BLE stack database. It then encodes the supplied information, and adds the corresponding characteristics. During initialization, it adds the Device Information Service to the BLE stack database. Then provide the encoding information and add the corresponding eigenvalues.

The source of the supplier ID

Two sources of vendor IDs are available in the 51822 library

#define  BLE_DIS_VENDOR_ID_SRC_BLUETOOTH_SIG   1 
#define  BLE_DIS_VENDOR_ID_SRC_USB_IMPL_FORUM   2 

From the Bluetooth Alliance SIG and forums.

DIS

In fact, I want to explain the source of the abbreviations of some functions of nodic. For example, when using the device information service, the functions with the dis abbreviation are often used, which are actually the abbreviations of the Device Information Service and the uart service. When the abbreviation of nus is used, it is actually the abbreviation of nordic uart service.
Header files need to be referenced when using Device Information Service

     #include <ble_dis.h>

main data structure

System ID parameter

Mainly include manufacturer: manufacturer_id and I: Organizationally_unique_id certified by the organization

/**@brief System ID parameters */
typedef struct
{
    uint64_t manufacturer_id;                                   /**< Manufacturer ID. Only 5 LSOs shall be used. */
    uint32_t organizationally_unique_id;                        /**< Organizationally unique ID. Only 3 LSOs shall be used. */
} ble_dis_sys_id_t;

ble_dis_reg_cert_data_list_t

/**@brief IEEE 11073-20601 Regulatory Certification Data List Structure */
typedef struct
{
    uint8_t *  p_list;                                          /**< Pointer the byte array containing the encoded opaque structure based on IEEE 11073-20601 specification. */
    uint8_t    list_len;                                        /**< Length of the byte array. */
} ble_dis_reg_cert_data_list_t;

ble_dis_pnp_id_t

vendor_id Vendor ID
product_id Product ID

/**@brief PnP ID parameters */
typedef struct
{
    uint8_t  vendor_id_source;                                  /**< Vendor ID Source. see @ref DIS_VENDOR_ID_SRC_VALUES. */
    uint16_t vendor_id;                                         /**< Vendor ID. */
    uint16_t product_id;                                        /**< Product ID. */
    uint16_t product_version;                                   /**< Product Version. */
} ble_dis_pnp_id_t;

ble_srv_security_mode_t

Settings, read and write permissions for Bluetooth.

    /**@brief Security settings structure.
     * @details This structure contains the security options needed during initialization of the
     *          service.
     */
    typedef struct
    {
        ble_gap_conn_sec_mode_t read_perm;                  /**< Read permissions. */
        ble_gap_conn_sec_mode_t write_perm;                 /**< Write permissions. */
    } ble_srv_security_mode_t;

ble_dis_init_t

The device information service initialization structure, which contains all possible characteristics of the device information.

/**@brief Device Information Service init structure. This contains all possible characteristics needed for initialization of the service.
 */
typedef struct
{
    ble_srv_utf8_str_t             manufact_name_str;           /**< Manufacturer Name String. */
    ble_srv_utf8_str_t             model_num_str;               /**< Model Number String. */
    ble_srv_utf8_str_t             serial_num_str;              /**< Serial Number String. */
    ble_srv_utf8_str_t             hw_rev_str;                  /**< Hardware Revision String. */
    ble_srv_utf8_str_t             fw_rev_str;                  /**< Firmware Revision String. */
    ble_srv_utf8_str_t             sw_rev_str;                  /**< Software Revision String. */
    ble_dis_sys_id_t *             p_sys_id;                    /**< System ID. */
    ble_dis_reg_cert_data_list_t * p_reg_cert_data_list;        /**< IEEE 11073-20601 Regulatory Certification Data List. */
    ble_dis_pnp_id_t *             p_pnp_id;                    /**< PnP ID. */
    ble_srv_security_mode_t        dis_attr_md;                 /**< Initial Security Setting for Device Information Characteristics.设备信息特征的初始安全设置。 */
} ble_dis_init_t;

dis_init

/**@brief Function for initializing the Device Information Service.
 */
void dis_init(uint8_t* app_version_string,uint8_t* hard_version_string)
{
    uint32_t       err_code;
    ble_dis_init_t dis_init_obj;

memset(&dis_init_obj, 0, sizeof(dis_init_obj));

//生产厂家
dis_init_obj.manufact_name_str.length = ; 
dis_init_obj.manufact_name_str.p_str  =;

dis_init_obj.model_num_str.length = ;
dis_init_obj.model_num_str.p_str  = ;

dis_init_obj.serial_num_str.length = ;
dis_init_obj.serial_num_str.p_str  = ;

dis_init_obj.hw_rev_str.length = ;
dis_init_obj.hw_rev_str.p_str  = ;

dis_init_obj.fw_rev_str.length = ;
dis_init_obj.fw_rev_str.p_str  = ;

dis_init_obj.sw_rev_str.length = ;
dis_init_obj.sw_rev_str.p_str  = ;
//设置dis可读属性。
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init_obj.dis_attr_md.read_perm);
//设置dis信息写无法访问即信息无法写入。
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init_obj.dis_attr_md.write_perm);

err_code = ble_dis_init(&dis_init_obj);
APP_ERROR_CHECK(err_code);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325598184&siteId=291194637