DA1458x DISS Database的组成结构 -- Device Information Service 分析(一)

Overview

本文基于DA1458x SDK 5.0.4。
Device Information Service 以下简称DIS or DISS。DISS的代码主要有以下两个组C文件组成

DA1458x DISS Database的组成结构 -- Device Information Service 分析(一)_第1张图片

另,DISS是依赖于APP_TASK任务来调度管理的。具体框架如下图(摘自Dialog官方文档)

DA1458x DISS Database的组成结构 -- Device Information Service 分析(一)_第2张图片

Full DISS Database Description (DISS Database 分析)

DISS的Database的变量名为 diss_att_db
由以下19个成员组成

No. Name Description
1 DIS_IDX_SVC Device Information Service Declaration
2 DIS_IDX_MANUFACTURER_NAME_CHAR Manufacturer Name Characteristic Declaration
3 DIS_IDX_MANUFACTURER_NAME_VAL Manufacturer Name Characteristic Value
4 DIS_IDX_MODEL_NB_STR_CHAR Model Number String Characteristic Declaration
5 DIS_IDX_MODEL_NB_STR_VAL Model Number String Characteristic Value
6 DIS_IDX_SERIAL_NB_STR_CHAR Serial Number String Characteristic Declaration
7 DIS_IDX_SERIAL_NB_STR_VAL Serial Number String Characteristic Value
8 DIS_IDX_HARD_REV_STR_CHAR Hardware Revision String Characteristic Declaration
9 DIS_IDX_HARD_REV_STR_VAL Hardware Revision String Characteristic Value
10 DIS_IDX_FIRM_REV_STR_CHAR Firmware Revision String Characteristic Declaration
11 DIS_IDX_FIRM_REV_STR_VAL Firmware Revision String Characteristic Value
12 DIS_IDX_SW_REV_STR_CHAR Software Revision String Characteristic Declaration
13 DIS_IDX_SW_REV_STR_VAL Software Revision String Characteristic Value
14 DIS_IDX_SYSTEM_ID_CHAR System ID Characteristic Declaration
15 DIS_IDX_SYSTEM_ID_VAL System ID Characteristic Value
16 DIS_IDX_IEEE_CHAR IEEE 11073-20601 Regulatory Certification Data List Characteristic Declaration
17 DIS_IDX_IEEE_VAL IEEE 11073-20601 Regulatory Certification Data List Characteristic Value
18 DIS_IDX_PNP_ID_CHAR PnP ID Characteristic Declaration
19 DIS_IDX_PNP_ID_VAL PnP ID Characteristic Value

这个变量非常重要,本文我们就围绕着它来一步步来分析。

diss_att_db结构体数组索引

首先这是一个结构体数组的索引,该索引采取的是枚举类型,方便阅读和理解。

///Attributes State Machine
enum
{
    DIS_IDX_SVC,

    DIS_IDX_MANUFACTURER_NAME_CHAR,
    DIS_IDX_MANUFACTURER_NAME_VAL,

    DIS_IDX_MODEL_NB_STR_CHAR,
    DIS_IDX_MODEL_NB_STR_VAL,

    DIS_IDX_SERIAL_NB_STR_CHAR,
    DIS_IDX_SERIAL_NB_STR_VAL,

    DIS_IDX_HARD_REV_STR_CHAR,
    DIS_IDX_HARD_REV_STR_VAL,

    DIS_IDX_FIRM_REV_STR_CHAR,
    DIS_IDX_FIRM_REV_STR_VAL,

    DIS_IDX_SW_REV_STR_CHAR,
    DIS_IDX_SW_REV_STR_VAL,

    DIS_IDX_SYSTEM_ID_CHAR,
    DIS_IDX_SYSTEM_ID_VAL,

    DIS_IDX_IEEE_CHAR,
    DIS_IDX_IEEE_VAL,

    DIS_IDX_PNP_ID_CHAR,
    DIS_IDX_PNP_ID_VAL,

    DIS_IDX_NB,
};

接下来我们看下attm_desc这个结构体的定义

struct attm_desc 结构体的定义

这个结构体的定义如下

 /// Attribute description (used to create database)
 struct attm_desc
 {
     /// Element UUID
     uint16_t uuid;
     /// Attribute permission
     uint16_t perm;
     /// Maximum length of the element
     att_size_t max_length;
     /// Current length of the element
     att_size_t length;
     /// Element value array
     uint8_t* value;
 };

