diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-10 19:02:57 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-10 19:02:57 +0100 |
commit | 1c97f6df59c825b26ecb18975fd9f62e14fc46ce (patch) | |
tree | 0bdd9b909e2f2476d78527d39efc301414048609 /Bluetooth.cpp | |
parent | 5cb96fd96f51e949c5311db3080c58d851b7c2e1 (diff) | |
download | ble-toys-1c97f6df59c825b26ecb18975fd9f62e14fc46ce.tar.gz ble-toys-1c97f6df59c825b26ecb18975fd9f62e14fc46ce.tar.bz2 ble-toys-1c97f6df59c825b26ecb18975fd9f62e14fc46ce.tar.xz ble-toys-1c97f6df59c825b26ecb18975fd9f62e14fc46ce.zip |
o wip.
Diffstat (limited to 'Bluetooth.cpp')
-rw-r--r-- | Bluetooth.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/Bluetooth.cpp b/Bluetooth.cpp index 22f67ec..43faf0a 100644 --- a/Bluetooth.cpp +++ b/Bluetooth.cpp @@ -14,12 +14,12 @@ namespace trygvis { std::ostringstream buf; buf - << setw(2) << hex << setfill('0') << (int)bytes[5] << ":" - << setw(2) << hex << setfill('0') << (int)bytes[4] << ":" - << setw(2) << hex << setfill('0') << (int)bytes[3] << ":" - << setw(2) << hex << setfill('0') << (int)bytes[2] << ":" - << setw(2) << hex << setfill('0') << (int)bytes[1] << ":" - << setw(2) << hex << setfill('0') << (int)bytes[0]; + << setw(2) << hex << setfill('0') << (int) bytes[5] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[4] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[3] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[2] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[1] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[0]; return buf.str(); } @@ -46,6 +46,39 @@ namespace trygvis { return new Mac(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]); } + AttPdu::AttPdu(ByteBuffer &bytes) : bytes(bytes) { + } + + AttPdu::AttPdu(ByteBuffer &bytes, AttPduType type) : bytes(bytes) { + bytes.add8(type); + } + + AttPduType AttPdu::getType() { + return (AttPduType) bytes.get8(0); + } + + AttPdu AttPdu::parse(ByteBuffer & bytes) { + if(size == 0) { + throw BluetoothException("PDU is too small"); + } + + AttPdu pdu = AttPdu(bytes, size); + + AttPduType type = pdu.getType(); + + switch (type) { + case READ_BY_GROUP_TYPE_RES: + if (size < 4) { + throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + size); + } + return pdu; + default: + throw BluetoothException("Uknown PDU type: " + type); + } + + return pdu; + } + // ----------------------------------------------------------------------- // Adapter // ----------------------------------------------------------------------- |