微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > GATT_WriteCharValue怎么写多个字节的数据

GATT_WriteCharValue怎么写多个字节的数据

时间:10-02 整理:3721RD 点击:

主机通过GATT_WriteCharValue写,只能写一个字节。在从机程序里面怎么设置特征值可以写多个字节?

#define ATT_ERR_INVALID_VALUE_SIZE       0x0d //!< The attribute value length is invalid for the operation

另外可以参考之前的帖子 http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/44889.aspx?pi2132219853=1

uint8 buffer[VSERIAL_BLOCK_SIZE];
attWriteReq_t req = {NULL};
req.handle = charHandle;
req.len = VSERIAL_BLOCK_SIZE;
req.cmd = 1;
if(enableAES == TRUE)
{
AES_Init(curDevice->aesKey);
AES_Encrypt(buffer, pValue);
osal_memcpy(&req.value, buffer, AES_BLOCK_SIZE);
}
else
{
osal_memcpy(&req.value, pValue, AES_BLOCK_SIZE);
}

return ( GATT_WriteNoRsp( conHandle, &req ) );

其中charHandle是特征值的handle,conHandle是连接的handle,aes加密是可选,我自己实现的。

看下一楼

这个问题解决了,原来是要修改simpleGATTprofile.c中的simpleProfile_WriteAttrCB函数,这里面规定了特征值字节数为1

if ( len != 1 )
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}

但是又出现了新的问题,写5个字节内的数据都没问题,但写6个字节以上的数据就直接Discconected,原因是0x08

#define LL_STATUS_ERROR_CONNECTION_TIMEOUT             0x08 // Connection Timeou

这是为什么?什么地方规定了只能5字节,不是最大为20字节吗?

#define ATT_MTU_SIZE                     L2CAP_MTU_SIZE

#define L2CAP_MTU_SIZE                   23

typedef struct
{
uint16 handle; //!< Handle of the attribute to be written (must be first field)
uint8 len; //!< Length of value
uint8 value[ATT_MTU_SIZE-3]; //!< Value of the attribute to be written
uint8 sig; //!< Authentication Signature status (not included (0), valid (1), invalid (2))
uint8 cmd; //!< Command Flag
} attWriteReq_t;

typedef struct
{
uint8 len; //!< Length of value
uint8 value[ATT_MTU_SIZE-1]; //!< Value of the attribute with the handle given
} attReadRsp_t;

typedef struct
{
uint16 handle; //!< Handle of the attribute to be written (must be first field)
uint16 offset; //!< Offset of the first octet to be written
uint8 len; //!< Length of value
uint8 value[ATT_MTU_SIZE-5]; //!< Part of the value of the attribute to be written
} attPrepareWriteReq_t;

第二个问题,这三个飘红的地方为什么规定的长度不一样?

恳请TI的工程师和高手来帮帮我!谢谢

写多个字节要修改simpleProfileChangeCB函数。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top