1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Merge branch 'fixed_arrays' into integration

This commit is contained in:
J. Nick Koston
2025-07-21 13:25:13 -10:00
5 changed files with 166 additions and 51 deletions

View File

@@ -1463,19 +1463,19 @@ message BluetoothGATTGetServicesRequest {
}
message BluetoothGATTDescriptor {
repeated uint64 uuid = 1;
repeated uint64 uuid = 1 [(fixed_array_size) = 2];
uint32 handle = 2;
}
message BluetoothGATTCharacteristic {
repeated uint64 uuid = 1;
repeated uint64 uuid = 1 [(fixed_array_size) = 2];
uint32 handle = 2;
uint32 properties = 3;
repeated BluetoothGATTDescriptor descriptors = 4;
}
message BluetoothGATTService {
repeated uint64 uuid = 1;
repeated uint64 uuid = 1 [(fixed_array_size) = 2];
uint32 handle = 2;
repeated BluetoothGATTCharacteristic characteristics = 3;
}
@@ -1486,7 +1486,7 @@ message BluetoothGATTGetServicesResponse {
option (ifdef) = "USE_BLUETOOTH_PROXY";
uint64 address = 1;
repeated BluetoothGATTService services = 2;
repeated BluetoothGATTService services = 2 [(fixed_array_size) = 1];
}
message BluetoothGATTGetServicesDoneResponse {

View File

@@ -1891,23 +1891,18 @@ bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarI
return true;
}
void BluetoothGATTDescriptor::encode(ProtoWriteBuffer buffer) const {
for (auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
}
void BluetoothGATTDescriptor::calculate_size(uint32_t &total_size) const {
if (!this->uuid.empty()) {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
}
void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const {
for (auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
buffer.encode_uint32(3, this->properties);
for (auto &it : this->descriptors) {
@@ -1915,42 +1910,33 @@ void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const {
}
}
void BluetoothGATTCharacteristic::calculate_size(uint32_t &total_size) const {
if (!this->uuid.empty()) {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
ProtoSize::add_uint32_field(total_size, 1, this->properties);
ProtoSize::add_repeated_message(total_size, 1, this->descriptors);
}
void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const {
for (auto &it : this->uuid) {
buffer.encode_uint64(1, it, true);
}
buffer.encode_uint64(1, this->uuid[0], true);
buffer.encode_uint64(1, this->uuid[1], true);
buffer.encode_uint32(2, this->handle);
for (auto &it : this->characteristics) {
buffer.encode_message(3, it, true);
}
}
void BluetoothGATTService::calculate_size(uint32_t &total_size) const {
if (!this->uuid.empty()) {
for (const auto &it : this->uuid) {
ProtoSize::add_uint64_field_repeated(total_size, 1, it);
}
}
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]);
ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]);
ProtoSize::add_uint32_field(total_size, 1, this->handle);
ProtoSize::add_repeated_message(total_size, 1, this->characteristics);
}
void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint64(1, this->address);
for (auto &it : this->services) {
buffer.encode_message(2, it, true);
}
buffer.encode_message(2, this->services[0], true);
}
void BluetoothGATTGetServicesResponse::calculate_size(uint32_t &total_size) const {
ProtoSize::add_uint64_field(total_size, 1, this->address);
ProtoSize::add_repeated_message(total_size, 1, this->services);
ProtoSize::add_message_object_repeated(total_size, 1, this->services[0]);
}
void BluetoothGATTGetServicesDoneResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint64(1, this->address);

View File

