请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LP-EM-CC2340R5 主题中讨论的其他器件:SysConfig
工具与软件:
您好!
我有两块 Launchpad 板、一块用作中央板、另一块用作外设。 当中央设备发送 GATT_WriteNoRsp (APP_CONNECTION_Handle、&req)时、我发现外设在2到3秒后接收到数据。 这是否正常? 如何加快此过程?
SDK 版本:7.40.0.64
Central Send data (中央发送数据)
/********************************************************************* * @fn SimpleGattProfile_writeAttrCB * * @brief Validate attribute data prior to a write operation * * @param connHandle - connection message was received on * @param pAttr - pointer to attribute * @param pValue - pointer to data to be written * @param len - length of data * @param offset - offset of the first octet to be written * @param method - type of write message * * @return SUCCESS, blePending or Failure */ bStatus_t SimpleGattProfile_writeAttrCB( uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method ) { bStatus_t status = SUCCESS; uint8 notifyApp = 0xFF; if ( pAttr->type.len == ATT_BT_UUID_SIZE ) { // 16-bit UUID uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); switch ( uuid ) { case SIMPLEGATTPROFILE_CHAR1_UUID: case SIMPLEGATTPROFILE_CHAR3_UUID: { //Validate the value // Make sure it's not a blob oper if ( offset == 0 ) { // if ( len != 1 ) // { // status = ATT_ERR_INVALID_VALUE_SIZE; // } if( ( (uuid == SIMPLEGATTPROFILE_CHAR1_UUID) && ( len != 1 ) ) || ( (uuid == SIMPLEGATTPROFILE_CHAR3_UUID) && ( len == 0) ) ) { status = ATT_ERR_INVALID_VALUE_SIZE; } } else { status = ATT_ERR_ATTR_NOT_LONG; } if ( status == SUCCESS ) { uint8 *pCurValue = (uint8 *)pAttr->pValue; *pCurValue = pValue[0]; if( pAttr->pValue == &simpleGattProfile_Char1 ) { notifyApp = SIMPLEGATTPROFILE_CHAR1; } else { //user add get data. memcpy(simpleGattProfile_Char3,pValue,len); user_peripheral_receive.P_Rx_data_len = len; user_peripheral_receive.P_Rx_data_ptr = simpleGattProfile_Char3; notifyApp = SIMPLEGATTPROFILE_CHAR3; } } } break; case GATT_CLIENT_CHAR_CFG_UUID: status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY ); user_peripheral_receive.P_notify_flag = *pValue; //notify the App that a change has occurred in Char 4 notifyApp = SIMPLEGATTPROFILE_CHAR4; break; default: // Should never get here! (characteristics 2 and 4 do not have write permissions) status = ATT_ERR_ATTR_NOT_FOUND; break; } } else { // 128-bit UUID status = ATT_ERR_INVALID_HANDLE; } // If a characteristic value changed then callback function to notify application of change if ((notifyApp != 0xFF ) && simpleGattProfile_appCBs && simpleGattProfile_appCBs->pfnSimpleGattProfile_Change) { SimpleGattProfile_callback( notifyApp ); } // Return status value return ( status ); }
外设接收数据
/********************************************************************* * @fn SimpleGatt_ChangeCB * * @brief Callback from Simple Profile indicating a characteristic * value change. * * @param paramId - parameter Id of the value that was changed. * * @return None. */ static void SimpleGatt_changeCB( uint8_t paramId ) { uint8_t newValue = 0; switch( paramId ) { case SIMPLEGATTPROFILE_CHAR1: { SimpleGattProfile_getParameter( SIMPLEGATTPROFILE_CHAR1, &newValue ); // evaluateNewCharacteristicValue(newValue); //add // Print the new value of char 1 MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE, 0, "Profile status: Simple profile - " "Char 1 value = " MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET, newValue); } break; case SIMPLEGATTPROFILE_CHAR3: { //SimpleGattProfile_getParameter(SIMPLEGATTPROFILE_CHAR3, &newValue); //user_peripheral_receive.P_Rx_data_len = len; //user_peripheral_receive.P_Rx_data_ptr = simpleGattProfile_Char3; UART2_write(uart, (char*)user_peripheral_receive.P_Rx_data_ptr, user_peripheral_receive.P_Rx_data_len, NULL); //UART2_write(uart, (char*)"\r\n", strlen((char*)"\r\n"), NULL); // Print the new value of char 3 MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE, 0, "Profile status: Simple profile - " "Char 3 value = " MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET, newValue); //SimpleGatt_notifyChar4(); } break; case SIMPLEGATTPROFILE_CHAR4: { // Print Notification registration to user if(user_peripheral_receive.P_notify_flag == 1 ) UART2_write(uart, (char*)"\r\nnotify = On\r\nOK\r\n", strlen((char*)"\r\nnotify = On\r\nOK\r\n"), NULL); else UART2_write(uart, (char*)"\r\nnotify = Off\r\nOK\r\n", strlen((char*)"\r\nnotify = Off\r\nOK\r\n"), NULL); MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE, 0, "Profile status: Simple profile - " "Char 4 = Notification registration"); //SimpleGatt_notifyChar4(); break; } default: // should not reach here! break; } }
外设接收数据(充电盒 SIMPLEGATTPROFILE_CHAR3)