FRDM-KW36入门学习(七、开机后自动广播)

6 篇文章 7 订阅
6 篇文章 0 订阅

由于nxp提供的例程基本都得按下按键sw2后,才会有广播。这样对于自己设计的板子上没有按键的就很受伤,所以这里讲如何让板子上电后不用按按键,就直接广播看现象。

首先得知道在哪里修改,查看程序流程

main_task-》 App_Thread-》 App_HandleHostMessageInput-》 BleApp_GenericCallback

前面的都是在Appmian文件里,对于所有的蓝牙工程都是用的它,所以真正程序开始做自己的是在最后这个步骤,在这个环境下有如下情况。

typedef enum gapGenericEventType_tag {
    gInitializationComplete_c,                  /*!< Initial setup started by Ble_HostInitialize is complete. */
    gInternalError_c,                           /*!< An internal error occurred. */
    gAdvertisingSetupFailed_c,                  /*!< Error during advertising setup. */
    gAdvertisingParametersSetupComplete_c,      /*!< Advertising parameters have been successfully set. Response to Gap_SetAdvertisingParameters. */
    gAdvertisingDataSetupComplete_c,            /*!< Advertising and/or scan response data has been successfully set. Response to Gap_SetAdvertisingData. */
    gWhiteListSizeRead_c,                       /*!< Contains the White List size. Response to Gap_ReadWhiteListSize. */
    gDeviceAddedToWhiteList_c,                  /*!< Device has been added to White List. Response to Gap_AddDeviceToWhiteList. */
    gDeviceRemovedFromWhiteList_c,              /*!< Device has been removed from the White List. Response to Gap_RemoveDeviceFromWhiteList. */
    gWhiteListCleared_c,                        /*!< White List has been cleared. Response to Gap_ClearWhiteList. */
    gRandomAddressReady_c,                      /*!< A random device address has been created. Response to Gap_CreateRandomDeviceAddress. */
    gCreateConnectionCanceled_c,                /*!< Connection initiation was successfully cancelled. Response to Gap_CancelInitiatingConnection. */
    gPublicAddressRead_c,                       /*!< Contains the public device address. Response to Gap_ReadPublicDeviceAddress. */
    gAdvTxPowerLevelRead_c,                     /*!< Contains the TX power on the advertising channel. Response to Gap_ReadAdvertisingTxPowerLevel. */
    gPrivateResolvableAddressVerified_c,        /*!< Contains the result of PRA verification. Response to Gap_VerifyPrivateResolvableAddress. */
    gRandomAddressSet_c,                        /*!< Random address has been set into the Controller. Response to Gap_SetRandomAddress. */
    gControllerResetComplete_c,                 /*!< Controller has been successfully reset. */
    gLeScPublicKeyRegenerated_c,                /*!< The private/public key pair used for LE Secure Connections pairing has been regenerated. */
    gLeScLocalOobData_c,                        /*!< Local OOB data used for LE Secure Connections pairing. */
    gHostPrivacyStateChanged_c,                 /*!< Host Privacy was enabled or disabled. */
    gControllerPrivacyStateChanged_c,           /*!< Controller Privacy was enabled or disabled. */
    gControllerTestEvent_c,                     /*!< Controller Test was started or stopped. */
    gTxPowerLevelSetComplete_c,                 /*!< Controller Tx Power Level set complete or invalid. */
    gLePhyEvent_c                               /*!< Phy Mode of a connection has been updated by the Controller. */
} gapGenericEventType_t;

在hrs工程里用的是红色的标记, gInitializationComplete_c 会去配置应用层,gAdvertisingParametersSetupComplete_c 会去处理广播事件,连接事件。这里我们希望当蓝牙数据设置完成后就开始广播(这个就是我们想去执行的),为了处罚广播事件,添加gAdvertisingDataSetupComplete_c 。添加的具体内容参考按键里面的,增加 BleApp_Start();具体修改如下

void BleApp_GenericCallback (gapGenericEvent_t* pGenericEvent)
{
    /* Call BLE Conn Manager */
    BleConnManager_GenericEvent(pGenericEvent);

    switch (pGenericEvent->eventType)
    {
        case gInitializationComplete_c:
        {
            BleApp_Config();
        }
        break;

        case gAdvertisingParametersSetupComplete_c:
        {
            App_StartAdvertising(BleApp_AdvertisingCallback, BleApp_ConnectionCallback);
        }
        break;
    
        case gAdvertisingDataSetupComplete_c:
        {            
            BleApp_Start();
        }
        break; 

        default:
            break;
    }
}

到这里其实只是配置好了广播参数,这里的都是准备工作为了促发广播事件,看BleApp_Start到底做了什么

BleApp_Start()-》BleApp_Advertise-》Gap_SetAdvertisingParameters

再分析App_StartAdvertising,所以最后广播在Gap_StartAdvertising这里启动

App_StartAdvertising-》Gap_StartAdvertising

这样download程序后,直接可以看到广播了,好处是方便调试。

 

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值