我们可以看到,第一个成员是16位UUID,用来记录这个Attribute(属性)的UUID;
第二个成员是Attribute permission(属性权限);
第三个成员是Maximum length of the element(元素的最大长度);
第四个成员是Current length of the element(当前元素的长处);
第五个成员是Element Value array(元素数组)。

uuid和perm为16bit无符号整型变量,value为uint8_t数组指针,att_size_t类型其实uint16_t

/// Attribute length type
typedef uint16_t att_size_t;

diss_att_db定义

定义如下(diss.c文件中)

/*
 * DIS ATTRIBUTES
 ****************************************************************************************
 */

/// Full DIS Database Description - Used to add attributes into the database
const struct attm_desc diss_att_db[DIS_IDX_NB] =
{
    // Device Information Service Declaration
    [DIS_IDX_SVC]                           =   {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), sizeof(diss_dis_svc),
                                                 sizeof(diss_dis_svc), (uint8_t *)&diss_dis_svc},

    // Manufacturer Name Characteristic Declaration
    [DIS_IDX_MANUFACTURER_NAME_CHAR]        =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_manufacturer_name_char),
                                                 sizeof(diss_manufacturer_name_char), (uint8_t *)&diss_manufacturer_name_char},
    // Manufacturer Name Characteristic Value
    [DIS_IDX_MANUFACTURER_NAME_VAL]         =   {ATT_CHAR_MANUF_NAME, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // Model Number String Characteristic Declaration
    [DIS_IDX_MODEL_NB_STR_CHAR]             =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_model_nb_str_char),
                                                 sizeof(diss_model_nb_str_char), (uint8_t *)&diss_model_nb_str_char},
    // Model Number String Characteristic Value
    [DIS_IDX_MODEL_NB_STR_VAL]              =   {ATT_CHAR_MODEL_NB, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // Serial Number String Characteristic Declaration
    [DIS_IDX_SERIAL_NB_STR_CHAR]            =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_serial_nb_str_char),
                                                 sizeof(diss_serial_nb_str_char), (uint8_t *)&diss_serial_nb_str_char},
    // Serial Number String Characteristic Value
    [DIS_IDX_SERIAL_NB_STR_VAL]             =   {ATT_CHAR_SERIAL_NB, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // Hardware Revision String Characteristic Declaration
    [DIS_IDX_HARD_REV_STR_CHAR]             =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_hard_rev_str_char),
                                                 sizeof(diss_hard_rev_str_char), (uint8_t *)&diss_hard_rev_str_char},
    // Hardware Revision String Characteristic Value
    [DIS_IDX_HARD_REV_STR_VAL]              =   {ATT_CHAR_HW_REV, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // Firmware Revision String Characteristic Declaration
    [DIS_IDX_FIRM_REV_STR_CHAR]             =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_firm_rev_str_char),
                                                 sizeof(diss_firm_rev_str_char), (uint8_t *)&diss_firm_rev_str_char},
    // Firmware Revision String Characteristic Value
    [DIS_IDX_FIRM_REV_STR_VAL]              =   {ATT_CHAR_FW_REV, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // Software Revision String Characteristic Declaration
    [DIS_IDX_SW_REV_STR_CHAR]               =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_sw_rev_str_char),
                                                 sizeof(diss_sw_rev_str_char), (uint8_t *)&diss_sw_rev_str_char},
    // Software Revision String Characteristic Value
    [DIS_IDX_SW_REV_STR_VAL]                =   {ATT_CHAR_SW_REV, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // System ID Characteristic Declaration
    [DIS_IDX_SYSTEM_ID_CHAR]                =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_system_id_char),
                                                 sizeof(diss_system_id_char), (uint8_t *)&diss_system_id_char},
    // System ID Characteristic Value
    [DIS_IDX_SYSTEM_ID_VAL]                 =   {ATT_CHAR_SYS_ID, PERM(RD, ENABLE), DIS_SYS_ID_LEN, 0, NULL},

    // IEEE 11073-20601 Regulatory Certification Data List Characteristic Declaration
    [DIS_IDX_IEEE_CHAR]                     =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_ieee_char),
                                                 sizeof(diss_ieee_char), (uint8_t *)&diss_ieee_char},
    // IEEE 11073-20601 Regulatory Certification Data List Characteristic Value
    [DIS_IDX_IEEE_VAL]                      =   {ATT_CHAR_IEEE_CERTIF, PERM(RD, ENABLE), DIS_VAL_MAX_LEN, 0, NULL},

    // PnP ID Characteristic Declaration
    [DIS_IDX_PNP_ID_CHAR]                   =   {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(diss_pnp_id_char),
                                                 sizeof(diss_pnp_id_char), (uint8_t *)&diss_pnp_id_char},
    // PnP ID Characteristic Value
    [DIS_IDX_PNP_ID_VAL]                    =   {ATT_CHAR_PNP_ID, PERM(RD, ENABLE), DIS_PNP_ID_LEN, 0, NULL},
};

