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.

CC2540 notify使能问题

Other Parts Discussed in Thread: CC2540, CC2541

请问,CC2540在发现特性值4的句柄之后多久可以使能Notify?为什么发现之后就使能不可以呢?过一段时间之后再使能才可以,请问这段时间可以设置吗?怎么设置?这段时间是多长?

  • zhikuan,

    可以发现后立即使能。

  • 那我发现后立即使能的返回值是这个blePending,我用了一个while直到返回值是SUCCESS,代码如下

    while(a)
    {
    if ( uptechBleState[uptechDeviceNum] == BLE_STATE_CONNECTED &&
    uptechBLEChartHdl[uptechDeviceNum][CHC4_HANDLE] != 0 &&
    uptechBLEProcedureInProgress[uptechDeviceNum] == FALSE )
    {
    attWriteReq_t wrreq;
    wrreq.handle = uptechBLEChartHdl[uptechDeviceNum][CHC4_HANDLE]+1;
    wrreq.len = 2;
    wrreq.value[0] = 0x01;
    wrreq.value[1] = 0x00;
    wrreq.sig = 0;
    wrreq.cmd = 0;
    a = GATT_WriteCharValue( uptechBLEConnHandle[uptechDeviceNum], &wrreq, simpleBLETaskId );
    }
    }

    之后发过来的通知消息还是收不到,我在定时器里定时3S执行这些指令就可以收到通知,不知道是怎么回事,求解答

  • zhikuan,

    你这样会重复去写那个使能notification,而且会阻塞其他进程,自然会有问题。

    你写一遍就够了,然后在回调中会收到write response,并且状态是success之后就立即可以收到notification了,你可以在central代码中搜索 “pMsg->method == ATT_WRITE_RSP” 就能找到例子。

    这个过程应该是瞬间的,不会3秒这样。

  • 按照您说的,我修改了代码如下:

    if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
    pMsg->hdr.status == bleProcedureComplete ) ||
    ( pMsg->method == ATT_ERROR_RSP ) )
    {
    if ( uptechBLESvcStartHdl[uptechDeviceNum] != 0 )
    {
    // Discover characteristic
    uptechBLEDiscState[uptechDeviceNum] = BLE_DISC_STATE_CHAR;

    req.startHandle = uptechBLESvcStartHdl[uptechDeviceNum] ;
    req.endHandle = uptechBLESvcEndHdl[uptechDeviceNum];
    req.type.len = ATT_BT_UUID_SIZE;
    req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR4_UUID);
    req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR4_UUID);
    GATT_ReadUsingCharUUID( uptechBLEConnHandle[uptechDeviceNum], &req, simpleBLETaskId );
    }
    }
    }
    else if ( uptechBLEDiscState[uptechDeviceNum] == BLE_DISC_STATE_CHAR )
    {
    if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
    pMsg->msg.readByTypeRsp.numPairs > 0 )
    {
    uptechBLEChartHdl[uptechDeviceNum][CHC4_HANDLE] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
    pMsg->msg.readByTypeRsp.dataList[1] );
    uptechBLEProcedureInProgress[uptechDeviceNum] = TRUE;
    }else{
    uptechBLEDiscState[uptechDeviceNum] = BLE_DISC_STATE_CHAR1;
    req.startHandle = uptechBLESvcStartHdl[uptechDeviceNum] ;
    req.endHandle = uptechBLESvcEndHdl[uptechDeviceNum];
    req.type.len = ATT_BT_UUID_SIZE;
    req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
    req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);
    GATT_ReadUsingCharUUID( uptechBLEConnHandle[uptechDeviceNum], &req, simpleBLETaskId );

    }
    }else if(uptechBLEDiscState[uptechDeviceNum] == BLE_DISC_STATE_CHAR1){
    if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
    pMsg->msg.readByTypeRsp.numPairs > 0 )
    {
    uptechBLEChartHdl[uptechDeviceNum][CHC1_HANDLE] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
    pMsg->msg.readByTypeRsp.dataList[1] );
    uptechBLEProcedureInProgress[uptechDeviceNum] = FALSE;
    #if DEBUG_PROC
    HalUARTWrite(HAL_UART_PORT_0,"Second\n", 7);
    #endif
    attWriteReq_t wrreq;
    wrreq.handle = uptechBLEChartHdl[uptechDeviceNum][CHC4_HANDLE]+1;
    wrreq.len = 2;
    wrreq.value[0] = 0x01;
    wrreq.value[1] = 0x00;
    wrreq.sig = 0;
    wrreq.cmd = 0;
    GATT_WriteCharValue( uptechBLEConnHandle[uptechDeviceNum], &wrreq, simpleBLETaskId );
    }
    uptechBLEDiscState[uptechDeviceNum] = BLE_DISC_STATE_IDLE;

    我查找到特性4的句柄,发送了一次使能Nontify,但是返回值不是SUCCESS,您有这方面的例子吗?最早使能Notify

  • 我也遇到了同样的问题,不能使能从机端的notify。可以来讨论一下,power3347@163.com

  • 你好,我刚学蓝牙,想问一个问题,要怎么样操作才能获得cc2541的特性值4的句柄?