Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions lib/win/src/ble_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,17 +579,18 @@ bool BLEManager::Read(const std::string& uuid, const winrt::guid& serviceUuid,
{
peripheral.GetCharacteristic(
serviceUuid, characteristicUuid, [=](std::optional<GattCharacteristic> characteristic) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
if (characteristic)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
characteristic->ReadValueAsync(BluetoothCacheMode::Uncached)
.Completed(
bind2(this, &BLEManager::OnRead, uuid, serviceId, characteristicId));
}
else
{
LOGE("GetCharacteristic error");
mEmit.Read(uuid, serviceId, characteristicId, Data(), false, "GetCharacteristic error");
}
});
return true;
Expand Down Expand Up @@ -631,10 +632,10 @@ bool BLEManager::Write(const std::string& uuid, const winrt::guid& serviceUuid,
{
peripheral.GetCharacteristic(
serviceUuid, characteristicUuid, [=](std::optional<GattCharacteristic> characteristic) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
if (characteristic)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
auto writer = DataWriter();
writer.WriteBytes(data);
auto value = writer.DetachBuffer();
Expand All @@ -647,6 +648,7 @@ bool BLEManager::Write(const std::string& uuid, const winrt::guid& serviceUuid,
else
{
LOGE("GetCharacteristic error");
mEmit.Write(uuid, serviceId, characteristicId, "GetCharacteristic error");
}
});
return true;
Expand Down Expand Up @@ -689,10 +691,10 @@ bool BLEManager::Notify(const std::string& uuid, const winrt::guid& serviceUuid,
IFDEVICE(device, uuid)
{
auto onCharacteristic = [=](std::optional<GattCharacteristic> characteristic) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
if (characteristic)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
bool subscribed = mNotifyMap.IsSubscribed(uuid, *characteristic);

if (on)
Expand All @@ -703,7 +705,7 @@ bool BLEManager::Notify(const std::string& uuid, const winrt::guid& serviceUuid,
mEmit.Notify(uuid, serviceId, characteristicId, true);
return;
}

auto onChanged = bind2(this, &BLEManager::OnValueChanged, uuid);
auto token = characteristic->ValueChanged(onChanged);
mNotifyMap.Add(uuid, *characteristic, token);
Expand Down Expand Up @@ -741,6 +743,7 @@ bool BLEManager::Notify(const std::string& uuid, const winrt::guid& serviceUuid,
else
{
LOGE("GetCharacteristic error");
mEmit.Notify(uuid, serviceId, characteristicId, on, "GetCharacteristic error");
}
};
peripheral.GetCharacteristic(serviceUuid, characteristicUuid, onCharacteristic);
Expand Down Expand Up @@ -787,10 +790,10 @@ bool BLEManager::DiscoverDescriptors(const std::string& uuid, const winrt::guid&
{
peripheral.GetCharacteristic(
serviceUuid, characteristicUuid, [=](std::optional<GattCharacteristic> characteristic) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
if (characteristic)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
auto completed = bind2(this, &BLEManager::OnDescriptorsDiscovered, uuid,
serviceId, characteristicId);
characteristic->GetDescriptorsAsync(BluetoothCacheMode::Uncached)
Expand All @@ -799,6 +802,8 @@ bool BLEManager::DiscoverDescriptors(const std::string& uuid, const winrt::guid&
else
{
LOGE("GetCharacteristic error");
std::vector<std::string> emptyDescriptors;
mEmit.DescriptorsDiscovered(uuid, serviceId, characteristicId, emptyDescriptors, "GetCharacteristic error");
}
});
return true;
Expand Down Expand Up @@ -836,18 +841,19 @@ bool BLEManager::ReadValue(const std::string& uuid, const winrt::guid& serviceUu
peripheral.GetDescriptor(
serviceUuid, characteristicUuid, descriptorUuid,
[=](std::optional<GattDescriptor> descriptor) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
std::string descriptorId = toStr(descriptorUuid);
if (descriptor)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
std::string descriptorId = toStr(descriptorUuid);
auto completed = bind2(this, &BLEManager::OnReadValue, uuid, serviceId,
characteristicId, descriptorId);
descriptor->ReadValueAsync(BluetoothCacheMode::Uncached).Completed(completed);
}
else
{
LOGE("descriptor not found");
mEmit.ReadValue(uuid, serviceId, characteristicId, descriptorId, Data(), "descriptor not found");
}
});
return true;
Expand Down Expand Up @@ -888,11 +894,11 @@ bool BLEManager::WriteValue(const std::string& uuid, const winrt::guid& serviceU
IFDEVICE(device, uuid)
{
auto onDescriptor = [=](std::optional<GattDescriptor> descriptor) {
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
std::string descriptorId = toStr(descriptorUuid);
if (descriptor)
{
std::string serviceId = toStr(serviceUuid);
std::string characteristicId = toStr(characteristicUuid);
std::string descriptorId = toStr(descriptorUuid);
auto writer = DataWriter();
writer.WriteBytes(data);
auto value = writer.DetachBuffer();
Expand All @@ -903,6 +909,7 @@ bool BLEManager::WriteValue(const std::string& uuid, const winrt::guid& serviceU
else
{
LOGE("descriptor not found");
mEmit.WriteValue(uuid, serviceId, characteristicId, descriptorId, "descriptor not found");
}
};
peripheral.GetDescriptor(serviceUuid, characteristicUuid, descriptorUuid, onDescriptor);
Expand Down