我正在开发一个 c++ 应用程序,用一些信息填充蓝牙阵列。它基于 mbed 平台 BLE_API,但我认为这不相关。我有以下代码,我试图将其重新考虑到一个函数中。
GattAttribute nameDescr1(BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)"Percentage", strlen("Percentage"));
GattAttribute *pdescriptors[] = { &nameDescr1 };
PercentageFill(PercentageUUID, valueBytes.getPointer(),
valueBytes.getNumValueBytes(), HeartRateValueBytes::MAX_VALUE_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
pdescriptors,
sizeof(pdescriptors) / sizeof(GattAttribute*)),
到目前为止,我得到了这个:
GattAttribute produceName (char title[]) {
GattAttribute nameDescr(BLE_UUID_DESCRIPTOR_CHAR_USER_DESC, (uint8_t *)title, strlen(title));
GattAttribute *descriptors[] = { &nameDescr };
return descriptors;
}
但是,可以预见的是,我会抛出一个错误:
错误:不存在合适的构造函数来将“GattAttribute *[1]”转换为“GattAttribute”
我可以看到它为什么抛出这个,但我不确定我应该如何返回整个数组,因为这是“PercentageFill”构造函数所需的格式。
谢谢。
更新:
为了提供完整的上下文,这是我正在设置的其他 Characteristcis(每个都有不同的名称):
NewService(BLE &_ble, uint8_t percentageFill, uint8_t replacementDue) :
ble(_ble),
valueBytes(percentageFill),
PercentageFill(PercentageUUID, valueBytes.getPointer(),
valueBytes.getNumValueBytes(), HeartRateValueBytes::MAX_VALUE_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
pdescriptors,
sizeof(pdescriptors) / sizeof(GattAttribute*)),
Time( TimeUUID,
&replacementDue,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
tdescriptors,
sizeof(tdescriptors) / sizeof(GattAttribute*)),
UseProfile( UseProfileUUID,
&controlPointValue,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES,
Udescriptors,
sizeof(Udescriptors) / sizeof(GattAttribute*)),) {
setupService();
}