diff options
Diffstat (limited to 'ble/Bluetooth.cpp')
-rw-r--r-- | ble/Bluetooth.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/ble/Bluetooth.cpp b/ble/Bluetooth.cpp index 31f82e3..fe63b4f 100644 --- a/ble/Bluetooth.cpp +++ b/ble/Bluetooth.cpp @@ -3,7 +3,6 @@ #include <sstream> #include <iomanip> -#include <string.h> namespace trygvis { namespace bluetooth { @@ -49,7 +48,7 @@ void Mac::copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, _5 = bytes[5]; } -Mac Mac::parseMac(string s) throw(BluetoothException) { +Mac Mac::parseMac(string s) { unsigned int bytes[6]; int count = sscanf(s.c_str(), "%02x:%02x:%02x:%02x:%02x:%02x", &bytes[0], &bytes[1], &bytes[2], &bytes[3], &bytes[4], &bytes[5]); @@ -86,6 +85,17 @@ void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t en bytes.write16le(uuid.value); } +void AttPdu::makeRead(ByteBuffer &bytes, uint16_t handle) { + bytes.write8(AttPduType::READ_REQ); + bytes.write16le(handle); +} + +void AttPdu::makeWrite(ByteBuffer &req, uint16_t handle, const ByteBuffer &bytes) { + req.write8(AttPduType::WRITE_REQ); + req.write16le(handle); + req.write(bytes); +} + vector<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) { DF << "bytes: " << bytes.toString(); @@ -128,6 +138,22 @@ vector<AttributeData> AttPdu::parseReadByType(ByteBuffer &bytes) { return parse(bytes, READ_BY_TYPE_RES); } +void AttPdu::parseRead(ByteBuffer &bytes) { + AttPduType t = (AttPduType) bytes.read8(); + + if (t != READ_RES) { + throw BluetoothException("Unexpected type: " + to_string(t)); + } +} + +void AttPdu::parseWrite(ByteBuffer &bytes) { + AttPduType t = (AttPduType) bytes.read8(); + + if (t != WRITE_RES) { + throw BluetoothException("Unexpected type: " + to_string(t)); + } +} + // ----------------------------------------------------------------------- // AttributeData // ----------------------------------------------------------------------- |