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.

[参考译文] CCS/LAUNCHXL-CC2650:自定义特性、如何写入字符串

Guru**** 2553450 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/581374/ccs-launchxl-cc2650-custom-characteristic-how-to-write-the-string

器件型号:LAUNCHXL-CC2650

工具/软件:Code Composer Studio

您好!

我实际上在 simlpe_peripheral 上构建了一个新的特征6。 该字符是由5个字符组成的字符串。 我实际上能够通过应用程序 BLE Scanner 在手机上看到它、并且能够将其读取到。 但我无法使写入工作。

我在 simpleProfile_WriteAttrCB 函数上添加了此代码、但它不起作用、似乎从未达到条件"Case SIMPLEPROFILE_CHAR6_UUID"、但 UUID 很好、可通过电话查看。  

静态 bStatus_t simpleProfile_WriteAttrCB (uint16_t connHandle、
gattAttribute_t *pAttr,
uint8_t *pValue、uint16_t len、
uint16_t offset、uint8_t 方法)
{
bStatus_t status = Success;
uint8 notifyApp = 0xFF;

if (pAttr->type.len == ATT_BT_UUID_SIZE)
{
// 16位 UUID
uint16 uuid = build_uint16 (pAttr->type.uuuuid[0]、pAttr->type.uuuid[1]);
交换机(uuid)
{
Case SIMPLEPROFILE_CHAR1_UUID:
Case SIMPLEPROFILE_CHAR3_UUID:


//验证值
//确保它不是一个 blob 操作器
如果(offset ==0)
{
如果(len!= 1)
{
状态= ATT_ERR_INVALID_VALUE SIZE;
}
}
其他
{
状态= ATT_ERR_ATTR_NOT _long;
}

//写入值
如果(status == Success)
{
uint8 *pCurValue =(uint8 *)pAttr->pValue;
*pCurValue = pValue[0];

if (pAttr->pValue =&simpleProfileChar1)
{
notifyApp = SIMPLEPROFILE_CHAR1;
}
其他
{
notifyApp = SIMPLEPROFILE_CHAR3;
}
}

中断;

Case SIMPLEPROFILE_CHAR6_UUID:


//验证值
//确保在
以下情况下不是 blob 操作符(offset =0)
{
如果(!= SIMPLEPROFILE_CHAR6_LEN)
{
状态= ATT_ERR_INVALID_VALUE 大小;
}


//如果(
status = SIMPLEVEL_PROLEVEL6


),则写入值(status = SIMPLEARENCOL = SIMPLE)
notifyApp = SIMPLEPROFILE_CHAR6;
}
中断;

案例 GATT_CLIENT_CHAR_CFG_UUID:
状态= GATTServApp_ProcessCCCWriteReq (connHandle、pAttr、pValue、len、
offset、GATT_CLIENT_CFG_NOTIY);
中断;

默认值:
//不应该来这里! (特征2和4没有写入权限)
状态= ATT_ERR_ATTR_NOT _找到;
中断;
}
}
否则
{
// 128位 UUID
状态= ATT_ERR_INVALID_Handle;
}

//如果特性值发生更改,则使用回调函数通知应用程序更改
(如果(notifyApp!= 0xFF)&& simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange)
{)
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
}

返回(状态);
} 

当我写入特征1时、我到达相应的情况、但不使用特征6。

有人能帮我解决这个问题吗? 复制接收到的字符串的方法是否正确?

此致、

John

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好、John、
    您如何在属性表中定义此项?

    您应该尝试以下操作:
    -设置数据包监听器以验证从机是否接受 GATT 写入请求命令。
    -尝试从应用发出写入请求并在 simpleProfile_WriteAttrCB 中设置断点时以调试模式运行、并观察 uuid 中的值。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Erik 您好!

    您说得对、我的问题来自属性表中的声明。 我只将 GATT_permit_read 放在特征值上、因此... 正如预期的那样、我无法写入它。 现在我有:  

    //特征值6
    {
    {ATT_BT_UUID_SIZE、simpleProfilechar6UUID}、
    GATT_permit_read | GATT_permit_write、
    0、
    simpleProfileChar6
    }、 

    它运行得很好、谢谢!

    此致、

    John