TI论坛
直播中

郑涵

7年用户 237经验值
私信 关注
[问答]

16bit UUID改为128bit UUID失败该怎么办?

我主要按照这里所说的改了CC2640的SimpleBLEPeripheral例程:
http://blog.csdn.net/feilusia/article/details/52334125
但是修改后,没有反应,CC2640是有在广播,但是搜不到有服务的UUID,只有MAC之类的信息,请问一下各位大牛,该怎么办???

回帖(7)

庄当甜

2019-10-30 09:25:18
您可以试一下 https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/205258 给出的代码
举报

郑涵

2019-10-30 09:34:53
引用: 小Qhhui 发表于 2019-10-30 16:27
您可以试一下 https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/205258 给出的代码

这个他改的部分,在我贴的那个链接里也有,而且我也是这样做的,就是16bit及其操作换成128bit及其对应操作,但我改了之后就是没有UUID了,无论是128bit的还是之前的16bit都没有
举报

马海娟

2019-10-30 09:44:39
引用: 小Qhhui 发表于 2019-10-30 16:27
您可以试一下 https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/205258 给出的代码

/* * Filename: serial_port_service.c * * Description: This is the simple_peripheral example modified to send * data over BLE at a high throughput. * * * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ * * *  Redistribution and use in source and binary forms, with or without *  modification, are permitted provided that the following conditions *  are met: * *    Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * *    Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the *    distribution. * *    Neither the name of Texas Instruments Incorporated nor the names of *    its contributors may be used to endorse or promote products derived *    from this software without specific prior written permission. * *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *//********************************************************************* * INCLUDES */#include #include "bcomdef.h"#include "OSAL.h"#include "linkdb.h"#include "att.h"#include "gatt.h"#include "gatt_uuid.h"#include "gattservapp.h"#include "gapbondmgr.h"#ifdef SDI_USE_UART#include "inc/sdi_task.h"#endif#include "serial_port_service.h"   #ifdef SDI_USE_UART#include "inc/sdi_tl_uart.h"#endif#include "ti/drivers/uart/UARTCC26XX.h"#include "board.h"#include "spp_ble_server.h"/********************************************************************* * MACROS */#define AUTO_NOTIFICATION FALSE/********************************************************************* * CONSTANTS */#define SERVAPP_NUM_ATTR_SUPPORTED        11gattAttribute_t SerialPortServiceAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED];   /********************************************************************* * TYPEDEFS */typedef enum UART_STATUS_CHAR [     FRAMING_ERR_BYTE,  PARITY_ERR_BYTE,  RF_OVERRUN_BYTE] UART_STATUS_BYTE_DEF;/*! *  @brief    UART config service settings * *  This enumeration defines the UART config bits in Byte 2 of config. char. */typedef enum UART_CONFIG_CHAR [    UART_CONFIG_START = 0,        /*!> 8;  ]  else  [      ret = bleInvalidRange;  ]        return ( ret );]/********************************************************************* * @fn      SerialPortService_AddStatusErrorCount * * @brief   Set a Serial Port Profile parameter. * * @param   errorCode - UART_Status error code  * * @return  bStatus_t */bStatus_t SerialPortService_AddStatusErrorCount( UART_Status errorCode )[  bStatus_t ret = SUCCESS;    switch(errorCode)  [  case UART_PARITY_ERROR:    numParityError++;    SerialPortServiceStatus[PARITY_ERR_BYTE] = numParityError;    break;  case UART_OVERRUN_ERROR:    numRFLinkOverRun++;    SerialPortServiceStatus[RF_OVERRUN_BYTE] = numRFLinkOverRun;    break;  case UART_FRAMING_ERROR:    numFramingError++;    SerialPortServiceStatus[FRAMING_ERR_BYTE] = numFramingError;    break;  ]    return ( ret );]/********************************************************************* * @fn      SerialPortService_SetStatusRXBytes * * @brief   Set a Serial Port Profile parameter. * * @param   param - Profile parameter ID * @param   len - length of data to write * @param   value - pointer to data to write.  This is dependent on *          the parameter ID and WILL be cast to the appropriate  *          data type (example: data type of uint16 will be cast to  *          uint16 pointer). * * @return  bStatus_t */bStatus_t SerialPortService_AddStatusRXBytes( uint16 count )[  bStatus_t ret = SUCCESS;    if( count )  [    numRxBytes += count;    SerialPortServiceStatus[4] = numRxBytes & 0x000000ff;    SerialPortServiceStatus[3] = (numRxBytes & 0x0000ff00) >> 8;  ]  else  [      ret = bleInvalidRange;  ]        return ( ret );]/********************************************************************* * @fn      SerialPortService_SetUartConfig * * @brief   Set a Serial Port Profile parameter. * * @param   param - Profile parameter ID * @param   len - length of data to write * @param   value - pointer to data to write.  This is dependent on *          the parameter ID and WILL be cast to the appropriate  *          data type (example: data type of uint16 will be cast to  *          uint16 pointer). * * @return  bStatus_t */bStatus_t SerialPortService_SetUartConfig( UART_Params *params )[  bStatus_t ret = SUCCESS;      SerialPortParams.readMode       = params->readMode;    SerialPortParams.writeMode      = params->writeMode;    SerialPortParams.readTimeout    = params->readTimeout;    SerialPortParams.writeTimeout   = params->writeTimeout;    SerialPortParams.readCallback   = params->readCallback;    SerialPortParams.writeCallback  = params->writeCallback;    SerialPortParams.readReturnMode = params->readReturnMode;    SerialPortParams.readDataMode   = params->readDataMode;    SerialPortParams.writeDataMode  = params->writeDataMode;    SerialPortParams.baudRate       = params->baudRate;    SerialPortParams.dataLength     = params->dataLength;    SerialPortParams.stopBits       = params->stopBits;    SerialPortParams.parityType     = params->parityType;    SerialPortParams.readEcho       = params->readEcho;    SerialPortParams.custom         = params->custom;      DEBUG("*****UART SETTINGS*****"); DEBUG_NEWLINE();           uint16_t count = SerialPortParams.baudRate/10;    SerialPortServiceConfig[1] = count & 0x00ff;    SerialPortServiceConfig[0] = (count & 0xff00) >> 8;        //DEBUG("UART Baud Rate: ");    //DEBUG((uint8_t*)convInt32ToText(SerialPortParams.baudRate)); DEBUG_NEWLINE();        SerialPortServiceConfig[2] &= 0xfe; //Start bit Low    SerialPortServiceConfig[2] |= 0x02; //Stop bit High        DEBUG("Stop bits: ");    if(SerialPortParams.stopBits == UART_STOP_TWO)    [      SerialPortServiceConfig[2] |= 0x04;   //SPB = 1, 2 stop bit      DEBUG("2 stop bit");    ]    else    [      SerialPortServiceConfig[2] &= 0xfb;   //SPB = 0, 1 stop bit      DEBUG("1 stop bit");    ]        DEBUG_NEWLINE();    DEBUG("Parity: ");        switch(SerialPortParams.parityType)    [    case UART_PAR_NONE:      SerialPortServiceConfig[2] &= 0xf7;   //Parity disabled      DEBUG("UART_PAR_NONE");      break;    case UART_PAR_EVEN:      SerialPortServiceConfig[2] |= 0x08;   //Parity enabled      SerialPortServiceConfig[2] |= 0x10;   //Even parity      DEBUG("UART_PAR_EVEN");      break;    case UART_PAR_ODD:      SerialPortServiceConfig[2] |= 0x08;   //Parity enabled      SerialPortServiceConfig[2] &= 0xef;   //Even parity      DEBUG("UART_PAR_ODD");      break;    case UART_PAR_ZERO:      break;    case UART_PAR_ONE:      break;    ]        DEBUG_NEWLINE();        //Hardware Flow control is not ready yet.    SerialPortServiceConfig[2] &= 0xdf;          return ( ret );]/********************************************************************* * @fn      SerialPortService_GetUartConfig * * @brief   Get a Serial Port Profile parameter. * * @param   param - Profile parameter ID * @param   len - length of data to write * @param   value - pointer to data to write.  This is dependent on *          the parameter ID and WILL be cast to the appropriate  *          data type (example: data type of uint16 will be cast to  *          uint16 pointer). * * @return  bStatus_t */bStatus_t SerialPortService_GetUartConfig( UART_Params *params )[  bStatus_t ret = SUCCESS;    params->readMode         =   SerialPortParams.readMode;        params->writeMode        =   SerialPortParams.writeMode;       params->readTimeout      =   SerialPortParams.readTimeout;     params->writeTimeout     =   SerialPortParams.writeTimeout;    params->readCallback     =   SerialPortParams.readCallback;    params->writeCallback    =   SerialPortParams.writeCallback;   params->readReturnMode   =   SerialPortParams.readReturnMode;  params->readDataMode     =   SerialPortParams.readDataMode;    params->writeDataMode    =   SerialPortParams.writeDataMode;   params->baudRate         =   SerialPortParams.baudRate;        params->dataLength       =   SerialPortParams.dataLength;      params->stopBits         =   SerialPortParams.stopBits;        params->parityType       =   SerialPortParams.parityType;      params->readEcho         =   SerialPortParams.readEcho;        params->custom           =   SerialPortParams.custom;              return ( ret );]/********************************************************************* * @fn      SerialPortService_GetParameter * * @brief   Get a Serial Port Profile parameter. * * @param   param - Profile parameter ID * @param   value - pointer to data to put.  This is dependent on *          the parameter ID and WILL be cast to the appropriate  *          data type (example: data type of uint16 will be cast to  *          uint16 pointer). * * @return  bStatus_t */bStatus_t SerialPortService_GetParameter( uint8 param, void *value )[  bStatus_t ret = SUCCESS;  switch ( param )  [    case SERIALPORTSERVICE_CHAR_DATA:      VOID memcpy( value, SerialPortServiceData, SERIALPORTSERVICE_DATA_LEN );      break;     case SERIALPORTSERVICE_CHAR_STATUS:      VOID memcpy( value, SerialPortServiceStatus, SERIALPORTSERVICE_STATUS_LEN );      break;           case SERIALPORTSERVICE_CHAR_CONFIG:      VOID memcpy( value, SerialPortServiceConfig, SERIALPORTSERVICE_CONFIG_LEN );      break;            default:      ret = INVALIDPARAMETER;      break;  ]    return ( ret );]/********************************************************************* * @fn          SerialPortService_ReadAttrCB * * @brief       Read an attribute. * * @param       connHandle - connection message was received on * @param       pAttr - pointer to attribute * @param       pValue - pointer to data to be read * @param       pLen - length of data to be read * @param       offset - offset of the first octet to be read * @param       maxLen - maximum length of data to be read * @param       method - type of read message * * @return      SUCCESS, blePending or Failure */static bStatus_t SerialPortService_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,                                            uint8 *pValue, uint16 *pLen, uint16 offset,                                           uint16 maxLen, uint8 method )[  bStatus_t status = SUCCESS;  // If attribute permissions require authorization to read, return error  if ( gattPermitAuthorRead( pAttr->permissions ) )  [    // Insufficient authorization    return ( ATT_ERR_INSUFFICIENT_AUTHOR );  ]    // Make sure it's not a blob operation (no attributes in the profile are long)  if ( offset > 0 )  [    return ( ATT_ERR_ATTR_NOT_LONG );  ]   if ( pAttr->type.len == ATT_UUID_SIZE )  [    // Get 16-bit UUID from 128-bit UUID    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[12], pAttr->type.uuid[13]);        switch ( uuid )    [      // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;      // gattserverapp handles those reads      // characteristics SERIALPORTSERVICE_STATUS_UUID and SERIALPORTSERVICE_CONFIG_UUID have read permissions      // characteristic SERIALPORTSERVICE_DATA_UUID does not have read permissions, but because it      //   can be sent as a notification, it is included here      case SERIALPORTSERVICE_DATA_UUID:        *pLen = charDataValueLen;        VOID memcpy( pValue, pAttr->pValue, charDataValueLen );        break;              case SERIALPORTSERVICE_STATUS_UUID:        *pLen = SERIALPORTSERVICE_STATUS_LEN;        VOID memcpy( pValue, pAttr->pValue, SERIALPORTSERVICE_STATUS_LEN );                //Reset all counters        numTxBytes = 0;        SerialPortServiceStatus[6] = 0x00;        SerialPortServiceStatus[5] = 0x00;        numRxBytes = 0;        SerialPortServiceStatus[4] = 0x00;        SerialPortServiceStatus[3] = 0x00;        numRFLinkOverRun = 0;        numFramingError = 0;        numParityError = 0;        break;              case SERIALPORTSERVICE_CONFIG_UUID:        *pLen = SERIALPORTSERVICE_CONFIG_LEN;        VOID memcpy( pValue, pAttr->pValue, SERIALPORTSERVICE_CONFIG_LEN );        break;         default:        // Should never get here! (characteristics 3 and 4 do not have read permissions)        *pLen = 0;        status = ATT_ERR_ATTR_NOT_FOUND;        break;    ]  ]  else if( pAttr->type.len == ATT_BT_UUID_SIZE)  [    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);    switch ( uuid )    [              default:        // Should never get here!        *pLen = 0;        status = ATT_ERR_ATTR_NOT_FOUND;        break;    ]  ]  else  [    //neither 16-bit UUID nor 128bit UUID    *pLen = 0;    status = ATT_ERR_INVALID_HANDLE;  ]  return ( status );]/********************************************************************* * @fn      SerialPortService_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 */static bStatus_t SerialPortService_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,                                            uint8 *pValue, uint16 len, uint16 offset,                                            uint8 method )[  bStatus_t status = SUCCESS;  uint8 notifyApp = 0xFF;    // If attribute permissions require authorization to write, return error  if ( gattPermitAuthorWrite( pAttr->permissions ) )  [    // Insufficient authorization    return ( ATT_ERR_INSUFFICIENT_AUTHOR );  ]    if ( pAttr->type.len == ATT_UUID_SIZE )  [    // 16-bit UUID    uint16 uuid = BUILD_UINT16( pAttr->type.uuid[12], pAttr->type.uuid[13]);    switch ( uuid )    [      case SERIALPORTSERVICE_DATA_UUID:        if ( offset == 0 )        [          if ( len > SERIALPORTSERVICE_DATA_LEN )          [            status = ATT_ERR_INVALID_VALUE_SIZE;          ]        ]        else        [          status = ATT_ERR_ATTR_NOT_LONG;        ]                //Write the value        if ( status == SUCCESS )        [          uint8 *pCurValue = (uint8 *)pAttr->pValue;                    //Copy/Store data to the GATT table entry          memset(pCurValue, 0, SERIALPORTSERVICE_DATA_LEN);          memcpy(pCurValue, pValue, len);          #ifdef SDI_USE_UART                    //Send Data to UART           SDITask_sendToUART(pCurValue, len);#else                   SNP_replyToHost_send(0x55, 0xFF, NULL, len, pCurValue);#endif          //Toggle LED to indicate data received from client          SPPBLEServer_toggleLed(Board_RLED, Board_LED_TOGGLE);                    if (len > 0)          [           SerialPortService_AddStatusRXBytes( len );          ]                notifyApp = SERIALPORTSERVICE_CHAR_DATA;        ]                     break;              case SERIALPORTSERVICE_CONFIG_UUID:        //Validate the value        if ( offset == 0 )        [         if ( len != SERIALPORTSERVICE_CONFIG_LEN )         [            status = ATT_ERR_INVALID_VALUE_SIZE;         ]        ]        else        [         status = ATT_ERR_ATTR_NOT_LONG;        ]                //Write the value        if ( status == SUCCESS )        [          uint8 *pCurValue = (uint8 *)pAttr->pValue;                    memset(pCurValue, 0, SERIALPORTSERVICE_CONFIG_LEN);          memcpy(pCurValue, pValue, len);                      //Configured in higher application layer                  notifyApp = SERIALPORTSERVICE_CHAR_CONFIG;        ]                     break;      default:        // Should never get here! (characteristics 2 and 4 do not have write permissions)        status = ATT_ERR_ATTR_NOT_FOUND;        break;    ]  ]  else 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 GATT_CLIENT_CHAR_CFG_UUID:       status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,                                                 offset, GATT_CLIENT_CFG_NOTIFY );       break;    default:        status = ATT_ERR_ATTR_NOT_FOUND;        break;    ]  ]  else  [      //neither 16bit UUID nor 128bit UUID      status = ATT_ERR_INVALID_HANDLE;  ]  // If a charactersitic value changed then callback function to notify application of change  if ( (notifyApp != 0xFF ) && SerialPortService_AppCBs && SerialPortService_AppCBs->pfnSerialPortServiceChange )  [    SerialPortService_AppCBs->pfnSerialPortServiceChange( notifyApp );    ]    return ( status );]/******************************************************************************************************************************************/                                                                          致力于帮助更多使用TI平台的开发者!
举报

郑涵

2019-10-30 09:53:16
引用: victorlekwk 发表于 2019-10-30 16:46
/* * Filename: serial_port_service.c * * Description: This is the simple_peripheral example modified to send * data over BLE at a high throughput. * * * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ * * *  Redistribution and use in source and binary forms, with or without *  ...

我参考这贴改了之后,发现原来是我自己改多了几个定义,以及忘了添加一些头文件的问题,谢谢,已经解决了
举报

更多回帖

发帖
×
20
完善资料,
赚取积分