由上述定义我们来一个个分析bas_att_db的五个成员变量。

[DIS_IDX_SVC]

首先是[DIS_IDX_SVC]成员变量。
DIS_IDX_SVC的value是diss_dis_svc变量,具体如下:

const att_svc_desc_t diss_dis_svc = ATT_SVC_BATTERY_SERVICE;

我们可以看到diss_dis_svc被赋值为一个枚举类型变量,具体值为0x180A。
类似的还有ATT_SVC_GENERIC_ACCESS、ATT_SVC_GENERIC_ATTRIBUTE、ATT_SVC_BATTERY_SERVICE、ATT_SVC_HID等。
具体定义如下:

/// Common 16-bit Universal Unique Identifier
enum {
    ATT_INVALID_UUID = 0,
    /*----------------- SERVICES ---------------------*/
    /// Generic Access Profile
    ATT_SVC_GENERIC_ACCESS                      = 0x1800,
    /// Attribute Profile
    ATT_SVC_GENERIC_ATTRIBUTE,
    ...
    /// Device Information Service
    ATT_SVC_DEVICE_INFO                         = 0x180A,
    ...
    /// Battery Service
    ATT_SVC_BATTERY_SERVICE,
    /// Blood Pressure Service
    ATT_SVC_BLOOD_PRESSURE                      = 0x1810,
    /// Alert Notification Service
    ATT_SVC_ALERT_NTF                           = 0x1811,
    /// HID Service
    ATT_SVC_HID                                 = 0x1812,
    ...
}

DA1458x DISS Database的组成结构 -- Device Information Service 分析(一)_第3张图片

小结

DISS Database类型总结

No. Index enum 类型 UUID
1 DIS_IDX_SVC ATT_DECL_PRIMARY_SERVICE DECLARATIONS 0x2800
2 DIS_IDX_MANUFACTURER_NAME_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
3 DIS_IDX_MANUFACTURER_NAME_VAL ATT_CHAR_MANUF_NAME CHARACTERISTICS 0x2A29
4 DIS_IDX_MODEL_NB_STR_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
5 DIS_IDX_MODEL_NB_STR_VAL ATT_CHAR_MODEL_NB CHARACTERISTICS 0x2A24
6 DIS_IDX_SERIAL_NB_STR_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
7 DIS_IDX_SERIAL_NB_STR_VAL ATT_CHAR_SERIAL_NB CHARACTERISTICS 0x2A25
8 DIS_IDX_HARD_REV_STR_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
9 DIS_IDX_HARD_REV_STR_VAL ATT_CHAR_HW_REV CHARACTERISTICS 0x2A27
10 DIS_IDX_FIRM_REV_STR_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
11 DIS_IDX_FIRM_REV_STR_VAL ATT_CHAR_FW_REV CHARACTERISTICS 0x2A26
12 DIS_IDX_SW_REV_STR_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
13 DIS_IDX_SW_REV_STR_VAL ATT_CHAR_SW_REV CHARACTERISTICS 0x2A28
14 DIS_IDX_SYSTEM_ID_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
15 DIS_IDX_SYSTEM_ID_VAL ATT_CHAR_SYS_ID CHARACTERISTICS 0x2A23
16 DIS_IDX_IEEE_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
17 DIS_IDX_IEEE_VAL ATT_CHAR_IEEE_CERTIF CHARACTERISTICS 0x2A2A
18 DIS_IDX_PNP_ID_CHAR ATT_DECL_CHARACTERISTIC DECLARATIONS 0x2803
19 DIS_IDX_PNP_ID_VAL ATT_CHAR_PNP_ID CHARACTERISTICS 0x2A50

你可能感兴趣的:(DA1458x)