mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Convet ByteArray to std::string in ble_gatt_client
PiperOrigin-RevId: 514786088
This commit is contained in:
committed by
Copybara-Service
parent
ead3df1ff8
commit
0c078b3528
@@ -182,22 +182,23 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
const Uuid &service_uuid, const Uuid &characteristic_uuid) override;
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
absl::optional<ByteArray> ReadCharacteristic(
|
||||
absl::optional<std::string> ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic &characteristic) override;
|
||||
|
||||
bool WriteCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
const ByteArray &value) override;
|
||||
absl::string_view value) override;
|
||||
|
||||
bool SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic &characteristic, bool enable,
|
||||
absl::AnyInvocable<void(const ByteArray &value)> on_characteristic_changed_cb) override;
|
||||
absl::AnyInvocable<void(absl::string_view value)> on_characteristic_changed_cb) override;
|
||||
|
||||
void Disconnect() override;
|
||||
|
||||
private:
|
||||
GNCMBleCentral *central_;
|
||||
std::string peripheral_id_;
|
||||
absl::flat_hash_map<api::ble_v2::GattCharacteristic, ByteArray> gatt_characteristic_values_;
|
||||
absl::flat_hash_map<api::ble_v2::GattCharacteristic, absl::string_view>
|
||||
gatt_characteristic_values_;
|
||||
};
|
||||
|
||||
absl::Mutex mutex_;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <CoreBluetooth/CoreBluetooth.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -539,7 +540,7 @@ bool BleMedium::GattClient::DiscoverServiceAndCharacteristics(
|
||||
api::ble_v2::GattCharacteristic characteristic = {.uuid = it->second,
|
||||
.service_uuid = service_uuid};
|
||||
gatt_characteristic_values_.insert(
|
||||
{characteristic, ByteArrayFromNSData(cb_characteristic.value)});
|
||||
{characteristic, ByteArrayFromNSData(cb_characteristic.value).string_data()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,24 +568,24 @@ absl::optional<api::ble_v2::GattCharacteristic> BleMedium::GattClient::GetCharac
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
absl::optional<ByteArray> BleMedium::GattClient::ReadCharacteristic(
|
||||
absl::optional<std::string> BleMedium::GattClient::ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
auto const it = gatt_characteristic_values_.find(characteristic);
|
||||
if (it == gatt_characteristic_values_.end()) {
|
||||
return absl::nullopt; // NOLINT
|
||||
}
|
||||
return it->second;
|
||||
return std::string(it->second);
|
||||
}
|
||||
|
||||
bool BleMedium::GattClient::WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, const ByteArray& value) {
|
||||
const api::ble_v2::GattCharacteristic& characteristic, absl::string_view value) {
|
||||
// No op.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleMedium::GattClient::SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(const ByteArray& value)> on_characteristic_changed_cb) {
|
||||
absl::AnyInvocable<void(absl::string_view value)> on_characteristic_changed_cb) {
|
||||
// No op since we can't write characteristics.
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user