Fork me on GitHub

随笔 - 997  文章 - 5  评论 - 181  阅读 - 300万 
一 概念
直接上英文原文,怕自己的翻译误导大家。
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 */
这两个结合在一起看,是不是就理解了呢?

 

 
posted on   虚生  阅读(384)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
历史上的今天:
2018-04-12 Linux下用ifconfig命令设置IP、掩码、网关
点击右上角即可分享
微信分享提示