CC2640 广播数据构成分析

来源:互联网 发布:爱家呐软件多少钱 编辑:程序博客网 时间:2024/06/05 23:49

第二章 CC2640广播数据构成

第一步:将SimpleBLEPeripheral例程烧录到蓝牙中然后就开启广播之旅了。。。。。。。。。

Packet Sniffer抓包

 1        2        3           4                5                           6                      7               8             9      10 

下标为1 P.nbr表示为接收数据包个数。

下标为2Time(us)表示从接收第一个数据包开始计时,每接一个包的间隔。故第一个为0,第二个为108003us,所以广播间隔大概为100ms。在此处有定义

// Advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL          160

当改变DEFAULT_ADVERTISING_INTERVAL的值为320时,结果为:

此时广播间隔为205006us,即约为200ms

下标为3 Channel为广播通道,0X25十进制为37.

  {
    uint8_t AdvMap = GAP_ADVCHAN_37;
    GAPRole_SetParameter(GAPROLE_ADV_CHANNEL_MAP, sizeof(uint8_t), &AdvMap);
  }

通过改变AdvMap的可以设置专用广播信道。默认的情况下为GAP_ADVCHAN_ALL所有信道都在广播。建议在实际使用是使用默认,这样可以提高抗干扰能力。

GAP_ADVCHAN_37可以在GAP.h中找。

/** @defgroup GAP_ADVCHAN_DEFINES GAP Advertisement Channel Map
 * @{
 */
#define GAP_ADVCHAN_37  0x01  //!< Advertisement Channel 37
#define GAP_ADVCHAN_38  0x02  //!< Advertisement Channel 38
#define GAP_ADVCHAN_39  0x04  //!< Advertisement Channel 39
#define GAP_ADVCHAN_ALL (GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39) //!< All Advertisement Channels Enabled
/** @} End GAP_ADVCHAN_DEFINES */

下标为4Access AddressDongle 自己MAC地址。

下标为5Adv PDU Type广播报文类型为ADV_IND  解释如下

#define GAP_ADTYPE_ADV_IND                0x00  //!< Connectable undirected advertisement

可非定向广播连接。

在程序中的位置为

static void gapRole_init(void)
{
  // Register the current thread as an ICall dispatcher application
  // so that the application can send and receive messages.
  ICall_registerApp(&selfEntity, &sem);
 
  gapRole_state = GAPROLE_INIT;
  gapRole_ConnectionHandle = INVALID_CONNHANDLE;
 
  // Get link DB maximum number of connections
  linkDBNumConns = linkDB_NumConns();

  // Setup timers as one-shot timers   分派一个时钟。
  Util_constructClock(&startAdvClock, gapRole_clockHandler,
                      0, 0, false, START_ADVERTISING_EVT);
  Util_constructClock(&startUpdateClock, gapRole_clockHandler,
                      0, 0, false, START_CONN_UPDATE_EVT);
  Util_constructClock(&updateTimeoutClock, gapRole_clockHandler,
                      0, 0, false, CONN_PARAM_TIMEOUT_EVT);
  
  // Initialize the Profile Advertising and Connection Parameters
  gapRole_profileRole = GAP_PROFILE_PERIPHERAL;
  VOID memset(gapRole_IRK, 0, KEYLEN);
  VOID memset(gapRole_SRK, 0, KEYLEN);
  gapRole_signCounter = 0;
  gapRole_AdvEventType = GAP_ADTYPE_ADV_IND;
  gapRole_AdvDirectType = ADDRTYPE_PUBLIC;
  gapRole_AdvChanMap = GAP_ADVCHAN_ALL;
  gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_ALL;

  // Restore Items from NV
  VOID osal_snv_read(BLE_NVID_IRK, KEYLEN, gapRole_IRK);
  VOID osal_snv_read(BLE_NVID_CSRK, KEYLEN, gapRole_SRK);
  VOID osal_snv_read(BLE_NVID_SIGNCOUNTER, sizeof(uint32_t),
                     &gapRole_signCounter);
}

下标为6 Adv PDU Header报头。

         广播类型是通用广播(Type 0AdvPDU Type)。

         地址类型都是publicgapRole_AdvDirectType = ADDRTYPE_PUBLIC;见上图。(TxAddRxAdd都为0)。

         长度字段指示PDU-Length AdvA + AdvData之和。

下标为7AdvA为本机MAC地址。在第一章中已经提到。

下标为8AdvData为广播数据,可以在

// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8_t advertData[] =
{
  // Flags; this sets the device to use limited discoverable
  // mode (advertises for 30 seconds at a time) instead of general
  // discoverable mode (advertises indefinitely)
  0x02,   // length of this data
  GAP_ADTYPE_FLAGS,
  DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,

  // service UUID, to notify central devices what services are included
  // in this peripheral
  0x03,   // length of this data
  GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all
#ifdef FEATURE_OAD
  LO_UINT16(OAD_SERVICE_UUID),
  HI_UINT16(OAD_SERVICE_UUID)
#else
  LO_UINT16(SIMPLEPROFILE_SERV_UUID),
  HI_UINT16(SIMPLEPROFILE_SERV_UUID)
#endif //!FEATURE_OAD
};

中找到答案。

 

1 0
原创粉丝点击