From 25d82b0c52120c81cfed5bc1f245408f08203b7b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 30 Aug 2018 22:17:06 +0200 Subject: Fixing lots of small nits: o boost::uuid didn't give much, use our own and add new short uuid type. o Fixing nits from clang-tidy. --- ble/Bluetooth.cpp | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'ble/Bluetooth.cpp') diff --git a/ble/Bluetooth.cpp b/ble/Bluetooth.cpp index 13c81b3..4160acc 100644 --- a/ble/Bluetooth.cpp +++ b/ble/Bluetooth.cpp @@ -71,14 +71,14 @@ AttPduType AttPdu::getType() { return (AttPduType) bytes.get8(0); } -void AttPdu::makeReadByGroupType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, SpecUuid uuid) { +void AttPdu::makeReadByGroupType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, ShortUuid uuid) { bytes.write8(AttPduType::READ_BY_GROUP_TYPE_REQ); bytes.write16le(startHandle); bytes.write16le(endHandle); bytes.write16le(uuid.value); } -void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, SpecUuid uuid) { +void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, ShortUuid uuid) { bytes.write8(AttPduType::READ_BY_TYPE_REQ); bytes.write16le(startHandle); bytes.write16le(endHandle); @@ -99,14 +99,14 @@ void AttPdu::makeWrite(ByteBuffer &req, uint16_t handle, const ByteBuffer &bytes vector AttPdu::parse(ByteBuffer &bytes, AttPduType type) { // cout << "bytes: " << bytes.toString(); - AttPduType t = (AttPduType) bytes.read8(); + auto t = static_cast(bytes.read8()); - if (t == INVALID_HANDLE) { + if (t == ERROR) { return vector(); } if (t != type) { - throw BluetoothException("Unexpected type: " + to_string(t)); + throw BluetoothException("Unexpected type: " + to_string(t) + ", expected " + to_string(type)); } if (bytes.getSize() < 4) { @@ -138,11 +138,13 @@ vector AttPdu::parseReadByType(ByteBuffer &bytes) { return parse(bytes, READ_BY_TYPE_RES); } +static uint16_t parseExchangeMtuReq(ByteBuffer &bytes); + void AttPdu::parseRead(ByteBuffer &bytes) { AttPduType t = (AttPduType) bytes.read8(); if (t != READ_RES) { - throw BluetoothException("Unexpected type: " + to_string(t)); + throw BluetoothException("Unexpected type: " + to_string(t) + ", expected " + to_string(READ_RES)); } } @@ -150,7 +152,7 @@ void AttPdu::parseWrite(ByteBuffer &bytes) { AttPduType t = (AttPduType) bytes.read8(); if (t != WRITE_RES) { - throw BluetoothException("Unexpected type: " + to_string(t)); + throw BluetoothException("Unexpected type: " + to_string(t) + ", expected " + to_string(WRITE_RES)); } } @@ -168,45 +170,36 @@ AttributeData::AttributeData(uint16_t handle, ByteBuffer value) : handle(handle), value(value) { } -AttributeData::~AttributeData() { -} +AttributeData::~AttributeData() = default; // ----------------------------------------------------------------------- // Gatt // ----------------------------------------------------------------------- -BluetoothGatt::BluetoothGatt() { -} +BluetoothGatt::BluetoothGatt() = default; -BluetoothGatt::~BluetoothGatt() { -} +BluetoothGatt::~BluetoothGatt() = default; // ----------------------------------------------------------------------- // Device // ----------------------------------------------------------------------- -BluetoothDevice::BluetoothDevice() { -} +BluetoothDevice::BluetoothDevice() = default; -BluetoothDevice::~BluetoothDevice() { -} +BluetoothDevice::~BluetoothDevice() = default; // ----------------------------------------------------------------------- // Adapter // ----------------------------------------------------------------------- -BluetoothAdapter::BluetoothAdapter() { -} - -BluetoothAdapter::~BluetoothAdapter() { -} +BluetoothAdapter::BluetoothAdapter() = default; +BluetoothAdapter::~BluetoothAdapter() = default; // ----------------------------------------------------------------------- // Bluetooth System. This is not sub-classed by implementations. // ----------------------------------------------------------------------- -BluetoothSystem::BluetoothSystem() { -} +BluetoothSystem::BluetoothSystem() = default; BluetoothSystem::~BluetoothSystem() { adapters.clear(); @@ -223,11 +216,12 @@ shared_ptr BluetoothSystem::getAdapter(string name) { return it->second; } -uuid_t makeUuid(const uuid_t base, uint8_t a, uint8_t b) { - uuid_t c = base; - c.data[2] = a; - c.data[3] = b; - return c; +Uuid makeUuid(const Uuid &base, uint8_t a, uint8_t b) { + uint8_t value[16]; + memcpy(value, base.value, 16); + value[2] = a; + value[3] = b; + return Uuid{value}; } } -- cgit v1.2.3