Adapt to new bytebuffer

This commit is contained in:
Rapsssito 2024-08-19 16:58:24 +02:00
parent e4bef0c2a3
commit 7e82aadbb7
2 changed files with 8 additions and 2 deletions

View file

@ -112,7 +112,7 @@ bool BLEServer::create_device_characteristics_() {
if (this->model_.has_value()) {
BLECharacteristic *model =
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
model->set_value(ByteBuffer::wrap(this->model_.value()));
model->set_value(ByteBuffer::wrap(std::vector<uint8_t>(this->model_.value().begin(), this->model_.value().end())));
} else {
BLECharacteristic *model =
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
@ -125,7 +125,7 @@ bool BLEServer::create_device_characteristics_() {
BLECharacteristic *manufacturer =
this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ);
manufacturer->set_value(ByteBuffer::wrap(this->manufacturer_));
manufacturer->set_value(ByteBuffer::wrap(std::vector<uint8_t>(this->manufacturer_.begin(), this->manufacturer_.end())));
return true;
}

View file

@ -27,36 +27,42 @@ ByteBuffer ByteBuffer::wrap(std::vector<uint8_t> data, Endian endianness) {
ByteBuffer ByteBuffer::wrap(uint8_t value) {
ByteBuffer buffer = ByteBuffer::create(1);
buffer.put_uint8(value);
buffer.flip();
return buffer;
}
ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) {
ByteBuffer buffer = ByteBuffer::create(2, endianness);
buffer.put_uint16(value);
buffer.flip();
return buffer;
}
ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) {
ByteBuffer buffer = ByteBuffer::create(4, endianness);
buffer.put_uint32(value);
buffer.flip();
return buffer;
}
ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) {
ByteBuffer buffer = ByteBuffer::create(8, endianness);
buffer.put_uint64(value);
buffer.flip();
return buffer;
}
ByteBuffer ByteBuffer::wrap(float value, Endian endianness) {
ByteBuffer buffer = ByteBuffer::create(sizeof(float), endianness);
buffer.put_float(value);
buffer.flip();
return buffer;
}
ByteBuffer ByteBuffer::wrap(double value, Endian endianness) {
ByteBuffer buffer = ByteBuffer::create(sizeof(double), endianness);
buffer.put_double(value);
buffer.flip();
return buffer;
}