@@ -1796,7 +1796,7 @@ class BluetoothGATTGetServicesRequest : public ProtoDecodableMessage {
};
class BluetoothGATTDescriptor : public ProtoMessage {
public:
std::vector<uint64_t> uuid{};
std::array<uint64_t, 2> uuid{};
uint32_t handle{0};
void encode(ProtoWriteBuffer buffer) const override;
void calculate_size(uint32_t &total_size) const override;
@@ -1808,7 +1808,7 @@ class BluetoothGATTDescriptor : public ProtoMessage {
};
class BluetoothGATTCharacteristic : public ProtoMessage {
public:
std::vector<uint64_t> uuid{};
std::array<uint64_t, 2> uuid{};
uint32_t handle{0};
uint32_t properties{0};
std::vector<BluetoothGATTDescriptor> descriptors{};
@@ -1822,7 +1822,7 @@ class BluetoothGATTCharacteristic : public ProtoMessage {
};
class BluetoothGATTService : public ProtoMessage {
public:
std::vector<uint64_t> uuid{};
std::array<uint64_t, 2> uuid{};
uint32_t handle{0};
std::vector<BluetoothGATTCharacteristic> characteristics{};
void encode(ProtoWriteBuffer buffer) const override;
@@ -1836,12 +1836,12 @@ class BluetoothGATTService : public ProtoMessage {
class BluetoothGATTGetServicesResponse : public ProtoMessage {
public:
static constexpr uint8_t MESSAGE_TYPE = 71;
static constexpr uint8_t ESTIMATED_SIZE = 38;
static constexpr uint8_t ESTIMATED_SIZE = 21;
#ifdef HAS_PROTO_MESSAGE_DUMP
const char *message_name() const override { return "bluetooth_gatt_get_services_response"; }
#endif
uint64_t address{0};
std::vector<BluetoothGATTService> services{};
std::array<BluetoothGATTService, 1> services{};
void encode(ProtoWriteBuffer buffer) const override;
void calculate_size(uint32_t &total_size) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP

View File

@@ -13,16 +13,17 @@ namespace bluetooth_proxy {
static const char *const TAG = "bluetooth_proxy.connection";
static std::vector<uint64_t> get_128bit_uuid_vec(esp_bt_uuid_t uuid_source) {
static std::array<uint64_t, 2> get_128bit_uuid_array(esp_bt_uuid_t uuid_source) {
esp_bt_uuid_t uuid = espbt::ESPBTUUID::from_uuid(uuid_source).as_128bit().get_uuid();
return std::vector<uint64_t>{((uint64_t) uuid.uuid.uuid128[15] << 56) | ((uint64_t) uuid.uuid.uuid128[14] << 48) |
((uint64_t) uuid.uuid.uuid128[13] << 40) | ((uint64_t) uuid.uuid.uuid128[12] << 32) |
((uint64_t) uuid.uuid.uuid128[11] << 24) | ((uint64_t) uuid.uuid.uuid128[10] << 16) |
((uint64_t) uuid.uuid.uuid128[9] << 8) | ((uint64_t) uuid.uuid.uuid128[8]),
((uint64_t) uuid.uuid.uuid128[7] << 56) | ((uint64_t) uuid.uuid.uuid128[6] << 48) |
((uint64_t) uuid.uuid.uuid128[5] << 40) | ((uint64_t) uuid.uuid.uuid128[4] << 32) |
((uint64_t) uuid.uuid.uuid128[3] << 24) | ((uint64_t) uuid.uuid.uuid128[2] << 16) |
((uint64_t) uuid.uuid.uuid128[1] << 8) | ((uint64_t) uuid.uuid.uuid128[0])};
return std::array<uint64_t, 2>{
((uint64_t) uuid.uuid.uuid128[15] << 56) | ((uint64_t) uuid.uuid.uuid128[14] << 48) |
((uint64_t) uuid.uuid.uuid128[13] << 40) | ((uint64_t) uuid.uuid.uuid128[12] << 32) |
((uint64_t) uuid.uuid.uuid128[11] << 24) | ((uint64_t) uuid.uuid.uuid128[10] << 16) |
((uint64_t) uuid.uuid.uuid128[9] << 8) | ((uint64_t) uuid.uuid.uuid128[8]),
((uint64_t) uuid.uuid.uuid128[7] << 56) | ((uint64_t) uuid.uuid.uuid128[6] << 48) |
((uint64_t) uuid.uuid.uuid128[5] << 40) | ((uint64_t) uuid.uuid.uuid128[4] << 32) |
((uint64_t) uuid.uuid.uuid128[3] << 24) | ((uint64_t) uuid.uuid.uuid128[2] << 16) |
((uint64_t) uuid.uuid.uuid128[1] << 8) | ((uint64_t) uuid.uuid.uuid128[0])};
}
void BluetoothConnection::dump_config() {
@@ -95,9 +96,8 @@ void BluetoothConnection::send_service_for_discovery_() {
api::BluetoothGATTGetServicesResponse resp;
resp.address = this->address_;
resp.services.emplace_back();
auto &service_resp = resp.services.back();
service_resp.uuid = get_128bit_uuid_vec(service_result.uuid);
auto &service_resp = resp.services[0];
service_resp.uuid = get_128bit_uuid_array(service_result.uuid);
service_resp.handle = service_result.start_handle;
// Get the number of characteristics directly with one call
@@ -136,7 +136,7 @@ void BluetoothConnection::send_service_for_discovery_() {
service_resp.characteristics.emplace_back();
auto &characteristic_resp = service_resp.characteristics.back();
characteristic_resp.uuid = get_128bit_uuid_vec(char_result.uuid);
characteristic_resp.uuid = get_128bit_uuid_array(char_result.uuid);
characteristic_resp.handle = char_result.char_handle;
characteristic_resp.properties = char_result.properties;
char_offset++;
@@ -176,7 +176,7 @@ void BluetoothConnection::send_service_for_discovery_() {
characteristic_resp.descriptors.emplace_back();
auto &descriptor_resp = characteristic_resp.descriptors.back();
descriptor_resp.uuid = get_128bit_uuid_vec(desc_result.uuid);
descriptor_resp.uuid = get_128bit_uuid_array(desc_result.uuid);
descriptor_resp.handle = desc_result.handle;
desc_offset++;
}