aboutsummaryrefslogtreecommitdiff
path: root/ble/Bluetooth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ble/Bluetooth.cpp')
-rw-r--r--ble/Bluetooth.cpp52
1 files changed, 23 insertions, 29 deletions
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<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) {
// cout << "bytes: " << bytes.toString();
- AttPduType t = (AttPduType) bytes.read8();
+ auto t = static_cast<AttPduType>(bytes.read8());
- if (t == INVALID_HANDLE) {
+ if (t == ERROR) {
return vector<AttributeData>();
}
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<AttributeData> 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<BluetoothAdapter> 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};
}
}