【发布时间】:2016-01-25 09:37:47
【问题描述】:
我正在尝试使用mbed API 将一些特征用户描述添加到我的自定义 BLE GATT 服务中。到目前为止,我的工作都是基于this 代码结构。但是,我想为这些特征添加名称。我找不到太多关于如何执行此操作的信息。但是,下面是将信息添加到特征的代码。
GattCharacteristic() 的构造函数将 GattAttribtues 数组作为可选参数。您可以将 User-Description 填充到 GattAttribute 中并将其传递给 Characteristic。我有这个结构为一个特性工作,但我正在努力为 3 个字符复制它。我无法将整个内容复制 3 次,因为我将它运行到很多关于数组等已定义的问题。如果我将描述堆叠在数组中,GattArray 不会接受它吗?
uint16_t newServiceUUID = 0xA000;
uint16_t PercentageUUID = 0xA001;
uint16_t TimeUUID = 0xA002;
uint16_t UseProfileUUID = 0xA003;
const static char DEVICE_NAME[] = "Device"; // Device name
static const uint16_t uuid16_list[] = {0xFFF};
static uint8_t percentageValue[10] = {0};
GattAttribute nameDescr( BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)"Percentage", strlen("Percentage"));
GattAttribute *descriptors[] = {&nameDescr};
WriteOnlyArrayGattCharacteristic<uint8_t,sizeof(percentageValue)>
percentageChar( PercentageUUID,
percentageValue,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
descriptors,
sizeof(descriptors) / sizeof(GattAttribute*) );
GattCharacteristic *characteristics[] = {&percentageChar, &timeChar, &UseProfileChar};
GattService newService(newServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
编辑
通过下面的讨论,我现在有:
#include <string>
class MyGattArray
{
public:
MyGattArray( const std::string& name ) :
attr( BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)name.c_str(), (name.size()+1) )
{
descriptors[0] = &attr;
}
GattAttribute attr;
GattAttribute *descriptors[1];
};
和
static uint8_t percentageValue[10] = {0};
MyGattArray PercentageName( "Percentage" );
GattAttribute *descriptors[] = {&(PercentageName.attr)};
WriteOnlyArrayGattCharacteristic<uint8_t,sizeof(percentageValue)>
percentageChar( PercentageUUID,
percentageValue,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
descriptors,
sizeof(descriptors) / sizeof(GattAttribute*) );
这会构建,但不会为特征命名。
【问题讨论】:
-
does not give the characteristic a name是什么意思,连接设备时字符有描述符吗?如果有,它的内容是什么? -
@jpo38 服务已创建,但特征只有0xA001描述,没有其他内容。
-
你有没有试过在这两种情况下调试
WriteOnlyArrayGattCharacteristic函数的执行? -
这很棘手,因为它不包含在函数中,所以我无法执行 printf。你要我检查什么?
-
使用调试器并检查两种解决方案在运行时有什么不同......
标签: c++ bluetooth bluetooth-lowenergy mbed