查看: 1729|回复: 0

[分享] KW36入门学习(六、开机后自动广播)

[复制链接]
  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3298

    主题

    6545

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32003
    最后登录
    2024-4-9
    发表于 2020-5-13 16:36:31 | 显示全部楼层 |阅读模式
    KW36入门学习(六、开机后自动广播)


    由于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程序后,直接可以看到广播了,好处是方便调试。



    文章出处:CSDN
    签到签到
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-20 07:27 , Processed in 0.097369 second(s), 18 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表