我正在尝试使用mbed API将一些特性用户描述添加到我的自定义 BLE GATT 服务中。到目前为止,我的工作都是基于这种代码结构。但是,我想为这些特征添加名称。我找不到太多关于如何执行此操作的信息。但是,下面是来自论坛的评论,说明了如何做到这一点。
The constructor for GattCharacteristic() takes an array of GattAttribtues as an optional argument. You can populate your User-Description into a GattAttribute and pass it along to the Characteristic.
到目前为止,我有这个结构来设置我的特性。
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};
WriteOnlyArrayGattCharacteristic<uint8_t,
sizeof(percentageValue)> percentageChar(PercentageUUID, percentageValue);
static uint8_t timeValue[10] = {0};
ReadWriteArrayGattCharacteristic<uint8_t,
sizeof(timeValue)> timeChar(TimeUUID, timeValue);
static uint8_t UseProfileValue[10] = {0};
WriteOnlyArrayGattCharacteristic<uint8_t,
sizeof(UseProfileValue)> UseProfileChar(UseProfileUUID, UseProfileValue);
// Set up custom service
GattCharacteristic *characteristics[] = {&percentageChar, &timeChar, &UseProfileChar};
GattService newService(newServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
如何为这 3 个特征添加描述?
编辑
我现在有:
static uint8_t percentageValue[10] = {0};
GattAttribute descr( BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)"Percentage", strlen("Percentage"));
WriteOnlyArrayGattCharacteristic<uint8_t,
sizeof(percentageValue)> percentageChar( PercentageUUID,
percentageValue,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
&descr,
1 );
Error: No instance of constructor "WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>::WriteOnlyArrayGattCharacteristic [with T=std::uint8_t, NUM_ELEMENTS=10U]" matches the argument list in "main.cpp"
它在“大小”行上抛出一个。