安卓調試工具掃描時直接顯示就是MAC地址。
蘋果設備是以UUID的方式顯示。
所以我們直接用安卓設備來測試。
我們連接時可以知道主機的地址。
變量是gapRole_ConnectedDevAddr,可以在peripherial.c里搜索GAP_LINK_ESTABLISHED_EVENT事件的處理。
static
void gapRole_ProcessGAPMsg( gapEventHdr_t
*pMsg )
{uint8 notify
= FALSE; switch ( pMsg
->opcode ){
case GAP_DEVICE_INIT_DONE_EVENT:{gapDeviceInitDoneEvent_t
*pPkt
= (gapDeviceInitDoneEvent_t
*)pMsg;bStatus_t stat
= pPkt
->hdr
.status;
if ( stat
== SUCCESS ){
VOID osal_snv_write( BLE_NVID_IRK, KEYLEN, gapRole_IRK );
VOID osal_snv_write( BLE_NVID_CSRK, KEYLEN, gapRole_SRK );
VOID osal_memcpy( gapRole_bdAddr, pPkt
->devAddr, B_ADDR_LEN );gapRole_state
= GAPROLE_STARTED;stat
= GAP_UpdateAdvertisingData( gapRole_TaskID,
TRUE, gapRole_AdvertDataLen, gapRole_AdvertData );}
if ( stat
!= SUCCESS ){gapRole_state
= GAPROLE_ERROR;}notify
= TRUE;}break;
case GAP_ADV_DATA_UPDATE_DONE_EVENT:{gapAdvDataUpdateEvent_t
*pPkt
= (gapAdvDataUpdateEvent_t
*)pMsg;
if ( pPkt
->hdr
.status
== SUCCESS ){
if ( pPkt
->adType ){pPkt
->hdr
.status
= GAP_UpdateAdvertisingData( gapRole_TaskID,
FALSE, gapRole_ScanRspDataLen, gapRole_ScanRspData );}
else{
VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );}}
if ( pPkt
->hdr
.status
!= SUCCESS ){gapRole_state
= GAPROLE_ERROR;notify
= TRUE;}}break;
case GAP_MAKE_DISCOVERABLE_DONE_EVENT:
case GAP_END_DISCOVERABLE_DONE_EVENT:{gapMakeDiscoverableRspEvent_t
*pPkt
= (gapMakeDiscoverableRspEvent_t
*)pMsg;
if ( pPkt
->hdr
.status
== SUCCESS ){
if ( pMsg
->opcode
== GAP_MAKE_DISCOVERABLE_DONE_EVENT ){gapRole_state
= GAPROLE_ADVERTISING;}
else {
if ( gapRole_AdvertOffTime
!= 0 ){
if ( ( gapRole_AdvEnabled ) ){
VOID osal_start_timerEx( gapRole_TaskID, START_ADVERTISING_EVT, gapRole_AdvertOffTime );}}
else{gapRole_AdvEnabled
= FALSE;}gapRole_state
= GAPROLE_WAITING;}}
else{gapRole_state
= GAPROLE_ERROR;}notify
= TRUE;}break;
case GAP_LINK_ESTABLISHED_EVENT:{gapEstLinkReqEvent_t
*pPkt
= (gapEstLinkReqEvent_t
*)pMsg;
if ( pPkt
->hdr
.status
== SUCCESS ){
VOID osal_memcpy( gapRole_ConnectedDevAddr, pPkt
->devAddr, B_ADDR_LEN );gapRole_ConnectionHandle
= pPkt
->connectionHandle;gapRole_state
= GAPROLE_CONNECTED;
if ( gapRole_RSSIReadRate ){
VOID osal_start_timerEx( gapRole_TaskID, RSSI_READ_EVT, gapRole_RSSIReadRate );}gapRole_ConnInterval
= pPkt
->connInterval;gapRole_ConnSlaveLatency
= pPkt
->connLatency;gapRole_ConnTimeout
= pPkt
->connTimeout;
if ( gapRole_ParamUpdateEnable
== TRUE ){uint16 timeout
= GAP_GetParamValue( TGAP_CONN_PAUSE_PERIPHERAL );osal_start_timerEx( gapRole_TaskID, START_CONN_UPDATE_EVT, timeout
*1000 );}
VOID GAPBondMgr_LinkEst( pPkt
->devAddrType, pPkt
->devAddr, pPkt
->connectionHandle, GAP_PROFILE_PERIPHERAL );}
else if ( pPkt
->hdr
.status
== bleGAPConnNotAcceptable ){gapRole_AdvEnabled
= FALSE;gapRole_state
= GAPROLE_WAITING;}
else{gapRole_state
= GAPROLE_ERROR;}notify
= TRUE;}break;
case GAP_LINK_TERMINATED_EVENT:{gapTerminateLinkEvent_t
*pPkt
= (gapTerminateLinkEvent_t
*)pMsg;GAPBondMgr_ProcessGAPMsg( (gapEventHdr_t
*)pMsg );osal_memset( gapRole_ConnectedDevAddr,
0, B_ADDR_LEN );gapRole_ConnInterval
= 0;gapRole_ConnSlaveLatency
= 0;gapRole_ConnTimeout
= 0;
VOID osal_stop_timerEx( gapRole_TaskID, START_CONN_UPDATE_EVT );
VOID osal_stop_timerEx( gapRole_TaskID, CONN_PARAM_TIMEOUT_EVT );
if( pPkt
->reason
== LL_SUPERVISION_TIMEOUT_TERM ){gapRole_state
= GAPROLE_WAITING_AFTER_TIMEOUT;}
else{gapRole_state
= GAPROLE_WAITING;}notify
= TRUE;
VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );gapRole_ConnectionHandle
= INVALID_CONNHANDLE;}break;
case GAP_LINK_PARAM_UPDATE_EVENT:{gapLinkUpdateEvent_t
*pPkt
= (gapLinkUpdateEvent_t
*)pMsg;
VOID osal_stop_timerEx( gapRole_TaskID, CONN_PARAM_TIMEOUT_EVT );
if ( pPkt
->hdr
.status
== SUCCESS ){gapRole_ConnInterval
= pPkt
->connInterval;gapRole_ConnSlaveLatency
= pPkt
->connLatency;gapRole_ConnTimeout
= pPkt
->connTimeout;
if ( osal_get_timeoutEx( gapRole_TaskID, START_CONN_UPDATE_EVT )
== 0 ){
if ( pGapRoles_ParamUpdateCB
!= NULL ){(
*pGapRoles_ParamUpdateCB)( gapRole_ConnInterval, gapRole_ConnSlaveLatency, gapRole_ConnTimeout );}}}}break;default:break;}
if ( notify
== TRUE ){
if ( pGapRoles_AppCGs
&& pGapRoles_AppCGs
->pfnStateChange ){pGapRoles_AppCGs
->pfnStateChange( gapRole_state );}}
}
應用場景:需要把mac地址通過藍牙傳輸上去的話,gapRole_ConnectedDevAddr可以使用的到。
總結
以上是生活随笔為你收集整理的【BLE】CC2541获取设备的MAC地址实验的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。