This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2 Central 变成主从一体机

Other Parts Discussed in Thread: CC2640R2F

我的sdk是simplelink_cc2640r2_sdk_1_40_00_45。请问,在CC2640R2F 的example 下central 如何变成主从一体机,实现发出adv 广播,

同时又能主动连接?

  • 建议你升级SDK,有主从一体的例程:C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\examples\rtos\CC2640R2_LAUNCHXL\blestack\multi_role
  • 目前simplelink_cc2640r2_sdk_1_40_00_45 也有主从一体机的例程,但是发现它的paring 事件不能触发,之前的central角色例程是可以触发pairing 事件的。所以想在central角色的例程上增加从机广播模块,只要能发出adv就行,不知要增加哪些内容?
  • 自己加比较复杂,也没有教程,建议你还是在multi_role中修改,paring 事件不能触发具体指的是什么
  • 我在multi-role中加了pairing&&bond 的代码部分;

    //dev_init
    {
    // The default passkey if no passcode callback function is registered with
    // GAPBondMgr (in GAPBondMgr_Register()). The default in this application
    // is to post an SBC_PASSCODE_NEEDED_EVT to the application where it will
    // generate a random passcode.
    uint32_t passkey = DEFAULT_PASSCODE;
    // send a pairing request after connecting; the device waits for the
    // application to start pairing
    uint8_t pairMode = DEFAULT_PAIRING_MODE;
    // use authenticated pairing
    uint8_t mitm = DEFAULT_MITM_MODE;
    // This is a display only device
    uint8_t ioCap = DEFAULT_IO_CAPABILITIES;
    // Create a bond during the pairing process
    uint8_t bonding = DEFAULT_BONDING_MODE;
    GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);

    GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
    GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
    GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
    }
    注册回调也有加上
    static gapBondCBs_t SimpleBLECentral_bondCB =
    {
    (pfnPasscodeCB_t)SimpleBLECentral_passcodeCB, // Passcode callback
    SimpleBLECentral_pairStateCB // Pairing / Bonding state Callback
    };
    现测试连接某个peripheral,发现在multi-role端并没有pairing 事件触发,在 events = Event_pend(syncEvent, Event_Id_NONE, MR_ALL_EVENTS, ICALL_TIMEOUT_FOREVER);没有收到触发事件,而peripheral 是有pairing流程的,只要被连接后,若central端没有绑定,就会发起配对请求;我通过wireshark ,看到peripheral端已经发出配对请求,而multi-role 没有响应。

  • 看下

      uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
    我测试可以自动发起绑定




     /*-----------------CLIENT------------------*/
        // Initialize GATT Client
        VOID GATT_InitClient();
    
        // Register for GATT local events and ATT Responses pending for transmission
        GATT_RegisterForMsgs(selfEntity);
    
        // Register to receive incoming ATT Indications/Notifications
        GATT_RegisterForInd(selfEntity);
      }
    
      // Setup the GAP Bond Manager
      {
        uint8_t pairMode = GAPBOND_PAIRING_MODE_INITIATE;
        uint8_t mitm = TRUE;
        uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
        uint8_t bonding = TRUE;
        uint8_t replaceBonds = FALSE;
    
        // Set pairing mode
        GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
    
        // Set authentication requirements
        GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
    
        // Set I/O capabilities
        GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
    
        // Set bonding requirements
        GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
    

  • 我的配对是被动发起模式,确实没有收到触发pairing事件:
    #define DEFAULT_PAIRING_MODE GAPBOND_PAIRING_MODE_WAIT_FOR_REQ
    #define DEFAULT_MITM_MODE TRUE
    #define DEFAULT_BONDING_MODE TRUE
    #define DEFAULT_IO_CAPABILITIES GAPBOND_IO_CAP_DISPLAY_ONLY//GAPBOND_IO_CAP_KEYBOARD_ONLY
    /*-----------------CLIENT------------------*/
    // Initialize GATT Client
    VOID GATT_InitClient();

    // Register for GATT local events and ATT Responses pending for transmission
    GATT_RegisterForMsgs(selfEntity);

    // Register to receive incoming ATT Indications/Notifications
    GATT_RegisterForInd(selfEntity);
    }
    // Setup the GAP Bond Manager. For more information see the section in the
    // User's Guide:
    // software-dl.ti.com/.../gapbondmngr.html
    {
    // The default passkey if no passcode callback function is registered with
    // GAPBondMgr (in GAPBondMgr_Register()). The default in this application
    // is to post an SBC_PASSCODE_NEEDED_EVT to the application where it will
    // generate a random passcode.
    uint32_t passkey = DEFAULT_PASSCODE;
    // send a pairing request after connecting; the device waits for the
    // application to start pairing
    uint8_t pairMode = DEFAULT_PAIRING_MODE;
    // use authenticated pairing
    uint8_t mitm = DEFAULT_MITM_MODE;
    // This is a display only device
    uint8_t ioCap = DEFAULT_IO_CAPABILITIES;
    // Create a bond during the pairing process
    uint8_t bonding = DEFAULT_BONDING_MODE;
    GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);

    GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode);
    GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm);
    GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
    GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
    }
    注册回调也是有的。
    // Bond Manager Callbacks
    static gapBondCBs_t SimpleBLECentral_bondCB =
    {
    (pfnPasscodeCB_t)SimpleBLECentral_passcodeCB, // Passcode callback
    SimpleBLECentral_pairStateCB // Pairing / Bonding state Callback
    };
    GAPBondMgr_Register(&SimpleBLECentral_bondCB);
  • simplelink_cc2640r2_sdk_1_40_00_45版本的SDK已经无法下载了,没办法帮你测试
    你改下uint8_t pairMode = DEFAULT_PAIRING_MODE;配对模式看看是否有变化,或者升级SDK试试
    /**
    * @defgroup GAPBondMgr_Pairing_Modes GAP Bond Manager Pairing Modes
    * @{
    */
    #define GAPBOND_PAIRING_MODE_NO_PAIRING 0x00 //!< Pairing is not allowed
    #define GAPBOND_PAIRING_MODE_WAIT_FOR_REQ 0x01 //!< Wait for a pairing request or slave security request
    #define GAPBOND_PAIRING_MODE_INITIATE 0x02 //!< Don't wait, initiate a pairing request or slave security request
    /** @} End GAPBondMgr_Pairing_Modes */
  • 谢谢!

    我的主从一体机中设置pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ,连接peripheral 后,原peripheral 的pairMode 是GAPBOND_PAIRING_MODE_INITIATE,正常情况下,peripheral 是会主动发起配对的,而我的主从一体机这端没有收到配对请求事件;

    而我的主从一体机中设置pairMode = GAPBOND_PAIRING_MODE_INITIATE ,用手机ble app去连接主从一体机,主从一体机是会主动发起配对的,在手机上可以显示配对窗口。

    现在就不清楚,为何主从一体机的central角色不能收到配对请求?

  • 我按照你的设置测试可以绑定成功

  • 谢谢!
    可能是我的sdk 1.40.00.45太老了,请问下,这与sdk版本有关系吗?你用的例程是example 下的CC2640R2_LAUNCHXL下的multi-role吗?
  • sdk 1.40.00.45到simplelink_cc2640r2_sdk_4_30_00_08中间有很多版本,你还是升级下,我用的例程是example 下的CC2640R2_LAUNCHXL下的multi-role