1

我正在尝试使用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"它在“大小”行上抛出一个。

4

1 回答 1

1

查看Characteristic类 API: https ://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/file/d494ad3e87bd/ble/GattCharacteristic.h :

template <typename T>
class WriteOnlyGattCharacteristic : public GattCharacteristic {
public:
    WriteOnlyGattCharacteristic<T>(const UUID     &uuid,
                                   T              *valuePtr,
                                   uint8_t        additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
                                   GattAttribute *descriptors[]        = NULL,
                                   unsigned       numDescriptors       = 0) :
        GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
                           BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
        /* empty */
    }
};

附加到特性的描述符必须作为您正在创建GattAttribute *descriptors[]的对象的第四个参数( ,默认情况下为 NULL,这意味着特性没有描述符)传递。*ArrayGattCharacteristic它们是GattAttribute,在您的特征之前创建并在创建时传递给它。

也许这可以添加一个描述符(未测试),应该使用数组来添加更多(就像你对特征所做的那样):

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*) );

希望这会有所帮助(再次;-))

于 2015-10-25T11:04:27.373 回答