• 可穿戴智能手环解决方案之BLE的ADV广播协议解读


    一 概念
    直接上英文原文,怕自己的翻译误导大家。
    When a BLE device is advertising, it periodically transmits packets, which contain information such as the preamble, access address, CRC, Bluetooth sender address, and so on. Application developers are often interested in theadvertising payloadthat is0-31 bytes longon the primary channelsbecause it is controlled by the application. For extended advertising, the maximum length is 1650 bytes, but advertising parameters may limit the amount of data that can be sent in a single advertisement. Other fields in the advertising packets are automatically filled by the Bluetooth stack.
     
    二 协议分析
    这里先记着这几个常用的数据类型,接下来就容易理解了。
    Some of the most commonly used data types are:
    0x01 = Flags
    0x03 = Complete List of 16-bit Service Class UUIDs
    0x09 = Complete Local Name
    0x08 = Shortened Local Name
    截图显示:
    对应代码:
    /**************************************************************************************************
      Advertising Data
    **************************************************************************************************/
    
    /*! advertising data, discoverable mode */
    static const uint8_t fitAdvDataDisc[] =
    {
      /*! flags */
      2,                                      /*! length */
      DM_ADV_TYPE_FLAGS,                      /*! AD type */
      DM_FLAG_LE_GENERAL_DISC |               /*! flags */
      DM_FLAG_LE_BREDR_NOT_SUP,
    
      /*! tx power */
      2,                                      /*! length */
      DM_ADV_TYPE_TX_POWER,                   /*! AD type */
      0,                                      /*! tx power */
    
      /*! service UUID list */
      9,                                      /*! length */
      DM_ADV_TYPE_16_UUID,                    /*! AD type */
      UINT16_TO_BYTES(ATT_UUID_HEART_RATE_SERVICE),
      UINT16_TO_BYTES(ATT_UUID_RUNNING_SPEED_SERVICE),
      UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE),
      UINT16_TO_BYTES(ATT_UUID_BATTERY_SERVICE)
    };
    
    /*! scan data, discoverable mode */
    static const uint8_t fitScanDataDisc[] =
    {
      /*! device name */
      4,                                      /*! length */
      DM_ADV_TYPE_LOCAL_NAME,                 /*! AD type */
      'F',
      'i',
      't'
    };
    看一下着里面的几个的几个宏定义,就理解adv广播的含义了:
     
    #define ATT_UUID_HEALTH_THERM_SERVICE 0x1809 /*!< \brief Health Thermometer Service */
    #define ATT_UUID_DEVICE_INFO_SERVICE 0x180A /*!< \brief Device Information Service */
    #define ATT_UUID_HEART_RATE_SERVICE 0x180D /*!< \brief Heart Rate Service */
    #define ATT_UUID_PHONE_ALERT_SERVICE 0x180E /*!< \brief Phone Alert Status Service */
    #define ATT_UUID_BATTERY_SERVICE 0x180F /*!< \brief Battery Service */
    #define DM_ADV_TYPE_FLAGS 0x01 /*!< \brief Flag bits */
    #define DM_ADV_TYPE_LOCAL_NAME 0x09 /*!< \brief Complete local name */
    #define DM_ADV_TYPE_TX_POWER 0x0A /*!< \brief TX power level */
    这两个结合在一起看,是不是就理解了呢?

     

     
  • 相关阅读:
    JS学习笔记-OO疑问之对象创建
    文件系统类型:
    Swift 编程语言新手教程
    数组长度计算
    tomcat配置文件server.xml具体解释
    openGL点精灵PointSprite具体解释: 纹理映射,旋转,缩放,移动
    iOS安全攻防(三):使用Reveal分析他人app
    逍遥叹
    oracle存储过程实例
    Java爬虫
  • 原文地址:https://www.cnblogs.com/dylancao/p/16136267.html
Copyright © 2020-2023  润新知